diff --git a/src/Gui/SettingsDialog/GeneralOptionsPage.cpp b/src/Gui/SettingsDialog/GeneralOptionsPage.cpp index 23e51cc..b94bb46 100644 --- a/src/Gui/SettingsDialog/GeneralOptionsPage.cpp +++ b/src/Gui/SettingsDialog/GeneralOptionsPage.cpp @@ -1,103 +1,111 @@ /* * Copyright (C) 2015 Boudhayan Gupta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "GeneralOptionsPage.h" #include "SpectacleConfig.h" #include #include #include #include GeneralOptionsPage::GeneralOptionsPage(QWidget *parent) : SettingsPage(parent) { // preamble and stuff QVBoxLayout *mainLayout = new QVBoxLayout(this); + // copy file location to clipboard after saving + + mCopyPathToClipboard = new QCheckBox(i18n("Copy file location to clipboard after saving"), this); + connect(mCopyPathToClipboard, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty); + mainLayout->addWidget(mCopyPathToClipboard, 1); + // Rectangular Region settings QGroupBox *rrGroup = new QGroupBox(i18n("Rectangular Region")); QVBoxLayout *rrLayout = new QVBoxLayout; rrGroup->setLayout(rrLayout); // use light background mUseLightBackground = new QCheckBox(i18n("Use light background"), this); connect(mUseLightBackground, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty); mainLayout->addWidget(mUseLightBackground, 1); // remember Rectangular Region box mRememberRect = new QCheckBox(i18n("Remember selected area"), this); connect(mRememberRect, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty); // show magnifier mShowMagnifier = new QCheckBox(i18n("Show magnifier"), this); connect(mShowMagnifier, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty); QVBoxLayout *rrCLayout = new QVBoxLayout; // rrCLayout->setContentsMargins(15, 10, 0, 10); rrCLayout->addWidget(mUseLightBackground); rrCLayout->addWidget(mRememberRect); rrCLayout->addWidget(mShowMagnifier); rrLayout->addLayout(rrCLayout); mainLayout->addWidget(rrGroup, 1); // read in the data resetChanges(); // finish up with the main layout mainLayout->addStretch(4); setLayout(mainLayout); } void GeneralOptionsPage::markDirty(bool checked) { Q_UNUSED(checked); mChangesMade = true; } void GeneralOptionsPage::saveChanges() { SpectacleConfig *cfgManager = SpectacleConfig::instance(); cfgManager->setUseLightRegionMaskColour(mUseLightBackground->checkState() == Qt::Checked); cfgManager->setRememberLastRectangularRegion(mRememberRect->checkState() == Qt::Checked); cfgManager->setShowMagnifierChecked(mShowMagnifier->checkState() == Qt::Checked); + cfgManager->setCopySaveLocationToClipboard(mCopyPathToClipboard->checkState() == Qt::Checked); mChangesMade = false; } void GeneralOptionsPage::resetChanges() { SpectacleConfig *cfgManager = SpectacleConfig::instance(); mUseLightBackground->setChecked(cfgManager->useLightRegionMaskColour()); mRememberRect->setChecked(cfgManager->rememberLastRectangularRegion()); mShowMagnifier->setChecked(cfgManager->showMagnifierChecked()); + mCopyPathToClipboard->setChecked(cfgManager->copySaveLocationToClipboard()); mChangesMade = false; } diff --git a/src/Gui/SettingsDialog/GeneralOptionsPage.h b/src/Gui/SettingsDialog/GeneralOptionsPage.h index 21b42c9..0315d34 100644 --- a/src/Gui/SettingsDialog/GeneralOptionsPage.h +++ b/src/Gui/SettingsDialog/GeneralOptionsPage.h @@ -1,51 +1,52 @@ /* * Copyright (C) 2015 Boudhayan Gupta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef GENERALOPTIONSPAGE_H #define GENERALOPTIONSPAGE_H #include "SettingsPage.h" class QCheckBox; class GeneralOptionsPage : public SettingsPage { Q_OBJECT public: explicit GeneralOptionsPage(QWidget *parent = nullptr); public slots: void saveChanges() Q_DECL_OVERRIDE; void resetChanges() Q_DECL_OVERRIDE; private slots: void markDirty(bool checked); private: QCheckBox *mRememberRect; QCheckBox *mUseLightBackground; + QCheckBox *mCopyPathToClipboard; QCheckBox *mShowMagnifier; }; #endif // GENERALOPTIONSPAGE_H diff --git a/src/Gui/SettingsDialog/SaveOptionsPage.cpp b/src/Gui/SettingsDialog/SaveOptionsPage.cpp index 158a55f..c2af0ad 100644 --- a/src/Gui/SettingsDialog/SaveOptionsPage.cpp +++ b/src/Gui/SettingsDialog/SaveOptionsPage.cpp @@ -1,191 +1,183 @@ /* * Copyright (C) 2015 Boudhayan Gupta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "SaveOptionsPage.h" #include "SpectacleConfig.h" #include #include #include #include #include #include #include #include -#include SaveOptionsPage::SaveOptionsPage(QWidget *parent) : SettingsPage(parent) { // set up the layout. start with the directory QGroupBox *dirGroup = new QGroupBox(i18n("Default Save Location"), this); QVBoxLayout *dirLayout = new QVBoxLayout; dirGroup->setLayout(dirLayout); QHBoxLayout *urlRequesterLayout = new QHBoxLayout; urlRequesterLayout->addWidget(new QLabel(i18n("Location:"), this)); mUrlRequester = new KUrlRequester; mUrlRequester->setMode(KFile::Directory); connect(mUrlRequester, &KUrlRequester::textChanged, this, &SaveOptionsPage::markDirty); urlRequesterLayout->addWidget(mUrlRequester); dirLayout->addLayout(urlRequesterLayout); - // copy file location to clipboard after saving - - mCopyPathToClipboard = new QCheckBox(i18n("Copy file location to clipboard after saving"), this); - connect(mCopyPathToClipboard, &QCheckBox::toggled, this, &SaveOptionsPage::markDirty); - dirLayout->addWidget(mCopyPathToClipboard, 1); - // filename chooser text field QGroupBox *fmtGroup = new QGroupBox(i18n("Default Save Filename")); QVBoxLayout *fmtLayout = new QVBoxLayout; fmtGroup->setLayout(fmtLayout); QHBoxLayout *saveNameLayout = new QHBoxLayout; saveNameLayout->addWidget(new QLabel(i18n("Filename:"), this)); mSaveNameFormat = new QLineEdit; connect(mSaveNameFormat, &QLineEdit::textEdited, this, &SaveOptionsPage::markDirty); connect(mSaveNameFormat, &QLineEdit::textEdited, [&](const QString &newText) { QString fmt; Q_FOREACH(auto item, QImageWriter::supportedImageFormats()) { fmt = QString::fromLocal8Bit(item); if (newText.endsWith(QLatin1Char('.') + fmt, Qt::CaseInsensitive)) { QString txtCopy = newText; txtCopy.chop(fmt.length() + 1); mSaveNameFormat->setText(txtCopy); mSaveImageFormat->setCurrentIndex(mSaveImageFormat->findText(fmt.toUpper())); } } }); saveNameLayout->addWidget(mSaveNameFormat); mSaveImageFormat = new QComboBox; mSaveImageFormat->addItems([&](){ QStringList items; Q_FOREACH(auto fmt, QImageWriter::supportedImageFormats()) { items.append(QString::fromLocal8Bit(fmt).toUpper()); } return items; }()); connect(mSaveImageFormat, &QComboBox::currentTextChanged, this, &SaveOptionsPage::markDirty); saveNameLayout->addWidget(mSaveImageFormat); fmtLayout->addLayout(saveNameLayout); // now the save filename format layout const QString helpText = i18nc("%1 is the default filename of a screenshot", "

You can use the following placeholders in the filename, which will be replaced " "with actual text when the file is saved:

" "
" "%Y: Year (4 digit)
" "%y: Year (2 digit)
" "%M: Month
" "%D: Day
" "%H: Hour
" "%m: Minute
" "%S: Second
" "%T: Window title" "
" "

To save to a sub-folder, use slashes to describe the desired path, e.g.:

" "
" "%Y/%M/%1" "
", SpectacleConfig::instance()->defaultFilename() + SpectacleConfig::instance()->defaultTimestampTemplate() ); QLabel *fmtHelpText = new QLabel(helpText, this); fmtHelpText->setWordWrap(true); fmtHelpText->setTextFormat(Qt::RichText); fmtHelpText->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); fmtLayout->addWidget(fmtHelpText); // read in the data resetChanges(); // finish up with the main layout QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->addWidget(dirGroup); mainLayout->addWidget(fmtGroup); mainLayout->addStretch(4); setLayout(mainLayout); } -void SaveOptionsPage::markDirty() +void SaveOptionsPage::markDirty(const QString &text) { + Q_UNUSED(text); mChangesMade = true; } void SaveOptionsPage::saveChanges() { // bring up the configuration reader SpectacleConfig *cfgManager = SpectacleConfig::instance(); // save the data cfgManager->setAutoSaveLocation(mUrlRequester->url().toDisplayString(QUrl::PreferLocalFile)); cfgManager->setAutoSaveFilenameFormat(mSaveNameFormat->text()); cfgManager->setSaveImageFormat(mSaveImageFormat->currentText().toLower()); - cfgManager->setCopySaveLocationToClipboard(mCopyPathToClipboard->checkState() == Qt::Checked); // done mChangesMade = false; } void SaveOptionsPage::resetChanges() { // bring up the configuration reader SpectacleConfig *cfgManager = SpectacleConfig::instance(); // read in the data mSaveNameFormat->setText(cfgManager->autoSaveFilenameFormat()); mUrlRequester->setUrl(QUrl::fromUserInput(cfgManager->autoSaveLocation())); - mCopyPathToClipboard->setChecked(cfgManager->copySaveLocationToClipboard()); // read in the save image format and calculate its index { int index = mSaveImageFormat->findText(cfgManager->saveImageFormat().toUpper()); if (index >= 0) { mSaveImageFormat->setCurrentIndex(index); } } // done mChangesMade = false; } diff --git a/src/Gui/SettingsDialog/SaveOptionsPage.h b/src/Gui/SettingsDialog/SaveOptionsPage.h index a0f6f7e..ec6f2f9 100644 --- a/src/Gui/SettingsDialog/SaveOptionsPage.h +++ b/src/Gui/SettingsDialog/SaveOptionsPage.h @@ -1,58 +1,55 @@ /* * Copyright (C) 2015 Boudhayan Gupta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef SAVEOPTIONSPAGE_H #define SAVEOPTIONSPAGE_H #include "SettingsPage.h" class QDialogButtonBox; class QLineEdit; class QComboBox; class KUrlRequester; -class QCheckBox; class SaveOptionsPage : public SettingsPage { Q_OBJECT public: explicit SaveOptionsPage(QWidget *parent = nullptr); public slots: void saveChanges() Q_DECL_OVERRIDE; void resetChanges() Q_DECL_OVERRIDE; private slots: - void markDirty(); + void markDirty(const QString &text); private: QDialogButtonBox *mDialogButtonBox; QLineEdit *mSaveNameFormat; KUrlRequester *mUrlRequester; QComboBox *mSaveImageFormat; - QCheckBox *mCopyPathToClipboard; - }; #endif // SAVEOPTIONSPAGE_H