mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 23:45:35 +08:00
Ref T369, adjusted text message component to support settings
This commit is contained in:
@@ -7,32 +7,31 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackcore/application.h"
|
||||
#include "blackcore/context/contextaudio.h"
|
||||
#include "blackcore/context/contextnetwork.h"
|
||||
#include "blackcore/context/contextownaircraft.h"
|
||||
#include "blackcore/corefacade.h"
|
||||
#include "ui_textmessagecomponent.h"
|
||||
#include "blackgui/components/textmessagecomponent.h"
|
||||
#include "blackgui/views/textmessageview.h"
|
||||
#include "blackgui/dockwidgetinfoarea.h"
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "blackgui/textmessagetextedit.h"
|
||||
#include "blackgui/views/textmessageview.h"
|
||||
#include "blackgui/views/viewbase.h"
|
||||
#include "blackmisc/verify.h"
|
||||
#include "blackcore/context/contextaudio.h"
|
||||
#include "blackcore/context/contextnetwork.h"
|
||||
#include "blackcore/context/contextownaircraft.h"
|
||||
#include "blackcore/application.h"
|
||||
#include "blackcore/corefacade.h"
|
||||
#include "blackmisc/audio/notificationsounds.h"
|
||||
#include "blackmisc/network/textmessage.h"
|
||||
#include "blackmisc/network/user.h"
|
||||
#include "blackmisc/aviation/atcstation.h"
|
||||
#include "blackmisc/aviation/callsign.h"
|
||||
#include "blackmisc/aviation/comsystem.h"
|
||||
#include "blackmisc/compare.h"
|
||||
#include "blackmisc/iterator.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/network/textmessage.h"
|
||||
#include "blackmisc/network/user.h"
|
||||
#include "blackmisc/pq/constants.h"
|
||||
#include "blackmisc/pq/frequency.h"
|
||||
#include "blackmisc/pq/units.h"
|
||||
#include "blackmisc/compare.h"
|
||||
#include "blackmisc/iterator.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/sequence.h"
|
||||
#include "ui_textmessagecomponent.h"
|
||||
#include "blackmisc/verify.h"
|
||||
|
||||
#include <QLayout>
|
||||
#include <QLineEdit>
|
||||
@@ -72,15 +71,32 @@ namespace BlackGui
|
||||
// le_textMessages is the own line edit
|
||||
bool c = connect(ui->le_textMessages, &QLineEdit::returnPressed, this, &CTextMessageComponent::textMessageEntered);
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Missing connect");
|
||||
c = connect(ui->gb_Settings, &QGroupBox::toggled, this, &CTextMessageComponent::onSettingsChecked);
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Missing connect");
|
||||
c = connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CTextMessageComponent::onChangedAircraftCockpit);
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Missing connect");
|
||||
|
||||
// style sheet
|
||||
c = connect(sGui, &CGuiApplication::styleSheetsChanged, this, &CTextMessageComponent::onStyleSheetChanged, Qt::QueuedConnection);
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Missing connect");
|
||||
c = connect(ui->comp_SettingsStyle, &CSettingsTextMessageStyle::changed, this, &CTextMessageComponent::updateSettings, Qt::QueuedConnection);
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Missing connect");
|
||||
|
||||
if (sGui && sGui->getCoreFacade())
|
||||
{
|
||||
c = connect(this, &CTextMessageComponent::commandEntered, sGui->getCoreFacade(), &CCoreFacade::parseCommandLine);
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Missing connect");
|
||||
}
|
||||
Q_UNUSED(c);
|
||||
|
||||
// init by settings
|
||||
QPointer<CTextMessageComponent> myself(this);
|
||||
QTimer::singleShot(250, this, [ = ]
|
||||
{
|
||||
// init decoupled when sub components are fully init
|
||||
if (!myself) { return; }
|
||||
this->onSettingsChanged();
|
||||
});
|
||||
}
|
||||
|
||||
CTextMessageComponent::~CTextMessageComponent()
|
||||
@@ -98,9 +114,9 @@ namespace BlackGui
|
||||
{
|
||||
switch (tab)
|
||||
{
|
||||
case TextMessagesAll: return ui->tb_TextMessagesAll;
|
||||
case TextMessagesCom1: return ui->tb_TextMessagesCOM1;
|
||||
case TextMessagesCom2: return ui->tb_TextMessagesCOM2;
|
||||
case TextMessagesAll: return ui->tb_TextMessagesAll;
|
||||
case TextMessagesCom1: return ui->tb_TextMessagesCOM1;
|
||||
case TextMessagesCom2: return ui->tb_TextMessagesCOM2;
|
||||
case TextMessagesUnicom: return ui->tb_TextMessagesUnicom;
|
||||
default:
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong index");
|
||||
@@ -109,9 +125,16 @@ namespace BlackGui
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CTextMessageTextEdit *CTextMessageComponent::getTextEdit(CTextMessageComponent::Tab tab) const
|
||||
{
|
||||
QWidget *w = this->getTabWidget(tab);
|
||||
if (!w) { return nullptr; }
|
||||
return this->findChild<CTextMessageTextEdit *>();
|
||||
}
|
||||
|
||||
void CTextMessageComponent::selectTabWidget(CTextMessageComponent::Tab tab)
|
||||
{
|
||||
QWidget *w = getTabWidget(tab);
|
||||
QWidget *w = this->getTabWidget(tab);
|
||||
if (w)
|
||||
{
|
||||
ui->tw_TextMessages->setCurrentWidget(w);
|
||||
@@ -191,8 +214,8 @@ namespace BlackGui
|
||||
emit this->displayInInfoWindow(CVariant::from(message), 5 * 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // message
|
||||
} // for
|
||||
}
|
||||
|
||||
void CTextMessageComponent::onChangedAircraftCockpit()
|
||||
@@ -200,6 +223,55 @@ namespace BlackGui
|
||||
this->showCurrentFrequenciesFromCockpit();
|
||||
}
|
||||
|
||||
void CTextMessageComponent::onSettingsChecked(bool checked)
|
||||
{
|
||||
ui->comp_SettingsOverlay->setVisible(checked);
|
||||
ui->comp_SettingsStyle->setVisible(checked);
|
||||
ui->gb_Settings->setFlat(!checked);
|
||||
}
|
||||
|
||||
void CTextMessageComponent::onSettingsChanged()
|
||||
{
|
||||
QList<CTextMessageTextEdit *> textEdits = this->findAllTextEdit();
|
||||
const QString style = this->getStyleSheet();
|
||||
for (CTextMessageTextEdit *textEdit : textEdits)
|
||||
{
|
||||
if (textEdit->hasTextDocument())
|
||||
{
|
||||
textEdit->setStyleSheetForContent(style);
|
||||
}
|
||||
}
|
||||
ui->comp_SettingsStyle->setStyle(this->getStyleSheet());
|
||||
}
|
||||
|
||||
void CTextMessageComponent::onStyleSheetChanged()
|
||||
{
|
||||
this->onSettingsChanged();
|
||||
}
|
||||
|
||||
void CTextMessageComponent::updateSettings()
|
||||
{
|
||||
const QString style = ui->comp_SettingsStyle->getStyle();
|
||||
CTextMessageSettings s = m_messageSettings.get();
|
||||
s.setStyleSheet(style);
|
||||
const CStatusMessage m = m_messageSettings.setAndSave(s);
|
||||
CLogMessage::preformatted(m);
|
||||
this->onStyleSheetChanged();
|
||||
}
|
||||
|
||||
QList<CTextMessageTextEdit *> CTextMessageComponent::findAllTextEdit() const
|
||||
{
|
||||
return this->findChildren<CTextMessageTextEdit *>();
|
||||
}
|
||||
|
||||
QString CTextMessageComponent::getStyleSheet() const
|
||||
{
|
||||
const QString styleSheet = m_messageSettings.get().getStyleSheet();
|
||||
return styleSheet.isEmpty() && sGui ?
|
||||
sGui->getStyleSheetUtility().style(CStyleSheetUtility::fileNameTextMessage()) :
|
||||
styleSheet;
|
||||
}
|
||||
|
||||
bool CTextMessageComponent::isCorrespondingTextMessageTabSelected(CTextMessage textMessage) const
|
||||
{
|
||||
if (!this->isVisibleWidget()) { return false; }
|
||||
@@ -233,7 +305,7 @@ namespace BlackGui
|
||||
|
||||
bool CTextMessageComponent::isNetworkConnected() const
|
||||
{
|
||||
return sGui->getIContextNetwork() && sGui->getIContextNetwork()->isConnected() ;
|
||||
return sGui && sGui->getIContextNetwork() && sGui->getIContextNetwork()->isConnected();
|
||||
}
|
||||
|
||||
void CTextMessageComponent::showCurrentFrequenciesFromCockpit()
|
||||
@@ -253,7 +325,7 @@ namespace BlackGui
|
||||
QWidget *CTextMessageComponent::addNewTextMessageTab(const CCallsign &callsign)
|
||||
{
|
||||
Q_ASSERT(!callsign.isEmpty());
|
||||
return addNewTextMessageTab(callsign.asString());
|
||||
return this->addNewTextMessageTab(callsign.asString());
|
||||
}
|
||||
|
||||
QWidget *CTextMessageComponent::addNewTextMessageTab(const QString &tabName)
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#ifndef BLACKGUI_COMPONENTS_TEXTMESSAGECOMPONENT_H
|
||||
#define BLACKGUI_COMPONENTS_TEXTMESSAGECOMPONENT_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackgui/settings/textmessagesettings.h"
|
||||
#include "blackgui/components/enablefordockwidgetinfoarea.h"
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/simulation/simulatedaircraft.h"
|
||||
#include "blackmisc/identifier.h"
|
||||
#include "blackmisc/variant.h"
|
||||
@@ -28,6 +28,8 @@ namespace Ui { class CTextMessageComponent; }
|
||||
namespace BlackGui
|
||||
{
|
||||
class CDockWidgetInfoArea;
|
||||
class CTextMessageTextEdit;
|
||||
|
||||
namespace Components
|
||||
{
|
||||
//! Text message widget
|
||||
@@ -56,14 +58,6 @@ namespace BlackGui
|
||||
//! \copydoc CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea
|
||||
virtual bool setParentDockWidgetInfoArea(CDockWidgetInfoArea *parentDockableWidget) override;
|
||||
|
||||
signals:
|
||||
//! Message to be displayed in info window
|
||||
void displayInInfoWindow(const BlackMisc::CVariant &message, int displayDurationMs) const;
|
||||
|
||||
//! Command line was entered
|
||||
void commandEntered(const QString commandLine, const BlackMisc::CIdentifier &originator);
|
||||
|
||||
public slots:
|
||||
//! Text messages received
|
||||
void onTextMessageReceived(const BlackMisc::Network::CTextMessageList &messages);
|
||||
|
||||
@@ -77,14 +71,24 @@ namespace BlackGui
|
||||
//! Display the tab for given callsign
|
||||
void showCorrespondingTab(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
|
||||
signals:
|
||||
//! Message to be displayed in info window
|
||||
void displayInInfoWindow(const BlackMisc::CVariant &message, int displayDurationMs) const;
|
||||
|
||||
//! Command line was entered
|
||||
void commandEntered(const QString commandLine, const BlackMisc::CIdentifier &originator);
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::CTextMessageComponent> ui;
|
||||
BlackMisc::CIdentifier m_identifier { "TextMessageComponent", this };
|
||||
BlackMisc::CSettingReadOnly<Settings::TextMessageSettings> m_messageSettings { this };
|
||||
BlackMisc::CSetting<Settings::TextMessageSettings> m_messageSettings { this, &CTextMessageComponent::onSettingsChanged };
|
||||
|
||||
//! Enum to widget
|
||||
QWidget *getTabWidget(Tab tab) const;
|
||||
|
||||
//! Related text edit
|
||||
CTextMessageTextEdit *getTextEdit(Tab tab) const;
|
||||
|
||||
//! Select given tab
|
||||
void selectTabWidget(Tab tab);
|
||||
|
||||
@@ -131,6 +135,24 @@ namespace BlackGui
|
||||
//! Cockpit values changed, used to updated some components
|
||||
void onChangedAircraftCockpit();
|
||||
|
||||
//! Settings have been checked (group box visible/invisible)
|
||||
void onSettingsChecked(bool checked);
|
||||
|
||||
//! Settings have been changed
|
||||
void onSettingsChanged();
|
||||
|
||||
//! Style sheet has been changed
|
||||
void onStyleSheetChanged();
|
||||
|
||||
//! Update settings
|
||||
void updateSettings();
|
||||
|
||||
//! Get all CTextMessageTextEdit child objects
|
||||
QList<CTextMessageTextEdit *> findAllTextEdit() const;
|
||||
|
||||
//! Global or settings stylesheet
|
||||
QString getStyleSheet() const;
|
||||
|
||||
//! Close text message tab
|
||||
void closeTextMessageTab();
|
||||
|
||||
|
||||
@@ -6,25 +6,16 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>260</width>
|
||||
<height>297</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Text messages</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="vl_TextMessages">
|
||||
<property name="spacing">
|
||||
<number>1</number>
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
@@ -36,7 +27,7 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
<number>5</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tw_TextMessages">
|
||||
@@ -231,13 +222,46 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="BlackGui::Components::CSettingsTextMessageInlineComponent" name="comp_Settings"/>
|
||||
<widget class="QGroupBox" name="gb_Settings">
|
||||
<property name="title">
|
||||
<string>Settings</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="vl_Settings">
|
||||
<property name="spacing">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="BlackGui::Components::CSettingsTextMessageInlineComponent" name="comp_SettingsOverlay"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="BlackGui::Components::CSettingsTextMessageStyle" name="comp_SettingsStyle"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="BlackGui::CLineEditHistory" name="le_textMessages">
|
||||
<property name="toolTip">
|
||||
<string>command line (e.g. ".com1", ".x", ".msg com1")</string>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>text message text goes here</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -264,14 +288,21 @@
|
||||
<extends>QLineEdit</extends>
|
||||
<header>blackgui/lineedithistory.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::Components::CSettingsTextMessageStyle</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>blackgui/components/settingstextmessagestyle.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>gb_Settings</tabstop>
|
||||
<tabstop>le_textMessages</tabstop>
|
||||
<tabstop>tep_TextMessagesCOM1</tabstop>
|
||||
<tabstop>tep_TextMessagesCOM2</tabstop>
|
||||
<tabstop>tep_TextMessagesUnicom</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "blackgui/stylesheetutility.h"
|
||||
#include "blackgui/textmessagetextedit.h"
|
||||
#include "blackmisc/aviation/callsign.h"
|
||||
#include "blackmisc/network/textmessage.h"
|
||||
@@ -20,6 +19,7 @@
|
||||
#include <QTextOption>
|
||||
#include <Qt>
|
||||
#include <QtGlobal>
|
||||
#include <QStringBuilder>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Network;
|
||||
@@ -55,10 +55,6 @@ namespace BlackGui
|
||||
connect(m_actionWordWrap, &QAction::triggered, this, &CTextMessageTextEdit::setWordWrap);
|
||||
|
||||
connect(this, &QTextEdit::customContextMenuRequested, this, &CTextMessageTextEdit::showContextMenuForTextEdit);
|
||||
|
||||
// style sheet
|
||||
connect(sGui, &CGuiApplication::styleSheetsChanged, this, &CTextMessageTextEdit::onStyleSheetChanged, Qt::QueuedConnection);
|
||||
onStyleSheetChanged();
|
||||
}
|
||||
|
||||
CTextMessageTextEdit::~CTextMessageTextEdit()
|
||||
@@ -75,7 +71,7 @@ namespace BlackGui
|
||||
{
|
||||
m_messages.push_front(textMessage);
|
||||
}
|
||||
QString html(toHtml(m_messages, m_withSender, m_withRecipient));
|
||||
const QString html(toHtml(m_messages, m_withSender, m_withRecipient));
|
||||
m_textDocument->setHtml(html);
|
||||
}
|
||||
|
||||
@@ -90,9 +86,18 @@ namespace BlackGui
|
||||
QTextEdit::clear();
|
||||
}
|
||||
|
||||
void CTextMessageTextEdit::redrawHtml()
|
||||
{
|
||||
Q_ASSERT_X(m_textDocument, Q_FUNC_INFO, "Missing text document");
|
||||
const QString html(toHtml(m_messages, m_withSender, m_withRecipient));
|
||||
m_textDocument->setHtml(html);
|
||||
}
|
||||
|
||||
void CTextMessageTextEdit::setStyleSheetForContent(const QString &styleSheet)
|
||||
{
|
||||
Q_ASSERT_X(m_textDocument, Q_FUNC_INFO, "Missing text document");
|
||||
m_textDocument->setDefaultStyleSheet(styleSheet);
|
||||
this->redrawHtml();
|
||||
}
|
||||
|
||||
QString CTextMessageTextEdit::toHtml(const CTextMessageList &messages, bool withFrom, bool withTo)
|
||||
@@ -172,13 +177,6 @@ namespace BlackGui
|
||||
menu->exec(this->mapToGlobal(pt));
|
||||
}
|
||||
|
||||
void CTextMessageTextEdit::onStyleSheetChanged()
|
||||
{
|
||||
Q_ASSERT(m_textDocument);
|
||||
QString style(sGui->getStyleSheetUtility().style(CStyleSheetUtility::fileNameTextMessage()));
|
||||
m_textDocument->setDefaultStyleSheet(style);
|
||||
}
|
||||
|
||||
void CTextMessageTextEdit::keepLastNMessages()
|
||||
{
|
||||
QObject *sender = QObject::sender();
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
class QAction;
|
||||
class QPoint;
|
||||
class QTextDocument;
|
||||
class QWidget;
|
||||
|
||||
namespace BlackMisc { namespace Network { class CTextMessage; } }
|
||||
namespace BlackGui
|
||||
@@ -46,17 +45,22 @@ namespace BlackGui
|
||||
//! Number of displayed messages
|
||||
int count() const;
|
||||
|
||||
public slots:
|
||||
//! Stylesheet for content
|
||||
void setStyleSheetForContent(const QString &styleSheet);
|
||||
|
||||
//! Clear
|
||||
void clear();
|
||||
|
||||
//! Has text document
|
||||
bool hasTextDocument() const { return m_textDocument; }
|
||||
|
||||
//! Redraw HTML
|
||||
void redrawHtml();
|
||||
|
||||
private:
|
||||
//! Context menu
|
||||
void showContextMenuForTextEdit(const QPoint &pt);
|
||||
|
||||
//! Stylesheet has been changed
|
||||
void onStyleSheetChanged();
|
||||
|
||||
//! Keep last n messages
|
||||
void keepLastNMessages();
|
||||
|
||||
@@ -69,9 +73,6 @@ namespace BlackGui
|
||||
//! Convert to HTML
|
||||
static QString toHtml(const BlackMisc::Network::CTextMessage &message, bool withFrom, bool withTo);
|
||||
|
||||
//! Stylesheet for content
|
||||
void setStyleSheetForContent(const QString &styleSheet);
|
||||
|
||||
//! Word wrap
|
||||
void setWordWrap(bool wordWrap);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user