|
| 1 | +#include "notificationdemodialog.hpp" |
| 2 | + |
| 3 | +#include <array> |
| 4 | + |
| 5 | +#include <QDialogButtonBox> |
| 6 | +#include <QHBoxLayout> |
| 7 | +#include <QPushButton> |
| 8 | +#include <QString> |
| 9 | +#include <QVBoxLayout> |
| 10 | + |
| 11 | +#include <aide/notificationtype.hpp> |
| 12 | + |
| 13 | +using aide::NotificationType; |
| 14 | +using aide::widgets::AideDialog; |
| 15 | +using demo::NotificationDemoDialog; |
| 16 | + |
| 17 | +namespace |
| 18 | +{ |
| 19 | + struct SeverityButton |
| 20 | + { |
| 21 | + NotificationType type; |
| 22 | + QString buttonLabel; |
| 23 | + QString message; |
| 24 | + }; |
| 25 | +} // namespace |
| 26 | + |
| 27 | +NotificationDemoDialog::NotificationDemoDialog(QWidget* parent) |
| 28 | + : AideDialog(parent) |
| 29 | +{ |
| 30 | + setWindowTitle(tr("Dialog Banner Demo")); |
| 31 | + |
| 32 | + auto* buttonsRow = new QHBoxLayout; |
| 33 | + |
| 34 | + const std::array<SeverityButton, 4> severityButtons{{ |
| 35 | + {NotificationType::Information, tr("Info"), |
| 36 | + tr("This is an informational banner.")}, |
| 37 | + {NotificationType::Success, tr("Success"), |
| 38 | + tr("This is a success banner.")}, |
| 39 | + {NotificationType::Warning, tr("Warning"), |
| 40 | + tr("This is a warning banner.")}, |
| 41 | + {NotificationType::Error, tr("Error"), tr("This is an error banner.")}, |
| 42 | + }}; |
| 43 | + |
| 44 | + for (const auto& severityButton : severityButtons) { |
| 45 | + auto* button = new QPushButton(severityButton.buttonLabel, this); |
| 46 | + connect(button, &QPushButton::clicked, this, [this, severityButton]() { |
| 47 | + showBanner(severityButton.type, severityButton.message); |
| 48 | + }); |
| 49 | + buttonsRow->addWidget(button); |
| 50 | + } |
| 51 | + |
| 52 | + auto* clearButton = new QPushButton(tr("Clear"), this); |
| 53 | + connect(clearButton, &QPushButton::clicked, this, &AideDialog::clearBanner); |
| 54 | + buttonsRow->addWidget(clearButton); |
| 55 | + |
| 56 | + contentLayout()->addLayout(buttonsRow); |
| 57 | + |
| 58 | + auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this); |
| 59 | + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); |
| 60 | + contentLayout()->addWidget(buttonBox); |
| 61 | +} |
0 commit comments