Ticket #791: new_ui_mouse_support_2.diff
File new_ui_mouse_support_2.diff, 7.2 KB (added by , 20 years ago) |
---|
-
mythmainwindow.cpp
29 29 30 30 //#include "screensaver.h" 31 31 32 #include "mythstroke.h" 33 #define GESTURE_TIMEOUT 1000 34 32 35 #ifdef USE_LIRC 33 36 static void *SpawnLirc(void *param) 34 37 { … … 127 130 128 131 bool AllowInput; 129 132 133 MythStroke stroker; 134 QTimer *strokeTimer; 135 130 136 QRegion repaintRegion; 131 137 }; 132 138 … … 197 203 d->escapekey = Key_Escape; 198 204 d->mainStack = NULL; 199 205 206 installEventFilter(this); 207 200 208 #ifdef USE_LIRC 201 209 pthread_t lirc_tid; 202 210 pthread_attr_t attr; … … 238 246 239 247 setAutoBufferSwap(false); 240 248 249 d->strokeTimer = new QTimer(this); 250 connect(d->strokeTimer, SIGNAL(timeout()), this, SLOT(mouseTimeout())); 251 241 252 d->drawTimer = new QTimer(this); 242 253 connect(d->drawTimer, SIGNAL(timeout()), this, SLOT(drawTimeout())); 243 254 d->drawTimer->start(1000 / 70); … … 724 735 d->AllowInput = allow; 725 736 } 726 737 727 void MythMainWindow:: keyPressEvent(QKeyEvent *e)738 void MythMainWindow::mouseTimeout() 728 739 { 740 MythGestureEvent *e; 741 742 /* complete the stroke if its our first timeout */ 743 if (d->stroker.recording()) 744 { 745 d->stroker.stop(); 746 } 747 748 /* get the last gesture */ 749 e = d->stroker.gesture(); 750 751 if (e->gesture() < MythGestureEvent::Click) 752 QApplication::postEvent(this, e); 753 } 754 755 bool MythMainWindow::eventFilter(QObject *o, QEvent *e) 756 { 757 758 MythGestureEvent *ge; 759 760 /* dont let anything through if input is disallowed. */ 729 761 if (!d->AllowInput) 730 return ;762 return true; 731 763 732 QValueVector<MythScreenStack *>::Iterator it;733 for (it = d->stackList.begin(); it != d->stackList.end(); ++it)764 /* filter mouse events */ 765 switch (e->type()) 734 766 { 735 MythScreenType *top = (*it)->GetTopScreen(); 736 if (top) 737 { 738 if (top->keyPressEvent(e)) 739 break; 740 } 767 case QEvent::KeyPress: 768 769 QValueVector<MythScreenStack *>::Iterator it; 770 for (it = d->stackList.begin(); it != d->stackList.end(); ++it) 771 { 772 MythScreenType *top = (*it)->GetTopScreen(); 773 if (top) 774 { 775 if (top->keyPressEvent(dynamic_cast<QKeyEvent*>(e))) 776 return true; 777 } 778 } 779 break; 780 781 case QEvent::MouseButtonPress: 782 783 if (!d->stroker.recording()) 784 { 785 d->stroker.start(); 786 d->stroker.record(dynamic_cast<QMouseEvent*>(e)->pos()); 787 788 /* start a single shot timer */ 789 d->strokeTimer->start(GESTURE_TIMEOUT); 790 791 return true; 792 } 793 794 case QEvent::MouseButtonRelease: 795 796 if (d->strokeTimer->isActive()) 797 d->strokeTimer->stop(); 798 799 if (d->stroker.recording()) 800 { 801 d->stroker.stop(); 802 ge = d->stroker.gesture(); 803 804 /* handle clicks separately */ 805 if (ge->gesture() == MythGestureEvent::Click) 806 { 807 MythUIType *clicked; 808 QValueVector<MythScreenStack *>::iterator it; 809 QPoint p = dynamic_cast<QMouseEvent*>(e)->pos(); 810 811 delete ge; 812 813 for (it = d->stackList.begin(); it != d->stackList.end(); it++) 814 { 815 MythScreenType *screen = (*it)->GetTopScreen(); 816 if ((clicked = screen->GetChildAt(p)) != NULL) 817 { 818 cout << "UI Type: " << clicked->name() << endl; 819 break; 820 } 821 } 822 } 823 else QApplication::postEvent(this, ge); 824 825 return true; 826 } 827 828 case QEvent::MouseMove: 829 830 if (d->stroker.recording()) 831 { 832 /* reset the timer */ 833 d->strokeTimer->stop(); 834 d->strokeTimer->start(GESTURE_TIMEOUT); 835 836 d->stroker.record(dynamic_cast<QMouseEvent*>(e)->pos()); 837 return true; 838 } 839 840 default: 841 break; 741 842 } 843 844 return false; 742 845 } 743 846 744 void MythMainWindow::customEvent(QCustomEvent* /* ce */)847 void MythMainWindow::customEvent(QCustomEvent* ce) 745 848 { 849 850 if (ce->type() == MythGestureEventType) 851 { 852 MythGestureEvent *ge = dynamic_cast<MythGestureEvent*>(ce); 853 if (ge != NULL) 854 { 855 cout << "Gesture: " << QString(*ge) << endl; 856 } 857 } 858 859 746 860 #if 0 747 861 if (ce->type() == kExitToMainMenuEventType && d->exitingtomain) 748 862 { -
mythuitype.cpp
82 82 return &m_ChildrenList; 83 83 } 84 84 85 MythUIType *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 85 107 bool MythUIType::NeedsRedraw(void) 86 108 { 87 109 return m_NeedsRedraw; -
mythmainwindow.h
85 85 86 86 public slots: 87 87 void drawTimeout(); 88 void mouseTimeout(); 88 89 89 90 protected: 90 91 MythMainWindow(); 91 92 92 void keyPressEvent(QKeyEvent *e);93 bool eventFilter(QObject *o, QEvent *e); 93 94 void customEvent(QCustomEvent *ce); 94 95 void closeEvent(QCloseEvent *e); 95 96 void paintEvent(QPaintEvent *e); -
libmythui.pro
28 28 SOURCES += mythscreenstack.cpp mythscreentype.cpp 29 29 SOURCES += mythuitype.cpp mythuiimage.cpp mythuitext.cpp 30 30 SOURCES += mythuistatetype.cpp mythlistbutton.cpp mythfontproperties.cpp 31 SOURCES += mythuibutton.cpp themedmenu.cpp dialogbox.cpp 31 SOURCES += mythuibutton.cpp themedmenu.cpp dialogbox.cpp mythstroke.cpp 32 32 33 33 inc.path = $${PREFIX}/include/mythui/ 34 34 … … 36 36 inc.files += mythpainter_ogl.h mythpainter_qt.h mythuistatetype.h 37 37 inc.files += mythscreenstack.h mythscreentype.h mythuitype.h mythuiimage.h 38 38 inc.files += mythuitext.h mythuibutton.h mythlistbutton.h 39 inc.files += themedmenu.h dialogbox.h mythfontproperties.h 39 inc.files += themedmenu.h dialogbox.h mythfontproperties.h mythstroke.h 40 40 41 41 INSTALLS += inc 42 42 -
mythuitype.h
25 25 void AddChild(MythUIType *child); 26 26 MythUIType *GetChild(const char *name, const char *inherits = 0); 27 27 QValueVector<MythUIType *> *GetAllChildren(void); 28 MythUIType *GetChildAt(const QPoint &p); 28 29 29 30 // Check set dirty status 30 31 bool NeedsRedraw(void);