diff --git a/src/Gui/SettingsDialog/GeneralOptionsPage.cpp b/src/Gui/SettingsDialog/GeneralOptionsPage.cpp index 2d76a63..f13dcb5 100644 --- a/src/Gui/SettingsDialog/GeneralOptionsPage.cpp +++ b/src/Gui/SettingsDialog/GeneralOptionsPage.cpp @@ -1,102 +1,82 @@ /* * 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 -#include GeneralOptionsPage::GeneralOptionsPage(QWidget *parent) : SettingsPage(parent) { - // preamble and stuff - - QVBoxLayout *mainLayout = new QVBoxLayout(this); + QFormLayout *mainLayout = new QFormLayout(this); + setLayout(mainLayout); // 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); + mainLayout->addRow(i18n("Rectangular Region:"), mUseLightBackground); // remember Rectangular Region box - mRememberRect = new QCheckBox(i18n("Remember selected area"), this); connect(mRememberRect, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty); + mainLayout->addRow(QString(), mRememberRect); // 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); + mainLayout->addRow(QString(), mShowMagnifier); // read in the data - resetChanges(); - - // finish up with the main layout - - mainLayout->addStretch(4); - setLayout(mainLayout); } void GeneralOptionsPage::markDirty() { 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); mChangesMade = false; } void GeneralOptionsPage::resetChanges() { SpectacleConfig *cfgManager = SpectacleConfig::instance(); mUseLightBackground->setChecked(cfgManager->useLightRegionMaskColour()); mRememberRect->setChecked(cfgManager->rememberLastRectangularRegion()); mShowMagnifier->setChecked(cfgManager->showMagnifierChecked()); mChangesMade = false; } diff --git a/src/Gui/SettingsDialog/SaveOptionsPage.cpp b/src/Gui/SettingsDialog/SaveOptionsPage.cpp index 158a55f..9825527 100644 --- a/src/Gui/SettingsDialog/SaveOptionsPage.cpp +++ b/src/Gui/SettingsDialog/SaveOptionsPage.cpp @@ -1,191 +1,173 @@ /* * 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 #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)); + QFormLayout *mainLayout = new QFormLayout; + setLayout(mainLayout); + // Save location mUrlRequester = new KUrlRequester; mUrlRequester->setMode(KFile::Directory); connect(mUrlRequester, &KUrlRequester::textChanged, this, &SaveOptionsPage::markDirty); - urlRequesterLayout->addWidget(mUrlRequester); - - dirLayout->addLayout(urlRequesterLayout); + mainLayout->addRow(i18n("Save Location:"), mUrlRequester); // 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); + mainLayout->addRow(QString(), mCopyPathToClipboard); - // filename chooser text field - QGroupBox *fmtGroup = new QGroupBox(i18n("Default Save Filename")); - QVBoxLayout *fmtLayout = new QVBoxLayout; - fmtGroup->setLayout(fmtLayout); + mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); + - QHBoxLayout *saveNameLayout = new QHBoxLayout; - saveNameLayout->addWidget(new QLabel(i18n("Filename:"), this)); + // filename chooser and instructional text + QVBoxLayout *saveNameLayout = new QVBoxLayout; + // filename chooser text field + QHBoxLayout *saveFieldLayout = new QHBoxLayout; 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); + saveFieldLayout->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); + saveFieldLayout->addWidget(mSaveImageFormat); + saveNameLayout->addLayout(saveFieldLayout); // 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.:

" + "

To save to a sub-folder, use slashes, 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); + fmtHelpText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); + saveNameLayout->addWidget(fmtHelpText); + mainLayout->addRow(i18n("Filename:"), saveNameLayout); - // read in the data + // 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() { 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; }