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

View: New views
6 Messages — Rating Filter:   Alert me  

[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 Threaded | Show Only this Message

Hi,

This patch shows the user when the snapshot will be taken.

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

snapshot of the feedback:
http://picasaweb.google.co.uk/thomas.coopman/BlogPictures/photo#5164524265927462770

--
Thomas Coopman
Thomas.coopman@...

[ksnapshot.diff]

Index: snapshottimer.cpp
===================================================================
--- snapshottimer.cpp (revision 0)
+++ snapshottimer.cpp (revision 0)
@@ -0,0 +1,80 @@
+#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);
+}
+
+SnapshotTimer::~SnapshotTimer()
+{
+}
+
+void SnapshotTimer::start(int seconds)
+{
+  show();
+  time = 0;
+  length = seconds;
+  timer.start(1000,this);
+}
+
+void SnapshotTimer::stop()
+{
+  setVisible(false);
+  hide();
+  timer.stop();
+}
+
+void SnapshotTimer::timerEvent(QTimerEvent *event)
+{
+  if (event->timerId() == timer.timerId()) {
+    if (time == length - 1) {
+      hide();
+    } else {
+      if (time == length) {
+ emit timeout();
+      }
+    }
+  } else {
+         QWidget::timerEvent(event);
+  }
+  ++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);
+    }
+
+    kDebug() << "after paintEvent";
+}
+
Index: snapshottimer.h
===================================================================
--- snapshottimer.h (revision 0)
+++ snapshottimer.h (revision 0)
@@ -0,0 +1,31 @@
+#ifndef SNAPSHOTTIMER_H
+#define SNAPSHOTTIMER_H
+
+#include <QWidget>
+#include <QBasicTimer>
+#include <QPixmap>
+
+class SnapshotTimer : public QWidget
+{
+  Q_OBJECT
+
+  public:
+    SnapshotTimer();
+    ~SnapshotTimer();
+    void start(int seconds);
+    void stop();
+
+  signals:
+    void timeout();
+
+  protected:
+    void timerEvent(QTimerEvent *event);
+    void paintEvent( QPaintEvent* e );
+
+  private:
+    QBasicTimer timer;
+    int time;
+    int length;
+};
+
+#endif
Index: regiongrabber.cpp
===================================================================
--- regiongrabber.cpp (revision 771994)
+++ 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: ksnapshot.cpp
===================================================================
--- ksnapshot.cpp (revision 771994)
+++ 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: regiongrabber.h
===================================================================
--- regiongrabber.h (revision 771994)
+++ 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;
Index: ksnapshot.h
===================================================================
--- ksnapshot.h (revision 771994)
+++ 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 771994)
+++ 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

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 Threaded | Show Only this Message

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

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

by Bugzilla from aseigo@kde.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Friday 08 February 2008, Thomas Coopman wrote:
> I separated the patch in two because I also fixed a bug in
> regiongrabber (double clicking to grab a region didn't work correctly)
...
> and I changed the use of QBasicTimer to QTimer

comments:

* need to add license headers to your new files. they can't go into svn
without them =)

* in SnapshotTimer::paintEvent() instead of using palette(), use the tooltip
palette, e.g.:

      QPalette pal(QToolTip::palette());
      QColor handleColor = pal.color( QPalette::Active, QPalette::Highlight );
      handleColor.setAlpha( 160 );
      QColor overlayColor( 0, 0, 0, 160 );
      QColor textColor = pal.color( QPalette::Active, QPalette::Text );
      QColor textBackgroundColor = pal.color( QPalette::Active,
QPalette::Base );

