Ref T369, adjusted text message component to support settings

This commit is contained in:
Klaus Basan
2018-09-23 03:37:53 +02:00
parent fec4643fc1
commit 6962a7bddb
5 changed files with 193 additions and 69 deletions

View File

@@ -7,32 +7,31 @@
* contained in the LICENSE file. * contained in the LICENSE file.
*/ */
#include "blackcore/application.h" #include "ui_textmessagecomponent.h"
#include "blackcore/context/contextaudio.h"
#include "blackcore/context/contextnetwork.h"
#include "blackcore/context/contextownaircraft.h"
#include "blackcore/corefacade.h"
#include "blackgui/components/textmessagecomponent.h" #include "blackgui/components/textmessagecomponent.h"
#include "blackgui/views/textmessageview.h"
#include "blackgui/dockwidgetinfoarea.h" #include "blackgui/dockwidgetinfoarea.h"
#include "blackgui/guiapplication.h" #include "blackgui/guiapplication.h"
#include "blackgui/textmessagetextedit.h" #include "blackgui/textmessagetextedit.h"
#include "blackgui/views/textmessageview.h" #include "blackcore/context/contextaudio.h"
#include "blackgui/views/viewbase.h" #include "blackcore/context/contextnetwork.h"
#include "blackmisc/verify.h" #include "blackcore/context/contextownaircraft.h"
#include "blackcore/application.h"
#include "blackcore/corefacade.h"
#include "blackmisc/audio/notificationsounds.h" #include "blackmisc/audio/notificationsounds.h"
#include "blackmisc/network/textmessage.h"
#include "blackmisc/network/user.h"
#include "blackmisc/aviation/atcstation.h" #include "blackmisc/aviation/atcstation.h"
#include "blackmisc/aviation/callsign.h" #include "blackmisc/aviation/callsign.h"
#include "blackmisc/aviation/comsystem.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/constants.h"
#include "blackmisc/pq/frequency.h" #include "blackmisc/pq/frequency.h"
#include "blackmisc/pq/units.h" #include "blackmisc/pq/units.h"
#include "blackmisc/compare.h"
#include "blackmisc/iterator.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/sequence.h" #include "blackmisc/sequence.h"
#include "ui_textmessagecomponent.h" #include "blackmisc/verify.h"
#include <QLayout> #include <QLayout>
#include <QLineEdit> #include <QLineEdit>
@@ -72,15 +71,32 @@ namespace BlackGui
// le_textMessages is the own line edit // le_textMessages is the own line edit
bool c = connect(ui->le_textMessages, &QLineEdit::returnPressed, this, &CTextMessageComponent::textMessageEntered); bool c = connect(ui->le_textMessages, &QLineEdit::returnPressed, this, &CTextMessageComponent::textMessageEntered);
Q_ASSERT_X(c, Q_FUNC_INFO, "Missing connect"); 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); c = connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CTextMessageComponent::onChangedAircraftCockpit);
Q_ASSERT_X(c, Q_FUNC_INFO, "Missing connect"); 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()) if (sGui && sGui->getCoreFacade())
{ {
c = connect(this, &CTextMessageComponent::commandEntered, sGui->getCoreFacade(), &CCoreFacade::parseCommandLine); c = connect(this, &CTextMessageComponent::commandEntered, sGui->getCoreFacade(), &CCoreFacade::parseCommandLine);
Q_ASSERT_X(c, Q_FUNC_INFO, "Missing connect"); Q_ASSERT_X(c, Q_FUNC_INFO, "Missing connect");
} }
Q_UNUSED(c); 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() CTextMessageComponent::~CTextMessageComponent()
@@ -98,9 +114,9 @@ namespace BlackGui
{ {
switch (tab) switch (tab)
{ {
case TextMessagesAll: return ui->tb_TextMessagesAll; case TextMessagesAll: return ui->tb_TextMessagesAll;
case TextMessagesCom1: return ui->tb_TextMessagesCOM1; case TextMessagesCom1: return ui->tb_TextMessagesCOM1;
case TextMessagesCom2: return ui->tb_TextMessagesCOM2; case TextMessagesCom2: return ui->tb_TextMessagesCOM2;
case TextMessagesUnicom: return ui->tb_TextMessagesUnicom; case TextMessagesUnicom: return ui->tb_TextMessagesUnicom;
default: default:
Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong index"); Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong index");
@@ -109,9 +125,16 @@ namespace BlackGui
return nullptr; 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) void CTextMessageComponent::selectTabWidget(CTextMessageComponent::Tab tab)
{ {
QWidget *w = getTabWidget(tab); QWidget *w = this->getTabWidget(tab);
if (w) if (w)
{ {
ui->tw_TextMessages->setCurrentWidget(w); ui->tw_TextMessages->setCurrentWidget(w);
@@ -191,8 +214,8 @@ namespace BlackGui
emit this->displayInInfoWindow(CVariant::from(message), 5 * 1000); emit this->displayInInfoWindow(CVariant::from(message), 5 * 1000);
} }
} }
} } // message
} } // for
} }
void CTextMessageComponent::onChangedAircraftCockpit() void CTextMessageComponent::onChangedAircraftCockpit()
@@ -200,6 +223,55 @@ namespace BlackGui
this->showCurrentFrequenciesFromCockpit(); 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 bool CTextMessageComponent::isCorrespondingTextMessageTabSelected(CTextMessage textMessage) const
{ {
if (!this->isVisibleWidget()) { return false; } if (!this->isVisibleWidget()) { return false; }
@@ -233,7 +305,7 @@ namespace BlackGui
bool CTextMessageComponent::isNetworkConnected() const bool CTextMessageComponent::isNetworkConnected() const
{ {
return sGui->getIContextNetwork() && sGui->getIContextNetwork()->isConnected() ; return sGui && sGui->getIContextNetwork() && sGui->getIContextNetwork()->isConnected();
} }
void CTextMessageComponent::showCurrentFrequenciesFromCockpit() void CTextMessageComponent::showCurrentFrequenciesFromCockpit()
@@ -253,7 +325,7 @@ namespace BlackGui
QWidget *CTextMessageComponent::addNewTextMessageTab(const CCallsign &callsign) QWidget *CTextMessageComponent::addNewTextMessageTab(const CCallsign &callsign)
{ {
Q_ASSERT(!callsign.isEmpty()); Q_ASSERT(!callsign.isEmpty());
return addNewTextMessageTab(callsign.asString()); return this->addNewTextMessageTab(callsign.asString());
} }
QWidget *CTextMessageComponent::addNewTextMessageTab(const QString &tabName) QWidget *CTextMessageComponent::addNewTextMessageTab(const QString &tabName)

View File

@@ -12,9 +12,9 @@
#ifndef BLACKGUI_COMPONENTS_TEXTMESSAGECOMPONENT_H #ifndef BLACKGUI_COMPONENTS_TEXTMESSAGECOMPONENT_H
#define BLACKGUI_COMPONENTS_TEXTMESSAGECOMPONENT_H #define BLACKGUI_COMPONENTS_TEXTMESSAGECOMPONENT_H
#include "blackgui/blackguiexport.h"
#include "blackgui/settings/textmessagesettings.h" #include "blackgui/settings/textmessagesettings.h"
#include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackgui/components/enablefordockwidgetinfoarea.h"
#include "blackgui/blackguiexport.h"
#include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/identifier.h" #include "blackmisc/identifier.h"
#include "blackmisc/variant.h" #include "blackmisc/variant.h"
@@ -28,6 +28,8 @@ namespace Ui { class CTextMessageComponent; }
namespace BlackGui namespace BlackGui
{ {
class CDockWidgetInfoArea; class CDockWidgetInfoArea;
class CTextMessageTextEdit;
namespace Components namespace Components
{ {
//! Text message widget //! Text message widget
@@ -56,14 +58,6 @@ namespace BlackGui
//! \copydoc CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea //! \copydoc CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea
virtual bool setParentDockWidgetInfoArea(CDockWidgetInfoArea *parentDockableWidget) override; 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 //! Text messages received
void onTextMessageReceived(const BlackMisc::Network::CTextMessageList &messages); void onTextMessageReceived(const BlackMisc::Network::CTextMessageList &messages);
@@ -77,14 +71,24 @@ namespace BlackGui
//! Display the tab for given callsign //! Display the tab for given callsign
void showCorrespondingTab(const BlackMisc::Aviation::CCallsign &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: private:
QScopedPointer<Ui::CTextMessageComponent> ui; QScopedPointer<Ui::CTextMessageComponent> ui;
BlackMisc::CIdentifier m_identifier { "TextMessageComponent", this }; 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 //! Enum to widget
QWidget *getTabWidget(Tab tab) const; QWidget *getTabWidget(Tab tab) const;
//! Related text edit
CTextMessageTextEdit *getTextEdit(Tab tab) const;
//! Select given tab //! Select given tab
void selectTabWidget(Tab tab); void selectTabWidget(Tab tab);
@@ -131,6 +135,24 @@ namespace BlackGui
//! Cockpit values changed, used to updated some components //! Cockpit values changed, used to updated some components
void onChangedAircraftCockpit(); 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 //! Close text message tab
void closeTextMessageTab(); void closeTextMessageTab();

View File

@@ -6,25 +6,16 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>260</width>
<height>300</height> <height>297</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Text messages</string> <string>Text messages</string>
</property> </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"> <layout class="QVBoxLayout" name="vl_TextMessages">
<property name="spacing"> <property name="spacing">
<number>1</number> <number>5</number>
</property> </property>
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
@@ -36,7 +27,7 @@
<number>0</number> <number>0</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>5</number>
</property> </property>
<item> <item>
<widget class="QTabWidget" name="tw_TextMessages"> <widget class="QTabWidget" name="tw_TextMessages">
@@ -231,13 +222,46 @@
</widget> </widget>
</item> </item>
<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>
<item> <item>
<widget class="BlackGui::CLineEditHistory" name="le_textMessages"> <widget class="BlackGui::CLineEditHistory" name="le_textMessages">
<property name="toolTip"> <property name="toolTip">
<string>command line (e.g. &quot;.com1&quot;, &quot;.x&quot;, &quot;.msg com1&quot;)</string> <string>command line (e.g. &quot;.com1&quot;, &quot;.x&quot;, &quot;.msg com1&quot;)</string>
</property> </property>
<property name="placeholderText">
<string>text message text goes here</string>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@@ -264,14 +288,21 @@
<extends>QLineEdit</extends> <extends>QLineEdit</extends>
<header>blackgui/lineedithistory.h</header> <header>blackgui/lineedithistory.h</header>
</customwidget> </customwidget>
<customwidget>
<class>BlackGui::Components::CSettingsTextMessageStyle</class>
<extends>QFrame</extends>
<header>blackgui/components/settingstextmessagestyle.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>tw_TextMessages</tabstop> <tabstop>tw_TextMessages</tabstop>
<tabstop>le_textMessages</tabstop>
<tabstop>tvp_TextMessagesAll</tabstop> <tabstop>tvp_TextMessagesAll</tabstop>
<tabstop>tep_TextMessagesUnicom</tabstop> <tabstop>gb_Settings</tabstop>
<tabstop>le_textMessages</tabstop>
<tabstop>tep_TextMessagesCOM1</tabstop> <tabstop>tep_TextMessagesCOM1</tabstop>
<tabstop>tep_TextMessagesCOM2</tabstop> <tabstop>tep_TextMessagesCOM2</tabstop>
<tabstop>tep_TextMessagesUnicom</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections/> <connections/>

View File

@@ -8,7 +8,6 @@
*/ */
#include "blackgui/guiapplication.h" #include "blackgui/guiapplication.h"
#include "blackgui/stylesheetutility.h"
#include "blackgui/textmessagetextedit.h" #include "blackgui/textmessagetextedit.h"
#include "blackmisc/aviation/callsign.h" #include "blackmisc/aviation/callsign.h"
#include "blackmisc/network/textmessage.h" #include "blackmisc/network/textmessage.h"
@@ -20,6 +19,7 @@
#include <QTextOption> #include <QTextOption>
#include <Qt> #include <Qt>
#include <QtGlobal> #include <QtGlobal>
#include <QStringBuilder>
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMisc::Network; using namespace BlackMisc::Network;
@@ -55,10 +55,6 @@ namespace BlackGui
connect(m_actionWordWrap, &QAction::triggered, this, &CTextMessageTextEdit::setWordWrap); connect(m_actionWordWrap, &QAction::triggered, this, &CTextMessageTextEdit::setWordWrap);
connect(this, &QTextEdit::customContextMenuRequested, this, &CTextMessageTextEdit::showContextMenuForTextEdit); connect(this, &QTextEdit::customContextMenuRequested, this, &CTextMessageTextEdit::showContextMenuForTextEdit);
// style sheet
connect(sGui, &CGuiApplication::styleSheetsChanged, this, &CTextMessageTextEdit::onStyleSheetChanged, Qt::QueuedConnection);
onStyleSheetChanged();
} }
CTextMessageTextEdit::~CTextMessageTextEdit() CTextMessageTextEdit::~CTextMessageTextEdit()
@@ -75,7 +71,7 @@ namespace BlackGui
{ {
m_messages.push_front(textMessage); 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); m_textDocument->setHtml(html);
} }
@@ -90,9 +86,18 @@ namespace BlackGui
QTextEdit::clear(); 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) void CTextMessageTextEdit::setStyleSheetForContent(const QString &styleSheet)
{ {
Q_ASSERT_X(m_textDocument, Q_FUNC_INFO, "Missing text document");
m_textDocument->setDefaultStyleSheet(styleSheet); m_textDocument->setDefaultStyleSheet(styleSheet);
this->redrawHtml();
} }
QString CTextMessageTextEdit::toHtml(const CTextMessageList &messages, bool withFrom, bool withTo) QString CTextMessageTextEdit::toHtml(const CTextMessageList &messages, bool withFrom, bool withTo)
@@ -172,13 +177,6 @@ namespace BlackGui
menu->exec(this->mapToGlobal(pt)); 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() void CTextMessageTextEdit::keepLastNMessages()
{ {
QObject *sender = QObject::sender(); QObject *sender = QObject::sender();

View File

@@ -22,7 +22,6 @@
class QAction; class QAction;
class QPoint; class QPoint;
class QTextDocument; class QTextDocument;
class QWidget;
namespace BlackMisc { namespace Network { class CTextMessage; } } namespace BlackMisc { namespace Network { class CTextMessage; } }
namespace BlackGui namespace BlackGui
@@ -46,17 +45,22 @@ namespace BlackGui
//! Number of displayed messages //! Number of displayed messages
int count() const; int count() const;
public slots: //! Stylesheet for content
void setStyleSheetForContent(const QString &styleSheet);
//! Clear //! Clear
void clear(); void clear();
//! Has text document
bool hasTextDocument() const { return m_textDocument; }
//! Redraw HTML
void redrawHtml();
private: private:
//! Context menu //! Context menu
void showContextMenuForTextEdit(const QPoint &pt); void showContextMenuForTextEdit(const QPoint &pt);
//! Stylesheet has been changed
void onStyleSheetChanged();
//! Keep last n messages //! Keep last n messages
void keepLastNMessages(); void keepLastNMessages();
@@ -69,9 +73,6 @@ namespace BlackGui
//! Convert to HTML //! Convert to HTML
static QString toHtml(const BlackMisc::Network::CTextMessage &message, bool withFrom, bool withTo); static QString toHtml(const BlackMisc::Network::CTextMessage &message, bool withFrom, bool withTo);
//! Stylesheet for content
void setStyleSheetForContent(const QString &styleSheet);
//! Word wrap //! Word wrap
void setWordWrap(bool wordWrap); void setWordWrap(bool wordWrap);