Changeset View
Changeset View
Standalone View
Standalone View
src/Gui/SettingsDialog/GeneralOptionsPage.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright 2019 David Redondo <kde@david-redondo.de> | ||||
2 | * Copyright (C) 2015 Boudhayan Gupta <bgupta@kde.org> | 3 | * Copyright (C) 2015 Boudhayan Gupta <bgupta@kde.org> | ||
3 | * | 4 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU Lesser General Public License as published by | 6 | * it under the terms of the GNU Lesser General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | 7 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | 8 | * (at your option) any later version. | ||
8 | * | 9 | * | ||
9 | * This program is distributed in the hope that it will be useful, | 10 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | 13 | * GNU General Public License for more details. | ||
13 | * | 14 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public License | 15 | * You should have received a copy of the GNU Lesser General Public License | ||
15 | * along with this program; if not, write to the Free Software | 16 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | * Boston, MA 02110-1301, USA. | 18 | * Boston, MA 02110-1301, USA. | ||
18 | */ | 19 | */ | ||
19 | 20 | | |||
20 | #include "GeneralOptionsPage.h" | 21 | #include "GeneralOptionsPage.h" | ||
21 | 22 | | |||
22 | #include "SpectacleConfig.h" | | |||
23 | | ||||
24 | #include <KLocalizedString> | 23 | #include <KLocalizedString> | ||
25 | #include <KTitleWidget> | 24 | #include <KTitleWidget> | ||
26 | #include <KWindowSystem> | 25 | #include <KWindowSystem> | ||
27 | 26 | | |||
28 | #include <QButtonGroup> | 27 | #include <QButtonGroup> | ||
29 | #include <QCheckBox> | 28 | #include <QCheckBox> | ||
29 | #include <QLineEdit> | ||||
30 | #include <QFormLayout> | 30 | #include <QFormLayout> | ||
31 | #include <QRadioButton> | 31 | #include <QRadioButton> | ||
32 | #include <QSpacerItem> | 32 | #include <QSpacerItem> | ||
33 | #include <QTextEdit> | ||||
33 | 34 | | |||
34 | GeneralOptionsPage::GeneralOptionsPage(QWidget *parent) : | 35 | GeneralOptionsPage::GeneralOptionsPage(QWidget *parent) : | ||
35 | SettingsPage(parent) | 36 | QWidget{parent} | ||
36 | { | 37 | { | ||
37 | QFormLayout *mainLayout = new QFormLayout(this); | 38 | QFormLayout *mainLayout = new QFormLayout(this); | ||
38 | setLayout(mainLayout); | 39 | setLayout(mainLayout); | ||
39 | 40 | | |||
40 | // When spectacle is running settings | 41 | // When spectacle is running settings | ||
41 | KTitleWidget* runningTitle = new KTitleWidget(this); | 42 | KTitleWidget* runningTitle = new KTitleWidget(this); | ||
42 | runningTitle->setText(i18n("When Spectacle is Running")); | 43 | runningTitle->setText(i18n("When Spectacle is Running")); | ||
43 | runningTitle->setLevel(2); | 44 | runningTitle->setLevel(2); | ||
44 | mainLayout->addRow(runningTitle); | 45 | mainLayout->addRow(runningTitle); | ||
45 | QRadioButton* takeNew = new QRadioButton(i18n("Take a new screenshot"), this); | 46 | QRadioButton* takeNew = new QRadioButton(i18n("Take a new screenshot"), this); | ||
46 | QRadioButton* startNewInstance = new QRadioButton(i18n("Open a new Spectacle window"), this); | 47 | QRadioButton* startNewInstance = new QRadioButton(i18n("Open a new Spectacle window"), this); | ||
47 | mPrintKeyActionGroup = new QButtonGroup(this); | 48 | QButtonGroup* printKeyActionGroup = new QButtonGroup(this); | ||
48 | mPrintKeyActionGroup->setExclusive(true); | 49 | printKeyActionGroup->setExclusive(true); | ||
49 | mPrintKeyActionGroup->addButton(takeNew, SpectacleConfig::PrintKeyActionRunning::TakeNewScreenshot); | 50 | printKeyActionGroup->addButton(takeNew,0);// SpectacleConfig::PrintKeyActionRunning::TakeNewScreenshot); | ||
50 | mPrintKeyActionGroup->addButton(startNewInstance, SpectacleConfig::PrintKeyActionRunning::StartNewInstance); | 51 | printKeyActionGroup->addButton(startNewInstance,1);// SpectacleConfig::PrintKeyActionRunning::StartNewInstance); | ||
51 | connect( mPrintKeyActionGroup, qOverload<int, bool>(&QButtonGroup::buttonToggled), this, &GeneralOptionsPage::markDirty); | | |||
52 | mainLayout->addRow(i18n("Press screenshot key to:"), takeNew); | 52 | mainLayout->addRow(i18n("Press screenshot key to:"), takeNew); | ||
53 | mainLayout->addRow(QString(), startNewInstance); | 53 | mainLayout->addRow(QString(), startNewInstance); | ||
54 | //On Wayland we can't programmatically raise and focus the window so we have to hide the option | 54 | //On Wayland we can't programmatically raise and focus the window so we have to hide the option | ||
55 | if (!(KWindowSystem::isPlatformWayland() || qstrcmp(qgetenv("XDG_SESSION_TYPE"), "wayland") == 0)) { | 55 | if (!(KWindowSystem::isPlatformWayland() || qstrcmp(qgetenv("XDG_SESSION_TYPE"), "wayland") == 0)) { | ||
56 | QRadioButton* focusWindow = new QRadioButton(i18n("Return focus to Spectacle"), this); | 56 | QRadioButton* focusWindow = new QRadioButton(i18n("Return focus to Spectacle"), this); | ||
57 | mPrintKeyActionGroup->addButton( focusWindow, SpectacleConfig::PrintKeyActionRunning::FocusWindow); | 57 | printKeyActionGroup->addButton( focusWindow,2);// SpectacleConfig::PrintKeyActionRunning::FocusWindow); | ||
58 | mainLayout->addRow(QString(), focusWindow); | 58 | mainLayout->addRow(QString(), focusWindow); | ||
59 | } | 59 | } | ||
60 | 60 | | |||
61 | //Workaround because KConfigWidgets doesn't support QButtonGroup (Bug 409037) | ||||
62 | auto workaroundLabel = new QLineEdit(this); | ||||
63 | workaroundLabel->setHidden(true); | ||||
64 | workaroundLabel->setObjectName(QStringLiteral("kcfg_printKeyActionRunning")); | ||||
65 | // Need to check default Button because we get no change event for that | ||||
66 | takeNew->setChecked(true); | ||||
67 | connect(workaroundLabel, &QLineEdit::textChanged, | ||||
68 | printKeyActionGroup, [printKeyActionGroup, takeNew](const QString& text){ | ||||
69 | auto button = printKeyActionGroup->button(text.toInt()); | ||||
70 | // We are missing a button on Wayland | ||||
71 | button ? button->setChecked(true) : takeNew->setChecked(true); | ||||
72 | }); | ||||
73 | connect(printKeyActionGroup, qOverload<int, bool>(&QButtonGroup::buttonToggled), | ||||
74 | workaroundLabel, [workaroundLabel] (int value, bool checked) { | ||||
75 | if (checked) { | ||||
76 | workaroundLabel->setText(QString::number(value)); | ||||
77 | } | ||||
78 | }); | ||||
79 | // /Workaround | ||||
80 | | ||||
61 | mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); | 81 | mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); | ||
62 | 82 | | |||
63 | // actions to take after taking a screenshot | 83 | // actions to take after taking a screenshot | ||
64 | mCopyImageToClipboard = new QCheckBox(i18n("Copy image to clipboard"), this); | 84 | auto copyImageToClipboard = new QCheckBox(i18n("Copy image to clipboard"), this); | ||
65 | connect(mCopyImageToClipboard, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty); | 85 | copyImageToClipboard->setObjectName(QStringLiteral("kcfg_copyImageToClipboard")); | ||
66 | mainLayout->addRow(i18n("After taking a screenshot:"), mCopyImageToClipboard); | 86 | mainLayout->addRow(i18n("After taking a screenshot:"), copyImageToClipboard); | ||
67 | 87 | | |||
68 | mAutoSaveImage = new QCheckBox(i18n("Autosave the image to the default location"), this); | 88 | auto autoSaveImage = new QCheckBox(i18n("Autosave the image to the default location"), this); | ||
69 | connect(mAutoSaveImage, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty); | 89 | autoSaveImage->setObjectName(QStringLiteral("kcfg_autoSaveImage")); | ||
70 | mainLayout->addRow(QString(), mAutoSaveImage); | 90 | mainLayout->addRow(QString(), autoSaveImage); | ||
71 | 91 | | |||
72 | mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); | 92 | mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); | ||
73 | 93 | | |||
74 | // Rectangular Region settings | 94 | // Rectangular Region settings | ||
75 | KTitleWidget *titleWidget = new KTitleWidget(this); | 95 | KTitleWidget *titleWidget = new KTitleWidget(this); | ||
76 | titleWidget->setText(i18n("Rectangular Region")); | 96 | titleWidget->setText(i18n("Rectangular Region")); | ||
77 | titleWidget->setLevel(2); | 97 | titleWidget->setLevel(2); | ||
78 | mainLayout->addRow(titleWidget); | 98 | mainLayout->addRow(titleWidget); | ||
79 | 99 | | |||
80 | // use light background | 100 | // use light background | ||
81 | mUseLightBackground = new QCheckBox(i18n("Use light background"), this); | 101 | QCheckBox* kcfg_useLightMaskColour = new QCheckBox(i18n("Use light background"), this); | ||
82 | connect(mUseLightBackground, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty); | 102 | kcfg_useLightMaskColour->setObjectName(QStringLiteral("kcfg_useLightMaskColour")); | ||
83 | mainLayout->addRow(i18n("General:"), mUseLightBackground); | 103 | mainLayout->addRow(i18n("General:"), kcfg_useLightMaskColour); | ||
84 | 104 | | |||
85 | // show magnifier | 105 | // show magnifier | ||
86 | mShowMagnifier = new QCheckBox(i18n("Show magnifier"), this); | 106 | auto showMagnifier = new QCheckBox(i18n("Show magnifier"), this); | ||
87 | connect(mShowMagnifier, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty); | 107 | showMagnifier->setObjectName(QStringLiteral("kcfg_showMagnifier")); | ||
88 | mainLayout->addRow(QString(), mShowMagnifier); | 108 | mainLayout->addRow(QString(), showMagnifier); | ||
89 | 109 | | |||
90 | // release mouse-button to capture | 110 | // release mouse-button to capture | ||
91 | mReleaseToCapture = new QCheckBox(i18n("Accept on click-and-release"), this); | 111 | auto releaseToCapture = new QCheckBox(i18n("Accept on click-and-release"), this); | ||
92 | connect(mReleaseToCapture, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty); | 112 | releaseToCapture->setObjectName(QStringLiteral("kcfg_useReleaseToCapture")); | ||
93 | mainLayout->addRow(QString(), mReleaseToCapture); | 113 | mainLayout->addRow(QString(), releaseToCapture); | ||
94 | 114 | | |||
95 | mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); | 115 | mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); | ||
96 | 116 | | |||
97 | // remember Rectangular Region box | 117 | // remember Rectangular Region box | ||
98 | QButtonGroup* rememberGroup = new QButtonGroup(this); | 118 | QButtonGroup* rememberGroup = new QButtonGroup(this); | ||
99 | rememberGroup->setExclusive(true); | 119 | rememberGroup->setExclusive(true); | ||
100 | QRadioButton* neverButton = new QRadioButton(i18n("Never"), this); | 120 | QRadioButton* neverButton = new QRadioButton(i18n("Never"), this); | ||
101 | mRememberAlways = new QRadioButton(i18n("Always"), this); | 121 | auto rememberAlways = new QRadioButton(i18n("Always"), this); | ||
102 | mRememberUntilClosed = new QRadioButton(i18n("Until Spectacle is closed"), this); | 122 | rememberAlways->setObjectName(QStringLiteral("kcfg_alwaysRememberRegion")); | ||
123 | auto rememberUntilClosed = new QRadioButton(i18n("Until Spectacle is closed"), this); | ||||
124 | rememberUntilClosed->setObjectName(QStringLiteral("kcfg_rememberLastRectangularRegion")); | ||||
103 | rememberGroup->addButton(neverButton); | 125 | rememberGroup->addButton(neverButton); | ||
104 | rememberGroup->addButton(mRememberAlways); | 126 | rememberGroup->addButton(rememberAlways); | ||
105 | rememberGroup->addButton(mRememberUntilClosed); | 127 | rememberGroup->addButton(rememberUntilClosed); | ||
106 | neverButton->setChecked(true); | | |||
107 | connect(rememberGroup, qOverload<QAbstractButton *, bool>(&QButtonGroup::buttonToggled), this, &GeneralOptionsPage::markDirty); | | |||
108 | mainLayout->addRow(i18n("Remember selected area:"), neverButton); | 128 | mainLayout->addRow(i18n("Remember selected area:"), neverButton); | ||
109 | mainLayout->addRow(QString(), mRememberAlways); | | |||
110 | mainLayout->addRow(QString(), mRememberUntilClosed ); | | |||
111 | | ||||
112 | // read in the data | | |||
113 | resetChanges(); | | |||
114 | } | | |||
115 | | ||||
116 | void GeneralOptionsPage::markDirty() | | |||
117 | { | | |||
118 | mChangesMade = true; | | |||
119 | } | | |||
120 | | ||||
121 | void GeneralOptionsPage::saveChanges() | | |||
122 | { | | |||
123 | SpectacleConfig *cfgManager = SpectacleConfig::instance(); | | |||
124 | | ||||
125 | cfgManager->setUseLightRegionMaskColour(mUseLightBackground->checkState() == Qt::Checked); | | |||
126 | cfgManager->setRememberLastRectangularRegion(mRememberUntilClosed->isChecked() || mRememberAlways->isChecked()); | | |||
127 | cfgManager->setAlwaysRememberRegion (mRememberAlways->isChecked()); | | |||
128 | cfgManager->setShowMagnifierChecked(mShowMagnifier->checkState() == Qt::Checked); | | |||
129 | cfgManager->setUseReleaseToCaptureChecked(mReleaseToCapture->checkState() == Qt::Checked); | | |||
130 | cfgManager->setPrintKeyActionRunning(static_cast<SpectacleConfig::PrintKeyActionRunning>(mPrintKeyActionGroup->checkedId())); | | |||
131 | cfgManager->setCopyImageToClipboard(mCopyImageToClipboard->checkState() == Qt::Checked); | | |||
132 | cfgManager->setAutoSaveImage(mAutoSaveImage->checkState() == Qt::Checked); | | |||
133 | | ||||
134 | mChangesMade = false; | | |||
135 | } | | |||
136 | | ||||
137 | void GeneralOptionsPage::resetChanges() | | |||
138 | { | | |||
139 | SpectacleConfig *cfgManager = SpectacleConfig::instance(); | | |||
140 | | ||||
141 | mUseLightBackground->setChecked(cfgManager->useLightRegionMaskColour()); | | |||
142 | mRememberUntilClosed->setChecked(cfgManager->rememberLastRectangularRegion()); | | |||
143 | mRememberAlways->setChecked(cfgManager->alwaysRememberRegion()); | | |||
144 | mShowMagnifier->setChecked(cfgManager->showMagnifierChecked()); | | |||
145 | mReleaseToCapture->setChecked(cfgManager->useReleaseToCapture()); | | |||
146 | mPrintKeyActionGroup->button(cfgManager->printKeyActionRunning())->setChecked(true); | | |||
147 | mCopyImageToClipboard->setChecked(cfgManager->copyImageToClipboard()); | | |||
148 | mAutoSaveImage->setChecked(cfgManager->autoSaveImage()); | | |||
149 | 129 | | |||
150 | mChangesMade = false; | 130 | mainLayout->addRow(QString(), rememberAlways); | ||
131 | mainLayout->addRow(QString(), rememberUntilClosed); | ||||
151 | } | 132 | } |