Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
c38081e5
Commit
c38081e5
authored
Apr 04, 2013
by
Francois Cartegnie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Qt: add events extender
parent
829bb536
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
241 additions
and
0 deletions
+241
-0
modules/gui/qt4/Modules.am
modules/gui/qt4/Modules.am
+3
-0
modules/gui/qt4/util/events_extender.cpp
modules/gui/qt4/util/events_extender.cpp
+144
-0
modules/gui/qt4/util/events_extender.hpp
modules/gui/qt4/util/events_extender.hpp
+94
-0
No files found.
modules/gui/qt4/Modules.am
View file @
c38081e5
...
@@ -70,6 +70,7 @@ nodist_SOURCES_qt4 = \
...
@@ -70,6 +70,7 @@ nodist_SOURCES_qt4 = \
util/input_slider.moc.cpp \
util/input_slider.moc.cpp \
util/timetooltip.moc.cpp \
util/timetooltip.moc.cpp \
util/customwidgets.moc.cpp \
util/customwidgets.moc.cpp \
util/events_extender.moc.cpp \
util/searchlineedit.moc.cpp \
util/searchlineedit.moc.cpp \
util/qmenuview.moc.cpp \
util/qmenuview.moc.cpp \
util/qvlcapp.moc.cpp \
util/qvlcapp.moc.cpp \
...
@@ -333,6 +334,7 @@ SOURCES_qt4 = qt4.cpp \
...
@@ -333,6 +334,7 @@ SOURCES_qt4 = qt4.cpp \
util/input_slider.cpp \
util/input_slider.cpp \
util/timetooltip.cpp \
util/timetooltip.cpp \
util/customwidgets.cpp \
util/customwidgets.cpp \
util/events_extender.cpp \
util/searchlineedit.cpp \
util/searchlineedit.cpp \
util/registry.cpp \
util/registry.cpp \
util/qmenuview.cpp \
util/qmenuview.cpp \
...
@@ -411,6 +413,7 @@ noinst_HEADERS = \
...
@@ -411,6 +413,7 @@ noinst_HEADERS = \
util/input_slider.hpp \
util/input_slider.hpp \
util/timetooltip.hpp \
util/timetooltip.hpp \
util/customwidgets.hpp \
util/customwidgets.hpp \
util/events_extender.hpp \
util/searchlineedit.hpp \
util/searchlineedit.hpp \
util/qvlcframe.hpp \
util/qvlcframe.hpp \
util/qvlcapp.hpp \
util/qvlcapp.hpp \
...
...
modules/gui/qt4/util/events_extender.cpp
0 → 100644
View file @
c38081e5
/*****************************************************************************
* events_extender.cpp: Events Extenders / Modifiers
****************************************************************************
* Copyright (C) 2013 the VideoLAN team
*
* 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) any later version.
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "events_extender.hpp"
#include <QTimer>
#include <QApplication>
#include <QMouseEvent>
const
QEvent
::
Type
MouseEventExtenderFilter
::
MouseButtonLongPress
=
(
QEvent
::
Type
)
QEvent
::
registerEventType
();
const
QEvent
::
Type
MouseEventExtenderFilter
::
MouseButtonShortClick
=
(
QEvent
::
Type
)
QEvent
::
registerEventType
();
const
QEvent
::
Type
MouseEventExtenderFilter
::
MouseButtonLongClick
=
(
QEvent
::
Type
)
QEvent
::
registerEventType
();
MouseEventExtenderFilter
::
ButtonState
::
ButtonState
(
QObject
*
parent
,
Qt
::
MouseButton
b
)
{
state
=
RELEASED
;
button
=
b
;
timer
=
new
QTimer
(
parent
);
timer
->
setInterval
(
2
*
QApplication
::
doubleClickInterval
()
);
timer
->
setSingleShot
(
true
);
timer
->
installEventFilter
(
parent
);
}
MouseEventExtenderFilter
::
ButtonState
::~
ButtonState
()
{
delete
timer
;
}
//! MouseEventExtenderFilter constructor
/*!
\param The QObject we're extending events.
*/
MouseEventExtenderFilter
::
MouseEventExtenderFilter
(
QObject
*
parent
)
:
QObject
(
parent
)
{}
MouseEventExtenderFilter
::~
MouseEventExtenderFilter
()
{
qDeleteAll
(
buttonsStates
.
begin
(),
buttonsStates
.
end
()
);
}
MouseEventExtenderFilter
::
ButtonState
*
MouseEventExtenderFilter
::
getState
(
Qt
::
MouseButton
button
)
{
foreach
(
ButtonState
*
bs
,
buttonsStates
)
if
(
bs
->
button
==
button
)
return
bs
;
ButtonState
*
bs
=
new
ButtonState
(
this
,
button
);
buttonsStates
<<
bs
;
return
bs
;
}
MouseEventExtenderFilter
::
ButtonState
*
MouseEventExtenderFilter
::
getStateByTimer
(
int
id
)
{
foreach
(
ButtonState
*
bs
,
buttonsStates
)
if
(
bs
->
timer
->
timerId
()
==
id
)
return
bs
;
return
NULL
;
}
void
MouseEventExtenderFilter
::
postEvent
(
QObject
*
obj
,
QEvent
::
Type
type
,
ButtonState
*
bs
)
const
{
QApplication
::
postEvent
(
obj
,
new
QMouseEvent
(
type
,
bs
->
localPos
,
bs
->
button
,
bs
->
buttons
,
bs
->
modifiers
)
);
}
bool
MouseEventExtenderFilter
::
eventFilter
(
QObject
*
obj
,
QEvent
*
e
)
{
ButtonState
*
bs
;
QMouseEvent
*
mouseevent
;
QTimerEvent
*
timerevent
;
switch
(
e
->
type
()
)
{
case
QEvent
:
:
Timer
:
timerevent
=
static_cast
<
QTimerEvent
*>
(
e
);
bs
=
getStateByTimer
(
timerevent
->
timerId
()
);
if
(
bs
)
{
killTimer
(
timerevent
->
timerId
()
);
bs
->
state
=
ButtonState
::
LONGPRESSED
;
postEvent
(
obj
,
MouseButtonLongPress
,
bs
);
}
break
;
case
QEvent
:
:
MouseButtonPress
:
mouseevent
=
static_cast
<
QMouseEvent
*>
(
e
);
bs
=
getState
(
mouseevent
->
button
()
);
bs
->
state
=
ButtonState
::
PRESSED
;
bs
->
localPos
=
mouseevent
->
pos
();
bs
->
buttons
=
mouseevent
->
buttons
();
bs
->
modifiers
=
mouseevent
->
modifiers
();
bs
->
timer
->
start
();
break
;
case
QEvent
:
:
MouseButtonRelease
:
mouseevent
=
static_cast
<
QMouseEvent
*>
(
e
);
bs
=
getState
(
mouseevent
->
button
()
);
if
(
bs
->
state
==
ButtonState
::
LONGPRESSED
)
postEvent
(
obj
,
MouseButtonLongClick
,
bs
);
else
if
(
bs
->
state
==
ButtonState
::
PRESSED
)
postEvent
(
obj
,
MouseButtonShortClick
,
bs
);
bs
->
state
=
ButtonState
::
RELEASED
;
bs
->
timer
->
stop
();
break
;
case
QEvent
:
:
Leave
:
case
QEvent
:
:
MouseButtonDblClick
:
mouseevent
=
static_cast
<
QMouseEvent
*>
(
e
);
bs
=
getState
(
mouseevent
->
button
()
);
bs
->
state
=
ButtonState
::
RELEASED
;
bs
->
timer
->
stop
();
// ff
default:
break
;
}
/* Pass requests to original handler */
return
parent
()
->
eventFilter
(
obj
,
e
);
}
modules/gui/qt4/util/events_extender.hpp
0 → 100644
View file @
c38081e5
/*****************************************************************************
* events_extender.hpp: Events Extenders / Modifiers
****************************************************************************
* Copyright (C) 2013 the VideoLAN team
*
* 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) any later version.
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef EVENTS_EXTENDER_HPP
#define EVENTS_EXTENDER_HPP
#include <QObject>
#include <QEvent>
#include <QList>
#include <QPoint>
class
QMouseEvent
;
class
QTimer
;
//! MouseEventExtenderFilter
/*!
Adds special QObject mouse events per button: LongPress, ShortClick
and LongClick.
Use by registering the extender as Object's event Filter. Will pass
back every original event to Object's filter.
*/
/* Note: The Extender being a QObject too, you can chain multiple extenders */
class
MouseEventExtenderFilter
:
public
QObject
{
Q_OBJECT
public:
//! MouseButtonLongPress Event.
/*!
Fired when the mouse has been pressed for longer than a single
click time.
*/
static
const
QEvent
::
Type
MouseButtonLongPress
;
//! MouseButtonShortClick Event.
/*!
Single mouse click event. Sent by extender to differenciate
from the Object's unmodified clicked() signal.
*/
static
const
QEvent
::
Type
MouseButtonShortClick
;
//! MouseButtonLongClick Event.
/*!
Single mouse long click event. Preceded by a LongPress Event.
*/
static
const
QEvent
::
Type
MouseButtonLongClick
;
MouseEventExtenderFilter
(
QObject
*
parent
);
~
MouseEventExtenderFilter
();
protected:
bool
eventFilter
(
QObject
*
,
QEvent
*
);
private:
class
ButtonState
{
public:
ButtonState
(
QObject
*
,
Qt
::
MouseButton
);
~
ButtonState
();
enum
{
RELEASED
,
PRESSED
,
LONGPRESSED
}
state
;
QPoint
localPos
;
Qt
::
MouseButton
button
;
Qt
::
MouseButtons
buttons
;
Qt
::
KeyboardModifiers
modifiers
;
QTimer
*
timer
;
};
ButtonState
*
getState
(
Qt
::
MouseButton
);
ButtonState
*
getStateByTimer
(
int
);
void
postEvent
(
QObject
*
,
QEvent
::
Type
,
ButtonState
*
)
const
;
QList
<
ButtonState
*>
buttonsStates
;
};
#endif // EVENTS_EXTENDER_HPP
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment