From 4f452d5815e14043f3c0977673bf338491032520 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sat, 15 Mar 2014 14:18:29 +0100 Subject: Add a timer for clicking away the notification dialog --- gui/dialogs/NotificationDialog.cpp | 84 +++++++++++++++++++++++++++++++++++++ gui/dialogs/NotificationDialog.h | 44 ++++++++++++++++++++ gui/dialogs/NotificationDialog.ui | 85 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 gui/dialogs/NotificationDialog.cpp create mode 100644 gui/dialogs/NotificationDialog.h create mode 100644 gui/dialogs/NotificationDialog.ui (limited to 'gui/dialogs') diff --git a/gui/dialogs/NotificationDialog.cpp b/gui/dialogs/NotificationDialog.cpp new file mode 100644 index 00000000..8f920371 --- /dev/null +++ b/gui/dialogs/NotificationDialog.cpp @@ -0,0 +1,84 @@ +#include "NotificationDialog.h" +#include "ui_NotificationDialog.h" + +#include + +NotificationDialog::NotificationDialog(const NotificationChecker::NotificationEntry &entry, QWidget *parent) : + QDialog(parent, Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::CustomizeWindowHint), + ui(new Ui::NotificationDialog) +{ + ui->setupUi(this); + + QStyle::StandardPixmap icon; + switch (entry.type) + { + case NotificationChecker::NotificationEntry::Critical: + icon = QStyle::SP_MessageBoxCritical; + break; + case NotificationChecker::NotificationEntry::Warning: + icon = QStyle::SP_MessageBoxWarning; + break; + case NotificationChecker::NotificationEntry::Information: + icon = QStyle::SP_MessageBoxInformation; + break; + } + ui->iconLabel->setPixmap(style()->standardPixmap(icon, 0, this)); + ui->messageLabel->setText(entry.message); + + m_dontShowAgainText = tr("Don't show again"); + m_closeText = tr("Close"); + + ui->dontShowAgainBtn->setText(m_dontShowAgainText + QString(" (%1)").arg(m_dontShowAgainTime)); + ui->closeBtn->setText(m_closeText + QString(" (%1)").arg(m_closeTime)); + + startTimer(1000); +} + +NotificationDialog::~NotificationDialog() +{ + delete ui; +} + +void NotificationDialog::timerEvent(QTimerEvent *event) +{ + if (m_dontShowAgainTime > 0) + { + m_dontShowAgainTime--; + if (m_dontShowAgainTime == 0) + { + ui->dontShowAgainBtn->setText(m_dontShowAgainText); + ui->dontShowAgainBtn->setEnabled(true); + } + else + { + ui->dontShowAgainBtn->setText(m_dontShowAgainText + QString(" (%1)").arg(m_dontShowAgainTime)); + } + } + if (m_closeTime > 0) + { + m_closeTime--; + if (m_closeTime == 0) + { + ui->closeBtn->setText(m_closeText); + ui->closeBtn->setEnabled(true); + } + else + { + ui->closeBtn->setText(m_closeText + QString(" (%1)").arg(m_closeTime)); + } + } + + if (m_closeTime == 0 && m_dontShowAgainTime == 0) + { + killTimer(event->timerId()); + } +} + +void NotificationDialog::on_dontShowAgainBtn_clicked() +{ + done(DontShowAgain); +} +void NotificationDialog::on_closeBtn_clicked() +{ + done(Normal); +} diff --git a/gui/dialogs/NotificationDialog.h b/gui/dialogs/NotificationDialog.h new file mode 100644 index 00000000..b7980a98 --- /dev/null +++ b/gui/dialogs/NotificationDialog.h @@ -0,0 +1,44 @@ +#ifndef NOTIFICATIONDIALOG_H +#define NOTIFICATIONDIALOG_H + +#include + +#include "logic/updater/NotificationChecker.h" + +namespace Ui { +class NotificationDialog; +} + +class NotificationDialog : public QDialog +{ + Q_OBJECT + +public: + explicit NotificationDialog(const NotificationChecker::NotificationEntry &entry, QWidget *parent = 0); + ~NotificationDialog(); + + enum ExitCode + { + Normal, + DontShowAgain + }; + +protected: + void timerEvent(QTimerEvent *event); + +private: + Ui::NotificationDialog *ui; + + int m_dontShowAgainTime = 10; + int m_closeTime = 5; + + QString m_dontShowAgainText; + QString m_closeText; + +private +slots: + void on_dontShowAgainBtn_clicked(); + void on_closeBtn_clicked(); +}; + +#endif // NOTIFICATIONDIALOG_H diff --git a/gui/dialogs/NotificationDialog.ui b/gui/dialogs/NotificationDialog.ui new file mode 100644 index 00000000..a2a276e9 --- /dev/null +++ b/gui/dialogs/NotificationDialog.ui @@ -0,0 +1,85 @@ + + + NotificationDialog + + + + 0 + 0 + 320 + 240 + + + + Dialog + + + + + + + + TextLabel + + + + + + + TextLabel + + + true + + + true + + + Qt::TextBrowserInteraction + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Don't show again + + + + + + + false + + + Close + + + + + + + + + + -- cgit v1.2.3 From 55e4cb6fb5ea59958ac0bc386b9df06476c1ddb4 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sat, 15 Mar 2014 14:35:35 +0100 Subject: Allow reseting notifications --- gui/dialogs/SettingsDialog.cpp | 5 +++++ gui/dialogs/SettingsDialog.ui | 10 ++++++++++ 2 files changed, 15 insertions(+) (limited to 'gui/dialogs') diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index d79bb558..7ec48336 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -308,6 +308,11 @@ void SettingsDialog::applySettings(SettingsObject *s) s->set("Language", ui->languageBox->itemData(ui->languageBox->currentIndex()).toLocale().bcp47Name()); + if (ui->resetNotificationsBtn->isChecked()) + { + s->set("ShownNotifications", QString()); + } + // Updates s->set("AutoUpdate", ui->autoUpdateCheckBox->isChecked()); s->set("UpdateChannel", m_currentUpdateChannel); diff --git a/gui/dialogs/SettingsDialog.ui b/gui/dialogs/SettingsDialog.ui index e8da8582..74ed68d2 100644 --- a/gui/dialogs/SettingsDialog.ui +++ b/gui/dialogs/SettingsDialog.ui @@ -284,6 +284,16 @@ + + + + Reset hidden notifications + + + true + + + -- cgit v1.2.3