SlideShare a Scribd company logo
Using Multi-Touch and
Gestures with Qt
                        10/09/09
Jens Bache-Wiig
Introduction

Jens Bache-Wiig
  •  Worked on Qt since 2005
  •  Platform Team
  •  Interim Widget Pimp




                               2
Agenda

•  Introduction
Concepts
API
Examples
Q&A




                  3
Agenda

Introduction
•  Concepts
API
Examples
Q&A




               4
Concepts

What do we mean when we say multi-touch?




                                           5
Concepts

A widget reacts to multiple touch-points

For example, to zoom/scale content...


      Lorem ipsum dolor sit       Lorem ipsum dolor 
      eamt. Dolore magna 
      aliquam erat volupat. Ut    sit eamt. Dolore 
      enim ad minimum             magna aliquam 
      veniami quis. Duis sutem 
      vel eum irure dolor in 
                                  erat volupat...cvc 
      rerit laputum 




                                                        6
Concepts

  Multiple widgets react to multiple touch-points
     For example, moving several sliders at once...




                                                      7
Concepts

Real life is multi-touch
Do you open a bottle with one finger?
Applications could do it too...



                                            1



                                        2




                                                8
Concepts

Part of our future since at least 1982... 




                                      Disney © 1982 




                                                       9
Concepts




           Sony Pictures © 2009 




                                   10
hBp://www.youtube.com 
Concepts

What do we mean when we say gestures?




                                        12
Concepts

A way to make common multi-touch use-cases
easy to use in your application

• Standard, platform-specific touch-based gestures
• Extensible API for custom gestures




                                                     13
Concepts

What are standard gestures?

•  Built-in multi-touch gestures that work in standard Qt
widgets




                                                            14
Concepts

Pan gesture

•  Scrolls content
•  Works in all scrollable Qt widgets

         Lorem ipsum dolor sit          Ut enim ad minimum 
         eamt. Dolore magna             veniami quis. Duis sutem 
         aliquam erat volupat.          vel eum irure dolor in 
         Ut enim ad minimum             rerit laputum 
         veniami quis. Duis
         sutem vel eum irure
         dolor in rerit laputum




                                                                    15
Concepts

Pinch gesture

Zoom and/or rotate content




                             16
Agenda

Introduction
Concepts
•  API
Examples
Q&A




               17
API

Multi-touch
  •  New event types
     •  TouchBegin
     •  TouchUpdate
     •  TouchEnd
  •  New QTouchEvent class
  •  QWidget and QGraphicsItem API




                                     18
API

QEvent::TouchBegin
  •  First in sequence
  •  Must be accepted to receive following events




                                                    19
API

QEvent::TouchUpdate
  •  Normal event indicating activity
  •  Expect more events to follow




                                        20
API

QEvent::TouchEnd
  •  Final event in sequence
  •  No more events without a new TouchBegin




                                               21
API

TouchBegin propagation
  •  When ignored, propagate to widget under first touch-
     point
  •  Widgets never receive multiple TouchBegin
  •  New touch-points on children are combined with first
     touch-point


                  1                                      1           2




    One event, one point, to grey widget    One event, two points, to grey widget 




                                                                                     22
API

TouchUpdate, TouchEnd do not propagate




                                         23
API

QTouchEvent
  •  Event class for QWidget and QGraphicsItem
  •  Contains list of active touch points
  •  Device type – TouchScreen or TouchPad




                                                 24
API

QTouchEvent::TouchPoint
  •    Information about one touch-point
  •    Integer identifier
  •    Primary touch-point flag
  •    State - Pressed, Moved, Stationary, or Released
  •    Current, previous, starting positions
  •    Local, scene, screen, normalized translations
  •    Area, pressure (if supported by device)




                                                         25
API

Touch events are not sent by default
  •  Must be enabled first
  •  When enabled, TouchBegin event will be accepted
     unless explicitly ignored




                                                       26
API

Qt::WA_AcceptsTouchEvents
  •  Set on QWidget to receive touch events
  •  To handle events, reimplement QWidget::event()
  •  Default implementation emulates mouse events for first
     non-primary touch-point
  •  Set on viewport() of QAbstractScrollArea based
     widgets
  •  To handle events, reimplement
     QAbstractScrollArea::viewportEvent()




                                                              27
API

QGraphicsItem::setAcceptsTouchEvents(bool)
  •  Set to true on item to receive touch events
  •  To handle, reimplement QGraphicsItem::sceneEvent()
  •  No default implementation




                                                          28
API

 Gestures

 •    QGesture and QGestureRecognizer classes
 •    Widgets subscribe to gestures
 •    Using standard gestures
 •    Implementing custom gestures




                                                29
API

QGesture
   •    Base class for more complex gestures
   •    Basic properties and convenience functions
   •    Delivered to QWidget or QGraphicsObject
   •    State (Started, Updated, Finished, Canceled)

QGestureEvent
  •  Contains a list of QGestures
  •  Normal event propagation rules apply




                                                       30