this way your tooltip will look like the other tooltips in KDE (e.g. follows
the user's colour scheme).

* "Prepare for snapshot in %1" should maybe include the unit, in this case
seconds? e.g. "Snapshot will be taken in %1 second(s)" ... so:

i18np("Snapshot will be taken in %1 second", "Snapshot will be taken in %1
seconds", (length - time) );

feel free to ignore my changing of your text all around, but the
word "seconds" should be in there and this does need to use the plural form
of i18n, i18np, to be properly translatable in any case (even without the
word "seconds" there)

minor stuff:

-        grabTimer.setSingleShot( true );

there's a grabTimer.stop() in the slot it's connected to, which i suppose
works just fine. it might make just as much, if not more, sense to set both
the timers in use there to single shots in the constructor and then get rid
of all the stop() calls as they are then unecessary.

one other comment i have is on coding style. the rest of the ksnapshot
codebase seems to use 4 space tabs (ok, except for that one ugly area where
it uses tabs *puke* ;) .. it also seems to *mostly* use the "braces on the
same line" style.. so as to not continue the
devolution-into-random-indentation of ksnapshot, perhaps you could indent
your feedback class with 4 space tabs and make this:

+    if ( !r.isNull() && r.isValid() )
+    {

into this:

+    if ( !r.isNull() && r.isValid() )  {

in RegionGrabber::grabRect()

otherwise .. i like! =) i'd say commit once some of these issues are taken
care of (do you have an svn account?)... thanks for the patches, and good
catch on the double click fubar..

--
Aaron J. Seigo
humru othro a kohnu se
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43

KDE core developer sponsored by Trolltech


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

signature.asc (201 bytes) Download Attachment

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

by Richard Moore-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Aaron,

I talked to Thomas on irc and he's worked up a new version (unfinished
I believe) that use a QLabel to avoid problems with the fixed size
widget and potentially longer translated texts (also helps when the
user has specified larger fonts).

The latest patch is at: http://kde.pastebin.com/m5cd0eb60

The bug fix patch for double clicks has been committed.

Cheers

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

Parent Message unknown 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 Threaded | Show Only this Message

---------- Forwarded message ----------
From: Thomas Coopman <thomas.coopman@...>
Date: Feb 8, 2008 9:12 PM
Subject: Re: [Kde-graphics-devel] [PATCH] ksnapshot: add feedback
about when snapshot will be taken.
To: "Aaron J. Seigo" <aseigo@...>


On Feb 8, 2008 5:50 PM, Aaron J. Seigo <aseigo@...> wrote:

> On Friday 08 February 2008, Thomas Coopman wrote:
> > I separated the patch in two because I also fixed a bug in
> > regiongrabber (double clicking to grab a region didn't work correctly)
> ...
> > and I changed the use of QBasicTimer to QTimer
>
> comments:
>
> * need to add license headers to your new files. they can't go into svn
> without them =)
done

>
> * in SnapshotTimer::paintEvent() instead of using palette(), use the tooltip
> palette, e.g.:
>
>       QPalette pal(QToolTip::palette());
>       QColor handleColor = pal.color( QPalette::Active, QPalette::Highlight );
>       handleColor.setAlpha( 160 );
>       QColor overlayColor( 0, 0, 0, 160 );
>       QColor textColor = pal.color( QPalette::Active, QPalette::Text );
>       QColor textBackgroundColor = pal.color( QPalette::Active,
> QPalette::Base );
done

>
> this way your tooltip will look like the other tooltips in KDE (e.g. follows
> the user's colour scheme).
>
> * "Prepare for snapshot in %1" should maybe include the unit, in this case
> seconds? e.g. "Snapshot will be taken in %1 second(s)" ... so:
>
> i18np("Snapshot will be taken in %1 second", "Snapshot will be taken in %1
> seconds", (length - time) );
>
> feel free to ignore my changing of your text all around, but the
> word "seconds" should be in there and this does need to use the plural form
> of i18n, i18np, to be properly translatable in any case (even without the
> word "seconds" there)
done

>
> minor stuff:
>
> -        grabTimer.setSingleShot( true );
>
> there's a grabTimer.stop() in the slot it's connected to, which i suppose
> works just fine. it might make just as much, if not more, sense to set both
> the timers in use there to single shots in the constructor and then get rid
> of all the stop() calls as they are then unecessary.
>
> one other comment i have is on coding style. the rest of the ksnapshot
> codebase seems to use 4 space tabs (ok, except for that one ugly area where
> it uses tabs *puke* ;) .. it also seems to *mostly* use the "braces on the
> same line" style.. so as to not continue the
> devolution-into-random-indentation of ksnapshot, perhaps you could indent
> your feedback class with 4 space tabs and make this:
>
> +    if ( !r.isNull() && r.isValid() )
> +    {
>
> into this:
>
> +    if ( !r.isNull() && r.isValid() )  {
>
> in RegionGrabber::grabRect()
4 space tabs: done,
about the braces: regiongrabber.cpp has it braces always on a new line, or I
>
> otherwise .. i like! =) i'd say commit once some of these issues are taken
> care of (do you have an svn account?)... thanks for the patches, and good
> catch on the double click fubar..
>
I also fixed regiongrabber to use QToolTip::pallete() and
QToolTip::font(), and commited that change.

> --
> Aaron J. Seigo
> humru othro a kohnu se
> GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43
>
> KDE core developer sponsored by Trolltech
>
> _______________________________________________
> Kde-graphics-devel mailing list
> Kde-graphics-devel@...
> https://mail.kde.org/mailman/listinfo/kde-graphics-devel
>
>


--

Thomas Coopman
Thomas.coopman@...



--
Thomas Coopman
Thomas.coopman@...

[ksnapshot_feedback3.diff]

Index: snapshottimer.cpp
===================================================================
--- snapshottimer.cpp (revision 0)
+++ snapshottimer.cpp (revision 0)
@@ -0,0 +1,104 @@
+/*
+* Copyright 2008 Thomas Coopman <thomas.coopman@...>
+*
+* 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) version 3 or any later version
+* accepted by the membership of KDE e.V. (or its successor approved
+* by the membership of KDE e.V.), which shall act as a proxy
+* defined in Section 14 of version 3 of the license.
+*
+* 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <QPainter>
+#include <QColor>
+#include <QPalette>
+#include <QToolTip>
+
+#include <klocale.h>
+
+#include "snapshottimer.h"
+
+SnapshotTimer::SnapshotTimer() : QWidget(0)
+{
+    setWindowFlags( Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
+
+    label = new QLabel(this);
+    QVBoxLayout *v = new QVBoxLayout(this);
+    v->addWidget(label);
+    v->setMargin(0);
+    setStyle();
+
+    connect(&timer, SIGNAL(timeout()), this, SLOT(bell()));
+}
+
+SnapshotTimer::~SnapshotTimer()
+{
+}
+
+void SnapshotTimer::start(int seconds)
+{
+    time = 0;
+    length = seconds;
+    timer.start(1000);
+    show();
+    updateText();
+}
+
+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;
+    updateText();
+}
+
+void SnapshotTimer::setStyle()
+{
+    QPalette pal(QToolTip::palette());
+    QFont font = QToolTip::font();
+    QColor handleColor = pal.color( QPalette::Active, QPalette::Highlight );
+    handleColor.setAlpha( 160 );
+    QColor overlayColor( 0, 0, 0, 160 );
+    QColor textColor = pal.color( QPalette::Active, QPalette::Text );
+    QColor textBackgroundColor = pal.color( QPalette::Active, QPalette::Base );
+    
+    //check if the font has set it size in points or in pixels
+    QString size;
+    if (font.pixelSize() == -1) {
+        size = QString("%1 pt").arg(font.pointSize());
+    } else {
+        size = QString("%1 px").arg(font.pixelSize());
+    }
+    
+    QString style = QString("* { background: " + textBackgroundColor.name() + "; color: " +  textColor.name() + "; border: 1px solid " + textColor.name() + "; font-size: " + size + "; font-family: " + font.family() + "}");
+    
+    label->setStyleSheet(style);
+}
+
+void SnapshotTimer::updateText()
+{
+    label->setText(i18np("Snapshot will be taken in %1 second", "Snapshot will be taken in %1 seconds", (length - time) ));
+}
+
Index: snapshottimer.h
===================================================================
--- snapshottimer.h (revision 0)
+++ snapshottimer.h (revision 0)
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2008 Thomas Coopman <thomas.coopman@...>
+ *
+ * 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) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SNAPSHOTTIMER_H
+#define SNAPSHOTTIMER_H
+
+#include <QWidget>
+#include <QTimer>
+#include <QPixmap>
+#include <QLabel>
+#include <QVBoxLayout>
+
+class SnapshotTimer : public QWidget
+{
+    Q_OBJECT
+
+    public:
+    SnapshotTimer();
+    ~SnapshotTimer();
+    void start(int seconds);
+    void stop();
+
+    signals:
+    void timeout();
+
+    protected slots:
+    void bell();
+
+    protected:
+    void updateText();
+    void setStyle();
+
+    private:
+    QTimer timer;
+    int time;
+    int length;
+    QLabel *label;
+};
+
+#endif
Index: ksnapshot.cpp
===================================================================
--- ksnapshot.cpp (revision 772433)
+++ 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 772433)
+++ 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 772433)
+++ 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

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

by Lubos Lunak :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Friday 08 of February 2008, Thomas Coopman wrote:

> Hi,
>
> This patch shows the user when the snapshot will be taken.
>
> I don't know if this was the best way of doing this, so feedback is
> appreciated.
>
> snapshot of the feedback:
> http://picasaweb.google.co.uk/thomas.coopman/BlogPictures/photo#51645242659
>27462770

 The patch, if I'm getting it right, simply always puts the message at (0,0).
To make it Xinerama aware, it should be put at
KGlobalSettings::desktopGeometry( ksnapshotgeometry.center()).topLeft().

 Also, some people may have useful things in the topleft corner and the
message should not be getting in the way - it should have the input shape set
to none. There's no Qt function for that, it needs using Xlib directly, and
it's also available only since the 1.1 XShape version.

 For the version check, see e.g. kdebase/workspace/kwin/lib/kwinglobals.cpp
(Extensions::shapeInputAvailable(), Extensions::init()), setting the shape
should be just XShapeCombineRectangles( QX11Info::display(), winId(),
ShapeInput, 0, 0, NULL, 0, ShapeSet, Unsorted ). And to compile with older X,

#ifndef ShapeInput
const int ShapeInput = 2;
#endif

might be helpful.

--
Lubos Lunak
KDE developer
--------------------------------------------------------------
SUSE LINUX, s.r.o.   e-mail: l.lunak@... , l.lunak@...
Lihovarska 1060/12   tel: +420 284 028 972
190 00 Prague 9      fax: +420 284 028 951
Czech Republic       http//www.suse.cz
_______________________________________________
Kde-graphics-devel mailing list
Kde-graphics-devel@...
https://mail.kde.org/mailman/listinfo/kde-graphics-devel