feat: simple config dialog
This commit is contained in:
parent
6709c21d70
commit
a2adb0e1d4
|
@ -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
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "graphicsview.h"
|
||||
#include "navigatorview.h"
|
||||
#include "graphicsscene.h"
|
||||
#include "settingsdialog.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QMovie>
|
||||
|
@ -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();
|
||||
|
|
16
settings.cpp
16
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<DoubleClickBehavior, QString> _map {
|
||||
|
|
10
settings.h
10
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);
|
||||
|
||||
|
|
50
settingsdialog.cpp
Normal file
50
settingsdialog.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include "settingsdialog.h"
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QFormLayout>
|
||||
#include <QStringListModel>
|
||||
|
||||
SettingsDialog::SettingsDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, m_stayOnTop(new QCheckBox)
|
||||
, m_doubleClickBehavior(new QComboBox)
|
||||
{
|
||||
QFormLayout * settingsForm = new QFormLayout(this);
|
||||
|
||||
static QMap<DoubleClickBehavior, QString> _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<DoubleClickBehavior>(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<int>(dcb));
|
||||
|
||||
connect(m_stayOnTop, &QCheckBox::stateChanged, this, [ = ](int state){
|
||||
Settings::instance()->setStayOnTop(state == Qt::Checked);
|
||||
});
|
||||
|
||||
connect(m_doubleClickBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
|
||||
Settings::instance()->setDoubleClickBehavior(static_cast<DoubleClickBehavior>(index));
|
||||
});
|
||||
|
||||
setMinimumSize(200,50); // FIXME: use minimumSizeHint() instead?
|
||||
}
|
||||
|
||||
SettingsDialog::~SettingsDialog()
|
||||
{
|
||||
|
||||
}
|
26
settingsdialog.h
Normal file
26
settingsdialog.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef SETTINGSDIALOG_H
|
||||
#define SETTINGSDIALOG_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QDialog>
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user