API

QGestureRecognizer
  •  “Just” an event filter + state machine
  •  Registered in QApplication
  •  Announces when a gesture is triggered




                                              31
API

 How do I use a gesture?
      •  Use grabGesture() to request it
      •  Handle the QGestureEvent and get:
          QPanGesture
             -  Offset property
          QPinchGesture
             -  Center-point, rotation, scale properties




                                                           32
API

 Implementing custom gestures
 •    Create a state machine:
      - subclass QGestureRecognizer
      - implement filterEvent(), createGesture(), reset()

 •    Create a gesture object:
      - subclass QGesture (optional)
      - fill QGesture with properties




                                                            33
API

Gestures can be simple : Four finger tap
class FourFingerTapGesture : public QGestureRecognizer
{
   virtual Result filterEvent(QGesture *, QObject *, QEvent *event)
     {
         if (event->type() == QEvent::TouchUpdate)
               if (static_cast<QTouchEvent *>(event)->touchPoints.size() == 4)
                    return GestureFinished;

         return Ignore;
     }
};




                                                                                 34
API

 Gestures can be complex
 •    Event filter could implement a state machine
 •    Continuous gesture going through Qt::GestureStated
      to Qt::GestureUpdated to Qt::GestureFinished
      states.
 •    Gesture may need to hijack events, store them, and
      replay them later




                                                           35
API

Special considerations when implementing and/
or using gestures




                                                36
API

Single gesture on parent widget with children
  •  Should the parent's gesture filter events for children?
GestureContext
  •  widget-only gesture
  •  widget-with-children gesture




                                                               37
API

 Multiple gestures on a single widget
 •    All gestures filter incoming events in undefined order
 •    Ignored gestures will be propagated
 •    You can partially ignore a gesture:

 bool gestureEvent(QGestureEvent *event) {
      event->ignore(Qt::PanGesture);
      event->accept(Qt::PinchGesture);
      return true;
 }




                                                               38
API

 Gesture has priority over normal event
    handling
 •  Gesture may need several events before
    starting
 •  Normal event handling interferes with
    gesture
 •  Events should be delayed




                                             39
Agenda

Introduction
Concepts
API
•  Examples
Q&A




               40
API

ITAI: PictureBlue
by Ariel Molina




                    h$p://vimeo.com/4990545 



                                               41
Examples

Using QTouchEvent...

MyWidget::MyWidget(QWidget *parent) {
  setAttribute(Qt::WA_AcceptsTouchEvents);
}




                                             42
Examples

Using QTouchEvent...

bool MyWidget::event(QEvent *e) {
  switch (e->type()) {
  case QEvent::TouchBegin:
  case QEvent::TouchUpdate:
  case QEvent::TouchEnd:
  {
       // creative stuff here
  }
}



                                    43
Examples

Using QTouchEvent...

QTouchEvent *te = static_cast<QTouchEvent *>(e);
QList<QTouchEvent::TouchPoint> points = te->touchPoints();

if (touchPoints.count() == 2) {
    // Do something interesting here
}




                                                             44
Examples

Using QTouchEvent...

// determine scale factor
QTouchEvent::TouchPoint p0 = touchPoints.first();
QTouchEvent::TouchPoint p1 = touchPoints.last();
QLineF line1(p0.startPos(), p1.startPos());
QLineF line2(p0.pos(), p1.pos());
qreal scaleFactor = line2.length() / line1.length();
setContentScale(scaleFactor);




                                                       45
Examples

Using QTouchEvent...

// determine angle between previous and current pos
QTouchEvent::TouchPoint p0 = touchPoints.first();
QTouchEvent::TouchPoint p1 = touchPoints.last();
QLineF line1(p0.lastPos(), p1.lastPos());
QLineF line2(p0.pos(), p1.pos());
qreal angle = line2.angleTo(line1);
rotateContentBy(angle);




                                                      46
And now some gestures... 
Examples

Custom gesture – four finger tap
class FourFingerTapGesture : public QGestureRecognizer {
   virtual QGesture createGesture(QObject *) {
         return new QGesture(“FourFingerTap”); }
     }
     virtual Result filterEvent(QGesture *state, QObject *, QEvent *event) {
         if (event->type() == QEvent::TouchUpdate)
           if (static_cast<QTouchEvent *>(event)->touchPoints.size() == 4) {

               state->setProperty(“foo”, QLatin1String(“bar”));
               return GestureFinished;

           }
         return Ignore;
     }
};
                                                                               48
Examples

