[Qt-interest] Do gestures work on symbian platform?
Dmitry Teslenko
dteslenko at gmail.com
Thu Sep 29 08:39:58 CEST 2011
Hello!
What's state of gestures on symbian paltform in Qt 4.7.3?
Either they are not working either there's something missing in docs
here:
http://doc.qt.nokia.com/latest/gestures-overview.html
Documents states that gesture recogintion can be made with QWidget or
QGraphicsObject. Down there's compileable example of a second approach.
Please point out that's missing. Because this app doesn't recognize
swype and pan. It recognizes pinch from time to time.
#include <QtGui>
class GestureObject : public QGraphicsObject {
public:
GestureObject();
virtual QRectF boundingRect() const;
virtual void paint(QPainter *painter, const
QStyleOptionGraphicsItem *option, QWidget *widget);
virtual QPainterPath shape() const;
virtual bool sceneEvent(QEvent *);
bool gestureEvent(QGestureEvent *);
protected:
private:
QColor m_color;
};
bool GestureObject::gestureEvent(QGestureEvent *event) {
QGesture *gesture = event->gesture(Qt::SwipeGesture);
if(gesture) {
QSwipeGesture *swipeGesture =
static_cast<QSwipeGesture *>(gesture);
if(swipeGesture && swipeGesture->state() ==
Qt::GestureFinished) {
switch(swipeGesture->horizontalDirection()) {
case QSwipeGesture::Left:
m_color = QColor("green");
update();
break;
case QSwipeGesture::Right:
m_color = QColor("blue");
update();
break;
default :
break;
}
}
}
gesture = event->gesture(Qt::PanGesture);
if(gesture) {
QPanGesture *panGesture = static_cast<QPanGesture *>(gesture);
m_color = QColor("yellow");
update();
}
gesture = event->gesture(Qt::PinchGesture);
if(gesture) {
QPinchGesture *pinchGesture = static_cast<QPinchGesture *>(gesture);
m_color = QColor("grey");
update();
}
return true;
}
bool GestureObject::sceneEvent(QEvent *event) {
if (event->type() == QEvent::Gesture) {
return gestureEvent(static_cast<QGestureEvent*>(event));
}
return QGraphicsObject::sceneEvent(event);
}
GestureObject::GestureObject() : m_color(QColor("red")) {
setAcceptTouchEvents(true);
grabGesture(Qt::PanGesture);
grabGesture(Qt::PinchGesture);
grabGesture(Qt::SwipeGesture);
}
QRectF GestureObject::boundingRect() const {
return QRectF(QPointF(-150, -150), QPointF(150, 150));
}
void GestureObject::paint(QPainter *painter, const
QStyleOptionGraphicsItem *option, QWidget *widget) {
painter->setBrush(m_color);
painter->drawRect(boundingRect());
}
QPainterPath GestureObject::shape() const {
QPainterPath path;
path.addRect(boundingRect());
return path;
}
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QGraphicsScene scene;
GestureObject *object = new GestureObject;
scene.addItem(object);
QGraphicsView view(&scene);
view.showFullScreen();
return app.exec();
}
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
More information about the Qt-interest-old
mailing list