Skip to content

Commit 27a0127

Browse files
committed
feat(demo): add editor banner controls to the notification launcher
Closes #167. Info/Success/Warning/Error buttons in the launcher's "Editor banner" section call addBanner() via the MainWindowInterface now exposed by Application::mainWindow(), tracking the returned Banner* pointers so "Clear all" can remove every stacked banner.
1 parent 63ac123 commit 27a0127

11 files changed

Lines changed: 401 additions & 13 deletions

demo/src/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ int main(int argc, char* argv[])
188188
[&notificationManager, mainWindow, demoBalloonGroupId,
189189
demoStickyBalloonGroupId]() {
190190
demo::NotificationLauncherDialog dialog(
191-
notificationManager, demoBalloonGroupId,
192-
demoStickyBalloonGroupId, mainWindow.get());
191+
notificationManager, *mainWindow,
192+
demoBalloonGroupId, demoStickyBalloonGroupId,
193+
mainWindow.get());
193194
dialog.exec();
194195
});
195196

demo/src/notificationlauncherdialog.cpp

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
#include <QVariant>
1616

1717
#include <aide/aidesettingsprovider.hpp>
18+
#include <aide/gui/widgets/banner.hpp>
1819
#include <aide/gui/widgets/gotittooltip.hpp>
20+
#include <aide/mainwindowinterface.hpp>
1921
#include <aide/notification.hpp>
2022
#include <aide/notificationaction.hpp>
2123
#include <aide/notificationmanagerinterface.hpp>
@@ -29,6 +31,7 @@ using aide::Notification;
2931
using aide::NotificationAction;
3032
using aide::NotificationManagerInterface;
3133
using aide::NotificationType;
34+
using aide::core::MainWindowInterface;
3235
using aide::widgets::GotItPosition;
3336
using aide::widgets::GotItTooltip;
3437
using demo::NotificationLauncherDialog;
@@ -57,10 +60,11 @@ namespace
5760

5861
NotificationLauncherDialog::NotificationLauncherDialog(
5962
NotificationManagerInterface& notificationManager,
60-
HierarchicalId balloonGroupId, HierarchicalId stickyBalloonGroupId,
61-
QWidget* parent)
63+
MainWindowInterface& mainWindow, HierarchicalId balloonGroupId,
64+
HierarchicalId stickyBalloonGroupId, QWidget* parent)
6265
: QDialog(parent)
6366
, m_notificationManager{notificationManager}
67+
, m_mainWindow{mainWindow}
6468
, m_balloonGroupId{std::move(balloonGroupId)}
6569
, m_stickyBalloonGroupId{std::move(stickyBalloonGroupId)}
6670
{
@@ -70,6 +74,7 @@ NotificationLauncherDialog::NotificationLauncherDialog(
7074
mainLayout->addWidget(createBalloonSection());
7175
mainLayout->addWidget(createGotItSection());
7276
mainLayout->addWidget(createDialogBannerSection());
77+
mainLayout->addWidget(createEditorBannerSection());
7378

7479
auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this);
7580
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
@@ -183,6 +188,43 @@ QWidget* NotificationLauncherDialog::createDialogBannerSection()
183188
return group;
184189
}
185190

191+
QWidget* NotificationLauncherDialog::createEditorBannerSection()
192+
{
193+
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
194+
auto* group = new QGroupBox(tr("Editor banner"));
195+
auto* groupLayout = new QVBoxLayout(group);
196+
197+
auto* severityRow = new QHBoxLayout;
198+
199+
const std::array<SeverityButton, 4> severityButtons{{
200+
{NotificationType::Information, tr("Info"), tr("Information"),
201+
tr("This is an informational editor banner.")},
202+
{NotificationType::Success, tr("Success"), tr("Success"),
203+
tr("This is a success editor banner.")},
204+
{NotificationType::Warning, tr("Warning"), tr("Warning"),
205+
tr("This is a warning editor banner.")},
206+
{NotificationType::Error, tr("Error"), tr("Error"),
207+
tr("This is an error editor banner.")},
208+
}};
209+
210+
for (const auto& severityButton : severityButtons) {
211+
auto* button = new QPushButton(severityButton.buttonLabel, group);
212+
connect(button, &QPushButton::clicked, this, [this, severityButton]() {
213+
addEditorBanner(severityButton.type, severityButton.content);
214+
});
215+
severityRow->addWidget(button);
216+
}
217+
218+
auto* clearAllButton = new QPushButton(tr("Clear all"), group);
219+
connect(clearAllButton, &QPushButton::clicked, this,
220+
&NotificationLauncherDialog::clearEditorBanners);
221+
222+
groupLayout->addLayout(severityRow);
223+
groupLayout->addWidget(clearAllButton);
224+
225+
return group;
226+
}
227+
186228
void NotificationLauncherDialog::showGotIt()
187229
{
188230
const auto settings = AideSettingsProvider::unversionableSettings();
@@ -255,3 +297,17 @@ void NotificationLauncherDialog::postStickyBalloon()
255297
tr("This balloon has no auto-dismiss timer; close it manually.");
256298
m_notificationManager.post(std::move(notification));
257299
}
300+
301+
void NotificationLauncherDialog::addEditorBanner(NotificationType type,
302+
const QString& message)
303+
{
304+
m_editorBanners.push_back(m_mainWindow.addBanner(type, message));
305+
}
306+
307+
void NotificationLauncherDialog::clearEditorBanners()
308+
{
309+
for (auto* banner : m_editorBanners) {
310+
m_mainWindow.removeBanner(banner);
311+
}
312+
m_editorBanners.clear();
313+
}

