Skip to content

Commit

Permalink
Reorganise the mouse gesture support so we handle events more like ke…
Browse files Browse the repository at this point in the history
…ypresses. This should be a lot more flexible and eventually let us implement more advanced behaviour. Bumps the binary version so a make clean will be required.

git-svn-id: http://svn.mythtv.org/svn/trunk@22473 7dbf422c-18fa-0310-86e9-fd20926502f2
  • Loading branch information
stuartm committed Oct 15, 2009
1 parent b413b76 commit 094fd03
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 69 deletions.
2 changes: 1 addition & 1 deletion mythtv/libs/libmythdb/mythversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/// Update this whenever the plug-in API changes.
/// Including changes in the libmythdb, libmyth and libmythui class methods
/// used by plug-ins.
#define MYTH_BINARY_VERSION "0.22.20091013-4"
#define MYTH_BINARY_VERSION "0.22.20091014-1"

/** \brief Increment this whenever the MythTV network protocol changes.
*
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmythui/libmythui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ QMAKE_CLEAN += $(TARGET) $(TARGETA) $(TARGETD) $(TARGET0) $(TARGET1) $(TARGET2)
HEADERS = mythmainwindow.h mythpainter.h mythimage.h mythrect.h
HEADERS += myththemebase.h
HEADERS += mythpainter_qt.h mythmainwindow_internal.h mythuihelper.h
HEADERS += mythscreenstack.h mythscreentype.h mythuitype.h mythuiimage.h
HEADERS += mythuitext.h mythuistatetype.h mythgesture.h xmlparsebase.h
HEADERS += mythscreenstack.h mythgesture.h mythuitype.h mythscreentype.h
HEADERS += mythuiimage.h mythuitext.h mythuistatetype.h xmlparsebase.h
HEADERS += mythuibutton.h myththemedmenu.h mythdialogbox.h
HEADERS += mythuiclock.h mythuitextedit.h mythprogressdialog.h mythuispinbox.h
HEADERS += mythuicheckbox.h mythuibuttonlist.h mythuigroup.h
Expand All @@ -31,8 +31,8 @@ HEADERS += mythvirtualkeyboard.h mythuishape.h mythuiguidegrid.h
SOURCES = mythmainwindow.cpp mythpainter.cpp mythimage.cpp mythrect.cpp
SOURCES += myththemebase.cpp
SOURCES += mythpainter_qt.cpp xmlparsebase.cpp mythuihelper.cpp
SOURCES += mythscreenstack.cpp mythscreentype.cpp mythgesture.cpp
SOURCES += mythuitype.cpp mythuiimage.cpp mythuitext.cpp
SOURCES += mythscreenstack.cpp mythgesture.cpp mythuitype.cpp mythscreentype.cpp
SOURCES += mythuiimage.cpp mythuitext.cpp
SOURCES += mythuistatetype.cpp mythfontproperties.cpp
SOURCES += mythuibutton.cpp myththemedmenu.cpp mythdialogbox.cpp
SOURCES += mythuiclock.cpp mythuitextedit.cpp mythprogressdialog.cpp
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/mythgesture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,5 +351,5 @@ static const char *gesturename[] = {
/* comments in header */
MythGestureEvent::operator QString() const
{
return gesturename[_gesture];
return gesturename[m_gesture];
}
29 changes: 22 additions & 7 deletions mythtv/libs/libmythui/mythgesture.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,34 @@ class MythGestureEvent : public QEvent
MaxGesture
};

enum Button {
NoButton,
LeftButton,
RightButton,
MiddleButton,
Aux1Button,
Aux2Button
};

/**
* @brief Create a myth gesture.
* @param type The gesture type, as per the Type enumeration.
* @sa Type
*/
inline MythGestureEvent(size_t gesture):QEvent((QEvent::Type)MythGestureEventType)
inline MythGestureEvent(Gesture gesture, Button button = LeftButton)
:QEvent((QEvent::Type)MythGestureEventType)
{
m_position = QPoint(0,0);
(gesture >= MaxGesture) ? _gesture = MaxGesture : _gesture = gesture;
m_button = button;
(gesture >= MaxGesture) ? m_gesture = MaxGesture : m_gesture = gesture;
}

/**
* @brief Get the gesture type.
* @return The gesture value corresponding to the Gesture
* enumeration.
*/
inline int gesture(void) const { return this->_gesture; }
inline Gesture gesture(void) const { return m_gesture; }

