[vlc-commits] Qt, new utility class to differentiate short and long clicks
Jean-Baptiste Kempf
git at videolan.org
Thu Apr 21 00:58:21 CEST 2011
vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Thu Apr 21 00:12:08 2011 +0200| [b306b3a78212fbf55697be599c0c1cadaa0dc633] | committer: Jean-Baptiste Kempf
Qt, new utility class to differentiate short and long clicks
ShortClick is the normal click
LongClick is emitted regularly until the button is released
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b306b3a78212fbf55697be599c0c1cadaa0dc633
---
modules/gui/qt4/util/customwidgets.cpp | 22 ++++++++++++++++++++++
modules/gui/qt4/util/customwidgets.hpp | 16 +++++++++++++++-
2 files changed, 37 insertions(+), 1 deletions(-)
diff --git a/modules/gui/qt4/util/customwidgets.cpp b/modules/gui/qt4/util/customwidgets.cpp
index b7245cc..5042c41 100644
--- a/modules/gui/qt4/util/customwidgets.cpp
+++ b/modules/gui/qt4/util/customwidgets.cpp
@@ -411,3 +411,25 @@ SpinningIcon::SpinningIcon( QWidget *parent, bool noIdleFrame )
SpinningIcon::~SpinningIcon()
{
}
+
+QToolButtonExt::QToolButtonExt(QWidget *parent, int ms ): longClick( false )
+{
+ setAutoRepeat( true );
+ setAutoRepeatDelay( ms );
+ setAutoRepeatInterval( 100 );
+ connect( this, SIGNAL(released()), this, SLOT(releasedSlot()) );
+}
+
+void QToolButtonExt::releasedSlot()
+{
+ if( isDown() )
+ longClick = true;
+
+ if( longClick )
+ emit longClicked();
+ else
+ emit shortClicked();
+
+ if( !isDown() )
+ longClick = false;
+}
diff --git a/modules/gui/qt4/util/customwidgets.hpp b/modules/gui/qt4/util/customwidgets.hpp
index f8416e4..e4301b3 100644
--- a/modules/gui/qt4/util/customwidgets.hpp
+++ b/modules/gui/qt4/util/customwidgets.hpp
@@ -34,6 +34,8 @@
#include <QSpinBox>
#include <QList>
#include <QTimer>
+#include <QToolButton>
+
class QPixmap;
class QFramelessButton : public QPushButton
@@ -46,6 +48,19 @@ protected:
virtual void paintEvent( QPaintEvent * event );
};
+class QToolButtonExt : public QToolButton
+{
+ Q_OBJECT
+public:
+ QToolButtonExt( QWidget *parent = 0, int ms = 1000 );
+private:
+ bool longClick;
+private slots:
+ void releasedSlot();
+signals:
+ void shortClicked();
+ void longClicked();
+};
class QElidingLabel : public QLabel
{
@@ -166,4 +181,3 @@ int qtWheelEventToVLCKey( QWheelEvent *e );
QString VLCKeyToString( unsigned val );
#endif
-
More information about the vlc-commits
mailing list