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

View File

@ -32,6 +32,7 @@
NetCamView::NetCamView(int friendId, QWidget* parent) NetCamView::NetCamView(int friendId, QWidget* parent)
: GenericNetCamView(parent) : GenericNetCamView(parent)
, selfFrame{nullptr} , selfFrame{nullptr}
, friendId{friendId}
{ {
QString id = FriendList::findFriend(friendId)->getToxId().toString(); QString id = FriendList::findFriend(friendId)->getToxId().toString();
videoSurface = new VideoSurface(Settings::getInstance().getSavedAvatar(id), this); videoSurface = new VideoSurface(Settings::getInstance().getSavedAvatar(id), this);
@ -70,10 +71,22 @@ NetCamView::NetCamView(int friendId, QWidget* parent)
selfFrame->resetBoundary(boundingRect); 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; VideoMode videoMode;
QSize videoSize = Settings::getInstance().getCamVideoRes(); QSize videoSize = Settings::getInstance().getCamVideoRes();
videoMode.width = videoSize.width(); videoMode.width = videoSize.width();
videoMode.height = videoSize.height(); videoMode.height = videoSize.height();
qDebug() << "SIZER" << videoSize;
videoMode.FPS = Settings::getInstance().getCamVideoFPS(); videoMode.FPS = Settings::getInstance().getCamVideoFPS();
CameraSource::getInstance().open(Settings::getInstance().getVideoDev(), videoMode); CameraSource::getInstance().open(Settings::getInstance().getVideoDev(), videoMode);
} }

View File

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

View File

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

View File

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