swift
overlaymessages.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_GUI_OVERLAYMESSAGES_H
7 #define SWIFT_GUI_OVERLAYMESSAGES_H
8 
9 #include <chrono>
10 #include <functional>
11 
12 #include <QFrame>
13 #include <QMessageBox>
14 #include <QObject>
15 #include <QScopedPointer>
16 #include <QString>
17 #include <QTimer>
18 
21 #include "gui/swiftguiexport.h"
22 #include "misc/aviation/callsign.h"
23 #include "misc/pixmap.h"
24 #include "misc/statusmessage.h"
25 #include "misc/statusmessagelist.h"
26 #include "misc/variant.h"
27 
28 class QKeyEvent;
29 class QPaintEvent;
30 class QPixmap;
31 
32 namespace Ui
33 {
34  class COverlayMessages;
35 }
36 namespace swift::misc::network
37 {
38  class CTextMessage;
39 }
40 namespace swift::gui
41 {
45  class SWIFT_GUI_EXPORT COverlayMessages : public QFrame
46  {
47  Q_OBJECT
48 
49  public:
51  explicit COverlayMessages(int w, int h, QWidget *parent);
52 
54  virtual ~COverlayMessages() override;
55 
57  void setModeToMessages();
58 
60  void setModeToMessage();
61 
63  void setModeToMessageSmall();
64 
66  void setModeToHTMLMessage();
67 
69  void setModeToProgressBar();
70 
72  void setModeToTextMessage();
73 
75  void setModeToOverlayTextMessage();
76 
78  void activateTextMessages(bool activate);
79 
81  bool isTextMessagesActivated() const;
82 
84  void setModeToImage();
85 
87  void setForceSmall(bool force) { m_forceSmall = force; }
88 
90  void setHeaderText(const QString &header);
91 
93  void setConfirmationMessage(const QString &message);
94 
96  void showOverlayMessagesWithConfirmation(const swift::misc::CStatusMessageList &messages,
97  bool appendOldMessages, const QString &confirmationMessage,
98  std::function<void()> okLambda,
99  QMessageBox::StandardButton defaultButton = QMessageBox::Cancel,
100  std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
101 
103  void clearOverlayMessages();
104 
106  void showOverlayMessages(const swift::misc::CStatusMessageList &messages, bool appendOldMessages = false,
107  std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
108 
110  void showOverlayMessagesOrSingleMessage(const swift::misc::CStatusMessageList &messages,
111  bool appendOldMessages = false,
112  std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
113 
115  void showOverlayMessagesOrHTMLMessage(const swift::misc::CStatusMessageList &messages,
116  bool appendOldMessages = false,
117  std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
118 
120  void sortOverlayMessages(const swift::misc::CPropertyIndex &propertyIndex,
121  Qt::SortOrder order = Qt::AscendingOrder);
122 
124  void setOverlayMessagesSorting(const swift::misc::CPropertyIndex &propertyIndex,
125  Qt::SortOrder order = Qt::AscendingOrder);
126 
128  void showOverlayMessage(const swift::misc::CStatusMessage &message,
129  std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
130 
132  void showOverlayTextMessage(const swift::misc::network::CTextMessage &textMessage,
133  std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
134 
136  void showOverlayInlineTextMessage(components::TextMessageTab tab);
137 
139  void showOverlayInlineTextMessage(const swift::misc::aviation::CCallsign &callsign);
140 
142  void showOverlayImage(const swift::misc::CPixmap &image,
143  std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
144 
146  void showOverlayImage(const QPixmap &image, std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
147 
149  void showOverlayVariant(const swift::misc::CVariant &variant,
150  std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
151 
153  void showHTMLMessage(const swift::misc::CStatusMessage &message,
154  std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
155 
157  void showHTMLMessage(const QString &htmlMessage,
158  std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
159 
161  void showDownloadProgress(int progress, qint64 current, qint64 max, const QUrl &url,
162  std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
163 
165  void showProgressBar(int percentage, const QString &message,
166  std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
167 
169  void close();
170 
172  void setDefaultConfirmationButton(int button = QMessageBox::Cancel);
173 
175  bool hasPendingConfirmation() const;
176 
178  void setReducedInfo(bool reduced);
179 
181  void addShadow(QColor color = Qt::gray);
182 
183  signals:
186 
187  protected:
189  void display(std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
190 
192  virtual void keyPressEvent(QKeyEvent *event) override;
193 
194  private:
195  QScopedPointer<Ui::COverlayMessages> ui;
197  QString m_header;
198  int m_lastConfirmation = QMessageBox::Cancel;
199  bool m_awaitingConfirmation = false;
200  bool m_hasKillButton = false;
201  bool m_forceSmall = false;
202  QTimer m_autoCloseTimer { this };
203  std::function<void()> m_okLambda;
204  QList<std::function<void()>> m_pendingMessageCalls;
205 
207  void onStyleSheetsChanged();
208 
210  void onOkClicked();
211 
213  void onCancelClicked();
214 
216  void init(int w, int h);
217 
219  void setHeader(const QString &header);
220 
222  bool useSmall() const;
223 
225  bool displayTextMessage(const swift::misc::network::CTextMessage &textMessage) const;
226  };
227 } // namespace swift::gui
228 
229 #endif // SWIFT_GUI_OVERLAYMESSAGES_H
Display status messages (nested in the parent widget)
void setForceSmall(bool force)
Force small (smaller layout)
void setHeaderText(const QString &header)
Set header text.
void confirmationCompleted()
Confirmation completed.
Pixmap which can be transferred via DBus.
Definition: pixmap.h:28
Class template for accessing a specific value in the CSettingsCache.
Streamable status message, e.g.
Status messages, e.g. from Core -> GUI.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition: variant.h:66
Value object encapsulating information of a callsign.
Definition: callsign.h:30
Value object encapsulating information of a text message.
Definition: textmessage.h:31
GUI related classes.
#define SWIFT_GUI_EXPORT
Export a class or function from the library.