demo/src/notificationlauncherdialog.hpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef DEMO_NOTIFICATION_LAUNCHER_DIALOG_HPP
22
#define DEMO_NOTIFICATION_LAUNCHER_DIALOG_HPP
33

4+
#include <vector>
5+
46
#include <QDialog>
57

68
#include <aide/hierarchicalid.hpp>
@@ -15,18 +17,28 @@ namespace aide
1517
class NotificationManagerInterface;
1618
} // namespace aide
1719

20+
namespace aide::core
21+
{
22+
class MainWindowInterface;
23+
} // namespace aide::core
24+
25+
namespace aide::widgets
26+
{
27+
class Banner;
28+
} // namespace aide::widgets
29+
1830
namespace demo
1931
{
2032
// Shell opened by the demo's "Demo -> Notifications" menu action (#164).
21-
// Owns the "Balloon", "Got it" (#165) and "Dialog banner" (#166)
22-
// sections; the editor banner (#167) section attaches its own QGroupBox
23-
// here as that ticket lands.
33+
// Owns the "Balloon", "Got it" (#165), "Dialog banner" (#166) and
34+
// "Editor banner" (#167) sections.
2435
class NotificationLauncherDialog : public QDialog
2536
{
2637
Q_OBJECT
2738
public:
2839
NotificationLauncherDialog(
2940
aide::NotificationManagerInterface& notificationManager,
41+
aide::core::MainWindowInterface& mainWindow,
3042
aide::HierarchicalId balloonGroupId,
3143
aide::HierarchicalId stickyBalloonGroupId,
3244
QWidget* parent = nullptr);
@@ -35,6 +47,7 @@ namespace demo
3547
[[nodiscard]] QWidget* createBalloonSection();
3648
[[nodiscard]] QWidget* createGotItSection();
3749
[[nodiscard]] QWidget* createDialogBannerSection();
50+
[[nodiscard]] QWidget* createEditorBannerSection();
3851

3952
void postBalloon(aide::NotificationType type, const QString& title,
4053
const QString& content);
@@ -44,12 +57,19 @@ namespace demo
4457
void showGotIt();
4558
static void resetGotItSeenFlag();
4659

60+
void addEditorBanner(aide::NotificationType type,
61+
const QString& message);
62+
void clearEditorBanners();
63+
4764
aide::NotificationManagerInterface& m_notificationManager;
65+
aide::core::MainWindowInterface& m_mainWindow;
4866
aide::HierarchicalId m_balloonGroupId;
4967
aide::HierarchicalId m_stickyBalloonGroupId;
5068

5169
QPushButton* m_gotItAnchorButton{nullptr};
5270
QComboBox* m_gotItPositionCombo{nullptr};
71+
72+
std::vector<aide::widgets::Banner*> m_editorBanners;
5373
};
5474
} // namespace demo
5575

demo/src/res/demo_ar_SA.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,5 +279,29 @@
279279
<source>Open dialog banner demo</source>
280280
<translation type="unfinished"></translation>
281281
</message>
282+
<message>
283+
<source>Editor banner</source>
284+
<translation type="unfinished"></translation>
285+
</message>
286+
<message>
287+
<source>This is an informational editor banner.</source>
288+
<translation type="unfinished"></translation>
289+
</message>
290+
<message>
291+
<source>This is a success editor banner.</source>
292+
<translation type="unfinished"></translation>
293+
</message>
294+
<message>
295+
<source>This is a warning editor banner.</source>
296+
<translation type="unfinished"></translation>
297+
</message>
298+
<message>
299+
<source>This is an error editor banner.</source>
300+
<translation type="unfinished"></translation>
301+
</message>
302+
<message>
303+
<source>Clear all</source>
304+
<translation type="unfinished"></translation>
305+
</message>
282306
</context>
283307
</TS>

demo/src/res/demo_de.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,5 +279,29 @@
279279
<source>Open dialog banner demo</source>
280280
<translation type="unfinished"></translation>
281281
</message>
282+
<message>
283+
<source>Editor banner</source>
284+
<translation type="unfinished"></translation>
285+
</message>
286+
<message>
287+
<source>This is an informational editor banner.</source>
288+
<translation type="unfinished"></translation>
289+
</message>
290+
<message>
291+
<source>This is a success editor banner.</source>
292+
<translation type="unfinished"></translation>
293+
</message>
294+
<message>
295+
<source>This is a warning editor banner.</source>
296+
<translation type="unfinished"></translation>
297+
</message>
298+
<message>
299+
<source>This is an error editor banner.</source>
300+
<translation type="unfinished"></translation>
301+
</message>
302+
<message>
303+
<source>Clear all</source>
304+
<translation type="unfinished"></translation>
305+
</message>
282306
</context>
283307
</TS>

