1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Video: resizable group avatar, synchronize avatar

This commit is contained in:
TheSpiritXIII 2015-08-19 12:42:54 -04:00
parent 50041a3140
commit 7886fdcb69
6 changed files with 107 additions and 37 deletions

View File

@ -20,27 +20,32 @@
#include "groupnetcamview.h"
#include "src/widget/tool/croppinglabel.h"
#include "src/video/videosurface.h"
#include <QScrollArea>
#include <QTimer>
#include <QMap>
#include "src/persistence/settings.h"
#include "src/audio/audio.h"
#include "src/core/core.h"
#include "src/friendlist.h"
#include "src/friend.h"
#include <QBoxLayout>
#include <QScrollArea>
#include <QSplitter>
#include <QTimer>
#include <QMap>
#include <QDebug>
class LabeledVideo : public QFrame
{
public:
LabeledVideo(QWidget* parent = 0, bool expanding = true)
LabeledVideo(const QPixmap& avatar, QWidget* parent = 0, bool expanding = true)
: QFrame(parent)
{
//setFrameStyle(QFrame::Box);
videoSurface = new VideoSurface(QPixmap(), 0, expanding);
qDebug() << "Created expanding? " << expanding;
videoSurface = new VideoSurface(avatar, 0, expanding);
videoSurface->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
videoSurface->setMinimumHeight(96);
videoSurface->setMinimumHeight(32);
//videoSurface->setMaximumHeight(96);
connect(videoSurface, &VideoSurface::ratioChanged, this, &LabeledVideo::updateSize);
label = new CroppingLabel(this);
label->setText("Unknown");
label->setTextFormat(Qt::PlainText);
label->setStyleSheet("color: white");
//label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@ -50,8 +55,6 @@ public:
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(videoSurface, 1);
layout->addWidget(label);
setMouseTracking(true);
}
~LabeledVideo()
@ -74,30 +77,33 @@ public:
return label->text();
}
void setActive(bool active = true)
{
if (active)
setStyleSheet("QFrame { background-color: #414141; border-radius: 10px; }");
else
setStyleSheet(QString());
}
protected:
void resizeEvent(QResizeEvent* event) final override
{
QWidget::resizeEvent(event);
qDebug() << "Resize!";
updateSize();
}
void mousePressEvent(QMouseEvent* event) final override
{
if (videoSurface->isExpanding())
{
setStyleSheet("QFrame { background-color: #414141; border-radius: 10px; }");
selected = true;
}
QWidget::resizeEvent(event);
}
private slots:
void updateSize()
{
qDebug() << videoSurface->isExpanding();
if (videoSurface->isExpanding())
{
int width = videoSurface->height() * videoSurface->getRatio();
videoSurface->setFixedWidth(width);
setMaximumWidth(width + layout()->margin() * 2);
videoSurface->setMinimumWidth(width);
videoSurface->setMaximumWidth(width);
//setMaximumWidth(width + layout()->margin() * 2);
qDebug() << videoSurface->minimumWidth();
}
}
@ -111,35 +117,40 @@ GroupNetCamView::GroupNetCamView(int group, QWidget *parent)
: GenericNetCamView(parent)
, group(group)
{
videoLabelSurface = new LabeledVideo(this, false);
videoLabelSurface = new LabeledVideo(QPixmap(), this, false);
videoSurface = videoLabelSurface->getVideoSurface();
//videoSurface->setExpanding(false);
videoSurface->setMinimumHeight(256);
videoSurface->setContentsMargins(6, 6, 6, 6);
videoSurface->setContentsMargins(6, 6, 6, 0);
videoLabelSurface->setContentsMargins(0, 0, 0, 0);
videoLabelSurface->layout()->setMargin(0);
videoLabelSurface->setStyleSheet("QFrame { background-color: black; }");
verLayout->insertWidget(0, videoLabelSurface, 1);
//verLayout->insertWidget(0, videoLabelSurface, 1);
QSplitter* splitter = new QSplitter(Qt::Vertical, this);
verLayout->insertWidget(0, splitter, 1);
splitter->addWidget(videoLabelSurface);
splitter->setStyleSheet("QSplitter { background-color: black; } QSplitter::handle { background-color: black; }");
QScrollArea* scrollArea = new QScrollArea();
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrollArea->setStyleSheet("QScrollArea { background-color: black; }");
scrollArea->setFrameStyle(QFrame::NoFrame);
QWidget* widget = new QWidget(nullptr);
scrollArea->setWidget(widget);
scrollArea->setWidgetResizable(true);
horLayout = new QHBoxLayout(widget);
//FlowLayout* horLayout = new FlowLayout(widget);
horLayout->addStretch();
horLayout->addStretch(1);
selfVideoSurface = new LabeledVideo(this);
selfVideoSurface = new LabeledVideo(Settings::getInstance().getSavedAvatar(Core::getInstance()->getSelfId().toString()), this);
horLayout->addWidget(selfVideoSurface);
horLayout->setAlignment(selfVideoSurface, Qt::AlignCenter | Qt::AlignHCenter);
//horLayout->setAlignment(selfVideoSurface, Qt::AlignCenter | Qt::AlignHCenter);
horLayout->addStretch();
verLayout->insertWidget(1, scrollArea);
scrollArea->setMinimumHeight(selfVideoSurface->height());
horLayout->addStretch(1);
splitter->addWidget(scrollArea);
scrollArea->setWidget(widget);
//verLayout->insertWidget(1, scrollArea);
//scrollArea->setMinimumHeight(selfVideoSurface->height());
connect(&Audio::getInstance(), &Audio::groupAudioPlayed, this, &GroupNetCamView::groupAudioPlayed);
@ -148,9 +159,9 @@ GroupNetCamView::GroupNetCamView(int group, QWidget *parent)
connect(timer, &QTimer::timeout, this, &GroupNetCamView::findActivePeer);
timer->start();
connect(Core::getInstance(), &Core::selfAvatarChanged, [this]()
connect(Core::getInstance(), &Core::selfAvatarChanged, [this](const QPixmap& pixmap)
{
selfVideoSurface->update();
selfVideoSurface->getVideoSurface()->setAvatar(pixmap);
findActivePeer();
});
connect(Core::getInstance(), &Core::usernameSet, [this](const QString& username)
@ -158,6 +169,8 @@ GroupNetCamView::GroupNetCamView(int group, QWidget *parent)
selfVideoSurface->setText(username);
findActivePeer();
});
connect(Core::getInstance(), &Core::friendAvatarChanged, this, &GroupNetCamView::friendAvatarChanged);
selfVideoSurface->setText(Core::getInstance()->getUsername());
}
@ -171,10 +184,10 @@ void GroupNetCamView::clearPeers()
void GroupNetCamView::addPeer(int peer, const QString& name)
{
LabeledVideo* labeledVideo = new LabeledVideo(this);
QPixmap groupAvatar = Settings::getInstance().getSavedAvatar(Core::getInstance()->getGroupPeerToxId(group, peer).toString());
LabeledVideo* labeledVideo = new LabeledVideo(groupAvatar, this);
labeledVideo->setText(name);
horLayout->insertWidget(horLayout->count() - 1, labeledVideo);
horLayout->setAlignment(labeledVideo, Qt::AlignCenter | Qt::AlignHCenter);
PeerVideo peerVideo;
peerVideo.video = labeledVideo;
videoList.insert(peer, peerVideo);
@ -202,6 +215,7 @@ void GroupNetCamView::setActive(int peer)
if (peer == -1)
{
videoLabelSurface->setText(selfVideoSurface->getText());
activePeer = -1;
return;
}
@ -212,7 +226,17 @@ void GroupNetCamView::setActive(int peer)
// When group video exists:
// videoSurface->setSource(peerVideo.value()->getVideoSurface()->source);
videoLabelSurface->setText(peerVideo.value().video->getText());
auto lastVideo = videoList.find(activePeer);
if (lastVideo != videoList.end())
lastVideo.value().video->setActive(false);
LabeledVideo *labeledVideo = peerVideo.value().video;
videoLabelSurface->setText(labeledVideo->getText());
videoLabelSurface->getVideoSurface()->setAvatar(labeledVideo->getVideoSurface()->getAvatar());
labeledVideo->setActive();
activePeer = peer;
}
}
@ -243,3 +267,24 @@ void GroupNetCamView::findActivePeer()
setActive(candidate);
}
void GroupNetCamView::friendAvatarChanged(int FriendId, const QPixmap &pixmap)
{
Friend* f = FriendList::findFriend(FriendId);
for (int i = 0; i < Core::getInstance()->getGroupNumberPeers(group); ++i)
{
if (Core::getInstance()->getGroupPeerToxId(group, i) == f->getToxId())
{
auto peerVideo = videoList.find(i);
if (peerVideo != videoList.end())
{
peerVideo.value().video->getVideoSurface()->setAvatar(pixmap);
findActivePeer();
}
break;
}
}
}

