Changeset View
Changeset View
Standalone View
Standalone View
src/Gui/KSMainWindow.cpp
Show First 20 Lines • Show All 116 Lines • ▼ Show 20 Line(s) | 115 | { | |||
---|---|---|---|---|---|
117 | KConfigGroup guiConfig(config, "GuiConfig"); | 117 | KConfigGroup guiConfig(config, "GuiConfig"); | ||
118 | 118 | | |||
119 | // window properties | 119 | // window properties | ||
120 | setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); | 120 | setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); | ||
121 | 121 | | |||
122 | QPoint location = guiConfig.readEntry("window-position", QPoint(50, 50)); | 122 | QPoint location = guiConfig.readEntry("window-position", QPoint(50, 50)); | ||
123 | move(location); | 123 | move(location); | ||
124 | 124 | | |||
125 | // change window title on save | 125 | // change window title on save and on autosave | ||
126 | 126 | | |||
127 | connect(ExportManager::instance(), &ExportManager::imageSaved, this, &KSMainWindow::imageSaved); | 127 | connect(ExportManager::instance(), &ExportManager::imageSaved, this, &KSMainWindow::imageSaved); | ||
128 | connect(ExportManager::instance(), &ExportManager::imageSavedAndCopied, this, &KSMainWindow::imageSavedAndCopied); | ||||
aprcela: already connected signal | |||||
128 | 129 | | |||
129 | // the KSGWidget | 130 | // the KSGWidget | ||
130 | 131 | | |||
131 | connect(mKSWidget, &KSWidget::newScreenshotRequest, this, &KSMainWindow::captureScreenshot); | 132 | connect(mKSWidget, &KSWidget::newScreenshotRequest, this, &KSMainWindow::captureScreenshot); | ||
132 | connect(mKSWidget, &KSWidget::dragInitiated, this, &KSMainWindow::dragAndDropRequest); | 133 | connect(mKSWidget, &KSWidget::dragInitiated, this, &KSMainWindow::dragAndDropRequest); | ||
133 | 134 | | |||
134 | // the Button Bar | 135 | // the Button Bar | ||
135 | 136 | | |||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Line(s) | |||||
215 | } | 216 | } | ||
216 | resize(QSize(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT).expandedTo(minimumSize())); | 217 | resize(QSize(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT).expandedTo(minimumSize())); | ||
217 | 218 | | |||
218 | // Allow Ctrl+Q to quit the app | 219 | // Allow Ctrl+Q to quit the app | ||
219 | QAction *actionQuit = KStandardAction::quit(qApp, &QApplication::quit, this); | 220 | QAction *actionQuit = KStandardAction::quit(qApp, &QApplication::quit, this); | ||
220 | actionQuit->setShortcut(QKeySequence::Quit); | 221 | actionQuit->setShortcut(QKeySequence::Quit); | ||
221 | addAction(actionQuit); | 222 | addAction(actionQuit); | ||
222 | 223 | | |||
224 | // message: open containing folder | ||||
225 | mOpenContaining = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder"), mMessageWidget); | ||||
226 | | ||||
223 | mHideMessageWidgetTimer = new QTimer(this); | 227 | mHideMessageWidgetTimer = new QTimer(this); | ||
224 | connect(mHideMessageWidgetTimer, &QTimer::timeout, | 228 | connect(mHideMessageWidgetTimer, &QTimer::timeout, | ||
225 | mMessageWidget, &KMessageWidget::animatedHide); | 229 | mMessageWidget, &KMessageWidget::animatedHide); | ||
226 | mHideMessageWidgetTimer->setInterval(10000); | 230 | mHideMessageWidgetTimer->setInterval(10000); | ||
227 | // done with the init | 231 | // done with the init | ||
228 | } | 232 | } | ||
229 | 233 | | |||
230 | int KSMainWindow::windowWidth(const QPixmap &pixmap) const | 234 | int KSMainWindow::windowWidth(const QPixmap &pixmap) const | ||
▲ Show 20 Lines • Show All 241 Lines • ▼ Show 20 Line(s) | 475 | { | |||
472 | SettingsDialog prefDialog(this); | 476 | SettingsDialog prefDialog(this); | ||
473 | prefDialog.exec(); | 477 | prefDialog.exec(); | ||
474 | } | 478 | } | ||
475 | 479 | | |||
476 | void KSMainWindow::imageSaved(const QUrl &location) | 480 | void KSMainWindow::imageSaved(const QUrl &location) | ||
477 | { | 481 | { | ||
478 | setWindowTitle(location.fileName()); | 482 | setWindowTitle(location.fileName()); | ||
479 | setWindowModified(false); | 483 | setWindowModified(false); | ||
480 | QAction* openContaining = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder"), mMessageWidget); | 484 | connect(mOpenContaining, &QAction::triggered, [=] { KIO::highlightInFileManager({location});}); | ||
davidre: We can also move and unify the connect calls into `init`. | |||||
Took me a while to understand this, as I never worked with lambdas before.. What about the variable location? aprcela: Took me a while to understand this, as I never worked with lambdas before..
What about the… | |||||
481 | connect(openContaining, &QAction::triggered, [=] { KIO::highlightInFileManager({location});}); | | |||
482 | showInlineMessage(i18n("The screenshot was saved as <a href=\"%1\">%2</a>", | 485 | showInlineMessage(i18n("The screenshot was saved as <a href=\"%1\">%2</a>", | ||
davidre: Sorry, I totally missed that but good idea to use `lastSaveFile()`. | |||||
483 | location.toString(), location.fileName()), KMessageWidget::Positive, | 486 | location.toString(), location.fileName()), KMessageWidget::Positive, | ||
484 | MessageDuration::AutoHide, {openContaining}); | 487 | MessageDuration::AutoHide, {mOpenContaining}); | ||
488 | } | ||||
489 | | ||||
490 | void KSMainWindow::imageSavedAndCopied(const QUrl &location) | ||||
491 | { | ||||
492 | setWindowTitle(location.fileName()); | ||||
493 | setWindowModified(false); | ||||
494 | connect(mOpenContaining, &QAction::triggered, [=] { KIO::highlightInFileManager({location});}); | ||||
495 | showInlineMessage(i18n("The screenshot was copied to the clipboard and saved as <a href=\"%1\">%2</a>", | ||||
496 | location.toString(), location.fileName()), KMessageWidget::Positive, | ||||
497 | MessageDuration::AutoHide, {mOpenContaining}); | ||||
485 | } | 498 | } | ||
486 | 499 | | |||
487 | void KSMainWindow::save() | 500 | void KSMainWindow::save() | ||
488 | { | 501 | { | ||
489 | SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::Save); | 502 | SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::Save); | ||
490 | setDefaultSaveAction(); | 503 | setDefaultSaveAction(); | ||
491 | 504 | | |||
We can make this action a member variable to reduce code duplication and use it here and in imageSaved. davidre: We can make this action a member variable to reduce code duplication and use it here and in… | |||||
aprcela: Changed.
Gets set in `init()`
Name: `mOpenContaining` | |||||
492 | const bool quitChecked = SpectacleConfig::instance()->quitAfterSaveOrCopyChecked(); | 505 | const bool quitChecked = SpectacleConfig::instance()->quitAfterSaveOrCopyChecked(); | ||
493 | ExportManager::instance()->doSave(QUrl(), /* notify */ quitChecked); | 506 | ExportManager::instance()->doSave(QUrl(), /* notify */ quitChecked); | ||
494 | if (quitChecked) { | 507 | if (quitChecked) { | ||
495 | quit(QuitBehavior::QuitExternally); | 508 | quit(QuitBehavior::QuitExternally); | ||
496 | } | 509 | } | ||
497 | } | 510 | } | ||
498 | 511 | | |||
499 | void KSMainWindow::saveAs() | 512 | void KSMainWindow::saveAs() | ||
Show All 18 Lines |
already connected signal