config file support
This commit is contained in:
parent
31fae2cc8c
commit
6709c21d70
|
@ -19,6 +19,7 @@ set (PPIC_CPP_FILES
|
|||
navigatorview.cpp
|
||||
opacityhelper.cpp
|
||||
toolbutton.cpp
|
||||
settings.cpp
|
||||
)
|
||||
|
||||
set (PPIC_HEADER_FILES
|
||||
|
@ -29,6 +30,7 @@ set (PPIC_HEADER_FILES
|
|||
navigatorview.h
|
||||
opacityhelper.h
|
||||
toolbutton.h
|
||||
settings.h
|
||||
)
|
||||
|
||||
set (PPIC_QRC_FILES
|
||||
|
|
|
@ -32,7 +32,8 @@ SOURCES += \
|
|||
graphicsscene.cpp \
|
||||
navigatorview.cpp \
|
||||
opacityhelper.cpp \
|
||||
toolbutton.cpp
|
||||
toolbutton.cpp \
|
||||
settings.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
|
@ -41,7 +42,8 @@ HEADERS += \
|
|||
graphicsscene.h \
|
||||
navigatorview.h \
|
||||
opacityhelper.h \
|
||||
toolbutton.h
|
||||
toolbutton.h \
|
||||
settings.h
|
||||
|
||||
TRANSLATIONS = \
|
||||
languages/PineapplePictures.ts \
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<context>
|
||||
<name>GraphicsView</name>
|
||||
<message>
|
||||
<location filename="../graphicsview.cpp" line="243"/>
|
||||
<location filename="../graphicsview.cpp" line="247"/>
|
||||
<source>File url list is empty</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
@ -22,12 +22,12 @@
|
|||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../graphicsview.cpp" line="251"/>
|
||||
<location filename="../graphicsview.cpp" line="255"/>
|
||||
<source>Image data is invalid</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../graphicsview.cpp" line="258"/>
|
||||
<location filename="../graphicsview.cpp" line="262"/>
|
||||
<source>Not supported mimedata: %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
@ -40,69 +40,69 @@
|
|||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="382"/>
|
||||
<location filename="../mainwindow.cpp" line="396"/>
|
||||
<source>&Copy</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="403"/>
|
||||
<location filename="../mainwindow.cpp" line="417"/>
|
||||
<source>Copy P&ixmap</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="408"/>
|
||||
<location filename="../mainwindow.cpp" line="422"/>
|
||||
<source>Copy &File Path</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="418"/>
|
||||
<location filename="../mainwindow.cpp" line="432"/>
|
||||
<source>&Paste Image</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="424"/>
|
||||
<location filename="../mainwindow.cpp" line="438"/>
|
||||
<source>&Paste Image File</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="429"/>
|
||||
<location filename="../mainwindow.cpp" line="448"/>
|
||||
<location filename="../mainwindow.cpp" line="443"/>
|
||||
<location filename="../mainwindow.cpp" line="462"/>
|
||||
<source>Stay on top</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="435"/>
|
||||
<location filename="../mainwindow.cpp" line="449"/>
|
||||
<location filename="../mainwindow.cpp" line="463"/>
|
||||
<source>Protected mode</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="441"/>
|
||||
<location filename="../mainwindow.cpp" line="455"/>
|
||||
<source>Help</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="444"/>
|
||||
<location filename="../mainwindow.cpp" line="458"/>
|
||||
<source>Launch application with image file path as argument to load the file.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="445"/>
|
||||
<location filename="../mainwindow.cpp" line="459"/>
|
||||
<source>Drag and drop image file onto the window is also supported.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="447"/>
|
||||
<location filename="../mainwindow.cpp" line="461"/>
|
||||
<source>Context menu option explanation:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="448"/>
|
||||
<location filename="../mainwindow.cpp" line="462"/>
|
||||
<source>Make window stay on top of all other windows.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="449"/>
|
||||
<location filename="../mainwindow.cpp" line="463"/>
|
||||
<source>Avoid close window accidentally. (eg. by double clicking the window)</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<context>
|
||||
<name>GraphicsView</name>
|
||||
<message>
|
||||
<location filename="../graphicsview.cpp" line="243"/>
|
||||
<location filename="../graphicsview.cpp" line="247"/>
|
||||
<source>File url list is empty</source>
|
||||
<translation>文件 URL 列表为空</translation>
|
||||
</message>
|
||||
|
@ -22,12 +22,12 @@
|
|||
<translation>文件不是有效的图片文件</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../graphicsview.cpp" line="251"/>
|
||||
<location filename="../graphicsview.cpp" line="255"/>
|
||||
<source>Image data is invalid</source>
|
||||
<translation>图片数据无效</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../graphicsview.cpp" line="258"/>
|
||||
<location filename="../graphicsview.cpp" line="262"/>
|
||||
<source>Not supported mimedata: %1</source>
|
||||
<translation>不受支持的 MimeData 格式:%1</translation>
|
||||
</message>
|
||||
|
@ -40,7 +40,7 @@
|
|||
<translation>文件 URL 列表为空</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="382"/>
|
||||
<location filename="../mainwindow.cpp" line="396"/>
|
||||
<source>&Copy</source>
|
||||
<translation>复制(&C)</translation>
|
||||
</message>
|
||||
|
@ -49,64 +49,64 @@
|
|||
<translation type="vanished">复制位图(&P)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="403"/>
|
||||
<location filename="../mainwindow.cpp" line="417"/>
|
||||
<source>Copy P&ixmap</source>
|
||||
<translation>复制位图(&I)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="408"/>
|
||||
<location filename="../mainwindow.cpp" line="422"/>
|
||||
<source>Copy &File Path</source>
|
||||
<translation>复制文件路径(&F)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="418"/>
|
||||
<location filename="../mainwindow.cpp" line="432"/>
|
||||
<source>&Paste Image</source>
|
||||
<translation>粘贴图像(&P)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="424"/>
|
||||
<location filename="../mainwindow.cpp" line="438"/>
|
||||
<source>&Paste Image File</source>
|
||||
<translation>粘贴图像文件(&P)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="429"/>
|
||||
<location filename="../mainwindow.cpp" line="448"/>
|
||||
<location filename="../mainwindow.cpp" line="443"/>
|
||||
<location filename="../mainwindow.cpp" line="462"/>
|
||||
<source>Stay on top</source>
|
||||
<translation>总在最前</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="435"/>
|
||||
<location filename="../mainwindow.cpp" line="449"/>
|
||||
<location filename="../mainwindow.cpp" line="463"/>
|
||||
<source>Protected mode</source>
|
||||
<translation>保护模式</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="441"/>
|
||||
<location filename="../mainwindow.cpp" line="455"/>
|
||||
<source>Help</source>
|
||||
<translation>帮助</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="444"/>
|
||||
<location filename="../mainwindow.cpp" line="458"/>
|
||||
<source>Launch application with image file path as argument to load the file.</source>
|
||||
<translation>以图片文件的路径作为参数运行程序即可直接打开图片文件。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="445"/>
|
||||
<location filename="../mainwindow.cpp" line="459"/>
|
||||
<source>Drag and drop image file onto the window is also supported.</source>
|
||||
<translation>也支持拖放图片文件到窗口内来加载图片。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="447"/>
|
||||
<location filename="../mainwindow.cpp" line="461"/>
|
||||
<source>Context menu option explanation:</source>
|
||||
<translation>菜单项说明:</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="448"/>
|
||||
<location filename="../mainwindow.cpp" line="462"/>
|
||||
<source>Make window stay on top of all other windows.</source>
|
||||
<translation>使窗口始终至于其它非置顶窗口上方。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="449"/>
|
||||
<location filename="../mainwindow.cpp" line="463"/>
|
||||
<source>Avoid close window accidentally. (eg. by double clicking the window)</source>
|
||||
<translation>避免窗口意外关闭。(如:不小心双击了窗口触发了关闭窗口行为)</translation>
|
||||
</message>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "mainwindow.h"
|
||||
|
||||
#include "settings.h"
|
||||
#include "toolbutton.h"
|
||||
#include "bottombuttongroup.h"
|
||||
#include "graphicsview.h"
|
||||
|
@ -27,7 +28,12 @@
|
|||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent)
|
||||
{
|
||||
if (Settings::instance()->alwaysOnTop()) {
|
||||
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
||||
} else {
|
||||
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
|
||||
}
|
||||
|
||||
this->setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
this->setMinimumSize(350, 350);
|
||||
this->setWindowIcon(QIcon(":/icons/app-icon.svg"));
|
||||
|
@ -101,13 +107,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
connect(m_bottomButtonGroup, &BottomButtonGroup::resetToOriginalBtnClicked,
|
||||
this, [ = ](){ m_graphicsView->resetScale(); });
|
||||
connect(m_bottomButtonGroup, &BottomButtonGroup::toggleWindowMaximum,
|
||||
this, [ = ](){
|
||||
if (isMaximized()) {
|
||||
showNormal();
|
||||
} else {
|
||||
showMaximized();
|
||||
}
|
||||
});
|
||||
this, &MainWindow::toggleMaximize);
|
||||
connect(m_bottomButtonGroup, &BottomButtonGroup::zoomInBtnClicked,
|
||||
this, [ = ](){ m_graphicsView->zoomView(1.25); });
|
||||
connect(m_bottomButtonGroup, &BottomButtonGroup::zoomOutBtnClicked,
|
||||
|
@ -325,7 +325,7 @@ void MainWindow::mousePressEvent(QMouseEvent *event)
|
|||
|
||||
void MainWindow::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->buttons() & Qt::LeftButton && m_clickedOnWindow) {
|
||||
if (event->buttons() & Qt::LeftButton && m_clickedOnWindow && !isMaximized()) {
|
||||
move(event->globalPos() - m_oldMousePos);
|
||||
event->accept();
|
||||
}
|
||||
|
@ -342,9 +342,22 @@ void MainWindow::mouseReleaseEvent(QMouseEvent *event)
|
|||
|
||||
void MainWindow::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
switch (Settings::instance()->doubleClickBehavior()) {
|
||||
case ActionCloseWindow:
|
||||
quitAppAction();
|
||||
event->accept();
|
||||
break;
|
||||
case ActionMaximizeWindow:
|
||||
toggleMaximize();
|
||||
event->accept();
|
||||
break;
|
||||
case ActionDoNothing:
|
||||
break;
|
||||
}
|
||||
|
||||
return QMainWindow::mouseDoubleClickEvent(event);
|
||||
// blumia: don't call parent constructor here, seems it will cause mouse move
|
||||
// event get called even if we set event->accept();
|
||||
// return QMainWindow::mouseDoubleClickEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::wheelEvent(QWheelEvent *event)
|
||||
|
@ -631,3 +644,12 @@ void MainWindow::toggleFullscreen()
|
|||
showFullScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::toggleMaximize()
|
||||
{
|
||||
if (isMaximized()) {
|
||||
showNormal();
|
||||
} else {
|
||||
showMaximized();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ protected slots:
|
|||
bool stayOnTop();
|
||||
void quitAppAction(bool force = false);
|
||||
void toggleFullscreen();
|
||||
void toggleMaximize();
|
||||
|
||||
private:
|
||||
QPoint m_oldMousePos;
|
||||
|
|
72
settings.cpp
Normal file
72
settings.cpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
#include "settings.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QStandardPaths>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
|
||||
Settings *Settings::m_settings_instance = nullptr;
|
||||
|
||||
Settings *Settings::instance()
|
||||
{
|
||||
if (!m_settings_instance) {
|
||||
m_settings_instance = new Settings;
|
||||
}
|
||||
|
||||
return m_settings_instance;
|
||||
}
|
||||
|
||||
bool Settings::alwaysOnTop()
|
||||
{
|
||||
return m_qsettings->value("always_on_top", true).toBool();
|
||||
}
|
||||
|
||||
DoubleClickBehavior Settings::doubleClickBehavior()
|
||||
{
|
||||
QString result = m_qsettings->value("double_click_behavior", "close").toString().toLower();
|
||||
|
||||
return stringToDoubleClickBehavior(result);
|
||||
}
|
||||
|
||||
QString Settings::doubleClickBehaviorToString(DoubleClickBehavior dcb)
|
||||
{
|
||||
static QMap<DoubleClickBehavior, QString> _map {
|
||||
{ActionCloseWindow, "close"},
|
||||
{ActionMaximizeWindow, "maximize"},
|
||||
{ActionDoNothing, "ignore"}
|
||||
};
|
||||
|
||||
return _map.value(dcb, "close");
|
||||
}
|
||||
|
||||
DoubleClickBehavior Settings::stringToDoubleClickBehavior(QString str)
|
||||
{
|
||||
static QMap<QString, DoubleClickBehavior> _map {
|
||||
{"close", ActionCloseWindow},
|
||||
{"maximize", ActionMaximizeWindow},
|
||||
{"ignore", ActionDoNothing}
|
||||
};
|
||||
|
||||
return _map.value(str, ActionCloseWindow);
|
||||
}
|
||||
|
||||
Settings::Settings()
|
||||
: QObject(qApp)
|
||||
{
|
||||
QString configPath;
|
||||
|
||||
QString portableConfigDirPath = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath("data");
|
||||
QFileInfo portableConfigDirInfo(portableConfigDirPath);
|
||||
if (portableConfigDirInfo.exists() && portableConfigDirInfo.isDir() && portableConfigDirInfo.isWritable()) {
|
||||
// we can use it.
|
||||
configPath = portableConfigDirPath;
|
||||
}
|
||||
|
||||
// %LOCALAPPDATA% under Windows.
|
||||
if (configPath.isEmpty()) {
|
||||
configPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
|
||||
}
|
||||
|
||||
m_qsettings = new QSettings(QDir(configPath).absoluteFilePath("config.ini"), QSettings::IniFormat, this);
|
||||
}
|
||||
|
35
settings.h
Normal file
35
settings.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
|
||||
enum DoubleClickBehavior {
|
||||
ActionDoNothing,
|
||||
ActionCloseWindow,
|
||||
ActionMaximizeWindow
|
||||
};
|
||||
|
||||
class Settings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static Settings *instance();
|
||||
|
||||
bool alwaysOnTop();
|
||||
DoubleClickBehavior doubleClickBehavior();
|
||||
|
||||
static QString doubleClickBehaviorToString(DoubleClickBehavior dcb);
|
||||
static DoubleClickBehavior stringToDoubleClickBehavior(QString str);
|
||||
|
||||
private:
|
||||
Settings();
|
||||
|
||||
static Settings *m_settings_instance;
|
||||
|
||||
QSettings *m_qsettings;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user