refs #841, UI to set text message settings and added this UI to textmessage component

This commit is contained in:
Klaus Basan
2016-12-23 01:05:35 +01:00
committed by Mathew Sutcliffe
parent b2e53d64f1
commit 062f0671ea
6 changed files with 236 additions and 20 deletions

View File

@@ -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

View File

@@ -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 <QScopedPointer>
#include <QFrame>
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::CSettingsTextMessageInlineComponent> ui;
BlackMisc::CSetting<BlackGui::Settings::TextMessageSettings> m_settings { this, &CSettingsTextMessageInlineComponent::settingsChanged }; //!< settings changed
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CSettingsTextMessageInlineComponent</class>
<widget class="QFrame" name="CSettingsTextMessageInlineComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>338</width>
<height>26</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<layout class="QHBoxLayout" name="hl_TextMessageSettings">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QLabel" name="lbl_Overlay">
<property name="toolTip">
<string>Overlay</string>
</property>
<property name="text">
<string>Ovl.:</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_Private">
<property name="text">
<string>private</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_Supervisor">
<property name="toolTip">
<string>supervisor</string>
</property>
<property name="text">
<string>super.</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_Selcal">
<property name="text">
<string>SELCAL</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_Frequency">
<property name="toolTip">
<string>frequency</string>
</property>
<property name="text">
<string>freq.</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_All">
<property name="text">
<string>all</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -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());

View File

@@ -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 <QFrame>
@@ -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::CTextMessageComponent> ui;
BlackMisc::CIdentifier m_identifier;
BlackMisc::CSettingReadOnly<BlackGui::Settings::TextMessageSettings> 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;

View File

@@ -230,6 +230,9 @@
</widget>
</widget>
</item>
<item>
<widget class="BlackGui::Components::CSettingsTextMessageInlineComponent" name="comp_Settings"/>
</item>
<item>
<widget class="QLineEdit" name="le_textMessages">
<property name="toolTip">
@@ -250,7 +253,21 @@
<extends>QTextEdit</extends>
<header>blackgui/textmessagetextedit.h</header>
</customwidget>
<customwidget>
<class>BlackGui::Components::CSettingsTextMessageInlineComponent</class>
<extends>QFrame</extends>
<header>blackgui/components/settingstextmessageinlinecomponent.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>tw_TextMessages</tabstop>
<tabstop>le_textMessages</tabstop>
<tabstop>tvp_TextMessagesAll</tabstop>
<tabstop>tep_TextMessagesUnicom</tabstop>
<tabstop>tep_TextMessagesCOM1</tabstop>
<tabstop>tep_TextMessagesCOM2</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>