« Return to Thread: [Kde-graphics-devel] [PATCH] ksnapshot: add feedback about when snapshot will be taken.

Re: [Kde-graphics-devel] [PATCH] ksnapshot: add feedback about when snapshot will be taken.

by Bugzilla from thomas.coopman@gmail.com :: Rate this Message:

Reply to Author | View in Thread

On Feb 8, 2008 9:32 AM, Thomas Coopman <thomas.coopman@...> wrote:
> Hi,
>
> This patch shows the user when the snapshot will be taken.
I've got some feedback from Richard Moore so I made following changes:

I separated the patch in two because I also fixed a bug in
regiongrabber (double clicking to grab a region didn't work correctly)


>
> I don't know if this was the best way of doing this, so feedback is appreciated.

and I changed the use of QBasicTimer to QTimer
>
> snapshot of the feedback:
> http://picasaweb.google.co.uk/thomas.coopman/BlogPictures/photo#5164524265927462770
>
> --
> Thomas Coopman
> Thomas.coopman@...
>



--
Thomas Coopman
Thomas.coopman@...

[ksnapshot_regiongrabber.diff]

Index: regiongrabber.cpp
===================================================================
--- regiongrabber.cpp (revision 772298)
+++ regiongrabber.cpp (working copy)
@@ -307,12 +307,7 @@
 
 void RegionGrabber::mouseDoubleClickEvent( QMouseEvent* )
 {
-    QRect r = selection.normalized();
-    if ( !r.isNull() && r.isValid() )
-    {
-        grabbing = true;
-        emit regionGrabbed( QPixmap::grabWidget( this, r ) );
-    }
+    grabRect();
 }
 
 void RegionGrabber::keyPressEvent( QKeyEvent* e )
@@ -323,12 +318,7 @@
     }
     else if ( e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return )
     {
-        QRect r = selection.normalized();
-        if ( !r.isNull() && r.isValid() )
-        {
-            grabbing = true;
-            emit regionGrabbed( pixmap.copy(r) );
-        }
+        grabRect();
     }
     else
     {
@@ -336,6 +326,16 @@
     }
 }
 
