diff --git a/src/video/groupnetcamview.cpp b/src/video/groupnetcamview.cpp index 06e2dbcce..3824e0eb8 100644 --- a/src/video/groupnetcamview.cpp +++ b/src/video/groupnetcamview.cpp @@ -20,27 +20,32 @@ #include "groupnetcamview.h" #include "src/widget/tool/croppinglabel.h" #include "src/video/videosurface.h" -#include -#include -#include +#include "src/persistence/settings.h" #include "src/audio/audio.h" #include "src/core/core.h" +#include "src/friendlist.h" +#include "src/friend.h" #include +#include +#include +#include +#include +#include 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; + } + } +} diff --git a/src/video/groupnetcamview.h b/src/video/groupnetcamview.h index 0994f8c2c..9991bac7d 100644 --- a/src/video/groupnetcamview.h +++ b/src/video/groupnetcamview.h @@ -39,6 +39,8 @@ public slots: private slots: void findActivePeer(); + void friendAvatarChanged(int FriendId, const QPixmap& pixmap); + //void update private: struct PeerVideo diff --git a/src/video/netcamview.cpp b/src/video/netcamview.cpp index 5dbf83115..231ec1b3c 100644 --- a/src/video/netcamview.cpp +++ b/src/video/netcamview.cpp @@ -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); } diff --git a/src/video/netcamview.h b/src/video/netcamview.h index 0015b1755..2aa1309c7 100644 --- a/src/video/netcamview.h +++ b/src/video/netcamview.h @@ -52,6 +52,7 @@ private: VideoSurface* selfVideoSurface; MovableWidget* selfFrame; + int friendId; bool e = false; }; diff --git a/src/video/videosurface.cpp b/src/video/videosurface.cpp index 1402d3366..ae284b2d0 100644 --- a/src/video/videosurface.cpp +++ b/src/video/videosurface.cpp @@ -85,6 +85,7 @@ float VideoSurface::getRatio() const void VideoSurface::setAvatar(const QPixmap &pixmap) { avatar = pixmap; + update(); } QPixmap VideoSurface::getAvatar() const diff --git a/src/widget/form/settings/avform.cpp b/src/widget/form/settings/avform.cpp index 45e07374c..90b0af65d 100644 --- a/src/widget/form/settings/avform.cpp +++ b/src/widget/form/settings/avform.cpp @@ -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); + } } }