Changeset View
Changeset View
Standalone View
Standalone View
src/Gui/KSWidget.cpp
Show All 28 Lines | |||||
29 | #include <QApplication> | 29 | #include <QApplication> | ||
30 | #include <QCheckBox> | 30 | #include <QCheckBox> | ||
31 | #include <QComboBox> | 31 | #include <QComboBox> | ||
32 | #include <QFormLayout> | 32 | #include <QFormLayout> | ||
33 | #include <QGridLayout> | 33 | #include <QGridLayout> | ||
34 | #include <QLabel> | 34 | #include <QLabel> | ||
35 | #include <QShortcut> | 35 | #include <QShortcut> | ||
36 | #include <QToolButton> | 36 | #include <QToolButton> | ||
37 | #include <QPainter> | ||||
38 | #include <QAbstractItemView> | ||||
ngraham: Keep includes alphabetized | |||||
37 | 39 | | |||
38 | #include <KLocalizedString> | 40 | #include <KLocalizedString> | ||
39 | 41 | | |||
42 | #include "CaptureAreaComboBox/CaptureModeModel.h" | ||||
43 | #include "CaptureAreaComboBox/CaptureModeDelegate.h" | ||||
ngraham: Keep local includes grouped together | |||||
44 | | ||||
40 | KSWidget::KSWidget(const Platform::GrabModes &theGrabModes, QWidget *parent) : | 45 | KSWidget::KSWidget(const Platform::GrabModes &theGrabModes, QWidget *parent) : | ||
41 | QWidget(parent) | 46 | QWidget(parent) | ||
42 | { | 47 | { | ||
43 | // get a handle to the configuration manager | 48 | // get a handle to the configuration manager | ||
44 | SpectacleConfig *lConfigMgr = SpectacleConfig::instance(); | 49 | SpectacleConfig *lConfigMgr = SpectacleConfig::instance(); | ||
45 | 50 | | |||
46 | // we'll init the widget that holds the image first | 51 | // we'll init the widget that holds the image first | ||
47 | mImageWidget = new KSImageWidget(this); | 52 | mImageWidget = new KSImageWidget(this); | ||
48 | mImageWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | 53 | mImageWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | ||
49 | connect(mImageWidget, &KSImageWidget::dragInitiated, this, &KSWidget::dragInitiated); | 54 | connect(mImageWidget, &KSImageWidget::dragInitiated, this, &KSWidget::dragInitiated); | ||
50 | 55 | | |||
51 | // the capture mode options first | 56 | // the capture mode options first | ||
52 | mCaptureModeLabel = new QLabel(i18n("<b>Capture Mode</b>"), this); | 57 | mCaptureModeLabel = new QLabel(i18n("<b>Capture Mode</b>"), this); | ||
58 | | ||||
53 | mCaptureArea = new QComboBox(this); | 59 | 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); | 60 | mCaptureArea->setMinimumWidth(240); | ||
61 | mCaptureArea->setModel(new CaptureModeModel {theGrabModes}); | ||||
ngraham: who deletes this model? | |||||
62 | //Custom Delegate for comboBox with support for displaying shortcuts | ||||
63 | mCaptureArea->setItemDelegate(new CaptureModeDelegate {}); | ||||
64 | | ||||
65 | //Calculate the mim width needed to display action + shortcut + spacing in the delegates | ||||
66 | QFontMetrics fm {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 | |||||
67 | QAbstractItemModel *model = mCaptureArea->model(); | ||||
68 | int maxWidthLeftText = 0; | ||||
69 | int maxWidthRightText = 0; | ||||
70 | for(int i = 0; i < model->rowCount(); ++i) { | ||||
ngraham: space after `for` | |||||
71 | QString leftText = model->data(model->index(i, 0)).toString(); | ||||
davidre: Also 2 spaces. | |||||
72 | QString rightText = model->data(model->index(i, 1)).toString(); | ||||
73 | | ||||
74 | int leftWidth = fm.horizontalAdvance(leftText); | ||||
75 | maxWidthLeftText = qMax(maxWidthLeftText, leftWidth); | ||||
76 | int rightWidth = fm.horizontalAdvance(rightText); | ||||
77 | maxWidthRightText = qMax(maxWidthRightText, rightWidth); | ||||
78 | } | ||||
79 | mCaptureArea->view()->setMinimumWidth(maxWidthLeftText + maxWidthRightText + 30); | ||||
ngraham: Needs a comment explaining the magic number | |||||
80 | | ||||
71 | connect(mCaptureArea, qOverload<int>(&QComboBox::currentIndexChanged), this, &KSWidget::captureModeChanged); | 81 | connect(mCaptureArea, qOverload<int>(&QComboBox::currentIndexChanged), this, &KSWidget::captureModeChanged); | ||
72 | 82 | | |||
73 | mDelayMsec = new SmartSpinBox(this); | 83 | mDelayMsec = new SmartSpinBox(this); | ||
74 | mDelayMsec->setDecimals(1); | 84 | mDelayMsec->setDecimals(1); | ||
75 | mDelayMsec->setSingleStep(1.0); | 85 | mDelayMsec->setSingleStep(1.0); | ||
76 | mDelayMsec->setMinimum(0.0); | 86 | mDelayMsec->setMinimum(0.0); | ||
77 | mDelayMsec->setMaximum(999.9); | 87 | mDelayMsec->setMaximum(999.9); | ||
78 | mDelayMsec->setSpecialValueText(i18n("No Delay")); | 88 | mDelayMsec->setSpecialValueText(i18n("No Delay")); | ||
Show All 22 Lines | |||||
101 | mMousePointer->setToolTip(i18n("Show the mouse cursor in the screenshot image")); | 111 | mMousePointer->setToolTip(i18n("Show the mouse cursor in the screenshot image")); | ||
102 | connect(mMousePointer, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setIncludePointerChecked); | 112 | connect(mMousePointer, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setIncludePointerChecked); | ||
103 | 113 | | |||
104 | mWindowDecorations = new QCheckBox(i18n("Include window titlebar and borders"), this); | 114 | 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")); | 115 | mWindowDecorations->setToolTip(i18n("Show the window title bar, the minimize/maximize/close buttons, and the window border")); | ||
106 | mWindowDecorations->setEnabled(false); | 116 | mWindowDecorations->setEnabled(false); | ||
107 | connect(mWindowDecorations, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setIncludeDecorationsChecked); | 117 | connect(mWindowDecorations, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setIncludeDecorationsChecked); | ||
108 | 118 | | |||
119 | if (theGrabModes.testFlag(Platform::GrabMode::TransientWithParent)) { | ||||
120 | mTransientWithParentAvailable = true; | ||||
ngraham: intentation needs to be 4 spaces | |||||
121 | } | ||||
122 | | ||||
109 | mCaptureTransientOnly = new QCheckBox(i18n("Capture the current pop-up only"), this); | 123 | 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" | 124 | 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")); | 125 | "If disabled, the pop-up is captured along with the parent window")); | ||
112 | mCaptureTransientOnly->setEnabled(false); | 126 | mCaptureTransientOnly->setEnabled(false); | ||
113 | connect(mCaptureTransientOnly, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setCaptureTransientWindowOnlyChecked); | 127 | connect(mCaptureTransientOnly, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setCaptureTransientWindowOnlyChecked); | ||
114 | 128 | | |||
115 | mQuitAfterSaveOrCopy = new QCheckBox(i18n("Quit after Save or Copy"), this); | 129 | mQuitAfterSaveOrCopy = new QCheckBox(i18n("Quit after Save or Copy"), this); | ||
116 | mQuitAfterSaveOrCopy->setToolTip(i18n("Quit Spectacle after saving or copying the image")); | 130 | mQuitAfterSaveOrCopy->setToolTip(i18n("Quit Spectacle after saving or copying the image")); | ||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Line(s) | 290 | case State::Cancel: | |||
278 | mTakeScreenshotButton->setDefaultAction(mCancelAction); | 292 | mTakeScreenshotButton->setDefaultAction(mCancelAction); | ||
279 | break; | 293 | break; | ||
280 | } | 294 | } | ||
281 | } | 295 | } | ||
282 | 296 | | |||
283 | void KSWidget::setProgress(double progress) | 297 | void KSWidget::setProgress(double progress) | ||
284 | { | 298 | { | ||
285 | mTakeScreenshotButton->setProgress(progress); | 299 | mTakeScreenshotButton->setProgress(progress); | ||
286 | } | 300 | } | ||
287 | 301 | | |||
davidre: Newline removed. |
Keep includes alphabetized