Commit 77bf3d50 authored by Cheng Sun's avatar Cheng Sun Committed by 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: default avatarJean-Baptiste Kempf <jb@videolan.org>
(cherry picked from commit 5337619228f8d48560601e15caf8affbb4eca3f6)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 764bbec2
......@@ -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;
}
......@@ -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();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment