Changeset View
Changeset View
Standalone View
Standalone View
src/Gui/KSWidget.cpp
Show All 31 Lines | |||||
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 | 37 | | |||
38 | #include <KLocalizedString> | 38 | #include <KLocalizedString> | ||
39 | 39 | | |||
40 | KSWidget::KSWidget(const Platform::GrabModes &theGrabModes, QWidget *parent) : | 40 | KSWidget::KSWidget(const CaptureModes &theCaptureModes, QWidget *parent) : | ||
41 | QWidget(parent) | 41 | QWidget(parent) | ||
42 | { | 42 | { | ||
43 | // get a handle to the configuration manager | 43 | // get a handle to the configuration manager | ||
44 | SpectacleConfig *lConfigMgr = SpectacleConfig::instance(); | 44 | SpectacleConfig *lConfigMgr = SpectacleConfig::instance(); | ||
45 | 45 | | |||
46 | // we'll init the widget that holds the image first | 46 | // we'll init the widget that holds the image first | ||
47 | mImageWidget = new KSImageWidget(this); | 47 | mImageWidget = new KSImageWidget(this); | ||
48 | mImageWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | 48 | mImageWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | ||
49 | connect(mImageWidget, &KSImageWidget::dragInitiated, this, &KSWidget::dragInitiated); | 49 | connect(mImageWidget, &KSImageWidget::dragInitiated, this, &KSWidget::dragInitiated); | ||
50 | 50 | | |||
51 | // the capture mode options first | 51 | // the capture mode options first | ||
52 | mCaptureModeLabel = new QLabel(i18n("<b>Capture Mode</b>"), this); | 52 | mCaptureModeLabel = new QLabel(i18n("<b>Capture Mode</b>"), this); | ||
53 | mCaptureArea = new QComboBox(this); | 53 | 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); | 54 | mCaptureArea->setMinimumWidth(240); | ||
55 | initComboBox(theCaptureModes); | ||||
71 | connect(mCaptureArea, qOverload<int>(&QComboBox::currentIndexChanged), this, &KSWidget::captureModeChanged); | 56 | connect(mCaptureArea, qOverload<int>(&QComboBox::currentIndexChanged), this, &KSWidget::captureModeChanged); | ||
72 | 57 | | |||
73 | mDelayMsec = new SmartSpinBox(this); | 58 | mDelayMsec = new SmartSpinBox(this); | ||
74 | mDelayMsec->setDecimals(1); | 59 | mDelayMsec->setDecimals(1); | ||
75 | mDelayMsec->setSingleStep(1.0); | 60 | mDelayMsec->setSingleStep(1.0); | ||
76 | mDelayMsec->setMinimum(0.0); | 61 | mDelayMsec->setMinimum(0.0); | ||
77 | mDelayMsec->setMaximum(999.9); | 62 | mDelayMsec->setMaximum(999.9); | ||
78 | mDelayMsec->setSpecialValueText(i18n("No Delay")); | 63 | mDelayMsec->setSpecialValueText(i18n("No Delay")); | ||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | |||||
166 | mCaptureTransientOnly->setChecked (lConfigMgr->captureTransientWindowOnlyChecked()); | 151 | mCaptureTransientOnly->setChecked (lConfigMgr->captureTransientWindowOnlyChecked()); | ||
167 | mQuitAfterSaveOrCopy->setChecked (lConfigMgr->quitAfterSaveOrCopyChecked()); | 152 | mQuitAfterSaveOrCopy->setChecked (lConfigMgr->quitAfterSaveOrCopyChecked()); | ||
168 | if (lConfigMgr->captureMode() >= 0) { | 153 | if (lConfigMgr->captureMode() >= 0) { | ||
169 | mCaptureArea->setCurrentIndex (lConfigMgr->captureMode()); | 154 | mCaptureArea->setCurrentIndex (lConfigMgr->captureMode()); | ||
170 | } | 155 | } | ||
171 | mDelayMsec->setValue (lConfigMgr->captureDelay()); | 156 | mDelayMsec->setValue (lConfigMgr->captureDelay()); | ||
172 | } | 157 | } | ||
173 | 158 | | |||
159 | void KSWidget::initComboBox(const CaptureModes &theCaptureModes) { | ||||
160 | mCaptureArea->clear(); | ||||
161 | | ||||
162 | bool multipleScreenSetup = QApplication::screens().count() != 1; | ||||
163 | | ||||
164 | if (theCaptureModes.testFlag(CaptureMode::AllScreens)) { | ||||
165 | if (multipleScreenSetup) | ||||
166 | mCaptureArea->insertItem(1, i18n("Full Screen (All Monitors)"), static_cast<int>(CaptureMode::AllScreens)); | ||||
167 | else | ||||
168 | mCaptureArea->insertItem(1, i18n("Full Screen"), static_cast<int>(CaptureMode::AllScreens)); | ||||
169 | } | ||||
170 | if (theCaptureModes.testFlag(CaptureMode::CurrentScreen) && multipleScreenSetup) | ||||
171 | mCaptureArea->insertItem(2, i18n("Current Screen"), static_cast<int>(CaptureMode::CurrentScreen)); | ||||
172 | if (theCaptureModes.testFlag(CaptureMode::ActiveWindow)) | ||||
173 | mCaptureArea->insertItem(3, i18n("Active Window"), static_cast<int>(CaptureMode::ActiveWindow)); | ||||
174 | if (theCaptureModes.testFlag(CaptureMode::WindowUnderCursor)) | ||||
175 | mCaptureArea->insertItem(4, i18n("Window Under Cursor"), static_cast<int>(CaptureMode::WindowUnderCursor)); | ||||
176 | if (theCaptureModes.testFlag(CaptureMode::TransientWithParent)) { | ||||
177 | mTransientWithParentAvailable = true; | ||||
178 | } | ||||
179 | if (theCaptureModes.testFlag(CaptureMode::RectangularRegion)) { | ||||
180 | mCaptureArea->insertItem(5, i18n("Rectangular Region"), static_cast<int>(CaptureMode::RectangularRegion)); | ||||
181 | } | ||||
182 | } | ||||
183 | | ||||
174 | int KSWidget::imagePaddingWidth() const | 184 | int KSWidget::imagePaddingWidth() const | ||
175 | { | 185 | { | ||
176 | int lRightLayoutLeft = 0; | 186 | int lRightLayoutLeft = 0; | ||
177 | int lRightLayoutRight = 0; | 187 | int lRightLayoutRight = 0; | ||
178 | int lMainLayoutRight = 0; | 188 | int lMainLayoutRight = 0; | ||
179 | 189 | | |||
180 | mRightLayout->getContentsMargins(&lRightLayoutLeft, nullptr, &lRightLayoutRight, nullptr); | 190 | mRightLayout->getContentsMargins(&lRightLayoutLeft, nullptr, &lRightLayoutRight, nullptr); | ||
181 | mMainLayout->getContentsMargins(nullptr, nullptr, &lMainLayoutRight, nullptr); | 191 | mMainLayout->getContentsMargins(nullptr, nullptr, &lMainLayoutRight, nullptr); | ||
Show All 26 Lines | 215 | { | |||
208 | mDelayMsec->setEnabled(true); | 218 | mDelayMsec->setEnabled(true); | ||
209 | } | 219 | } | ||
210 | 220 | | |||
211 | // private slots | 221 | // private slots | ||
212 | 222 | | |||
213 | void KSWidget::newScreenshotClicked() | 223 | void KSWidget::newScreenshotClicked() | ||
214 | { | 224 | { | ||
215 | int lDelay = mCaptureOnClick->isChecked() ? -1 : (mDelayMsec->value() * 1000); | 225 | int lDelay = mCaptureOnClick->isChecked() ? -1 : (mDelayMsec->value() * 1000); | ||
216 | auto lMode = static_cast<Spectacle::CaptureMode>(mCaptureArea->currentData().toInt()); | 226 | auto lMode = static_cast<CaptureMode>(mCaptureArea->currentData().toInt()); | ||
217 | if (mTransientWithParentAvailable && | 227 | if (mTransientWithParentAvailable && | ||
218 | lMode == Spectacle::CaptureMode::WindowUnderCursor && | 228 | lMode == CaptureMode::WindowUnderCursor && | ||
219 | !(mCaptureTransientOnly->isChecked())) { | 229 | !(mCaptureTransientOnly->isChecked())) { | ||
220 | lMode = Spectacle::CaptureMode::TransientWithParent; | 230 | lMode = CaptureMode::TransientWithParent; | ||
221 | } | 231 | } | ||
222 | setButtonState(State::Cancel); | 232 | setButtonState(State::Cancel); | ||
223 | emit newScreenshotRequest(lMode, lDelay, mMousePointer->isChecked(), mWindowDecorations->isChecked()); | 233 | emit newScreenshotRequest(lMode, lDelay, mMousePointer->isChecked(), mWindowDecorations->isChecked()); | ||
224 | } | 234 | } | ||
225 | 235 | | |||
226 | void KSWidget::onClickStateChanged(int theState) | 236 | void KSWidget::onClickStateChanged(int theState) | ||
227 | { | 237 | { | ||
228 | if (theState == Qt::Checked) { | 238 | if (theState == Qt::Checked) { | ||
229 | mDelayMsec->setEnabled(false); | 239 | mDelayMsec->setEnabled(false); | ||
230 | } else if (theState == Qt::Unchecked) { | 240 | } else if (theState == Qt::Unchecked) { | ||
231 | mDelayMsec->setEnabled(true); | 241 | mDelayMsec->setEnabled(true); | ||
232 | } | 242 | } | ||
233 | } | 243 | } | ||
234 | 244 | | |||
235 | void KSWidget::captureModeChanged(int theIndex) | 245 | void KSWidget::captureModeChanged(int theIndex) | ||
236 | { | 246 | { | ||
247 | // TO DO: Is it a good idea to save the index? The index might change? | ||||
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 | CaptureMode lCaptureMode = static_cast<CaptureMode>(mCaptureArea->itemData(theIndex).toInt()); | ||
241 | switch(lCaptureMode) { | 252 | switch(lCaptureMode) { | ||
242 | case Spectacle::CaptureMode::WindowUnderCursor: | 253 | case 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 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 CaptureMode::AllScreens: | ||
255 | case Spectacle::CaptureMode::CurrentScreen: | 266 | case CaptureMode::CurrentScreen: | ||
256 | case Spectacle::CaptureMode::RectangularRegion: | 267 | case 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: | | |||
261 | case Spectacle::CaptureMode::InvalidChoice: | | |||
262 | default: | 271 | default: | ||
263 | qCWarning(SPECTACLE_GUI_LOG) << "Skipping invalid or unreachable enum value"; | 272 | qCWarning(SPECTACLE_GUI_LOG) << "Skipping invalid or unreachable enum value"; | ||
264 | break; | 273 | break; | ||
265 | } | 274 | } | ||
266 | } | 275 | } | ||
267 | 276 | | |||
268 | void KSWidget::setButtonState(State state) | 277 | void KSWidget::setButtonState(State state) | ||
269 | { | 278 | { | ||
Show All 18 Lines |