summaryrefslogtreecommitdiffstats
path: root/krita/plugins/viewplugins/screenshot
diff options
context:
space:
mode:
Diffstat (limited to 'krita/plugins/viewplugins/screenshot')
-rw-r--r--krita/plugins/viewplugins/screenshot/Makefile.am26
-rw-r--r--krita/plugins/viewplugins/screenshot/kritascreenshot.desktop47
-rw-r--r--krita/plugins/viewplugins/screenshot/ksnapshot.cpp499
-rw-r--r--krita/plugins/viewplugins/screenshot/ksnapshot.h135
-rw-r--r--krita/plugins/viewplugins/screenshot/ksnapshotwidget.ui335
-rw-r--r--krita/plugins/viewplugins/screenshot/ksnapshotwidget.ui.h118
-rw-r--r--krita/plugins/viewplugins/screenshot/main.cpp38
-rw-r--r--krita/plugins/viewplugins/screenshot/regiongrabber.cpp170
-rw-r--r--krita/plugins/viewplugins/screenshot/regiongrabber.h71
-rw-r--r--krita/plugins/viewplugins/screenshot/screenshot-kpresenter.rc9
-rw-r--r--krita/plugins/viewplugins/screenshot/screenshot-krita.rc9
-rw-r--r--krita/plugins/viewplugins/screenshot/screenshot-kword.rc9
-rw-r--r--krita/plugins/viewplugins/screenshot/screenshot.cpp78
-rw-r--r--krita/plugins/viewplugins/screenshot/screenshot.h42
14 files changed, 1586 insertions, 0 deletions
diff --git a/krita/plugins/viewplugins/screenshot/Makefile.am b/krita/plugins/viewplugins/screenshot/Makefile.am
new file mode 100644
index 00000000..616ebdcd
--- /dev/null
+++ b/krita/plugins/viewplugins/screenshot/Makefile.am
@@ -0,0 +1,26 @@
+kritarcdir = $(kde_datadir)/kritaplugins
+kritarc_DATA = screenshot-krita.rc
+
+EXTRA_DIST = $(kritarc_DATA)
+
+INCLUDES = -I$(srcdir)/../../../sdk \
+ -I$(srcdir)/../../../core \
+ -I$(srcdir)/../../../kritacolor/ \
+ -I$(srcdir)/../../../ui \
+ $(KOFFICE_INCLUDES) \
+ $(all_includes)
+
+kde_module_LTLIBRARIES = kritascreenshot.la
+
+kritascreenshot_la_SOURCES = screenshot.cpp ksnapshot.cpp regiongrabber.cpp ksnapshotwidget.ui
+noinst_HEADERS = screenshot.h ksnapshot.h regiongrabber.h ksnapshotwidget.h ksnapshotwidget.ui.h
+
+kritascreenshot_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+kritascreenshot_la_LIBADD = ../../../libkritacommon.la
+
+kde_services_DATA = kritascreenshot.desktop
+
+kritascreenshot_la_METASOURCES = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/kscreenshot_plugin.pot
diff --git a/krita/plugins/viewplugins/screenshot/kritascreenshot.desktop b/krita/plugins/viewplugins/screenshot/kritascreenshot.desktop
new file mode 100644
index 00000000..2420e527
--- /dev/null
+++ b/krita/plugins/viewplugins/screenshot/kritascreenshot.desktop
@@ -0,0 +1,47 @@
+[Desktop Entry]
+Name=Screenshot
+Name[bg]=Снимка на екрана
+Name[br]=Skrammpaker
+Name[ca]=Captura de pantalla
+Name[cy]=Sgrinlun
+Name[da]=Skærmaftryk
+Name[de]=Bildschirmphoto
+Name[el]=Στιγμιότυπο οθόνης
+Name[eo]=Ekrankopio
+Name[es]=Captura de pantalla
+Name[et]=Ekraanipilt
+Name[fa]=تصویر پرده
+Name[fr]=Capture d'écran
+Name[fy]=Skermôfbylding
+Name[ga]=Seat den Scáileán
+Name[gl]=Captura de Pantalla
+Name[he]=תמונת מסך
+Name[hu]=Képernyőfelvétel
+Name[is]=Skjámynd
+Name[it]=Schermata
+Name[ja]=スクリーンショット
+Name[km]=រូបថត​អេក្រង់
+Name[lv]=Ekrānattēls
+Name[nb]=Skjermbilde
+Name[nds]=Schirmbild
+Name[ne]=स्क्रिनसट
+Name[nl]=Schermafbeelding
+Name[pl]=Zrzut ekranu
+Name[pt]=Captura
+Name[pt_BR]=Captura de Tela
+Name[ru]=Снимок экрана
+Name[se]=Šearbmagovva
+Name[sk]=Snímač obrazovky
+Name[sl]=Posnetek zaslona
+Name[sr]=Снимак екрана
+Name[sr@Latn]=Snimak ekrana
+Name[sv]=Skärmdump
+Name[uk]=Знімок екрана
+Name[uz]=Skrinshot
+Name[uz@cyrillic]=Скриншот
+Name[zh_CN]=抓图
+Name[zh_TW]=螢幕快照
+ServiceTypes=Krita/ViewPlugin
+Type=Service
+X-KDE-Library=kritascreenshot
+X-Krita-Version=2
diff --git a/krita/plugins/viewplugins/screenshot/ksnapshot.cpp b/krita/plugins/viewplugins/screenshot/ksnapshot.cpp
new file mode 100644
index 00000000..77b4da4b
--- /dev/null
+++ b/krita/plugins/viewplugins/screenshot/ksnapshot.cpp
@@ -0,0 +1,499 @@
+/*
+ * KSnapshot
+ *
+ * (c) Richard J. Moore 1997-2002
+ * (c) Matthias Ettrich 2000
+ * (c) Aaron J. Seigo 2002
+ * (c) Nadeem Hasan 2003
+ * This adaptation: (c) Boudewijn Rempt 2005
+ *
+ * Released under the GPL see file LICENSE for details.
+ */
+
+#include <kapplication.h>
+#include <klocale.h>
+#include <kimageio.h>
+#include <kfiledialog.h>
+#include <kimagefilepreview.h>
+#include <kmessagebox.h>
+#include <kdebug.h>
+#include <kprinter.h>
+#include <kio/netaccess.h>
+#include <ksavefile.h>
+#include <ktempfile.h>
+
+#include <qbitmap.h>
+#include <qdragobject.h>
+#include <qimage.h>
+#include <qclipboard.h>
+#include <qvbox.h>
+
+#include <kaccel.h>
+#include <knotifyclient.h>
+#include <khelpmenu.h>
+#include <kpopupmenu.h>
+#include <kpushbutton.h>
+#include <kstartupinfo.h>
+
+#include <qcursor.h>
+#include <qregexp.h>
+#include <qpainter.h>
+#include <qpaintdevicemetrics.h>
+#include <qwhatsthis.h>
+
+#include <stdlib.h>
+
+#include "ksnapshot.h"
+#include "regiongrabber.h"
+#include "ksnapshotwidget.h"
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
+#include <config.h>
+
+#ifdef HAVE_X11_EXTENSIONS_SHAPE_H
+#include <X11/extensions/shape.h>
+#endif
+
+#include <kglobal.h>
+
+KSnapshot::KSnapshot(QWidget *parent, const char *name)
+ : super(parent, name, false, QString::null, Ok|Cancel)
+{
+ grabber = new QWidget( 0, 0, WStyle_Customize | WX11BypassWM );
+ Q_CHECK_PTR(grabber);
+ grabber->move( -1000, -1000 );
+ grabber->installEventFilter( this );
+
+#ifdef HAVE_X11_EXTENSIONS_SHAPE_H
+ int tmp1, tmp2;
+ //Check whether the extension is available
+ haveXShape = XShapeQueryExtension( qt_xdisplay(), &tmp1, &tmp2 );
+#endif
+
+ QVBox *vbox = makeVBoxMainWidget();
+ mainWidget = new KSnapshotWidget( vbox, "mainWidget" );
+ Q_CHECK_PTR(mainWidget);
+
+ mainWidget->btnSave->hide();
+ mainWidget->btnPrint->hide();
+ connect(mainWidget, SIGNAL(startImageDrag()), SLOT(slotDragSnapshot()));
+
+ connect( mainWidget, SIGNAL( newClicked() ), SLOT( slotGrab() ) );
+ connect( mainWidget, SIGNAL( printClicked() ), SLOT( slotPrint() ) );
+
+ grabber->show();
+ grabber->grabMouse( waitCursor );
+
+ snapshot = QPixmap::grabWindow( qt_xrootwin() );
+ updatePreview();
+ grabber->releaseMouse();
+ grabber->hide();
+
+ KConfig *conf=KGlobal::config();
+ conf->setGroup("GENERAL");
+ mainWidget->setDelay(conf->readNumEntry("delay",0));
+ mainWidget->setMode( conf->readNumEntry( "mode", 0 ) );
+ mainWidget->setIncludeDecorations(conf->readBoolEntry("includeDecorations",true));
+
+ connect( &grabTimer, SIGNAL( timeout() ), this, SLOT( grabTimerDone() ) );
+
+ KAccel* accel = new KAccel(this);
+ Q_CHECK_PTR(accel);
+ accel->insert(KStdAccel::Print, this, SLOT(slotPrint()));
+ accel->insert(KStdAccel::New, this, SLOT(slotGrab()));
+
+ accel->insert( "Print2", Qt::Key_P, this, SLOT(slotPrint()));
+ accel->insert( "New2", Qt::Key_N, this, SLOT(slotGrab()));
+ accel->insert( "New3", Qt::Key_Space, this, SLOT(slotGrab()));
+
+ mainWidget->btnNew->setFocus();
+
+}
+
+KSnapshot::~KSnapshot()
+{
+}
+
+bool KSnapshot::save( const QString &filename )
+{
+ return save( KURL::fromPathOrURL( filename ));
+}
+
+bool KSnapshot::save( const KURL& url )
+{
+ QString type( KImageIO::type(url.path()) );
+ if ( type.isNull() )
+ type = "PNG";
+
+ bool ok = false;
+
+ if ( url.isLocalFile() ) {
+ KSaveFile saveFile( url.path() );
+ if ( saveFile.status() == 0 ) {
+ if ( snapshot.save( saveFile.file(), type.latin1() ) )
+ ok = saveFile.close();
+ }
+ }
+ else {
+ KTempFile tmpFile;
+ tmpFile.setAutoDelete( true );
+ if ( tmpFile.status() == 0 ) {
+ if ( snapshot.save( tmpFile.file(), type.latin1() ) ) {
+ if ( tmpFile.close() )
+ ok = KIO::NetAccess::upload( tmpFile.name(), url, this );
+ }
+ }
+ }
+
+ QApplication::restoreOverrideCursor();
+ if ( !ok ) {
+ kdWarning() << "KSnapshot was unable to save the snapshot" << endl;
+
+ QString caption = i18n("Unable to Save Image");
+ QString text = i18n("KSnapshot was unable to save the image to\n%1.")
+ .arg(url.prettyURL());
+ KMessageBox::error(this, text, caption);
+ }
+
+ return ok;
+}
+
+void KSnapshot::slotCopy()
+{
+ QClipboard *cb = QApplication::clipboard();
+ cb->setPixmap( snapshot );
+}
+
+void KSnapshot::slotDragSnapshot()
+{
+ QDragObject *drobj = new QImageDrag(snapshot.convertToImage(), this);
+ Q_CHECK_PTR(drobj);
+ drobj->setPixmap(mainWidget->preview());
+ drobj->dragCopy();
+}
+
+void KSnapshot::slotGrab()
+{
+ hide();
+ if ( mainWidget->mode() == Region )
+ {
+ rgnGrab = new RegionGrabber();
+ Q_CHECK_PTR(rgnGrab);
+ connect( rgnGrab, SIGNAL( regionGrabbed( const QPixmap & ) ),
+ SLOT( slotRegionGrabbed( const QPixmap & ) ) );
+ }
+ else
+ {
+ if ( mainWidget->delay() )
+ grabTimer.start( mainWidget->delay() * 1000, true );
+ else {
+ grabber->show();
+ grabber->grabMouse( crossCursor );
+ }
+ }
+}
+
+void KSnapshot::slotPrint()
+{
+ KPrinter printer;
+ if (snapshot.width() > snapshot.height())
+ printer.setOrientation(KPrinter::Landscape);
+ else
+ printer.setOrientation(KPrinter::Portrait);
+
+ qApp->processEvents();
+
+ if (printer.setup(this, i18n("Print Screenshot")))
+ {
+ qApp->processEvents();
+
+ QPainter painter(&printer);
+ QPaintDeviceMetrics metrics(painter.device());
+
+ float w = snapshot.width();
+ float dw = w - metrics.width();
+ float h = snapshot.height();
+ float dh = h - metrics.height();
+ bool scale = false;
+
+ if ( (dw > 0.0) || (dh > 0.0) )
+ scale = true;
+
+ if ( scale ) {
+
+ QImage img = snapshot.convertToImage();
+ qApp->processEvents();
+
+ float newh, neww;
+ if ( dw > dh ) {
+ neww = w-dw;
+ newh = neww/w*h;
+ }
+ else {
+ newh = h-dh;
+ neww = newh/h*w;
+ }
+
+ img = img.smoothScale( int(neww), int(newh), QImage::ScaleMin );
+ qApp->processEvents();
+
+ int x = (metrics.width()-img.width())/2;
+ int y = (metrics.height()-img.height())/2;
+
+ painter.drawImage( x, y, img);
+ }
+ else {
+ int x = (metrics.width()-snapshot.width())/2;
+ int y = (metrics.height()-snapshot.height())/2;
+ painter.drawPixmap( x, y, snapshot );
+ }
+ }
+
+ qApp->processEvents();
+}
+
+void KSnapshot::slotRegionGrabbed( const QPixmap &pix )
+{
+ if ( !pix.isNull() )
+ {
+ snapshot = pix;
+ updatePreview();
+ modified = true;
+ }
+
+ delete rgnGrab;
+ QApplication::restoreOverrideCursor();
+ show();
+}
+
+bool KSnapshot::eventFilter( QObject* o, QEvent* e)
+{
+ if ( o == grabber && e->type() == QEvent::MouseButtonPress ) {
+ QMouseEvent* me = (QMouseEvent*) e;
+ if ( QWidget::mouseGrabber() != grabber )
+ return false;
+ if ( me->button() == LeftButton )
+ performGrab();
+ }
+ return false;
+}
+
+void KSnapshot::updatePreview()
+{
+ QImage img = snapshot.convertToImage();
+ double r1 = ((double) snapshot.height() ) / snapshot.width();
+ if ( r1 * mainWidget->previewWidth() < mainWidget->previewHeight() )
+ img = img.smoothScale( mainWidget->previewWidth(),
+ int( mainWidget->previewWidth() * r1 ));
+ else
+ img = img.smoothScale( (int) (((double)mainWidget->previewHeight()) / r1),
+ (mainWidget->previewHeight() ) );
+
+ QPixmap pm;
+ pm.convertFromImage( img );
+ mainWidget->setPreview( pm );
+}
+
+void KSnapshot::grabTimerDone()
+{
+ performGrab();
+ KNotifyClient::beep(i18n("The screen has been successfully grabbed."));
+}
+
+static
+Window findRealWindow( Window w, int depth = 0 )
+{
+ if( depth > 5 )
+ return None;
+ static Atom wm_state = XInternAtom( qt_xdisplay(), "WM_STATE", False );
+ Atom type;
+ int format;
+ unsigned long nitems, after;
+ unsigned char* prop;
+ if( XGetWindowProperty( qt_xdisplay(), w, wm_state, 0, 0, False, AnyPropertyType,
+ &type, &format, &nitems, &after, &prop ) == Success ) {
+ if( prop != NULL )
+ XFree( prop );
+ if( type != None )
+ return w;
+ }
+ Window root, parent;
+ Window* children;
+ unsigned int nchildren;
+ Window ret = None;
+ if( XQueryTree( qt_xdisplay(), w, &root, &parent, &children, &nchildren ) != 0 ) {
+ for( unsigned int i = 0;
+ i < nchildren && ret == None;
+ ++i )
+ ret = findRealWindow( children[ i ], depth + 1 );
+ if( children != NULL )
+ XFree( children );
+ }
+ return ret;
+}
+
+void KSnapshot::performGrab()
+{
+ grabber->releaseMouse();
+ grabber->hide();
+ grabTimer.stop();
+ XGrabServer( qt_xdisplay());
+ if ( mainWidget->mode() == WindowUnderCursor ) {
+ Window root;
+ Window child;
+ uint mask;
+ int rootX, rootY, winX, winY;
+ XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child,
+ &rootX, &rootY, &winX, &winY,
+ &mask);
+ if( child == None )
+ child = qt_xrootwin();
+ if( !mainWidget->includeDecorations()) {
+ Window real_child = findRealWindow( child );
+ if( real_child != None ) // test just in case
+ child = real_child;
+ }
+ int x, y;
+ unsigned int w, h;
+ unsigned int border;
+ unsigned int depth;
+ XGetGeometry( qt_xdisplay(), child, &root, &x, &y,
+ &w, &h, &border, &depth );
+ w += 2 * border;
+ h += 2 * border;
+
+ Window parent;
+ Window* children;
+ unsigned int nchildren;
+ if( XQueryTree( qt_xdisplay(), child, &root, &parent,
+ &children, &nchildren ) != 0 ) {
+ if( children != NULL )
+ XFree( children );
+ int newx, newy;
+ Window dummy;
+ if( XTranslateCoordinates( qt_xdisplay(), parent, qt_xrootwin(),
+ x, y, &newx, &newy, &dummy )) {
+ x = newx;
+ y = newy;
+ }
+ }
+
+ snapshot = QPixmap::grabWindow( qt_xrootwin(), x, y, w, h );
+
+#ifdef HAVE_X11_EXTENSIONS_SHAPE_H
+ //No XShape - no work.
+ if (haveXShape) {
+ QBitmap mask(w, h);
+ //As the first step, get the mask from XShape.
+ int count, order;
+ XRectangle* rects = XShapeGetRectangles( qt_xdisplay(), child,
+ ShapeBounding, &count, &order);
+ //The ShapeBounding region is the outermost shape of the window;
+ //ShapeBounding - ShapeClipping is defined to be the border.
+ //Since the border area is part of the window, we use bounding
+ // to limit our work region
+ if (rects) {
+ //Create a QRegion from the rectangles describing the bounding mask.
+ QRegion contents;
+ for (int pos = 0; pos < count; pos++)
+ contents += QRegion(rects[pos].x, rects[pos].y,
+ rects[pos].width, rects[pos].height);
+ XFree(rects);
+
+ //Create the bounding box.
+ QRegion bbox(0, 0, snapshot.width(), snapshot.height());
+
+ if( border > 0 ) {
+ contents.translate( border, border );
+ contents += QRegion( 0, 0, border, h );
+ contents += QRegion( 0, 0, w, border );
+ contents += QRegion( 0, h - border, w, border );
+ contents += QRegion( w - border, 0, border, h );
+ }
+
+ //Get the masked away area.
+ QRegion maskedAway = bbox - contents;
+ QMemArray<QRect> maskedAwayRects = maskedAway.rects();
+
+ //Construct a bitmap mask from the rectangles
+ QPainter p(&mask);
+ p.fillRect(0, 0, w, h, Qt::color1);
+ for (uint pos = 0; pos < maskedAwayRects.count(); pos++)
+ p.fillRect(maskedAwayRects[pos], Qt::color0);
+ p.end();
+
+ snapshot.setMask(mask);
+ }
+ }
+#endif
+ }
+ else {
+ snapshot = QPixmap::grabWindow( qt_xrootwin() );
+ }
+ XUngrabServer( qt_xdisplay());
+ updatePreview();
+ QApplication::restoreOverrideCursor();
+ modified = true;
+// show();
+ slotOk();
+}
+
+void KSnapshot::setTime(int newTime)
+{
+ mainWidget->setDelay(newTime);
+}
+
+void KSnapshot::setURL( const QString &url )
+{
+ KURL newURL = KURL::fromPathOrURL( url );
+ if ( newURL == filename )
+ return;
+
+ filename = newURL;
+}
+
+void KSnapshot::setGrabMode( int m )
+{
+ mainWidget->setMode( m );
+}
+
+void KSnapshot::slotMovePointer(int x, int y)
+{
+ QCursor::setPos( x, y );
+}
+
+void KSnapshot::exit()
+{
+
+ KConfig *conf=KGlobal::config();
+ conf->setGroup("GENERAL");
+ conf->writeEntry("delay",mainWidget->delay());
+ conf->writeEntry("mode",mainWidget->mode());
+ conf->writeEntry("includeDecorations",mainWidget->includeDecorations());
+ KURL url = filename;
+ url.setPass( QString::null );
+ conf->writePathEntry("filename",url.url());
+
+ reject();
+}
+
+void KSnapshot::slotOk()
+{
+
+ KConfig *conf=KGlobal::config();
+ conf->setGroup("GENERAL");
+ conf->writeEntry("delay",mainWidget->delay());
+ conf->writeEntry("mode",mainWidget->mode());
+ conf->writeEntry("includeDecorations",mainWidget->includeDecorations());
+ KURL url = filename;
+ url.setPass( QString::null );
+ conf->writePathEntry("filename",url.url());
+
+ emit screenGrabbed();
+
+ accept();
+}
+
+#include "ksnapshot.moc"
diff --git a/krita/plugins/viewplugins/screenshot/ksnapshot.h b/krita/plugins/viewplugins/screenshot/ksnapshot.h
new file mode 100644
index 00000000..7eeccb62
--- /dev/null
+++ b/krita/plugins/viewplugins/screenshot/ksnapshot.h
@@ -0,0 +1,135 @@
+// -*- c++ -*-
+/*
+ * (c) Richard J. Moore 1997-2002
+ * (c) Matthias Ettrich 2000
+ * (c) Aaron J. Seigo 2002
+ * (c) Nadeem Hasan 2003
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef KSNAPSHOT_H
+#define KSNAPSHOT_H
+
+#include <qlabel.h>
+#include <qpixmap.h>
+#include <qtimer.h>
+
+#include <dcopclient.h>
+#include <kglobalsettings.h>
+#include <kdialogbase.h>
+#include <kurl.h>
+
+class RegionGrabber;
+class KSnapshotWidget;
+
+class KSnapshotThumb : public QLabel
+{
+ Q_OBJECT
+
+public:
+ KSnapshotThumb(QWidget *parent, const char *name = 0)
+ : QLabel(parent, name)
+ {
+ setAlignment(AlignHCenter | AlignVCenter);
+ }
+ virtual ~KSnapshotThumb() {}
+
+signals:
+ void startDrag();
+
+protected:
+ void mousePressEvent(QMouseEvent * e)
+ {
+ mClickPt = e->pos();
+ }
+
+ void mouseMoveEvent(QMouseEvent * e)
+ {
+ if (mClickPt != QPoint(0, 0) &&
+ (e->pos() - mClickPt).manhattanLength() > KGlobalSettings::dndEventDelay())
+ {
+ mClickPt = QPoint(0, 0);
+ emit startDrag();
+ }
+ }
+
+ void mouseReleaseEvent(QMouseEvent * /*e*/)
+ {
+ mClickPt = QPoint(0, 0);
+ }
+
+ QPoint mClickPt;
+};
+
+class KSnapshot : public KDialogBase
+{
+ typedef KDialogBase super;
+ Q_OBJECT
+
+public:
+ KSnapshot(QWidget *parent= 0, const char *name= 0);
+ ~KSnapshot();
+
+ enum CaptureMode { FullScreen=0, WindowUnderCursor=1, Region=2 };
+
+ bool save( const QString &filename );
+ bool save( const KURL& url );
+
+ QString url() const { return filename.url(); }
+
+signals:
+ void screenGrabbed();
+
+protected slots:
+ void slotGrab();
+ void slotCopy();
+ void slotPrint();
+ void slotMovePointer( int x, int y );
+
+ void setTime(int newTime);
+ void setURL(const QString &newURL);
+ void setGrabMode( int m );
+ void exit();
+
+ void slotOk();
+
+
+protected:
+ void reject() { close(); }
+ bool eventFilter( QObject*, QEvent* );
+
+private slots:
+ void grabTimerDone();
+ void slotDragSnapshot();
+ void slotRegionGrabbed( const QPixmap & );
+
+private:
+ void updatePreview();
+ void performGrab();
+ void autoincFilename();
+
+ QPixmap snapshot;
+ QTimer grabTimer;
+ QWidget* grabber;
+ KURL filename;
+ KSnapshotWidget *mainWidget;
+ RegionGrabber *rgnGrab;
+ bool modified;
+ bool haveXShape;
+};
+
+#endif // KSNAPSHOT_H
+
diff --git a/krita/plugins/viewplugins/screenshot/ksnapshotwidget.ui b/krita/plugins/viewplugins/screenshot/ksnapshotwidget.ui
new file mode 100644
index 00000000..bd24e6ef
--- /dev/null
+++ b/krita/plugins/viewplugins/screenshot/ksnapshotwidget.ui
@@ -0,0 +1,335 @@
+<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
+<class>KSnapshotWidget</class>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>KSnapshotWidget</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>358</width>
+ <height>241</height>
+ </rect>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <widget class="KSnapshotThumb" row="0" column="0" rowspan="4" colspan="3">
+ <property name="name">
+ <cstring>lblImage</cstring>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>200</width>
+ <height>130</height>
+ </size>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>Thumbnail of the current snapshot</string>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>This is a thumbnail of the current snapshot.
+
+The image can be dragged to another application or document to copy the full screenshot there. Try it with the Konqueror file manager.</string>
+ </property>
+ </widget>
+ <widget class="KPushButton" row="0" column="3">
+ <property name="name">
+ <cstring>btnNew</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;New Snapshot</string>
+ </property>
+ <property name="iconSet">
+ <iconset>"tool_screenshot"</iconset>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>Click this button to take a new snapshot.</string>
+ </property>
+ </widget>
+ <widget class="KPushButton" row="2" column="3">
+ <property name="name">
+ <cstring>btnSave</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Save As...</string>
+ </property>
+ <property name="iconSet">
+ <iconset>"filesave"</iconset>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>Click this button to save the current snapshot. To quickly save the snapshot without showing the file dialog, press Ctrl+Shift+S. The filename is automatically incremented after each save.</string>
+ </property>
+ </widget>
+ <spacer row="1" column="3">
+ <property name="name">
+ <cstring>Spacer6</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>16</width>
+ <height>16</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="KPushButton" row="3" column="3">
+ <property name="name">
+ <cstring>btnPrint</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Print...</string>
+ </property>
+ <property name="iconSet">
+ <iconset>"fileprint"</iconset>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>Click this button to print the current screenshot.</string>
+ </property>
+ </widget>
+ <widget class="Line" row="4" column="0" rowspan="1" colspan="4">
+ <property name="name">
+ <cstring>line1</cstring>
+ </property>
+ <property name="frameShape">
+ <enum>HLine</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>Sunken</enum>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ </widget>
+ <widget class="QSpinBox" row="6" column="1">
+ <property name="name">
+ <cstring>spinDelay</cstring>
+ </property>
+ <property name="suffix">
+ <string> sec</string>
+ </property>
+ <property name="specialValueText">
+ <string>No delay</string>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>Snapshot delay in seconds</string>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>&lt;qt&gt;
+This is the number of seconds to wait after clicking the &lt;i&gt;New Snapshot&lt;/i&gt; button before taking the snapshot.
+&lt;p&gt;
+This is very useful for getting windows, menus and other items on the screen set up just the way you want.
+&lt;p&gt;
+If &lt;i&gt;no delay&lt;/i&gt; is set, the program will wait for a mouse click before taking a snapshot.
+&lt;/p&gt;
+&lt;/qt&gt;</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="6" column="0">
+ <property name="name">
+ <cstring>lblDelay</cstring>
+ </property>
+ <property name="text">
+ <string>Snapshot &amp;delay:</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>spinDelay</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" row="5" column="0">
+ <property name="name">
+ <cstring>textLabel1</cstring>
+ </property>
+ <property name="text">
+ <string>Cap&amp;ture mode:</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>comboMode</cstring>
+ </property>
+ </widget>
+ <spacer row="6" column="2" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>Spacer1</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>156</width>
+ <height>16</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="QCheckBox" row="7" column="0" rowspan="1" colspan="4">
+ <property name="name">
+ <cstring>cbIncludeDecorations</cstring>
+ </property>
+ <property name="text">
+ <string>Include &amp;window decorations</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>When enabled, snapshot of a window will also include the window decorations</string>
+ </property>
+ </widget>
+ <widget class="QComboBox" row="5" column="1" rowspan="1" colspan="3">
+ <item>
+ <property name="text">
+ <string>Full Screen</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Window Under Cursor</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Region</string>
+ </property>
+ </item>
+ <property name="name">
+ <cstring>comboMode</cstring>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>&lt;qt&gt;Using this menu, you can select from the three following snapshot modes:
+&lt;p&gt;
+&lt;b&gt;Full Screen&lt;/b&gt; - captures the entire desktop.&lt;br&gt;
+&lt;b&gt;Window Under Cursor&lt;/b&gt; - captures only the window (or menu) that is under the mouse cursor when the snapshot is taken.&lt;br&gt;
+&lt;b&gt;Region&lt;/b&gt; - captures only the region of the desktop that you specify. When taking a new snapshot in this mode you will be able to select any area of the screen by clicking and dragging the mouse.&lt;/p&gt;&lt;/qt&gt;</string>
+ </property>
+ </widget>
+ <spacer row="8" column="1">
+ <property name="name">
+ <cstring>spacer3</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>20</width>
+ <height>31</height>
+ </size>
+ </property>
+ </spacer>
+ </grid>
+</widget>
+<customwidgets>
+ <customwidget>
+ <class>KSnapshotThumb</class>
+ <header location="local">ksnapshot.h</header>
+ <sizehint>
+ <width>-1</width>
+ <height>-1</height>
+ </sizehint>
+ <container>0</container>
+ <sizepolicy>
+ <hordata>5</hordata>
+ <verdata>5</verdata>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ <pixmap>image0</pixmap>
+ <signal>startDrag()</signal>
+ </customwidget>
+</customwidgets>
+<images>
+ <image name="image0">
+ <data format="XPM.GZ" length="5230">789c9597db4e1d4b0e86eff31428be8b46b5fb54dd551acd051020211c4320c0682eecaa5e9ccf90005bf3ee53cbbfe9d9c9c548a38ea27c2977b5cbfe6dd7fae3c3c2e1cee6c2873fde3d3cf2e3595a48a77cbff0213f5d5dbdfcf35ffff8f3ddfba65998fff161a179ffb777ef771f17d2c2d6cdf53807c705a889cdac6ee72c47736eebd637b5f2b672d70ecd30e744ca7d9b9a4ad7579587363433e527e5d072abefbb03636978ceb4a31c5bc13a91716ad41f89e0aec2fe74abcc6d6ad5f9e4945357375ef75f997357751dd61d19c71afb61bdef421b951f274ebaffb6716cb3f2b2f230f18d3183dd95b1b441d7d59f2e94757ccf1b27eceff69563618d0f5dcfd9d7beeb7a5dd7f3fac6fb4ee32b87c619f1168d976f7d6ff6df26d6ef4b301e1bac7f54f63e747a5e87f5c173276aff605c22a8fefc540e5e3af5972f956359577bf2c6d978cb78d6697edc9eb2f8b143fed7945359d778b0e6c3e7be81bf7465dce23cf4ac3c16567f19fecefaae53bd081b7baccbb131b7d05f679ca03f27c6b9d1f388c6bbaffab7f80dca4d1fed7bfafdbeedb9533d490f1e2ae8d5693ccacb83d77cd027e3d4416faa97beefa3d7f8f086f168f9d9020f43a3f5c5aa877e28eb88f74fe319becfaa873e0c15de775f95639f3dec37c143d361bf2be3cef4b76bdcb7d84ff5d2cbd0227facf1ecd360fa67d54b9f078ffcd10f636e11ff53e3847853ad3c1b668837e9fe43358c2df45a81430b3db2e6676842d368fd48abdc068b87e0fd2e788bf792b21f861e7afd0e0e5ce37dcdd7d0872218e5d789f57b3218a71ae7bb501eca3af67b510e21c05fd27a1b6218ac3ef17d0ed68fe8cb1be3fc6e5159863ca0bfed824340fe687d62c4838c23f677f0370de380fcdd2be7e03dfab1d6cf300bcd80fa80bfb358dbf9547fa18abe413d68fe421d63ade7737aded094cf63fdcc38f4d0bfee17dac2d08380a3a0dff24cb90bdc23ffaa87e0636c912fed87612e38d4df1e982bc4dbdd29872001f14aca319413eb793e83cbfbe8af27606e4c0f5f8d3bcb7763ec6b8da73b57e69083d61f9d82b9b5fada31f635fcaf8d7b7b5ffb41f16e34ff34fe214dfc0c8e1ef1a22330bfcdc345e31e4c33e3c1e6e181b1609e3ac43f8759803e8cd9f2e7e0ff18ab80ef5d8239e2fc0ef129f90ff0bf0773347fee8d13ce279bc6b34af5c61abf58157bf4b765b05435f4abfec726968c2b67e536fa80fe388279067f680d2c750dff75fe9766da07e44bc02521ba4e1d584c1fb261dcc23fd97f63f8c3af136bfc687362c4e76962ed8fac7a2ecdb7853f7c63ec6bf467bd3fc421c680780c60b6f9275fc045aea84fadaf18a2e0fc04ff0237bd9e8fefc0d236e8ef3f8d83c57fdd38daf94edeb886be74fec618b3ed7f3731e66b0fe67a403e76c0454ef8de9231dbfe9f8dc5fc47be38a6887ad2f950964d2fdc1a27d3c7b6710693f6ef9864b4fdb4ffc6cc5540fea0972c339c87afc1c9f4443a5fe2c84d40bd2f82cb3ae6c7b1716dbc37b1e68bf5be118b7e3dead78125d87d0bfa99bd7d8fb78c1bdb4fcfcfd51bcb9d716bebda3fb8966cf7cf57709103f2e327c6fe5a2fdc4ab4fb01deef5283fa65d50ffb54c13fd67ec37d61e845fb070f8571df7c341eec7e7a691c6ae453fb771937d1fa999ebfa43358bf573d3327c6fdd0a9de59b87414e59f60911ef3ff07380d16bf0b63b6fbb8ce0f4e523a80ee8ff8a5f21fe83f384f2e8cf9d419db7d4bb4bff32cb1dd871ae38c79417962dd9f8f2786bfaa3fa992ddbf68d5d8d6797d62dc27b4bf4a9bdeee5be7c619efbb169c2b9bb7aa67e972857a67d59bf8943cf4a6f5237dae3b9c3f4f8cef5713637e6a3c6548e546a7eb87e0b28e7cf7c68ddd2fb15f28acf166bd2f484c19f921f8cbc57de84ff52c397b8f7e178d7bbb7f7e9f18f743d593ccd210d12f9e8c05fd8417c1e5e704e2afefa7aa5cf850ff4fc6a1473debfc4d7561c4ebd3c48897f69fd4e4d8eb7e4efb736a0b23fe9adfd465bb3f388d6ff22933fa1df6f7597ad483c62371f6e6ff8671b6f89e198fb8cfb0ea3f49619c6f6562cc27d5474a7906e6b589d1df549f29e78479450fe0b1c2fc67d5731a0ba33ffc97a167fd7d92ebb1b1f9a87acdcdd8a23ff2e3c4a81fed0fb91bbb88f8e9f772f9b9c6b8bfac187bd41febbcc8c35831f4bb6edc227eeec8b847bc58ef0f398d91a1179d6f391746bdebfd60ac4716b0180bd8a97e473f8ea2dfdb7d9c3f8e1cff8f8760057b27e57f92cb6e743377e24efff29cb97377e12edd55b190c99eddb5bb71b7eeceddbb07f7e89edc0ff7d33dbb17f7ea16dd925b761fdd8a63d8174f52b15e756bee93fbecd6dd17b7e136dd96db763b6ed77d2dd67bee9bdb77078ed49e8b27b7c5fabb3b7447eed855ae768d6bcbd339ef7a37b8e022392a2734fbd1dd119350a24c23cde8844ee98ccee9c2f9c2977445d77443b793fd8ceee89e1ee8919ee807fdb4e7995ee8b5d82fd252b15ffe8bfd097da4155aa535fa34597fa6f5f2f717da28f69bb445dbb433d99fd22e7da53dfa3659efd3017da7c3f2af233aa68aeadfec1b6aa9236fd63d0d14ca15c0719913737b965fedcbf0c83cc29a677cc2a77cc6e77cc1977cc5d7c5fee637fbdbb2db9d5adff343b17ee427fec1737ee69762fffa9bfd222ff17259fdc82bbcca6bfc893ff33a7fe10ddee42ddee69ddfec77f92beff137dee703fece877cc4c7aee58a6b6ee8b8fc10ed7eb13f635f9a4bc5e54719477152ba671977a505c84845c57222a7bfd89fcb999ccb855cca955cbfc5546ee456ee68b14cf67b799047799aec2fdc92fc28999cef567224cff222afb2c85b32e36d599265f9282bb23ad95fba6559934f2593f3e798b74acc8fd5f6b3accb17d9904dd9926db3a7520d1fdd37d9915df95a72599e1291566df7e49beccb817c974339829eb55e56dc7e51ec0d2dcbb1545297a791563af1c5eff2d3beb4faf8562f568f0744745b9e9d5f1f7992d5e412a186ffef7afff7dfdffd077c99ae99</data>
+ </image>
+</images>
+<connections>
+ <connection>
+ <sender>comboMode</sender>
+ <signal>activated(int)</signal>
+ <receiver>KSnapshotWidget</receiver>
+ <slot>slotModeChanged(int)</slot>
+ </connection>
+ <connection>
+ <sender>btnNew</sender>
+ <signal>clicked()</signal>
+ <receiver>KSnapshotWidget</receiver>
+ <slot>slotNewClicked()</slot>
+ </connection>
+ <connection>
+ <sender>btnPrint</sender>
+ <signal>clicked()</signal>
+ <receiver>KSnapshotWidget</receiver>
+ <slot>slotPrintClicked()</slot>
+ </connection>
+ <connection>
+ <sender>btnSave</sender>
+ <signal>clicked()</signal>
+ <receiver>KSnapshotWidget</receiver>
+ <slot>slotSaveClicked()</slot>
+ </connection>
+ <connection>
+ <sender>lblImage</sender>
+ <signal>startDrag()</signal>
+ <receiver>KSnapshotWidget</receiver>
+ <slot>slotStartDrag()</slot>
+ </connection>
+</connections>
+<tabstops>
+ <tabstop>btnNew</tabstop>
+ <tabstop>btnSave</tabstop>
+ <tabstop>btnPrint</tabstop>
+ <tabstop>comboMode</tabstop>
+ <tabstop>spinDelay</tabstop>
+ <tabstop>cbIncludeDecorations</tabstop>
+</tabstops>
+<includes>
+ <include location="global" impldecl="in implementation">kdialog.h</include>
+ <include location="global" impldecl="in implementation">kiconloader.h</include>
+ <include location="global" impldecl="in implementation">kglobalsettings.h</include>
+ <include location="local" impldecl="in implementation">ksnapshotwidget.ui.h</include>
+</includes>
+<signals>
+ <signal>newClicked()</signal>
+ <signal>saveClicked()</signal>
+ <signal>printClicked()</signal>
+ <signal>startImageDrag()</signal>
+</signals>
+<slots>
+ <slot access="protected" specifier="non virtual">slotModeChanged( int mode )</slot>
+ <slot access="protected" specifier="non virtual">slotNewClicked()</slot>
+ <slot access="protected" specifier="non virtual">slotSaveClicked()</slot>
+ <slot access="protected" specifier="non virtual">slotPrintClicked()</slot>
+ <slot access="protected" specifier="non virtual">slotStartDrag()</slot>
+ <slot specifier="non virtual" returnType="int">previewWidth()</slot>
+ <slot specifier="non virtual" returnType="int">previewHeight()</slot>
+</slots>
+<functions>
+ <function specifier="non virtual">setPreview( const QPixmap &amp; pm )</function>
+ <function specifier="non virtual">setDelay( int i )</function>
+ <function specifier="non virtual">setIncludeDecorations( bool b )</function>
+ <function specifier="non virtual">setMode( int mode )</function>
+ <function specifier="non virtual" returnType="int">delay()</function>
+ <function specifier="non virtual" returnType="bool">includeDecorations()</function>
+ <function specifier="non virtual" returnType="int">mode()</function>
+ <function specifier="non virtual" returnType="QPixmap">preview()</function>
+</functions>
+<pixmapfunction>SmallIconSet</pixmapfunction>
+<layoutdefaults spacing="6" margin="11"/>
+<layoutfunctions spacing="KDialog::spacingHint" margin="KDialog::marginHint"/>
+</UI>
diff --git a/krita/plugins/viewplugins/screenshot/ksnapshotwidget.ui.h b/krita/plugins/viewplugins/screenshot/ksnapshotwidget.ui.h
new file mode 100644
index 00000000..e61b0c6e
--- /dev/null
+++ b/krita/plugins/viewplugins/screenshot/ksnapshotwidget.ui.h
@@ -0,0 +1,118 @@
+/****************************************************************************
+** ui.h extension file, included from the uic-generated form implementation.
+**
+** If you wish to add, delete or rename functions or slots use
+** Qt Designer which will update this file, preserving your code. Create an
+** init() function in place of a constructor, and a destroy() function in
+** place of a destructor.
+*****************************************************************************/
+
+
+void KSnapshotWidget::slotModeChanged( int mode )
+{
+ switch ( mode )
+ {
+ case 0:
+ lblDelay->setEnabled(true);
+ spinDelay->setEnabled(true);
+ cbIncludeDecorations->setEnabled(false);
+ break;
+ case 1:
+ lblDelay->setEnabled(true);
+ spinDelay->setEnabled(true);
+ cbIncludeDecorations->setEnabled(true);
+ break;
+ case 2:
+ lblDelay->setEnabled(false);
+ spinDelay->setEnabled(false);
+ cbIncludeDecorations->setEnabled(false);
+ default:
+ break;
+ }
+}
+
+
+void KSnapshotWidget::setPreview( const QPixmap &pm )
+{
+ lblImage->setPixmap(pm);
+}
+
+
+void KSnapshotWidget::setDelay( int i )
+{
+ spinDelay->setValue(i);
+}
+
+
+void KSnapshotWidget::setIncludeDecorations( bool b )
+{
+ cbIncludeDecorations->setChecked(b);
+}
+
+
+void KSnapshotWidget::setMode( int mode )
+{
+ comboMode->setCurrentItem(mode);
+ slotModeChanged(mode);
+}
+
+
+int KSnapshotWidget::delay()
+{
+ return spinDelay->value();
+}
+
+
+bool KSnapshotWidget::includeDecorations()
+{
+ return cbIncludeDecorations->isChecked();
+}
+
+
+int KSnapshotWidget::mode()
+{
+ return comboMode->currentItem();
+}
+
+
+void KSnapshotWidget::slotNewClicked()
+{
+ emit newClicked();
+}
+
+
+void KSnapshotWidget::slotSaveClicked()
+{
+ emit saveClicked();
+}
+
+
+void KSnapshotWidget::slotPrintClicked()
+{
+ emit printClicked();
+}
+
+
+void KSnapshotWidget::slotStartDrag()
+{
+ emit startImageDrag();
+}
+
+
+QPixmap KSnapshotWidget::preview()
+{
+ return *lblImage->pixmap();
+}
+
+
+int KSnapshotWidget::previewWidth()
+{
+ return lblImage->width();
+}
+
+
+int KSnapshotWidget::previewHeight()
+{
+ return lblImage->height();
+}
+
diff --git a/krita/plugins/viewplugins/screenshot/main.cpp b/krita/plugins/viewplugins/screenshot/main.cpp
new file mode 100644
index 00000000..70f61349
--- /dev/null
+++ b/krita/plugins/viewplugins/screenshot/main.cpp
@@ -0,0 +1,38 @@
+#include <kapplication.h>
+#include "ksnapshot.h"
+#include <kimageio.h>
+#include <klocale.h>
+#include <kcmdlineargs.h>
+#include <kaboutdata.h>
+#include <kiconloader.h>
+
+static const char description[] =
+ I18N_NOOP("KDE Screenshot Utility");
+
+int main(int argc, char **argv)
+{
+ KAboutData aboutData( "ksnapshot", I18N_NOOP("KSnapshot"),
+ KSNAPVERSION, description, KAboutData::License_GPL,
+ "(c) 1997-2003, Richard J. Moore,\n(c) 2000, Matthias Ettrich,\n(c) 2002-2003 Aaron J. Seigo");
+ aboutData.addAuthor("Richard J. Moore",0, "rich@kde.org");
+ aboutData.addAuthor("Matthias Ettrich",0, "ettrich@kde.org");
+ aboutData.addAuthor("Aaron J. Seigo", 0, "aseigo@kde.org");
+ aboutData.addCredit( "Nadeem Hasan", "Region Grabbing\nReworked GUI",
+ "nhasan@kde.org" );
+ KCmdLineArgs::init( argc, argv, &aboutData );
+
+ KApplication app;
+
+ KImageIO::registerFormats();
+
+ // Create top level window
+ KSnapshot *toplevel= new KSnapshot();
+ Q_CHECK_PTR(toplevel);
+ app.dcopClient()->setDefaultObject( toplevel->objId() );
+ toplevel->setCaption( app.makeStdCaption("") );
+ toplevel->setIcon(SmallIcon("tool_screenshot"));
+ app.setMainWidget(toplevel);
+ toplevel->show();
+ return app.exec();
+}
+
diff --git a/krita/plugins/viewplugins/screenshot/regiongrabber.cpp b/krita/plugins/viewplugins/screenshot/regiongrabber.cpp
new file mode 100644
index 00000000..f42f6b94
--- /dev/null
+++ b/krita/plugins/viewplugins/screenshot/regiongrabber.cpp
@@ -0,0 +1,170 @@
+/*
+ * This file was copied from ksnapshot
+ *
+ * Copyright (C) 2003 Nadeem Hasan <nhasan@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "regiongrabber.h"
+
+#include <qpainter.h>
+#include <qpalette.h>
+#include <qstyle.h>
+#include <qtimer.h>
+#include <qtooltip.h>
+
+#include <kglobalsettings.h>
+
+SizeTip::SizeTip( QWidget *parent, const char *name )
+ : QLabel( parent, name, WStyle_Customize | WX11BypassWM |
+ WStyle_StaysOnTop | WStyle_NoBorder | WStyle_Tool )
+{
+ setMargin( 2 );
+ setIndent( 0 );
+ setFrameStyle( QFrame::Plain | QFrame::Box );
+
+ setPalette( QToolTip::palette() );
+}
+
+void SizeTip::setTip( const QRect &rect )
+{
+ QString tip = QString( "%1x%2" ).arg( rect.width() )
+ .arg( rect.height() );
+
+ setText( tip );
+ adjustSize();
+
+ positionTip( rect );
+}
+
+void SizeTip::positionTip( const QRect &rect )
+{
+ QRect tipRect = geometry();
+ tipRect.moveTopLeft( QPoint( 0, 0 ) );
+
+ if ( rect.intersects( tipRect ) )
+ {
+ QRect deskR = KGlobalSettings::desktopGeometry( QPoint( 0, 0 ) );
+
+ tipRect.moveCenter( QPoint( deskR.width()/2, deskR.height()/2 ) );
+ if ( !rect.contains( tipRect, true ) && rect.intersects( tipRect ) )
+ tipRect.moveBottomRight( geometry().bottomRight() );
+ }
+
+ move( tipRect.topLeft() );
+}
+
+RegionGrabber::RegionGrabber()
+ : QWidget( 0, 0 ),
+ mouseDown( false ), sizeTip( 0L )
+{
+ sizeTip = new SizeTip( ( QWidget * )0L );
+
+ tipTimer = new QTimer( this );
+ Q_CHECK_PTR(tipTimer);
+ connect( tipTimer, SIGNAL( timeout() ), SLOT( updateSizeTip() ) );
+
+ QTimer::singleShot( 200, this, SLOT( initGrabber() ) );
+}
+
+RegionGrabber::~RegionGrabber()
+{
+ delete sizeTip;
+}
+
+void RegionGrabber::initGrabber()
+{
+ pixmap = QPixmap::grabWindow( qt_xrootwin() );
+ setPaletteBackgroundPixmap( pixmap );
+
+ showFullScreen();
+
+ grabMouse( crossCursor );
+}
+
+void RegionGrabber::mousePressEvent( QMouseEvent *e )
+{
+ if ( e->button() == LeftButton )
+ {
+ mouseDown = true;
+ grabRect = QRect( e->pos(), e->pos() );
+ }
+}
+
+void RegionGrabber::mouseMoveEvent( QMouseEvent *e )
+{
+ if ( mouseDown )
+ {
+ sizeTip->hide();
+ tipTimer->start( 250, true );
+
+ drawRubber();
+ grabRect.setBottomRight( e->pos() );
+ drawRubber();
+ }
+}
+
+void RegionGrabber::mouseReleaseEvent( QMouseEvent *e )
+{
+ mouseDown = false;
+ drawRubber();
+ sizeTip->hide();
+
+ grabRect.setBottomRight( e->pos() );
+ grabRect = grabRect.normalize();
+
+ QPixmap region = QPixmap::grabWindow( winId(), grabRect.x(), grabRect.y(),
+ grabRect.width(), grabRect.height() );
+
+ releaseMouse();
+
+ emit regionGrabbed( region );
+}
+
+void RegionGrabber::keyPressEvent( QKeyEvent *e )
+{
+ if ( e->key() == Qt::Key_Escape )
+ {
+ releaseMouse();
+ emit regionGrabbed( QPixmap() );
+ }
+ else
+ e->ignore();
+}
+
+void RegionGrabber::updateSizeTip()
+{
+ QRect rect = grabRect.normalize();
+
+ sizeTip->setTip( rect );
+ sizeTip->show();
+}
+
+void RegionGrabber::drawRubber()
+{
+ QPainter p;
+ p.begin( this );
+ p.setRasterOp( NotROP );
+ p.setPen( QPen( color0, 1 ) );
+ p.setBrush( NoBrush );
+
+ style().drawPrimitive( QStyle::PE_FocusRect, &p, grabRect, colorGroup(),
+ QStyle::Style_Default, QStyleOption( colorGroup().base() ) );
+
+ p.end();
+}
+
+#include "regiongrabber.moc"
diff --git a/krita/plugins/viewplugins/screenshot/regiongrabber.h b/krita/plugins/viewplugins/screenshot/regiongrabber.h
new file mode 100644
index 00000000..74bf78c9
--- /dev/null
+++ b/krita/plugins/viewplugins/screenshot/regiongrabber.h
@@ -0,0 +1,71 @@
+/*
+ * This file is copied from ksnapshot.
+ *
+ * Copyright (C) 2003 Nadeem Hasan <nhasan@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or ( at your option ) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef REGIONGRABBER_H
+#define REGIONGRABBER_H
+
+#include <qlabel.h>
+#include <qpixmap.h>
+
+class QTimer;
+
+class SizeTip : public QLabel
+{
+public:
+ SizeTip( QWidget *parent, const char *name=0 );
+ ~SizeTip() {}
+
+ void setTip( const QRect &rect );
+ void positionTip( const QRect &rect );
+};
+
+class RegionGrabber : public QWidget
+{
+ Q_OBJECT
+
+public:
+ RegionGrabber();
+ ~RegionGrabber();
+
+protected slots:
+ void initGrabber();
+ void updateSizeTip();
+
+ signals:
+ void regionGrabbed( const QPixmap & );
+
+protected:
+ void mousePressEvent( QMouseEvent *e );
+ void mouseReleaseEvent( QMouseEvent *e );
+ void mouseMoveEvent( QMouseEvent *e );
+ void keyPressEvent( QKeyEvent *e );
+
+ void drawRubber();
+
+ bool mouseDown;
+ QRect grabRect;
+ QPixmap pixmap;
+
+ SizeTip *sizeTip;
+ QTimer *tipTimer;
+};
+
+#endif // REGIONGRABBER_H
+
diff --git a/krita/plugins/viewplugins/screenshot/screenshot-kpresenter.rc b/krita/plugins/viewplugins/screenshot/screenshot-kpresenter.rc
new file mode 100644
index 00000000..14cd9d2e
--- /dev/null
+++ b/krita/plugins/viewplugins/screenshot/screenshot-kpresenter.rc
@@ -0,0 +1,9 @@
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui library="kritascreenshot" version="1">
+<MenuBar>
+ <Menu name="Insert"><text>&amp;Insert</text>
+ <Separator/>
+ <Action name="screenshot"/>
+ </Menu>
+</MenuBar>
+</kpartgui>
diff --git a/krita/plugins/viewplugins/screenshot/screenshot-krita.rc b/krita/plugins/viewplugins/screenshot/screenshot-krita.rc
new file mode 100644
index 00000000..07f14197
--- /dev/null
+++ b/krita/plugins/viewplugins/screenshot/screenshot-krita.rc
@@ -0,0 +1,9 @@
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui library="kritascreenshot" version="1">
+<MenuBar>
+ <Menu name="Tools"><text>&amp;Tools</text>
+ <Seperator/>
+ <Action name="screenshot"/>
+ </Menu>
+</MenuBar>
+</kpartgui>
diff --git a/krita/plugins/viewplugins/screenshot/screenshot-kword.rc b/krita/plugins/viewplugins/screenshot/screenshot-kword.rc
new file mode 100644
index 00000000..f1f3fce1
--- /dev/null
+++ b/krita/plugins/viewplugins/screenshot/screenshot-kword.rc
@@ -0,0 +1,9 @@
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui library="kritascreenshot" version="1">
+<MenuBar>
+ <Menu name="insert"><text>&amp;Insert</text>
+ <Separator/>
+ <Action name="screenshot"/>
+ </Menu>
+</MenuBar>
+</kpartgui>
diff --git a/krita/plugins/viewplugins/screenshot/screenshot.cpp b/krita/plugins/viewplugins/screenshot/screenshot.cpp
new file mode 100644
index 00000000..c7508ae9
--- /dev/null
+++ b/krita/plugins/viewplugins/screenshot/screenshot.cpp
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the KDE project
+ *
+ * This file was copied from ksnapshot
+ *
+ * Copyright (C) 2001 Nikolas Zimmermann <wildfox@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kinstance.h>
+#include <kmessagebox.h>
+#include <kstandarddirs.h>
+#include <ktempfile.h>
+#include <kdebug.h>
+#include <KoView.h>
+#include <KoDocument.h>
+#include <kgenericfactory.h>
+#include <klocale.h>
+
+#include "ksnapshot.h"
+#include <kimageio.h>
+#include <kis_view.h>
+#include <kis_image.h>
+#include "screenshot.moc"
+
+
+K_EXPORT_COMPONENT_FACTORY( kritascreenshot, KGenericFactory<Screenshot>( "krita" ) )
+
+Screenshot::Screenshot(QObject *parent, const char *name, const QStringList &)
+ : KParts::Plugin(parent, name)
+{
+ KGlobal::locale()->insertCatalogue("kscreenshot_plugin");
+ setInstance(KGenericFactory<Screenshot>::instance());
+ setXMLFile(locate("data","kritaplugins/screenshot-krita.rc"), true);
+ KImageIO::registerFormats();
+
+ snapshot = new KSnapshot();
+ Q_CHECK_PTR(snapshot);
+ connect( snapshot, SIGNAL( screenGrabbed() ), SLOT( slotScreenGrabbed() ) );
+
+ (void) new KAction(i18n("&Screenshot..."), SmallIcon("tool_screenshot"), 0, this, SLOT(slotScreenshot()), actionCollection(), "screenshot");
+
+}
+
+Screenshot::~Screenshot()
+{
+ delete snapshot;
+}
+
+void Screenshot::slotScreenshot()
+{
+ snapshot->show();
+}
+
+void Screenshot::slotScreenGrabbed()
+{
+ KTempFile temp(locateLocal("tmp", "screenshot"), ".png");
+ snapshot->save(temp.name());
+
+ KisView *view = dynamic_cast<KisView *>(parent());
+ if(view)
+ view->importImage(temp.name());
+}
diff --git a/krita/plugins/viewplugins/screenshot/screenshot.h b/krita/plugins/viewplugins/screenshot/screenshot.h
new file mode 100644
index 00000000..5e4c7c5d
--- /dev/null
+++ b/krita/plugins/viewplugins/screenshot/screenshot.h
@@ -0,0 +1,42 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2001 Nikolas Zimmermann <wildfox@kde.org>
+ * Copyright (C) 2004 Boudewijn Rempt <boud@valdyas.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#ifndef SCREENSHOT_H
+#define SCREENSHOT_H
+
+#include <kparts/plugin.h>
+
+class KSnapshot;
+
+class Screenshot : public KParts::Plugin
+{
+ Q_OBJECT
+public:
+ Screenshot(QObject *parent, const char *name, const QStringList &);
+ virtual ~Screenshot();
+
+private slots:
+ void slotScreenshot();
+ void slotScreenGrabbed();
+
+private:
+ KSnapshot * snapshot;
+};
+
+#endif