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 | } | ||||
rkflx: Modernize like you've done before… | |||||
296 | | ||||
299 | mMessageWidget->setMessageType(KMessageWidget::Information); | 297 | mMessageWidget->setMessageType(KMessageWidget::Information); | ||
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… | |||||
300 | mMessageWidget->setText(i18n("The screenshot has been copied to the clipboard.")); | 298 | mMessageWidget->setText(i18n("The screenshot has been copied to the clipboard.")); | ||
301 | mMessageWidget->setIcon(QIcon::fromTheme(QStringLiteral("dialog-information"))); | 299 | mMessageWidget->setIcon(QIcon::fromTheme(QStringLiteral("dialog-information"))); | ||
302 | 300 | | |||
303 | mMessageWidget->animatedShow(); | 301 | mMessageWidget->animatedShow(); | ||
304 | QTimer::singleShot(10000, mMessageWidget, &KMessageWidget::animatedHide); | 302 | QTimer::singleShot(10000, mMessageWidget, &KMessageWidget::animatedHide); | ||
305 | } | 303 | } | ||
306 | 304 | | |||
307 | void KSMainWindow::showPreferencesDialog() | 305 | void KSMainWindow::showPreferencesDialog() | ||
308 | { | 306 | { | ||
309 | SettingsDialog prefDialog(this); | 307 | SettingsDialog prefDialog(this); | ||
310 | prefDialog.exec(); | 308 | prefDialog.exec(); | ||
311 | } | 309 | } | ||
312 | 310 | | |||
313 | void KSMainWindow::setScreenshotWindowTitle(QUrl location) | 311 | void KSMainWindow::setScreenshotWindowTitle(QUrl location) | ||
314 | { | 312 | { | ||
315 | setWindowTitle(location.fileName()); | 313 | setWindowTitle(location.fileName()); | ||
316 | setWindowModified(false); | 314 | setWindowModified(false); | ||
317 | } | 315 | } | ||
318 | 316 | | |||
319 | void KSMainWindow::save() | 317 | void KSMainWindow::save() | ||
320 | { | 318 | { | ||
321 | SpectacleConfig::instance()->setLastUsedSaveMode(1); | 319 | SpectacleConfig::instance()->setLastUsedSaveMode(1); | ||
322 | buildSaveMenu(); | 320 | buildSaveMenu(); | ||
321 | | ||||
322 | if (SpectacleConfig::instance()->quitAfterSaveOrCopyChecked()) { | ||||
323 | ExportManager::instance()->doSave(QUrl(), true); | ||||
324 | qApp->setQuitOnLastWindowClosed(false); | ||||
rkflx: `//`? | |||||
325 | hide(); | ||||
326 | } | ||||
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 | else { | ||||
323 | ExportManager::instance()->doSave(); | 328 | ExportManager::instance()->doSave(); | ||
324 | } | 329 | } | ||
330 | } | ||||
325 | 331 | | |||
326 | void KSMainWindow::saveAs() | 332 | void KSMainWindow::saveAs() | ||
327 | { | 333 | { | ||
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… | |||||
328 | SpectacleConfig::instance()->setLastUsedSaveMode(0); | 334 | SpectacleConfig::instance()->setLastUsedSaveMode(0); | ||
329 | buildSaveMenu(); | 335 | buildSaveMenu(); | ||
330 | ExportManager::instance()->doSaveAs(this); | | |||
331 | } | | |||
332 | 336 | | |||
333 | void KSMainWindow::saveAndExit() | 337 | if (SpectacleConfig::instance()->quitAfterSaveOrCopyChecked()) { | ||
334 | { | 338 | if (ExportManager::instance()->doSaveAs(this, true)) { | ||
335 | SpectacleConfig::instance()->setLastUsedSaveMode(2); | | |||
336 | qApp->setQuitOnLastWindowClosed(false); | | |||
337 | ExportManager::instance()->doSave(QUrl(), true); | | |||
338 | hide(); | 339 | 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 | } | 340 | } | ||
341 | } | ||||
342 | else { | ||||
343 | ExportManager::instance()->doSaveAs(this, false); | ||||
344 | } | ||||
345 | } |
This works for me too and might be more modern Qt: