diff options
Diffstat (limited to 'examples/qml/painteditem')
-rw-r--r-- | examples/qml/painteditem/painteditem.pro | 5 | ||||
-rw-r--r-- | examples/qml/painteditem/smile/main.cpp | 96 | ||||
-rw-r--r-- | examples/qml/painteditem/smile/smile.pro | 11 | ||||
-rw-r--r-- | examples/qml/painteditem/smile/smile.qml | 132 | ||||
-rw-r--r-- | examples/qml/painteditem/textballoons/TextBalloonPlugin/plugin.h | 56 | ||||
-rw-r--r-- | examples/qml/painteditem/textballoons/TextBalloonPlugin/qmldir | 1 | ||||
-rw-r--r-- | examples/qml/painteditem/textballoons/textballoon.cpp | 92 | ||||
-rw-r--r-- | examples/qml/painteditem/textballoons/textballoon.h | 68 | ||||
-rw-r--r-- | examples/qml/painteditem/textballoons/textballoons.pro | 23 | ||||
-rw-r--r-- | examples/qml/painteditem/textballoons/textballoons.qml | 110 |
10 files changed, 594 insertions, 0 deletions
diff --git a/examples/qml/painteditem/painteditem.pro b/examples/qml/painteditem/painteditem.pro new file mode 100644 index 0000000000..e3afd6b0f0 --- /dev/null +++ b/examples/qml/painteditem/painteditem.pro @@ -0,0 +1,5 @@ +TEMPLATE = subdirs + +SUBDIRS = \ + smile \ + textballoons diff --git a/examples/qml/painteditem/smile/main.cpp b/examples/qml/painteditem/smile/main.cpp new file mode 100644 index 0000000000..1c7888b10b --- /dev/null +++ b/examples/qml/painteditem/smile/main.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 Nokia Corporation 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 <QGuiApplication> +#include <QPainter> +#include <QtQml/qqml.h> +#include <QtQuick/qquickview.h> +#include <QtQuick/qquickpainteditem.h> +class MyPaintItem : public QQuickPaintedItem +{ + Q_OBJECT + Q_PROPERTY(QString face READ face WRITE setFace NOTIFY faceChanged) +public: + MyPaintItem() + : QQuickPaintedItem() + , m_face(QLatin1String(":-)")) + { + setAntialiasing(true); + } + QString face() const {return m_face;} + void setFace(const QString &face) { + if (m_face != face) { + m_face = face; + emit faceChanged(); + } + } + virtual void paint(QPainter *p) + { + QRectF rect(0, 0, width(), height()); + rect.adjust(10, 10, -10, -10); + p->setPen(QPen(Qt::black, 20)); + p->setBrush(Qt::yellow); + p->drawEllipse(rect); + p->setPen(Qt::black); + p->setFont(QFont(QLatin1String("Times"), qRound(rect.height() / 2))); + p->drawText(rect, Qt::AlignCenter, m_face); + } +signals: + void faceChanged(); +private: + QString m_face; +}; + +int main(int argc, char ** argv) +{ + QGuiApplication app(argc, argv); + + qmlRegisterType<MyPaintItem>("MyModule", 1, 0, "MyPaintItem"); + + QQuickView view; + view.setResizeMode(QQuickView::SizeRootObjectToView); + view.setSource(QUrl::fromLocalFile("smile.qml")); + view.show(); + view.raise(); + + return app.exec(); +} + +#include "main.moc" diff --git a/examples/qml/painteditem/smile/smile.pro b/examples/qml/painteditem/smile/smile.pro new file mode 100644 index 0000000000..b1af4ee0ad --- /dev/null +++ b/examples/qml/painteditem/smile/smile.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +TARGET = painteditem + +QT += qml quick + +macx: CONFIG -= app_bundle + +SOURCES += main.cpp + +CONFIG += console + diff --git a/examples/qml/painteditem/smile/smile.qml b/examples/qml/painteditem/smile/smile.qml new file mode 100644 index 0000000000..33919bc04f --- /dev/null +++ b/examples/qml/painteditem/smile/smile.qml @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 Nokia Corporation 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import MyModule 1.0 + +Rectangle { + width: 500 + height: 500 + gradient: Gradient { + GradientStop { position: 0.0; color: "#00249a" } + GradientStop { position: 0.7; color: "#ffd94f" } + GradientStop { position: 1.0; color: "#ffa322" } + } + MyPaintItem { + renderTarget:PaintedItem.Image + clip:true + width:240 + height:240 + anchors.left : parent.left + anchors.top :parent.top + anchors.margins: 10 + smooth: true + MouseArea { + anchors.fill:parent + onClicked: { + if (parent.face == ":-)") + parent.face = ":-("; + else + parent.face = ":-)"; + parent.update() + } + } + } + MyPaintItem { + clip:true + renderTarget:PaintedItem.Image + width:240 + height:240 + anchors.right : parent.right + anchors.top :parent.top + anchors.margins: 10 + smooth: true + MouseArea { + anchors.fill:parent + onClicked: { + if (parent.face == ":-)") + parent.face = ":-("; + else + parent.face = ":-)"; + parent.update() + } + } + } + MyPaintItem { + clip:true + renderTarget:PaintedItem.Image + width:240 + height:240 + anchors.left : parent.left + anchors.bottom :parent.bottom + anchors.margins: 10 + smooth: true + MouseArea { + anchors.fill:parent + onClicked: { + if (parent.face == ":-)") + parent.face = ":-("; + else + parent.face = ":-)"; + parent.update() + } + } + } + MyPaintItem { + clip:true + renderTarget:PaintedItem.Image + width:240 + height:240 + anchors.right : parent.right + anchors.bottom :parent.bottom + anchors.margins: 10 + smooth: true + MouseArea { + anchors.fill:parent + onClicked: { + if (parent.face == ":-)") + parent.face = ":-("; + else + parent.face = ":-)"; + parent.update() + } + } + } +}
\ No newline at end of file diff --git a/examples/qml/painteditem/textballoons/TextBalloonPlugin/plugin.h b/examples/qml/painteditem/textballoons/TextBalloonPlugin/plugin.h new file mode 100644 index 0000000000..e6523e15a9 --- /dev/null +++ b/examples/qml/painteditem/textballoons/TextBalloonPlugin/plugin.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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. +** +** 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QQmlExtensionPlugin> + +#include "../textballoon.h" + +class TextBalloonPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT +public: + void registerTypes(const char *uri) + { + qmlRegisterType<TextBalloon>(uri, 1, 0, "TextBalloon"); + } +}; + +Q_EXPORT_PLUGIN2(qmltextballoonplugin, TextBalloonPlugin); diff --git a/examples/qml/painteditem/textballoons/TextBalloonPlugin/qmldir b/examples/qml/painteditem/textballoons/TextBalloonPlugin/qmldir new file mode 100644 index 0000000000..e8a08ae9d3 --- /dev/null +++ b/examples/qml/painteditem/textballoons/TextBalloonPlugin/qmldir @@ -0,0 +1 @@ +plugin qmltextballoonplugin diff --git a/examples/qml/painteditem/textballoons/textballoon.cpp b/examples/qml/painteditem/textballoons/textballoon.cpp new file mode 100644 index 0000000000..d097adfe1b --- /dev/null +++ b/examples/qml/painteditem/textballoons/textballoon.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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. +** +** 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "textballoon.h" + +//! [0] +TextBalloon::TextBalloon(QQuickItem *parent) + : QQuickPaintedItem(parent) + , rightAligned(false) +{ +} +//! [0] + +//! [1] +void TextBalloon::paint(QPainter *painter) +{ + QBrush brush(QColor("#007430")); + + painter->setBrush(brush); + painter->setPen(Qt::NoPen); + painter->setRenderHint(QPainter::Antialiasing); + + painter->drawRoundedRect(0, 0, boundingRect().width(), boundingRect().height() - 10, 10, 10); + + if (rightAligned) + { + const QPointF points[3] = { + QPointF(boundingRect().width() - 10.0, boundingRect().height() - 10.0), + QPointF(boundingRect().width() - 20.0, boundingRect().height()), + QPointF(boundingRect().width() - 30.0, boundingRect().height() - 10.0), + }; + painter->drawConvexPolygon(points, 3); + } + else + { + const QPointF points[3] = { + QPointF(10.0, boundingRect().height() - 10.0), + QPointF(20.0, boundingRect().height()), + QPointF(30.0, boundingRect().height() - 10.0), + }; + painter->drawConvexPolygon(points, 3); + } +} +//! [1] + +bool TextBalloon::isRightAligned() +{ + return this->rightAligned; +} + +void TextBalloon::setRightAligned(bool rightAligned) +{ + this->rightAligned = rightAligned; +} diff --git a/examples/qml/painteditem/textballoons/textballoon.h b/examples/qml/painteditem/textballoons/textballoon.h new file mode 100644 index 0000000000..93ed0a7105 --- /dev/null +++ b/examples/qml/painteditem/textballoons/textballoon.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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. +** +** 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TEXTBALLOON_H +#define TEXTBALLOON_H + +#include <QtQuick> + +//! [0] +class TextBalloon : public QQuickPaintedItem +{ + Q_OBJECT + Q_PROPERTY(bool rightAligned READ isRightAligned WRITE setRightAligned NOTIFY rightAlignedChanged) + + public: + TextBalloon(QQuickItem *parent = 0); + void paint(QPainter *painter); + + bool isRightAligned(); + void setRightAligned(bool rightAligned); + + private: + bool rightAligned; + + signals: + void rightAlignedChanged(); +}; +//! [0] + +#endif diff --git a/examples/qml/painteditem/textballoons/textballoons.pro b/examples/qml/painteditem/textballoons/textballoons.pro new file mode 100644 index 0000000000..9bc0f3c04a --- /dev/null +++ b/examples/qml/painteditem/textballoons/textballoons.pro @@ -0,0 +1,23 @@ +TEMPLATE = lib +CONFIG += qt plugin +QT += qml quick + +TARGET = qmltextballoonplugin + +HEADERS += TextBalloonPlugin/plugin.h \ + textballoon.h + +SOURCES += textballoon.cpp + +DESTDIR = TextBalloonPlugin + +qqmlsources.files += \ + TextBalloonPlugin/qmldir + +qqmlsources.path += $$[QT_INSTALL_EXAMPLES]/qtdeclarative/qml/painteditem/textballoons/TextBalloonPlugin + +sources.files = textballoons.qml +sources.path += $$[QT_INSTALL_EXAMPLES]/qtdeclarative/qml/painteditem/textballoons +target.path += $$[QT_INSTALL_EXAMPLES]/qtdeclarative/qml/painteditem/textballoons/TextBalloonPlugin + +INSTALLS = qqmlsources sources target diff --git a/examples/qml/painteditem/textballoons/textballoons.qml b/examples/qml/painteditem/textballoons/textballoons.qml new file mode 100644 index 0000000000..b00ce2bfed --- /dev/null +++ b/examples/qml/painteditem/textballoons/textballoons.qml @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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. +** +** 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import TextBalloonPlugin 1.0 + +Item { + height: 480 + width: 640 + + //! [0] + ListModel { + id: balloonModel + ListElement { + balloonWidth: 200 + } + ListElement { + balloonWidth: 350 + } + } + + ListView { + anchors.bottom: controls.top + anchors.bottomMargin: 2 + anchors.top: parent.top + id: balloonView + delegate: TextBalloon { + anchors.right: index % 2 == 0 ? undefined : parent.right + height: 60 + rightAligned: index % 2 == 0 ? false : true + width: balloonWidth + } + model: balloonModel + spacing: 5 + width: parent.width + } + //! [0] + + //! [1] + Rectangle { + id: controls + + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.margins: 1 + anchors.right: parent.right + border.width: 2 + color: "white" + height: parent.height * 0.15 + + Text { + anchors.centerIn: parent + text: "Add another balloon" + } + + MouseArea { + anchors.fill: parent + hoverEnabled: true + onClicked: { + balloonModel.append({"balloonWidth": Math.floor(Math.random() * 300 + 100)}) + balloonView.positionViewAtIndex(balloonView.count -1, ListView.End) + } + onEntered: { + parent.color = "#8ac953" + } + onExited: { + parent.color = "white" + } + } + } + //! [1] +} |