/**
* @brief Get the symbolic name of the gesture.
Expand All @@ -99,12 +110,16 @@ class MythGestureEvent : public QEvent
operator QString() const;

void SetPosition(QPoint position) { m_position = position; }
QPoint GetPosition() { return m_position; }
QPoint GetPosition() const { return m_position; }

private:
void SetButton(Button button) { m_button = button; }
Button GetButton(void) const { return m_button; }

size_t _gesture;
private:
Gesture m_gesture;
QPoint m_position;
Button m_button;

};

/* forward declaration of private information */
Expand Down Expand Up @@ -203,7 +218,7 @@ class MythGesture
size_t max_sequence;
int scale_ratio;
float bin_percent;
size_t last_gesture;
MythGestureEvent::Gesture last_gesture;
QList <QPoint> points;

MythGesturePrivate *p;
Expand Down
52 changes: 32 additions & 20 deletions mythtv/libs/libmythui/mythmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1481,37 +1481,49 @@ bool MythMainWindow::eventFilter(QObject *, QEvent *e)
/* handle clicks separately */
if (ge->gesture() == MythGestureEvent::Click)
{
MythUIType *clicked;
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(e);
if (!mouseEvent)
return false;

QVector<MythScreenStack *>::iterator it;
QPoint p = dynamic_cast<QMouseEvent*>(e)->pos();
QPoint p = mouseEvent->pos();

ge->SetPosition(p);

MythGestureEvent::Button button = MythGestureEvent::NoButton;
switch (mouseEvent->button())
{
case Qt::LeftButton :
button = MythGestureEvent::LeftButton;
break;
case Qt::RightButton :
button = MythGestureEvent::RightButton;
break;
case Qt::MidButton :
button = MythGestureEvent::MiddleButton;
break;
case Qt::XButton1 :
button = MythGestureEvent::Aux1Button;
break;
case Qt::XButton2 :
button = MythGestureEvent::Aux2Button;
break;
default :
button = MythGestureEvent::NoButton;
}

ge->SetButton(button);

for (it = d->stackList.end()-1; it != d->stackList.begin()-1;
--it)
{
MythScreenType *screen = (*it)->GetTopScreen();

if (!screen)
if (!screen || !screen->ContainsPoint(p))
continue;

// A focusable screen should be a rare event but there
// but may be desirable in a couple of scenarios
// e.g. Clicking anywhere on the screen when watching a
// video could bring up playback controls, or pause/play
if (screen->CanTakeFocus())
{
screen->gestureEvent(screen, ge);
break;
}

MythUIType *clicked = screen->GetChildAt(p);
if (clicked && clicked->IsEnabled())
{
screen->SetFocusWidget(clicked);
clicked->gestureEvent(clicked, ge);
if (screen->gestureEvent(ge))
break;
}

// Note: The following break prevents clicks being
// sent to windows below popups
Expand Down Expand Up @@ -1591,7 +1603,7 @@ void MythMainWindow::customEvent(QEvent *ce)
{
MythScreenType *screen = toplevel->GetTopScreen();
if (screen)
screen->gestureEvent(NULL, ge);
screen->gestureEvent(ge);
}
VERBOSE(VB_IMPORTANT, QString("Gesture: %1")
.arg(QString(*ge).toLocal8Bit().constData()));
Expand Down
16 changes: 15 additions & 1 deletion mythtv/libs/libmythui/mythscreentype.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

#include "mythscreentype.h"

#include <QDomDocument>

#include "mythverbose.h"

#include "mythscreentype.h"
#include "mythscreenstack.h"
#include "mythmainwindow.h"
#include "mythuihelper.h"
Expand Down Expand Up @@ -330,6 +331,19 @@ bool MythScreenType::keyPressEvent(QKeyEvent *event)
return handled;
}

bool MythScreenType::gestureEvent(MythGestureEvent *ge)
{
MythUIType *clicked = GetChildAt(ge->GetPosition());
if (clicked && clicked->IsEnabled())
{
SetFocusWidget(clicked);
if (clicked->gestureEvent(ge))
return true;
}

return false;
}

bool MythScreenType::ParseElement(QDomElement &element)
{
if (element.tagName() == "area")
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythui/mythscreentype.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MPUBLIC MythScreenType : public MythUIType
virtual bool Create(void); // do the actual work of making the screen.
virtual void Init(void);
virtual bool keyPressEvent(QKeyEvent *);
virtual bool gestureEvent(MythGestureEvent *);

// if the widget is full screen and obscures widgets below it
bool IsFullscreen(void) const;
Expand Down
17 changes: 10 additions & 7 deletions mythtv/libs/libmythui/mythuibutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,21 @@ bool MythUIButton::keyPressEvent(QKeyEvent *e)
* \param uitype The mythuitype receiving the event
* \param event Mouse event
*/
void MythUIButton::gestureEvent(MythUIType *uitype, MythGestureEvent *event)
bool MythUIButton::gestureEvent(MythGestureEvent *event)
{
if (event->gesture() == MythGestureEvent::Click)
{
if (!IsEnabled())
return;
if (IsEnabled())
{
if (m_Pushed)
UnPush();
else
Push();

if (m_Pushed)
UnPush();
else
Push();
return true;
}
}
return false;
}

void MythUIButton::Push(bool lock)
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/mythuibutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MPUBLIC MythUIButton : public MythUIType

virtual void Reset(void);

virtual void gestureEvent(MythUIType *uitype, MythGestureEvent *event);
virtual bool gestureEvent(MythGestureEvent *event);
virtual bool keyPressEvent(QKeyEvent *);

void SetText(const QString &msg);
Expand Down
15 changes: 10 additions & 5 deletions mythtv/libs/libmythui/mythuibuttonlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,21 +899,24 @@ bool MythUIButtonList::keyPressEvent(QKeyEvent *e)
* \param uitype The mythuitype receiving the event
* \param event Mouse event
*/
void MythUIButtonList::gestureEvent(MythUIType *uitype, MythGestureEvent *event)
bool MythUIButtonList::gestureEvent(MythGestureEvent *event)
{
bool handled = false;

if (event->gesture() == MythGestureEvent::Click)
{
// We want the relative position of the click
QPoint position = event->GetPosition() - m_Parent->GetArea().topLeft();

MythUIType *type = uitype->GetChildAt(position,false,false);
MythUIType *type = GetChildAt(position,false,false);

if (!type)
return;
return false;

MythUIStateType *object = dynamic_cast<MythUIStateType *>(type);
if (object)
{
handled = true;
QString name = object->objectName();

if (name == "upscrollarrow")
Expand All @@ -936,10 +939,12 @@ void MythUIButtonList::gestureEvent(MythUIType *uitype, MythGestureEvent *event)
SetItemCurrent(item);
}
}

return;
else
handled = false;
}
}

return handled;
}

