diff --git a/dialogs/helpdialog.cpp b/dialogs/helpdialog.cpp index 5406c43..912dedd 100644 --- a/dialogs/helpdialog.cpp +++ b/dialogs/helpdialog.cpp @@ -5,12 +5,14 @@ #include #include #include +#include + +#define HIDE_DIALOG_SETTING_KEY "hideHelpDialog" HelpDialog::HelpDialog(const QString& path, const QString& page, QWidget* parent) - : QDialog(parent) + : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint) { - setWindowFlags(Qt::Tool); - setWindowTitle(tr("HOW TO USE REVERSCREEN")); + setWindowTitle(tr("HELP")); QTextBrowser* textBrowser = new QTextBrowser; textBrowser->setSource(QUrl(path + page)); @@ -18,10 +20,11 @@ HelpDialog::HelpDialog(const QString& path, const QString& page, QWidget* parent textBrowser->setTextInteractionFlags(Qt::NoTextInteraction); QCheckBox* checkBox = new QCheckBox(tr("Don't show this dialog again")); + connect(checkBox, &QCheckBox::toggled, this, &HelpDialog::checkBoxToggled); checkBox->setCheckState(Qt::Checked); - connect(checkBox, SIGNAL(toggled(bool)), this, SLOT(checkBoxToggled(bool))); QPushButton* closeButton = new QPushButton(tr("Close")); + connect(closeButton, QPushButton::clicked, this, &HelpDialog::reject); QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addWidget(checkBox); @@ -33,28 +36,18 @@ HelpDialog::HelpDialog(const QString& path, const QString& page, QWidget* parent mainLayout->addLayout(buttonLayout); setLayout(mainLayout); - connect(closeButton, SIGNAL(clicked()), this, SLOT(reject())); - - QSettings settings; - bool checked = settings.value("hideHelpDialog", true).toBool(); - checkBox->setCheckState(checked ? Qt::Checked : Qt::Unchecked); - setFixedSize(450, 300); move(parent->geometry().center() - geometry().center()); } -void HelpDialog::showPage(const QString& path, const QString& page, QWidget* parent) +bool HelpDialog::canShowDialog() { QSettings settings; - bool hideHelpDialog = settings.value("hideHelpDialog", false).toBool(); - if (!hideHelpDialog){ - HelpDialog *helpDialog = new HelpDialog(path, page, parent); - helpDialog->exec(); - } + return !settings.value(HIDE_DIALOG_SETTING_KEY, false).toBool(); } void HelpDialog::checkBoxToggled(bool checked) { QSettings settings; - settings.setValue("hideHelpDialog", checked); + settings.setValue(HIDE_DIALOG_SETTING_KEY, checked); } diff --git a/dialogs/helpdialog.h b/dialogs/helpdialog.h index 65f470e..cbb2c02 100644 --- a/dialogs/helpdialog.h +++ b/dialogs/helpdialog.h @@ -12,7 +12,7 @@ class HelpDialog : public QDialog public: HelpDialog(const QString& path, const QString& page, QWidget* parent); - static void showPage(const QString& path, const QString& page, QWidget* parent); + static bool canShowDialog(); private slots: void checkBoxToggled(bool); diff --git a/mainwindow.cpp b/mainwindow.cpp index 81f2207..99287e3 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -360,14 +360,18 @@ void MainWindow::setupUi() _actionSave->setShortcut(QKeySequence("Ctrl+S")); _actionCrop = new QAction(_awesome->icon(fa::crop), tr("Crop"), this); _actionCrop->setShortcut(QKeySequence("Ctrl+X")); + _actionHelp = new QAction(tr("Help"), this); + _actionHelp->setShortcut(QKeySequence("F1")); addAction(_actionPaste); + addAction(_actionHelp); connect(_actionCapture, &QAction::triggered, this, &MainWindow::slotActionCapture); connect(_actionPaste, &QAction::triggered, this, &MainWindow::slotActionPaste); connect(_actionCopy, &QAction::triggered, this, &MainWindow::slotActionCopy); connect(_actionSave, &QAction::triggered, this, &MainWindow::slotActionSave); connect(_actionCrop, &QAction::triggered, this, &MainWindow::slotActionCrop); + connect(_actionHelp, &QAction::triggered, this, &MainWindow::slotActionHelp); // central widget _scrollArea = new QScrollArea(this); @@ -537,6 +541,11 @@ void MainWindow::closeEvent(QCloseEvent *event) QMainWindow::closeEvent(event); } -void MainWindow::slotActionHelp(){ - HelpDialog::showPage("qrc:/docs","/usage_tips.html", this); +void MainWindow::slotActionHelp() +{ + bool canShowHelp = (sender() == _actionHelp) || HelpDialog::canShowDialog(); + if (canShowHelp) { + HelpDialog* helpDialog = new HelpDialog("qrc:/docs","/usage_tips.html", this); + helpDialog->exec(); + } } diff --git a/mainwindow.h b/mainwindow.h index 3071636..265c0b1 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -97,5 +97,6 @@ private slots: QAction* _actionCopy; QAction* _actionSave; QAction* _actionCrop; + QAction* _actionHelp; };