From 75cfe1c5dd1c23523135d38e751f4cedba5cd0dd Mon Sep 17 00:00:00 2001 From: frostasm Date: Wed, 11 Oct 2017 13:10:40 +0300 Subject: [PATCH 1/2] Add the auto hide functionality to the MessageWidget --- src/gui/MessageWidget.cpp | 36 +++++++++++++++++++++++++++++++++--- src/gui/MessageWidget.h | 9 +++++++++ src/http/OptionDialog.cpp | 1 + 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/gui/MessageWidget.cpp b/src/gui/MessageWidget.cpp index de981b92a..b3d014c33 100644 --- a/src/gui/MessageWidget.cpp +++ b/src/gui/MessageWidget.cpp @@ -18,20 +18,50 @@ #include "MessageWidget.h" -MessageWidget::MessageWidget(QWidget* parent) - :KMessageWidget(parent) -{ +#include "QTimer" +MessageWidget::MessageWidget(QWidget* parent) + : KMessageWidget(parent) + , m_autoHideTimer(new QTimer(this)) + , m_autoHideTimeout(6000) +{ + m_autoHideTimer->setSingleShot(true); + connect(m_autoHideTimer, SIGNAL(timeout()), this, SLOT(animatedHide())); + connect(this, SIGNAL(hideAnimationFinished()), m_autoHideTimer, SLOT(stop())); +} + +int MessageWidget::autoHideTimeout() const +{ + return m_autoHideTimeout; } void MessageWidget::showMessage(const QString& text, MessageWidget::MessageType type) +{ + showMessage(text, type, m_autoHideTimeout); +} + +void MessageWidget::showMessage(const QString &text, KMessageWidget::MessageType type, int autoHideTimeout) { setMessageType(type); setText(text); animatedShow(); + if (autoHideTimeout > 0) { + m_autoHideTimer->start(autoHideTimeout); + } else { + m_autoHideTimer->stop(); + } } void MessageWidget::hideMessage() { animatedHide(); + m_autoHideTimer->stop(); +} + +void MessageWidget::setAutoHideTimeout(int autoHideTimeout) +{ + m_autoHideTimeout = autoHideTimeout; + if (autoHideTimeout <= 0) { + m_autoHideTimer->stop(); + } } diff --git a/src/gui/MessageWidget.h b/src/gui/MessageWidget.h index 03ebee3eb..4a25737b1 100644 --- a/src/gui/MessageWidget.h +++ b/src/gui/MessageWidget.h @@ -21,6 +21,8 @@ #include "gui/KMessageWidget.h" +class QTimer; + class MessageWidget : public KMessageWidget { Q_OBJECT @@ -28,10 +30,17 @@ class MessageWidget : public KMessageWidget public: explicit MessageWidget(QWidget* parent = 0); + int autoHideTimeout() const; + public slots: void showMessage(const QString& text, MessageWidget::MessageType type); + void showMessage(const QString& text, MessageWidget::MessageType type, int autoHideTimeout); void hideMessage(); + void setAutoHideTimeout(int autoHideTimeout); +private: + QTimer* m_autoHideTimer; + int m_autoHideTimeout; }; #endif // MESSAGEWIDGET_H diff --git a/src/http/OptionDialog.cpp b/src/http/OptionDialog.cpp index 9fb66bd6f..b0823c7b4 100644 --- a/src/http/OptionDialog.cpp +++ b/src/http/OptionDialog.cpp @@ -35,6 +35,7 @@ OptionDialog::OptionDialog(QWidget *parent) : m_ui->warningWidget->showMessage(tr("The following options can be dangerous!\nChange them only if you know what you are doing."), MessageWidget::Warning); m_ui->warningWidget->setIcon(FilePath::instance()->icon("status", "dialog-warning")); m_ui->warningWidget->setCloseButtonVisible(false); + m_ui->warningWidget->setAutoHideTimeout(-1); m_ui->tabWidget->setEnabled(m_ui->enableHttpServer->isChecked()); connect(m_ui->enableHttpServer, SIGNAL(toggled(bool)), m_ui->tabWidget, SLOT(setEnabled(bool))); From f38fe5a9dda5f17393373c67c0c4735ad578c95d Mon Sep 17 00:00:00 2001 From: frostasm Date: Thu, 19 Oct 2017 21:46:09 +0300 Subject: [PATCH 2/2] Disable automatic hiding of an information message for YubiKey --- src/gui/DatabaseWidget.cpp | 5 +++-- src/gui/DatabaseWidget.h | 3 ++- src/gui/MainWindow.cpp | 14 ++++++++------ src/gui/MainWindow.h | 6 ++++-- src/gui/MessageWidget.cpp | 5 ++++- src/gui/MessageWidget.h | 3 +++ src/http/OptionDialog.cpp | 2 +- 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 3a39bddcf..7fbcbe35c 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -1325,9 +1325,10 @@ void DatabaseWidget::closeUnlockDialog() m_unlockDatabaseDialog->close(); } -void DatabaseWidget::showMessage(const QString& text, MessageWidget::MessageType type) +void DatabaseWidget::showMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton, int autoHideTimeout) { - m_messageWidget->showMessage(text, type); + m_messageWidget->setCloseButtonVisible(showClosebutton); + m_messageWidget->showMessage(text, type, autoHideTimeout); } void DatabaseWidget::hideMessage() diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 734e979e7..934820009 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -166,7 +166,8 @@ public slots: void setSearchLimitGroup(bool state); void endSearch(); - void showMessage(const QString& text, MessageWidget::MessageType type); + void showMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton = true, + int autoHideTimeout = MessageWidget::DefaultAutoHideTimeout); void hideMessage(); private slots: diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 14531a4f2..cfa18597f 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -952,16 +952,17 @@ bool MainWindow::isTrayIconEnabled() const && QSystemTrayIcon::isSystemTrayAvailable(); } -void MainWindow::displayGlobalMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton) +void MainWindow::displayGlobalMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton, + int autoHideTimeout) { m_ui->globalMessageWidget->setCloseButtonVisible(showClosebutton); - m_ui->globalMessageWidget->showMessage(text, type); + m_ui->globalMessageWidget->showMessage(text, type, autoHideTimeout); } -void MainWindow::displayTabMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton) +void MainWindow::displayTabMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton, + int autoHideTimeout) { - m_ui->globalMessageWidget->setCloseButtonVisible(showClosebutton); - m_ui->tabWidget->currentDatabaseWidget()->showMessage(text, type); + m_ui->tabWidget->currentDatabaseWidget()->showMessage(text, type, showClosebutton, autoHideTimeout); } void MainWindow::hideGlobalMessage() @@ -978,7 +979,8 @@ void MainWindow::hideTabMessage() void MainWindow::showYubiKeyPopup() { - displayGlobalMessage(tr("Please touch the button on your YubiKey!"), MessageWidget::Information, false); + displayGlobalMessage(tr("Please touch the button on your YubiKey!"), MessageWidget::Information, + false, MessageWidget::DisableAutoHide); setEnabled(false); } diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index caf3f5854..ea17107ad 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -54,8 +54,10 @@ public slots: void openDatabase(const QString& fileName, const QString& pw = QString(), const QString& keyFile = QString()); void appExit(); - void displayGlobalMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton = true); - void displayTabMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton = true); + void displayGlobalMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton = true, + int autoHideTimeout = MessageWidget::DefaultAutoHideTimeout); + void displayTabMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton = true, + int autoHideTimeout = MessageWidget::DefaultAutoHideTimeout); void hideGlobalMessage(); void showYubiKeyPopup(); void hideYubiKeyPopup(); diff --git a/src/gui/MessageWidget.cpp b/src/gui/MessageWidget.cpp index b3d014c33..2be298055 100644 --- a/src/gui/MessageWidget.cpp +++ b/src/gui/MessageWidget.cpp @@ -20,10 +20,13 @@ #include "QTimer" +const int MessageWidget::DefaultAutoHideTimeout = 6000; +const int MessageWidget::DisableAutoHide = -1; + MessageWidget::MessageWidget(QWidget* parent) : KMessageWidget(parent) , m_autoHideTimer(new QTimer(this)) - , m_autoHideTimeout(6000) + , m_autoHideTimeout(DefaultAutoHideTimeout) { m_autoHideTimer->setSingleShot(true); connect(m_autoHideTimer, SIGNAL(timeout()), this, SLOT(animatedHide())); diff --git a/src/gui/MessageWidget.h b/src/gui/MessageWidget.h index 4a25737b1..c29c320bf 100644 --- a/src/gui/MessageWidget.h +++ b/src/gui/MessageWidget.h @@ -32,6 +32,9 @@ public: int autoHideTimeout() const; + static const int DefaultAutoHideTimeout; + static const int DisableAutoHide; + public slots: void showMessage(const QString& text, MessageWidget::MessageType type); void showMessage(const QString& text, MessageWidget::MessageType type, int autoHideTimeout); diff --git a/src/http/OptionDialog.cpp b/src/http/OptionDialog.cpp index b0823c7b4..03ae6e9ce 100644 --- a/src/http/OptionDialog.cpp +++ b/src/http/OptionDialog.cpp @@ -35,7 +35,7 @@ OptionDialog::OptionDialog(QWidget *parent) : m_ui->warningWidget->showMessage(tr("The following options can be dangerous!\nChange them only if you know what you are doing."), MessageWidget::Warning); m_ui->warningWidget->setIcon(FilePath::instance()->icon("status", "dialog-warning")); m_ui->warningWidget->setCloseButtonVisible(false); - m_ui->warningWidget->setAutoHideTimeout(-1); + m_ui->warningWidget->setAutoHideTimeout(MessageWidget::DisableAutoHide); m_ui->tabWidget->setEnabled(m_ui->enableHttpServer->isChecked()); connect(m_ui->enableHttpServer, SIGNAL(toggled(bool)), m_ui->tabWidget, SLOT(setEnabled(bool)));