From 26a5f60a29f5815cbfde00cf8091979df92b450c Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Sat, 5 Jan 2019 17:11:16 +0800 Subject: [PATCH] feat: Hold shift to avoid remember save state Change-Id: I9f193ba08ffa923518e8fdb7ea817ab77b68b762 --- src/mainwindow.cpp | 7 ++++++- src/utils/configsettings.cpp | 18 ++++++++++++++++++ src/utils/configsettings.h | 4 ++++ src/widgets/resources/qss/savetips.qss | 1 + src/widgets/savetips.cpp | 4 ++-- src/widgets/subtoolbar.cpp | 7 ++++++- src/widgets/toolbutton.h | 4 ++-- 7 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c12a9aeb..5e7a8b8f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1226,7 +1226,12 @@ bool MainWindow::saveAction(const QPixmap &pix) QStandardPaths::StandardLocation saveOption = QStandardPaths::TempLocation; bool copyToClipboard = false; - m_saveIndex = ConfigSettings::instance()->value("save", "save_op").toInt(); + + if (ConfigSettings::instance()->hasTemporarySaveAction()) { + m_saveIndex = ConfigSettings::instance()->getAndResetTemporarySaveAction(); + } else { + m_saveIndex = ConfigSettings::instance()->value("save", "save_op").toInt(); + } switch (m_saveIndex) { case 0: { saveOption = QStandardPaths::DesktopLocation; diff --git a/src/utils/configsettings.cpp b/src/utils/configsettings.cpp index beece127..010d54bb 100644 --- a/src/utils/configsettings.cpp +++ b/src/utils/configsettings.cpp @@ -64,6 +64,24 @@ ConfigSettings* ConfigSettings::instance() { return m_configSettings; } +void ConfigSettings::setTemporarySaveAction(int save_op) +{ + m_temporary_save_op = save_op; +} + +bool ConfigSettings::hasTemporarySaveAction() +{ + return m_temporary_save_op >= 0; +} + +int ConfigSettings::getAndResetTemporarySaveAction() +{ + int ret = m_temporary_save_op; + m_temporary_save_op = -1; + + return ret; +} + void ConfigSettings::setValue(const QString &group, const QString &key, QVariant val) { m_settings->beginGroup(group); diff --git a/src/utils/configsettings.h b/src/utils/configsettings.h index 34a1d8bd..eae00dce 100644 --- a/src/utils/configsettings.h +++ b/src/utils/configsettings.h @@ -29,6 +29,9 @@ class ConfigSettings : public QObject { public: static ConfigSettings *instance(); + void setTemporarySaveAction(int save_op); + bool hasTemporarySaveAction(); + int getAndResetTemporarySaveAction(); void setValue(const QString &group, const QString &key, QVariant val); QVariant value(const QString &group, const QString &key, @@ -45,6 +48,7 @@ class ConfigSettings : public QObject { ~ConfigSettings(); static ConfigSettings* m_configSettings; + int m_temporary_save_op = -1; QSettings* m_settings; QMutex m_mutex; }; diff --git a/src/widgets/resources/qss/savetips.qss b/src/widgets/resources/qss/savetips.qss index befadbe7..2fbbf13b 100644 --- a/src/widgets/resources/qss/savetips.qss +++ b/src/widgets/resources/qss/savetips.qss @@ -3,4 +3,5 @@ SaveTips { font-size: 12px; font-weight: medium; border: none; + padding-left: 5px; } diff --git a/src/widgets/savetips.cpp b/src/widgets/savetips.cpp index 51c2c3a5..08f4a3b6 100644 --- a/src/widgets/savetips.cpp +++ b/src/widgets/savetips.cpp @@ -45,8 +45,8 @@ SaveTips::SaveTips(QWidget *parent) } void SaveTips::setSaveText(QString text) { - m_text = " " + text; - setTipWidth(stringWidth(this->font(), m_text) + 10); + m_text = text; + setTipWidth(stringWidth(this->font(), m_text) + 10); // setText(text); } diff --git a/src/widgets/subtoolbar.cpp b/src/widgets/subtoolbar.cpp index fa600155..87b1281e 100644 --- a/src/widgets/subtoolbar.cpp +++ b/src/widgets/subtoolbar.cpp @@ -502,7 +502,12 @@ void SubToolBar::switchContent(QString shapeType) { } void SubToolBar::setSaveOption(int saveOption) { - ConfigSettings::instance()->setValue("save", "save_op", saveOption); + if (QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)) { + qDebug() << "Shift key holded: temporary action, will not remember the save_op."; + ConfigSettings::instance()->setTemporarySaveAction(saveOption); + } else { + ConfigSettings::instance()->setValue("save", "save_op", saveOption); + } emit saveAction(); } diff --git a/src/widgets/toolbutton.h b/src/widgets/toolbutton.h index 90ccb960..95712030 100644 --- a/src/widgets/toolbutton.h +++ b/src/widgets/toolbutton.h @@ -48,12 +48,12 @@ public slots: void onExist(); protected: - void enterEvent(QEvent* e) { + void enterEvent(QEvent* e) override { emit onEnter(); QPushButton::enterEvent(e); } - void leaveEvent(QEvent* e) { + void leaveEvent(QEvent* e) override { emit onExist(); QPushButton::leaveEvent(e); }