Changeset View
Changeset View
Standalone View
Standalone View
src/Gui/KSMainWindow.cpp
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | 53 | KSMainWindow::KSMainWindow(bool onClickAvailable, QWidget *parent) : | |||
---|---|---|---|---|---|
56 | mDivider(new QFrame), | 56 | mDivider(new QFrame), | ||
57 | mDialogButtonBox(new QDialogButtonBox), | 57 | mDialogButtonBox(new QDialogButtonBox), | ||
58 | mConfigureButton(new QToolButton), | 58 | mConfigureButton(new QToolButton), | ||
59 | mToolsButton(new QPushButton), | 59 | mToolsButton(new QPushButton), | ||
60 | mSendToButton(new QPushButton), | 60 | mSendToButton(new QPushButton), | ||
61 | mClipboardButton(new QToolButton), | 61 | mClipboardButton(new QToolButton), | ||
62 | mSaveButton(new QToolButton), | 62 | mSaveButton(new QToolButton), | ||
63 | mSaveMenu(new QMenu), | 63 | mSaveMenu(new QMenu), | ||
64 | mSaveAsAction(new QAction), | ||||
65 | mSaveAction(new QAction), | ||||
64 | mMessageWidget(new KMessageWidget), | 66 | mMessageWidget(new KMessageWidget), | ||
65 | mToolsMenu(new QMenu), | 67 | mToolsMenu(new QMenu), | ||
66 | mExportMenu(new ExportMenu(this)), | 68 | mExportMenu(new ExportMenu(this)), | ||
67 | mOnClickAvailable(onClickAvailable) | 69 | mOnClickAvailable(onClickAvailable) | ||
68 | { | 70 | { | ||
69 | // before we do anything, we need to set a window property | 71 | // before we do anything, we need to set a window property | ||
70 | // that skips the close/hide window animation on kwin. this | 72 | // that skips the close/hide window animation on kwin. this | ||
71 | // fixes a ghost image of the spectacle window that appears | 73 | // fixes a ghost image of the spectacle window that appears | ||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | 120 | { | |||
158 | mClipboardButton->setText(i18n("Copy To Clipboard")); | 160 | mClipboardButton->setText(i18n("Copy To Clipboard")); | ||
159 | mClipboardButton->setToolTip(i18n("Copy the current screenshot image to the clipboard.")); | 161 | mClipboardButton->setToolTip(i18n("Copy the current screenshot image to the clipboard.")); | ||
160 | mClipboardButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | 162 | mClipboardButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | ||
161 | mDialogButtonBox->addButton(mClipboardButton, QDialogButtonBox::ActionRole); | 163 | mDialogButtonBox->addButton(mClipboardButton, QDialogButtonBox::ActionRole); | ||
162 | 164 | | |||
163 | mSaveButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | 165 | mSaveButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | ||
164 | mSaveButton->setMenu(mSaveMenu); | 166 | mSaveButton->setMenu(mSaveMenu); | ||
165 | mSaveButton->setPopupMode(QToolButton::MenuButtonPopup); | 167 | mSaveButton->setPopupMode(QToolButton::MenuButtonPopup); | ||
166 | buildSaveMenu(); | | |||
167 | mDialogButtonBox->addButton(mSaveButton, QDialogButtonBox::ActionRole); | 168 | mDialogButtonBox->addButton(mSaveButton, QDialogButtonBox::ActionRole); | ||
168 | 169 | | |||
169 | // the help menu | 170 | // the help menu | ||
170 | | ||||
ngraham: Technically this is an unrelated change, but these line breaks bug me too and I was planning to… | |||||
171 | KHelpMenu *helpMenu = new KHelpMenu(this, KAboutData::applicationData(), true); | 171 | KHelpMenu *helpMenu = new KHelpMenu(this, KAboutData::applicationData(), true); | ||
172 | mDialogButtonBox->button(QDialogButtonBox::Help)->setMenu(helpMenu->menu()); | 172 | mDialogButtonBox->button(QDialogButtonBox::Help)->setMenu(helpMenu->menu()); | ||
173 | 173 | | |||
174 | // the save menu | ||||
175 | mSaveAsAction = KStandardAction::saveAs(this, &KSMainWindow::saveAs, this); | ||||
176 | mSaveAction = KStandardAction::save(this, &KSMainWindow::save, this); | ||||
177 | mSaveMenu->addAction(mSaveAsAction); | ||||
178 | mSaveMenu->addAction(mSaveAction); | ||||
179 | setDefaultSaveAction(); | ||||
180 | | ||||
174 | // message widget | 181 | // message widget | ||
175 | connect(mMessageWidget, &KMessageWidget::linkActivated, this, [](const QString &str) { QDesktopServices::openUrl(QUrl(str)); } ); | 182 | connect(mMessageWidget, &KMessageWidget::linkActivated, this, [](const QString &str) { QDesktopServices::openUrl(QUrl(str)); } ); | ||
176 | 183 | | |||
177 | // layouts | 184 | // layouts | ||
178 | 185 | | |||
179 | mDivider->setFrameShape(QFrame::HLine); | 186 | mDivider->setFrameShape(QFrame::HLine); | ||
180 | mDivider->setLineWidth(2); | 187 | mDivider->setLineWidth(2); | ||
181 | 188 | | |||
Show All 35 Lines | 217 | { | |||
217 | 224 | | |||
218 | int alignedWindowWidth = qMin(mKSWidget->imagePaddingWidth() + imageWidth, MAXIMUM_WINDOW_WIDTH); | 225 | int alignedWindowWidth = qMin(mKSWidget->imagePaddingWidth() + imageWidth, MAXIMUM_WINDOW_WIDTH); | ||
219 | alignedWindowWidth += layout()->contentsMargins().left() + layout()->contentsMargins().right(); | 226 | alignedWindowWidth += layout()->contentsMargins().left() + layout()->contentsMargins().right(); | ||
220 | alignedWindowWidth += 2; // margins is removing 1 - 1 pixel for some reason | 227 | alignedWindowWidth += 2; // margins is removing 1 - 1 pixel for some reason | ||
221 | 228 | | |||
222 | return alignedWindowWidth; | 229 | return alignedWindowWidth; | ||
223 | } | 230 | } | ||
224 | 231 | | |||
225 | void KSMainWindow::buildSaveMenu() | 232 | void KSMainWindow::setDefaultSaveAction() | ||
226 | { | 233 | { | ||
227 | // first clear the menu | | |||
228 | mSaveMenu->clear(); | | |||
229 | | ||||
230 | // get our actions in order | | |||
231 | QAction *actionSave = KStandardAction::save(this, &KSMainWindow::save, this); | | |||
232 | QAction *actionSaveAs = KStandardAction::saveAs(this, &KSMainWindow::saveAs, this); | | |||
233 | mSaveMenu->addAction(actionSaveAs); | | |||
234 | mSaveMenu->addAction(actionSave); | | |||
235 | | ||||
236 | // put the actions in order | | |||
237 | switch (saveButtonMode()) { | 234 | switch (saveButtonMode()) { | ||
238 | case SaveMode::SaveAs: | 235 | case SaveMode::SaveAs: | ||
239 | mSaveButton->setDefaultAction(actionSaveAs); | 236 | mSaveButton->setDefaultAction(mSaveAsAction); | ||
240 | break; | 237 | break; | ||
241 | case SaveMode::Save: | 238 | case SaveMode::Save: | ||
242 | mSaveButton->setDefaultAction(actionSave); | 239 | mSaveButton->setDefaultAction(mSaveAction); | ||
243 | break; | 240 | break; | ||
244 | } | 241 | } | ||
245 | } | 242 | } | ||
246 | 243 | | |||
247 | // overrides | 244 | // overrides | ||
248 | 245 | | |||
249 | void KSMainWindow::moveEvent(QMoveEvent *event) | 246 | void KSMainWindow::moveEvent(QMoveEvent *event) | ||
250 | { | 247 | { | ||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | |||||
336 | { | 333 | { | ||
337 | setWindowTitle(location.fileName()); | 334 | setWindowTitle(location.fileName()); | ||
338 | setWindowModified(false); | 335 | setWindowModified(false); | ||
339 | } | 336 | } | ||
340 | 337 | | |||
341 | void KSMainWindow::save() | 338 | void KSMainWindow::save() | ||
342 | { | 339 | { | ||
343 | SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::Save); | 340 | SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::Save); | ||
344 | buildSaveMenu(); | 341 | setDefaultSaveAction(); | ||
345 | 342 | | |||
346 | if (SpectacleConfig::instance()->quitAfterSaveOrCopyChecked()) { | 343 | if (SpectacleConfig::instance()->quitAfterSaveOrCopyChecked()) { | ||
347 | ExportManager::instance()->doSave(QUrl(), true); | 344 | ExportManager::instance()->doSave(QUrl(), true); | ||
348 | qApp->setQuitOnLastWindowClosed(false); | 345 | qApp->setQuitOnLastWindowClosed(false); | ||
349 | hide(); | 346 | hide(); | ||
350 | } | 347 | } | ||
351 | else { | 348 | else { | ||
352 | ExportManager::instance()->doSave(); | 349 | ExportManager::instance()->doSave(); | ||
353 | } | 350 | } | ||
354 | } | 351 | } | ||
355 | 352 | | |||
356 | void KSMainWindow::saveAs() | 353 | void KSMainWindow::saveAs() | ||
357 | { | 354 | { | ||
358 | SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::SaveAs); | 355 | SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::SaveAs); | ||
359 | buildSaveMenu(); | 356 | setDefaultSaveAction(); | ||
360 | 357 | | |||
361 | if (SpectacleConfig::instance()->quitAfterSaveOrCopyChecked()) { | 358 | if (SpectacleConfig::instance()->quitAfterSaveOrCopyChecked()) { | ||
362 | if (ExportManager::instance()->doSaveAs(this, true)) { | 359 | if (ExportManager::instance()->doSaveAs(this, true)) { | ||
363 | qApp->setQuitOnLastWindowClosed(false); | 360 | qApp->setQuitOnLastWindowClosed(false); | ||
364 | hide(); | 361 | hide(); | ||
365 | } | 362 | } | ||
366 | } | 363 | } | ||
367 | else { | 364 | else { | ||
368 | ExportManager::instance()->doSaveAs(this, false); | 365 | ExportManager::instance()->doSaveAs(this, false); | ||
369 | } | 366 | } | ||
370 | } | 367 | } |
Technically this is an unrelated change, but these line breaks bug me too and I was planning to push a quick formatting fix at some point anyway (including turning all the tabs into spaces), so don't worry about it.