diff --git a/src/blackgui/components/dbmappingcomponentaware.cpp b/src/blackgui/components/dbmappingcomponentaware.cpp index 82e3d2c55..59957b066 100644 --- a/src/blackgui/components/dbmappingcomponentaware.cpp +++ b/src/blackgui/components/dbmappingcomponentaware.cpp @@ -33,16 +33,16 @@ namespace BlackGui m_mappingComponent = m; } - void CDbMappingComponentAware::showMappingComponentOverlayMessage(const CStatusMessage &message, int timeoutMs) + bool CDbMappingComponentAware::showMappingComponentOverlayMessage(const CStatusMessage &message, int timeoutMs) { - if (!m_mappingComponent) { return; } - m_mappingComponent->showOverlayMessage(message, timeoutMs); + if (!m_mappingComponent) { return false; } + return m_mappingComponent->showOverlayMessage(message, timeoutMs); } - void CDbMappingComponentAware::showMappingComponentOverlayHtmlMessage(const CStatusMessage &message, int timeoutMs) + bool CDbMappingComponentAware::showMappingComponentOverlayHtmlMessage(const CStatusMessage &message, int timeoutMs) { - if (!m_mappingComponent) { return; } - m_mappingComponent->showOverlayHTMLMessage(message, timeoutMs); + if (!m_mappingComponent) { return false; } + return m_mappingComponent->showOverlayHTMLMessage(message, timeoutMs); } } // ns } // ns diff --git a/src/blackgui/components/dbmappingcomponentaware.h b/src/blackgui/components/dbmappingcomponentaware.h index d4e38b7c0..e7bf92602 100644 --- a/src/blackgui/components/dbmappingcomponentaware.h +++ b/src/blackgui/components/dbmappingcomponentaware.h @@ -45,8 +45,8 @@ namespace BlackGui CDbMappingComponentAware &operator =(const CDbMappingComponentAware &) = default; //! Overlay messages @{ - void showMappingComponentOverlayMessage(const BlackMisc::CStatusMessage &message, int timeoutMs = -1); - void showMappingComponentOverlayHtmlMessage(const BlackMisc::CStatusMessage &message, int timeoutMs = -1); + bool showMappingComponentOverlayMessage(const BlackMisc::CStatusMessage &message, int timeoutMs = -1); + bool showMappingComponentOverlayHtmlMessage(const BlackMisc::CStatusMessage &message, int timeoutMs = -1); //! @} private : diff --git a/src/blackgui/components/dbownmodelsetcomponent.cpp b/src/blackgui/components/dbownmodelsetcomponent.cpp index 000f45eb2..61d3bdc2c 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.cpp +++ b/src/blackgui/components/dbownmodelsetcomponent.cpp @@ -6,7 +6,6 @@ * or distributed except according to the terms contained in the LICENSE file. */ -#include "blackgui/guiapplication.h" #include "blackgui/components/dbmappingcomponent.h" #include "blackgui/components/dbownmodelsetcomponent.h" #include "blackgui/components/dbownmodelsetformdialog.h" @@ -19,6 +18,8 @@ #include "blackgui/views/aircraftmodelview.h" #include "blackgui/views/viewbase.h" #include "blackgui/views/aircraftmodelstatisticsdialog.h" +#include "blackgui/guiapplication.h" +#include "blackgui/guiutility.h" #include "blackmisc/simulation/aircraftmodelutils.h" #include "blackmisc/simulation/aircraftmodellist.h" #include "blackmisc/simulation/distributorlist.h" @@ -238,15 +239,24 @@ namespace BlackGui if (!ownModelSet.isEmpty()) { const CSimulatorInfo sim = this->getSelectedSimulator(); - const CStatusMessage m = this->setCachedModels(ownModelSet, sim); + const CStatusMessage m = this->setCachedModels(ownModelSet, sim); CLogMessage::preformatted(m); if (m.isSuccess()) { - this->showMappingComponentOverlayHtmlMessage(QStringLiteral("Save model set for '%1'").arg(sim.toQString(true)), 5000); + const QString msg = QStringLiteral("Saved model set for '%1'").arg(sim.toQString(true)); + + // display either as overlay of componet or view + if (!this->showMappingComponentOverlayHtmlMessage(msg, 5000)) + { + ui->tvp_OwnModelSet->showOverlayHTMLMessage(msg, 5000); + } } else { - this->showMappingComponentOverlayMessage(m); + if (!this->showMappingComponentOverlayMessage(m)) + { + ui->tvp_OwnModelSet->showOverlayMessage(m); + } } } return; @@ -493,6 +503,11 @@ namespace BlackGui } } + bool CDbOwnModelSetComponent::runsInDialog() + { + return CGuiUtility::findParentDialog(this, 5); + } + void CDbOwnModelSetComponent::CLoadModelSetMenu::customMenu(CMenuActions &menuActions) { // for the moment I use all sims, I could restrict to CSimulatorInfo::getLocallyInstalledSimulators(); diff --git a/src/blackgui/components/dbownmodelsetcomponent.h b/src/blackgui/components/dbownmodelsetcomponent.h index 4db6c5c67..0c83debaa 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.h +++ b/src/blackgui/components/dbownmodelsetcomponent.h @@ -179,6 +179,9 @@ namespace BlackGui //! Update distributor order void updateDistributorOrder(const BlackMisc::Simulation::CSimulatorInfo &simulator); + //! Is that component running in a dialog + bool runsInDialog(); + QScopedPointer ui; QScopedPointer m_modelSetFormDialog; QScopedPointer m_firstModelSetDialog; diff --git a/src/blackgui/guiutility.cpp b/src/blackgui/guiutility.cpp index 937e78eba..d6f41ff5b 100644 --- a/src/blackgui/guiutility.cpp +++ b/src/blackgui/guiutility.cpp @@ -591,17 +591,17 @@ namespace BlackGui return QApplication::topLevelWidgets().contains(widget); } - bool CGuiUtility::isQMainWindow(QWidget *widget) + bool CGuiUtility::isQMainWindow(const QWidget *widget) { if (!widget) { return false; } - QMainWindow *mw = qobject_cast(widget); + const QMainWindow *mw = qobject_cast(widget); return mw; } - bool CGuiUtility::isDialog(QWidget *widget) + bool CGuiUtility::isDialog(const QWidget *widget) { if (!widget) { return false; } - QDialog *mw = qobject_cast(widget); + const QDialog *mw = qobject_cast(widget); return mw; } @@ -789,6 +789,20 @@ namespace BlackGui return nullptr; } + QDialog *CGuiUtility::findParentDialog(QWidget *widget, int maxLevel) + { + if (CGuiUtility::isDialog(widget)) { return qobject_cast(widget); } + int level = 0; + while (widget->parent()) + { + level++; + if (level > maxLevel) { return nullptr; } + widget = widget->parentWidget(); + if (CGuiUtility::isDialog(widget)) { return qobject_cast(widget); } + } + return nullptr; + } + void CGuiUtility::setElidedText(QLabel *label, const QString &text, Qt::TextElideMode mode) { if (!label) { return; } diff --git a/src/blackgui/guiutility.h b/src/blackgui/guiutility.h index 4c89918c3..be1dd2227 100644 --- a/src/blackgui/guiutility.h +++ b/src/blackgui/guiutility.h @@ -206,8 +206,8 @@ namespace BlackGui static bool isTopLevelWindow(QWidget *widget); //! Check window type @{ - static bool isQMainWindow(QWidget *widget); - static bool isDialog(QWidget *widget); + static bool isQMainWindow(const QWidget *widget); + static bool isDialog(const QWidget *widget); //! @} //! Fade in a widget @@ -261,6 +261,9 @@ namespace BlackGui //! Find parent dialog if there is any, otherwise null static QDialog *findParentDialog(QWidget *widget); + //! Find parent dialog if there is any, otherwise null + static QDialog *findParentDialog(QWidget *widget, int maxLevel); + //! Set elided text static void setElidedText(QLabel *label, const QString &text, Qt::TextElideMode mode = Qt::ElideMiddle); diff --git a/src/blackgui/overlaymessagesframe.h b/src/blackgui/overlaymessagesframe.h index 54f0b9b52..047b33ca6 100644 --- a/src/blackgui/overlaymessagesframe.h +++ b/src/blackgui/overlaymessagesframe.h @@ -188,21 +188,23 @@ namespace BlackGui } //! \copydoc BlackGui::COverlayMessages::showOverlayMessage - void showOverlayMessage(const BlackMisc::CStatusMessage &message, int timeOutMs = -1) + bool showOverlayMessage(const BlackMisc::CStatusMessage &message, int timeOutMs = -1) { - if (message.isEmpty()) { return; } + if (message.isEmpty()) { return false; } this->initInnerFrame(); m_overlayMessages->showOverlayMessage(message, timeOutMs); WIDGET::repaint(); + return true; } //! \copydoc BlackGui::COverlayMessages::showOverlayTextMessage - void showOverlayTextMessage(const BlackMisc::Network::CTextMessage &textMessage, int timeOutMs = -1) + bool showOverlayTextMessage(const BlackMisc::Network::CTextMessage &textMessage, int timeOutMs = -1) { - if (textMessage.isEmpty()) { return; } + if (textMessage.isEmpty()) { return false; } this->initInnerFrame(); m_overlayMessages->showOverlayTextMessage(textMessage, timeOutMs); WIDGET::repaint(); + return true; } //! \copydoc BlackGui::COverlayMessages::showOverlayVariant @@ -231,19 +233,21 @@ namespace BlackGui } //! \copydoc BlackGui::COverlayMessages::showHTMLMessage - void showOverlayHTMLMessage(const QString &htmlMessage, int timeOutMs = -1) + bool showOverlayHTMLMessage(const QString &htmlMessage, int timeOutMs = -1) { this->initMinimalFrame(); m_overlayMessages->showHTMLMessage(htmlMessage, timeOutMs); WIDGET::repaint(); + return true; } //! \copydoc BlackGui::COverlayMessages::showHTMLMessage - void showOverlayHTMLMessage(const BlackMisc::CStatusMessage &message, int timeOutMs = -1) + bool showOverlayHTMLMessage(const BlackMisc::CStatusMessage &message, int timeOutMs = -1) { this->initMinimalFrame(); m_overlayMessages->showHTMLMessage(message, timeOutMs); WIDGET::repaint(); + return true; } //! \copydoc BlackGui::COverlayMessages::showDownloadProgress