Settings for text messages, ascending or descending (latest first/last)

This commit is contained in:
Klaus Basan
2019-09-02 23:01:06 +02:00
parent cb56b80518
commit e73682d2c6
7 changed files with 77 additions and 20 deletions

View File

@@ -33,7 +33,7 @@ namespace BlackGui
explicit CSettingsTextMessageStyle(QWidget *parent = nullptr);
//! Destructor
virtual ~CSettingsTextMessageStyle();
virtual ~CSettingsTextMessageStyle() override;
//! Fmily, size and style
QStringList getFamilySizeStyle() const;
@@ -59,7 +59,7 @@ namespace BlackGui
private:
QScopedPointer<Ui::CSettingsTextMessageStyle> ui;
CSettingsFontDialog *m_fontSettingsDialog = nullptr;
CTextEditDialog *m_textEditDialog = nullptr;
CTextEditDialog *m_textEditDialog = nullptr;
QString m_style;
//! Change font

View File

@@ -2,6 +2,14 @@
<ui version="4.0">
<class>CSettingsTextMessageStyle</class>
<widget class="QFrame" name="CSettingsTextMessageStyle">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>440</width>
<height>26</height>
</rect>
</property>
<property name="windowTitle">
<string>Text message style</string>
</property>

View File

@@ -81,6 +81,9 @@ namespace BlackGui
c = connect(ui->comp_AtcStations, &CAtcButtonComponent::requestAtcStation, this, &CTextMessageComponent::onAtcButtonClicked, Qt::QueuedConnection);
Q_ASSERT_X(c, Q_FUNC_INFO, "Missing connect");
c = connect(ui->cb_LatestFirst, &QCheckBox::toggled, this, &CTextMessageComponent::onLatestFirstChanged, Qt::QueuedConnection);
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");
@@ -106,10 +109,12 @@ namespace BlackGui
{
// init decoupled when sub components are fully init
if (!myself || !sGui || sGui->isShuttingDown()) { return; }
this->onSettingsChanged();
this->onSettingsChanged(); // init
this->showCurrentFrequenciesFromCockpit();
const bool latestFirst = m_messageSettings.get().isLatestFirst();
ui->tvp_TextMessagesAll->setSorting(CTextMessage::IndexUtcTimestamp, latestFirst ? Qt::DescendingOrder : Qt::AscendingOrder);
// hde for the beginning
// hide for the beginning
ui->gb_Settings->setChecked(false);
ui->gb_MessageTo->setChecked(false);
});
@@ -239,7 +244,8 @@ namespace BlackGui
// message for me? right frequency? otherwise quit
if (this->hasAllMessagesTab() && (relevantForMe || message.isServerMessage()))
{
ui->tvp_TextMessagesAll->insert(message);
ui->tvp_TextMessagesAll->push_back(message); // no sorting
ui->tvp_TextMessagesAll->resort();
}
if (!relevantForMe) { continue; }
@@ -270,6 +276,7 @@ namespace BlackGui
{
ui->comp_SettingsOverlay->setVisible(checked);
ui->comp_SettingsStyle->setVisible(checked);
ui->cb_LatestFirst->setVisible(checked);
ui->gb_Settings->setFlat(!checked);
}
@@ -284,17 +291,30 @@ namespace BlackGui
{
QList<CTextMessageTextEdit *> textEdits = this->findAllTextEdit();
const QString style = this->getStyleSheet();
const bool latestFirst = m_messageSettings.get().isLatestFirst();
for (CTextMessageTextEdit *textEdit : textEdits)
{
textEdit->setLatestFirst(latestFirst);
textEdit->setStyleSheetForContent(style);
}
ui->comp_SettingsStyle->setStyle(this->getStyleSheet());
if (latestFirst != ui->cb_LatestFirst->isChecked()) { ui->cb_LatestFirst->setChecked(latestFirst); }
this->update(); // refresh window
}
void CTextMessageComponent::onLatestFirstChanged(bool checked)
{
CTextMessageSettings s = m_messageSettings.get();
if (s.isLatestFirst() == checked) { return; }
s.setLatestFirst(checked);
const CStatusMessage m = m_messageSettings.setAndSave(s);
CLogMessage::preformatted(m);
this->onSettingsChanged(); // latest first
}
void CTextMessageComponent::onStyleSheetChanged()
{
this->onSettingsChanged();
this->onSettingsChanged(); // style sheet
}
void CTextMessageComponent::onAtcButtonClicked(const CAtcStation &station)
@@ -308,6 +328,7 @@ namespace BlackGui
const QString style = ui->comp_SettingsStyle->getStyle();
CTextMessageSettings s = m_messageSettings.get();
s.setStyleSheet(style);
s.setLatestFirst(ui->cb_LatestFirst->isChecked());
const CStatusMessage m = m_messageSettings.setAndSave(s);
CLogMessage::preformatted(m);
this->onStyleSheetChanged();

View File

@@ -199,6 +199,9 @@ namespace BlackGui
//! Settings have been changed
void onSettingsChanged();
//! Latest 1st checked
void onLatestFirstChanged(bool checked);
//! Style sheet has been changed
void onStyleSheetChanged();

View File

