Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pinebit committed Nov 13, 2016
1 parent 78b495c commit 523f640
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
27 changes: 10 additions & 17 deletions dialogs/helpdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@
#include <QGroupBox>
#include <QSettings>
#include <QDir>
#include <QDebug>

#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));
textBrowser->setContextMenuPolicy(Qt::NoContextMenu);
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);
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion dialogs/helpdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
1 change: 1 addition & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,6 @@ private slots:
QAction* _actionCopy;
QAction* _actionSave;
QAction* _actionCrop;
QAction* _actionHelp;
};

0 comments on commit 523f640

Please sign in to comment.