Git commit 6108bd8343c14f58e9d6c9df500066d6b44f4f6a by Martin Koller. Committed on 25/03/2011 at 23:15. Pushed by mkoller into branch 'master'.
Add "screenshot" action to file menu FEATURE: 179658 GUI: M +0 -2 CMakeLists.txt M +2 -5 kolourpaintui.rc M +0 -2 mainWindow/kpMainWindow.cpp M +2 -15 mainWindow/kpMainWindow.h M +1 -1 mainWindow/kpMainWindowPrivate.h M +38 -11 mainWindow/kpMainWindow_File.cpp D +0 -223 mainWindow/kpMainWindow_Help.cpp http://commits.kde.org/kolourpaint/6108bd8343c14f58e9d6c9df500066d6b44f4f6a diff --git a/CMakeLists.txt b/CMakeLists.txt index 39b00cc..4b8cdbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -212,7 +212,6 @@ ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_Colors.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_Edit.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_File.cpp -${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_Help.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_Image.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_Settings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_StatusBar.cpp @@ -434,7 +433,6 @@ ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_Colors.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_Edit.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_File.cpp -${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_Help.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_Image.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_Settings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mainWindow/kpMainWindow_StatusBar.cpp diff --git a/kolourpaintui.rc b/kolourpaintui.rc index e7ed0fc..e8b550b 100644 --- a/kolourpaintui.rc +++ b/kolourpaintui.rc @@ -4,7 +4,7 @@ SYNC: Do not change the number of quotes before the version number - it is parsed by the KolourPaint wrapper shell script (in standalone backport releases of KolourPaint) --> -<gui name="kolourpaint" version="72"> +<gui name="kolourpaint" version="73"> <!-- SYNC: Check for duplicate actions in menus caused by some of our actions @@ -17,6 +17,7 @@ SYNC: Check for duplicate actions in menus caused by some of our actions <!-- <Action name="file_new_window" append="new_merge" /> --> <Action name="file_scan" append="open_merge" /> + <Action name="file_screenshot" append="open_merge" /> <Separator append="open_merge" /> <Action name="file_properties" append="open_merge" /> @@ -115,10 +116,6 @@ SYNC: Check for duplicate actions in menus caused by some of our actions <Action name="settings_show_path" append="show_merge" /> </Menu> - <Menu name="help"> - <Action name="help_taking_screenshots" /> - </Menu> - <!-- HACK: See kpmainwindow.cpp:kpMainWindow::createGUI(). --> <Menu name="toolToolBarHiddenMenu"> <Action name="tool_brush" /> diff --git a/mainWindow/kpMainWindow.cpp b/mainWindow/kpMainWindow.cpp index 1439dec..a159509 100644 --- a/mainWindow/kpMainWindow.cpp +++ b/mainWindow/kpMainWindow.cpp @@ -607,7 +607,6 @@ void kpMainWindow::setupActions () setupImageMenuActions (); setupColorsMenuActions (); setupSettingsMenuActions (); - setupHelpMenuActions (); setupTextToolBarActions (); setupToolActions (); @@ -624,7 +623,6 @@ void kpMainWindow::enableDocumentActions (bool enable) enableImageMenuDocumentActions (enable); enableColorsMenuDocumentActions (enable); enableSettingsMenuDocumentActions (enable); - enableHelpMenuDocumentActions (enable); } //--------------------------------------------------------------------- diff --git a/mainWindow/kpMainWindow.h b/mainWindow/kpMainWindow.h index 586d1a4..b0ad9a9 100644 --- a/mainWindow/kpMainWindow.h +++ b/mainWindow/kpMainWindow.h @@ -346,6 +346,8 @@ private slots: void slotScan (); void slotScanned (const QImage &image, int); + void slotScreenshot(); + void slotProperties (); bool save (bool localOnly = false); @@ -700,23 +702,8 @@ public: void setTextStyle (const kpTextStyle &textStyle_); int settingTextStyle () const; - -// -// Help Menu -// - -private: - void setupHelpMenuActions (); - void enableHelpMenuDocumentActions (bool enable = true); - -private slots: - void slotHelpTakingScreenshots (); - void slotHelpTakingScreenshotsFollowLink (const QString &link); - - private: struct kpMainWindowPrivate *d; }; - #endif // KP_MAIN_WINDOW_H diff --git a/mainWindow/kpMainWindowPrivate.h b/mainWindow/kpMainWindowPrivate.h index 322b12e..a0f5d9d 100644 --- a/mainWindow/kpMainWindowPrivate.h +++ b/mainWindow/kpMainWindowPrivate.h @@ -120,7 +120,7 @@ struct kpMainWindowPrivate QAction *actionNew, *actionOpen; KRecentFilesAction *actionOpenRecent; - KAction *actionScan, *actionProperties, + KAction *actionScan, *actionScreenshot, *actionProperties, *actionSave, *actionSaveAs, *actionExport, *actionReload, *actionPrint, *actionPrintPreview, diff --git a/mainWindow/kpMainWindow_File.cpp b/mainWindow/kpMainWindow_File.cpp index b7de7d8..b2e4417 100644 --- a/mainWindow/kpMainWindow_File.cpp +++ b/mainWindow/kpMainWindow_File.cpp @@ -37,8 +37,9 @@ #include <qpainter.h> #include <qpixmap.h> #include <qsize.h> -#include <QtGui/QPrinter> -#include <QtGui/QPrintDialog> +#include <QPrinter> +#include <QPrintDialog> +#include <QApplication> #include <kapplication.h> #include <kaction.h> @@ -100,9 +101,13 @@ void kpMainWindow::setupFileMenuActions () connect(d->actionExport, SIGNAL(triggered(bool) ), SLOT (slotExport ())); d->actionScan = ac->addAction("file_scan"); - d->actionScan->setText (i18n ("Scan...")); - d->actionScan->setIcon (SmallIcon ("scanner")); - connect(d->actionScan, SIGNAL(triggered(bool) ), SLOT (slotScan ())); + d->actionScan->setText(i18n ("Scan...")); + d->actionScan->setIcon(SmallIcon("scanner")); + connect(d->actionScan, SIGNAL(triggered(bool)), SLOT(slotScan())); + + d->actionScreenshot = ac->addAction("file_screenshot"); + d->actionScreenshot->setText(i18n("Acquire Screenshot")); + connect(d->actionScreenshot, SIGNAL(triggered(bool)), SLOT(slotScreenshot())); d->actionProperties = ac->addAction ("file_properties"); d->actionProperties->setText (i18n ("Properties")); @@ -130,6 +135,8 @@ void kpMainWindow::setupFileMenuActions () enableFileMenuDocumentActions (false); } +//--------------------------------------------------------------------- + // private void kpMainWindow::enableFileMenuDocumentActions (bool enable) { @@ -158,6 +165,8 @@ void kpMainWindow::enableFileMenuDocumentActions (bool enable) // d->actionQuit->setEnabled (enable); } +//--------------------------------------------------------------------- + // private void kpMainWindow::addRecentURL (const KUrl &url_) { @@ -238,6 +247,8 @@ void kpMainWindow::addRecentURL (const KUrl &url_) } } +//--------------------------------------------------------------------- + // private slot // TODO: Disable action if @@ -261,6 +272,8 @@ void kpMainWindow::slotNew () } } +//--------------------------------------------------------------------- + // private QSize kpMainWindow::defaultDocSize () const @@ -288,6 +301,8 @@ QSize kpMainWindow::defaultDocSize () const return docSize; } +//--------------------------------------------------------------------- + // private void kpMainWindow::saveDefaultDocSize (const QSize &size) { @@ -301,6 +316,7 @@ void kpMainWindow::saveDefaultDocSize (const QSize &size) cfg.sync (); } +//--------------------------------------------------------------------- // private bool kpMainWindow::shouldOpen () @@ -323,6 +339,8 @@ bool kpMainWindow::shouldOpen () return true; } +//--------------------------------------------------------------------- + // private void kpMainWindow::setDocumentChoosingWindow (kpDocument *doc) { @@ -330,18 +348,12 @@ void kpMainWindow::setDocumentChoosingWindow (kpDocument *doc) if (d->document && !d->document->isEmpty () && !d->configOpenImagesInSameWindow) { - #if DEBUG_KP_MAIN_WINDOW - kDebug () << "\topen in new window"; - #endif // Send doc to new window. kpMainWindow *win = new kpMainWindow (doc); win->show (); } else { - #if DEBUG_KP_MAIN_WINDOW - kDebug () << "\topen in same window"; - #endif // (sets up views, doc signals) setDocument (doc); } @@ -625,6 +637,21 @@ void kpMainWindow::slotScanned (const QImage &image, int) //--------------------------------------------------------------------- +void kpMainWindow::slotScreenshot() +{ + toolEndShape (); + QPixmap pixmap = QPixmap::grabWindow(QApplication::desktop()->winId()); + + kpDocument *doc = new kpDocument(pixmap.width(), pixmap.height(), + documentEnvironment()); + doc->setImage(pixmap.toImage()); + + // Send document to current or new window. + setDocumentChoosingWindow(doc); +} + +//--------------------------------------------------------------------- + // private slot void kpMainWindow::slotProperties () { diff --git a/mainWindow/kpMainWindow_Help.cpp b/mainWindow/kpMainWindow_Help.cpp deleted file mode 100644 index 8237ca2..0000000 --- a/mainWindow/kpMainWindow_Help.cpp +++ /dev/null @@ -1,223 +0,0 @@ - -/* - Copyright (c) 2003-2007 Clarence Dang <dang at kde.org> - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -#include <kpMainWindow.h> -#include <kpMainWindowPrivate.h> - -#include <QLabel> -#include <QtDBus> - -#include <kaction.h> -#include <kactioncollection.h> - -#include <kconfig.h> -#include <kconfiggroup.h> -#include <kdebug.h> -#include <kdialog.h> -#include <kglobal.h> -#include <klocale.h> -#include <krun.h> -#include <kshortcut.h> - - -// private -void kpMainWindow::setupHelpMenuActions () -{ - KActionCollection *ac = actionCollection (); - - - // Explanation for action name: - // "Taking" is like a digital camera when you record the image and is - // analogous to pressing PrintScreen. However, "Acquiring" is when - // the image is brought into KolourPaint, just as you would acquire - // from a digital camera in future versions of KolourPaint. Hence - // "Acquiring" is more appropriate. - // -- Thurston - d->actionHelpTakingScreenshots = ac->addAction ("help_taking_screenshots"); - d->actionHelpTakingScreenshots->setText (i18n ("Acquiring &Screenshots")); - connect (d->actionHelpTakingScreenshots, SIGNAL (triggered (bool)), - SLOT (slotHelpTakingScreenshots ())); - - - enableHelpMenuDocumentActions (false); -} - -// private -void kpMainWindow::enableHelpMenuDocumentActions (bool /*enable*/) -{ - // d->m_actionHelpTakingScreenshots -} - - -// SYNC: kdebase/kwin/kwinbindings.cpp -static QString printScreenShortcutString () -{ - KConfigGroup cfg (KGlobal::config (), "Global Shortcuts"); - - // TODO: i18n() entry name? kwinbindings.cpp seems to but it doesn't - // make sense. - const QString cfgEntryString = cfg.readEntry ("Desktop Screenshot"); - - - // (only use 1st key sequence, if it exists) - const QString humanReadableShortcut = - KShortcut (cfgEntryString).primary().toString (); - - if (!humanReadableShortcut.isEmpty ()) - { - return humanReadableShortcut; - } - else - { - // (localised) - return KShortcut (Qt::CTRL + Qt::Key_Print).toString (); - } -} - - -// private slot -void kpMainWindow::slotHelpTakingScreenshots () -{ -#if DEBUG_KP_MAIN_WINDOW - kDebug () << "kpMainWindow::slotHelpTakingScreenshots()"; -#endif - - toolEndShape (); - - - // TODO: Totally bogus logic if kwin not running under same user as KolourPaint. - // SYNC: KWin contains PrintScreen key logic -#if DEBUG_KP_MAIN_WINDOW - //kDebug () << "\tdcopApps=" << dcopApps; -#endif - bool isRunningKDE = true; // COMPAT QDBus::sessionBus().busService()->nameHasOwner("kwin"); - -#if 0 -{ - int i = 0; - FILE *fp = fopen ("/home/kdevel/kolourpaint.tmp", "rt"); - if (fp && fscanf (fp, "Hello: %d", &i) == 1) - isRunningKDE = i, fclose (fp); -} -#endif - - QString message; - if (isRunningKDE) - { - message = i18n - ( - "<p>" - "To acquire a screenshot, press <b>%1</b>." - " The screenshot will be placed into the clipboard" - " and you will be able to paste it in KolourPaint." - "</p>" - - "<p>" - "You may configure the <b>Desktop Screenshot</b> shortcut" - " in the KDE System Settings" - " module <a href=\"configure kde shortcuts\">Keyboard Shortcuts</a>." - "</p>" - - "<p>Alternatively, you may try the application" - " <a href=\"run ksnapshot\">KSnapshot</a>." - "</p>", - // TODO: Totally bogus logic if kwin not running under same user as KolourPaint. - ::printScreenShortcutString () - ); - } - else - { - message = i18n - ( - "<p>" - "You do not appear to be running KDE." - "</p>" - - // We tell them this much even though they aren't running KDE - // to entice them to use KDE since it's so easy. - "<p>" - "Once you have loaded KDE:<br>" - "<blockquote>" - "To acquire a screenshot, press <b>%1</b>." - " The screenshot will be placed into the clipboard" - " and you will be able to paste it in KolourPaint." - "</blockquote>" - "</p>" - - "<p>Alternatively, you may try the application" - " <a href=\"run ksnapshot\">KSnapshot</a>." - "</p>", - // TODO: Totally bogus logic if kwin not running under same user as KolourPaint. - ::printScreenShortcutString () - ); - } - - - // Add extra vertical space - message += "<p> </p>"; - - - KDialog dlg (this); - dlg.setCaption (i18n ("Acquiring Screenshots")); - dlg.setButtons (KDialog::Close); - dlg.setDefaultButton (KDialog::Close); - dlg.showButtonSeparator (true); - - QLabel *messageLabel = new QLabel (message, &dlg); - messageLabel->setWordWrap(true); - - connect (messageLabel, SIGNAL (linkActivated (const QString &)), - this, SLOT (slotHelpTakingScreenshotsFollowLink (const QString &))); - - dlg.setMainWidget (messageLabel); - - dlg.exec (); -} - -// private -void kpMainWindow::slotHelpTakingScreenshotsFollowLink (const QString &link) -{ -#if DEBUG_KP_MAIN_WINDOW - kDebug () << "kpMainWindow::slotHelpTakingScreenshotsFollowLink(" - << link << ")" << endl; -#endif - - if (link == "configure kde shortcuts") - { - KRun::runCommand ("kcmshell4 keys", this); - } - else if (link == "run ksnapshot") - { - KRun::runCommand ("ksnapshot", this); - } - else - { - kError () << "kpMainWindow::slotHelpTakingScreenshotsFollowLink(" - << link << ")" << endl; - } -}