Custom gesture – four finger tap
class Label : public QLabel {
   virtual void gestureEvent(QGestureEvent *event) {
      if (QGesture *g = event->gesture(“FourFingerTap”)) {
          setText(g->property(“foo”));
        event->accept(g);

     } ...

 QLabel *label = new Qlabel;

 label->setPixmap(QPixmap(“qt-logo.png”));

 label->grabGesture(“FourFingerTap”);




                                                             49
Agenda

Introduction
Concepts
API
Examples
•  Q&A




               50
Thanks!

Any Questions?




                 51

More Related Content

What's hot

유니티 + Nodejs를 활용한 멀티플레이어 게임 개발하기
유니티 + Nodejs를 활용한 멀티플레이어 게임 개발하기유니티 + Nodejs를 활용한 멀티플레이어 게임 개발하기
유니티 + Nodejs를 활용한 멀티플레이어 게임 개발하기
Kiyoung Moon
 
Qt test framework
Qt test frameworkQt test framework
Qt test framework
ICS
 
도커 무작정 따라하기: 도커가 처음인 사람도 60분이면 웹 서버를 올릴 수 있습니다!
도커 무작정 따라하기: 도커가 처음인 사람도 60분이면 웹 서버를 올릴 수 있습니다!도커 무작정 따라하기: 도커가 처음인 사람도 60분이면 웹 서버를 올릴 수 있습니다!
도커 무작정 따라하기: 도커가 처음인 사람도 60분이면 웹 서버를 올릴 수 있습니다!
pyrasis
 
Gaming on AWS - 1. AWS로 글로벌 게임 런칭하기 - 장르별 아키텍처 중심
Gaming on AWS - 1. AWS로 글로벌 게임 런칭하기 - 장르별 아키텍처 중심Gaming on AWS - 1. AWS로 글로벌 게임 런칭하기 - 장르별 아키텍처 중심
Gaming on AWS - 1. AWS로 글로벌 게임 런칭하기 - 장르별 아키텍처 중심
Amazon Web Services Korea
 
[IGC2018] 청강대 이득우 - 언리얼에디터확장을위해알아야할것들
[IGC2018] 청강대 이득우 - 언리얼에디터확장을위해알아야할것들[IGC2018] 청강대 이득우 - 언리얼에디터확장을위해알아야할것들
[IGC2018] 청강대 이득우 - 언리얼에디터확장을위해알아야할것들
강 민우
 
Qt and QML performance tips & tricks for Qt 4.7
Qt and QML performance tips & tricks for Qt 4.7Qt and QML performance tips & tricks for Qt 4.7
Qt and QML performance tips & tricks for Qt 4.7
Pasi Kellokoski
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part III
ICS
 
Qt for Python
Qt for PythonQt for Python
Qt for Python
ICS
 
그럴듯한 랜덤 생성 컨텐츠 만들기
그럴듯한 랜덤 생성 컨텐츠 만들기그럴듯한 랜덤 생성 컨텐츠 만들기
그럴듯한 랜덤 생성 컨텐츠 만들기
Yongha Kim
 
GameInstance에 대해서 알아보자
GameInstance에 대해서 알아보자GameInstance에 대해서 알아보자
GameInstance에 대해서 알아보자
TonyCms
 
Introduction to QML
Introduction to QMLIntroduction to QML
Introduction to QML
Alan Uthoff
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI development
ICS
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
Aniruddha Chakrabarti
 
모던 C++ 정리
모던 C++ 정리모던 C++ 정리
모던 C++ 정리
Hansol Kang
 
Kubernetes #2 monitoring
Kubernetes #2   monitoring Kubernetes #2   monitoring
Kubernetes #2 monitoring
Terry Cho
 
송창규, unity build로 빌드타임 반토막내기, NDC2010
송창규, unity build로 빌드타임 반토막내기, NDC2010송창규, unity build로 빌드타임 반토막내기, NDC2010
송창규, unity build로 빌드타임 반토막내기, NDC2010devCAT Studio, NEXON
 
전형규, 가성비 좋은 렌더링 테크닉 10선, NDC2012
전형규, 가성비 좋은 렌더링 테크닉 10선, NDC2012전형규, 가성비 좋은 렌더링 테크닉 10선, NDC2012
전형규, 가성비 좋은 렌더링 테크닉 10선, NDC2012devCAT Studio, NEXON
 
Hook me UP ( React Hooks Introduction)
Hook me UP ( React Hooks Introduction)Hook me UP ( React Hooks Introduction)
Hook me UP ( React Hooks Introduction)
Carlos Mafla
 
UI아트 작업자를 위한 언리얼엔진4 UMG #1
UI아트 작업자를 위한 언리얼엔진4 UMG #1UI아트 작업자를 위한 언리얼엔진4 UMG #1
UI아트 작업자를 위한 언리얼엔진4 UMG #1
Hong-Gi Joe
 
Umg ,이벤트 바인딩, Invaidation Box
Umg ,이벤트 바인딩, Invaidation BoxUmg ,이벤트 바인딩, Invaidation Box
Umg ,이벤트 바인딩, Invaidation Box
대영 노
 

What's hot (20)

유니티 + Nodejs를 활용한 멀티플레이어 게임 개발하기
유니티 + Nodejs를 활용한 멀티플레이어 게임 개발하기유니티 + Nodejs를 활용한 멀티플레이어 게임 개발하기
유니티 + Nodejs를 활용한 멀티플레이어 게임 개발하기
 
Qt test framework
Qt test frameworkQt test framework
Qt test framework
 
도커 무작정 따라하기: 도커가 처음인 사람도 60분이면 웹 서버를 올릴 수 있습니다!
도커 무작정 따라하기: 도커가 처음인 사람도 60분이면 웹 서버를 올릴 수 있습니다!도커 무작정 따라하기: 도커가 처음인 사람도 60분이면 웹 서버를 올릴 수 있습니다!
도커 무작정 따라하기: 도커가 처음인 사람도 60분이면 웹 서버를 올릴 수 있습니다!
 
Gaming on AWS - 1. AWS로 글로벌 게임 런칭하기 - 장르별 아키텍처 중심
Gaming on AWS - 1. AWS로 글로벌 게임 런칭하기 - 장르별 아키텍처 중심Gaming on AWS - 1. AWS로 글로벌 게임 런칭하기 - 장르별 아키텍처 중심
Gaming on AWS - 1. AWS로 글로벌 게임 런칭하기 - 장르별 아키텍처 중심
 
[IGC2018] 청강대 이득우 - 언리얼에디터확장을위해알아야할것들
[IGC2018] 청강대 이득우 - 언리얼에디터확장을위해알아야할것들[IGC2018] 청강대 이득우 - 언리얼에디터확장을위해알아야할것들
[IGC2018] 청강대 이득우 - 언리얼에디터확장을위해알아야할것들
 
Qt and QML performance tips & tricks for Qt 4.7
Qt and QML performance tips & tricks for Qt 4.7Qt and QML performance tips & tricks for Qt 4.7
Qt and QML performance tips & tricks for Qt 4.7
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part III
 
Qt for Python
Qt for PythonQt for Python
Qt for Python
 
그럴듯한 랜덤 생성 컨텐츠 만들기
그럴듯한 랜덤 생성 컨텐츠 만들기그럴듯한 랜덤 생성 컨텐츠 만들기
그럴듯한 랜덤 생성 컨텐츠 만들기
 
GameInstance에 대해서 알아보자
GameInstance에 대해서 알아보자GameInstance에 대해서 알아보자
GameInstance에 대해서 알아보자
 
Introduction to QML
Introduction to QMLIntroduction to QML
Introduction to QML
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI development
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
모던 C++ 정리
모던 C++ 정리모던 C++ 정리
모던 C++ 정리
 
Kubernetes #2 monitoring
Kubernetes #2   monitoring Kubernetes #2   monitoring
Kubernetes #2 monitoring
 
송창규, unity build로 빌드타임 반토막내기, NDC2010
송창규, unity build로 빌드타임 반토막내기, NDC2010송창규, unity build로 빌드타임 반토막내기, NDC2010
송창규, unity build로 빌드타임 반토막내기, NDC2010
 
전형규, 가성비 좋은 렌더링 테크닉 10선, NDC2012
전형규, 가성비 좋은 렌더링 테크닉 10선, NDC2012전형규, 가성비 좋은 렌더링 테크닉 10선, NDC2012
전형규, 가성비 좋은 렌더링 테크닉 10선, NDC2012
 
Hook me UP ( React Hooks Introduction)
Hook me UP ( React Hooks Introduction)Hook me UP ( React Hooks Introduction)
Hook me UP ( React Hooks Introduction)
 
UI아트 작업자를 위한 언리얼엔진4 UMG #1
UI아트 작업자를 위한 언리얼엔진4 UMG #1UI아트 작업자를 위한 언리얼엔진4 UMG #1
UI아트 작업자를 위한 언리얼엔진4 UMG #1
 
Umg ,이벤트 바인딩, Invaidation Box
Umg ,이벤트 바인딩, Invaidation BoxUmg ,이벤트 바인딩, Invaidation Box
Umg ,이벤트 바인딩, Invaidation Box
 

Viewers also liked

Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2
NokiaAppForum
 
Multi Touch And Gesture Event Interface And Types
Multi Touch And Gesture Event Interface And TypesMulti Touch And Gesture Event Interface And Types
Multi Touch And Gesture Event Interface And Types
Ethan Cha
 
Qt Licensing Explained
Qt Licensing ExplainedQt Licensing Explained
Qt Licensing Explained
account inactive
 
Qt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickQt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt Quick
ICS
 
Conseil ue 31 03 full text
Conseil ue 31 03 full textConseil ue 31 03 full text
Conseil ue 31 03 full text
Daniel BASTIEN
 
MECHANICAL & THERMAL PROPERTIES OF NANO COMPOSITES
MECHANICAL & THERMAL PROPERTIES OF NANO COMPOSITESMECHANICAL & THERMAL PROPERTIES OF NANO COMPOSITES
MECHANICAL & THERMAL PROPERTIES OF NANO COMPOSITES
Arjun K Gopi
 
PyQtではじめるGUIプログラミング
PyQtではじめるGUIプログラミングPyQtではじめるGUIプログラミング
PyQtではじめるGUIプログラミング
Ransui Iso
 

Viewers also liked (7)

Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2
 
Multi Touch And Gesture Event Interface And Types
Multi Touch And Gesture Event Interface And TypesMulti Touch And Gesture Event Interface And Types
Multi Touch And Gesture Event Interface And Types
 
Qt Licensing Explained
Qt Licensing ExplainedQt Licensing Explained
Qt Licensing Explained
 
Qt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickQt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt Quick
 
Conseil ue 31 03 full text
Conseil ue 31 03 full textConseil ue 31 03 full text
Conseil ue 31 03 full text
 
MECHANICAL & THERMAL PROPERTIES OF NANO COMPOSITES
MECHANICAL & THERMAL PROPERTIES OF NANO COMPOSITESMECHANICAL & THERMAL PROPERTIES OF NANO COMPOSITES
MECHANICAL & THERMAL PROPERTIES OF NANO COMPOSITES
 
PyQtではじめるGUIプログラミング
PyQtではじめるGUIプログラミングPyQtではじめるGUIプログラミング
PyQtではじめるGUIプログラミング
 

Similar to Using Multi-Touch and Gestures with Qt

Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1
NokiaAppForum
 
Using multitouch and sensors in Java
Using multitouch and sensors in JavaUsing multitouch and sensors in Java
Using multitouch and sensors in JavaIntel Software Brasil
 
Qt State Machine Framework
Qt State Machine FrameworkQt State Machine Framework
Qt State Machine Framework
account inactive
 
Awt event
Awt eventAwt event
Awt event
Vijay Kumar
 
Input and Interaction
Input and InteractionInput and Interaction
Input and Interaction
Syed Zaid Irshad
 
Delegateless Coordinator
Delegateless CoordinatorDelegateless Coordinator
Delegateless Coordinator
Tales Andrade
 
The Future of Qt Widgets
The Future of Qt WidgetsThe Future of Qt Widgets
The Future of Qt Widgets
account inactive
 
The Future of Qt Widgets
The Future of Qt WidgetsThe Future of Qt Widgets
The Future of Qt Widgets
Marius Bugge Monsen
 
Qt Widget In-Depth
Qt Widget In-DepthQt Widget In-Depth
Qt Widget In-Depth
account inactive
 
Meet the Widgets: Another Way to Implement UI
Meet the Widgets: Another Way to Implement UIMeet the Widgets: Another Way to Implement UI
Meet the Widgets: Another Way to Implement UI
ICS
 
Android Develpment vol. 2, MFF UK, 2015
Android Develpment vol. 2, MFF UK, 2015Android Develpment vol. 2, MFF UK, 2015
Android Develpment vol. 2, MFF UK, 2015
Tomáš Kypta
 
PROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part IIPROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part II
SivaSankari36
 
Advance ui development and design
Advance ui  development and design Advance ui  development and design
Advance ui development and design
Rakesh Jha
 
Porting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - WebinarPorting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - Webinar
Janel Heilbrunn
 
Porting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - WebinarPorting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - Webinar
ICS
 
Multi Touch presentation
Multi Touch presentationMulti Touch presentation
Multi Touch presentationsenthil0809
 
09events
09events09events
09events
Waheed Warraich
 

Similar to Using Multi-Touch and Gestures with Qt (20)

Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1
 
Java-Events
Java-EventsJava-Events
Java-Events
 
Using multitouch and sensors in Java
Using multitouch and sensors in JavaUsing multitouch and sensors in Java
Using multitouch and sensors in Java
 
Qt State Machine Framework
Qt State Machine FrameworkQt State Machine Framework
Qt State Machine Framework
 
Awt event
Awt eventAwt event
Awt event
 
Input and Interaction
Input and InteractionInput and Interaction
Input and Interaction
 
Delegateless Coordinator
Delegateless CoordinatorDelegateless Coordinator
Delegateless Coordinator
 
The Future of Qt Widgets
The Future of Qt WidgetsThe Future of Qt Widgets
The Future of Qt Widgets
 
The Future of Qt Widgets
The Future of Qt WidgetsThe Future of Qt Widgets
The Future of Qt Widgets
 
Qt Widget In-Depth
Qt Widget In-DepthQt Widget In-Depth
Qt Widget In-Depth
 
Qt Widgets In Depth
Qt Widgets In DepthQt Widgets In Depth
Qt Widgets In Depth
 
Meet the Widgets: Another Way to Implement UI
Meet the Widgets: Another Way to Implement UIMeet the Widgets: Another Way to Implement UI
Meet the Widgets: Another Way to Implement UI
 
Android Develpment vol. 2, MFF UK, 2015
Android Develpment vol. 2, MFF UK, 2015Android Develpment vol. 2, MFF UK, 2015
Android Develpment vol. 2, MFF UK, 2015
 
PROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part IIPROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part II
 
Dacj 2-2 b
Dacj 2-2 bDacj 2-2 b
Dacj 2-2 b
 
Advance ui development and design
Advance ui  development and design Advance ui  development and design
Advance ui development and design
 
Porting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - WebinarPorting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - Webinar
 
Porting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - WebinarPorting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - Webinar
 
Multi Touch presentation
Multi Touch presentationMulti Touch presentation
Multi Touch presentation
 
09events
09events09events
09events
 

More from account inactive

Meet Qt
Meet QtMeet Qt
KDE Plasma for Mobile Phones
KDE Plasma for Mobile PhonesKDE Plasma for Mobile Phones
KDE Plasma for Mobile Phones
account inactive
 
Shipping Mobile Applications Using Qt for Symbian
Shipping Mobile Applications Using Qt for SymbianShipping Mobile Applications Using Qt for Symbian
Shipping Mobile Applications Using Qt for Symbian
account inactive
 
Scripting Your Qt Application
Scripting Your Qt ApplicationScripting Your Qt Application
Scripting Your Qt Application
account inactive
 
Special Effects with Qt Graphics View
Special Effects with Qt Graphics ViewSpecial Effects with Qt Graphics View
Special Effects with Qt Graphics View
account inactive
 
Developments in The Qt WebKit Integration
Developments in The Qt WebKit IntegrationDevelopments in The Qt WebKit Integration
Developments in The Qt WebKit Integration
account inactive
 
Qt Kwan-Do
Qt Kwan-DoQt Kwan-Do
Qt Kwan-Do
account inactive
 
Qt on Real Time Operating Systems
Qt on Real Time Operating SystemsQt on Real Time Operating Systems
Qt on Real Time Operating Systems
account inactive
 
Development with Qt for Windows CE
Development with Qt for Windows CEDevelopment with Qt for Windows CE
Development with Qt for Windows CE
account inactive
 
Translating Qt Applications
Translating Qt ApplicationsTranslating Qt Applications
Translating Qt Applications
account inactive
 
Qt Creator Bootcamp
Qt Creator BootcampQt Creator Bootcamp
Qt Creator Bootcamp
account inactive
 
Mobile Development with Qt for Symbian
Mobile Development with Qt for SymbianMobile Development with Qt for Symbian
Mobile Development with Qt for Symbian
account inactive
 
How to Make Your Qt App Look Native
How to Make Your Qt App Look NativeHow to Make Your Qt App Look Native
How to Make Your Qt App Look Native
account inactive
 
Animation Framework: A Step Towards Modern UIs
Animation Framework: A Step Towards Modern UIsAnimation Framework: A Step Towards Modern UIs
Animation Framework: A Step Towards Modern UIs
account inactive
 
Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)
Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)
Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)
account inactive
 
