Changeset View
Standalone View
src/Gui/KSMainWindow.cpp
Show First 20 Lines • Show All 182 Lines • ▼ Show 20 Line(s) | 108 | { | |||
---|---|---|---|---|---|
183 | 183 | | |||
184 | // disable onClick mode if not available on the platform | 184 | // disable onClick mode if not available on the platform | ||
185 | 185 | | |||
186 | if (!mOnClickAvailable) { | 186 | if (!mOnClickAvailable) { | ||
187 | mKSWidget->disableOnClick(); | 187 | mKSWidget->disableOnClick(); | ||
188 | } | 188 | } | ||
189 | resize(QSize(840, 420).expandedTo(minimumSize())); | 189 | resize(QSize(840, 420).expandedTo(minimumSize())); | ||
190 | 190 | | |||
191 | // Allow Ctrl+Q to quit the app | ||||
192 | QAction *actionQuit = KStandardAction::quit(qApp, &QApplication::quit, this); | ||||
193 | actionQuit->setShortcut(QKeySequence::Quit); | ||||
rkflx: This works for me too and might be more modern Qt:
QAction *actionQuit = KStandardAction… | |||||
194 | addAction(actionQuit); | ||||
191 | 195 | | |||
192 | // done with the init | 196 | // done with the init | ||
193 | } | 197 | } | ||
194 | 198 | | |||
195 | void KSMainWindow::buildSaveMenu() | 199 | void KSMainWindow::buildSaveMenu() | ||
196 | { | 200 | { | ||
197 | // first clear the menu | 201 | // first clear the menu | ||
198 | mSaveMenu->clear(); | 202 | mSaveMenu->clear(); | ||
199 | 203 | | |||
rkflx: Now {key Ctrl Q} does not work anymore. | |||||
200 | // get our actions in order | 204 | // get our actions in order | ||
201 | QAction *actionSave = KStandardAction::save(this, &KSMainWindow::save, this); | 205 | QAction *actionSave = KStandardAction::save(this, &KSMainWindow::save, this); | ||
202 | QAction *actionSaveAs = KStandardAction::saveAs(this, &KSMainWindow::saveAs, this); | 206 | QAction *actionSaveAs = KStandardAction::saveAs(this, &KSMainWindow::saveAs, this); | ||
203 | QAction *actionSaveExit = new QAction(QIcon::fromTheme(QStringLiteral("document-save")), i18n("Save &&& Exit"), this); | | |||
204 | actionSaveExit->setToolTip(i18n("Save screenshot in your Pictures directory and exit")); | | |||
205 | actionSaveExit->setShortcut(QKeySequence(QKeySequence::Quit)); | | |||
206 | connect(actionSaveExit, &QAction::triggered, this, &KSMainWindow::saveAndExit); | | |||
207 | 207 | | |||
208 | // static or dynamic | 208 | // static or dynamic | ||
209 | SpectacleConfig *cfgManager = SpectacleConfig::instance(); | 209 | SpectacleConfig *cfgManager = SpectacleConfig::instance(); | ||
210 | int switchState = cfgManager->useDynamicSaveButton() ? cfgManager->lastUsedSaveMode() : 0; | 210 | int switchState = cfgManager->useDynamicSaveButton() ? cfgManager->lastUsedSaveMode() : 0; | ||
211 | 211 | | |||
212 | // put the actions in order | 212 | // put the actions in order | ||
213 | switch (switchState) { | 213 | switch (switchState) { | ||
214 | case 0: | 214 | case 0: | ||
215 | default: | 215 | default: | ||
216 | mSaveButton->setDefaultAction(actionSaveAs); | 216 | mSaveButton->setDefaultAction(actionSaveAs); | ||
217 | mSaveMenu->addAction(actionSaveExit); | | |||
218 | mSaveMenu->addAction(actionSave); | 217 | mSaveMenu->addAction(actionSave); | ||
219 | break; | 218 | break; | ||
220 | case 1: | 219 | case 1: | ||
221 | mSaveButton->setDefaultAction(actionSave); | 220 | mSaveButton->setDefaultAction(actionSave); | ||
222 | mSaveMenu->addAction(actionSaveExit); | | |||
223 | mSaveMenu->addAction(actionSaveAs); | | |||
224 | break; | | |||
225 | case 2: | | |||
226 | mSaveButton->setDefaultAction(actionSaveExit); | | |||
227 | mSaveMenu->addAction(actionSave); | | |||
228 | mSaveMenu->addAction(actionSaveAs); | 221 | mSaveMenu->addAction(actionSaveAs); | ||
229 | break; | 222 | break; | ||
230 | } | 223 | } | ||
231 | } | 224 | } | ||
232 | 225 | | |||
233 | // overrides | 226 | // overrides | ||
234 | 227 | | |||
235 | void KSMainWindow::moveEvent(QMoveEvent *event) | 228 | void KSMainWindow::moveEvent(QMoveEvent *event) | ||
Show All 25 Lines | 248 | { | |||
261 | 254 | | |||
262 | show(); | 255 | show(); | ||
263 | } | 256 | } | ||
264 | 257 | | |||
265 | void KSMainWindow::showPrintDialog() | 258 | void KSMainWindow::showPrintDialog() | ||
266 | { | 259 | { | ||
267 | QPrinter *printer = new QPrinter(QPrinter::HighResolution); | 260 | QPrinter *printer = new QPrinter(QPrinter::HighResolution); | ||
268 | QPrintDialog printDialog(printer, this); | 261 | QPrintDialog printDialog(printer, this); | ||
269 | if (printDialog.exec() == QDialog::Accepted) { | 262 | if (printDialog.exec() == QDialog::Accepted) { | ||
270 | ExportManager::instance()->doPrint(printer); | 263 | ExportManager::instance()->doPrint(printer); | ||
271 | return; | 264 | return; | ||
That's wrong: This way Print does not quit when accepting, but when cancelling (IMO it should never quit, so perhaps edit the test plan and remove this code). rkflx: That's wrong: This way {nav Print} does not quit when accepting, but when cancelling (IMO it… | |||||
272 | } | 265 | } | ||
273 | delete printer; | 266 | delete printer; | ||
274 | } | 267 | } | ||
275 | 268 | | |||
276 | void KSMainWindow::showImageSharedFeedback(bool error, const QString &message) | 269 | void KSMainWindow::showImageSharedFeedback(bool error, const QString &message) | ||
277 | { | 270 | { | ||
278 | if (error) { | 271 | if (error) { | ||
Personally, I wouldn't quit here either. Did not test this part, but at least I'd expect some form of feedback about success or error. rkflx: Personally, I wouldn't quit here either. Did not test this part, but at least I'd expect some… | |||||
279 | mMessageWidget->setMessageType(KMessageWidget::Error); | 272 | mMessageWidget->setMessageType(KMessageWidget::Error); | ||
280 | mMessageWidget->setText(i18n("There was a problem sharing the image: %1", message)); | 273 | mMessageWidget->setText(i18n("There was a problem sharing the image: %1", message)); | ||
281 | mMessageWidget->setIcon(QIcon::fromTheme(QStringLiteral("dialog-error"))); | 274 | mMessageWidget->setIcon(QIcon::fromTheme(QStringLiteral("dialog-error"))); | ||
282 | } else { | 275 | } else { | ||
283 | mMessageWidget->setMessageType(KMessageWidget::Positive); | 276 | mMessageWidget->setMessageType(KMessageWidget::Positive); | ||
284 | if (message.isEmpty()) | 277 | if (message.isEmpty()) | ||
285 | mMessageWidget->setText(i18n("Image shared")); | 278 | mMessageWidget->setText(i18n("Image shared")); | ||
286 | else | 279 | else | ||
287 | mMessageWidget->setText(i18n("You can find the shared image at: <a href=\"%1\">%1</a>", message)); | 280 | mMessageWidget->setText(i18n("You can find the shared image at: <a href=\"%1\">%1</a>", message)); | ||
288 | mMessageWidget->setIcon(QIcon::fromTheme(QStringLiteral("dialog-ok-apply"))); | 281 | mMessageWidget->setIcon(QIcon::fromTheme(QStringLiteral("dialog-ok-apply"))); | ||
289 | } | 282 | } | ||
290 | 283 | | |||
291 | mMessageWidget->animatedShow(); | 284 | mMessageWidget->animatedShow(); | ||
292 | QTimer::singleShot(20000, mMessageWidget, &KMessageWidget::animatedHide); | 285 | QTimer::singleShot(20000, mMessageWidget, &KMessageWidget::animatedHide); | ||
293 | } | 286 | } | ||
294 | 287 | | |||
295 | void KSMainWindow::sendToClipboard() | 288 | void KSMainWindow::sendToClipboard() | ||
296 | { | 289 | { | ||
297 | ExportManager::instance()->doCopyToClipboard(); | 290 | ExportManager::instance()->doCopyToClipboard(); | ||
298 | 291 | | |||
292 | if (SpectacleConfig::instance()->quitAfterSaveOrCopyChecked()) { | ||||
293 | qApp->setQuitOnLastWindowClosed(false); | ||||
294 | hide(); | ||||
295 | QTimer::singleShot(250, qApp, SLOT(quit())); | ||||
rkflx: Modernize like you've done before… | |||||
296 | } | ||||
297 | | ||||
Is pasting a screenshot after Copy To Clipboard → Quit actually working? For me it isn't, regardless of the state of the checkbox. Can you confirm? rkflx: Is pasting a screenshot after {nav Copy To Clipboard > Quit} actually working? For me it isn't… | |||||
Oh right, this doesn't work yet on X11 because the image can't be saved to the standard X11 clipboard. See D9117 for more information. The patch author there might be able to get it working with a bit of technical assistance (a bit beyond my level, I'm afraid). ngraham: Oh right, this doesn't work yet on X11 because the image can't be saved to the standard X11… | |||||
I could get it to work for manually copying and quitting by unchecking "Ignore images" in Klipper's settings (it's checked by default, but why?). Still, for auto-quit I'm still unable to paste afterwards and the image does not appear in Klipper. It might be a problem in your code, if it works on X11 in other cases. rkflx: I could get it to work for manually copying and quitting by unchecking "Ignore images" in… | |||||
299 | mMessageWidget->setMessageType(KMessageWidget::Information); | 298 | mMessageWidget->setMessageType(KMessageWidget::Information); | ||
300 | mMessageWidget->setText(i18n("The screenshot has been copied to the clipboard.")); | 299 | mMessageWidget->setText(i18n("The screenshot has been copied to the clipboard.")); | ||
301 | mMessageWidget->setIcon(QIcon::fromTheme(QStringLiteral("dialog-information"))); | 300 | mMessageWidget->setIcon(QIcon::fromTheme(QStringLiteral("dialog-information"))); | ||
302 | 301 | | |||
303 | mMessageWidget->animatedShow(); | 302 | mMessageWidget->animatedShow(); | ||
304 | QTimer::singleShot(10000, mMessageWidget, &KMessageWidget::animatedHide); | 303 | QTimer::singleShot(10000, mMessageWidget, &KMessageWidget::animatedHide); | ||
305 | } | 304 | } | ||
306 | 305 | | |||
307 | void KSMainWindow::showPreferencesDialog() | 306 | void KSMainWindow::showPreferencesDialog() | ||
308 | { | 307 | { | ||
309 | SettingsDialog prefDialog(this); | 308 | SettingsDialog prefDialog(this); | ||
310 | prefDialog.exec(); | 309 | prefDialog.exec(); | ||
311 | } | 310 | } | ||
312 | 311 | | |||
313 | void KSMainWindow::setScreenshotWindowTitle(QUrl location) | 312 | void KSMainWindow::setScreenshotWindowTitle(QUrl location) | ||
314 | { | 313 | { | ||
315 | setWindowTitle(location.fileName()); | 314 | setWindowTitle(location.fileName()); | ||
316 | setWindowModified(false); | 315 | setWindowModified(false); | ||
317 | } | 316 | } | ||
318 | 317 | | |||
319 | void KSMainWindow::save() | 318 | void KSMainWindow::save() | ||
320 | { | 319 | { | ||
321 | SpectacleConfig::instance()->setLastUsedSaveMode(1); | 320 | SpectacleConfig::instance()->setLastUsedSaveMode(1); | ||
322 | buildSaveMenu(); | 321 | buildSaveMenu(); | ||
322 | | ||||
323 | if (SpectacleConfig::instance()->quitAfterSaveOrCopyChecked()) { | ||||
324 | ExportManager::instance()->doSave(QUrl(), true); | ||||
325 | qApp->setQuitOnLastWindowClosed(false); | ||||
rkflx: `//`? | |||||
326 | hide(); | ||||
I see you copied this over, however do you know what this is for? Perhaps related to Bug 389694? rkflx: I see you copied this over, however do you know what this is for? Perhaps related to [Bug… | |||||
This is to prevent Spectacle from quitting before the notification is displayed, I believe. I'm open to better ways of accomplishing the same thing, because I've noticed that bug, too. ngraham: This is to prevent Spectacle from quitting before the notification is displayed, I believe. I'm… | |||||
Okay, thanks for checking. I have no time to investigate this further currently. Let's do it this way: Keep the calls everywhere they are needed, and we have the bug to track the issue (perhaps add a comment over there). rkflx: Okay, thanks for checking. I have no time to investigate this further currently.
Let's do it… | |||||
327 | } | ||||
328 | else { | ||||
323 | ExportManager::instance()->doSave(); | 329 | ExportManager::instance()->doSave(); | ||
324 | } | 330 | } | ||
331 | } | ||||
325 | 332 | | |||
326 | void KSMainWindow::saveAs() | 333 | void KSMainWindow::saveAs() | ||
Somewhere there's a bug: Cancelling the Save As dialog quits, but it should only abort the dialog. rkflx: Somewhere there's a bug: {nav Cancelling} the {nav Save As} dialog quits, but it should only… | |||||
327 | { | 334 | { | ||
328 | SpectacleConfig::instance()->setLastUsedSaveMode(0); | 335 | SpectacleConfig::instance()->setLastUsedSaveMode(0); | ||
329 | buildSaveMenu(); | 336 | buildSaveMenu(); | ||
330 | ExportManager::instance()->doSaveAs(this); | | |||
331 | } | | |||
332 | 337 | | |||
333 | void KSMainWindow::saveAndExit() | 338 | if (SpectacleConfig::instance()->quitAfterSaveOrCopyChecked()) { | ||
334 | { | 339 | if (ExportManager::instance()->doSaveAs(this, true)) { | ||
335 | SpectacleConfig::instance()->setLastUsedSaveMode(2); | | |||
336 | qApp->setQuitOnLastWindowClosed(false); | | |||
337 | ExportManager::instance()->doSave(QUrl(), true); | | |||
338 | hide(); | 340 | hide(); | ||
rkflx: > {nav Save As} must be fixed
qApp->setQuitOnLastWindowClosed(false);
hide(); | |||||
rkflx: Ping (otherwise clicking on {nav Open} in the notfication is broken). | |||||
339 | } | 341 | } | ||
342 | } | ||||
343 | else { | ||||
344 | ExportManager::instance()->doSaveAs(this, false); | ||||
345 | } | ||||
346 | } |
This works for me too and might be more modern Qt: