[kde-doc-english] [kolourpaint] mainWindow: make the screenshot configurable (delay seconds, hide window)

Martin Koller kollix at aon.at
Sat Mar 26 22:26:25 CET 2011


Git commit 59cc5c4b7a487e4ef9a302365486e2e99c3455e9 by Martin Koller.
Committed on 26/03/2011 at 22:23.
Pushed by mkoller into branch 'master'.

make the screenshot configurable (delay seconds, hide window)

GUI:

M  +1    -0    mainWindow/kpMainWindow.h     
M  +53   -8    mainWindow/kpMainWindow_File.cpp     

http://commits.kde.org/kolourpaint/59cc5c4b7a487e4ef9a302365486e2e99c3455e9

diff --git a/mainWindow/kpMainWindow.h b/mainWindow/kpMainWindow.h
index b0ad9a9..b45e49c 100644
--- a/mainWindow/kpMainWindow.h
+++ b/mainWindow/kpMainWindow.h
@@ -347,6 +347,7 @@ private slots:
     void slotScanned (const QImage &image, int);
 
     void slotScreenshot();
+    void slotMakeScreenshot();
 
     void slotProperties ();
 
diff --git a/mainWindow/kpMainWindow_File.cpp b/mainWindow/kpMainWindow_File.cpp
index b2e4417..d1516d6 100644
--- a/mainWindow/kpMainWindow_File.cpp
+++ b/mainWindow/kpMainWindow_File.cpp
@@ -40,13 +40,18 @@
 #include <QPrinter>
 #include <QPrintDialog>
 #include <QApplication>
+#include <QTimer>
+#include <QLabel>
+#include <QCheckBox>
+#include <QVBoxLayout>
 
-#include <kapplication.h>
+#include <kdialog.h>
 #include <kaction.h>
 #include <kactioncollection.h>
 #include <kconfig.h>
 #include <kconfiggroup.h>
 #include <kdebug.h>
+#include <KIntSpinBox>
 #include <kfiledialog.h>
 #include <kglobal.h>
 #include <kiconloader.h>
@@ -639,15 +644,55 @@ void kpMainWindow::slotScanned (const QImage &image, int)
 
 void kpMainWindow::slotScreenshot()
 {
-    toolEndShape ();
-    QPixmap pixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
+  toolEndShape();
 
-    kpDocument *doc = new kpDocument(pixmap.width(), pixmap.height(),
-                                     documentEnvironment());
-    doc->setImage(pixmap.toImage());
+  KDialog *dialog = new KDialog(this);
+  dialog->setButtons(KDialog::Ok | KDialog::Cancel);
 
-    // Send document to current or new window.
-    setDocumentChoosingWindow(doc);
+  QLabel *label = new QLabel(i18n("Snapshot Delay"));
+  KIntSpinBox *seconds = new KIntSpinBox;
+  seconds->setRange(0, 99);
+  seconds->setSuffix(ki18np(" second", " seconds"));
+  seconds->setSpecialValueText(i18n("No delay"));
+
+  QCheckBox *hideWindow = new QCheckBox(i18n("Hide Main Window"));
+  hideWindow->setChecked(true);
+
+  QVBoxLayout *vbox = new QVBoxLayout(dialog->mainWidget());
+  vbox->addWidget(label);
+  vbox->addWidget(seconds);
+  vbox->addWidget(hideWindow);
+
+  if ( dialog->exec() == KDialog::Rejected )
+  {
+    delete dialog;
+    return;
+  }
+
+  if ( hideWindow->isChecked() )
+    hide();
+
+  // at least 1 seconds to make sure the window is hidden and the hide effect already stopped
+  QTimer::singleShot((seconds->value() + 1) * 1000, this, SLOT(slotMakeScreenshot()));
+
+  delete dialog;
+}
+
+//---------------------------------------------------------------------
+
+void kpMainWindow::slotMakeScreenshot()
+{
+  QCoreApplication::processEvents();
+  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);
+
+  show();  // in case we hid the mainwindow, show it again
 }
 
 //---------------------------------------------------------------------


More information about the kde-doc-english mailing list