aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick/painteditem/textballoons
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-03-05 11:39:24 +1000
committerMatthew Vogt <matthew.vogt@nokia.com>2012-03-05 11:39:54 +1000
commit0284817d6cd7e17afa8da26ee6e9199100754446 (patch)
treec351d55d5a606c81c72e481f846b9b9e2603c883 /examples/quick/painteditem/textballoons
parent377eb94eb19dafeca20d12bc6b624f1779fae514 (diff)
parent36bd7f616f37f5f60e59bce1f0d8970248d627de (diff)
Merge master <-> api_changes
Diffstat (limited to 'examples/quick/painteditem/textballoons')
-rw-r--r--examples/quick/painteditem/textballoons/TextBalloonPlugin/plugin.h55
-rw-r--r--examples/quick/painteditem/textballoons/TextBalloonPlugin/qmldir1
-rw-r--r--examples/quick/painteditem/textballoons/textballoon.cpp92
-rw-r--r--examples/quick/painteditem/textballoons/textballoon.h68
-rw-r--r--examples/quick/painteditem/textballoons/textballoon.json1
-rw-r--r--examples/quick/painteditem/textballoons/textballoons.pro25
-rw-r--r--examples/quick/painteditem/textballoons/textballoons.qml110
7 files changed, 352 insertions, 0 deletions
diff --git a/examples/quick/painteditem/textballoons/TextBalloonPlugin/plugin.h b/examples/quick/painteditem/textballoons/TextBalloonPlugin/plugin.h
new file mode 100644
index 0000000000..c500c1c525
--- /dev/null
+++ b/examples/quick/painteditem/textballoons/TextBalloonPlugin/plugin.h
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** 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
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface" FILE "textballoon.json")
+public:
+ void registerTypes(const char *uri)
+ {
+ qmlRegisterType<TextBalloon>(uri, 1, 0, "TextBalloon");
+ }
+};
diff --git a/examples/quick/painteditem/textballoons/TextBalloonPlugin/qmldir b/examples/quick/painteditem/textballoons/TextBalloonPlugin/qmldir
new file mode 100644
index 0000000000..e8a08ae9d3
--- /dev/null
+++ b/examples/quick/painteditem/textballoons/TextBalloonPlugin/qmldir
@@ -0,0 +1 @@
+plugin qmltextballoonplugin
diff --git a/examples/quick/painteditem/textballoons/textballoon.cpp b/examples/quick/painteditem/textballoons/textballoon.cpp
new file mode 100644
index 0000000000..d097adfe1b
--- /dev/null
+++ b/examples/quick/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/quick/painteditem/textballoons/textballoon.h b/examples/quick/painteditem/textballoons/textballoon.h
new file mode 100644
index 0000000000..93ed0a7105
--- /dev/null
+++ b/examples/quick/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/quick/painteditem/textballoons/textballoon.json b/examples/quick/painteditem/textballoons/textballoon.json
new file mode 100644
index 0000000000..0967ef424b
--- /dev/null
+++ b/examples/quick/painteditem/textballoons/textballoon.json
@@ -0,0 +1 @@
+{}
diff --git a/examples/quick/painteditem/textballoons/textballoons.pro b/examples/quick/painteditem/textballoons/textballoons.pro
new file mode 100644
index 0000000000..d612048ee8
--- /dev/null
+++ b/examples/quick/painteditem/textballoons/textballoons.pro
@@ -0,0 +1,25 @@
+TEMPLATE = lib
+CONFIG += qt plugin
+QT += qml quick
+
+TARGET = qmltextballoonplugin
+
+HEADERS += TextBalloonPlugin/plugin.h \
+ textballoon.h
+
+SOURCES += textballoon.cpp
+
+OTHER_FILES += textballoon.json
+
+DESTDIR = TextBalloonPlugin
+
+qdeclarativesources.files += \
+ TextBalloonPlugin/qmldir
+
+qdeclarativesources.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 = qdeclarativesources sources target
diff --git a/examples/quick/painteditem/textballoons/textballoons.qml b/examples/quick/painteditem/textballoons/textballoons.qml
new file mode 100644
index 0000000000..b00ce2bfed
--- /dev/null
+++ b/examples/quick/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]
+}