From 4fab72a5eb19d34eb9b96a192fd901ddf7db2c92 Mon Sep 17 00:00:00 2001 From: Nico Vertriest Date: Thu, 12 Dec 2013 10:22:34 +0100 Subject: Doc: corrected broken links Links fixed: Extra Filters Basic Tools blockingfortuneclient Thread Support Drag and drop examples qBinaryFind qmake common project types imagegestures Task-number: QTBUG-34749 Change-Id: Ib93dda00716dc596db327fee5b97e110a9f27fa7 Reviewed-by: Martin Smith --- .../imagegestures/doc/src/imagegestures.qdoc | 100 +++++++++++++++++++++ examples/widgets/doc/src/plugandpaint.qdoc | 20 ++--- 2 files changed, 110 insertions(+), 10 deletions(-) create mode 100644 examples/gestures/imagegestures/doc/src/imagegestures.qdoc (limited to 'examples') diff --git a/examples/gestures/imagegestures/doc/src/imagegestures.qdoc b/examples/gestures/imagegestures/doc/src/imagegestures.qdoc new file mode 100644 index 0000000000..cb76ee83b1 --- /dev/null +++ b/examples/gestures/imagegestures/doc/src/imagegestures.qdoc @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example gestures/imagegestures + \title Image Gestures Example + + This example shows how to enable gestures for a widget and use gesture input + to perform actions. + + We use two classes to create the user interface for the application: \c MainWidget + and \c ImageWidget. The \c MainWidget class is simply used as a container for the + \c ImageWidget class, which we will configure to accept gesture input. Since we + are interested in the way gestures are used, we will concentrate on the + implementation of the \c ImageWidget class. + + \section1 ImageWidget Class Definition + + The \c ImageWidget class is a simple QWidget subclass that reimplements the general + QWidget::event() handler function in addition to several more specific event handlers: + + \snippet examples/gestures/imagegestures/imagewidget.h class definition begin + \dots + \snippet examples/gestures/imagegestures/imagewidget.h class definition end + + We also implement a private helper function, \c gestureEvent(), to help manage + gesture events delivered to the widget, and three functions to perform actions + based on gestures: \c panTriggered(), \c pinchTriggered() and \c swipeTriggered(). + + \section1 ImageWidget Class Implementation + + In the widget's constructor, we begin by setting up various parameters that will + be used to control the way images are displayed. + + \snippet examples/gestures/imagegestures/imagewidget.cpp constructor + + We enable three of the standard gestures for the widget by calling QWidget::grabGesture() + with the types of gesture we need. These will be recognized by the application's + default gesture recognizer, and events will be delivered to our widget. + + Since QWidget does not define a specific event handler for gestures, the widget + needs to reimplement the general QWidget::event() to receive gesture events. + + \snippet examples/gestures/imagegestures/imagewidget.cpp event handler + + We implement the event handler to delegate gesture events to a private function + specifically written for the task, and pass all other events to QWidget's + implementation. + + The \c gestureHandler() function examines the gestures supplied by the + newly-delivered QGestureEvent. Since only one gesture of a given type can be + used on a widget at any particular time, we can check for each gesture type + using the QGestureEvent::gesture() function: + + \snippet examples/gestures/imagegestures/imagewidget.cpp gesture event handler + + If a QGesture object is supplied for a certain type of gesture, we call a special + purpose function to deal with it, casting the gesture object to the appropriate + QGesture subclass. + + To illustrate how a standard gesture can be interpreted by an application, we + show the implementation of the \c swipeTriggered() function, which handles the + gesture associated with a brushing or swiping motion on the user's display or + input device: + + \snippet examples/gestures/imagegestures/imagewidget.cpp swipe function + + The QSwipeGesture class provides specialized functions and defines a enum + to make it more convenient for developers to discover which direction, if + any, the user swiped the display. Here, we simply navigate to the previous + image in the collection if the user swiped upwards or to the left; otherwise + we navigate to the next image in the collection. + + The other gestures are also handled by special purpose functions, but use + the values of properties held by the QGesture object passed to them. +*/ diff --git a/examples/widgets/doc/src/plugandpaint.qdoc b/examples/widgets/doc/src/plugandpaint.qdoc index bfb763b7d1..5098d892ef 100644 --- a/examples/widgets/doc/src/plugandpaint.qdoc +++ b/examples/widgets/doc/src/plugandpaint.qdoc @@ -47,9 +47,9 @@ If you want to learn how to make your own application extensible through plugins, we recommend that you start by reading this overview, which explains how to make an application use plugins. - Afterward, you can read the + Afterwards, you can read the \l{tools/plugandpaintplugins/basictools}{Basic Tools} and - \l{plugandpaintplugins/extrafilters}{Extra Filters} + \l{tools/plugandpaintplugins/extrafilters}{Extra Filters} overviews, which show how to implement static and dynamic plugins, respectively. @@ -126,8 +126,8 @@ a good idea to include a version number in the string, as we did above. - The \l{plugandpaintplugins/basictools}{Basic Tools} plugin - and the \l{plugandpaintplugins/extrafilters}{Extra Filters} + The \l{tools/plugandpaintplugins/basictools}{Basic Tools} plugin + and the \l{tools/plugandpaintplugins/extrafilters}{Extra Filters} plugin shows how to derive from \c BrushInterface, \c ShapeInterface, and \c FilterInterface. @@ -275,7 +275,7 @@ \section1 Importing Static Plugins - The \l{plugandpaintplugins/basictools}{Basic Tools} plugin + The \l{tools/plugandpaintplugins/basictools}{Basic Tools} plugin is built as a static plugin, to ensure that it is always available to the application. This requires using the Q_IMPORT_PLUGIN() macro somewhere in the application (in a \c @@ -307,7 +307,7 @@ This completes our review of the Plug & Paint application. At this point, you might want to take a look at the - \l{plugandpaintplugins/basictools}{Basic Tools} example + \l{tools/plugandpaintplugins/basictools}{Basic Tools} example plugin. */ @@ -473,7 +473,7 @@ To make the plugin a static plugin, all that is required is to specify \c static in addition to \c plugin. The - \l{plugandpaintplugins/extrafilters}{Extra Filters} plugin, + \l{tools/plugandpaintplugins/extrafilters}{Extra Filters} plugin, which is compiled as a dynamic plugin, doesn't specify \c static in its \c .pro file. @@ -503,13 +503,13 @@ The Extra Filters example is a plugin for the \l{plugandpaint}{Plug & Paint} example. It provides a set of filters in addition to those provided by the - \l{plugandpaintplugins/basictools}{Basic Tools} plugin. + \l{tools/plugandpaintplugins/basictools}{Basic Tools} plugin. Since the approach is identical to - \l{plugandpaintplugins/basictools}{Basic Tools}, we won't + \l{tools/plugandpaintplugins/basictools}{Basic Tools}, we won't review the code here. The only part of interest is the \c .pro file, since Extra Filters is a dynamic plugin - (\l{plugandpaintplugins/basictools}{Basic Tools} is + (\l{tools/plugandpaintplugins/basictools}{Basic Tools} is linked statically into the Plug & Paint executable). Here's the project file for building the Extra Filters plugin: -- cgit v1.2.3 From 14addd2cbbb013a256a2c59d9a5b3ac8ca951e0d Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 31 Jan 2014 11:40:27 +0100 Subject: Update some screenshots in qtbase/examples/widgets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The screenshots were taken on Windows 7 with the Aero theme. Change-Id: Ief04c3a9c0084a778606ba72f1f3199119d5c64e Reviewed-by: Topi Reiniƶ --- .../doc/images/basicgraphicslayouts-example.png | Bin 119062 -> 79461 bytes .../widgets/doc/images/basiclayouts-example.png | Bin 28406 -> 28771 bytes examples/widgets/doc/images/dropsite-example.png | Bin 118905 -> 36033 bytes .../widgets/doc/images/fridgemagnets-example.png | Bin 33012 -> 31707 bytes .../doc/images/graphicsanchorlayout-example.png | Bin 11592 -> 24372 bytes .../images/graphicssimpleanchorlayout-example.png | Bin 13715 -> 16743 bytes examples/widgets/doc/images/mainwindow-demo.png | Bin 62759 -> 85771 bytes .../doc/images/mousebutton-buttontester.png | Bin 14492 -> 17428 bytes 8 files changed, 0 insertions(+), 0 deletions(-) (limited to 'examples') diff --git a/examples/widgets/doc/images/basicgraphicslayouts-example.png b/examples/widgets/doc/images/basicgraphicslayouts-example.png index 5c8f4cbc5d..6b8b39090f 100644 Binary files a/examples/widgets/doc/images/basicgraphicslayouts-example.png and b/examples/widgets/doc/images/basicgraphicslayouts-example.png differ diff --git a/examples/widgets/doc/images/basiclayouts-example.png b/examples/widgets/doc/images/basiclayouts-example.png index f293423a8e..4a1c45dd80 100644 Binary files a/examples/widgets/doc/images/basiclayouts-example.png and b/examples/widgets/doc/images/basiclayouts-example.png differ diff --git a/examples/widgets/doc/images/dropsite-example.png b/examples/widgets/doc/images/dropsite-example.png index 42b988d733..2c42c7be69 100644 Binary files a/examples/widgets/doc/images/dropsite-example.png and b/examples/widgets/doc/images/dropsite-example.png differ diff --git a/examples/widgets/doc/images/fridgemagnets-example.png b/examples/widgets/doc/images/fridgemagnets-example.png index 9adb572afc..2a890aad4e 100644 Binary files a/examples/widgets/doc/images/fridgemagnets-example.png and b/examples/widgets/doc/images/fridgemagnets-example.png differ diff --git a/examples/widgets/doc/images/graphicsanchorlayout-example.png b/examples/widgets/doc/images/graphicsanchorlayout-example.png index d30d6839d9..3f35fdb6b7 100644 Binary files a/examples/widgets/doc/images/graphicsanchorlayout-example.png and b/examples/widgets/doc/images/graphicsanchorlayout-example.png differ diff --git a/examples/widgets/doc/images/graphicssimpleanchorlayout-example.png b/examples/widgets/doc/images/graphicssimpleanchorlayout-example.png index d073b12c0c..543670e05c 100644 Binary files a/examples/widgets/doc/images/graphicssimpleanchorlayout-example.png and b/examples/widgets/doc/images/graphicssimpleanchorlayout-example.png differ diff --git a/examples/widgets/doc/images/mainwindow-demo.png b/examples/widgets/doc/images/mainwindow-demo.png index 5799dc0fa3..0e146d156e 100644 Binary files a/examples/widgets/doc/images/mainwindow-demo.png and b/examples/widgets/doc/images/mainwindow-demo.png differ diff --git a/examples/widgets/doc/images/mousebutton-buttontester.png b/examples/widgets/doc/images/mousebutton-buttontester.png index 82fcb7617f..f8f71db59b 100644 Binary files a/examples/widgets/doc/images/mousebutton-buttontester.png and b/examples/widgets/doc/images/mousebutton-buttontester.png differ -- cgit v1.2.3 From 0b26ad05bbadeef493317c994cc7ccb53b0a612c Mon Sep 17 00:00:00 2001 From: Nico Vertriest Date: Thu, 23 Jan 2014 16:10:26 +0100 Subject: Doc: corrected link/example errors Update pro files after move gestures folder Update snippet statements Corrected path in imagegestures.pro Task-number: QTBUG-34749 Change-Id: Icc19908914e36507e412ab63bf0cc2809aa48e17 Reviewed-by: Jerome Pasion --- examples/examples.pro | 1 - examples/gestures/gestures.pro | 6 - .../imagegestures/doc/src/imagegestures.qdoc | 100 -------- examples/gestures/imagegestures/imagegestures.pro | 12 - examples/gestures/imagegestures/imagewidget.cpp | 267 --------------------- examples/gestures/imagegestures/imagewidget.h | 100 -------- examples/gestures/imagegestures/main.cpp | 58 ----- examples/gestures/imagegestures/mainwidget.cpp | 55 ----- examples/gestures/imagegestures/mainwidget.h | 64 ----- examples/network/doc/src/fortuneclient.qdoc | 2 +- examples/network/doc/src/fortuneserver.qdoc | 2 +- examples/threads/doc/src/mandelbrot.qdoc | 2 +- examples/widgets/doc/src/plugandpaint.qdoc | 8 +- examples/widgets/gestures/gestures.pro | 6 + .../imagegestures/doc/src/imagegestures.qdoc | 100 ++++++++ .../gestures/imagegestures/imagegestures.pro | 12 + .../widgets/gestures/imagegestures/imagewidget.cpp | 267 +++++++++++++++++++++ .../widgets/gestures/imagegestures/imagewidget.h | 100 ++++++++ examples/widgets/gestures/imagegestures/main.cpp | 58 +++++ .../widgets/gestures/imagegestures/mainwidget.cpp | 55 +++++ .../widgets/gestures/imagegestures/mainwidget.h | 64 +++++ examples/widgets/widgets.pro | 1 + 22 files changed, 670 insertions(+), 670 deletions(-) delete mode 100644 examples/gestures/gestures.pro delete mode 100644 examples/gestures/imagegestures/doc/src/imagegestures.qdoc delete mode 100644 examples/gestures/imagegestures/imagegestures.pro delete mode 100644 examples/gestures/imagegestures/imagewidget.cpp delete mode 100644 examples/gestures/imagegestures/imagewidget.h delete mode 100644 examples/gestures/imagegestures/main.cpp delete mode 100644 examples/gestures/imagegestures/mainwidget.cpp delete mode 100644 examples/gestures/imagegestures/mainwidget.h create mode 100644 examples/widgets/gestures/gestures.pro create mode 100644 examples/widgets/gestures/imagegestures/doc/src/imagegestures.qdoc create mode 100644 examples/widgets/gestures/imagegestures/imagegestures.pro create mode 100644 examples/widgets/gestures/imagegestures/imagewidget.cpp create mode 100644 examples/widgets/gestures/imagegestures/imagewidget.h create mode 100644 examples/widgets/gestures/imagegestures/main.cpp create mode 100644 examples/widgets/gestures/imagegestures/mainwidget.cpp create mode 100644 examples/widgets/gestures/imagegestures/mainwidget.h (limited to 'examples') diff --git a/examples/examples.pro b/examples/examples.pro index b0f59c2020..79d8d14fce 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -4,7 +4,6 @@ CONFIG += no_docs_target SUBDIRS = \ dbus \ embedded \ - gestures \ gui \ ipc \ json \ diff --git a/examples/gestures/gestures.pro b/examples/gestures/gestures.pro deleted file mode 100644 index ecbcf07480..0000000000 --- a/examples/gestures/gestures.pro +++ /dev/null @@ -1,6 +0,0 @@ -requires(qtHaveModule(widgets)) - -TEMPLATE = \ - subdirs -SUBDIRS = \ - imagegestures diff --git a/examples/gestures/imagegestures/doc/src/imagegestures.qdoc b/examples/gestures/imagegestures/doc/src/imagegestures.qdoc deleted file mode 100644 index cb76ee83b1..0000000000 --- a/examples/gestures/imagegestures/doc/src/imagegestures.qdoc +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example gestures/imagegestures - \title Image Gestures Example - - This example shows how to enable gestures for a widget and use gesture input - to perform actions. - - We use two classes to create the user interface for the application: \c MainWidget - and \c ImageWidget. The \c MainWidget class is simply used as a container for the - \c ImageWidget class, which we will configure to accept gesture input. Since we - are interested in the way gestures are used, we will concentrate on the - implementation of the \c ImageWidget class. - - \section1 ImageWidget Class Definition - - The \c ImageWidget class is a simple QWidget subclass that reimplements the general - QWidget::event() handler function in addition to several more specific event handlers: - - \snippet examples/gestures/imagegestures/imagewidget.h class definition begin - \dots - \snippet examples/gestures/imagegestures/imagewidget.h class definition end - - We also implement a private helper function, \c gestureEvent(), to help manage - gesture events delivered to the widget, and three functions to perform actions - based on gestures: \c panTriggered(), \c pinchTriggered() and \c swipeTriggered(). - - \section1 ImageWidget Class Implementation - - In the widget's constructor, we begin by setting up various parameters that will - be used to control the way images are displayed. - - \snippet examples/gestures/imagegestures/imagewidget.cpp constructor - - We enable three of the standard gestures for the widget by calling QWidget::grabGesture() - with the types of gesture we need. These will be recognized by the application's - default gesture recognizer, and events will be delivered to our widget. - - Since QWidget does not define a specific event handler for gestures, the widget - needs to reimplement the general QWidget::event() to receive gesture events. - - \snippet examples/gestures/imagegestures/imagewidget.cpp event handler - - We implement the event handler to delegate gesture events to a private function - specifically written for the task, and pass all other events to QWidget's - implementation. - - The \c gestureHandler() function examines the gestures supplied by the - newly-delivered QGestureEvent. Since only one gesture of a given type can be - used on a widget at any particular time, we can check for each gesture type - using the QGestureEvent::gesture() function: - - \snippet examples/gestures/imagegestures/imagewidget.cpp gesture event handler - - If a QGesture object is supplied for a certain type of gesture, we call a special - purpose function to deal with it, casting the gesture object to the appropriate - QGesture subclass. - - To illustrate how a standard gesture can be interpreted by an application, we - show the implementation of the \c swipeTriggered() function, which handles the - gesture associated with a brushing or swiping motion on the user's display or - input device: - - \snippet examples/gestures/imagegestures/imagewidget.cpp swipe function - - The QSwipeGesture class provides specialized functions and defines a enum - to make it more convenient for developers to discover which direction, if - any, the user swiped the display. Here, we simply navigate to the previous - image in the collection if the user swiped upwards or to the left; otherwise - we navigate to the next image in the collection. - - The other gestures are also handled by special purpose functions, but use - the values of properties held by the QGesture object passed to them. -*/ diff --git a/examples/gestures/imagegestures/imagegestures.pro b/examples/gestures/imagegestures/imagegestures.pro deleted file mode 100644 index c40c29564f..0000000000 --- a/examples/gestures/imagegestures/imagegestures.pro +++ /dev/null @@ -1,12 +0,0 @@ -QT += widgets - -HEADERS = imagewidget.h \ - mainwidget.h -SOURCES = imagewidget.cpp \ - main.cpp \ - mainwidget.cpp - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/gestures/imagegestures -INSTALLS += target - diff --git a/examples/gestures/imagegestures/imagewidget.cpp b/examples/gestures/imagegestures/imagewidget.cpp deleted file mode 100644 index aad40afc26..0000000000 --- a/examples/gestures/imagegestures/imagewidget.cpp +++ /dev/null @@ -1,267 +0,0 @@ - -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "imagewidget.h" - -#include - -//! [constructor] -ImageWidget::ImageWidget(QWidget *parent) - : QWidget(parent), - position(0), - horizontalOffset(0), - verticalOffset(0), - rotationAngle(0), - scaleFactor(1), - currentStepScaleFactor(1) - -{ - setMinimumSize(QSize(100,100)); - -//! [enable gestures] - grabGesture(Qt::PanGesture); - grabGesture(Qt::PinchGesture); - grabGesture(Qt::SwipeGesture); -//! [enable gestures] -} -//! [constructor] - -//! [event handler] -bool ImageWidget::event(QEvent *event) -{ - if (event->type() == QEvent::Gesture) - return gestureEvent(static_cast(event)); - return QWidget::event(event); -} -//! [event handler] - -void ImageWidget::paintEvent(QPaintEvent*) -{ - QPainter p(this); - - float iw = currentImage.width(); - float ih = currentImage.height(); - float wh = height(); - float ww = width(); - - p.translate(ww/2, wh/2); - p.translate(horizontalOffset, verticalOffset); - p.rotate(rotationAngle); - p.scale(currentStepScaleFactor * scaleFactor, currentStepScaleFactor * scaleFactor); - p.translate(-iw/2, -ih/2); - p.drawImage(0, 0, currentImage); -} - -void ImageWidget::mouseDoubleClickEvent(QMouseEvent *) -{ - rotationAngle = 0; - scaleFactor = 1; - currentStepScaleFactor = 1; - verticalOffset = 0; - horizontalOffset = 0; - update(); -} - -//! [gesture event handler] -bool ImageWidget::gestureEvent(QGestureEvent *event) -{ - if (QGesture *swipe = event->gesture(Qt::SwipeGesture)) - swipeTriggered(static_cast(swipe)); - else if (QGesture *pan = event->gesture(Qt::PanGesture)) - panTriggered(static_cast(pan)); - if (QGesture *pinch = event->gesture(Qt::PinchGesture)) - pinchTriggered(static_cast(pinch)); - return true; -} -//! [gesture event handler] - -void ImageWidget::panTriggered(QPanGesture *gesture) -{ -#ifndef QT_NO_CURSOR - switch (gesture->state()) { - case Qt::GestureStarted: - case Qt::GestureUpdated: - setCursor(Qt::SizeAllCursor); - break; - default: - setCursor(Qt::ArrowCursor); - } -#endif - QPointF delta = gesture->delta(); - horizontalOffset += delta.x(); - verticalOffset += delta.y(); - update(); -} - -void ImageWidget::pinchTriggered(QPinchGesture *gesture) -{ - QPinchGesture::ChangeFlags changeFlags = gesture->changeFlags(); - if (changeFlags & QPinchGesture::RotationAngleChanged) { - qreal value = gesture->property("rotationAngle").toReal(); - qreal lastValue = gesture->property("lastRotationAngle").toReal(); - rotationAngle += value - lastValue; - } - if (changeFlags & QPinchGesture::ScaleFactorChanged) { - qreal value = gesture->property("scaleFactor").toReal(); - currentStepScaleFactor = value; - } - if (gesture->state() == Qt::GestureFinished) { - scaleFactor *= currentStepScaleFactor; - currentStepScaleFactor = 1; - } - update(); -} - -//! [swipe function] -void ImageWidget::swipeTriggered(QSwipeGesture *gesture) -{ - if (gesture->state() == Qt::GestureFinished) { - if (gesture->horizontalDirection() == QSwipeGesture::Left - || gesture->verticalDirection() == QSwipeGesture::Up) - goPrevImage(); - else - goNextImage(); - update(); - } -} -//! [swipe function] - -void ImageWidget::resizeEvent(QResizeEvent*) -{ - update(); -} - -void ImageWidget::openDirectory(const QString &path) -{ - this->path = path; - QDir dir(path); - QStringList nameFilters; - nameFilters << "*.jpg" << "*.png"; - files = dir.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name); - - position = 0; - goToImage(0); - update(); -} - -QImage ImageWidget::loadImage(const QString &fileName) -{ - QImageReader reader(fileName); - if (!reader.canRead()) { - qDebug() << fileName << ": can't load image"; - return QImage(); - } - - QImage image; - if (!reader.read(&image)) { - qDebug() << fileName << ": corrupted image"; - return QImage(); - } - return image; -} - -void ImageWidget::goNextImage() -{ - if (files.isEmpty()) - return; - - if (position < files.size()-1) { - ++position; - prevImage = currentImage; - currentImage = nextImage; - if (position+1 < files.size()) - nextImage = loadImage(path+QLatin1String("/")+files.at(position+1)); - else - nextImage = QImage(); - } - update(); -} - -void ImageWidget::goPrevImage() -{ - if (files.isEmpty()) - return; - - if (position > 0) { - --position; - nextImage = currentImage; - currentImage = prevImage; - if (position > 0) - prevImage = loadImage(path+QLatin1String("/")+files.at(position-1)); - else - prevImage = QImage(); - } - update(); -} - -void ImageWidget::goToImage(int index) -{ - if (files.isEmpty()) - return; - - if (index < 0 || index >= files.size()) { - qDebug() << "goToImage: invalid index: " << index; - return; - } - - if (index == position+1) { - goNextImage(); - return; - } - - if (position > 0 && index == position-1) { - goPrevImage(); - return; - } - - position = index; - - if (index > 0) - prevImage = loadImage(path+QLatin1String("/")+files.at(position-1)); - else - prevImage = QImage(); - currentImage = loadImage(path+QLatin1String("/")+files.at(position)); - if (position+1 < files.size()) - nextImage = loadImage(path+QLatin1String("/")+files.at(position+1)); - else - nextImage = QImage(); - update(); -} diff --git a/examples/gestures/imagegestures/imagewidget.h b/examples/gestures/imagegestures/imagewidget.h deleted file mode 100644 index 7aaf554117..0000000000 --- a/examples/gestures/imagegestures/imagewidget.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef IMAGEWIDGET_H -#define IMAGEWIDGET_H - -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QGestureEvent; -class QPanGesture; -class QPinchGesture; -class QSwipeGesture; -QT_END_NAMESPACE - -//! [class definition begin] -class ImageWidget : public QWidget -{ - Q_OBJECT - -public: - ImageWidget(QWidget *parent = 0); - void openDirectory(const QString &path); - -protected: - bool event(QEvent *event); - void paintEvent(QPaintEvent *event); - void resizeEvent(QResizeEvent *event); - void mouseDoubleClickEvent(QMouseEvent *event); - -private: - bool gestureEvent(QGestureEvent *event); - void panTriggered(QPanGesture*); - void pinchTriggered(QPinchGesture*); - void swipeTriggered(QSwipeGesture*); -//! [class definition begin] - - void updateImage(); - QImage loadImage(const QString &fileName); - void loadImage(); - void goNextImage(); - void goPrevImage(); - void goToImage(int index); - - QString path; - QStringList files; - int position; - - QImage prevImage, nextImage; - QImage currentImage; - - float horizontalOffset; - float verticalOffset; - float rotationAngle; - float scaleFactor; - float currentStepScaleFactor; -//! [class definition end] -}; -//! [class definition end] - -#endif diff --git a/examples/gestures/imagegestures/main.cpp b/examples/gestures/imagegestures/main.cpp deleted file mode 100644 index aec32149f0..0000000000 --- a/examples/gestures/imagegestures/main.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include "mainwidget.h" - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - MainWidget w; - w.show(); - - if (QApplication::arguments().size() > 1) - w.openDirectory(QApplication::arguments().at(1)); - else - w.openDirectory(QFileDialog::getExistingDirectory(0, "Select image folder")); - - return app.exec(); -} diff --git a/examples/gestures/imagegestures/mainwidget.cpp b/examples/gestures/imagegestures/mainwidget.cpp deleted file mode 100644 index 105cdf184e..0000000000 --- a/examples/gestures/imagegestures/mainwidget.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $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/imagegestures/mainwidget.h b/examples/gestures/imagegestures/mainwidget.h deleted file mode 100644 index 5135466fde..0000000000 --- a/examples/gestures/imagegestures/mainwidget.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MAINWIDGET_H -#define MAINWIDGET_H - -#include - -class ImageWidget; - -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 diff --git a/examples/network/doc/src/fortuneclient.qdoc b/examples/network/doc/src/fortuneclient.qdoc index bf208475a8..01acf45837 100644 --- a/examples/network/doc/src/fortuneclient.qdoc +++ b/examples/network/doc/src/fortuneclient.qdoc @@ -63,7 +63,7 @@ \endlist In this example, we will demonstrate the asynchronous approach. The - \l{blockingfortuneclient}{Blocking Fortune Client} example + \l{blockingfortuneclient}{Blocking Fortune Client Example} illustrates the synchronous approach. Our class contains some data and a few private slots: diff --git a/examples/network/doc/src/fortuneserver.qdoc b/examples/network/doc/src/fortuneserver.qdoc index 022e16a9d7..fd61f864f0 100644 --- a/examples/network/doc/src/fortuneserver.qdoc +++ b/examples/network/doc/src/fortuneserver.qdoc @@ -33,7 +33,7 @@ This example is intended to be run alongside the \l{fortuneclient}{Fortune Client} example or the - \l{blockingfortuneclient}{Blocking Fortune Client} example. + \l{blockingfortuneclient}{Blocking Fortune Client Example}. \image fortuneserver-example.png Screenshot of the Fortune Server example diff --git a/examples/threads/doc/src/mandelbrot.qdoc b/examples/threads/doc/src/mandelbrot.qdoc index 6a9d0da193..c1393769f1 100644 --- a/examples/threads/doc/src/mandelbrot.qdoc +++ b/examples/threads/doc/src/mandelbrot.qdoc @@ -47,7 +47,7 @@ large set of problems, including synchronous network I/O and database access, where the user interface must remain responsive while some heavy operation is taking place. The \l - network/blockingfortuneclient example shows the same principle at + {Blocking Fortune Client Example} shows the same principle at work in a TCP client. The Mandelbrot application supports zooming and scrolling using diff --git a/examples/widgets/doc/src/plugandpaint.qdoc b/examples/widgets/doc/src/plugandpaint.qdoc index 5098d892ef..4e48245bd9 100644 --- a/examples/widgets/doc/src/plugandpaint.qdoc +++ b/examples/widgets/doc/src/plugandpaint.qdoc @@ -316,7 +316,7 @@ \title Plug & Paint Basic Tools Example The Basic Tools example is a static plugin for the - \l{plugandpaint}{Plug & Paint} example. It provides a set + \l{tools/plugandpaint}{Plug & Paint} example. It provides a set of basic brushes, shapes, and filters. Through the Basic Tools example, we will review the four steps involved in writing a Qt plugin: @@ -333,7 +333,7 @@ \snippet tools/plugandpaintplugins/basictools/basictoolsplugin.h 0 We start by including \c interfaces.h, which defines the plugin - interfaces for the \l{plugandpaint}{Plug & Paint} + interfaces for the \l{tools/plugandpaint}{Plug & Paint} application. For the \c #include to work, we need to add an \c INCLUDEPATH entry to the \c .pro file with the path to Qt's \c examples/tools directory. @@ -344,7 +344,7 @@ The \c Q_INTERFACES() macro is necessary to tell \l{moc}, Qt's meta-object compiler, that the base classes are plugin interfaces. Without the \c Q_INTERFACES() macro, we couldn't use - \l qobject_cast() in the \l{plugandpaint}{Plug & Paint} + \l qobject_cast() in the \l{tools/plugandpaint}{Plug & Paint} application to detect interfaces. For an explanation for the \c Q_PLUGIN_METADATA() macro see \l {Exporting the Plugin}. @@ -501,7 +501,7 @@ \title Plug & Paint Extra Filters Example The Extra Filters example is a plugin for the - \l{plugandpaint}{Plug & Paint} example. It provides a set + \l{tools/plugandpaint}{Plug & Paint} example. It provides a set of filters in addition to those provided by the \l{tools/plugandpaintplugins/basictools}{Basic Tools} plugin. diff --git a/examples/widgets/gestures/gestures.pro b/examples/widgets/gestures/gestures.pro new file mode 100644 index 0000000000..ecbcf07480 --- /dev/null +++ b/examples/widgets/gestures/gestures.pro @@ -0,0 +1,6 @@ +requires(qtHaveModule(widgets)) + +TEMPLATE = \ + subdirs +SUBDIRS = \ + imagegestures diff --git a/examples/widgets/gestures/imagegestures/doc/src/imagegestures.qdoc b/examples/widgets/gestures/imagegestures/doc/src/imagegestures.qdoc new file mode 100644 index 0000000000..d6d215d6bd --- /dev/null +++ b/examples/widgets/gestures/imagegestures/doc/src/imagegestures.qdoc @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example gestures/imagegestures + \title Image Gestures Example + + This example shows how to enable gestures for a widget and use gesture input + to perform actions. + + We use two classes to create the user interface for the application: \c MainWidget + and \c ImageWidget. The \c MainWidget class is simply used as a container for the + \c ImageWidget class, which we will configure to accept gesture input. Since we + are interested in the way gestures are used, we will concentrate on the + implementation of the \c ImageWidget class. + + \section1 ImageWidget Class Definition + + The \c ImageWidget class is a simple QWidget subclass that reimplements the general + QWidget::event() handler function in addition to several more specific event handlers: + + \snippet gestures/imagegestures/imagewidget.h class definition begin + \dots + \snippet gestures/imagegestures/imagewidget.h class definition end + + We also implement a private helper function, \c gestureEvent(), to help manage + gesture events delivered to the widget, and three functions to perform actions + based on gestures: \c panTriggered(), \c pinchTriggered() and \c swipeTriggered(). + + \section1 ImageWidget Class Implementation + + In the widget's constructor, we begin by setting up various parameters that will + be used to control the way images are displayed. + + \snippet gestures/imagegestures/imagewidget.cpp constructor + + We enable three of the standard gestures for the widget by calling QWidget::grabGesture() + with the types of gesture we need. These will be recognized by the application's + default gesture recognizer, and events will be delivered to our widget. + + Since QWidget does not define a specific event handler for gestures, the widget + needs to reimplement the general QWidget::event() to receive gesture events. + + \snippet gestures/imagegestures/imagewidget.cpp event handler + + We implement the event handler to delegate gesture events to a private function + specifically written for the task, and pass all other events to QWidget's + implementation. + + The \c gestureHandler() function examines the gestures supplied by the + newly-delivered QGestureEvent. Since only one gesture of a given type can be + used on a widget at any particular time, we can check for each gesture type + using the QGestureEvent::gesture() function: + + \snippet gestures/imagegestures/imagewidget.cpp gesture event handler + + If a QGesture object is supplied for a certain type of gesture, we call a special + purpose function to deal with it, casting the gesture object to the appropriate + QGesture subclass. + + To illustrate how a standard gesture can be interpreted by an application, we + show the implementation of the \c swipeTriggered() function, which handles the + gesture associated with a brushing or swiping motion on the user's display or + input device: + + \snippet gestures/imagegestures/imagewidget.cpp swipe function + + The QSwipeGesture class provides specialized functions and defines a enum + to make it more convenient for developers to discover which direction, if + any, the user swiped the display. Here, we simply navigate to the previous + image in the collection if the user swiped upwards or to the left; otherwise + we navigate to the next image in the collection. + + The other gestures are also handled by special purpose functions, but use + the values of properties held by the QGesture object passed to them. +*/ diff --git a/examples/widgets/gestures/imagegestures/imagegestures.pro b/examples/widgets/gestures/imagegestures/imagegestures.pro new file mode 100644 index 0000000000..0d5b2f286c --- /dev/null +++ b/examples/widgets/gestures/imagegestures/imagegestures.pro @@ -0,0 +1,12 @@ +QT += widgets + +HEADERS = imagewidget.h \ + mainwidget.h +SOURCES = imagewidget.cpp \ + main.cpp \ + mainwidget.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/gestures/imagegestures +INSTALLS += target + diff --git a/examples/widgets/gestures/imagegestures/imagewidget.cpp b/examples/widgets/gestures/imagegestures/imagewidget.cpp new file mode 100644 index 0000000000..aad40afc26 --- /dev/null +++ b/examples/widgets/gestures/imagegestures/imagewidget.cpp @@ -0,0 +1,267 @@ + +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "imagewidget.h" + +#include + +//! [constructor] +ImageWidget::ImageWidget(QWidget *parent) + : QWidget(parent), + position(0), + horizontalOffset(0), + verticalOffset(0), + rotationAngle(0), + scaleFactor(1), + currentStepScaleFactor(1) + +{ + setMinimumSize(QSize(100,100)); + +//! [enable gestures] + grabGesture(Qt::PanGesture); + grabGesture(Qt::PinchGesture); + grabGesture(Qt::SwipeGesture); +//! [enable gestures] +} +//! [constructor] + +//! [event handler] +bool ImageWidget::event(QEvent *event) +{ + if (event->type() == QEvent::Gesture) + return gestureEvent(static_cast(event)); + return QWidget::event(event); +} +//! [event handler] + +void ImageWidget::paintEvent(QPaintEvent*) +{ + QPainter p(this); + + float iw = currentImage.width(); + float ih = currentImage.height(); + float wh = height(); + float ww = width(); + + p.translate(ww/2, wh/2); + p.translate(horizontalOffset, verticalOffset); + p.rotate(rotationAngle); + p.scale(currentStepScaleFactor * scaleFactor, currentStepScaleFactor * scaleFactor); + p.translate(-iw/2, -ih/2); + p.drawImage(0, 0, currentImage); +} + +void ImageWidget::mouseDoubleClickEvent(QMouseEvent *) +{ + rotationAngle = 0; + scaleFactor = 1; + currentStepScaleFactor = 1; + verticalOffset = 0; + horizontalOffset = 0; + update(); +} + +//! [gesture event handler] +bool ImageWidget::gestureEvent(QGestureEvent *event) +{ + if (QGesture *swipe = event->gesture(Qt::SwipeGesture)) + swipeTriggered(static_cast(swipe)); + else if (QGesture *pan = event->gesture(Qt::PanGesture)) + panTriggered(static_cast(pan)); + if (QGesture *pinch = event->gesture(Qt::PinchGesture)) + pinchTriggered(static_cast(pinch)); + return true; +} +//! [gesture event handler] + +void ImageWidget::panTriggered(QPanGesture *gesture) +{ +#ifndef QT_NO_CURSOR + switch (gesture->state()) { + case Qt::GestureStarted: + case Qt::GestureUpdated: + setCursor(Qt::SizeAllCursor); + break; + default: + setCursor(Qt::ArrowCursor); + } +#endif + QPointF delta = gesture->delta(); + horizontalOffset += delta.x(); + verticalOffset += delta.y(); + update(); +} + +void ImageWidget::pinchTriggered(QPinchGesture *gesture) +{ + QPinchGesture::ChangeFlags changeFlags = gesture->changeFlags(); + if (changeFlags & QPinchGesture::RotationAngleChanged) { + qreal value = gesture->property("rotationAngle").toReal(); + qreal lastValue = gesture->property("lastRotationAngle").toReal(); + rotationAngle += value - lastValue; + } + if (changeFlags & QPinchGesture::ScaleFactorChanged) { + qreal value = gesture->property("scaleFactor").toReal(); + currentStepScaleFactor = value; + } + if (gesture->state() == Qt::GestureFinished) { + scaleFactor *= currentStepScaleFactor; + currentStepScaleFactor = 1; + } + update(); +} + +//! [swipe function] +void ImageWidget::swipeTriggered(QSwipeGesture *gesture) +{ + if (gesture->state() == Qt::GestureFinished) { + if (gesture->horizontalDirection() == QSwipeGesture::Left + || gesture->verticalDirection() == QSwipeGesture::Up) + goPrevImage(); + else + goNextImage(); + update(); + } +} +//! [swipe function] + +void ImageWidget::resizeEvent(QResizeEvent*) +{ + update(); +} + +void ImageWidget::openDirectory(const QString &path) +{ + this->path = path; + QDir dir(path); + QStringList nameFilters; + nameFilters << "*.jpg" << "*.png"; + files = dir.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name); + + position = 0; + goToImage(0); + update(); +} + +QImage ImageWidget::loadImage(const QString &fileName) +{ + QImageReader reader(fileName); + if (!reader.canRead()) { + qDebug() << fileName << ": can't load image"; + return QImage(); + } + + QImage image; + if (!reader.read(&image)) { + qDebug() << fileName << ": corrupted image"; + return QImage(); + } + return image; +} + +void ImageWidget::goNextImage() +{ + if (files.isEmpty()) + return; + + if (position < files.size()-1) { + ++position; + prevImage = currentImage; + currentImage = nextImage; + if (position+1 < files.size()) + nextImage = loadImage(path+QLatin1String("/")+files.at(position+1)); + else + nextImage = QImage(); + } + update(); +} + +void ImageWidget::goPrevImage() +{ + if (files.isEmpty()) + return; + + if (position > 0) { + --position; + nextImage = currentImage; + currentImage = prevImage; + if (position > 0) + prevImage = loadImage(path+QLatin1String("/")+files.at(position-1)); + else + prevImage = QImage(); + } + update(); +} + +void ImageWidget::goToImage(int index) +{ + if (files.isEmpty()) + return; + + if (index < 0 || index >= files.size()) { + qDebug() << "goToImage: invalid index: " << index; + return; + } + + if (index == position+1) { + goNextImage(); + return; + } + + if (position > 0 && index == position-1) { + goPrevImage(); + return; + } + + position = index; + + if (index > 0) + prevImage = loadImage(path+QLatin1String("/")+files.at(position-1)); + else + prevImage = QImage(); + currentImage = loadImage(path+QLatin1String("/")+files.at(position)); + if (position+1 < files.size()) + nextImage = loadImage(path+QLatin1String("/")+files.at(position+1)); + else + nextImage = QImage(); + update(); +} diff --git a/examples/widgets/gestures/imagegestures/imagewidget.h b/examples/widgets/gestures/imagegestures/imagewidget.h new file mode 100644 index 0000000000..7aaf554117 --- /dev/null +++ b/examples/widgets/gestures/imagegestures/imagewidget.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IMAGEWIDGET_H +#define IMAGEWIDGET_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QGestureEvent; +class QPanGesture; +class QPinchGesture; +class QSwipeGesture; +QT_END_NAMESPACE + +//! [class definition begin] +class ImageWidget : public QWidget +{ + Q_OBJECT + +public: + ImageWidget(QWidget *parent = 0); + void openDirectory(const QString &path); + +protected: + bool event(QEvent *event); + void paintEvent(QPaintEvent *event); + void resizeEvent(QResizeEvent *event); + void mouseDoubleClickEvent(QMouseEvent *event); + +private: + bool gestureEvent(QGestureEvent *event); + void panTriggered(QPanGesture*); + void pinchTriggered(QPinchGesture*); + void swipeTriggered(QSwipeGesture*); +//! [class definition begin] + + void updateImage(); + QImage loadImage(const QString &fileName); + void loadImage(); + void goNextImage(); + void goPrevImage(); + void goToImage(int index); + + QString path; + QStringList files; + int position; + + QImage prevImage, nextImage; + QImage currentImage; + + float horizontalOffset; + float verticalOffset; + float rotationAngle; + float scaleFactor; + float currentStepScaleFactor; +//! [class definition end] +}; +//! [class definition end] + +#endif diff --git a/examples/widgets/gestures/imagegestures/main.cpp b/examples/widgets/gestures/imagegestures/main.cpp new file mode 100644 index 0000000000..aec32149f0 --- /dev/null +++ b/examples/widgets/gestures/imagegestures/main.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwidget.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + MainWidget w; + w.show(); + + if (QApplication::arguments().size() > 1) + w.openDirectory(QApplication::arguments().at(1)); + else + w.openDirectory(QFileDialog::getExistingDirectory(0, "Select image folder")); + + return app.exec(); +} diff --git a/examples/widgets/gestures/imagegestures/mainwidget.cpp b/examples/widgets/gestures/imagegestures/mainwidget.cpp new file mode 100644 index 0000000000..105cdf184e --- /dev/null +++ b/examples/widgets/gestures/imagegestures/mainwidget.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $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/widgets/gestures/imagegestures/mainwidget.h b/examples/widgets/gestures/imagegestures/mainwidget.h new file mode 100644 index 0000000000..5135466fde --- /dev/null +++ b/examples/widgets/gestures/imagegestures/mainwidget.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWIDGET_H +#define MAINWIDGET_H + +#include + +class ImageWidget; + +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 diff --git a/examples/widgets/widgets.pro b/examples/widgets/widgets.pro index 9c82ad0bb7..d7d3dbc445 100644 --- a/examples/widgets/widgets.pro +++ b/examples/widgets/widgets.pro @@ -9,6 +9,7 @@ SUBDIRS = \ dialogs \ draganddrop \ effects \ + gestures \ graphicsview \ itemviews \ layouts \ -- cgit v1.2.3 From 1d5ee909694586536f4e0f747f2cd8cbcf98da51 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 31 Jan 2014 16:02:58 +0100 Subject: Update some more screenshots in qtbase/examples/widgets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The screenshots were taken on Windows 7 with the Aero theme. Change-Id: I2517664e25389f4fb87408daec7b720dfb785bf0 Reviewed-by: Topi Reiniƶ --- .../doc/images/draganddroppuzzle-example.png | Bin 191122 -> 259104 bytes examples/widgets/doc/images/echopluginexample.png | Bin 5921 -> 10610 bytes .../doc/images/graphicsflowlayout-example.png | Bin 15345 -> 18988 bytes .../widgets/doc/images/itemviewspuzzle-example.png | Bin 211091 -> 196251 bytes 4 files changed, 0 insertions(+), 0 deletions(-) (limited to 'examples') diff --git a/examples/widgets/doc/images/draganddroppuzzle-example.png b/examples/widgets/doc/images/draganddroppuzzle-example.png index 812278210d..ca6844581e 100644 Binary files a/examples/widgets/doc/images/draganddroppuzzle-example.png and b/examples/widgets/doc/images/draganddroppuzzle-example.png differ diff --git a/examples/widgets/doc/images/echopluginexample.png b/examples/widgets/doc/images/echopluginexample.png index 7cb1e4d63b..24e039714f 100644 Binary files a/examples/widgets/doc/images/echopluginexample.png and b/examples/widgets/doc/images/echopluginexample.png differ diff --git a/examples/widgets/doc/images/graphicsflowlayout-example.png b/examples/widgets/doc/images/graphicsflowlayout-example.png index a5f9b3dc40..953d54086a 100644 Binary files a/examples/widgets/doc/images/graphicsflowlayout-example.png and b/examples/widgets/doc/images/graphicsflowlayout-example.png differ diff --git a/examples/widgets/doc/images/itemviewspuzzle-example.png b/examples/widgets/doc/images/itemviewspuzzle-example.png index 05ae28be81..aae6a953ca 100644 Binary files a/examples/widgets/doc/images/itemviewspuzzle-example.png and b/examples/widgets/doc/images/itemviewspuzzle-example.png differ -- cgit v1.2.3