The Mobility Project
The Mobility ProjectThe Mobility Project
The Mobility Project
account inactive
 
Copy Your Favourite Nokia App with Qt
Copy Your Favourite Nokia App with QtCopy Your Favourite Nokia App with Qt
Copy Your Favourite Nokia App with Qt
account inactive
 
The Next Generation Qt Item Views
The Next Generation Qt Item ViewsThe Next Generation Qt Item Views
The Next Generation Qt Item Views
account inactive
 
Optimizing Performance in Qt-Based Applications
Optimizing Performance in Qt-Based ApplicationsOptimizing Performance in Qt-Based Applications
Optimizing Performance in Qt-Based Applications
account inactive
 
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization SoftwareCase Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
account inactive
 

More from account inactive (20)

Meet Qt
Meet QtMeet Qt
Meet Qt
 
KDE Plasma for Mobile Phones
KDE Plasma for Mobile PhonesKDE Plasma for Mobile Phones
KDE Plasma for Mobile Phones
 
Shipping Mobile Applications Using Qt for Symbian
Shipping Mobile Applications Using Qt for SymbianShipping Mobile Applications Using Qt for Symbian
Shipping Mobile Applications Using Qt for Symbian
 
Scripting Your Qt Application
Scripting Your Qt ApplicationScripting Your Qt Application
Scripting Your Qt Application
 
