Ticket #791: new_ui_mouse_support.diff

File new_ui_mouse_support.diff, 5.8 KB (added by mfgalizi@…, 18 years ago)

Moves event handling to filter and enables gestures

  • mythmainwindow.cpp

     
    2929
    3030//#include "screensaver.h"
    3131
     32#include "mythstroke.h"
     33
    3234#ifdef USE_LIRC
    3335static void *SpawnLirc(void *param)
    3436{
     
    127129
    128130    bool AllowInput;
    129131
     132    MythStroke stroker;
     133
    130134    QRegion repaintRegion;
    131135};
    132136
     
    197201    d->escapekey = Key_Escape;
    198202    d->mainStack = NULL;
    199203
     204    installEventFilter(this);
     205
    200206#ifdef USE_LIRC
    201207    pthread_t lirc_tid;
    202208    pthread_attr_t attr;
     
    724730    d->AllowInput = allow;
    725731}
    726732
    727 void MythMainWindow::keyPressEvent(QKeyEvent *e)
     733bool MythMainWindow::eventFilter(QObject *o, QEvent *e)
    728734{
     735
     736    MythGestureEvent *ge;
     737
     738    /* dont let anything through if input is disallowed. */
    729739    if (!d->AllowInput)
    730         return;
     740        return true;
    731741
    732     QValueVector<MythScreenStack *>::Iterator it;
    733     for (it = d->stackList.begin(); it != d->stackList.end(); ++it)
     742    /* filter mouse events */
     743    switch (e->type())
    734744    {
    735          MythScreenType *top = (*it)->GetTopScreen();
    736          if (top)
    737          {
    738              if (top->keyPressEvent(e))
    739                  break;
    740          }
     745    case QEvent::KeyPress:
     746
     747        QValueVector<MythScreenStack *>::Iterator it;
     748        for (it = d->stackList.begin(); it != d->stackList.end(); ++it)
     749        {
     750            MythScreenType *top = (*it)->GetTopScreen();
     751            if (top)
     752            {
     753                if (top->keyPressEvent(dynamic_cast<QKeyEvent*>(e)))
     754                    return true;
     755            }
     756        }
     757        break;
     758
     759    case QEvent::MouseButtonPress:
     760
     761        d->stroker.start();
     762        d->stroker.record(dynamic_cast<QMouseEvent*>(e)->pos());
     763        return true;
     764
     765    case QEvent::MouseButtonRelease:
     766
     767        ge = d->stroker.complete();
     768
     769        /* handle clicks separately */
     770        if (ge->gesture() == MythGestureEvent::Click)
     771        {           
     772            MythUIType *clicked;
     773            QValueVector<MythScreenStack *>::iterator it;
     774            QPoint p = dynamic_cast<QMouseEvent*>(e)->pos();
     775
     776            delete ge;
     777
     778            for (it = d->stackList.begin(); it != d->stackList.end(); it++)
     779            {
     780                MythScreenType *screen = (*it)->GetTopScreen();
     781                if ((clicked = screen->GetChildAt(p)) != NULL)
     782                {
     783                    cout << "UI Type: " << clicked->name() << endl;
     784                    break;
     785                }
     786            }
     787        }
     788        else QApplication::postEvent(this, ge);
     789
     790        return true;
     791
     792    case QEvent::MouseMove:
     793
     794        d->stroker.record(dynamic_cast<QMouseEvent*>(e)->pos());
     795        return true;
     796
     797    default:
     798        break;       
    741799    }
     800
     801    return false;
    742802}
    743803
    744 void MythMainWindow::customEvent(QCustomEvent* /* ce */)
     804void MythMainWindow::customEvent(QCustomEvent* ce)
    745805{
     806
     807    if (ce->type() == MythGestureEventType)
     808    {
     809        MythGestureEvent *ge = dynamic_cast<MythGestureEvent*>(ce);
     810        if (ge != NULL)
     811        {
     812            cout << "Gesture: " << QString(*ge) << endl;
     813        }
     814    }
     815
     816
    746817#if 0
    747818    if (ce->type() == kExitToMainMenuEventType && d->exitingtomain)
    748819    {
  • mythuitype.cpp

     
    8282    return &m_ChildrenList;
    8383}
    8484
     85MythUIType *MythUIType::GetChildAt(const QPoint &p)
     86{
     87    if (GetArea().contains(p)) {
     88
     89        /* assumes no selectible ui type will contain another
     90         * selectible ui type. */
     91        if (CanTakeFocus() && IsVisible()) return this;
     92
     93        /* check all children */
     94        QValueVector<MythUIType*>::iterator it;
     95        for (it = m_ChildrenList.begin(); it != m_ChildrenList.end(); ++it)
     96        {
     97            MythUIType *child = (*it)->GetChildAt(p - GetArea().topLeft());
     98            if (child != NULL)
     99            {
     100                return child;
     101            }
     102        }
     103    }
     104    return NULL;
     105}
     106
    85107bool MythUIType::NeedsRedraw(void)
    86108{
    87109    return m_NeedsRedraw;
  • mythmainwindow.h

     
    8989  protected:
    9090    MythMainWindow();
    9191
    92     void keyPressEvent(QKeyEvent *e);
     92    bool eventFilter(QObject *o, QEvent *e);
    9393    void customEvent(QCustomEvent *ce);
    9494    void closeEvent(QCloseEvent *e);
    9595    void paintEvent(QPaintEvent *e);
  • libmythui.pro

     
    2828SOURCES += mythscreenstack.cpp mythscreentype.cpp
    2929SOURCES += mythuitype.cpp mythuiimage.cpp mythuitext.cpp
    3030SOURCES += mythuistatetype.cpp mythlistbutton.cpp mythfontproperties.cpp
    31 SOURCES += mythuibutton.cpp themedmenu.cpp dialogbox.cpp
     31SOURCES += mythuibutton.cpp themedmenu.cpp dialogbox.cpp mythstroke.cpp
    3232
    3333inc.path = $${PREFIX}/include/mythui/
    3434
     
    3636inc.files += mythpainter_ogl.h mythpainter_qt.h mythuistatetype.h
    3737inc.files += mythscreenstack.h mythscreentype.h mythuitype.h mythuiimage.h
    3838inc.files += mythuitext.h mythuibutton.h mythlistbutton.h
    39 inc.files += themedmenu.h dialogbox.h mythfontproperties.h
     39inc.files += themedmenu.h dialogbox.h mythfontproperties.h mythstroke.h
    4040
    4141INSTALLS += inc
    4242
  • mythuitype.h

     
    2525    void AddChild(MythUIType *child);
    2626    MythUIType *GetChild(const char *name, const char *inherits = 0);
    2727    QValueVector<MythUIType *> *GetAllChildren(void);
     28    MythUIType *GetChildAt(const QPoint &p);
    2829
    2930    // Check set dirty status
    3031    bool NeedsRedraw(void);