From 0547b2847e29c037c7484fd5bc34ef92ebd1acdf Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 17 Jun 2014 17:59:14 +0200 Subject: [PATCH] refs #275, own info window component * added to CVariant for value object * signal in text message to indicate overlay messages * info window component (currently not runtme aware, maybe changed in future) * removed old window, adjusted GUI --- samples/blackgui/infowindow.cpp | 41 ----- samples/blackgui/infowindow.h | 44 ------ samples/blackgui/infowindow.ui | 96 ------------ samples/blackgui/mainwindow.cpp | 44 ++---- samples/blackgui/mainwindow.h | 12 +- samples/blackgui/mainwindow_init.cpp | 3 +- samples/blackgui/mainwindow_voice.cpp | 2 +- src/blackgui/infowindowcomponent.cpp | 137 +++++++++++++++++ src/blackgui/infowindowcomponent.h | 66 +++++++++ src/blackgui/infowindowcomponent.ui | 206 ++++++++++++++++++++++++++ src/blackgui/textmessagecomponent.cpp | 4 +- src/blackgui/textmessagecomponent.h | 5 +- src/blackmisc/valueobject.h | 14 +- 13 files changed, 435 insertions(+), 239 deletions(-) delete mode 100644 samples/blackgui/infowindow.cpp delete mode 100644 samples/blackgui/infowindow.h delete mode 100644 samples/blackgui/infowindow.ui create mode 100644 src/blackgui/infowindowcomponent.cpp create mode 100644 src/blackgui/infowindowcomponent.h create mode 100644 src/blackgui/infowindowcomponent.ui diff --git a/samples/blackgui/infowindow.cpp b/samples/blackgui/infowindow.cpp deleted file mode 100644 index fe94b772e..000000000 --- a/samples/blackgui/infowindow.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "infowindow.h" -#include "ui_infowindow.h" -#include -#include - - -/* - * Constructor - */ -CInfoWindow::CInfoWindow(QWidget *parent) : - QWizardPage(parent), - ui(new Ui::InfoWindow) -{ - ui->setupUi(this); -} - -/* - * Destructor - */ -CInfoWindow::~CInfoWindow() { } - -/* - * Info message for some time - */ -void CInfoWindow::setInfoMessage(const QString &message, int displayTimeMs) -{ - // center - const QRect parent = this->parentWidget()->geometry(); - const QRect myself = this->rect(); - int dx = (parent.width() - myself.width()) / 2; - int dy = (parent.height() - myself.height()) / 2; - dy -= 80; // some offset, in order to display further on top - this->move(dx, dy); - - // message and display - this->ui->te_Message->setText(message); - this->show(); - - // hide after some time - QTimer::singleShot(displayTimeMs, this, SLOT(hide())); -} diff --git a/samples/blackgui/infowindow.h b/samples/blackgui/infowindow.h deleted file mode 100644 index 57ce69b3a..000000000 --- a/samples/blackgui/infowindow.h +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright (C) 2013 VATSIM Community / authors - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef SAMPLE_INFOWINDOW_H -#define SAMPLE_INFOWINDOW_H - -#include -#include - -namespace Ui -{ - class InfoWindow; -} - -class CInfoWindow : public QWizardPage -{ - Q_OBJECT - -public: - /*! - * \brief Constructor - * \param parent - */ - explicit CInfoWindow(QWidget *parent = nullptr); - - /*! - * \brief Destructor - */ - ~CInfoWindow(); - - /*! - * \brief Set info message displayed for some time - * \param message - * \param displayTimeMs - */ - void setInfoMessage(const QString &message, int displayTimeMs = 4000); - -private: - QScopedPointer ui; -}; - -#endif // guard diff --git a/samples/blackgui/infowindow.ui b/samples/blackgui/infowindow.ui deleted file mode 100644 index 9f53f638d..000000000 --- a/samples/blackgui/infowindow.ui +++ /dev/null @@ -1,96 +0,0 @@ - - - InfoWindow - - - - 0 - 0 - 245 - 89 - - - - WizardPage - - - QWidget { - font-family: arial-rounded; - font: bold 10px; - color: black; /** font **/ -} - -QPushButton { - background-color: transparent; - border-style: solid; - border-width: 0px; - border-radius:3px; - border-color: green; - max-height:20px; -} - -QTextEdit { - background-color: rgba(255, 255, 0, 240); /* transparent yellow */ - border-style: solid; - border-width:1px; - border-radius:6px; - border-color: green; - opacity: 0.5; -} - - - - - - - true - - - - - - - - 0 - 0 - - - - - 20 - 20 - - - - - - - - :/blackgui/icons/close.png:/blackgui/icons/close.png - - - - - - - - - - - pb_Close - clicked() - InfoWindow - hide() - - - 272 - 52 - - - 302 - 67 - - - - - diff --git a/samples/blackgui/mainwindow.cpp b/samples/blackgui/mainwindow.cpp index a0155f6ab..94040f748 100644 --- a/samples/blackgui/mainwindow.cpp +++ b/samples/blackgui/mainwindow.cpp @@ -24,7 +24,7 @@ using namespace BlackMisc::Audio; MainWindow::MainWindow(GuiModes::WindowMode windowMode, QWidget *parent) : QMainWindow(parent, windowMode == GuiModes::WindowFrameless ? (Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) : (Qt::Tool | Qt::WindowStaysOnTopHint)), ui(new Ui::MainWindow), - m_infoWindow(nullptr), + m_compInfoWindow(nullptr), m_init(false), m_windowMode(windowMode), m_audioTestRunning(NoAudioTest), // contexts and runtime m_coreAvailable(false), m_contextNetworkAvailable(false), m_contextAudioAvailable(false), @@ -48,7 +48,11 @@ MainWindow::MainWindow(GuiModes::WindowMode windowMode, QWidget *parent) : this->setAttribute(Qt::WA_TranslucentBackground, true); // this->setAttribute(Qt::WA_PaintOnScreen); } + + // GUI ui->setupUi(this); + this->m_compInfoWindow = new CInfoWindowComponent(this); // setupUi has to be first! + } /* @@ -73,10 +77,10 @@ void MainWindow::gracefulShutdown() this->getIContextApplication()->notifyAboutComponentChange(IContextApplication::ComponentGui, IContextApplication::ActionStops); // close info window - if (this->m_infoWindow) + if (this->m_compInfoWindow) { - this->m_infoWindow->close(); - this->m_infoWindow = nullptr; + this->m_compInfoWindow->close(); + this->m_compInfoWindow = nullptr; } // shut down all timers @@ -266,7 +270,7 @@ void MainWindow::displayStatusMessage(const CStatusMessage &statusMessage) // display overlay for errors, but not for validation if (statusMessage.getSeverity() == CStatusMessage::SeverityError && statusMessage.getType() != CStatusMessage::TypeValidation) - this->displayOverlayInfo(statusMessage); + this->m_compInfoWindow->displayStatusMessage(statusMessage); } /* @@ -426,36 +430,6 @@ void MainWindow::changeWindowOpacity(int opacity) this->ui->hs_SettingsGuiOpacity->setValue(o * 100.0); } -/* - * Display the info window - */ -void MainWindow::displayOverlayInfo(const QString &message) -{ - if (!this->m_infoWindow) - { - this->m_infoWindow = new CInfoWindow(this); - } - - // display window - if (message.isEmpty()) - { - this->m_infoWindow->hide(); - } - else - { - this->m_infoWindow->setInfoMessage(message); - } -} - -/* - * Info window by - */ -void MainWindow::displayOverlayInfo(const CStatusMessage &message) -{ - this->displayOverlayInfo(message.getMessage()); - // further code goes here, such as marking errors as red ... -} - void MainWindow::updateSimulatorData() { if (this->getIContextSimulator()->isConnected()) diff --git a/samples/blackgui/mainwindow.h b/samples/blackgui/mainwindow.h index 67635a158..be06571c3 100644 --- a/samples/blackgui/mainwindow.h +++ b/samples/blackgui/mainwindow.h @@ -10,7 +10,6 @@ #pragma push_macro("interface") #undef interface -#include "infowindow.h" #include "guimodeenums.h" #include "blackinput/keyboard.h" #include "blackcore/context_audio.h" @@ -27,6 +26,7 @@ #include "blackgui/userlistmodel.h" #include "blackgui/statusmessagelistmodel.h" #include "blackgui/keyboardkeylistmodel.h" +#include "blackgui/infowindowcomponent.h" #include "blackmisc/nwtextmessage.h" #include "blacksound/soundgenerator.h" #include @@ -93,7 +93,7 @@ protected: private: QScopedPointer ui; - CInfoWindow *m_infoWindow; + BlackGui::CInfoWindowComponent *m_compInfoWindow; bool m_init; GuiModes::WindowMode m_windowMode; AudioTest m_audioTestRunning; @@ -314,14 +314,6 @@ private slots: //! Toogle Windows stay on top void toogleWindowStayOnTop(); - //! Display the overlay window - //! Empty string hides window - void displayOverlayInfo(const QString &message = ""); - - //! Overlay info displaying status message - void displayOverlayInfo(const BlackMisc::CStatusMessage &message); - - }; #pragma pop_macro("interface") diff --git a/samples/blackgui/mainwindow_init.cpp b/samples/blackgui/mainwindow_init.cpp index 248d04f0b..dc2465a35 100644 --- a/samples/blackgui/mainwindow_init.cpp +++ b/samples/blackgui/mainwindow_init.cpp @@ -214,8 +214,7 @@ void MainWindow::initGuiSignals() // command line / text messages connected = this->connect(this->ui->le_CommandLineInput, SIGNAL(returnPressed()), this->ui->comp_TextMessages, SLOT(commandEntered())); Q_ASSERT(connected); - this->connect(this->ui->comp_TextMessages, SIGNAL(displayOverlayInfo(BlackMisc::CStatusMessage)), this, SLOT(displayOverlayInfo(BlackMisc::CStatusMessage))); - Q_ASSERT(connected); + this->connect(this->ui->comp_TextMessages, &CTextMessageComponent::displayInInfoWindow, this->m_compInfoWindow, &CInfoWindowComponent::display); this->ui->comp_TextMessages->setSelcalCallback(std::bind(&CCockpitV1Component::getSelcalCode, this->ui->comp_Cockpit)); // voice diff --git a/samples/blackgui/mainwindow_voice.cpp b/samples/blackgui/mainwindow_voice.cpp index e1fa84dcb..ac1f721e6 100644 --- a/samples/blackgui/mainwindow_voice.cpp +++ b/samples/blackgui/mainwindow_voice.cpp @@ -140,7 +140,7 @@ void MainWindow::audioVolumes() this->ui->lbl_StatusVoiceStatus->setPixmap(muted ? this->m_resPixmapVoiceMuted : this->m_resPixmapVoiceHigh); this->ui->comp_Cockpit->setCockpitVoiceStatusPixmap(muted ? this->m_resPixmapVoiceMuted : this->m_resPixmapVoiceHigh); this->ui->pb_SoundMute->setStyleSheet(muted ? "background-color: red;" : ""); - if (muted) this->displayOverlayInfo("Sound is muted!"); + if (muted) this->m_compInfoWindow->displayStringMessage("Sound is muted!"); // update own aircraft, also set volume/mute in voice this->m_ownAircraft.setCom1System(com1); diff --git a/src/blackgui/infowindowcomponent.cpp b/src/blackgui/infowindowcomponent.cpp new file mode 100644 index 000000000..284aa1d29 --- /dev/null +++ b/src/blackgui/infowindowcomponent.cpp @@ -0,0 +1,137 @@ +#include "infowindowcomponent.h" +#include "ui_infowindowcomponent.h" + +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::Network; + +namespace BlackGui +{ + + /* + * Constructor + */ + CInfoWindowComponent::CInfoWindowComponent(QWidget *parent) : + QWizardPage(parent), ui(new Ui::InfoWindow), m_hideTimer(nullptr) + { + ui->setupUi(this); + this->hide(); + this->m_hideTimer = new QTimer(this); + this->m_hideTimer->setSingleShot(true); + connect(this->m_hideTimer, &QTimer::timeout, this, &CInfoWindowComponent::hide); + } + + /* + * Destructor + */ + CInfoWindowComponent::~CInfoWindowComponent() { } + + /* + * Info message for some time + */ + void CInfoWindowComponent::displayStringMessage(const QString &message, int displayTimeMs) + { + if (message.isEmpty()) + { + this->hide(); + return; + } + + // message and display + this->ui->te_StringMessage->setText(message); + this->setCurrentPage(this->ui->pg_StringMessage); + this->showWindow(displayTimeMs); + } + + /* + * Info message for some time + */ + void CInfoWindowComponent::displayTextMessage(const CTextMessage &textMessage, int displayTimeMs) + { + if (textMessage.isEmpty()) + { + this->hide(); + return; + } + + // message and display + this->ui->le_TmFrom->setText(textMessage.getSenderCallsign().asString()); + this->ui->le_TmTo->setText(textMessage.getRecipientCallsign().asString()); + this->ui->le_TmReceived->setText(textMessage.receivedTime()); + this->ui->te_TmText->setText(textMessage.getMessage()); + + this->setCurrentPage(this->ui->pg_TextMessage); + this->showWindow(displayTimeMs); + } + + /* + * Display status message + */ + void CInfoWindowComponent::displayStatusMessage(const CStatusMessage &statusMessage, int displayTimeMs) + { + if (statusMessage.isEmpty()) + { + this->hide(); + return; + } + + this->ui->le_SmSeverity->setText(statusMessage.getSeverityAsString()); + this->ui->le_SmType->setText(statusMessage.getTypeAsString()); + this->ui->te_SmStatusMessage->setText(statusMessage.getMessage()); + this->ui->lbl_SmSeverity->setPixmap(statusMessage.toIcon()); + + this->setCurrentPage(this->ui->pg_StatusMessage); + this->showWindow(displayTimeMs); + } + + /* + * Display + */ + void CInfoWindowComponent::display(const BlackMisc::CVariant &variant, int displayTimeMs) + { + if (variant.isNull()) return; + if (variant.canConvert()) + this->displayTextMessage(variant.value(), displayTimeMs); + else if (variant.canConvert()) + this->displayStatusMessage(variant.value(), displayTimeMs); + else + this->displayStringMessage(variant.toString(), displayTimeMs); + } + + /* + * Init this window + */ + void CInfoWindowComponent::initWindow() + { + // center + const QRect parent = this->parentWidget()->geometry(); + const QRect myself = this->rect(); + int dx = (parent.width() - myself.width()) / 2; + int dy = (parent.height() - myself.height()) / 2; + dy -= 80; // some offset, in order to display further on top + this->move(dx, dy); + this->show(); + } + + /* + * Show window + */ + void CInfoWindowComponent::showWindow(int displayTimeMs) + { + this->initWindow(); + + // hide after some time + this->m_hideTimer->start(displayTimeMs); + } + + /* + * Set current widget + */ + void CInfoWindowComponent::setCurrentPage(QWidget *widget) + { + this->ui->sw_DifferentModes->setCurrentWidget(widget); + } + +} // namespace diff --git a/src/blackgui/infowindowcomponent.h b/src/blackgui/infowindowcomponent.h new file mode 100644 index 000000000..cbeecca5d --- /dev/null +++ b/src/blackgui/infowindowcomponent.h @@ -0,0 +1,66 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKGUI_INFOWINDOW_H +#define BLACKGUI_INFOWINDOW_H + +#include "blackmisc/nwtextmessage.h" +#include "blackmisc/statusmessage.h" +#include "blackmisc/variant.h" + +#include +#include + +namespace Ui { class InfoWindow; } + +namespace BlackGui +{ + + /*! + * Multi purpose info window (pop up window) + */ + class CInfoWindowComponent : public QWizardPage + { + Q_OBJECT + + public: + const static int DefaultDisplayTimeMs = 4000; //!< Display n milliseconds + + //! Constructor + explicit CInfoWindowComponent(QWidget *parent = nullptr); + + //! Destructor + ~CInfoWindowComponent(); + + public slots: + + //! Info message, pure string + void displayStringMessage(const QString &message, int displayTimeMs = DefaultDisplayTimeMs); + + //! Info message, based on text message + void displayTextMessage(const BlackMisc::Network::CTextMessage &textMessage, int displayTimeMs = DefaultDisplayTimeMs); + + //! Info message, based on status message + void displayStatusMessage(const BlackMisc::CStatusMessage &statusMessage, int displayTimeMs = DefaultDisplayTimeMs); + + //! Display any of the specialized types + void display(const BlackMisc::CVariant &variant, int displayTimeMs = DefaultDisplayTimeMs); + + private: + QScopedPointer ui; //!< user interface + QTimer *m_hideTimer; + + //! Init the window + void initWindow(); + + //! Show window, hide after some time + void showWindow(int displayTimeMs); + + //! Current page + void setCurrentPage(QWidget *widget); + }; +} + +#endif // guard diff --git a/src/blackgui/infowindowcomponent.ui b/src/blackgui/infowindowcomponent.ui new file mode 100644 index 000000000..05ba9e283 --- /dev/null +++ b/src/blackgui/infowindowcomponent.ui @@ -0,0 +1,206 @@ + + + InfoWindow + + + + 0 + 0 + 278 + 143 + + + + WizardPage + + + QWidget { + font-family: arial-rounded; + font: bold 10px; + color: black; /** font **/ +} + +QPushButton { + background-color: transparent; + border-style: solid; + border-width: 0px; + border-radius:3px; + border-color: green; + max-height:20px; +} + +QTextEdit { + background-color: rgba(255, 255, 0, 240); /* transparent yellow */ + border-style: solid; + border-width:1px; + border-radius:6px; + border-color: green; + opacity: 0.5; +} + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 2 + + + + + + + true + + + + + + + + + + + + + To + + + + + + + Received + + + + + + + + + + From + + + + + + + true + + + + + + + true + + + + + + + + + + + + + + + + + + Severity + + + + + + + Type + + + + + + + true + + + + + + + + + + + + + + + + + + + + 0 + 0 + + + + + 20 + 20 + + + + + + + + :/blackgui/icons/close.png:/blackgui/icons/close.png + + + + + + + + + + + pb_Close + clicked() + InfoWindow + hide() + + + 272 + 52 + + + 302 + 67 + + + + + diff --git a/src/blackgui/textmessagecomponent.cpp b/src/blackgui/textmessagecomponent.cpp index 009d664c9..4c5cca444 100644 --- a/src/blackgui/textmessagecomponent.cpp +++ b/src/blackgui/textmessagecomponent.cpp @@ -81,7 +81,7 @@ namespace BlackGui } else { - emit this->displayOverlayInfo(CStatusMessage::getInfoMessage("SELCAL received", CStatusMessage::TypeGui)); + emit this->displayInInfoWindow(CStatusMessage::getInfoMessage("SELCAL received", CStatusMessage::TypeGui).toCVariant(), 3 * 1000); } } continue; // not displayed @@ -127,7 +127,7 @@ namespace BlackGui { // if the channel is selected, do nothing if (!this->isCorrespondingTextMessageTabSelected(message)) - emit this->displayOverlayInfo(message.asStatusMessage(true, true, "\t")); + emit this->displayInInfoWindow(message.toCVariant(), 5 * 1000); } } } diff --git a/src/blackgui/textmessagecomponent.h b/src/blackgui/textmessagecomponent.h index 49a67743a..43ae4ad10 100644 --- a/src/blackgui/textmessagecomponent.h +++ b/src/blackgui/textmessagecomponent.h @@ -38,8 +38,8 @@ namespace BlackGui void setSelcalCallback(const std::function &selcalCallback) { this->m_selcalCallback = selcalCallback; } signals: - //! Invisible text message - void displayOverlayInfo(const BlackMisc::CStatusMessage &message) const; + //! Message to be displayed in info window + void displayInInfoWindow(const BlackMisc::CVariant &message, int displayDurationMs) const; public slots: //! Command entered @@ -110,7 +110,6 @@ namespace BlackGui //! Clear text edit void clearTextEdit(); - }; } diff --git a/src/blackmisc/valueobject.h b/src/blackmisc/valueobject.h index 177f2b7c9..8d8e29436 100644 --- a/src/blackmisc/valueobject.h +++ b/src/blackmisc/valueobject.h @@ -4,6 +4,7 @@ #include "dbus.h" #include "tuple.h" #include "json.h" +#include "variant.h" #include #include #include @@ -36,7 +37,7 @@ namespace BlackMisc public: //! True if and only if T is derived from CPhysicalQuantity. - static const bool value = sizeof(test(*(T*)0)) == sizeof(yes); + static const bool value = sizeof(test(*(T *)0)) == sizeof(yes); }; } @@ -101,7 +102,7 @@ namespace BlackMisc friend bool operator!=(const CValueObject &valueObject, const CIndexVariantMap &valueMap); //! Comparison operator to allow valueobjects be used as keys in QMap and std::set. - template friend typename std::enable_if::value && ! PhysicalQuantities::IsQuantity::value, bool>::type + template friend typename std::enable_if < std::is_base_of::value &&! PhysicalQuantities::IsQuantity::value, bool >::type operator<(const T &lhs, const T &rhs) { const auto &lhsBase = static_cast(lhs); @@ -110,7 +111,7 @@ namespace BlackMisc } //! Comparison for symmetry with operator<. - template friend typename std::enable_if::value && ! PhysicalQuantities::IsQuantity::value, bool>::type + template friend typename std::enable_if < std::is_base_of::value &&! PhysicalQuantities::IsQuantity::value, bool >::type operator>(const T &lhs, const T &rhs) { const auto &lhsBase = static_cast(lhs); @@ -119,7 +120,7 @@ namespace BlackMisc } //! Comparison for symmetry with operator<. - template friend typename std::enable_if::value && ! PhysicalQuantities::IsQuantity::value, bool>::type + template friend typename std::enable_if < std::is_base_of::value &&! PhysicalQuantities::IsQuantity::value, bool >::type operator<=(const T &lhs, const T &rhs) { const auto &lhsBase = static_cast(lhs); @@ -128,7 +129,7 @@ namespace BlackMisc } //! Comparison for symmetry with operator<. - template friend typename std::enable_if::value && ! PhysicalQuantities::IsQuantity::value, bool>::type + template friend typename std::enable_if < std::is_base_of::value &&! PhysicalQuantities::IsQuantity::value, bool >::type operator>=(const T &lhs, const T &rhs) { const auto &lhsBase = static_cast(lhs); @@ -167,6 +168,9 @@ namespace BlackMisc //! Virtual method to return QVariant, used with DBus QVariant lists virtual QVariant toQVariant() const = 0; + //! Virtual method to return CVariant + virtual CVariant toCVariant() const { return CVariant(this->toQVariant()); } + //! Contribute to JSON object virtual QJsonObject toJson() const { QJsonObject json; return json;}