Special Effects with Qt Graphics View
Special Effects with Qt Graphics ViewSpecial Effects with Qt Graphics View
Special Effects with Qt Graphics View
 
Developments in The Qt WebKit Integration
Developments in The Qt WebKit IntegrationDevelopments in The Qt WebKit Integration
Developments in The Qt WebKit Integration
 
Qt Kwan-Do
Qt Kwan-DoQt Kwan-Do
Qt Kwan-Do
 
Qt on Real Time Operating Systems
Qt on Real Time Operating SystemsQt on Real Time Operating Systems
Qt on Real Time Operating Systems
 
Development with Qt for Windows CE
Development with Qt for Windows CEDevelopment with Qt for Windows CE
Development with Qt for Windows CE
 
Translating Qt Applications
Translating Qt ApplicationsTranslating Qt Applications
Translating Qt Applications
 
Qt Creator Bootcamp
Qt Creator BootcampQt Creator Bootcamp
Qt Creator Bootcamp
 
Mobile Development with Qt for Symbian
Mobile Development with Qt for SymbianMobile Development with Qt for Symbian
Mobile Development with Qt for Symbian
 
How to Make Your Qt App Look Native
How to Make Your Qt App Look NativeHow to Make Your Qt App Look Native
How to Make Your Qt App Look Native
 
