Changeset View
Changeset View
Standalone View
Standalone View
src/Gui/KSWidget.cpp
Show All 18 Lines | |||||
19 | 19 | | |||
20 | #include "KSWidget.h" | 20 | #include "KSWidget.h" | ||
21 | #include "spectacle_gui_debug.h" | 21 | #include "spectacle_gui_debug.h" | ||
22 | 22 | | |||
23 | #include "KSImageWidget.h" | 23 | #include "KSImageWidget.h" | ||
24 | #include "SmartSpinBox.h" | 24 | #include "SmartSpinBox.h" | ||
25 | #include "SpectacleConfig.h" | 25 | #include "SpectacleConfig.h" | ||
26 | #include "ProgressButton.h" | 26 | #include "ProgressButton.h" | ||
27 | #include "CaptureAreaComboBox/CaptureModeModel.h" | ||||
28 | #include "CaptureAreaComboBox/CaptureModeDelegate.h" | ||||
27 | 29 | | |||
30 | #include <QAbstractItemView> | ||||
28 | #include <QAction> | 31 | #include <QAction> | ||
29 | #include <QApplication> | 32 | #include <QApplication> | ||
30 | #include <QCheckBox> | 33 | #include <QCheckBox> | ||
31 | #include <QComboBox> | 34 | #include <QComboBox> | ||
32 | #include <QFormLayout> | 35 | #include <QFormLayout> | ||
33 | #include <QGridLayout> | 36 | #include <QGridLayout> | ||
34 | #include <QLabel> | 37 | #include <QLabel> | ||
38 | #include <QPainter> | ||||
35 | #include <QShortcut> | 39 | #include <QShortcut> | ||
36 | #include <QToolButton> | 40 | #include <QToolButton> | ||
37 | 41 | | |||
38 | #include <KLocalizedString> | 42 | #include <KLocalizedString> | ||
ngraham: Keep includes alphabetized | |||||
39 | 43 | | |||
40 | KSWidget::KSWidget(const Platform::GrabModes &theGrabModes, QWidget *parent) : | 44 | KSWidget::KSWidget(const Platform::GrabModes &theGrabModes, QWidget *parent) : | ||
41 | QWidget(parent) | 45 | QWidget(parent) | ||
ngraham: Keep local includes grouped together | |||||
42 | { | 46 | { | ||
43 | // get a handle to the configuration manager | 47 | // get a handle to the configuration manager | ||
44 | SpectacleConfig *lConfigMgr = SpectacleConfig::instance(); | 48 | SpectacleConfig *lConfigMgr = SpectacleConfig::instance(); | ||
45 | 49 | | |||
46 | // we'll init the widget that holds the image first | 50 | // we'll init the widget that holds the image first | ||
47 | mImageWidget = new KSImageWidget(this); | 51 | mImageWidget = new KSImageWidget(this); | ||
48 | mImageWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | 52 | mImageWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | ||
49 | connect(mImageWidget, &KSImageWidget::dragInitiated, this, &KSWidget::dragInitiated); | 53 | connect(mImageWidget, &KSImageWidget::dragInitiated, this, &KSWidget::dragInitiated); | ||
50 | 54 | | |||
51 | // the capture mode options first | 55 | // the capture mode options first | ||
52 | mCaptureModeLabel = new QLabel(i18n("<b>Capture Mode</b>"), this); | 56 | mCaptureModeLabel = new QLabel(i18n("<b>Capture Mode</b>"), this); | ||
57 | | ||||
53 | mCaptureArea = new QComboBox(this); | 58 | mCaptureArea = new QComboBox(this); | ||
54 | QString lFullScreenLabel = QApplication::screens().count() == 1 | | |||
55 | ? i18n("Full Screen") | | |||
56 | : i18n("Full Screen (All Monitors)"); | | |||
57 | | ||||
58 | if (theGrabModes.testFlag(Platform::GrabMode::AllScreens)) | | |||
59 | mCaptureArea->insertItem(1, lFullScreenLabel, Spectacle::CaptureMode::AllScreens); | | |||
60 | if (theGrabModes.testFlag(Platform::GrabMode::CurrentScreen)) | | |||
61 | mCaptureArea->insertItem(2, i18n("Current Screen"), Spectacle::CaptureMode::CurrentScreen); | | |||
62 | if (theGrabModes.testFlag(Platform::GrabMode::ActiveWindow)) | | |||
63 | mCaptureArea->insertItem(3, i18n("Active Window"), Spectacle::CaptureMode::ActiveWindow); | | |||
64 | if (theGrabModes.testFlag(Platform::GrabMode::WindowUnderCursor)) | | |||
65 | mCaptureArea->insertItem(4, i18n("Window Under Cursor"), Spectacle::CaptureMode::WindowUnderCursor); | | |||
66 | if (theGrabModes.testFlag(Platform::GrabMode::TransientWithParent)) { | | |||
67 | mTransientWithParentAvailable = true; | | |||
68 | } | | |||
69 | mCaptureArea->insertItem(5, i18n("Rectangular Region"), Spectacle::CaptureMode::RectangularRegion); | | |||
70 | mCaptureArea->setMinimumWidth(240); | 59 | mCaptureArea->setMinimumWidth(240); | ||
60 | mCaptureArea->setModel(new CaptureModeModel {theGrabModes}); | ||||
ngraham: who deletes this model? | |||||
61 | //Custom Delegate for comboBox with support for displaying shortcuts | ||||
62 | mCaptureArea->setItemDelegate(new CaptureModeDelegate {}); | ||||
63 | | ||||
64 | //Calculate the mim width needed to display action + shortcut + spacing in the delegates | ||||
65 | QFontMetrics fontMetrics {QGuiApplication::font()}; | ||||
fm is a non-descriptive variable name. Use fontMetrics or even just metrics instead ngraham: `fm` is a non-descriptive variable name. Use `fontMetrics` or even just `metrics` instead | |||||
66 | int maxWidthLeftText = 0; | ||||
67 | int maxWidthRightText = 0; | ||||
68 | for (int i = 0; i < mCaptureArea->count(); ++i) { | ||||
69 | int leftWidth = fontMetrics.horizontalAdvance(mCaptureArea->itemData(i, Qt::DisplayRole).toString()); | ||||
ngraham: space after `for` | |||||
70 | maxWidthLeftText = qMax(maxWidthLeftText, leftWidth); | ||||
davidre: Also 2 spaces. | |||||
71 | int rightWidth = fontMetrics.horizontalAdvance(mCaptureArea->itemData(i, ShortcutRole).toString()); | ||||
72 | maxWidthRightText = qMax(maxWidthRightText, rightWidth); | ||||
73 | } | ||||
74 | //spacing between longest left text and longest right text in the popup of the QComboBox | ||||
75 | int spacingComboBox = 30; | ||||
76 | mCaptureArea->view()->setMinimumWidth(maxWidthLeftText + maxWidthRightText + spacingComboBox); | ||||
77 | | ||||
71 | connect(mCaptureArea, qOverload<int>(&QComboBox::currentIndexChanged), this, &KSWidget::captureModeChanged); | 78 | connect(mCaptureArea, qOverload<int>(&QComboBox::currentIndexChanged), this, &KSWidget::captureModeChanged); | ||
ngraham: Needs a comment explaining the magic number | |||||
72 | 79 | | |||
73 | mDelayMsec = new SmartSpinBox(this); | 80 | mDelayMsec = new SmartSpinBox(this); | ||
74 | mDelayMsec->setDecimals(1); | 81 | mDelayMsec->setDecimals(1); | ||
75 | mDelayMsec->setSingleStep(1.0); | 82 | mDelayMsec->setSingleStep(1.0); | ||
76 | mDelayMsec->setMinimum(0.0); | 83 | mDelayMsec->setMinimum(0.0); | ||
77 | mDelayMsec->setMaximum(999.9); | 84 | mDelayMsec->setMaximum(999.9); | ||
78 | mDelayMsec->setSpecialValueText(i18n("No Delay")); | 85 | mDelayMsec->setSpecialValueText(i18n("No Delay")); | ||
79 | mDelayMsec->setMinimumWidth(160); | 86 | mDelayMsec->setMinimumWidth(160); | ||
Show All 21 Lines | |||||
101 | mMousePointer->setToolTip(i18n("Show the mouse cursor in the screenshot image")); | 108 | mMousePointer->setToolTip(i18n("Show the mouse cursor in the screenshot image")); | ||
102 | connect(mMousePointer, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setIncludePointerChecked); | 109 | connect(mMousePointer, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setIncludePointerChecked); | ||
103 | 110 | | |||
104 | mWindowDecorations = new QCheckBox(i18n("Include window titlebar and borders"), this); | 111 | 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")); | 112 | mWindowDecorations->setToolTip(i18n("Show the window title bar, the minimize/maximize/close buttons, and the window border")); | ||
106 | mWindowDecorations->setEnabled(false); | 113 | mWindowDecorations->setEnabled(false); | ||
107 | connect(mWindowDecorations, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setIncludeDecorationsChecked); | 114 | connect(mWindowDecorations, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setIncludeDecorationsChecked); | ||
108 | 115 | | |||
116 | if (theGrabModes.testFlag(Platform::GrabMode::TransientWithParent)) { | ||||
117 | mTransientWithParentAvailable = true; | ||||
ngraham: intentation needs to be 4 spaces | |||||
118 | } | ||||
119 | | ||||
109 | mCaptureTransientOnly = new QCheckBox(i18n("Capture the current pop-up only"), this); | 120 | 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" | 121 | 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")); | 122 | "If disabled, the pop-up is captured along with the parent window")); | ||
112 | mCaptureTransientOnly->setEnabled(false); | 123 | mCaptureTransientOnly->setEnabled(false); | ||
113 | connect(mCaptureTransientOnly, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setCaptureTransientWindowOnlyChecked); | 124 | connect(mCaptureTransientOnly, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setCaptureTransientWindowOnlyChecked); | ||
114 | 125 | | |||
115 | mQuitAfterSaveOrCopy = new QCheckBox(i18n("Quit after Save or Copy"), this); | 126 | mQuitAfterSaveOrCopy = new QCheckBox(i18n("Quit after Save or Copy"), this); | ||
116 | mQuitAfterSaveOrCopy->setToolTip(i18n("Quit Spectacle after saving or copying the image")); | 127 | mQuitAfterSaveOrCopy->setToolTip(i18n("Quit Spectacle after saving or copying the image")); | ||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | 216 | { | |||
208 | mDelayMsec->setEnabled(true); | 219 | mDelayMsec->setEnabled(true); | ||
209 | } | 220 | } | ||
210 | 221 | | |||
211 | // private slots | 222 | // private slots | ||
212 | 223 | | |||
213 | void KSWidget::newScreenshotClicked() | 224 | void KSWidget::newScreenshotClicked() | ||
214 | { | 225 | { | ||
215 | int lDelay = mCaptureOnClick->isChecked() ? -1 : (mDelayMsec->value() * 1000); | 226 | int lDelay = mCaptureOnClick->isChecked() ? -1 : (mDelayMsec->value() * 1000); | ||
216 | auto lMode = static_cast<Spectacle::CaptureMode>(mCaptureArea->currentData().toInt()); | 227 | auto lMode = static_cast<Spectacle::CaptureMode>(mCaptureArea->currentData(ActionRole).toInt()); | ||
217 | if (mTransientWithParentAvailable && | 228 | if (mTransientWithParentAvailable && | ||
218 | lMode == Spectacle::CaptureMode::WindowUnderCursor && | 229 | lMode == Spectacle::CaptureMode::WindowUnderCursor && | ||
219 | !(mCaptureTransientOnly->isChecked())) { | 230 | !(mCaptureTransientOnly->isChecked())) { | ||
220 | lMode = Spectacle::CaptureMode::TransientWithParent; | 231 | lMode = Spectacle::CaptureMode::TransientWithParent; | ||
221 | } | 232 | } | ||
222 | setButtonState(State::Cancel); | 233 | setButtonState(State::Cancel); | ||
223 | emit newScreenshotRequest(lMode, lDelay, mMousePointer->isChecked(), mWindowDecorations->isChecked()); | 234 | emit newScreenshotRequest(lMode, lDelay, mMousePointer->isChecked(), mWindowDecorations->isChecked()); | ||
224 | } | 235 | } | ||
225 | 236 | | |||
226 | void KSWidget::onClickStateChanged(int theState) | 237 | void KSWidget::onClickStateChanged(int theState) | ||
227 | { | 238 | { | ||
228 | if (theState == Qt::Checked) { | 239 | if (theState == Qt::Checked) { | ||
229 | mDelayMsec->setEnabled(false); | 240 | mDelayMsec->setEnabled(false); | ||
230 | } else if (theState == Qt::Unchecked) { | 241 | } else if (theState == Qt::Unchecked) { | ||
231 | mDelayMsec->setEnabled(true); | 242 | mDelayMsec->setEnabled(true); | ||
232 | } | 243 | } | ||
233 | } | 244 | } | ||
234 | 245 | | |||
235 | void KSWidget::captureModeChanged(int theIndex) | 246 | void KSWidget::captureModeChanged(int theIndex) | ||
236 | { | 247 | { | ||
237 | SpectacleConfig::instance()->setCaptureMode(theIndex); | 248 | SpectacleConfig::instance()->setCaptureMode(theIndex); | ||
238 | 249 | | |||
239 | 250 | | |||
240 | Spectacle::CaptureMode lCaptureMode = static_cast<Spectacle::CaptureMode>(mCaptureArea->itemData(theIndex).toInt()); | 251 | Spectacle::CaptureMode lCaptureMode = static_cast<Spectacle::CaptureMode>(mCaptureArea->itemData(theIndex, ActionRole).toInt()); | ||
241 | switch(lCaptureMode) { | 252 | switch(lCaptureMode) { | ||
242 | case Spectacle::CaptureMode::WindowUnderCursor: | 253 | case Spectacle::CaptureMode::WindowUnderCursor: | ||
243 | mWindowDecorations->setEnabled(true); | 254 | mWindowDecorations->setEnabled(true); | ||
244 | if (mTransientWithParentAvailable) { | 255 | if (mTransientWithParentAvailable) { | ||
245 | mCaptureTransientOnly->setEnabled(true); | 256 | mCaptureTransientOnly->setEnabled(true); | ||
246 | } else { | 257 | } else { | ||
247 | mCaptureTransientOnly->setEnabled(false); | 258 | mCaptureTransientOnly->setEnabled(false); | ||
248 | } | 259 | } | ||
249 | break; | 260 | break; | ||
250 | case Spectacle::CaptureMode::ActiveWindow: | 261 | case Spectacle::CaptureMode::ActiveWindow: | ||
251 | mWindowDecorations->setEnabled(true); | 262 | mWindowDecorations->setEnabled(true); | ||
252 | mCaptureTransientOnly->setEnabled(false); | 263 | mCaptureTransientOnly->setEnabled(false); | ||
253 | break; | 264 | break; | ||
254 | case Spectacle::CaptureMode::AllScreens: | 265 | case Spectacle::CaptureMode::EntireScreen: | ||
255 | case Spectacle::CaptureMode::CurrentScreen: | 266 | case Spectacle::CaptureMode::CurrentScreen: | ||
256 | case Spectacle::CaptureMode::RectangularRegion: | 267 | case Spectacle::CaptureMode::RectangularRegion: | ||
257 | mWindowDecorations->setEnabled(false); | 268 | mWindowDecorations->setEnabled(false); | ||
258 | mCaptureTransientOnly->setEnabled(false); | 269 | mCaptureTransientOnly->setEnabled(false); | ||
259 | break; | 270 | break; | ||
260 | case Spectacle::CaptureMode::TransientWithParent: | 271 | case Spectacle::CaptureMode::TransientWithParent: | ||
261 | case Spectacle::CaptureMode::InvalidChoice: | 272 | case Spectacle::CaptureMode::InvalidChoice: | ||
262 | default: | 273 | default: | ||
Show All 15 Lines | 287 | case State::Cancel: | |||
278 | mTakeScreenshotButton->setDefaultAction(mCancelAction); | 289 | mTakeScreenshotButton->setDefaultAction(mCancelAction); | ||
279 | break; | 290 | break; | ||
280 | } | 291 | } | ||
281 | } | 292 | } | ||
282 | 293 | | |||
283 | void KSWidget::setProgress(double progress) | 294 | void KSWidget::setProgress(double progress) | ||
284 | { | 295 | { | ||
285 | mTakeScreenshotButton->setProgress(progress); | 296 | mTakeScreenshotButton->setProgress(progress); | ||
286 | } | 297 | } | ||
287 | 298 | | |||
davidre: Newline removed. |
Keep includes alphabetized