demo/src/res/demo_en.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,5 +277,29 @@
277277
<source>Open dialog banner demo</source>
278278
<translation type="unfinished"></translation>
279279
</message>
280+
<message>
281+
<source>Editor banner</source>
282+
<translation type="unfinished"></translation>
283+
</message>
284+
<message>
285+
<source>This is an informational editor banner.</source>
286+
<translation type="unfinished"></translation>
287+
</message>
288+
<message>
289+
<source>This is a success editor banner.</source>
290+
<translation type="unfinished"></translation>
291+
</message>
292+
<message>
293+
<source>This is a warning editor banner.</source>
294+
<translation type="unfinished"></translation>
295+
</message>
296+
<message>
297+
<source>This is an error editor banner.</source>
298+
<translation type="unfinished"></translation>
299+
</message>
300+
<message>
301+
<source>Clear all</source>
302+
<translation type="unfinished"></translation>
303+
</message>
280304
</context>
281305
</TS>

demo/src/res/demo_es_ES.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,5 +279,29 @@
279279
<source>Open dialog banner demo</source>
280280
<translation type="unfinished"></translation>
281281
</message>
282+
<message>
283+
<source>Editor banner</source>
284+
<translation type="unfinished"></translation>
285+
</message>
286+
<message>
287+
<source>This is an informational editor banner.</source>
288+
<translation type="unfinished"></translation>
289+
</message>
290+
<message>
291+
<source>This is a success editor banner.</source>
292+
<translation type="unfinished"></translation>
293+
</message>
294+
<message>
295+
<source>This is a warning editor banner.</source>
296+
<translation type="unfinished"></translation>
297+
</message>
298+
<message>
299+
<source>This is an error editor banner.</source>
300+
<translation type="unfinished"></translation>
301+
</message>
302+
<message>
303+
<source>Clear all</source>
304+
<translation type="unfinished"></translation>
305+
</message>
282306
</context>
283307
</TS>

demo/src/res/demo_fr_FR.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,5 +279,29 @@
279279
<source>Open dialog banner demo</source>
280280
<translation type="unfinished"></translation>
281281
</message>
282+
<message>
283+
<source>Editor banner</source>
284+
<translation type="unfinished"></translation>
285+
</message>
286+
<message>
287+
<source>This is an informational editor banner.</source>
288+
<translation type="unfinished"></translation>
289+
</message>
290+
<message>
291+
<source>This is a success editor banner.</source>
292+
<translation type="unfinished"></translation>
293+
</message>
294+
<message>
295+
<source>This is a warning editor banner.</source>
296+
<translation type="unfinished"></translation>
297+
</message>
298+
<message>
299+
<source>This is an error editor banner.</source>
300+
<translation type="unfinished"></translation>
301+
</message>
302+
<message>
303+
<source>Clear all</source>
304+
<translation type="unfinished"></translation>
305+
</message>
282306
</context>
283307
</TS>

demo/src/res/demo_hi_IN.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,5 +279,29 @@
279279
<source>Open dialog banner demo</source>
280280
<translation type="unfinished"></translation>
281281
</message>
282+
<message>
283+
<source>Editor banner</source>
284+
<translation type="unfinished"></translation>
285+
</message>
286+
<message>
287+
<source>This is an informational editor banner.</source>
288+
<translation type="unfinished"></translation>
289+
</message>
290+
<message>
291+
<source>This is a success editor banner.</source>
292+
<translation type="unfinished"></translation>
293+
</message>
294+
<message>
295+
<source>This is a warning editor banner.</source>
296+
<translation type="unfinished"></translation>
297+
</message>
298+
<message>
299+
<source>This is an error editor banner.</source>
300+
<translation type="unfinished"></translation>
301+
</message>
302+
<message>
303+
<source>Clear all</source>
304+
<translation type="unfinished"></translation>
305+
</message>
282306
</context>
283307
</TS>

demo/src/res/demo_zh_CN.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,5 +279,29 @@
279279
<source>Open dialog banner demo</source>
280280
<translation type="unfinished"></translation>
281281
</message>
282+
<message>
283+
<source>Editor banner</source>
284+
<translation type="unfinished"></translation>
285+
</message>
286+
<message>
287+
<source>This is an informational editor banner.</source>
288+
<translation type="unfinished"></translation>
289+
</message>
290+
<message>
291+
<source>This is a success editor banner.</source>
292+
<translation type="unfinished"></translation>
293+
</message>
294+
<message>
295+
<source>This is a warning editor banner.</source>
296+
<translation type="unfinished"></translation>
297+
</message>
298+
<message>
299+
<source>This is an error editor banner.</source>
300+
<translation type="unfinished"></translation>
301+
</message>
302+
<message>
303+
<source>Clear all</source>
304+
<translation type="unfinished"></translation>
305+
</message>
282306
</context>
283307
</TS>

0 commit comments

Comments
 (0)