From be24d069fea7252c8c67d8a9ccf132399c7efa18 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 13 Apr 2017 01:16:54 +0200 Subject: [PATCH] refs #935, resizing for message frame also avoid showing overlay message too soon (ie when not full initialized) --- src/blackgui/overlaymessagesframe.cpp | 29 ++++++++++++++++++--------- src/blackgui/overlaymessagesframe.h | 6 +++--- src/swiftguistandard/swiftguistd.cpp | 17 +++++++++++----- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/blackgui/overlaymessagesframe.cpp b/src/blackgui/overlaymessagesframe.cpp index 00fd39da3..24e64746f 100644 --- a/src/blackgui/overlaymessagesframe.cpp +++ b/src/blackgui/overlaymessagesframe.cpp @@ -12,21 +12,25 @@ #include "blackgui/stylesheetutility.h" #include "blackgui/guiutility.h" #include "blackmisc/network/textmessage.h" +#include "blackmisc/verify.h" #include #include #include #include #include +#include namespace BlackGui { COverlayMessagesFrame::COverlayMessagesFrame(QWidget *parent) : QFrame(parent) - { } + { + // void + } COverlayMessagesFrame::~COverlayMessagesFrame() - {} + { } void COverlayMessagesFrame::showStatusMessagesFrame() { @@ -42,11 +46,6 @@ namespace BlackGui } } - void COverlayMessagesFrame::hideStatusMessagesFrame() - { - if (!m_overlayMessages) { return; } - } - void COverlayMessagesFrame::showOverlayMessagesWithConfirmation(const BlackMisc::CStatusMessageList &messages, const QString &confirmationMessage, std::function okLambda, int defaultButton, int timeOutMs) { if (messages.isEmpty()) { return; } @@ -106,10 +105,21 @@ namespace BlackGui } } + void COverlayMessagesFrame::resizeEvent(QResizeEvent *event) + { + QFrame::resizeEvent(event); + if (this->m_overlayMessages && this->m_overlayMessages->isVisible()) + { + this->initInnerFrame(); + } + } + QSize COverlayMessagesFrame::innerFrameSize() const { - const int w = this->width(); - const int h = this->height(); + // check against minimum if widget is initialized, but not yet resized + const int w = std::max(this->width(), this->minimumWidth()); + const int h = std::max(this->height(), this->minimumHeight()); + int wInner = this->m_widthFactor * w; int hInner = this->m_heightFactor * h; if (wInner > this->maximumWidth()) wInner = this->maximumWidth(); @@ -122,6 +132,7 @@ namespace BlackGui const QSize inner(innerFrameSize()); if (!this->m_overlayMessages) { + // lazy init this->m_overlayMessages = new COverlayMessages(inner.width(), inner.height(), this); this->m_overlayMessages->addShadow(); this->m_overlayMessages->showKillButton(m_showKillButton); diff --git a/src/blackgui/overlaymessagesframe.h b/src/blackgui/overlaymessagesframe.h index d5054577e..d7e62b85f 100644 --- a/src/blackgui/overlaymessagesframe.h +++ b/src/blackgui/overlaymessagesframe.h @@ -55,9 +55,6 @@ namespace BlackGui //! Show kill button void showKillButton(bool killButton); - //! Hide the inner frame - void hideStatusMessagesFrame(); - //! Inner frame factors 0..1 //! \remarks can also be restricted by maximumHeight() / maximumWidth() void setInnerFrameFactor(double xFactor, double yFactor); @@ -91,6 +88,9 @@ namespace BlackGui //! \copydoc QFrame::keyPressEvent virtual void keyPressEvent(QKeyEvent *event) override; + //! \copydoc QFrame::resizeEvent + virtual void resizeEvent(QResizeEvent *event) override; + COverlayMessages *m_overlayMessages = nullptr; //!< embedded QFrame with Status messages private: diff --git a/src/swiftguistandard/swiftguistd.cpp b/src/swiftguistandard/swiftguistd.cpp index c5740bf23..6172d9e8a 100644 --- a/src/swiftguistandard/swiftguistd.cpp +++ b/src/swiftguistandard/swiftguistd.cpp @@ -201,7 +201,6 @@ bool SwiftGuiStd::isMainPageSelected(SwiftGuiStd::MainPageIndex mainPage) const return ui->sw_MainMiddle->currentIndex() == static_cast(mainPage); } - void SwiftGuiStd::ps_loginRequested() { if (ui->sw_MainMiddle->currentIndex() == static_cast(MainPageLogin)) @@ -403,6 +402,7 @@ void SwiftGuiStd::ps_verifyDataAvailability() void SwiftGuiStd::ps_sharedFilesHeadersLoaded() { Q_ASSERT_X(sGui && sGui->hasWebDataServices(), Q_FUNC_INFO, "Missing web services"); + Q_ASSERT_X(CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "Wrong thread"); const CEntityFlags::Entity newEntities = sGui->getWebDataServices()->getEntitiesWithNewerHeaderTimestamp(CEntityFlags::AllDbEntities); if (newEntities == CEntityFlags::NoEntity) { return; } CStatusMessage sm = CStatusMessage(this).info("New data for shared files:"); @@ -413,11 +413,18 @@ void SwiftGuiStd::ps_sharedFilesHeadersLoaded() sm = CStatusMessage(this).info("Load data for '%1'?") << CEntityFlags::flagToString(newSingleEntity); sms.push_back(sm); } - auto lambda = [newEntities]() + + // allow to init GUI completely + const int delay = 2500; + QTimer::singleShot(delay, this, [ = ] { - sGui->getWebDataServices()->triggerLoadingDirectlyFromSharedFiles(newEntities, false); - }; - ui->fr_CentralFrameInside->showOverlayMessagesWithConfirmation(sms, "Load data?", lambda); + // delayed call + auto lambda = [newEntities]() + { + sGui->getWebDataServices()->triggerLoadingDirectlyFromSharedFiles(newEntities, false); + }; + ui->fr_CentralFrameInside->showOverlayMessagesWithConfirmation(sms, "Load data?", lambda); + }); } void SwiftGuiStd::playNotifcationSound(CNotificationSounds::Notification notification) const