when resizing/rotating with multitouch, spply a transform, resize to the proper size only at touch end event

svn path=/trunk/KDE/kdelibs/; revision=1053705
This commit is contained in:
Marco Martin 2009-11-24 16:26:28 +00:00
parent dc295eca70
commit a045136fe0

View File

@ -734,9 +734,27 @@ void AppletHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
bool AppletHandle::sceneEvent(QEvent *event) bool AppletHandle::sceneEvent(QEvent *event)
{ {
switch (event->type()) { switch (event->type()) {
case QEvent::TouchEnd: {
QTransform t = m_applet->transform();
QRectF geom = m_applet->geometry();
QPointF translation(t.m31(), t.m32());
QPointF center = geom.center();
geom.setWidth(geom.width()*qAbs(t.m11()));
geom.setHeight(geom.height()*qAbs(t.m22()));
geom.moveCenter(center);
m_applet->setGeometry(geom);
t.reset();
t.translate(m_applet->size().width()/2, m_applet->size().height()/2);
t.rotateRadians(m_angle);
t.translate(-m_applet->size().width()/2, -m_applet->size().height()/2);
m_applet->setTransform(t);
return true;
}
case QEvent::TouchBegin: case QEvent::TouchBegin:
case QEvent::TouchUpdate: case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{ {
QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints(); QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
if (touchPoints.count() == 2) { if (touchPoints.count() == 2) {
@ -746,28 +764,21 @@ bool AppletHandle::sceneEvent(QEvent *event)
//rotation //rotation
QLineF line0(touchPoint0.lastScenePos(), touchPoint1.lastScenePos()); QLineF line0(touchPoint0.lastScenePos(), touchPoint1.lastScenePos());
QLineF line1(touchPoint0.scenePos(), touchPoint1.scenePos()); QLineF line1(touchPoint0.scenePos(), touchPoint1.scenePos());
//m_applet->setTransformOriginPoint(m_applet->boundingRect().center()); m_angle = m_angle+(line1.angleTo(line0)*M_PI_2/90);
m_angle = m_applet->rotation()+line1.angleTo(line0);
//m_applet->setRotation(m_angle);
//m_applet->setTransformOriginPoint(QPointF(0,0));
QTransform t = m_applet->transform(); QTransform t = m_applet->transform();
t.translate(m_applet->size().width()/2, m_applet->size().height()/2); t.translate(m_applet->size().width()/2, m_applet->size().height()/2);
t.rotate(m_angle); t.rotate(line1.angleTo(line0));
t.translate(-m_applet->size().width()/2, -m_applet->size().height()/2);
m_applet->setTransform(t);
//scaling //scaling
qreal scaleFactor = 1; qreal scaleFactor = 1;
if (line0.length() > 0) { if (line0.length() > 0) {
scaleFactor = line1.length() / line0.length(); scaleFactor = line1.length() / line0.length();
} }
QRectF geom = m_applet->geometry();
QPointF oldCenter(geom.center()); t.scale(scaleFactor, scaleFactor);
geom.setWidth(geom.width()*scaleFactor); t.translate(-m_applet->size().width()/2, -m_applet->size().height()/2);
geom.setHeight(geom.height()*scaleFactor); m_applet->setTransform(t);
geom.moveCenter(oldCenter);
m_applet->setGeometry(geom);
} }
return true; return true;
} }