View File

@ -39,6 +39,8 @@ public slots:
private slots:
void findActivePeer();
void friendAvatarChanged(int FriendId, const QPixmap& pixmap);
//void update
private:
struct PeerVideo

View File

@ -32,6 +32,7 @@
NetCamView::NetCamView(int friendId, QWidget* parent)
: GenericNetCamView(parent)
, selfFrame{nullptr}
, friendId{friendId}
{
QString id = FriendList::findFriend(friendId)->getToxId().toString();
videoSurface = new VideoSurface(Settings::getInstance().getSavedAvatar(id), this);
@ -70,10 +71,22 @@ NetCamView::NetCamView(int friendId, QWidget* parent)
selfFrame->resetBoundary(boundingRect);
});
connect(Core::getInstance(), &Core::selfAvatarChanged, [this](const QPixmap& pixmap)
{
selfVideoSurface->setAvatar(pixmap);
});
connect(Core::getInstance(), &Core::friendAvatarChanged, [this](int FriendId, const QPixmap& pixmap)
{
if (this->friendId == FriendId)
videoSurface->setAvatar(pixmap);
});
VideoMode videoMode;
QSize videoSize = Settings::getInstance().getCamVideoRes();
videoMode.width = videoSize.width();
videoMode.height = videoSize.height();
qDebug() << "SIZER" << videoSize;
videoMode.FPS = Settings::getInstance().getCamVideoFPS();
CameraSource::getInstance().open(Settings::getInstance().getVideoDev(), videoMode);
}

View File

@ -52,6 +52,7 @@ private:
VideoSurface* selfVideoSurface;
MovableWidget* selfFrame;
int friendId;
bool e = false;
};

View File

@ -85,6 +85,7 @@ float VideoSurface::getRatio() const
void VideoSurface::setAvatar(const QPixmap &pixmap)
{
avatar = pixmap;
update();
}
QPixmap VideoSurface::getAvatar() const

View File

@ -178,6 +178,14 @@ void AVForm::updateVideoModes(int curIndex)
break;
}
}
if (videoModes.size())
{
bodyUI->videoModescomboBox->setUpdatesEnabled(false);
bodyUI->videoModescomboBox->setCurrentIndex(-1);
bodyUI->videoModescomboBox->setUpdatesEnabled(true);
bodyUI->videoModescomboBox->setCurrentIndex(0);
}
}
}