diff --git a/CMakeLists.txt b/CMakeLists.txt index 0504c85..6cd978a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ set (PPIC_CPP_FILES opacityhelper.cpp toolbutton.cpp settings.cpp + settingsdialog.cpp ) set (PPIC_HEADER_FILES @@ -31,6 +32,7 @@ set (PPIC_HEADER_FILES opacityhelper.h toolbutton.h settings.h + settingsdialog.h ) set (PPIC_QRC_FILES diff --git a/PineapplePictures.pro b/PineapplePictures.pro index bfb93b8..45ae584 100644 --- a/PineapplePictures.pro +++ b/PineapplePictures.pro @@ -33,7 +33,8 @@ SOURCES += \ navigatorview.cpp \ opacityhelper.cpp \ toolbutton.cpp \ - settings.cpp + settings.cpp \ + settingsdialog.cpp HEADERS += \ mainwindow.h \ @@ -43,7 +44,8 @@ HEADERS += \ navigatorview.h \ opacityhelper.h \ toolbutton.h \ - settings.h + settings.h \ + settingsdialog.h TRANSLATIONS = \ languages/PineapplePictures.ts \ diff --git a/mainwindow.cpp b/mainwindow.cpp index 0bc37f5..de25c98 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -6,6 +6,7 @@ #include "graphicsview.h" #include "navigatorview.h" #include "graphicsscene.h" +#include "settingsdialog.h" #include #include @@ -28,7 +29,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { - if (Settings::instance()->alwaysOnTop()) { + if (Settings::instance()->stayOnTop()) { this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); } else { this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint); @@ -445,12 +446,21 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event) }); stayOnTopMode->setCheckable(true); stayOnTopMode->setChecked(stayOnTop()); + QAction * protectedMode = new QAction(tr("Protected mode")); connect(protectedMode, &QAction::triggered, this, [ = ](){ toggleProtectedMode(); }); protectedMode->setCheckable(true); protectedMode->setChecked(m_protectedMode); + + QAction * toggleSettings = new QAction(tr("Configure...")); + connect(toggleSettings, &QAction::triggered, this, [ = ](){ + SettingsDialog * sd = new SettingsDialog(this); + sd->exec(); + sd->deleteLater(); + }); + QAction * helpAction = new QAction(tr("Help")); connect(helpAction, &QAction::triggered, this, [ = ](){ QStringList sl { @@ -478,6 +488,7 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event) menu->addAction(stayOnTopMode); menu->addAction(protectedMode); menu->addSeparator(); + menu->addAction(toggleSettings); menu->addAction(helpAction); menu->exec(mapToGlobal(event->pos())); menu->deleteLater(); diff --git a/settings.cpp b/settings.cpp index 1d589fb..861af74 100644 --- a/settings.cpp +++ b/settings.cpp @@ -16,9 +16,9 @@ Settings *Settings::instance() return m_settings_instance; } -bool Settings::alwaysOnTop() +bool Settings::stayOnTop() { - return m_qsettings->value("always_on_top", true).toBool(); + return m_qsettings->value("stay_on_top", true).toBool(); } DoubleClickBehavior Settings::doubleClickBehavior() @@ -28,6 +28,18 @@ DoubleClickBehavior Settings::doubleClickBehavior() return stringToDoubleClickBehavior(result); } +void Settings::setStayOnTop(bool on) +{ + m_qsettings->setValue("stay_on_top", on); + m_qsettings->sync(); +} + +void Settings::setDoubleClickBehavior(DoubleClickBehavior dcb) +{ + m_qsettings->setValue("double_click_behavior", doubleClickBehaviorToString(dcb)); + m_qsettings->sync(); +} + QString Settings::doubleClickBehaviorToString(DoubleClickBehavior dcb) { static QMap _map { diff --git a/settings.h b/settings.h index 0f729e4..3656e2e 100644 --- a/settings.h +++ b/settings.h @@ -6,7 +6,10 @@ enum DoubleClickBehavior { ActionDoNothing, ActionCloseWindow, - ActionMaximizeWindow + ActionMaximizeWindow, + + ActionStart = ActionDoNothing, + ActionEnd = ActionMaximizeWindow }; class Settings : public QObject @@ -15,9 +18,12 @@ class Settings : public QObject public: static Settings *instance(); - bool alwaysOnTop(); + bool stayOnTop(); DoubleClickBehavior doubleClickBehavior(); + void setStayOnTop(bool on); + void setDoubleClickBehavior(DoubleClickBehavior dcb); + static QString doubleClickBehaviorToString(DoubleClickBehavior dcb); static DoubleClickBehavior stringToDoubleClickBehavior(QString str); diff --git a/settingsdialog.cpp b/settingsdialog.cpp new file mode 100644 index 0000000..f4b830a --- /dev/null +++ b/settingsdialog.cpp @@ -0,0 +1,50 @@ +#include "settingsdialog.h" + +#include "settings.h" + +#include +#include +#include +#include + +SettingsDialog::SettingsDialog(QWidget *parent) + : QDialog(parent) + , m_stayOnTop(new QCheckBox) + , m_doubleClickBehavior(new QComboBox) +{ + QFormLayout * settingsForm = new QFormLayout(this); + + static QMap _map { + { ActionDoNothing, tr("Do nothing") }, + { ActionCloseWindow, tr("Close the window") }, + { ActionMaximizeWindow, tr("Toggle maximize") } + }; + + QStringList dropDown; + for (int dcb = ActionStart; dcb <= ActionEnd; dcb++) { + dropDown.append(_map.value(static_cast(dcb))); + } + + settingsForm->addRow(tr("Stay on top when start-up"), m_stayOnTop); + settingsForm->addRow(tr("Double-click behavior"), m_doubleClickBehavior); + + m_stayOnTop->setChecked(Settings::instance()->stayOnTop()); + m_doubleClickBehavior->setModel(new QStringListModel(dropDown)); + DoubleClickBehavior dcb = Settings::instance()->doubleClickBehavior(); + m_doubleClickBehavior->setCurrentIndex(static_cast(dcb)); + + connect(m_stayOnTop, &QCheckBox::stateChanged, this, [ = ](int state){ + Settings::instance()->setStayOnTop(state == Qt::Checked); + }); + + connect(m_doubleClickBehavior, QOverload::of(&QComboBox::currentIndexChanged), this, [ = ](int index){ + Settings::instance()->setDoubleClickBehavior(static_cast(index)); + }); + + setMinimumSize(200,50); // FIXME: use minimumSizeHint() instead? +} + +SettingsDialog::~SettingsDialog() +{ + +} diff --git a/settingsdialog.h b/settingsdialog.h new file mode 100644 index 0000000..03cbca1 --- /dev/null +++ b/settingsdialog.h @@ -0,0 +1,26 @@ +#ifndef SETTINGSDIALOG_H +#define SETTINGSDIALOG_H + +#include +#include +#include + +class QCheckBox; +class QComboBox; +class SettingsDialog : public QDialog +{ + Q_OBJECT +public: + explicit SettingsDialog(QWidget *parent = nullptr); + ~SettingsDialog(); + +signals: + +public slots: + +private: + QCheckBox * m_stayOnTop = nullptr; + QComboBox * m_doubleClickBehavior = nullptr; +}; + +#endif // SETTINGSDIALOG_H