Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
feat: Hold shift to avoid remember save state
Browse files Browse the repository at this point in the history
Change-Id: I9f193ba08ffa923518e8fdb7ea817ab77b68b762
  • Loading branch information
BLumia committed Jan 24, 2019
1 parent 466b0fa commit 26a5f60
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions src/utils/configsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/utils/configsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
};
Expand Down
1 change: 1 addition & 0 deletions src/widgets/resources/qss/savetips.qss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ SaveTips {
font-size: 12px;
font-weight: medium;
border: none;
padding-left: 5px;
}
4 changes: 2 additions & 2 deletions src/widgets/savetips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 6 additions & 1 deletion src/widgets/subtoolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/toolbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 26a5f60

Please # to comment.