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 | 26 | | |||
27 | #include <QAction> | ||||
27 | #include <QApplication> | 28 | #include <QApplication> | ||
28 | #include <QCheckBox> | 29 | #include <QCheckBox> | ||
29 | #include <QComboBox> | 30 | #include <QComboBox> | ||
30 | #include <QDebug> | 31 | #include <QDebug> | ||
31 | #include <QFormLayout> | 32 | #include <QFormLayout> | ||
32 | #include <QGridLayout> | 33 | #include <QGridLayout> | ||
33 | #include <QLabel> | 34 | #include <QLabel> | ||
34 | #include <QPushButton> | | |||
35 | #include <QShortcut> | 35 | #include <QShortcut> | ||
36 | #include <QToolButton> | ||||
36 | 37 | | |||
37 | #include <KLocalizedString> | 38 | #include <KLocalizedString> | ||
38 | 39 | | |||
39 | KSWidget::KSWidget(const Platform::GrabModes &theGrabModes, QWidget *parent) : | 40 | KSWidget::KSWidget(const Platform::GrabModes &theGrabModes, QWidget *parent) : | ||
40 | QWidget(parent) | 41 | QWidget(parent) | ||
41 | { | 42 | { | ||
42 | // get a handle to the configuration manager | 43 | // get a handle to the configuration manager | ||
43 | SpectacleConfig *lConfigMgr = SpectacleConfig::instance(); | 44 | SpectacleConfig *lConfigMgr = SpectacleConfig::instance(); | ||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | |||||
117 | 118 | | |||
118 | mContentOptionsForm = new QVBoxLayout; | 119 | mContentOptionsForm = new QVBoxLayout; | ||
119 | mContentOptionsForm->addWidget(mMousePointer); | 120 | mContentOptionsForm->addWidget(mMousePointer); | ||
120 | mContentOptionsForm->addWidget(mWindowDecorations); | 121 | mContentOptionsForm->addWidget(mWindowDecorations); | ||
121 | mContentOptionsForm->addWidget(mCaptureTransientOnly); | 122 | mContentOptionsForm->addWidget(mCaptureTransientOnly); | ||
122 | mContentOptionsForm->addWidget(mQuitAfterSaveOrCopy); | 123 | mContentOptionsForm->addWidget(mQuitAfterSaveOrCopy); | ||
123 | mContentOptionsForm->setContentsMargins(24, 0, 0, 0); | 124 | mContentOptionsForm->setContentsMargins(24, 0, 0, 0); | ||
124 | 125 | | |||
126 | mTakeNewScreenshotAction = new QAction(QIcon::fromTheme(QStringLiteral("spectacle")), i18n("Take a New Screenshot"), this); | ||||
broulik: Keep the label as it was: "Take a New Screenshot" | |||||
127 | mTakeNewScreenshotAction->setShortcut(QKeySequence::New); | ||||
128 | connect(mTakeNewScreenshotAction, &QAction::triggered, this, &KSWidget::newScreenshotClicked); | ||||
129 | | ||||
130 | mCancelAction = new QAction(QIcon::fromTheme(QStringLiteral("dialog-cancel")), i18n("Cancel"), this); | ||||
131 | mCancelAction->setShortcut(QKeySequence::Cancel); | ||||
132 | connect(mCancelAction, &QAction::triggered, this, [this] { | ||||
You forget to set the window title back. It stays at e.g. "2 seconds" if I cancel broulik: You forget to set the window title back. It stays at e.g. "2 seconds" if I cancel | |||||
133 | emit screenshotCanceled(); | ||||
134 | setButtonState(State::TakeNewScreenshot); | ||||
135 | }); | ||||
136 | | ||||
125 | // the take a new screenshot button | 137 | // the take a new screenshot button | ||
126 | mTakeScreenshotButton = new QPushButton(i18n("Take a New Screenshot"), this); | 138 | mTakeScreenshotButton = new QToolButton(this); | ||
127 | mTakeScreenshotButton->setIcon(QIcon::fromTheme(QStringLiteral("spectacle"))); | | |||
128 | mTakeScreenshotButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | 139 | mTakeScreenshotButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | ||
140 | mTakeScreenshotButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | ||||
I would force it to Qt::ToolButtonTextBesideIcon however I tried with diferent styles and it always looked like a QPushButton, so maybe that behavior is only relevant for when inside a QToolbar broulik: I would force it to `Qt::ToolButtonTextBesideIcon` however I tried with diferent styles and it… | |||||
141 | setButtonState(State::TakeNewScreenshot); | ||||
129 | mTakeScreenshotButton->setFocus(); | 142 | mTakeScreenshotButton->setFocus(); | ||
130 | connect(mTakeScreenshotButton, &QPushButton::clicked, this, &KSWidget::newScreenshotClicked); | | |||
131 | | ||||
132 | QShortcut *takeScreenshotShortcut = new QShortcut(QKeySequence(QKeySequence::New), mTakeScreenshotButton); | | |||
133 | connect(takeScreenshotShortcut, &QShortcut::activated, this, [this]() { | | |||
134 | mTakeScreenshotButton->animateClick(100); | | |||
135 | }); | | |||
136 | 143 | | |||
137 | // finally, finish up the layouts | 144 | // finally, finish up the layouts | ||
138 | mRightLayout = new QVBoxLayout; | 145 | mRightLayout = new QVBoxLayout; | ||
139 | mRightLayout->addStretch(1); | 146 | mRightLayout->addStretch(1); | ||
140 | mRightLayout->addWidget(mCaptureModeLabel); | 147 | mRightLayout->addWidget(mCaptureModeLabel); | ||
141 | mRightLayout->addLayout(mCaptureModeForm); | 148 | mRightLayout->addLayout(mCaptureModeForm); | ||
142 | mRightLayout->addStretch(1); | 149 | mRightLayout->addStretch(1); | ||
143 | mRightLayout->addWidget(mContentOptionsLabel); | 150 | mRightLayout->addWidget(mContentOptionsLabel); | ||
Show All 12 Lines | |||||
156 | mMousePointer->setChecked (lConfigMgr->includePointerChecked()); | 163 | mMousePointer->setChecked (lConfigMgr->includePointerChecked()); | ||
157 | mWindowDecorations->setChecked (lConfigMgr->includeDecorationsChecked()); | 164 | mWindowDecorations->setChecked (lConfigMgr->includeDecorationsChecked()); | ||
158 | mCaptureOnClick->setChecked (lConfigMgr->onClickChecked()); | 165 | mCaptureOnClick->setChecked (lConfigMgr->onClickChecked()); | ||
159 | mCaptureTransientOnly->setChecked (lConfigMgr->captureTransientWindowOnlyChecked()); | 166 | mCaptureTransientOnly->setChecked (lConfigMgr->captureTransientWindowOnlyChecked()); | ||
160 | mQuitAfterSaveOrCopy->setChecked (lConfigMgr->quitAfterSaveOrCopyChecked()); | 167 | mQuitAfterSaveOrCopy->setChecked (lConfigMgr->quitAfterSaveOrCopyChecked()); | ||
161 | if (lConfigMgr->captureMode() >= 0) { | 168 | if (lConfigMgr->captureMode() >= 0) { | ||
162 | mCaptureArea->setCurrentIndex (lConfigMgr->captureMode()); | 169 | mCaptureArea->setCurrentIndex (lConfigMgr->captureMode()); | ||
163 | } | 170 | } | ||
164 | mDelayMsec->setValue (lConfigMgr->captureDelay()); | 171 | mDelayMsec->setValue (lConfigMgr->captureDelay()); | ||
broulik: Unrelated change | |||||
davidre: It looked so bad I thought I had accidentally changed it | |||||
165 | } | 172 | } | ||
166 | 173 | | |||
167 | int KSWidget::imagePaddingWidth() const | 174 | int KSWidget::imagePaddingWidth() const | ||
168 | { | 175 | { | ||
169 | int lRightLayoutLeft = 0; | 176 | int lRightLayoutLeft = 0; | ||
170 | int lRightLayoutRight = 0; | 177 | int lRightLayoutRight = 0; | ||
171 | int lMainLayoutRight = 0; | 178 | int lMainLayoutRight = 0; | ||
172 | 179 | | |||
Show All 34 Lines | |||||
207 | { | 214 | { | ||
208 | int lDelay = mCaptureOnClick->isChecked() ? -1 : (mDelayMsec->value() * 1000); | 215 | int lDelay = mCaptureOnClick->isChecked() ? -1 : (mDelayMsec->value() * 1000); | ||
209 | auto lMode = static_cast<Spectacle::CaptureMode>(mCaptureArea->currentData().toInt()); | 216 | auto lMode = static_cast<Spectacle::CaptureMode>(mCaptureArea->currentData().toInt()); | ||
210 | if (mTransientWithParentAvailable && | 217 | if (mTransientWithParentAvailable && | ||
211 | lMode == Spectacle::CaptureMode::WindowUnderCursor && | 218 | lMode == Spectacle::CaptureMode::WindowUnderCursor && | ||
212 | !(mCaptureTransientOnly->isChecked())) { | 219 | !(mCaptureTransientOnly->isChecked())) { | ||
213 | lMode = Spectacle::CaptureMode::TransientWithParent; | 220 | lMode = Spectacle::CaptureMode::TransientWithParent; | ||
214 | } | 221 | } | ||
222 | setButtonState(State::Cancel); | ||||
215 | emit newScreenshotRequest(lMode, lDelay, mMousePointer->isChecked(), mWindowDecorations->isChecked()); | 223 | emit newScreenshotRequest(lMode, lDelay, mMousePointer->isChecked(), mWindowDecorations->isChecked()); | ||
broulik: Clever trick I must say :) | |||||
216 | } | 224 | } | ||
217 | 225 | | |||
218 | void KSWidget::onClickStateChanged(int theState) | 226 | void KSWidget::onClickStateChanged(int theState) | ||
219 | { | 227 | { | ||
220 | if (theState == Qt::Checked) { | 228 | if (theState == Qt::Checked) { | ||
221 | mDelayMsec->setEnabled(false); | 229 | mDelayMsec->setEnabled(false); | ||
222 | } else if (theState == Qt::Unchecked) { | 230 | } else if (theState == Qt::Unchecked) { | ||
223 | mDelayMsec->setEnabled(true); | 231 | mDelayMsec->setEnabled(true); | ||
Show All 27 Lines | 256 | case Spectacle::CaptureMode::RectangularRegion: | |||
251 | break; | 259 | break; | ||
252 | case Spectacle::CaptureMode::TransientWithParent: | 260 | case Spectacle::CaptureMode::TransientWithParent: | ||
253 | case Spectacle::CaptureMode::InvalidChoice: | 261 | case Spectacle::CaptureMode::InvalidChoice: | ||
254 | default: | 262 | default: | ||
255 | qCWarning(SPECTACLE_GUI_LOG) << "Skipping invalid or unreachable enum value"; | 263 | qCWarning(SPECTACLE_GUI_LOG) << "Skipping invalid or unreachable enum value"; | ||
256 | break; | 264 | break; | ||
257 | } | 265 | } | ||
258 | } | 266 | } | ||
267 | | ||||
268 | void KSWidget::setButtonState(State state) | ||||
Thinking about it, would using an enum make this nicer? broulik: Thinking about it, would using an `enum` make this nicer?
`setButtonState(State::Cancel)` or… | |||||
269 | { | ||||
270 | switch (state) { | ||||
271 | case State::TakeNewScreenshot: | ||||
272 | mTakeScreenshotButton->removeAction(mCancelAction); | ||||
273 | mTakeScreenshotButton->setDefaultAction(mTakeNewScreenshotAction); | ||||
274 | break; | ||||
275 | case State::Cancel: | ||||
276 | mTakeScreenshotButton->removeAction(mTakeNewScreenshotAction); | ||||
277 | mTakeScreenshotButton->setDefaultAction(mCancelAction); | ||||
278 | break; | ||||
279 | } | ||||
280 | } |
Keep the label as it was: "Take a New Screenshot"