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