GeneralOptionsPage.cpp 6.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
/*
 *  Copyright (C) 2015 Boudhayan Gupta <bgupta@kde.org>
 *
 *  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 <QGroupBox>
#include <QVBoxLayout>
#include <QLabel>
#include <QCheckBox>

#include <KLocalizedString>

#include "SpectacleConfig.h"

GeneralOptionsPage::GeneralOptionsPage(QWidget *parent) :
    SettingsPage(parent)
{
    // preamble and stuff

    QVBoxLayout *mainLayout = new QVBoxLayout(this);

    // dynamic save button

    QGroupBox *dsGroup = new QGroupBox(i18n("Dynamic Save Button"));
    QVBoxLayout *dsLayout = new QVBoxLayout;
    dsGroup->setLayout(dsLayout);
    dsGroup->setStyleSheet(QStringLiteral("QGroupBox { font-weight: bold; }"));

    QLabel *dsHelpText = new QLabel;
    dsHelpText->setWordWrap(true);
    dsHelpText->setText(i18n("The default behavior of the save button is to <b>Save & Exit</b>. Enable this "
                             "option to change the save button to either <b>Save</b>, <b>Save As</b> or "
                             "<b>Save & Exit</b>, according to the save action you perform, every time you "
                             "save an image."));
    dsLayout->addWidget(dsHelpText);

    mUseLastSaveAction = new QCheckBox;
    mUseLastSaveAction->setText(i18n("Set save button action to last used save method"));
    connect(mUseLastSaveAction, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty);

    QVBoxLayout *dsCLayout = new QVBoxLayout;
    dsCLayout->setContentsMargins(15, 10, 0, 10);
    dsCLayout->addWidget(mUseLastSaveAction);
    dsLayout->addLayout(dsCLayout);
    mainLayout->addWidget(dsGroup, 1);

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    // copy save path to clipboard

    QGroupBox *cpGroup = new QGroupBox(i18n("Copy Save Location to Clipboard"));
    QVBoxLayout *cpLayout = new QVBoxLayout;
    cpGroup->setLayout(cpLayout);
    cpGroup->setStyleSheet(QStringLiteral("QGroupBox { font-weight: bold; }"));

    QLabel *cpHelpText = new QLabel;
    cpHelpText->setWordWrap(true);
    cpHelpText->setText(i18n("When a screenshot is saved, copy the location at which the file was saved "
                             "to the clipboard. You can then paste it anywhere that accepts text input. "
                             "Note that you must be running a clipboard manager in order to keep the path "
                             "in the clipboard after Spectacle quits."));
    cpLayout->addWidget(cpHelpText);

    mCopyPathToClipboard = new QCheckBox;
    mCopyPathToClipboard->setText(i18n("Copy save location to the clipboard"));
    connect(mCopyPathToClipboard, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty);

    QVBoxLayout *cpCLayout = new QVBoxLayout;
    cpCLayout->setContentsMargins(15, 10, 0, 10);
    cpCLayout->addWidget(mCopyPathToClipboard);
    cpLayout->addLayout(cpCLayout);
    mainLayout->addWidget(cpGroup, 1);

88 89 90 91 92 93 94 95 96 97
    // use a light background for the rectangular region grabber

    QGroupBox *lbGroup = new QGroupBox(i18n("Light Background For Rectangular Region"));
    QVBoxLayout *lbLayout = new QVBoxLayout;
    lbGroup->setLayout(lbLayout);
    lbGroup->setStyleSheet(QStringLiteral("QGroupBox { font-weight: bold; }"));

    QLabel *lbHelpText = new QLabel;
    lbHelpText->setWordWrap(true);
    lbHelpText->setText(i18n("Use a light background color to mask the cropped-out area in the rectangular "
98
                             "region selector. This may make dark cursors easier to see."));
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    lbLayout->addWidget(lbHelpText);

    mUseLightBackground = new QCheckBox;
    mUseLightBackground->setText(i18n("Use light background color"));
    connect(mUseLightBackground, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty);

    QVBoxLayout *lbCLayout = new QVBoxLayout;
    lbCLayout->setContentsMargins(15, 10, 0, 10);
    lbCLayout->addWidget(mUseLightBackground);
    lbLayout->addLayout(lbCLayout);
    mainLayout->addWidget(lbGroup, 1);

    // remember rectangular region

    QGroupBox *rrGroup = new QGroupBox(i18n("Remember Rectangular Region"));
    QVBoxLayout *rrLayout = new QVBoxLayout;
    rrGroup->setLayout(rrLayout);
    rrGroup->setStyleSheet(QStringLiteral("QGroupBox { font-weight: bold; }"));

    QLabel *rrHelpText = new QLabel;
    rrHelpText->setWordWrap(true);
120 121 122
    rrHelpText->setText(i18n("By default, Spectacle does not show an initial selection when you take a "
                             "screenshot of a rectangular region. Enable this option to remember the last "
                             "selected region of the screen, and set it as the initial selection when you "
123 124 125 126 127 128 129 130 131 132 133 134 135
                             "use the rectangular region selector the next time."));
    rrLayout->addWidget(rrHelpText);

    mRememberRect = new QCheckBox;
    mRememberRect->setText(i18n("Remember rectangular region"));
    connect(mRememberRect, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty);

    QVBoxLayout *rrCLayout = new QVBoxLayout;
    rrCLayout->setContentsMargins(15, 10, 0, 10);
    rrCLayout->addWidget(mRememberRect);
    rrLayout->addLayout(rrCLayout);
    mainLayout->addWidget(rrGroup, 1);

136 137 138 139
    // read in the data

    resetChanges();

140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
    // 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->setUseDynamicSaveButton(mUseLastSaveAction->checkState() == Qt::Checked);
    cfgManager->setUseLightRegionMaskColour(mUseLightBackground->checkState() == Qt::Checked);
    cfgManager->setRememberLastRectangularRegion(mRememberRect->checkState() == Qt::Checked);
159
    cfgManager->setCopySaveLocationToClipboard(mCopyPathToClipboard->checkState() == Qt::Checked);
160 161

    mChangesMade = false;
162
}
163 164 165 166 167 168 169 170

void GeneralOptionsPage::resetChanges()
{
    SpectacleConfig *cfgManager = SpectacleConfig::instance();

    mUseLastSaveAction->setChecked(cfgManager->useDynamicSaveButton());
    mUseLightBackground->setChecked(cfgManager->useLightRegionMaskColour());
    mRememberRect->setChecked(cfgManager->rememberLastRectangularRegion());
171
    mCopyPathToClipboard->setChecked(cfgManager->copySaveLocationToClipboard());
172 173 174

    mChangesMade = false;
}