QPoint MythUIButtonList::GetButtonPosition(int column, int row) const
Expand Down
3 changes: 1 addition & 2 deletions mythtv/libs/libmythui/mythuibuttonlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "mythuitype.h"
#include "mythuiimage.h"
#include "mythuitext.h"
#include "mythgesture.h"

class MythUIButtonList;
class MythFontProperties;
Expand Down Expand Up @@ -108,7 +107,7 @@ class MPUBLIC MythUIButtonList : public MythUIType
~MythUIButtonList();

virtual bool keyPressEvent(QKeyEvent *);
virtual void gestureEvent(MythUIType *uitype, MythGestureEvent *event);
virtual bool gestureEvent(MythGestureEvent *event);

void SetDrawFromBottom(bool draw);

Expand Down
14 changes: 0 additions & 14 deletions mythtv/libs/libmythui/mythuibuttontree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,20 +538,6 @@ bool MythUIButtonTree::keyPressEvent(QKeyEvent *event)
return handled;
}

// /*!
// * \copydoc MythUIType::gestureEvent()
// */
// void MythUIButtonTree::gestureEvent(MythUIType *uitype, MythGestureEvent *event)
// {
// if (event->gesture() == MythGestureEvent::Click)
// {
// QPoint position = event->GetPosition();
//
// MythUIType *object = GetChildAt(position, false);
// object->gestureEvent(object, event);
// }
// }

/*!
* \copydoc MythUIType::ParseElement()
*/
Expand Down
7 changes: 6 additions & 1 deletion mythtv/libs/libmythui/mythuicheckbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,18 @@ void MythUICheckBox::Disable()
* \param uitype The mythuitype receiving the event
* \param event Mouse event
*/
void MythUICheckBox::gestureEvent(MythUIType *uitype, MythGestureEvent *event)
bool MythUICheckBox::gestureEvent(MythGestureEvent *event)
{
if (event->gesture() == MythGestureEvent::Click)
{
if (IsEnabled())
{
toggleCheckState();
return true;
}
}

return false;
}

/** \brief Key event handler
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythui/mythuicheckbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MPUBLIC MythUICheckBox : public MythUIType
enum StateType { None = 0, Normal, Disabled, Active, Selected,
SelectedInactive };

virtual void gestureEvent(MythUIType *uitype, MythGestureEvent *event);
virtual bool gestureEvent(MythGestureEvent *event);
virtual bool keyPressEvent(QKeyEvent *);

void toggleCheckState(void);
Expand Down
Loading

0 comments on commit 094fd03

Please sign in to comment.