From 8848b25305d3aef379206ab1fc5ff4da81233984 Mon Sep 17 00:00:00 2001 From: Yuriy Puchkov Date: Tue, 6 Oct 2020 14:08:40 +0300 Subject: [PATCH] Join two similar options 'Save path' and 'Save default path for screenshots' --- src/config/geneneralconf.cpp | 87 ++++++++--------------------------- src/config/geneneralconf.h | 6 +-- src/utils/confighandler.cpp | 24 ++++------ src/utils/confighandler.h | 7 +-- src/utils/filenamehandler.cpp | 2 +- src/utils/screenshotsaver.cpp | 3 +- 6 files changed, 35 insertions(+), 94 deletions(-) diff --git a/src/config/geneneralconf.cpp b/src/config/geneneralconf.cpp index 267ec78e..b0fe1f88 100644 --- a/src/config/geneneralconf.cpp +++ b/src/config/geneneralconf.cpp @@ -44,7 +44,6 @@ GeneneralConf::GeneneralConf(QWidget* parent) initCopyAndCloseAfterUpload(); initCopyPathAfterSave(); initSaveAfterCopy(); - initFilePathConfiguration(); // this has to be at the end initConfingButtons(); @@ -330,12 +329,15 @@ void GeneneralConf::initSaveAfterCopy() this, &GeneneralConf::saveAfterCopyChanged); - QHBoxLayout* pathLayout = new QHBoxLayout(); - m_layout->addStretch(); QGroupBox* box = new QGroupBox(tr("Save Path")); box->setFlat(true); - box->setLayout(pathLayout); m_layout->addWidget(box); + m_layout->addStretch(); + + QVBoxLayout* vboxLayout = new QVBoxLayout(); + box->setLayout(vboxLayout); + + QHBoxLayout* pathLayout = new QHBoxLayout(); m_savePath = new QLineEdit( QStandardPaths::writableLocation(QStandardPaths::PicturesLocation), this); @@ -350,6 +352,17 @@ void GeneneralConf::initSaveAfterCopy() &QPushButton::clicked, this, &GeneneralConf::changeSavePath); + + m_screenshotPathFixedCheck = + new QCheckBox(tr("Use fixed path for screenshots to save"), this); + m_screenshotPathFixedCheck->setChecked(ConfigHandler().savePathFixed()); + connect(m_screenshotPathFixedCheck, + SIGNAL(toggled(bool)), + this, + SLOT(togglePathFixed())); + + vboxLayout->addLayout(pathLayout); + vboxLayout->addWidget(m_screenshotPathFixedCheck); } void GeneneralConf::saveAfterCopyChanged(bool checked) @@ -379,50 +392,6 @@ void GeneneralConf::initCopyPathAfterSave() }); } -void GeneneralConf::initFilePathConfiguration() -{ - QGroupBox* box = new QGroupBox(tr("Select default path for Screenshots")); - box->setFlat(true); - - QVBoxLayout* boxLayout = new QVBoxLayout(); - box->setLayout(boxLayout); - - QHBoxLayout* pathBrowseLayout = new QHBoxLayout(); - - m_screenshotPathFixedCheck = - new QCheckBox(tr("Use fixed path for screenshots to save"), this); - m_screenshotPathFixedCheck->setChecked( - !ConfigHandler().savePathFixed().isEmpty()); - connect(m_screenshotPathFixedCheck, - SIGNAL(toggled(bool)), - this, - SLOT(pathFixed())); - - m_screenshotPathFixedText = - new QLineEdit(ConfigHandler().savePathFixed(), this); - m_screenshotPathFixedText->setDisabled(true); - QString foreground = this->palette().foreground().color().name(); - m_screenshotPathFixedText->setStyleSheet( - QStringLiteral("color: %1").arg(foreground)); - - m_screenshotPathFixedBrowse = new QPushButton(tr("Change..."), this); - m_screenshotPathFixedBrowse->setEnabled( - m_screenshotPathFixedCheck->isChecked()); - connect(m_screenshotPathFixedBrowse, - &QPushButton::clicked, - this, - &GeneneralConf::setPathFixed); - - pathBrowseLayout->addWidget(m_screenshotPathFixedText); - pathBrowseLayout->addWidget(m_screenshotPathFixedBrowse); - - boxLayout->addWidget(m_screenshotPathFixedCheck); - boxLayout->addLayout(pathBrowseLayout); - - m_layout->addStretch(); - m_layout->addWidget(box); -} - const QString GeneneralConf::chooseFolder(const QString pathDefault) { QString path; @@ -448,25 +417,7 @@ const QString GeneneralConf::chooseFolder(const QString pathDefault) return path; } -void GeneneralConf::setPathFixed() +void GeneneralConf::togglePathFixed() { - QString pathDefault = m_screenshotPathFixedText->text(); - QString path = chooseFolder(pathDefault); - if (path.isNull()) { - return; - } - m_screenshotPathFixedText->setText(path); - ConfigHandler().setSavePathFixed(path); -} - -void GeneneralConf::pathFixed() -{ - bool status = m_screenshotPathFixedCheck->isChecked(); - m_screenshotPathFixedBrowse->setEnabled(status); - if (!status) { - m_screenshotPathFixedText->setText(""); - ConfigHandler().setSavePathFixed(m_screenshotPathFixedText->text()); - } else { - emit setPathFixed(); - } + ConfigHandler().setSavePathFixed(m_screenshotPathFixedCheck->isChecked()); } diff --git a/src/config/geneneralconf.h b/src/config/geneneralconf.h index e541c17c..c7974082 100644 --- a/src/config/geneneralconf.h +++ b/src/config/geneneralconf.h @@ -46,8 +46,7 @@ private slots: void importConfiguration(); void exportFileConfiguration(); void resetConfiguration(); - void setPathFixed(); - void pathFixed(); + void togglePathFixed(); private: const QString chooseFolder(const QString currentPath = ""); @@ -63,7 +62,6 @@ private: void initCopyAndCloseAfterUpload(); void initSaveAfterCopy(); void initCopyPathAfterSave(); - void initFilePathConfiguration(); // class members QVBoxLayout* m_layout; @@ -82,7 +80,5 @@ private: QCheckBox* m_saveAfterCopy; QLineEdit* m_savePath; QPushButton* m_changeSaveButton; - QLineEdit* m_screenshotPathFixedText; QCheckBox* m_screenshotPathFixedCheck; - QPushButton* m_screenshotPathFixedBrowse; }; diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index 1699d25b..b7f09230 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -124,31 +124,25 @@ void ConfigHandler::setUserColors(const QVector& l) QVariant::fromValue(hexColors)); } -QString ConfigHandler::savePathValue() +QString ConfigHandler::savePath() { - QString savePath = - m_settings.value(QStringLiteral("savePathFixed")).toString(); - if (savePath.isEmpty()) { - savePath = m_settings.value(QStringLiteral("savePath")).toString(); - } - return savePath; + return m_settings.value(QStringLiteral("savePath")).toString(); } void ConfigHandler::setSavePath(const QString& savePath) { - QString savePathFixed = - m_settings.value(QStringLiteral("savePathFixed")).toString(); - if (savePathFixed.isEmpty()) { - m_settings.setValue(QStringLiteral("savePath"), savePath); - } + m_settings.setValue(QStringLiteral("savePath"), savePath); } -QString ConfigHandler::savePathFixed() +bool ConfigHandler::savePathFixed() { - return m_settings.value(QStringLiteral("savePathFixed")).toString(); + if (!m_settings.contains(QStringLiteral("savePathFixed"))) { + m_settings.setValue(QStringLiteral("savePathFixed"), false); + } + return m_settings.value(QStringLiteral("savePathFixed")).toBool(); } -void ConfigHandler::setSavePathFixed(const QString& savePathFixed) +void ConfigHandler::setSavePathFixed(bool savePathFixed) { m_settings.setValue(QStringLiteral("savePathFixed"), savePathFixed); } diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h index da16ca3a..0ec01ef0 100644 --- a/src/utils/confighandler.h +++ b/src/utils/confighandler.h @@ -33,10 +33,11 @@ public: QVector getUserColors(); void setUserColors(const QVector&); - QString savePathValue(); + QString savePath(); void setSavePath(const QString&); - QString savePathFixed(); - void setSavePathFixed(const QString&); + + bool savePathFixed(); + void setSavePathFixed(bool); QColor uiMainColorValue(); void setUIMainColor(const QColor&); diff --git a/src/utils/filenamehandler.cpp b/src/utils/filenamehandler.cpp index 35eee619..22119bac 100644 --- a/src/utils/filenamehandler.cpp +++ b/src/utils/filenamehandler.cpp @@ -73,7 +73,7 @@ void FileNameHandler::setPattern(const QString& pattern) QString FileNameHandler::absoluteSavePath(QString& directory, QString& filename) { ConfigHandler config; - directory = config.savePathValue(); + directory = config.savePath(); if (directory.isEmpty() || !QDir(directory).exists() || !QFileInfo(directory).isWritable()) { directory = diff --git a/src/utils/screenshotsaver.cpp b/src/utils/screenshotsaver.cpp index 958e0f06..f803987a 100644 --- a/src/utils/screenshotsaver.cpp +++ b/src/utils/screenshotsaver.cpp @@ -79,7 +79,7 @@ bool ScreenshotSaver::saveToFilesystemGUI(const QPixmap& capture) while (!ok) { ConfigHandler config; QString savePath = FileNameHandler().absoluteSavePath(); - if (config.savePathFixed().size() == 0) { + if (!config.savePathFixed()) { savePath = QFileDialog::getSaveFileName( nullptr, QObject::tr("Save screenshot"), @@ -95,7 +95,6 @@ bool ScreenshotSaver::saveToFilesystemGUI(const QPixmap& capture) if (!savePath.endsWith(QLatin1String(".png"), Qt::CaseInsensitive) && !savePath.endsWith(QLatin1String(".bmp"), Qt::CaseInsensitive) && !savePath.endsWith(QLatin1String(".jpg"), Qt::CaseInsensitive)) { - savePath += QLatin1String(".png"); }