@@ -2,6 +2,14 @@
<ui version="4.0">
<class>CTextMessageComponent</class>
<widget class="QFrame" name="CTextMessageComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>260</width>
<height>367</height>
</rect>
</property>
<property name="windowTitle">
<string>Text messages</string>
</property>
@@ -249,10 +257,7 @@
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="vl_Settings">
<property name="spacing">
<number>1</number>
</property>
<layout class="QGridLayout" name="gl_Settings">
<property name="leftMargin">
<number>1</number>
</property>
@@ -265,8 +270,8 @@
<property name="bottomMargin">
<number>1</number>
</property>
<item alignment="Qt::AlignRight">
<widget class="BlackGui::Components::CSettingsTextMessageInlineComponent" name="comp_SettingsOverlay">
<item row="1" column="1">
<widget class="BlackGui::Components::CSettingsTextMessageStyle" name="comp_SettingsStyle">
<property name="minimumSize">
<size>
<width>200</width>
@@ -275,8 +280,15 @@
</property>
</widget>
</item>
<item alignment="Qt::AlignRight">
<widget class="BlackGui::Components::CSettingsTextMessageStyle" name="comp_SettingsStyle">
<item row="1" column="0" alignment="Qt::AlignRight">
<widget class="QCheckBox" name="cb_LatestFirst">
<property name="text">
<string>latest 1st</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="BlackGui::Components::CSettingsTextMessageInlineComponent" name="comp_SettingsOverlay">
<property name="minimumSize">
<size>
<width>200</width>

View File

@@ -74,12 +74,13 @@ namespace BlackGui
QString CTextMessageSettings::convertToQString(bool i18n) const
{
Q_UNUSED(i18n);
return QStringLiteral("Private: %1 supervisor: %2 frequency: %3 all: %4 focus: %5").arg(
return QStringLiteral("Private: %1 supervisor: %2 frequency: %3 all: %4 focus: %5 latest 1st: %6").arg(
boolToOnOff(this->getPopupPrivateMessages()),
boolToOnOff(this->getPopupSupervisorMessages()),
boolToOnOff(this->getPopupFrequencyMessages()),
boolToOnOff(this->getPopupAllMessages()),
boolToYesNo(this->focusOverlayWindow())
boolToYesNo(this->focusOverlayWindow()),
boolToYesNo(this->isLatestFirst())
);
}
@@ -94,8 +95,9 @@ namespace BlackGui
case IndexPopupPrivateMessages: return CVariant::fromValue(this->popupPrivateMessages());
case IndexPopupSupervisorMessages: return CVariant::fromValue(this->popupSupervisorMessages());
case IndexPopupSelcalMessages: return CVariant::fromValue(this->popupSelcalMessages());
case IndexStyle: return CVariant::fromValue(this->getStyleSheet());
case IndexFocus: return CVariant::fromValue(this->focusOverlayWindow());
case IndexStyle: return CVariant::fromValue(this->getStyleSheet());
case IndexLatestFirst: return CVariant::fromValue(this->isLatestFirst());
case IndexFocus: return CVariant::fromValue(this->focusOverlayWindow());
default: return CValueObject::propertyByIndex(index);
}
}
@@ -111,8 +113,9 @@ namespace BlackGui
case IndexPopupSupervisorMessages: this->setSupervisorMessages(variant.toBool()); break;
case IndexPopupPrivateMessages: this->setPopupPrivateMessages(variant.toBool()); break;
case IndexPopupSelcalMessages: this->setPopupSelcalMessages(variant.toBool()); break;
case IndexFocus: this->setFocusOverlayWindows(variant.toBool()); break;
case IndexStyle: this->setStyleSheet(variant.toQString()); break;
case IndexFocus: this->setFocusOverlayWindows(variant.toBool()); break;
case IndexLatestFirst: this->setLatestFirst(variant.toBool()); break;
case IndexStyle: this->setStyleSheet(variant.toQString()); break;
default: CValueObject::setPropertyByIndex(index, variant); break;
}
}

View File

@@ -38,6 +38,7 @@ namespace BlackGui
IndexPopupAllMessages,
IndexPopupSelcalMessages,
IndexFocus,
IndexLatestFirst,
IndexStyle
};
@@ -95,6 +96,12 @@ namespace BlackGui
//! Popup the given message? Complete check including frequencies.
bool popup(const BlackMisc::Network::CTextMessage &textMessage, const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft) const;
//! Latest messages 1st?
bool isLatestFirst() const { return m_latestFirst; }
//! Latest messages 1st?
void setLatestFirst(bool latestFirst) { m_latestFirst = latestFirst; }
//! CSS style sheet
const QString &getStyleSheet() const { return m_styleSheet; }
@@ -126,6 +133,7 @@ namespace BlackGui
bool m_popupAllMessages = false;
bool m_popupSelcalMessages = true;
bool m_focus = true;
bool m_latestFirst = false; //!< latest messages first
QString m_styleSheet;
BLACK_METACLASS(
@@ -135,6 +143,8 @@ namespace BlackGui
BLACK_METAMEMBER(popupFrequencyMessages),
BLACK_METAMEMBER(popupAllMessages),
BLACK_METAMEMBER(popupSelcalMessages),
BLACK_METAMEMBER(focus),
BLACK_METAMEMBER(latestFirst),
BLACK_METAMEMBER(styleSheet)
);
};