Changeset View
Changeset View
Standalone View
Standalone View
src/Gui/KSWidget.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 "KSWidget.h" | 21 | #include "KSWidget.h" | ||
21 | #include "spectacle_gui_debug.h" | 22 | #include "spectacle_gui_debug.h" | ||
22 | 23 | | |||
23 | #include "KSImageWidget.h" | 24 | #include "KSImageWidget.h" | ||
25 | #include "settings.h" | ||||
24 | #include "SmartSpinBox.h" | 26 | #include "SmartSpinBox.h" | ||
25 | #include "SpectacleConfig.h" | | |||
26 | #include "ProgressButton.h" | 27 | #include "ProgressButton.h" | ||
27 | 28 | | |||
28 | #include <QAction> | 29 | #include <QAction> | ||
29 | #include <QApplication> | 30 | #include <QApplication> | ||
30 | #include <QCheckBox> | 31 | #include <QCheckBox> | ||
31 | #include <QComboBox> | 32 | #include <QComboBox> | ||
32 | #include <QFormLayout> | 33 | #include <QFormLayout> | ||
33 | #include <QGridLayout> | 34 | #include <QGridLayout> | ||
34 | #include <QLabel> | 35 | #include <QLabel> | ||
35 | #include <QShortcut> | 36 | #include <QShortcut> | ||
36 | #include <QToolButton> | 37 | #include <QToolButton> | ||
37 | 38 | | |||
38 | #include <KLocalizedString> | 39 | #include <KLocalizedString> | ||
39 | 40 | | |||
40 | KSWidget::KSWidget(const Platform::GrabModes &theGrabModes, QWidget *parent) : | 41 | KSWidget::KSWidget(const Platform::GrabModes &theGrabModes, QWidget *parent) : | ||
41 | QWidget(parent) | 42 | QWidget(parent) | ||
42 | { | 43 | { | ||
43 | // get a handle to the configuration manager | | |||
44 | SpectacleConfig *lConfigMgr = SpectacleConfig::instance(); | | |||
45 | | ||||
46 | // we'll init the widget that holds the image first | 44 | // we'll init the widget that holds the image first | ||
47 | mImageWidget = new KSImageWidget(this); | 45 | mImageWidget = new KSImageWidget(this); | ||
48 | mImageWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | 46 | mImageWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | ||
49 | connect(mImageWidget, &KSImageWidget::dragInitiated, this, &KSWidget::dragInitiated); | 47 | connect(mImageWidget, &KSImageWidget::dragInitiated, this, &KSWidget::dragInitiated); | ||
50 | 48 | | |||
51 | // the capture mode options first | 49 | // the capture mode options first | ||
52 | mCaptureModeLabel = new QLabel(i18n("<b>Capture Mode</b>"), this); | 50 | mCaptureModeLabel = new QLabel(i18n("<b>Capture Mode</b>"), this); | ||
53 | mCaptureArea = new QComboBox(this); | 51 | mCaptureArea = new QComboBox(this); | ||
54 | QString lFullScreenLabel = QApplication::screens().count() == 1 | 52 | QString lFullScreenLabel = QApplication::screens().count() == 1 | ||
55 | ? i18n("Full Screen") | 53 | ? i18n("Full Screen") | ||
56 | : i18n("Full Screen (All Monitors)"); | 54 | : i18n("Full Screen (All Monitors)"); | ||
57 | 55 | | |||
58 | if (theGrabModes.testFlag(Platform::GrabMode::AllScreens)) | 56 | if (theGrabModes.testFlag(Platform::GrabMode::AllScreens)) { | ||
59 | mCaptureArea->insertItem(1, lFullScreenLabel, Spectacle::CaptureMode::AllScreens); | 57 | mCaptureArea->insertItem(0, lFullScreenLabel, Spectacle::CaptureMode::AllScreens); | ||
60 | if (theGrabModes.testFlag(Platform::GrabMode::CurrentScreen)) | 58 | mCaptureArea->insertItem(1, i18n("Rectangular Region"), Spectacle::CaptureMode::RectangularRegion); | ||
59 | } | ||||
60 | if (theGrabModes.testFlag(Platform::GrabMode::CurrentScreen)) { | ||||
61 | mCaptureArea->insertItem(2, i18n("Current Screen"), Spectacle::CaptureMode::CurrentScreen); | 61 | mCaptureArea->insertItem(2, i18n("Current Screen"), Spectacle::CaptureMode::CurrentScreen); | ||
62 | if (theGrabModes.testFlag(Platform::GrabMode::ActiveWindow)) | 62 | } | ||
63 | if (theGrabModes.testFlag(Platform::GrabMode::ActiveWindow)) { | ||||
63 | mCaptureArea->insertItem(3, i18n("Active Window"), Spectacle::CaptureMode::ActiveWindow); | 64 | mCaptureArea->insertItem(3, i18n("Active Window"), Spectacle::CaptureMode::ActiveWindow); | ||
64 | if (theGrabModes.testFlag(Platform::GrabMode::WindowUnderCursor)) | 65 | } | ||
66 | if (theGrabModes.testFlag(Platform::GrabMode::WindowUnderCursor)) { | ||||
65 | mCaptureArea->insertItem(4, i18n("Window Under Cursor"), Spectacle::CaptureMode::WindowUnderCursor); | 67 | mCaptureArea->insertItem(4, i18n("Window Under Cursor"), Spectacle::CaptureMode::WindowUnderCursor); | ||
68 | } | ||||
66 | if (theGrabModes.testFlag(Platform::GrabMode::TransientWithParent)) { | 69 | if (theGrabModes.testFlag(Platform::GrabMode::TransientWithParent)) { | ||
67 | mTransientWithParentAvailable = true; | 70 | mTransientWithParentAvailable = true; | ||
68 | } | 71 | } | ||
69 | mCaptureArea->insertItem(5, i18n("Rectangular Region"), Spectacle::CaptureMode::RectangularRegion); | | |||
70 | mCaptureArea->setMinimumWidth(240); | 72 | mCaptureArea->setMinimumWidth(240); | ||
73 | int index = mCaptureArea->findData(Settings::captureMode()); | ||||
74 | mCaptureArea->setCurrentIndex(index >= 0 ? index : 0); | ||||
71 | connect(mCaptureArea, qOverload<int>(&QComboBox::currentIndexChanged), this, &KSWidget::captureModeChanged); | 75 | connect(mCaptureArea, qOverload<int>(&QComboBox::currentIndexChanged), this, &KSWidget::captureModeChanged); | ||
72 | 76 | | |||
73 | mDelayMsec = new SmartSpinBox(this); | 77 | mDelayMsec = new SmartSpinBox(this); | ||
74 | mDelayMsec->setDecimals(1); | 78 | mDelayMsec->setDecimals(1); | ||
75 | mDelayMsec->setSingleStep(1.0); | 79 | mDelayMsec->setSingleStep(1.0); | ||
76 | mDelayMsec->setMinimum(0.0); | 80 | mDelayMsec->setMinimum(0.0); | ||
77 | mDelayMsec->setMaximum(999.9); | 81 | mDelayMsec->setMaximum(999.9); | ||
78 | mDelayMsec->setSpecialValueText(i18n("No Delay")); | 82 | mDelayMsec->setSpecialValueText(i18n("No Delay")); | ||
79 | mDelayMsec->setMinimumWidth(160); | 83 | mDelayMsec->setMinimumWidth(160); | ||
80 | connect(mDelayMsec, qOverload<qreal>(&SmartSpinBox::valueChanged), lConfigMgr, &SpectacleConfig::setCaptureDelay); | 84 | connect(mDelayMsec, qOverload<qreal>(&SmartSpinBox::valueChanged), &Settings::setCaptureDelay); | ||
81 | 85 | | |||
82 | mCaptureOnClick = new QCheckBox(i18n("On Click"), this); | 86 | mCaptureOnClick = new QCheckBox(i18n("On Click"), this); | ||
83 | mCaptureOnClick->setToolTip(i18n("Wait for a mouse click before capturing the screenshot image")); | 87 | mCaptureOnClick->setToolTip(i18n("Wait for a mouse click before capturing the screenshot image")); | ||
84 | connect(mCaptureOnClick, &QCheckBox::stateChanged, this, &KSWidget::onClickStateChanged); | 88 | connect(mCaptureOnClick, &QCheckBox::stateChanged, this, &KSWidget::onClickStateChanged); | ||
85 | connect(mCaptureOnClick, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setOnClickChecked); | 89 | connect(mCaptureOnClick, &QCheckBox::clicked, &Settings::setOnClickChecked); | ||
86 | 90 | | |||
87 | mDelayLayout = new QHBoxLayout; | 91 | mDelayLayout = new QHBoxLayout; | ||
88 | mDelayLayout->addWidget(mDelayMsec); | 92 | mDelayLayout->addWidget(mDelayMsec); | ||
89 | mDelayLayout->addWidget(mCaptureOnClick); | 93 | mDelayLayout->addWidget(mCaptureOnClick); | ||
90 | 94 | | |||
91 | mCaptureModeForm = new QFormLayout; | 95 | mCaptureModeForm = new QFormLayout; | ||
92 | mCaptureModeForm->addRow(i18n("Area:"), mCaptureArea); | 96 | mCaptureModeForm->addRow(i18n("Area:"), mCaptureArea); | ||
93 | mCaptureModeForm->addRow(i18n("Delay:"), mDelayLayout); | 97 | mCaptureModeForm->addRow(i18n("Delay:"), mDelayLayout); | ||
94 | mCaptureModeForm->setContentsMargins(24, 0, 0, 0); | 98 | mCaptureModeForm->setContentsMargins(24, 0, 0, 0); | ||
95 | 99 | | |||
96 | // options (mouse pointer, window decorations, quit after saving or copying) | 100 | // options (mouse pointer, window decorations, quit after saving or copying) | ||
97 | mContentOptionsLabel = new QLabel(this); | 101 | mContentOptionsLabel = new QLabel(this); | ||
98 | mContentOptionsLabel->setText(i18n("<b>Options</b>")); | 102 | mContentOptionsLabel->setText(i18n("<b>Options</b>")); | ||
99 | 103 | | |||
100 | mMousePointer = new QCheckBox(i18n("Include mouse pointer"), this); | 104 | mMousePointer = new QCheckBox(i18n("Include mouse pointer"), this); | ||
101 | mMousePointer->setToolTip(i18n("Show the mouse cursor in the screenshot image")); | 105 | mMousePointer->setToolTip(i18n("Show the mouse cursor in the screenshot image")); | ||
102 | connect(mMousePointer, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setIncludePointerChecked); | 106 | connect(mMousePointer, &QCheckBox::clicked, &Settings::setIncludePointer); | ||
103 | 107 | | |||
104 | mWindowDecorations = new QCheckBox(i18n("Include window titlebar and borders"), this); | 108 | mWindowDecorations = new QCheckBox(i18n("Include window titlebar and borders"), this); | ||
105 | mWindowDecorations->setToolTip(i18n("Show the window title bar, the minimize/maximize/close buttons, and the window border")); | 109 | mWindowDecorations->setToolTip(i18n("Show the window title bar, the minimize/maximize/close buttons, and the window border")); | ||
106 | mWindowDecorations->setEnabled(false); | 110 | mWindowDecorations->setEnabled(false); | ||
107 | connect(mWindowDecorations, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setIncludeDecorationsChecked); | 111 | connect(mWindowDecorations, &QCheckBox::clicked, &Settings::setIncludeDecorations); | ||
108 | 112 | | |||
109 | mCaptureTransientOnly = new QCheckBox(i18n("Capture the current pop-up only"), this); | 113 | mCaptureTransientOnly = new QCheckBox(i18n("Capture the current pop-up only"), this); | ||
110 | mCaptureTransientOnly->setToolTip(i18n("Capture only the current pop-up window (like a menu, tooltip etc).\n" | 114 | mCaptureTransientOnly->setToolTip(i18n("Capture only the current pop-up window (like a menu, tooltip etc).\n" | ||
111 | "If disabled, the pop-up is captured along with the parent window")); | 115 | "If disabled, the pop-up is captured along with the parent window")); | ||
112 | mCaptureTransientOnly->setEnabled(false); | 116 | mCaptureTransientOnly->setEnabled(false); | ||
113 | connect(mCaptureTransientOnly, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setCaptureTransientWindowOnlyChecked); | 117 | connect(mCaptureTransientOnly, &QCheckBox::clicked, &Settings::setTransientOnly); | ||
114 | 118 | | |||
115 | mQuitAfterSaveOrCopy = new QCheckBox(i18n("Quit after manual Save or Copy"), this); | 119 | mQuitAfterSaveOrCopy = new QCheckBox(i18n("Quit after manual Save or Copy"), this); | ||
116 | mQuitAfterSaveOrCopy->setToolTip(i18n("Quit Spectacle after manually saving or copying the image")); | 120 | mQuitAfterSaveOrCopy->setToolTip(i18n("Quit Spectacle after manually saving or copying the image")); | ||
117 | connect(mQuitAfterSaveOrCopy, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setQuitAfterSaveOrCopyChecked); | 121 | connect(mQuitAfterSaveOrCopy, &QCheckBox::clicked, &Settings::setQuitAfterSaveCopyExport); | ||
118 | 122 | | |||
119 | mContentOptionsForm = new QVBoxLayout; | 123 | mContentOptionsForm = new QVBoxLayout; | ||
120 | mContentOptionsForm->addWidget(mMousePointer); | 124 | mContentOptionsForm->addWidget(mMousePointer); | ||
121 | mContentOptionsForm->addWidget(mWindowDecorations); | 125 | mContentOptionsForm->addWidget(mWindowDecorations); | ||
122 | mContentOptionsForm->addWidget(mCaptureTransientOnly); | 126 | mContentOptionsForm->addWidget(mCaptureTransientOnly); | ||
123 | mContentOptionsForm->addWidget(mQuitAfterSaveOrCopy); | 127 | mContentOptionsForm->addWidget(mQuitAfterSaveOrCopy); | ||
124 | mContentOptionsForm->setContentsMargins(24, 0, 0, 0); | 128 | mContentOptionsForm->setContentsMargins(24, 0, 0, 0); | ||
125 | 129 | | |||
Show All 29 Lines | |||||
155 | 159 | | |||
156 | mMainLayout = new QGridLayout(this); | 160 | mMainLayout = new QGridLayout(this); | ||
157 | mMainLayout->addWidget(mImageWidget, 0, 0, 1, 1); | 161 | mMainLayout->addWidget(mImageWidget, 0, 0, 1, 1); | ||
158 | mMainLayout->addLayout(mRightLayout, 0, 1, 1, 1); | 162 | mMainLayout->addLayout(mRightLayout, 0, 1, 1, 1); | ||
159 | mMainLayout->setColumnMinimumWidth(0, 320); | 163 | mMainLayout->setColumnMinimumWidth(0, 320); | ||
160 | mMainLayout->setColumnMinimumWidth(1, 320); | 164 | mMainLayout->setColumnMinimumWidth(1, 320); | ||
161 | 165 | | |||
162 | // and read in the saved checkbox states and capture mode indices | 166 | // and read in the saved checkbox states and capture mode indices | ||
163 | mMousePointer->setChecked (lConfigMgr->includePointerChecked()); | 167 | mMousePointer->setChecked(Settings::includePointer()); | ||
164 | mWindowDecorations->setChecked (lConfigMgr->includeDecorationsChecked()); | 168 | mWindowDecorations->setChecked(Settings::includeDecorations()); | ||
165 | mCaptureOnClick->setChecked (lConfigMgr->onClickChecked()); | 169 | mCaptureOnClick->setChecked(Settings::onClickChecked()); | ||
166 | mCaptureTransientOnly->setChecked (lConfigMgr->captureTransientWindowOnlyChecked()); | 170 | mCaptureTransientOnly->setChecked(Settings::transientOnly()); | ||
167 | mQuitAfterSaveOrCopy->setChecked (lConfigMgr->quitAfterSaveOrCopyChecked()); | 171 | mQuitAfterSaveOrCopy->setChecked(Settings::quitAfterSaveCopyExport()); | ||
168 | if (lConfigMgr->captureMode() >= 0) { | 172 | mDelayMsec->setValue(Settings::captureDelay()); | ||
169 | mCaptureArea->setCurrentIndex (lConfigMgr->captureMode()); | | |||
170 | } | | |||
171 | mDelayMsec->setValue (lConfigMgr->captureDelay()); | | |||
172 | } | 173 | } | ||
173 | 174 | | |||
174 | int KSWidget::imagePaddingWidth() const | 175 | int KSWidget::imagePaddingWidth() const | ||
175 | { | 176 | { | ||
176 | int lRightLayoutLeft = 0; | 177 | int lRightLayoutLeft = 0; | ||
177 | int lRightLayoutRight = 0; | 178 | int lRightLayoutRight = 0; | ||
178 | int lMainLayoutRight = 0; | 179 | int lMainLayoutRight = 0; | ||
179 | 180 | | |||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 229 | if (theState == Qt::Checked) { | |||
229 | mDelayMsec->setEnabled(false); | 230 | mDelayMsec->setEnabled(false); | ||
230 | } else if (theState == Qt::Unchecked) { | 231 | } else if (theState == Qt::Unchecked) { | ||
231 | mDelayMsec->setEnabled(true); | 232 | mDelayMsec->setEnabled(true); | ||
232 | } | 233 | } | ||
233 | } | 234 | } | ||
234 | 235 | | |||
235 | void KSWidget::captureModeChanged(int theIndex) | 236 | void KSWidget::captureModeChanged(int theIndex) | ||
236 | { | 237 | { | ||
237 | SpectacleConfig::instance()->setCaptureMode(theIndex); | 238 | Spectacle::CaptureMode captureMode = static_cast<Spectacle::CaptureMode>(mCaptureArea->itemData(theIndex).toInt()); | ||
238 | 239 | Settings::setCaptureMode(captureMode); | |||
239 | 240 | | |||
240 | Spectacle::CaptureMode lCaptureMode = static_cast<Spectacle::CaptureMode>(mCaptureArea->itemData(theIndex).toInt()); | 241 | switch(captureMode) { | ||
241 | switch(lCaptureMode) { | | |||
242 | case Spectacle::CaptureMode::WindowUnderCursor: | 242 | case Spectacle::CaptureMode::WindowUnderCursor: | ||
243 | mWindowDecorations->setEnabled(true); | 243 | mWindowDecorations->setEnabled(true); | ||
244 | if (mTransientWithParentAvailable) { | 244 | if (mTransientWithParentAvailable) { | ||
245 | mCaptureTransientOnly->setEnabled(true); | 245 | mCaptureTransientOnly->setEnabled(true); | ||
246 | } else { | 246 | } else { | ||
247 | mCaptureTransientOnly->setEnabled(false); | 247 | mCaptureTransientOnly->setEnabled(false); | ||
248 | } | 248 | } | ||
249 | break; | 249 | break; | ||
Show All 38 Lines |