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 510ac9e57..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) @@ -226,7 +227,7 @@ GenericChatForm::~GenericChatForm() void GenericChatForm::adjustFileMenuPosition() { - QPoint pos = fileButton->pos(); + QPoint pos = fileButton->mapTo(bodySplitter, QPoint()); QSize size = fileFlyout->size(); fileFlyout->move(pos.x() - size.width(), pos.y()); } @@ -244,7 +245,6 @@ void GenericChatForm::hideFileMenu() { if(fileFlyout->isShown() || fileFlyout->isBeingShown()) fileFlyout->animateHide(); - } bool GenericChatForm::isEmpty() @@ -506,8 +506,8 @@ void GenericChatForm::resizeEvent(QResizeEvent* event) bool GenericChatForm::eventFilter(QObject* object, QEvent* event) { - EmoticonsWidget * ev = qobject_cast(object); - if (( ev) && (event->type() == QEvent::KeyPress) ) + EmoticonsWidget* ev = qobject_cast(object); + if (ev && event->type() == QEvent::KeyPress) { QKeyEvent* key = static_cast(event); msgEdit->sendKeyEvent(key); @@ -527,15 +527,21 @@ bool GenericChatForm::eventFilter(QObject* object, QEvent* event) showFileMenu(); break; - case QEvent::Leave: { - QPoint pos = mapFromGlobal(QCursor::pos()); - QRect fileRect(fileFlyout->pos(), fileFlyout->size()); - fileRect = fileRect.united(QRect(fileButton->pos(), fileButton->size())); + case QEvent::Leave: + { + QPoint flyPos = fileFlyout->mapToGlobal(QPoint()); + QSize flySize = fileFlyout->size(); - if (!fileRect.contains(pos)) + QPoint filePos = fileButton->mapToGlobal(QPoint()); + QSize fileSize = fileButton->size(); + + QRect region = QRect(flyPos, flySize).united(QRect(filePos, fileSize)); + + if (!region.contains(QCursor::pos())) hideFileMenu(); - } break; + break; + } case QEvent::MouseButtonPress: hideFileMenu(); @@ -625,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() @@ -632,6 +643,10 @@ void GenericChatForm::hideNetcam() if (!netcam) return; + ContentDialog* current = ContentDialog::current(); + if (current) + current->onVideoHide(); + netcam->close(); netcam->hide(); delete netcam;