summaryrefslogtreecommitdiffstats
path: root/examples/gestures
diff options
context:
space:
mode:
authorDavid Boddie <dboddie@trolltech.com>2009-10-13 17:20:40 (GMT)
committerDavid Boddie <dboddie@trolltech.com>2009-10-16 15:15:19 (GMT)
commit0266b3d62eb9f091c93dc6b2c59eaad0f64ddedc (patch)
treede3da46df6b0086a7228c174c7963d9b30e165cb /examples/gestures
parent06d1c12c24c38b0cd8822b1faf2694c7331f75cb (diff)
downloadQt-0266b3d62eb9f091c93dc6b2c59eaad0f64ddedc.zip
Qt-0266b3d62eb9f091c93dc6b2c59eaad0f64ddedc.tar.gz
Qt-0266b3d62eb9f091c93dc6b2c59eaad0f64ddedc.tar.bz2
Doc: Gesture API documentation review and improvements.
Reviewed-by: Trust Me
Diffstat (limited to 'examples/gestures')
-rw-r--r--examples/gestures/imageviewer/imageviewer.pro8
-rw-r--r--examples/gestures/imageviewer/imagewidget.cpp10
-rw-r--r--examples/gestures/imageviewer/main.cpp33
-rw-r--r--examples/gestures/imageviewer/mainwidget.cpp56
-rw-r--r--examples/gestures/imageviewer/mainwidget.h63
5 files changed, 133 insertions, 37 deletions
diff --git a/examples/gestures/imageviewer/imageviewer.pro b/examples/gestures/imageviewer/imageviewer.pro
index 68c1f1c..7780ad9 100644
--- a/examples/gestures/imageviewer/imageviewer.pro
+++ b/examples/gestures/imageviewer/imageviewer.pro
@@ -1,6 +1,8 @@
-HEADERS += imagewidget.h
-SOURCES += imagewidget.cpp \
- main.cpp
+HEADERS = imagewidget.h \
+ mainwidget.h
+SOURCES = imagewidget.cpp \
+ main.cpp \
+ mainwidget.cpp
# install
target.path = $$[QT_INSTALL_EXAMPLES]/gestures/imageviewer
diff --git a/examples/gestures/imageviewer/imagewidget.cpp b/examples/gestures/imageviewer/imagewidget.cpp
index f3fd8e4..c4a4e50 100644
--- a/examples/gestures/imageviewer/imagewidget.cpp
+++ b/examples/gestures/imageviewer/imagewidget.cpp
@@ -59,17 +59,21 @@ ImageWidget::ImageWidget(QWidget *parent)
setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_NoSystemBackground);
+//! [enable gestures]
grabGesture(Qt::PanGesture);
grabGesture(Qt::PinchGesture);
grabGesture(Qt::SwipeGesture);
+//! [enable gestures]
}
+//! [event handler]
bool ImageWidget::event(QEvent *event)
{
if (event->type() == QEvent::Gesture)
return gestureEvent(static_cast<QGestureEvent*>(event));
return QWidget::event(event);
}
+//! [event handler]
void ImageWidget::paintEvent(QPaintEvent*)
{
@@ -98,6 +102,7 @@ void ImageWidget::mouseDoubleClickEvent(QMouseEvent *)
update();
}
+//! [gesture event handler]
bool ImageWidget::gestureEvent(QGestureEvent *event)
{
if (QGesture *pan = event->gesture(Qt::PanGesture)) {
@@ -112,6 +117,7 @@ bool ImageWidget::gestureEvent(QGestureEvent *event)
}
return false;
}
+//! [gesture event handler]
void ImageWidget::panTriggered(QPanGesture *gesture)
{
@@ -147,7 +153,7 @@ void ImageWidget::pinchTriggered(QPinchGesture *gesture)
update();
}
-//! [swipe slot]
+//! [swipe function]
void ImageWidget::swipeTriggered(QSwipeGesture *gesture)
{
if (gesture->horizontalDirection() == QSwipeGesture::Left
@@ -157,7 +163,7 @@ void ImageWidget::swipeTriggered(QSwipeGesture *gesture)
goNextImage();
update();
}
-//! [swipe slot]
+//! [swipe function]
void ImageWidget::resizeEvent(QResizeEvent*)
{
diff --git a/examples/gestures/imageviewer/main.cpp b/examples/gestures/imageviewer/main.cpp
index c3d03f3..9c99f31 100644
--- a/examples/gestures/imageviewer/main.cpp
+++ b/examples/gestures/imageviewer/main.cpp
@@ -41,36 +41,7 @@
#include <QtGui>
-#include "imagewidget.h"
-
-class MainWidget : public QMainWindow
-{
- Q_OBJECT
-
-public:
- MainWidget(QWidget *parent = 0);
-
-public slots:
- void openDirectory(const QString &path);
-
-private:
- bool loadImage(const QString &fileName);
-
- ImageWidget *imageWidget;
-};
-
-MainWidget::MainWidget(QWidget *parent)
- : QMainWindow(parent)
-{
- resize(400, 300);
- imageWidget = new ImageWidget(this);
- setCentralWidget(imageWidget);
-}
-
-void MainWidget::openDirectory(const QString &path)
-{
- imageWidget->openDirectory(path);
-}
+#include "mainwidget.h"
int main(int argc, char *argv[])
{
@@ -86,5 +57,3 @@ int main(int argc, char *argv[])
return app.exec();
}
-
-#include "main.moc"
diff --git a/examples/gestures/imageviewer/mainwidget.cpp b/examples/gestures/imageviewer/mainwidget.cpp
new file mode 100644
index 0000000..51e9f1e
--- /dev/null
+++ b/examples/gestures/imageviewer/mainwidget.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "imagewidget.h"
+#include "mainwidget.h"
+
+MainWidget::MainWidget(QWidget *parent)
+ : QMainWindow(parent)
+{
+ resize(400, 300);
+ imageWidget = new ImageWidget(this);
+ setCentralWidget(imageWidget);
+}
+
+void MainWidget::openDirectory(const QString &path)
+{
+ imageWidget->openDirectory(path);
+}
diff --git a/examples/gestures/imageviewer/mainwidget.h b/examples/gestures/imageviewer/mainwidget.h
new file mode 100644
index 0000000..1a99155
--- /dev/null
+++ b/examples/gestures/imageviewer/mainwidget.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWIDGET_H
+#define MAINWIDGET_H
+
+#include <QMainWindow>
+
+class MainWidget : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWidget(QWidget *parent = 0);
+
+public slots:
+ void openDirectory(const QString &path);
+
+private:
+ bool loadImage(const QString &fileName);
+
+ ImageWidget *imageWidget;
+};
+
+#endif