[vlc-commits] Fix QToolButtonExt edge cases
Cheng Sun
git at videolan.org
Tue Dec 20 00:23:44 CET 2011
vlc/vlc-1.2 | branch: master | Cheng Sun <chengsun9 at gmail.com> | Sat Dec 17 21:22:11 2011 +0000| [77bf3d50cb0e411a3e08ff37e3d8d8cf21cbf000] | committer: Jean-Baptiste Kempf
Fix QToolButtonExt edge cases
Previously QToolButtonExt had some undesirable edge case behaviour.
Firstly, once the user presses down on a QToolButtonExt there is no
way to cancel the action; either a short or a long click will be
generated. Compare this to a normal button, which can be cancelled by
releasing the mouse outside of the button area.
Secondly, with the mouse button held down, moving the mouse in and out
of the button area will generate multiple short click events, when no
event at all is desired.
This patch corrects this: by releasing the mouse outside the button area
no event is generated; additionally no short click events are generated
simply by moving the depressed mouse in and out of the button.
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
(cherry picked from commit 5337619228f8d48560601e15caf8affbb4eca3f6)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.2.git/?a=commit;h=77bf3d50cb0e411a3e08ff37e3d8d8cf21cbf000
---
modules/gui/qt4/util/customwidgets.cpp | 51 ++++++++++++++++++++++++++++---
modules/gui/qt4/util/customwidgets.hpp | 2 +
2 files changed, 48 insertions(+), 5 deletions(-)
diff --git a/modules/gui/qt4/util/customwidgets.cpp b/modules/gui/qt4/util/customwidgets.cpp
index 76f2a35..11dafd9 100644
--- a/modules/gui/qt4/util/customwidgets.cpp
+++ b/modules/gui/qt4/util/customwidgets.cpp
@@ -403,25 +403,66 @@ SpinningIcon::SpinningIcon( QWidget *parent, bool noIdleFrame )
}
QToolButtonExt::QToolButtonExt(QWidget *parent, int ms )
- :QToolButton( parent ), longClick( false )
+ : QToolButton( parent ),
+ shortClick( false ),
+ longClick( false )
{
setAutoRepeat( true );
/* default to twice the doubleclick delay */
setAutoRepeatDelay( ( ms > 0 )? ms : 2 * QApplication::doubleClickInterval() );
setAutoRepeatInterval( 100 );
connect( this, SIGNAL(released()), this, SLOT(releasedSlot()) );
+ connect( this, SIGNAL(clicked()), this, SLOT(clickedSlot()) );
}
+/* table illustrating the different scenarios and the events generated
+ * ====================
+ *
+ * event isDown()
+ *
+ * released false }
+ * clicked false }= short click
+ *
+ * released false = cancelled click (mouse released outside of button area,
+ * before long click delay kicks in)
+ *
+ * released true }
+ * clicked true }= long click (multiple of these generated)
+ * released false = stop long click (mouse released / moved outside of
+ * button area)
+ * (clicked false) = stop long click (additional event if mouse released
+ * inside of button area)
+ */
+
void QToolButtonExt::releasedSlot()
{
if( isDown() )
+ {
+ // we are beginning a long click
longClick = true;
+ shortClick = false;
+ }
+ else
+ {
+ if( longClick )
+ {
+ // we are stopping a long click
+ longClick = false;
+ shortClick = false;
+ }
+ else
+ {
+ // we are generating a short click
+ longClick = false;
+ shortClick = true;
+ }
+ }
+}
+void QToolButtonExt::clickedSlot()
+{
if( longClick )
emit longClicked();
- else
+ else if( shortClick )
emit shortClicked();
-
- if( !isDown() )
- longClick = false;
}
diff --git a/modules/gui/qt4/util/customwidgets.hpp b/modules/gui/qt4/util/customwidgets.hpp
index 0814ca0..d1fcec6 100644
--- a/modules/gui/qt4/util/customwidgets.hpp
+++ b/modules/gui/qt4/util/customwidgets.hpp
@@ -54,9 +54,11 @@ class QToolButtonExt : public QToolButton
public:
QToolButtonExt( QWidget *parent = 0, int ms = 0 );
private:
+ bool shortClick;
bool longClick;
private slots:
void releasedSlot();
+ void clickedSlot();
signals:
void shortClicked();
void longClicked();
More information about the vlc-commits
mailing list