diff --git a/src/blackgui/components/settingstextmessageinlinecomponent.cpp b/src/blackgui/components/settingstextmessageinlinecomponent.cpp new file mode 100644 index 000000000..25844363f --- /dev/null +++ b/src/blackgui/components/settingstextmessageinlinecomponent.cpp @@ -0,0 +1,59 @@ +/* Copyright (C) 2016 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackmisc/logmessage.h" +#include "blackmisc/statusmessage.h" +#include "settingstextmessageinlinecomponent.h" +#include "ui_settingstextmessageinlinecomponent.h" + +using namespace BlackGui::Settings; +using namespace BlackMisc; + +namespace BlackGui +{ + namespace Components + { + CSettingsTextMessageInlineComponent::CSettingsTextMessageInlineComponent(QWidget *parent) : + QFrame(parent), + ui(new Ui::CSettingsTextMessageInlineComponent) + { + ui->setupUi(this); + connect(ui->cb_All, &QCheckBox::released, this, &CSettingsTextMessageInlineComponent::changeSettings); + connect(ui->cb_Frequency, &QCheckBox::released, this, &CSettingsTextMessageInlineComponent::changeSettings); + connect(ui->cb_Private, &QCheckBox::released, this, &CSettingsTextMessageInlineComponent::changeSettings); + connect(ui->cb_Supervisor, &QCheckBox::released, this, &CSettingsTextMessageInlineComponent::changeSettings); + settingsChanged(); + } + + CSettingsTextMessageInlineComponent::~CSettingsTextMessageInlineComponent() + { } + + void CSettingsTextMessageInlineComponent::settingsChanged() + { + const CTextMessageSettings s(m_settings.get()); + ui->cb_All->setChecked(s.getPopupAllMessages()); + ui->cb_Supervisor->setChecked(s.getPopupSupervisorMessages()); + ui->cb_Frequency->setChecked(s.getPopupFrequencyMessages()); + ui->cb_Private->setChecked(s.getPopupPrivateMessages()); + ui->cb_Selcal->setChecked(s.getPopupSelcalMessages()); + } + + void CSettingsTextMessageInlineComponent::changeSettings() + { + CTextMessageSettings s(m_settings.get()); + s.setPopupAllMessages(ui->cb_All->isChecked()); + s.setPopupFrequencyMessages(ui->cb_Frequency->isChecked()); + s.setPopupPrivateMessages(ui->cb_Private->isChecked()); + s.setSupervisorMessages(ui->cb_Supervisor->isChecked()); + s.setPopupSelcalMessages(ui->cb_Selcal->isChecked()); + const CStatusMessage m = m_settings.setAndSave(s); + CLogMessage::preformatted(m); + } + } // ns +} // ns diff --git a/src/blackgui/components/settingstextmessageinlinecomponent.h b/src/blackgui/components/settingstextmessageinlinecomponent.h new file mode 100644 index 000000000..c23ba9dff --- /dev/null +++ b/src/blackgui/components/settingstextmessageinlinecomponent.h @@ -0,0 +1,52 @@ +/* Copyright (C) 2016 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_COMPONENTS_SETTINGSTEXTMESSAGEINLINECOMPONENT_H +#define BLACKGUI_COMPONENTS_SETTINGSTEXTMESSAGEINLINECOMPONENT_H + + +#include "blackgui/settings/textmessagesettings.h" +#include +#include + +namespace Ui { class CSettingsTextMessageInlineComponent; } +namespace BlackGui +{ + namespace Components + { + /*! + * Settings for text messages + */ + class CSettingsTextMessageInlineComponent : public QFrame + { + Q_OBJECT + + public: + //! Constructor + explicit CSettingsTextMessageInlineComponent(QWidget *parent = nullptr); + + //! Destructor + virtual ~CSettingsTextMessageInlineComponent(); + + private: + //! Settings have been changed + void settingsChanged(); + + //! Change the settings + void changeSettings(); + + QScopedPointer ui; + BlackMisc::CSetting m_settings { this, &CSettingsTextMessageInlineComponent::settingsChanged }; //!< settings changed + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/settingstextmessageinlinecomponent.ui b/src/blackgui/components/settingstextmessageinlinecomponent.ui new file mode 100644 index 000000000..59aa22997 --- /dev/null +++ b/src/blackgui/components/settingstextmessageinlinecomponent.ui @@ -0,0 +1,84 @@ + + + CSettingsTextMessageInlineComponent + + + + 0 + 0 + 338 + 26 + + + + Frame + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + Overlay + + + Ovl.: + + + + + + + private + + + + + + + supervisor + + + super. + + + + + + + SELCAL + + + + + + + frequency + + + freq. + + + + + + + all + + + + + + + + diff --git a/src/blackgui/components/textmessagecomponent.cpp b/src/blackgui/components/textmessagecomponent.cpp index ed5146a86..7a4b5aa3e 100644 --- a/src/blackgui/components/textmessagecomponent.cpp +++ b/src/blackgui/components/textmessagecomponent.cpp @@ -47,6 +47,7 @@ using namespace BlackCore; using namespace BlackCore::Context; using namespace BlackMisc; using namespace BlackGui; +using namespace BlackGui::Settings; using namespace BlackGui::Views; using namespace BlackMisc::Network; using namespace BlackMisc::Audio; @@ -118,19 +119,23 @@ namespace BlackGui void CTextMessageComponent::displayTextMessage(const CTextMessageList &messages) { if (messages.isEmpty()) return; + const CSimulatedAircraft ownAircraft(this->getOwnAircraft()); + const CTextMessageSettings msgSettings(this->m_messageSettings.getThreadLocal()); + for (const CTextMessage &message : messages) { bool relevantForMe = false; // SELCAL - if (message.isSelcalMessage() && getOwnAircraft().isSelcalSelected(message.getSelcalCode())) + if (message.isSelcalMessage() && ownAircraft.isSelcalSelected(message.getSelcalCode())) { // this is SELCAL for me if (sGui->getIContextAudio()) { sGui->getIContextAudio()->playSelcalTone(message.getSelcalCode()); } - else + + if (msgSettings.popupSelcalMessages()) { emit this->displayInInfoWindow(CLogMessage(this).info("SELCAL received"), 3 * 1000); } @@ -148,12 +153,12 @@ namespace BlackGui if (message.isRadioMessage()) { // check for own COM frequencies - if (message.isSendToFrequency(this->getOwnAircraft().getCom1System().getFrequencyActive())) + if (message.isSendToFrequency(ownAircraft.getCom1System().getFrequencyActive())) { ui->tep_TextMessagesCOM1->insertTextMessage(message); relevantForMe = true; } - if (message.isSendToFrequency(this->getOwnAircraft().getCom2System().getFrequencyActive())) + if (message.isSendToFrequency(ownAircraft.getCom2System().getFrequencyActive())) { ui->tep_TextMessagesCOM2->insertTextMessage(message); relevantForMe = true; @@ -179,7 +184,10 @@ namespace BlackGui // if the channel is selected, do nothing if (!this->isCorrespondingTextMessageTabSelected(message)) { - emit this->displayInInfoWindow(CVariant::from(message), 5 * 1000); + if (msgSettings.popup(message, ownAircraft)) + { + emit this->displayInInfoWindow(CVariant::from(message), 5 * 1000); + } } } } @@ -215,7 +223,7 @@ namespace BlackGui else { // frequency message - const CSimulatedAircraft ownAircraft = this->getOwnAircraft(); + const CSimulatedAircraft ownAircraft(this->getOwnAircraft()); if (ui->tw_TextMessages->currentWidget() == ui->tb_TextMessagesAll) { return true; } if (textMessage.isSendToFrequency(ownAircraft.getCom1System().getFrequencyActive())) { @@ -299,7 +307,7 @@ namespace BlackGui } } - const CSimulatedAircraft CTextMessageComponent::getOwnAircraft() const + CSimulatedAircraft CTextMessageComponent::getOwnAircraft() const { Q_ASSERT(sGui->getIContextOwnAircraft()); return sGui->getIContextOwnAircraft()->getOwnAircraft(); @@ -315,11 +323,12 @@ namespace BlackGui CAtcStation station(sGui->getIContextNetwork()->getOnlineStationForCallsign(callsign)); if (!station.getCallsign().isEmpty()) { - if (this->getOwnAircraft().getCom1System().isActiveFrequencyWithin25kHzChannel(station.getFrequency())) + const CSimulatedAircraft ownAircraft(this->getOwnAircraft()); + if (ownAircraft.getCom1System().isActiveFrequencyWithin25kHzChannel(station.getFrequency())) { return getTabWidget(TextMessagesCom1); } - else if (this->getOwnAircraft().getCom2System().isActiveFrequencyWithin25kHzChannel(station.getFrequency())) + else if (ownAircraft.getCom2System().isActiveFrequencyWithin25kHzChannel(station.getFrequency())) { return getTabWidget(TextMessagesCom2); } @@ -421,9 +430,9 @@ namespace BlackGui else { // not a standard channel - QString selectedTabText = ui->tw_TextMessages->tabText(index).trimmed(); bool isNumber; - double frequency = selectedTabText.toDouble(&isNumber); + const QString selectedTabText = ui->tw_TextMessages->tabText(index).trimmed(); + const double frequency = selectedTabText.toDouble(&isNumber); if (isNumber) { CFrequency radioFrequency = CFrequency(frequency, CFrequencyUnit::MHz()); diff --git a/src/blackgui/components/textmessagecomponent.h b/src/blackgui/components/textmessagecomponent.h index 199de9e09..2206c6001 100644 --- a/src/blackgui/components/textmessagecomponent.h +++ b/src/blackgui/components/textmessagecomponent.h @@ -13,10 +13,10 @@ #define BLACKGUI_COMPONENTS_TEXTMESSAGECOMPONENT_H #include "blackgui/blackguiexport.h" +#include "blackgui/settings/textmessagesettings.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" -#include "blackmisc/identifier.h" -#include "blackmisc/network/textmessagelist.h" #include "blackmisc/simulation/simulatedaircraft.h" +#include "blackmisc/identifier.h" #include "blackmisc/variant.h" #include @@ -26,16 +26,10 @@ class QWidget; -namespace BlackMisc -{ - namespace Aviation { class CCallsign; } - namespace Network { class CTextMessage; } -} namespace Ui { class CTextMessageComponent; } namespace BlackGui { class CDockWidgetInfoArea; - namespace Components { //! Text message widget @@ -87,6 +81,7 @@ namespace BlackGui private: QScopedPointer ui; BlackMisc::CIdentifier m_identifier; + BlackMisc::CSettingReadOnly m_messageSettings { this }; //! Enum to widget QWidget *getTabWidget(Tab tab) const; @@ -111,7 +106,7 @@ namespace BlackGui void addPrivateChannelTextMessage(const BlackMisc::Network::CTextMessage &textMessage); //! Own aircraft - const BlackMisc::Simulation::CSimulatedAircraft getOwnAircraft() const; + BlackMisc::Simulation::CSimulatedAircraft getOwnAircraft() const; //! For this text message's recepient, is the current tab selected? bool isCorrespondingTextMessageTabSelected(BlackMisc::Network::CTextMessage textMessage) const; diff --git a/src/blackgui/components/textmessagecomponent.ui b/src/blackgui/components/textmessagecomponent.ui index 868f626b8..90ef4a64f 100644 --- a/src/blackgui/components/textmessagecomponent.ui +++ b/src/blackgui/components/textmessagecomponent.ui @@ -230,6 +230,9 @@ + + + @@ -250,7 +253,21 @@ QTextEdit
blackgui/textmessagetextedit.h
+ + BlackGui::Components::CSettingsTextMessageInlineComponent + QFrame +
blackgui/components/settingstextmessageinlinecomponent.h
+ 1 +
+ + tw_TextMessages + le_textMessages + tvp_TextMessagesAll + tep_TextMessagesUnicom + tep_TextMessagesCOM1 + tep_TextMessagesCOM2 +