From 9010b08874c6c103bd150745e95c0d213d65ea9b Mon Sep 17 00:00:00 2001 From: Zimnx Date: Mon, 17 Mar 2014 11:25:22 +0100 Subject: [PATCH 1/2] Fixed Show/Hide label in Tray when minimizing; Added checkbox to OnCloseAplicationDialog which indicates if window shoud appear in future --- src/Settings/guisettingspage.cpp | 3 +++ src/Settings/guisettingspage.hpp | 1 + src/Settings/settings.cpp | 11 +++++++++++ src/Settings/settings.hpp | 4 ++++ src/closeapplicationdialog.cpp | 12 +++++++++--- src/closeapplicationdialog.hpp | 5 ++++- src/mainwindow.cpp | 33 ++++++++++++++++++++++++++------ 7 files changed, 59 insertions(+), 10 deletions(-) diff --git a/src/Settings/guisettingspage.cpp b/src/Settings/guisettingspage.cpp index 9ff5c17..258fd18 100644 --- a/src/Settings/guisettingspage.cpp +++ b/src/Settings/guisettingspage.cpp @@ -99,6 +99,7 @@ void GuiSettingsPage::applyChanges() settings.setEmojiFontFamily(emojiSettings->getFontFamily()); settings.setEmojiFontPointSize(emojiSettings->getFontPointSize()); settings.setMinimizeOnClose(minimizeToTrayCheckbox->isChecked()); + settings.setShowConfrimationDialogOnClose(showConfrimationDialogOnCloseCheckbox->isChecked()); } QGroupBox *GuiSettingsPage::buildAnimationGroup() @@ -197,7 +198,9 @@ QGroupBox* GuiSettingsPage::buildOthersGroup() QGroupBox *group = new QGroupBox(tr("Others"), this); QVBoxLayout* layout = new QVBoxLayout(group); minimizeToTrayCheckbox = new QCheckBox(tr("Minimize to tray on close"), group); + showConfrimationDialogOnCloseCheckbox = new QCheckBox(tr("Show confrimation dialog on close")); layout->addWidget(minimizeToTrayCheckbox); + layout->addWidget(showConfrimationDialogOnCloseCheckbox); return group; } diff --git a/src/Settings/guisettingspage.hpp b/src/Settings/guisettingspage.hpp index 2d14d21..1540bf9 100644 --- a/src/Settings/guisettingspage.hpp +++ b/src/Settings/guisettingspage.hpp @@ -50,6 +50,7 @@ private slots: EmojiFontSettingsDialog *emojiSettings; QCheckBox* enableAnimationCheckbox; QCheckBox* minimizeToTrayCheckbox; + QCheckBox* showConfrimationDialogOnCloseCheckbox; QComboBox* smileypackCombobox; QToolButton *emojiButton; diff --git a/src/Settings/settings.cpp b/src/Settings/settings.cpp index 385bbfb..6a98425 100644 --- a/src/Settings/settings.cpp +++ b/src/Settings/settings.cpp @@ -99,6 +99,7 @@ void Settings::load() emojiFontFamily = s.value("emojiFontFamily", "DejaVu Sans").toString(); emojiFontPointSize = s.value("emojiFontPointSize", QApplication::font().pointSize()).toInt(); minimizeOnClose = s.value("minimizeOnClose", true).toBool(); + showConfrimationDialogOnClose = s.value("showConfrimationDialogOnClose",true).toBool(); s.endGroup(); loaded = true; @@ -151,6 +152,7 @@ void Settings::save() s.setValue("emojiFontFamily", emojiFontFamily); s.setValue("emojiFontPointSize", emojiFontPointSize); s.setValue("minimizeOnClose", minimizeOnClose); + s.setValue("showConfrimationDialogOnClose",showConfrimationDialogOnClose); s.endGroup(); } @@ -286,3 +288,12 @@ void Settings::setMinimizeOnClose(bool newValue) { minimizeOnClose = newValue; } + +bool Settings::isShowConfrimationDialogOnCloseEnabled() const +{ + return showConfrimationDialogOnClose; +} +void Settings::setShowConfrimationDialogOnClose(bool newValue) +{ + showConfrimationDialogOnClose = newValue; +} diff --git a/src/Settings/settings.hpp b/src/Settings/settings.hpp index 53a72f4..a54dc4d 100644 --- a/src/Settings/settings.hpp +++ b/src/Settings/settings.hpp @@ -93,6 +93,9 @@ class Settings : public QObject bool isMinimizeOnCloseEnabled() const; void setMinimizeOnClose(bool newValue); + bool isShowConfrimationDialogOnCloseEnabled() const; + void setShowConfrimationDialogOnClose(bool newValue); + private: Settings(); Settings(Settings &settings) = delete; @@ -124,6 +127,7 @@ class Settings : public QObject QString emojiFontFamily; int emojiFontPointSize; bool minimizeOnClose; + bool showConfrimationDialogOnClose; signals: //void dataChanged(); diff --git a/src/closeapplicationdialog.cpp b/src/closeapplicationdialog.cpp index d3c57e4..6415c5d 100644 --- a/src/closeapplicationdialog.cpp +++ b/src/closeapplicationdialog.cpp @@ -15,7 +15,7 @@ */ #include "closeapplicationdialog.hpp" - +#include "Settings/settings.hpp" #include #include #include @@ -36,15 +36,21 @@ CloseApplicationDialog::CloseApplicationDialog(QWidget *parent) : connect(buttonBox, &QDialogButtonBox::accepted, this, &CloseApplicationDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &CloseApplicationDialog::reject); + askAgainBox = new QCheckBox("Don't ask again",this); + askAgainBox->setChecked(false); + QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(closeLabel); - layout->addSpacing(16); - layout->addWidget(buttonBox); + layout->addSpacing(8); + layout->addWidget(buttonBox,0,Qt::AlignCenter); + layout->addSpacing(8); + layout->addWidget(askAgainBox); } void CloseApplicationDialog::accept() { + Settings::getInstance().setShowConfrimationDialogOnClose(!askAgainBox->isChecked()); qApp->quit(); QDialog::accept(); } diff --git a/src/closeapplicationdialog.hpp b/src/closeapplicationdialog.hpp index 4b1b0de..0f9119f 100644 --- a/src/closeapplicationdialog.hpp +++ b/src/closeapplicationdialog.hpp @@ -18,13 +18,16 @@ #define CLOSEAPPLICATIONDIALOG_HPP #include - +#include class CloseApplicationDialog : public QDialog { Q_OBJECT public: explicit CloseApplicationDialog(QWidget *parent = 0); +private: + QCheckBox* askAgainBox; + public slots: void accept(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8d0223a..1816b55 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -200,12 +200,22 @@ void MainWindow::closeEvent(QCloseEvent *event) bool minimize = Settings::getInstance().isMinimizeOnCloseEnabled(); if (isVisible() && minimize) { hide(); + trayMenuShowHideAction->setText(tr("Show")); event->ignore(); } else { - Settings::getInstance().saveGeometryState(this); - Settings::getInstance().saveGeometryState(splitterWidget); - QMainWindow::closeEvent(event); - qApp->quit(); + CloseApplicationDialog dialog(this); + bool showConfrimationDialog = Settings::getInstance().isShowConfrimationDialogOnCloseEnabled(); + QDialog::DialogCode onCloseDialogResult = QDialog::Accepted; + if (showConfrimationDialog) + onCloseDialogResult = static_cast(dialog.exec()); + if(onCloseDialogResult == QDialog::Accepted) { + Settings::getInstance().saveGeometryState(this); + Settings::getInstance().saveGeometryState(splitterWidget); + QMainWindow::closeEvent(event); + qApp->quit(); + } else { + event->ignore(); + } } } @@ -276,7 +286,12 @@ void MainWindow::onAboutAppActionTriggered() void MainWindow::onTrayMenuQuitApplicationActionTriggered() { CloseApplicationDialog dialog(this); - dialog.exec(); + bool showConfrimationDialog = Settings::getInstance().isShowConfrimationDialogOnCloseEnabled(); + if(showConfrimationDialog){ + dialog.exec(); + } else { + qApp->quit(); + } } void MainWindow::onShowHideWindow() @@ -297,8 +312,14 @@ void MainWindow::onTrayMenuStatusActionTriggered() Status selectedStatus = static_cast(statusAction->data().toInt()); if (selectedStatus == Status::Offline) { + bool showConfrimationDialog = Settings::getInstance().isShowConfrimationDialogOnCloseEnabled(); CloseApplicationDialog dialog(this); - dialog.exec(); + if(showConfrimationDialog) { + dialog.exec(); + } else { + qApp->quit(); + } + } else { emit statusSet(selectedStatus); } From ab0be2fcf69ff4357e4363a70741d5140608b6cb Mon Sep 17 00:00:00 2001 From: Zimnx Date: Mon, 17 Mar 2014 14:52:41 +0100 Subject: [PATCH 2/2] Different layout for ClosingAplication dialog. AskCheckbox is in the same line as buttons --- src/closeapplicationdialog.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/closeapplicationdialog.cpp b/src/closeapplicationdialog.cpp index 6415c5d..8b41e8b 100644 --- a/src/closeapplicationdialog.cpp +++ b/src/closeapplicationdialog.cpp @@ -39,13 +39,14 @@ CloseApplicationDialog::CloseApplicationDialog(QWidget *parent) : askAgainBox = new QCheckBox("Don't ask again",this); askAgainBox->setChecked(false); - QVBoxLayout* layout = new QVBoxLayout(this); + QHBoxLayout* buttonsLayout = new QHBoxLayout(); + buttonsLayout->addWidget(askAgainBox); + buttonsLayout->addWidget(buttonBox); - layout->addWidget(closeLabel); - layout->addSpacing(8); - layout->addWidget(buttonBox,0,Qt::AlignCenter); + QVBoxLayout* layout = new QVBoxLayout(this); + layout->addWidget(closeLabel,0,Qt::AlignHCenter); layout->addSpacing(8); - layout->addWidget(askAgainBox); + layout->addLayout(buttonsLayout); } void CloseApplicationDialog::accept()