Animation Framework: A Step Towards Modern UIs
Animation Framework: A Step Towards Modern UIsAnimation Framework: A Step Towards Modern UIs
Animation Framework: A Step Towards Modern UIs
 
Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)
Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)
Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)
 
The Mobility Project
The Mobility ProjectThe Mobility Project
The Mobility Project
 
Copy Your Favourite Nokia App with Qt
Copy Your Favourite Nokia App with QtCopy Your Favourite Nokia App with Qt
Copy Your Favourite Nokia App with Qt
 
The Next Generation Qt Item Views
The Next Generation Qt Item ViewsThe Next Generation Qt Item Views
The Next Generation Qt Item Views
 
Optimizing Performance in Qt-Based Applications
Optimizing Performance in Qt-Based ApplicationsOptimizing Performance in Qt-Based Applications
Optimizing Performance in Qt-Based Applications
 
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization SoftwareCase Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
 

Recently uploaded

PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 

Recently uploaded (20)

PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 

Using Multi-Touch and Gestures with Qt

  • 1. Using Multi-Touch and Gestures with Qt 10/09/09 Jens Bache-Wiig
  • 2. Introduction Jens Bache-Wiig •  Worked on Qt since 2005 •  Platform Team •  Interim Widget Pimp 2
  • 5. Concepts What do we mean when we say multi-touch? 5
  • 6. Concepts A widget reacts to multiple touch-points For example, to zoom/scale content... Lorem ipsum dolor sit  Lorem ipsum dolor  eamt. Dolore magna  aliquam erat volupat. Ut  sit eamt. Dolore  enim ad minimum  magna aliquam  veniami quis. Duis sutem  vel eum irure dolor in  erat volupat...cvc  rerit laputum  6
  • 7. Concepts Multiple widgets react to multiple touch-points For example, moving several sliders at once... 7
  • 8. Concepts Real life is multi-touch Do you open a bottle with one finger? Applications could do it too... 1 2 8
  • 10. Concepts Sony Pictures © 2009  10
  • 12. Concepts What do we mean when we say gestures? 12
  • 13. Concepts A way to make common multi-touch use-cases easy to use in your application • Standard, platform-specific touch-based gestures • Extensible API for custom gestures 13
  • 14. Concepts What are standard gestures? •  Built-in multi-touch gestures that work in standard Qt widgets 14
  • 15. Concepts Pan gesture •  Scrolls content •  Works in all scrollable Qt widgets Lorem ipsum dolor sit Ut enim ad minimum  eamt. Dolore magna veniami quis. Duis sutem  aliquam erat volupat. vel eum irure dolor in  Ut enim ad minimum rerit laputum  veniami quis. Duis sutem vel eum irure dolor in rerit laputum 15
  • 18. API Multi-touch •  New event types •  TouchBegin •  TouchUpdate •  TouchEnd •  New QTouchEvent class •  QWidget and QGraphicsItem API 18
  • 19. API QEvent::TouchBegin •  First in sequence •  Must be accepted to receive following events 19
  • 20. API QEvent::TouchUpdate •  Normal event indicating activity •  Expect more events to follow 20
  • 21. API QEvent::TouchEnd •  Final event in sequence •  No more events without a new TouchBegin 21
  • 22. API TouchBegin propagation •  When ignored, propagate to widget under first touch- point •  Widgets never receive multiple TouchBegin •  New touch-points on children are combined with first touch-point 1 1 2 One event, one point, to grey widget  One event, two points, to grey widget  22
  • 23. API TouchUpdate, TouchEnd do not propagate 23
  • 24. API QTouchEvent •  Event class for QWidget and QGraphicsItem •  Contains list of active touch points •  Device type – TouchScreen or TouchPad 24
  • 25. API QTouchEvent::TouchPoint •  Information about one touch-point •  Integer identifier •  Primary touch-point flag •  State - Pressed, Moved, Stationary, or Released •  Current, previous, starting positions •  Local, scene, screen, normalized translations •  Area, pressure (if supported by device) 25
  • 26. API Touch events are not sent by default •  Must be enabled first •  When enabled, TouchBegin event will be accepted unless explicitly ignored 26
  • 27. API Qt::WA_AcceptsTouchEvents •  Set on QWidget to receive touch events •  To handle events, reimplement QWidget::event() •  Default implementation emulates mouse events for first non-primary touch-point •  Set on viewport() of QAbstractScrollArea based widgets •  To handle events, reimplement QAbstractScrollArea::viewportEvent() 27
  • 28. API QGraphicsItem::setAcceptsTouchEvents(bool) •  Set to true on item to receive touch events •  To handle, reimplement QGraphicsItem::sceneEvent() •  No default implementation 28
  • 29. API Gestures •  QGesture and QGestureRecognizer classes •  Widgets subscribe to gestures •  Using standard gestures •  Implementing custom gestures 29
  • 30. API QGesture •  Base class for more complex gestures •  Basic properties and convenience functions •  Delivered to QWidget or QGraphicsObject •  State (Started, Updated, Finished, Canceled) QGestureEvent •  Contains a list of QGestures •  Normal event propagation rules apply 30
  • 31. API QGestureRecognizer •  “Just” an event filter + state machine •  Registered in QApplication •  Announces when a gesture is triggered 31
  • 32. API How do I use a gesture? •  Use grabGesture() to request it •  Handle the QGestureEvent and get: QPanGesture -  Offset property QPinchGesture -  Center-point, rotation, scale properties 32
  • 33. API Implementing custom gestures •  Create a state machine: - subclass QGestureRecognizer - implement filterEvent(), createGesture(), reset() •  Create a gesture object: - subclass QGesture (optional) - fill QGesture with properties 33
  • 34. API Gestures can be simple : Four finger tap class FourFingerTapGesture : public QGestureRecognizer { virtual Result filterEvent(QGesture *, QObject *, QEvent *event) { if (event->type() == QEvent::TouchUpdate) if (static_cast<QTouchEvent *>(event)->touchPoints.size() == 4) return GestureFinished; return Ignore; } }; 34
  • 35. API Gestures can be complex •  Event filter could implement a state machine •  Continuous gesture going through Qt::GestureStated to Qt::GestureUpdated to Qt::GestureFinished states. •  Gesture may need to hijack events, store them, and replay them later 35
  • 36. API Special considerations when implementing and/ or using gestures 36
  • 37. API Single gesture on parent widget with children •  Should the parent's gesture filter events for children? GestureContext •  widget-only gesture •  widget-with-children gesture 37
  • 38. API Multiple gestures on a single widget •  All gestures filter incoming events in undefined order •  Ignored gestures will be propagated •  You can partially ignore a gesture: bool gestureEvent(QGestureEvent *event) { event->ignore(Qt::PanGesture); event->accept(Qt::PinchGesture); return true; } 38
  • 39. API Gesture has priority over normal event handling •  Gesture may need several events before starting •  Normal event handling interferes with gesture •  Events should be delayed 39
  • 41. API ITAI: PictureBlue by Ariel Molina h$p://vimeo.com/4990545  41
  • 42. Examples Using QTouchEvent... MyWidget::MyWidget(QWidget *parent) { setAttribute(Qt::WA_AcceptsTouchEvents); } 42
  • 43. Examples Using QTouchEvent... bool MyWidget::event(QEvent *e) { switch (e->type()) { case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: { // creative stuff here } } 43
  • 44. Examples Using QTouchEvent... QTouchEvent *te = static_cast<QTouchEvent *>(e); QList<QTouchEvent::TouchPoint> points = te->touchPoints(); if (touchPoints.count() == 2) { // Do something interesting here } 44
  • 45. Examples Using QTouchEvent... // determine scale factor QTouchEvent::TouchPoint p0 = touchPoints.first(); QTouchEvent::TouchPoint p1 = touchPoints.last(); QLineF line1(p0.startPos(), p1.startPos()); QLineF line2(p0.pos(), p1.pos()); qreal scaleFactor = line2.length() / line1.length(); setContentScale(scaleFactor); 45
  • 46. Examples Using QTouchEvent... // determine angle between previous and current pos QTouchEvent::TouchPoint p0 = touchPoints.first(); QTouchEvent::TouchPoint p1 = touchPoints.last(); QLineF line1(p0.lastPos(), p1.lastPos()); QLineF line2(p0.pos(), p1.pos()); qreal angle = line2.angleTo(line1); rotateContentBy(angle); 46
  • 48. Examples Custom gesture – four finger tap class FourFingerTapGesture : public QGestureRecognizer { virtual QGesture createGesture(QObject *) { return new QGesture(“FourFingerTap”); } } virtual Result filterEvent(QGesture *state, QObject *, QEvent *event) { if (event->type() == QEvent::TouchUpdate) if (static_cast<QTouchEvent *>(event)->touchPoints.size() == 4) { state->setProperty(“foo”, QLatin1String(“bar”)); return GestureFinished; } return Ignore; } }; 48
  • 49. Examples Custom gesture – four finger tap class Label : public QLabel { virtual void gestureEvent(QGestureEvent *event) { if (QGesture *g = event->gesture(“FourFingerTap”)) { setText(g->property(“foo”)); event->accept(g); } ... QLabel *label = new Qlabel; label->setPixmap(QPixmap(“qt-logo.png”)); label->grabGesture(“FourFingerTap”); 49