From 49882297708ce0d3e817334b8ef937ef3fd9bd0c Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Sat, 14 Nov 2009 17:33:00 +0000 Subject: [PATCH] support for touchEvents svn path=/trunk/KDE/kdelibs/; revision=1049191 --- private/applethandle.cpp | 47 ++++++++++++++++++++++++++++++++++++++++ private/applethandle_p.h | 1 + 2 files changed, 48 insertions(+) diff --git a/private/applethandle.cpp b/private/applethandle.cpp index 5e2dec937..b3282223e 100644 --- a/private/applethandle.cpp +++ b/private/applethandle.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -71,6 +72,7 @@ AppletHandle::AppletHandle(Containment *parent, Applet *applet, const QPointF &h setFlags(flags() | QGraphicsItem::ItemStacksBehindParent); KColorScheme colorScheme(QPalette::Active, KColorScheme::View, Theme::defaultTheme()->colorScheme()); + setAcceptTouchEvents(true); m_gradientColor = colorScheme.background(KColorScheme::NormalBackground).color(); m_originalGeom = m_applet->geometry(); m_originalTransform = m_applet->transform(); @@ -729,6 +731,51 @@ void AppletHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } } +bool AppletHandle::sceneEvent(QEvent *event) +{ + switch (event->type()) { + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: + { + QList touchPoints = static_cast(event)->touchPoints(); + if (touchPoints.count() == 2) { + const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first(); + const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last(); + + //rotation + QLineF line0(touchPoint0.lastScenePos(), touchPoint1.lastScenePos()); + QLineF line1(touchPoint0.scenePos(), touchPoint1.scenePos()); + //m_applet->setTransformOriginPoint(m_applet->boundingRect().center()); + m_angle = m_applet->rotation()+line1.angleTo(line0); + //m_applet->setRotation(m_angle); + //m_applet->setTransformOriginPoint(QPointF(0,0)); + QTransform t = m_applet->transform(); + t.translate(m_applet->size().width()/2, m_applet->size().height()/2); + t.rotate(m_angle); + t.translate(-m_applet->size().width()/2, -m_applet->size().height()/2); + m_applet->setTransform(t); + + + //scaling + qreal scaleFactor = 1; + if (line0.length() > 0) { + scaleFactor = line1.length() / line0.length(); + } + QRectF geom = m_applet->geometry(); + geom.setWidth(geom.width()*scaleFactor); + geom.setHeight(geom.height()*scaleFactor); + geom.moveCenter(line1.pointAt(0.5)); + m_applet->setGeometry(geom); + } + return true; + } + default: + break; + } + return QGraphicsItem::sceneEvent(event); +} + //pos relative to scene void AppletHandle::switchContainment(Containment *containment, const QPointF &pos) { diff --git a/private/applethandle_p.h b/private/applethandle_p.h index f98da263f..d91b9d5f9 100644 --- a/private/applethandle_p.h +++ b/private/applethandle_p.h @@ -78,6 +78,7 @@ class AppletHandle : public QGraphicsObject void hoverMoveEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); bool sceneEventFilter(QGraphicsItem *watched, QEvent *event); + bool sceneEvent(QEvent*); Q_SIGNALS: void disappearDone(AppletHandle *self);