diff options
-rw-r--r-- | examples/examples.pro | 1 | ||||
-rw-r--r-- | examples/openvg/README | 40 | ||||
-rw-r--r-- | examples/openvg/openvg.pro | 8 | ||||
-rw-r--r-- | examples/openvg/star/main.cpp | 54 | ||||
-rw-r--r-- | examples/openvg/star/star.pro | 6 | ||||
-rw-r--r-- | examples/openvg/star/starwidget.cpp | 115 | ||||
-rw-r--r-- | examples/openvg/star/starwidget.h | 66 |
7 files changed, 290 insertions, 0 deletions
diff --git a/examples/examples.pro b/examples/examples.pro index 5382e28..5855e4f 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -36,6 +36,7 @@ embedded:SUBDIRS += qws contains(QT_BUILD_PARTS, tools):SUBDIRS += qtestlib } contains(QT_CONFIG, opengl): SUBDIRS += opengl +contains(QT_CONFIG, openvg): SUBDIRS += openvg contains(QT_CONFIG, dbus): SUBDIRS += dbus win32: SUBDIRS += activeqt contains(QT_CONFIG, xmlpatterns): SUBDIRS += xmlpatterns diff --git a/examples/openvg/README b/examples/openvg/README new file mode 100644 index 0000000..5e385ea --- /dev/null +++ b/examples/openvg/README @@ -0,0 +1,40 @@ +Qt provides support for integration with OpenVG implementations on +platforms with appropriate hardware acceleration. + +These examples demonstrate the basic techniques used to take advantage of +OpenVG in Qt applications. In particular, the "star" example shows how +to mix QPainter and OpenVG calls in the same paint event. + +The example launcher provided with Qt can be used to explore each of the +examples in this directory. + +Documentation for these examples can be found via the Tutorial and Examples +link in the main Qt documentation. + + +Finding the Qt Examples and Demos launcher +========================================== + +On Windows: + +The launcher can be accessed via the Windows Start menu. Select the menu +entry entitled "Qt Examples and Demos" entry in the submenu containing +the Qt tools. + +On Mac OS X: + +For the binary distribution, the qtdemo executable is installed in the +/Developer/Applications/Qt directory. For the source distribution, it is +installed alongside the other Qt tools on the path specified when Qt is +configured. + +On Unix/Linux: + +The qtdemo executable is installed alongside the other Qt tools on the path +specified when Qt is configured. + +On all platforms: + +The source code for the launcher can be found in the demos/qtdemo directory +in the Qt package. This example is built at the same time as the Qt libraries, +tools, examples, and demonstrations. diff --git a/examples/openvg/openvg.pro b/examples/openvg/openvg.pro new file mode 100644 index 0000000..d76a389 --- /dev/null +++ b/examples/openvg/openvg.pro @@ -0,0 +1,8 @@ +TEMPLATE = subdirs +SUBDIRS = star + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/openvg +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS openvg.pro README +sources.path = $$[QT_INSTALL_EXAMPLES]/openvg +INSTALLS += target sources diff --git a/examples/openvg/star/main.cpp b/examples/openvg/star/main.cpp new file mode 100644 index 0000000..eec2186 --- /dev/null +++ b/examples/openvg/star/main.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenGL module 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include "starwidget.h" + +int main(int argc, char *argv[]) +{ +#ifdef Q_OS_SYMBIAN + QApplication::setGraphicsSystem("openvg"); +#endif + QApplication app(argc, argv); + StarWidget mw; + mw.show(); + return app.exec(); +} diff --git a/examples/openvg/star/star.pro b/examples/openvg/star/star.pro new file mode 100644 index 0000000..90c236d --- /dev/null +++ b/examples/openvg/star/star.pro @@ -0,0 +1,6 @@ +TEMPLATE = app +TARGET = star +CONFIG += qt debug warn_on +QT += openvg +SOURCES = starwidget.cpp main.cpp +HEADERS = starwidget.h diff --git a/examples/openvg/star/starwidget.cpp b/examples/openvg/star/starwidget.cpp new file mode 100644 index 0000000..9d2a255 --- /dev/null +++ b/examples/openvg/star/starwidget.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenGL module 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "starwidget.h" + +StarWidget::StarWidget(QWidget *parent) + : QWidget(parent) + , path(VG_INVALID_HANDLE) + , pen(Qt::red, 4.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin) + , brush(Qt::yellow) +{ + setMinimumSize(220, 250); + setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); +} + +static VGubyte const starSegments[] = { + VG_MOVE_TO_ABS, + VG_LINE_TO_REL, + VG_LINE_TO_REL, + VG_LINE_TO_REL, + VG_LINE_TO_REL, + VG_CLOSE_PATH +}; +static VGfloat const starCoords[] = { + 110, 35, + 50, 160, + -130, -100, + 160, 0, + -130, 100 +}; + +void StarWidget::paintEvent(QPaintEvent *) +{ + QPainter painter; + painter.begin(this); + + // Make sure that we are using the OpenVG paint engine. + if (painter.paintEngine()->type() != QPaintEngine::OpenVG) { +#ifdef Q_WS_QWS + qWarning("Not using OpenVG: use the '-display' option to specify an OpenVG driver"); +#else + qWarning("Not using OpenVG: specify '-graphicssystem OpenVG'"); +#endif + return; + } + + // Select a pen and a brush for drawing the star. + painter.setPen(pen); + painter.setBrush(brush); + + // We want the star border to be anti-aliased. + painter.setRenderHints(QPainter::Antialiasing); + + // Flush the state changes to the OpenVG implementation + // and prepare to perform raw OpenVG calls. + painter.paintEngine()->syncState(); + + // Cache the path if we haven't already. + if (path == VG_INVALID_HANDLE) { + path = vgCreatePath(VG_PATH_FORMAT_STANDARD, + VG_PATH_DATATYPE_F, + 1.0f, // scale + 0.0f, // bias + 6, // segmentCapacityHint + 10, // coordCapacityHint + VG_PATH_CAPABILITY_ALL); + vgAppendPathData(path, sizeof(starSegments), starSegments, starCoords); + } + + // Draw the star directly using the OpenVG API. + vgDrawPath(path, VG_FILL_PATH | VG_STROKE_PATH); + + // Restore normal QPainter operations. + painter.paintEngine()->syncState(); + + painter.end(); +} diff --git a/examples/openvg/star/starwidget.h b/examples/openvg/star/starwidget.h new file mode 100644 index 0000000..883f8c4 --- /dev/null +++ b/examples/openvg/star/starwidget.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenGL module 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef STARWIDGET_H +#define STARWIDGET_H + +#include <QWidget> +#include <QPainter> +#include <QPaintEngine> +#include "qvg.h" + +class StarWidget : public QWidget +{ + Q_OBJECT +public: + StarWidget(QWidget *parent = 0); + ~StarWidget() {} + +protected: + void paintEvent(QPaintEvent *); + +private: + VGPath path; + QPen pen; + QBrush brush; +}; + +#endif |