|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
[Kde-graphics-devel] [PATCH] ksnapshot: add feedback about when snapshot will be taken.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.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.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 |
|
|
Re: [Kde-graphics-devel] [PATCH] ksnapshot: add feedback about when snapshot will be taken.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 |
|
|
|
|
|
Re: [Kde-graphics-devel] [PATCH] ksnapshot: add feedback about when snapshot will be taken.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 |
| Free embeddable forum powered by Nabble | Forum Help |