From f8a45b40519de8f38cef80f5ffc41c19417e0139 Mon Sep 17 00:00:00 2001 From: Diadlo Date: Thu, 30 Jun 2016 13:29:30 +0300 Subject: [PATCH] fix(video): Changed minimum window size with video Fix #3396. --- src/video/genericnetcamview.cpp | 28 ++++++++++++------ src/video/genericnetcamview.h | 7 +++-- src/widget/contentdialog.cpp | 38 ++++++++++++++++++++---- src/widget/contentdialog.h | 8 ++++- src/widget/form/chatform.cpp | 2 +- src/widget/form/genericchatform.cpp | 46 ++++++++++++++++++----------- 6 files changed, 91 insertions(+), 38 deletions(-) diff --git a/src/video/genericnetcamview.cpp b/src/video/genericnetcamview.cpp index 499ae3d4a..d10ea30d8 100644 --- a/src/video/genericnetcamview.cpp +++ b/src/video/genericnetcamview.cpp @@ -18,9 +18,10 @@ */ #include "genericnetcamview.h" + #include -#include #include +#include GenericNetCamView::GenericNetCamView(QWidget *parent) : QWidget(parent) @@ -35,6 +36,7 @@ GenericNetCamView::GenericNetCamView(QWidget *parent) buttonLayout->addStretch(); button = new QPushButton(); buttonLayout->addWidget(button); + buttonLayout->setSizeConstraint(QLayout::SetMinimumSize); connect(button, &QPushButton::clicked, this, &GenericNetCamView::showMessageClicked); verLayout->addSpacing(spacing); @@ -52,18 +54,26 @@ GenericNetCamView::GenericNetCamView(QWidget *parent) setStyleSheet("NetCamView { background-color: #c1c1c1; }"); } +QSize GenericNetCamView::getSurfaceMinSize() +{ + QSize surfaceSize = videoSurface->minimumSize(); + QSize buttonSize = button->size(); + QSize panelSize(0, 45); + + return surfaceSize + buttonSize + panelSize; +} + void GenericNetCamView::setShowMessages(bool show, bool notify) { - if (show) - { - button->setText(tr("Show Messages")); - - if (notify) - button->setIcon(QIcon(":/ui/chatArea/info.svg")); - } - else + if (!show) { button->setText(tr("Hide Messages")); button->setIcon(QIcon()); + return; } + + button->setText(tr("Show Messages")); + + if (notify) + button->setIcon(QIcon(":/ui/chatArea/info.svg")); } diff --git a/src/video/genericnetcamview.h b/src/video/genericnetcamview.h index 7cb1a79a2..816ee3135 100644 --- a/src/video/genericnetcamview.h +++ b/src/video/genericnetcamview.h @@ -20,17 +20,18 @@ #ifndef GENERICNETCAMVIEW_H #define GENERICNETCAMVIEW_H +#include +#include #include -class VideoSurface; -class QPushButton; -class QVBoxLayout; +#include "src/video/videosurface.h" class GenericNetCamView : public QWidget { Q_OBJECT public: explicit GenericNetCamView(QWidget* parent); + QSize getSurfaceMinSize(); signals: void showMessageClicked(); diff --git a/src/widget/contentdialog.cpp b/src/widget/contentdialog.cpp index 6dfdc4382..5121fb2b4 100644 --- a/src/widget/contentdialog.cpp +++ b/src/widget/contentdialog.cpp @@ -18,6 +18,14 @@ */ #include "contentdialog.h" + +#include +#include +#include +#include +#include +#include + #include "contentlayout.h" #include "friendwidget.h" #include "groupwidget.h" @@ -34,12 +42,6 @@ #include "src/widget/friendlistlayout.h" #include "src/widget/form/settingswidget.h" #include "src/widget/translator.h" -#include -#include -#include -#include -#include -#include ContentDialog* ContentDialog::currentDialog = nullptr; QHash> ContentDialog::friendList; @@ -49,6 +51,8 @@ ContentDialog::ContentDialog(SettingsWidget* settingsWidget, QWidget* parent) : ActivateDialog(parent, Qt::Window) , activeChatroomWidget(nullptr) , settingsWidget(settingsWidget) + , videoSurfaceSize(QSize()) + , videoCount(0) { QVBoxLayout* boxLayout = new QVBoxLayout(this); boxLayout->setMargin(0); @@ -360,6 +364,28 @@ void ContentDialog::cycleContacts(bool forward, bool loop) } } +void ContentDialog::onVideoShow(QSize size) +{ + videoCount++; + if (videoCount > 1) + return; + + videoSurfaceSize = size; + QSize minSize = minimumSize(); + setMinimumSize(minSize + videoSurfaceSize); +} + +void ContentDialog::onVideoHide() +{ + videoCount--; + if (videoCount > 0) + return; + + QSize minSize = minimumSize(); + setMinimumSize(minSize - videoSurfaceSize); + videoSurfaceSize = QSize(); +} + ContentDialog* ContentDialog::current() { return currentDialog; diff --git a/src/widget/contentdialog.h b/src/widget/contentdialog.h index 29d67b4e7..1c2f9dadc 100644 --- a/src/widget/contentdialog.h +++ b/src/widget/contentdialog.h @@ -20,10 +20,11 @@ #ifndef CONTENTDIALOG_H #define CONTENTDIALOG_H -#include "src/widget/tool/activatedialog.h" #include + #include "src/core/corestructs.h" #include "src/widget/genericchatitemlayout.h" +#include "src/widget/tool/activatedialog.h" template class QHash; template class QSet; @@ -54,6 +55,8 @@ public: void ensureSplitterVisible(); void cycleContacts(bool forward, bool loop = true); + void onVideoShow(QSize size); + void onVideoHide(); static ContentDialog* current(); static bool existsFriendWidget(int friendId, bool focus); @@ -111,6 +114,9 @@ private: GenericChatroomWidget* activeChatroomWidget; GenericChatroomWidget* displayWidget = nullptr; SettingsWidget* settingsWidget; + QSize videoSurfaceSize; + int videoCount; + static ContentDialog* currentDialog; static QHash> friendList; static QHash> groupList; diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 8905c65bb..6ae3e4dd7 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -100,7 +100,7 @@ ChatForm::ChatForm(Friend* chatFriend) headTextLayout->addWidget(callDuration, 1, Qt::AlignCenter); callDuration->hide(); - chatWidget->setMinimumHeight(160); + chatWidget->setMinimumHeight(50); connect(this, &GenericChatForm::messageInserted, this, &ChatForm::onMessageInserted); loadHistoryAction = menu.addAction(QString(), this, SLOT(onLoadHistory())); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index e67504647..17f23b7e7 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -19,33 +19,34 @@ #include "genericchatform.h" +#include #include #include -#include -#include #include +#include +#include #include -#include "src/persistence/smileypack.h" -#include "src/widget/emoticonswidget.h" -#include "src/widget/style.h" -#include "src/widget/widget.h" -#include "src/persistence/settings.h" -#include "src/widget/tool/chattextedit.h" -#include "src/widget/maskablepixmapwidget.h" -#include "src/core/core.h" -#include "src/grouplist.h" -#include "src/group.h" -#include "src/friendlist.h" -#include "src/friend.h" #include "src/chatlog/chatlog.h" #include "src/chatlog/content/timestamp.h" +#include "src/core/core.h" +#include "src/friend.h" +#include "src/friendlist.h" +#include "src/group.h" +#include "src/grouplist.h" +#include "src/persistence/settings.h" +#include "src/persistence/smileypack.h" +#include "src/video/genericnetcamview.h" +#include "src/widget/contentdialog.h" +#include "src/widget/contentlayout.h" +#include "src/widget/emoticonswidget.h" +#include "src/widget/maskablepixmapwidget.h" +#include "src/widget/style.h" +#include "src/widget/tool/chattextedit.h" +#include "src/widget/tool/croppinglabel.h" #include "src/widget/tool/flyoutoverlaywidget.h" #include "src/widget/translator.h" -#include "src/widget/contentlayout.h" -#include "src/widget/tool/croppinglabel.h" -#include -#include "src/video/genericnetcamview.h" +#include "src/widget/widget.h" GenericChatForm::GenericChatForm(QWidget *parent) : QWidget(parent, Qt::Window) @@ -630,6 +631,11 @@ void GenericChatForm::showNetcam() bodySplitter->insertWidget(0, netcam); bodySplitter->setCollapsible(0, false); + + QSize minSize = netcam->getSurfaceMinSize(); + ContentDialog* current = ContentDialog::current(); + if (current) + current->onVideoShow(minSize); } void GenericChatForm::hideNetcam() @@ -637,6 +643,10 @@ void GenericChatForm::hideNetcam() if (!netcam) return; + ContentDialog* current = ContentDialog::current(); + if (current) + current->onVideoHide(); + netcam->close(); netcam->hide(); delete netcam;