swift
settingstextmessageinlinecomponent.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <QCheckBox>
7 #include <QPointer>
8 #include <QPushButton>
9 #include <QTimer>
10 
11 #include "ui_settingstextmessageinlinecomponent.h"
12 
13 #include "misc/logmessage.h"
14 #include "misc/statusmessage.h"
15 
16 using namespace swift::gui::settings;
17 using namespace swift::misc;
18 
19 namespace swift::gui::components
20 {
21  CSettingsTextMessageInlineComponent::CSettingsTextMessageInlineComponent(QWidget *parent)
22  : QFrame(parent), ui(new Ui::CSettingsTextMessageInlineComponent)
23  {
24  ui->setupUi(this);
25  connect(ui->cb_All, &QCheckBox::released, this, &CSettingsTextMessageInlineComponent::changeSettings);
26  connect(ui->cb_Frequency, &QCheckBox::released, this, &CSettingsTextMessageInlineComponent::changeSettings);
27  connect(ui->cb_Private, &QCheckBox::released, this, &CSettingsTextMessageInlineComponent::changeSettings);
28  connect(ui->cb_Supervisor, &QCheckBox::released, this, &CSettingsTextMessageInlineComponent::changeSettings);
29  connect(ui->cb_Focus, &QCheckBox::released, this, &CSettingsTextMessageInlineComponent::changeSettings);
30  connect(ui->pb_Disable, &QPushButton::released, this,
31  &CSettingsTextMessageInlineComponent::disableAllOverlayMessages);
32  connect(ui->pb_Reset, &QPushButton::released, this, &CSettingsTextMessageInlineComponent::resetOverlayMessages);
33 
34  this->settingsChanged();
35  }
36 
38 
39  void CSettingsTextMessageInlineComponent::settingsChanged()
40  {
41  const CTextMessageSettings s(m_settings.get());
42  ui->cb_All->setChecked(s.getPopupAllMessages());
43  ui->cb_Supervisor->setChecked(s.getPopupSupervisorMessages());
44  ui->cb_Frequency->setChecked(s.getPopupFrequencyMessages());
45  ui->cb_Private->setChecked(s.getPopupPrivateMessages());
46  ui->cb_Selcal->setChecked(s.getPopupSelcalMessages());
47  ui->cb_Focus->setChecked(s.focusOverlayWindow());
48  }
49 
50  void CSettingsTextMessageInlineComponent::changeSettings()
51  {
52  CTextMessageSettings s(m_settings.get());
53  s.setPopupAllMessages(ui->cb_All->isChecked());
54  s.setPopupFrequencyMessages(ui->cb_Frequency->isChecked());
55  s.setPopupPrivateMessages(ui->cb_Private->isChecked());
56  s.setSupervisorMessages(ui->cb_Supervisor->isChecked());
57  s.setPopupSelcalMessages(ui->cb_Selcal->isChecked());
58  s.setFocusOverlayWindows(ui->cb_Focus->isChecked());
59  const CStatusMessage m = m_settings.setAndSave(s);
60  CLogMessage::preformatted(m);
61  }
62 
63  void CSettingsTextMessageInlineComponent::disableAllOverlayMessages()
64  {
65  CTextMessageSettings s(m_settings.get());
66  s.disableAllPopups();
67  const CStatusMessage m = m_settings.setAndSave(s);
68  CLogMessage::preformatted(m);
69 
70  QPointer<CSettingsTextMessageInlineComponent> myself(this);
71  QTimer::singleShot(500, this, [=] {
72  if (myself) { myself->settingsChanged(); }
73  });
74  }
75 
76  void CSettingsTextMessageInlineComponent::resetOverlayMessages()
77  {
79  const CStatusMessage m = m_settings.setAndSave(s);
80  CLogMessage::preformatted(m);
81 
82  QPointer<CSettingsTextMessageInlineComponent> myself(this);
83  QTimer::singleShot(500, this, [=] {
84  if (myself) { myself->settingsChanged(); }
85  });
86  }
87 } // namespace swift::gui::components
CStatusMessage setAndSave(const T &value, qint64 timestamp=0)
Write and save in the same step. Must be called from the thread in which the owner lives.
Definition: valuecache.h:417
T get() const
Get a copy of the current value.
Definition: valuecache.h:408
Streamable status message, e.g.
High level reusable GUI components.
Definition: aboutdialog.cpp:13
Free functions in swift::misc.
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...
Definition: threadutils.h:30