+void RegionGrabber::grabRect()
+{
+    QRect r = selection.normalized();
+    if ( !r.isNull() && r.isValid() )
+    {
+ grabbing = true;
+        emit regionGrabbed( pixmap.copy(r) );
+    }
+}
+
 void RegionGrabber::updateHandles()
 {
     QRect r = selection.normalized().adjusted( 0, 0, -1, -1 );
Index: regiongrabber.h
===================================================================
--- regiongrabber.h (revision 772298)
+++ regiongrabber.h (working copy)
@@ -55,6 +55,7 @@
     void updateHandles();
     QRegion handleMask() const;
     QPoint limitPointToRect( const QPoint &p, const QRect &r ) const;
+    void grabRect();
 
     QRect selection;
     bool mouseDown;




[ksnapshot_feedback.diff]

Index: snapshottimer.cpp
===================================================================
--- snapshottimer.cpp (revision 0)
+++ snapshottimer.cpp (revision 0)
@@ -0,0 +1,76 @@
+#include <QTimerEvent>
+#include <QPainter>
+#include <QPaintEvent>
+
+#include <KDebug>
+#include <klocale.h>
+
+
+#include "snapshottimer.h"
+
+SnapshotTimer::SnapshotTimer() : QWidget(0)
+{
+    setWindowFlags( Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
+    resize(180,20);
+    connect(&timer, SIGNAL(timeout()), this, SLOT(bell()));
+}
+
+SnapshotTimer::~SnapshotTimer()
+{
+}
+
+void SnapshotTimer::start(int seconds)
+{
+  show();
+  time = 0;
+  length = seconds;
+  timer.start(1000);
+}
+
+void SnapshotTimer::stop()
+{
+  setVisible(false);
+  hide();
+  timer.stop();
+}
+
+void SnapshotTimer::bell()
+{
+  if (time == length - 1) {
+    hide();
+  } else {
+    if (time == length) {
+      emit timeout();
+      timer.stop();
+    }
+  }
+  ++time;
+  update();
+}
+
+void SnapshotTimer::paintEvent( QPaintEvent* e )
+{
+    Q_UNUSED( e );
+
+    QPainter painter( this );
+
+    if (time < length) {
+  
+      QColor handleColor = palette().color( QPalette::Active, QPalette::Highlight );
+      handleColor.setAlpha( 160 );
+      QColor overlayColor( 0, 0, 0, 160 );
+      QColor textColor = palette().color( QPalette::Active, QPalette::Text );
+      QColor textBackgroundColor = palette().color( QPalette::Active, QPalette::Base );
+
+  
+      painter.setPen( textColor );
+      painter.setBrush( textBackgroundColor );
+      QString helpText = i18n( "Prepare for snapshot in %1", (length-time) );
+      QRect textRect = painter.boundingRect( rect().adjusted( 2, 2, -2, -2 ), Qt::TextWordWrap, helpText );
+      textRect.adjust( -2, -2, 4, 2 );
+      painter.drawRect( rect().adjusted(0,0,-1,-1) );
+      textRect.moveTopLeft( QPoint( 3, 3 ) );
+      painter.drawText(textRect, helpText);
+    }
+}
+
Index: snapshottimer.h
===================================================================
--- snapshottimer.h (revision 0)
+++ snapshottimer.h (revision 0)
@@ -0,0 +1,33 @@
+#ifndef SNAPSHOTTIMER_H
+#define SNAPSHOTTIMER_H
+
+#include <QWidget>
+#include <QTimer>
+#include <QPixmap>
+
+class SnapshotTimer : public QWidget
+{
+  Q_OBJECT
+
+  public:
+    SnapshotTimer();
+    ~SnapshotTimer();
+    void start(int seconds);
+    void stop();
+
+  signals:
+    void timeout();
+
+  protected slots:
+    void bell();
+
+  protected:
+    void paintEvent( QPaintEvent* e );
+
+  private:
+    QTimer timer;
+    int time;
+    int length;
+};
+
+#endif
Index: ksnapshot.cpp
===================================================================
--- ksnapshot.cpp (revision 772298)
+++ ksnapshot.cpp (working copy)
@@ -253,8 +253,7 @@
     hide();
 
     if ( delay() ) {
-        grabTimer.setSingleShot( true );
-        grabTimer.start( delay() * 1000 );
+        grabTimer.start( delay());
     }
     else {
         if ( mode() == Region ) {
Index: ksnapshot.h
===================================================================
--- ksnapshot.h (revision 772298)
+++ ksnapshot.h (working copy)
@@ -39,6 +39,7 @@
 #include <kservice.h>
 #include <kurl.h>
 #include "ksnapshotobject.h"
+#include "snapshottimer.h"
 
 class KSnapshotWidget;
 class QMenu;
@@ -193,7 +194,7 @@
 private:
     void performGrab();
     void grabRegion();
-    QTimer grabTimer;
+    SnapshotTimer grabTimer;
     QTimer updateTimer;
     QMenu*  openMenu;
     KSnapshotWidget *mainWidget;
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt (revision 772298)
+++ CMakeLists.txt (working copy)
@@ -6,6 +6,7 @@
 
 set(ksnapshot_file_SRCS
  regiongrabber.cpp
+ snapshottimer.cpp
  windowgrabber.cpp
  ksnapshotobject.cpp)
 


_______________________________________________
Kde-graphics-devel mailing list
Kde-graphics-devel@...
https://mail.kde.org/mailman/listinfo/kde-graphics-devel

 « Return to Thread: [Kde-graphics-devel] [PATCH] ksnapshot: add feedback about when snapshot will be taken.