Git commit 7485e210b2db48f7b59f1165cb5322519a0710c9 by Christoph Feck, on behalf of J?r?me Borme. Committed on 22/05/2013 at 00:12. Pushed by cfeck into branch 'master'.
Reuse previous region for subsequent snapshots FEATURE: 233404 FIXED-IN: 4.11 M +7 -0 doc/index.docbook M +5 -2 freeregiongrabber.cpp M +2 -1 freeregiongrabber.h M +2 -1 kbackgroundsnapshot.cpp M +16 -2 ksnapshot.cpp M +5 -0 ksnapshot.h M +5 -2 regiongrabber.cpp M +2 -1 regiongrabber.h http://commits.kde.org/ksnapshot/7485e210b2db48f7b59f1165cb5322519a0710c9 diff --git a/doc/index.docbook b/doc/index.docbook index 5ff4a2f..a52fab1 100644 --- a/doc/index.docbook +++ b/doc/index.docbook @@ -236,6 +236,13 @@ to capture the screenshot. <para>If you have multiple screens, <guilabel>Current Screen</guilabel> captures the screen containing the mouse cursor when the screenshot is taken.</para> + +<para>When keeping &ksnapshot; open to take several snapshots using <guibutton> +Rectangular Region</guibutton> or <guibutton>Freehand Region</guibutton>, +the subsequent snapshots will be initialized with the last shape used with this +function (since you launched &ksnapshot;). You have then the possibility to adjust the +handles of the rectangular shape, to move the freehand region, or to completely replace the +shape by starting to draw a new one at a different place of the screen.</para> </sect1> <sect1 id="additional-features"> diff --git a/freeregiongrabber.cpp b/freeregiongrabber.cpp index b25c968..f7f1924 100644 --- a/freeregiongrabber.cpp +++ b/freeregiongrabber.cpp @@ -29,9 +29,9 @@ #include <klocale.h> #include <KWindowSystem> -FreeRegionGrabber::FreeRegionGrabber( ) : +FreeRegionGrabber::FreeRegionGrabber( const QPolygon &startFreeRegion ) : QWidget( 0, Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool ), - selection(), mouseDown( false ), newSelection( false ), + selection( startFreeRegion ), mouseDown( false ), newSelection( false ), handleSize( 10 ), mouseOverHandle( 0 ), showHelp( true ), grabbing( false ) { @@ -263,8 +263,10 @@ void FreeRegionGrabber::mouseDoubleClickEvent( QMouseEvent* ) void FreeRegionGrabber::keyPressEvent( QKeyEvent* e ) { + QPolygon pol = selection; if ( e->key() == Qt::Key_Escape ) { + emit freeRegionUpdated( pol ); emit freeRegionGrabbed( QPixmap() ); } else if ( e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return ) @@ -307,6 +309,7 @@ void FreeRegionGrabber::grabRect() pt.drawPixmap(pixmap2.rect(), pixmap, pol.boundingRect()); pt.end(); + emit freeRegionUpdated(pol); emit freeRegionGrabbed(pixmap2); } } diff --git a/freeregiongrabber.h b/freeregiongrabber.h index 1af2c43..0a327c3 100644 --- a/freeregiongrabber.h +++ b/freeregiongrabber.h @@ -33,7 +33,7 @@ class FreeRegionGrabber : public QWidget Q_OBJECT public: - FreeRegionGrabber(); + FreeRegionGrabber( const QPolygon &startFreeRegion ); ~FreeRegionGrabber(); protected slots: @@ -41,6 +41,7 @@ protected slots: signals: void freeRegionGrabbed( const QPixmap & ); + void freeRegionUpdated( const QPolygon & ); protected: void paintEvent( QPaintEvent* e ); diff --git a/kbackgroundsnapshot.cpp b/kbackgroundsnapshot.cpp index 160a284..9d81ba1 100644 --- a/kbackgroundsnapshot.cpp +++ b/kbackgroundsnapshot.cpp @@ -139,7 +139,8 @@ void KBackgroundSnapshot::slotGrab() void KBackgroundSnapshot::grabRegion() { - rgnGrab = new RegionGrabber(); + QRect emptySelection; + rgnGrab = new RegionGrabber(emptySelection); connect( rgnGrab, SIGNAL(regionGrabbed(QPixmap)), SLOT(slotRegionGrabbed(QPixmap)) ); diff --git a/ksnapshot.cpp b/ksnapshot.cpp index f5f3e40..a685cd3 100644 --- a/ksnapshot.cpp +++ b/ksnapshot.cpp @@ -586,6 +586,16 @@ void KSnapshot::slotRegionGrabbed( const QPixmap &pix ) show(); } +void KSnapshot::slotRegionUpdated( const QRect &selection ) +{ + lastRegion = selection; +} + +void KSnapshot::slotFreeRegionUpdated( const QPolygon &selection ) +{ + lastFreeRegion = selection; +} + void KSnapshot::slotWindowGrabbed( const QPixmap &pix ) { if ( !pix.isNull() ) @@ -645,17 +655,21 @@ void KSnapshot::updatePreview() void KSnapshot::grabRegion() { - rgnGrab = new RegionGrabber(); + rgnGrab = new RegionGrabber(lastRegion); connect( rgnGrab, SIGNAL(regionGrabbed(QPixmap)), SLOT(slotRegionGrabbed(QPixmap)) ); + connect( rgnGrab, SIGNAL(regionUpdated(QRect)), + SLOT(slotRegionUpdated(QRect)) ); } void KSnapshot::grabFreeRegion() { - freeRgnGrab = new FreeRegionGrabber(); + freeRgnGrab = new FreeRegionGrabber(lastFreeRegion); connect( freeRgnGrab, SIGNAL(freeRegionGrabbed(QPixmap)), SLOT(slotRegionGrabbed(QPixmap)) ); + connect( freeRgnGrab, SIGNAL(freeRegionUpdated(QPolygon)), + SLOT(slotFreeRegionUpdated(QPolygon)) ); } diff --git a/ksnapshot.h b/ksnapshot.h index cc51252..8b5fe29 100644 --- a/ksnapshot.h +++ b/ksnapshot.h @@ -103,6 +103,8 @@ private slots: void updateCaption(); void updatePreview(); void slotRegionGrabbed( const QPixmap & ); + void slotRegionUpdated( const QRect & ); + void slotFreeRegionUpdated( const QPolygon & ); void slotWindowGrabbed( const QPixmap & ); void slotModeChanged( int mode ); void setPreview( const QPixmap &pm ); @@ -139,6 +141,9 @@ private: QPoint savedPosition; bool haveXFixes; bool includeAlpha; + QPolygon lastFreeRegion; + QRect lastRegion; + #ifdef KIPI_FOUND KIPI::PluginLoader* mPluginLoader; friend KUrl::List KSnapshotImageCollectionShared::images(); diff --git a/regiongrabber.cpp b/regiongrabber.cpp index 028bf09..fb038a3 100644 --- a/regiongrabber.cpp +++ b/regiongrabber.cpp @@ -28,9 +28,9 @@ #include <klocale.h> #include <KWindowSystem> -RegionGrabber::RegionGrabber( ) : +RegionGrabber::RegionGrabber( const QRect &startSelection ) : QWidget( 0, Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool ), - selection(), mouseDown( false ), newSelection( false ), + selection( startSelection ), mouseDown( false ), newSelection( false ), handleSize( 10 ), mouseOverHandle( 0 ), showHelp( true ), grabbing( false ), TLHandle(0,0,handleSize,handleSize), TRHandle(0,0,handleSize,handleSize), @@ -334,8 +334,10 @@ void RegionGrabber::mouseDoubleClickEvent( QMouseEvent* ) void RegionGrabber::keyPressEvent( QKeyEvent* e ) { + QRect r = selection; if ( e->key() == Qt::Key_Escape ) { + emit regionUpdated( r ); emit regionGrabbed( QPixmap() ); } else if ( e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return ) @@ -354,6 +356,7 @@ void RegionGrabber::grabRect() if ( !r.isNull() && r.isValid() ) { grabbing = true; + emit regionUpdated( r ); emit regionGrabbed( pixmap.copy(r) ); } } diff --git a/regiongrabber.h b/regiongrabber.h index 3d408e4..3ade77b 100644 --- a/regiongrabber.h +++ b/regiongrabber.h @@ -36,7 +36,7 @@ class RegionGrabber : public QWidget enum MaskType { StrokeMask, FillMask }; public: - RegionGrabber(); + RegionGrabber( const QRect &startSelection ); ~RegionGrabber(); protected slots: @@ -44,6 +44,7 @@ protected slots: signals: void regionGrabbed( const QPixmap & ); + void regionUpdated( const QRect & ); protected: void paintEvent( QPaintEvent* e );