summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-12-22 09:43:41 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-12-22 09:43:41 (GMT)
commitedaae2daf2637e2f446e0fd462d85ca21234426e (patch)
treee997639c36f34c27491ef94ee8a83629f79f2e2a
parent481a636a5a2f3a5a52b752dd59435e7c3e5455d3 (diff)
parente180de35280e48ded1c22b519d6d36f30cf5100d (diff)
downloadQt-edaae2daf2637e2f446e0fd462d85ca21234426e.zip
Qt-edaae2daf2637e2f446e0fd462d85ca21234426e.tar.gz
Qt-edaae2daf2637e2f446e0fd462d85ca21234426e.tar.bz2
Merge branch 'kinetic-declarativeui' of scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r--examples/declarative/loader/Browser.qml232
-rw-r--r--examples/declarative/loader/Button.qml16
-rw-r--r--examples/declarative/loader/images/folder.pngbin1841 -> 0 bytes
-rw-r--r--examples/declarative/loader/images/titlebar.pngbin1436 -> 0 bytes
-rw-r--r--examples/declarative/loader/images/titlebar.sci5
-rw-r--r--examples/declarative/loader/images/up.pngbin662 -> 0 bytes
-rw-r--r--examples/declarative/loader/loader.pro19
-rw-r--r--examples/declarative/loader/loader.qml10
-rw-r--r--examples/declarative/loader/loader.qrc11
-rw-r--r--examples/declarative/loader/main.cpp287
-rw-r--r--examples/declarative/loader/qmlfolderlistmodel.cpp388
-rw-r--r--examples/declarative/loader/qmlfolderlistmodel.h118
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsanchors.cpp12
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsanchors_p.h4
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h4
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsflickable.cpp14
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h7
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsgridview.cpp47
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsitem_p.h3
-rw-r--r--src/declarative/graphicsitems/qmlgraphicstext.cpp57
-rw-r--r--src/declarative/graphicsitems/qmlgraphicstext_p.h3
-rw-r--r--src/declarative/graphicsitems/qmlgraphicstext_p_p.h1
-rw-r--r--src/declarative/qml/qmlbasicscript.cpp17
-rw-r--r--src/declarative/qml/qmlbasicscript_p.h2
-rw-r--r--src/declarative/qml/qmlbinding.h2
-rw-r--r--src/declarative/qml/qmlbindingoptimizations.cpp71
-rw-r--r--src/declarative/qml/qmlbindingoptimizations_p.h26
-rw-r--r--src/declarative/qml/qmlbindingvme.cpp5
-rw-r--r--src/declarative/qml/qmlcompiler.cpp21
-rw-r--r--src/declarative/qml/qmldom.cpp17
-rw-r--r--src/declarative/qml/qmldom.h3
-rw-r--r--src/declarative/qml/qmlinstruction.cpp3
-rw-r--r--src/declarative/qml/qmlinstruction_p.h1
-rw-r--r--src/declarative/qml/qmlvme.cpp19
-rw-r--r--src/declarative/qml/qpodvector_p.h4
-rw-r--r--src/declarative/util/qmlstyledtext.cpp356
-rw-r--r--src/declarative/util/qmlstyledtext_p.h63
-rw-r--r--src/declarative/util/util.pri6
-rw-r--r--tests/benchmarks/declarative/creation/tst_creation.cpp29
39 files changed, 581 insertions, 1302 deletions
diff --git a/examples/declarative/loader/Browser.qml b/examples/declarative/loader/Browser.qml
deleted file mode 100644
index f3a1182..0000000
--- a/examples/declarative/loader/Browser.qml
+++ /dev/null
@@ -1,232 +0,0 @@
-import Qt 4.6
-
-Rectangle {
- id: root
- property bool keyPressed: false
- property var folders: folders1
- property var view: view1
- width: parent.width
- height: parent.height
- color: palette.window
- FolderListModel {
- id: folders1
- nameFilters: [ "*.qml" ]
- folder: "file:///E:/" // Documents on your S60 phone (or Windows E: drive)
- }
- FolderListModel {
- id: folders2
- nameFilters: [ "*.qml" ]
- folder: "file:///E:/" // Documents on your S60 phone (or Windows E: drive)
- }
-
- SystemPalette { id: palette }
-
- Script {
- function down(path) {
- if (folders == folders1) {
- view = view2
- folders = folders2;
- view1.state = "exitLeft";
- } else {
- view = view1
- folders = folders1;
- view2.state = "exitLeft";
- }
- view.x = root.width;
- view.state = "current";
- folders.folder = path;
- }
- function up() {
- var path = folders.parentFolder;
- if (folders == folders1) {
- view = view2
- folders = folders2;
- view1.state = "exitRight";
- } else {
- view = view1
- folders = folders1;
- view2.state = "exitRight";
- }
- view.x = -root.width;
- view.state = "current";
- folders.folder = path;
- }
- }
-
- Component {
- id: folderDelegate
- Rectangle {
- id: wrapper
- function launch() {
- if (folders.isFolder(index)) {
- down(filePath);
- } else {
- qmlLauncher.launch(filePath);
- }
- }
- width: root.width
- height: 48
- color: "transparent"
- Rectangle {
- id: highlight; visible: false
- anchors.fill: parent
- gradient: Gradient {
- GradientStop { id: t1; position: 0.0; color: palette.highlight }
- GradientStop { id: t2; position: 1.0; color: Qt.lighter(palette.highlight) }
- }
- }
- Item {
- width: 46; height: 46
- Image { source: "images/folder.png"; anchors.centerIn: parent; visible: folders.isFolder(index)}
- }
- Text {
- id: nameText
- anchors.fill: parent; verticalAlignment: Text.AlignVCenter
- text: fileName; anchors.leftMargin: 48
- font.pixelSize: 32
- color: wrapper.isCurrentItem ? palette.highlightedText : palette.text
- }
- MouseRegion {
- id: mouseRegion
- anchors.fill: parent
- onClicked: { launch() }
- }
- states: [
- State {
- name: "pressed"
- when: mouseRegion.pressed
- PropertyChanges { target: highlight; visible: true }
- PropertyChanges { target: nameText; color: palette.highlightedText }
- }
- ]
- }
- }
-
- ListView {
- id: view1
- anchors.top: titleBar.bottom
- anchors.bottom: parent.bottom
- x: 0
- width: parent.width
- model: folders1
- delegate: folderDelegate
- highlight: Rectangle { color: palette.highlight; visible: root.keyPressed }
- focus: true
- pressDelay: 100
- state: "current"
- states: [
- State {
- name: "current"
- PropertyChanges { target: view1; x: 0 }
- },
- State {
- name: "exitLeft"
- PropertyChanges { target: view1; x: -root.width }
- },
- State {
- name: "exitRight"
- PropertyChanges { target: view1; x: root.width }
- }
- ]
- transitions: [
- Transition {
- to: "current"
- SequentialAnimation {
- NumberAnimation { matchProperties: "x"; duration: 250 }
- }
- },
- Transition {
- NumberAnimation { matchProperties: "x"; duration: 250 }
- NumberAnimation { matchProperties: "x"; duration: 250 }
- }
- ]
- }
-
- ListView {
- id: view2
- anchors.top: titleBar.bottom
- anchors.bottom: parent.bottom
- x: parent.width
- width: parent.width
- model: folders2
- delegate: folderDelegate
- highlight: Rectangle { color: palette.highlight; visible: root.keyPressed }
- focus: true
- pressDelay: 100
- states: [
- State {
- name: "current"
- PropertyChanges { target: view2; x: 0 }
- },
- State {
- name: "exitLeft"
- PropertyChanges { target: view2; x: -root.width }
- },
- State {
- name: "exitRight"
- PropertyChanges { target: view2; x: root.width }
- }
- ]
- transitions: [
- Transition {
- to: "current"
- SequentialAnimation {
- NumberAnimation { matchProperties: "x"; duration: 250 }
- }
- },
- Transition {
- NumberAnimation { matchProperties: "x"; duration: 250 }
- }
- ]
- }
-
- Keys.onPressed: {
- root.keyPressed = true;
- if (event.key == Qt.Key_Return || event.key == Qt.Key_Select || event.key == Qt.Key_Right) {
- view.currentItem.launch();
- event.accepted = true;
- }
- }
- Keys.onLeftPressed: up()
-
- BorderImage {
- source: "images/titlebar.sci";
- width: parent.width;
- height: 48
- y: -7
- id: titleBar
-
- Rectangle {
- id: upButton
- width: 40
- height: titleBar.height - 7
- color: "transparent"
-
- Image { anchors.centerIn: parent; source: "images/up.png" }
- MouseRegion { id: upRegion; anchors.fill: parent
- onClicked: if (folders.parentFolder != "") up()
- }
- states: [
- State {
- name: "pressed"
- when: upRegion.pressed
- PropertyChanges { target: upButton; color: palette.highlightedText }
- }
- ]
- }
- Rectangle {
- color: "gray"
- x: 40
- width: 1
- height: 40
- }
-
- Text {
- anchors.left: upButton.right; anchors.right: parent.right; height: parent.height
- anchors.leftMargin: 4; anchors.rightMargin: 4
- text: folders.folder; color: "white"
- elide: Text.ElideLeft; horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter
- font.pixelSize: 32
- }
- }
-}
diff --git a/examples/declarative/loader/Button.qml b/examples/declarative/loader/Button.qml
deleted file mode 100644
index 928ff06..0000000
--- a/examples/declarative/loader/Button.qml
+++ /dev/null
@@ -1,16 +0,0 @@
-import Qt 4.6
-
-Rectangle {
- id: container
-
- property var text
- signal clicked
-
- height: text.height + 10
- width: text.width + 20
- border.width: 1
- radius: 4
- color: "grey"
- MouseRegion { anchors.fill: parent; onClicked: container.clicked() }
- Text { id: text; anchors.centerIn:parent; font.pointSize: 10; text: parent.text }
-}
diff --git a/examples/declarative/loader/images/folder.png b/examples/declarative/loader/images/folder.png
deleted file mode 100644
index e53e2ad..0000000
--- a/examples/declarative/loader/images/folder.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/loader/images/titlebar.png b/examples/declarative/loader/images/titlebar.png
deleted file mode 100644
index 51c9008..0000000
--- a/examples/declarative/loader/images/titlebar.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/loader/images/titlebar.sci b/examples/declarative/loader/images/titlebar.sci
deleted file mode 100644
index 0418d94..0000000
--- a/examples/declarative/loader/images/titlebar.sci
+++ /dev/null
@@ -1,5 +0,0 @@
-border.left: 10
-border.top: 12
-border.bottom: 12
-border.right: 10
-source: titlebar.png
diff --git a/examples/declarative/loader/images/up.png b/examples/declarative/loader/images/up.png
deleted file mode 100644
index b05f802..0000000
--- a/examples/declarative/loader/images/up.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/loader/loader.pro b/examples/declarative/loader/loader.pro
deleted file mode 100644
index 84b2d21..0000000
--- a/examples/declarative/loader/loader.pro
+++ /dev/null
@@ -1,19 +0,0 @@
-SOURCES = main.cpp qmlfolderlistmodel.cpp
-HEADERS = qmlfolderlistmodel.h
-RESOURCES = loader.qrc
-
-QT += script declarative network
-
-target.path = $$[QT_INSTALL_EXAMPLES]/declarative/loader
-sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS loader.pro
-sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/loader
-INSTALLS += target sources
-
-symbian {
-# TARGET.UID3 =
- include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
- TARGET.EPOCHEAPSIZE = 0x20000 0x2000000
- HEADERS += $$QT_SOURCE_TREE/examples/network/qftp/sym_iap_util.h
- LIBS += -lesock -lconnmon -linsock
- TARGET.CAPABILITY = NetworkServices
-}
diff --git a/examples/declarative/loader/loader.qml b/examples/declarative/loader/loader.qml
deleted file mode 100644
index 319db84..0000000
--- a/examples/declarative/loader/loader.qml
+++ /dev/null
@@ -1,10 +0,0 @@
-import Qt 4.6
-
-Rectangle {
- width: 300
- height: 400
- Loader {
- anchors.fill: parent
- source: "Browser.qml"
- }
-}
diff --git a/examples/declarative/loader/loader.qrc b/examples/declarative/loader/loader.qrc
deleted file mode 100644
index 94d7b92..0000000
--- a/examples/declarative/loader/loader.qrc
+++ /dev/null
@@ -1,11 +0,0 @@
-<RCC>
- <qresource prefix="/" >
- <file>loader.qml</file>
- <file>Browser.qml</file>
- <file>images/up.png</file>
- <file>Button.qml</file>
- <file>images/folder.png</file>
- <file>images/titlebar.sci</file>
- <file>images/titlebar.png</file>
- </qresource>
-</RCC>
diff --git a/examples/declarative/loader/main.cpp b/examples/declarative/loader/main.cpp
deleted file mode 100644
index 22e3646..0000000
--- a/examples/declarative/loader/main.cpp
+++ /dev/null
@@ -1,287 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include <QApplication>
-#include <QUrl>
-#include <QFileInfo>
-#include <QDir>
-#include <QPlainTextEdit>
-#include <QAction>
-#include <QVBoxLayout>
-#include <QMainWindow>
-#include <QMenuBar>
-#include <QDebug>
-#include <QmlContext>
-#include <QmlComponent>
-#include <QmlEngine>
-#include <qmlview.h>
-#include <QDebug>
-#include <QNetworkDiskCache>
-#include <QNetworkAccessManager>
-#include <QtCore>
-
-#if defined (Q_OS_SYMBIAN)
-#define SYMBIAN_NETWORK_INIT
-#endif
-
-#if defined (SYMBIAN_NETWORK_INIT)
-#include "sym_iap_util.h"
-#endif
-
-QmlView *canvas = 0;
-
-class Logger : public QWidget
-{
- Q_OBJECT
-public:
- Logger() : QWidget() {
- logText = new QPlainTextEdit;
- QVBoxLayout *layout = new QVBoxLayout;
- layout->addWidget(logText);
- layout->setMargin(0);
- setLayout(layout);
-#ifdef Q_OS_SYMBIAN
- QAction *closeAction = new QAction("Close", this);
- closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
- connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
- addAction(closeAction);
-#endif
- connect(logText, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
- }
-
- void append(const QString &text) {
- logText->appendPlainText(text);
- }
-
- static Logger *instance() {
- static Logger *logger = 0;
- if (!logger)
- logger = new Logger();
- return logger;
- }
-
-signals:
- void textChanged();
-
-private:
- QPlainTextEdit *logText;
-};
-
-void myMessageOutput(QtMsgType type, const char *msg)
-{
- switch (type) {
- case QtDebugMsg:
- Logger::instance()->append(QString(msg));
- break;
- case QtWarningMsg:
- Logger::instance()->append(QString(msg));
- break;
- case QtCriticalMsg:
- Logger::instance()->append(QString(msg));
- break;
- case QtFatalMsg:
- Logger::instance()->append(QString(msg));
- abort();
- }
-}
-
-
-class QmlLauncher : public QObject
-{
- Q_OBJECT
-public:
- QmlLauncher() {}
-
- Q_INVOKABLE void launch(const QString &fileName)
- {
- m_fileName = fileName;
- QMetaObject::invokeMethod(this, "doLaunch", Qt::QueuedConnection);
- }
-
-private slots:
- void doLaunch()
- {
- qDebug() << "dolaunch";
- QUrl url(m_fileName);
- QFileInfo fi(url.toLocalFile());
- if (fi.exists()) {
- canvas->reset();
-
- url = QUrl::fromLocalFile(fi.absoluteFilePath());
- QmlContext *ctxt = canvas->rootContext();
- QDir dir(fi.path()+"/dummydata", "*.qml");
- QStringList list = dir.entryList();
- for (int i = 0; i < list.size(); ++i) {
- QString qml = list.at(i);
- QFile f(dir.filePath(qml));
- f.open(QIODevice::ReadOnly);
- QByteArray data = f.readAll();
- QmlComponent comp(canvas->engine());
- comp.setData(data, QUrl());
- QObject *dummyData = comp.create();
-
- if(comp.isError()) {
- QList<QmlError> errors = comp.errors();
- foreach (const QmlError &error, errors) {
- qWarning() << error;
- }
- }
-
- if (dummyData) {
- qml.truncate(qml.length()-4);
- ctxt->setContextProperty(qml, dummyData);
- dummyData->setParent(this);
- }
- }
-
- canvas->setUrl(url);
- canvas->execute();
- }
- }
-
-signals:
- void logUpdated();
-
-private:
- QString m_fileName;
-};
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-public:
- MainWindow() : QMainWindow()
- {
- }
-
-public slots:
- void toggleFullScreen()
- {
- if (isFullScreen()) {
-#ifdef Q_OS_SYMBIAN
- showMaximized();
-#else
- showNormal();
-#endif
- } else {
- showFullScreen();
- }
- }
-
- void showLog()
- {
-#ifdef Q_OS_SYMBIAN
- Logger::instance()->showMaximized();
-#else
- Logger::instance()->show();
-#endif
- }
-
- void enableNetwork()
- {
-#if defined(SYMBIAN_NETWORK_INIT)
- qt_SetDefaultIap();
-#endif
- }
-};
-
-class ConfiguredNetworkAccessManager : public QNetworkAccessManager {
-public:
- ConfiguredNetworkAccessManager()
- {
- QNetworkDiskCache *cache = new QNetworkDiskCache;
- cache->setCacheDirectory(QDir::tempPath()+QLatin1String("/qml-loader-network-cache"));
- setCache(cache);
- }
-
- QNetworkReply *createRequest (Operation op, const QNetworkRequest &req, QIODevice * outgoingData)
- {
- QNetworkRequest request = req;
- request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
- request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
- return QNetworkAccessManager::createRequest(op,request,outgoingData);
- }
-};
-
-
-int main(int argc, char *argv[])
-{
- qInstallMsgHandler(myMessageOutput);
- QApplication app(argc, argv);
-
- MainWindow *mw = new MainWindow;
-
- QmlLauncher *launcher = new QmlLauncher;
-
- QObject::connect(Logger::instance(), SIGNAL(textChanged()), launcher, SIGNAL(logUpdated()));
-
- canvas = new QmlView;
- canvas->setFocusPolicy(Qt::StrongFocus);
- canvas->engine()->setNetworkAccessManager(new ConfiguredNetworkAccessManager);
-
- QMenuBar *mb = mw->menuBar();
- QAction *showLogAction = new QAction("View Log...", mw);
- mb->addAction(showLogAction);
- QObject::connect(showLogAction, SIGNAL(triggered()), mw, SLOT(showLog()));
- QAction *toggleFSAction = new QAction("Fullscreen", mw);
- mb->addAction(toggleFSAction);
- QObject::connect(toggleFSAction, SIGNAL(triggered()), mw, SLOT(toggleFullScreen()));
-#if defined(SYMBIAN_NETWORK_INIT)
- QAction *enableNetworkAction = new QAction("Enable Network", mw);
- mb->addAction(enableNetworkAction);
- QObject::connect(enableNetworkAction, SIGNAL(triggered()), mw, SLOT(enableNetwork()));
-#endif
-
- QmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("qmlLauncher", launcher);
- canvas->setUrl(QUrl("qrc:/loader.qml"));
-#ifdef Q_OS_SYMBIAN
- canvas->setContentResizable(true);
- mw->showMaximized();
-#else
- mw->show();
-#endif
- canvas->execute();
- mw->setCentralWidget(canvas);
-
- return app.exec();
-}
-
-#include "main.moc"
diff --git a/examples/declarative/loader/qmlfolderlistmodel.cpp b/examples/declarative/loader/qmlfolderlistmodel.cpp
deleted file mode 100644
index 14d2324..0000000
--- a/examples/declarative/loader/qmlfolderlistmodel.cpp
+++ /dev/null
@@ -1,388 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmlfolderlistmodel.h"
-#include <QDirModel>
-#include <QDebug>
-#include <QtDeclarative/qmlcontext.h>
-
-class QmlFolderListModelPrivate
-{
-public:
- QmlFolderListModelPrivate()
- : sortField(QmlFolderListModel::Name), sortReversed(false), count(0) {
- nameFilters << QLatin1String("*");
- }
-
- void updateSorting() {
- QDir::SortFlags flags = 0;
- switch(sortField) {
- case QmlFolderListModel::Unsorted:
- flags |= QDir::Unsorted;
- break;
- case QmlFolderListModel::Name:
- flags |= QDir::Name;
- break;
- case QmlFolderListModel::Time:
- flags |= QDir::Time;
- break;
- case QmlFolderListModel::Size:
- flags |= QDir::Size;
- break;
- case QmlFolderListModel::Type:
- flags |= QDir::Type;
- break;
- }
-
- if (sortReversed)
- flags |= QDir::Reversed;
-
- model.setSorting(flags);
- }
-
- QDirModel model;
- QUrl folder;
- QStringList nameFilters;
- QModelIndex folderIndex;
- QmlFolderListModel::SortField sortField;
- bool sortReversed;
- int count;
-};
-
-/*!
- \qmlclass FolderListModel
- \brief The FolderListModel provides a model of the contents of a folder in a filesystem.
-
- FolderListModel provides access to the local filesystem. The \e folder property
- specifies the folder to list.
-
- Qt uses "/" as a universal directory separator in the same way that "/" is
- used as a path separator in URLs. If you always use "/" as a directory
- separator, Qt will translate your paths to conform to the underlying
- operating system.
-
- The roles available are:
- \list
- \o fileName
- \o filePath
- \endlist
-
- Additionally a file entry can be differentiated from a folder entry
- via the \l isFolder() method.
-*/
-
-QmlFolderListModel::QmlFolderListModel(QObject *parent)
- : QListModelInterface(parent)
-{
- d = new QmlFolderListModelPrivate;
- d->model.setFilter(QDir::AllDirs | QDir::Files | QDir::Drives | QDir::NoDotAndDotDot);
- connect(&d->model, SIGNAL(rowsInserted(const QModelIndex&,int,int))
- , this, SLOT(inserted(const QModelIndex&,int,int)));
- connect(&d->model, SIGNAL(rowsRemoved(const QModelIndex&,int,int))
- , this, SLOT(removed(const QModelIndex&,int,int)));
- connect(&d->model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&))
- , this, SLOT(dataChanged(const QModelIndex&,const QModelIndex&)));
- connect(&d->model, SIGNAL(modelReset()), this, SLOT(refresh()));
- connect(&d->model, SIGNAL(layoutChanged()), this, SLOT(refresh()));
-}
-
-QmlFolderListModel::~QmlFolderListModel()
-{
- delete d;
-}
-
-QHash<int,QVariant> QmlFolderListModel::data(int index, const QList<int> &roles) const
-{
- Q_UNUSED(roles);
- QHash<int,QVariant> folderData;
- QModelIndex modelIndex = d->model.index(index, 0, d->folderIndex);
- if (modelIndex.isValid()) {
- folderData[QDirModel::FileNameRole] = d->model.data(modelIndex, QDirModel::FileNameRole);
- folderData[QDirModel::FilePathRole] = QUrl::fromLocalFile(d->model.data(modelIndex, QDirModel::FilePathRole).toString());
- }
-
- return folderData;
-}
-
-int QmlFolderListModel::count() const
-{
- return d->count;
-}
-
-QList<int> QmlFolderListModel::roles() const
-{
- QList<int> r;
- r << QDirModel::FileNameRole;
- r << QDirModel::FilePathRole;
- return r;
-}
-
-QString QmlFolderListModel::toString(int role) const
-{
- switch (role) {
- case QDirModel::FileNameRole:
- return QLatin1String("fileName");
- case QDirModel::FilePathRole:
- return QLatin1String("filePath");
- }
-
- return QString();
-}
-
-/*!
- \qmlproperty string FolderListModel::folder
-
- The \a folder property holds the folder the model is currently providing.
-
- It is a URL, but must be a file: or qrc: URL (or relative to such a URL).
-*/
-QUrl QmlFolderListModel::folder() const
-{
- return d->folder;
-}
-
-void QmlFolderListModel::setFolder(const QUrl &folder)
-{
- if (folder == d->folder)
- return;
- QModelIndex index = d->model.index(folder.toLocalFile());
- if (index.isValid() && d->model.isDir(index)) {
- d->folder = folder;
- QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection);
- emit folderChanged();
- }
-}
-
-QUrl QmlFolderListModel::parentFolder() const
-{
- int pos = d->folder.path().lastIndexOf(QLatin1Char('/'));
- if (pos == -1)
- return QUrl();
- QUrl r = d->folder;
- r.setPath(d->folder.path().left(pos));
- return r;
-}
-
-/*!
- \qmlproperty list<string> FolderListModel::nameFilters
-
- The \a nameFilters property contains a list of filename filters.
- The filters may include the ? and * wildcards.
-
- The example below filters on PNG and JPEG files:
-
- \code
- FolderListModel {
- nameFilters: [ "*.png", "*.jpg" ]
- }
- \endcode
-*/
-QStringList QmlFolderListModel::nameFilters() const
-{
- return d->nameFilters;
-}
-
-void QmlFolderListModel::setNameFilters(const QStringList &filters)
-{
- d->nameFilters = filters;
- d->model.setNameFilters(d->nameFilters);
-}
-
-void QmlFolderListModel::componentComplete()
-{
- if (!d->folder.isValid() || !QDir().exists(d->folder.toLocalFile()))
- setFolder(QUrl(QLatin1String("file://")+QDir::currentPath()));
-
- if (!d->folderIndex.isValid())
- QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection);
-}
-
-QmlFolderListModel::SortField QmlFolderListModel::sortField() const
-{
- return d->sortField;
-}
-
-void QmlFolderListModel::setSortField(SortField field)
-{
- if (field != d->sortField) {
- d->sortField = field;
- d->updateSorting();
- }
-}
-
-bool QmlFolderListModel::sortReversed() const
-{
- return d->sortReversed;
-}
-
-void QmlFolderListModel::setSortReversed(bool rev)
-{
- if (rev != d->sortReversed) {
- d->sortReversed = rev;
- d->updateSorting();
- }
-}
-
-/*!
- \qmlmethod bool FolderListModel::isFolder(int index)
-
- Returns true if the entry \a index is a folder; otherwise
- returns false.
-*/
-bool QmlFolderListModel::isFolder(int index) const
-{
- if (index != -1) {
- QModelIndex idx = d->model.index(index, 0, d->folderIndex);
- if (idx.isValid())
- return d->model.isDir(idx);
- }
- return false;
-}
-
-void QmlFolderListModel::refresh()
-{
- d->folderIndex = QModelIndex();
- if (d->count) {
- int tmpCount = d->count;
- d->count = 0;
- emit itemsRemoved(0, tmpCount);
- }
- d->folderIndex = d->model.index(d->folder.toLocalFile());
- d->count = d->model.rowCount(d->folderIndex);
- if (d->count) {
- emit itemsInserted(0, d->count);
- }
-}
-
-void QmlFolderListModel::inserted(const QModelIndex &index, int start, int end)
-{
- if (index == d->folderIndex) {
- d->count = d->model.rowCount(d->folderIndex);
- emit itemsInserted(start, end - start + 1);
- }
-}
-
-void QmlFolderListModel::removed(const QModelIndex &index, int start, int end)
-{
- if (index == d->folderIndex) {
- d->count = d->model.rowCount(d->folderIndex);
- emit itemsRemoved(start, end - start + 1);
- }
-}
-
-void QmlFolderListModel::dataChanged(const QModelIndex &start, const QModelIndex &end)
-{
- qDebug() << "data changed";
- if (start.parent() == d->folderIndex)
- emit itemsChanged(start.row(), end.row() - start.row() + 1, roles());
-}
-
-/*!
- \qmlproperty bool FolderListModel::showDirs
-
- If true (the default), directories are included in the model.
-
- Note that the nameFilters are ignored for directories.
-*/
-bool QmlFolderListModel::showDirs() const
-{
- return d->model.filter() & QDir::AllDirs;
-}
-
-void QmlFolderListModel::setShowDirs(bool on)
-{
- if (!(d->model.filter() & QDir::AllDirs) == !on)
- return;
- if (on)
- d->model.setFilter(d->model.filter() | QDir::AllDirs | QDir::Drives);
- else
- d->model.setFilter(d->model.filter() & ~(QDir::AllDirs | QDir::Drives));
-}
-
-/*!
- \qmlproperty bool FolderListModel::showDotAndDotDot
-
- If true, the "." and ".." directories are included in the model.
-
- The default is false.
-*/
-bool QmlFolderListModel::showDotAndDotDot() const
-{
- return !(d->model.filter() & QDir::NoDotAndDotDot);
-}
-
-void QmlFolderListModel::setShowDotAndDotDot(bool on)
-{
- if (!(d->model.filter() & QDir::NoDotAndDotDot) == on)
- return;
- if (on)
- d->model.setFilter(d->model.filter() & ~QDir::NoDotAndDotDot);
- else
- d->model.setFilter(d->model.filter() | QDir::NoDotAndDotDot);
-}
-
-/*!
- \qmlproperty bool FolderListModel::showOnlyReadable
-
- If true, only readable files and directories are shown.
-
- The default is false.
-*/
-bool QmlFolderListModel::showOnlyReadable() const
-{
- return d->model.filter() & QDir::Readable;
-}
-
-void QmlFolderListModel::setShowOnlyReadable(bool on)
-{
- if (!(d->model.filter() & QDir::Readable) == !on)
- return;
- if (on)
- d->model.setFilter(d->model.filter() | QDir::Readable);
- else
- d->model.setFilter(d->model.filter() & ~QDir::Readable);
-}
-
-
-QML_DEFINE_TYPE(Qt,4,6,FolderListModel,QmlFolderListModel)
-
-QT_END_NAMESPACE
-
diff --git a/examples/declarative/loader/qmlfolderlistmodel.h b/examples/declarative/loader/qmlfolderlistmodel.h
deleted file mode 100644
index ac9568f..0000000
--- a/examples/declarative/loader/qmlfolderlistmodel.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMLFOLDERLISTMODEL_H
-#define QMLFOLDERLISTMODEL_H
-
-#include <qml.h>
-#include "../../../src/declarative/3rdparty/qlistmodelinterface_p.h"
-
-class QmlContext;
-class QModelIndex;
-
-class QmlFolderListModelPrivate;
-class QmlFolderListModel : public QListModelInterface, public QmlParserStatus
-{
- Q_OBJECT
- Q_INTERFACES(QmlParserStatus)
-
- Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged)
- Q_PROPERTY(QUrl parentFolder READ parentFolder NOTIFY folderChanged)
- Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters)
- Q_PROPERTY(SortField sortField READ sortField WRITE setSortField)
- Q_PROPERTY(bool sortReversed READ sortReversed WRITE setSortReversed)
- Q_PROPERTY(bool showDirs READ showDirs WRITE setShowDirs)
- Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot)
- Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable)
-
-public:
- QmlFolderListModel(QObject *parent = 0);
- ~QmlFolderListModel();
-
- virtual QHash<int,QVariant> data(int index, const QList<int> &roles = (QList<int>())) const;
- virtual int count() const;
- virtual QList<int> roles() const;
- virtual QString toString(int role) const;
-
- QUrl folder() const;
- void setFolder(const QUrl &folder);
-
- QUrl parentFolder() const;
-
- QStringList nameFilters() const;
- void setNameFilters(const QStringList &filters);
-
- virtual void componentComplete();
-
- Q_INVOKABLE bool isFolder(int index) const;
-
- enum SortField { Unsorted, Name, Time, Size, Type };
- SortField sortField() const;
- void setSortField(SortField field);
- Q_ENUMS(SortField)
-
- bool sortReversed() const;
- void setSortReversed(bool rev);
-
- bool showDirs() const;
- void setShowDirs(bool);
- bool showDotAndDotDot() const;
- void setShowDotAndDotDot(bool);
- bool showOnlyReadable() const;
- void setShowOnlyReadable(bool);
-
-Q_SIGNALS:
- void folderChanged();
-
-private Q_SLOTS:
- void refresh();
- void inserted(const QModelIndex &index, int start, int end);
- void removed(const QModelIndex &index, int start, int end);
- void dataChanged(const QModelIndex &start, const QModelIndex &end);
-
-private:
- Q_DISABLE_COPY(QmlFolderListModel)
- QmlFolderListModelPrivate *d;
-};
-
-QML_DECLARE_TYPE(QmlFolderListModel)
-
-#endif // QMLFOLDERLISTMODEL_H
diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp
index c2e1fa2..ddf2a3b 100644
--- a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp
@@ -50,7 +50,7 @@
QT_BEGIN_NAMESPACE
-QML_DEFINE_TYPE(Qt,4,6,Anchors,QmlGraphicsAnchors)
+QML_DEFINE_NOCREATE_TYPE(QmlGraphicsAnchors)
//TODO: should we cache relationships, so we don't have to check each time (parent-child or sibling)?
//TODO: support non-parent, non-sibling (need to find lowest common ancestor)
@@ -131,8 +131,8 @@ static qreal adjustedPosition(QmlGraphicsItem *item, QmlGraphicsAnchorLine::Anch
\warning Currently, only anchoring to siblings or parent is supported.
*/
-QmlGraphicsAnchors::QmlGraphicsAnchors(QObject *parent)
- : QObject(*new QmlGraphicsAnchorsPrivate(), parent)
+QmlGraphicsAnchors::QmlGraphicsAnchors(QmlGraphicsItem *item, QObject *parent)
+ : QObject(*new QmlGraphicsAnchorsPrivate(item), parent)
{
}
@@ -980,12 +980,6 @@ QmlGraphicsAnchors::UsedAnchors QmlGraphicsAnchors::usedAnchors() const
return d->usedAnchors;
}
-void QmlGraphicsAnchors::setItem(QmlGraphicsItem *item)
-{
- Q_D(QmlGraphicsAnchors);
- d->item = item;
-}
-
bool QmlGraphicsAnchorsPrivate::checkHValid() const
{
if (usedAnchors & QmlGraphicsAnchors::HasLeftAnchor &&
diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors_p.h b/src/declarative/graphicsitems/qmlgraphicsanchors_p.h
index a67a9f8..dc6a7a8 100644
--- a/src/declarative/graphicsitems/qmlgraphicsanchors_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicsanchors_p.h
@@ -79,7 +79,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsAnchors : public QObject
Q_PROPERTY(QmlGraphicsItem *centerIn READ centerIn WRITE setCenterIn RESET resetCenterIn NOTIFY centerInChanged)
public:
- QmlGraphicsAnchors(QObject *parent=0);
+ QmlGraphicsAnchors(QmlGraphicsItem *item, QObject *parent=0);
virtual ~QmlGraphicsAnchors();
enum UsedAnchor {
@@ -157,8 +157,6 @@ public:
UsedAnchors usedAnchors() const;
- void setItem(QmlGraphicsItem *item);
-
void classBegin();
void componentComplete();
diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h b/src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h
index 45c983f..5b02158 100644
--- a/src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h
@@ -95,9 +95,9 @@ class QmlGraphicsAnchorsPrivate : public QObjectPrivate, public QmlGraphicsItemC
{
Q_DECLARE_PUBLIC(QmlGraphicsAnchors)
public:
- QmlGraphicsAnchorsPrivate()
+ QmlGraphicsAnchorsPrivate(QmlGraphicsItem *i)
: updatingMe(false), updatingHorizontalAnchor(0),
- updatingVerticalAnchor(0), updatingFill(0), updatingCenterIn(0), item(0), usedAnchors(0), fill(0),
+ updatingVerticalAnchor(0), updatingFill(0), updatingCenterIn(0), item(i), usedAnchors(0), fill(0),
centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0),
margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0),
componentComplete(true)
diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp
index ed70b14..ba17115 100644
--- a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp
@@ -152,7 +152,9 @@ void QmlGraphicsFlickableVisibleArea::updateVisible()
QmlGraphicsFlickablePrivate::QmlGraphicsFlickablePrivate()
- : viewport(new QmlGraphicsItem), _moveX(viewport, &QmlGraphicsItem::setX), _moveY(viewport, &QmlGraphicsItem::setY)
+ : viewport(new QmlGraphicsItem)
+ , _moveX(this, &QmlGraphicsFlickablePrivate::setRoundedViewportX)
+ , _moveY(this, &QmlGraphicsFlickablePrivate::setRoundedViewportY)
, vWidth(-1), vHeight(-1), overShoot(true), flicked(false), moving(false), stealMouse(false)
, pressed(false), atXEnd(false), atXBeginning(true), atYEnd(false), atYBeginning(true)
, interactive(true), deceleration(500), maxVelocity(2000), reportedVelocitySmoothing(100)
@@ -828,6 +830,16 @@ void QmlGraphicsFlickablePrivate::clearDelayedPress()
}
}
+void QmlGraphicsFlickablePrivate::setRoundedViewportX(qreal x)
+{
+ viewport->setX(qRound(x));
+}
+
+void QmlGraphicsFlickablePrivate::setRoundedViewportY(qreal y)
+{
+ viewport->setY(qRound(y));
+}
+
void QmlGraphicsFlickable::timerEvent(QTimerEvent *event)
{
Q_D(QmlGraphicsFlickable);
diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h b/src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h
index b19a08c..d59a9e4 100644
--- a/src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h
@@ -82,10 +82,13 @@ public:
void captureDelayedPress(QGraphicsSceneMouseEvent *event);
void clearDelayedPress();
+ void setRoundedViewportX(qreal x);
+ void setRoundedViewportY(qreal y);
+
public:
QmlGraphicsItem *viewport;
- QmlTimeLineValueProxy<QmlGraphicsItem> _moveX;
- QmlTimeLineValueProxy<QmlGraphicsItem> _moveY;
+ QmlTimeLineValueProxy<QmlGraphicsFlickablePrivate> _moveX;
+ QmlTimeLineValueProxy<QmlGraphicsFlickablePrivate> _moveY;
QmlTimeLine timeline;
qreal vWidth;
qreal vHeight;
diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp
index c75c80c..0ba1491 100644
--- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp
@@ -156,6 +156,7 @@ public:
, cellWidth(100), cellHeight(100), columns(1), requestedIndex(-1)
, highlightComponent(0), highlight(0), trackedItem(0)
, moveReason(Other), buffer(0), highlightXAnimator(0), highlightYAnimator(0)
+ , bufferMode(NoBuffer)
, ownModel(false), wrap(false), autoHighlight(true)
, fixCurrentVisibility(false), lazyRelease(false) {}
@@ -163,7 +164,7 @@ public:
void clear();
FxGridItem *createItem(int modelIndex);
void releaseItem(FxGridItem *item);
- void refill(qreal from, qreal to);
+ void refill(qreal from, qreal to, bool doBuffer=false);
void updateGrid();
void layout(bool removed=false);
@@ -326,6 +327,8 @@ public:
int buffer;
QmlEaseFollow *highlightXAnimator;
QmlEaseFollow *highlightYAnimator;
+ enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 };
+ BufferMode bufferMode;
bool ownModel : 1;
bool wrap : 1;
@@ -392,14 +395,21 @@ void QmlGraphicsGridViewPrivate::releaseItem(FxGridItem *item)
delete item;
}
-void QmlGraphicsGridViewPrivate::refill(qreal from, qreal to)
+void QmlGraphicsGridViewPrivate::refill(qreal from, qreal to, bool doBuffer)
{
Q_Q(QmlGraphicsGridView);
if (!isValid() || !q->isComponentComplete())
return;
- from -= buffer;
- to += buffer;
+ qreal bufferFrom = from - buffer;
+ qreal bufferTo = to + buffer;
+ qreal fillFrom = from;
+ qreal fillTo = to;
+ if (doBuffer && (bufferMode & BufferAfter))
+ fillTo = bufferTo;
+ if (doBuffer && (bufferMode & BufferBefore))
+ fillFrom = bufferFrom;
+
bool changed = false;
int colPos = colPosAt(visibleIndex);
@@ -424,7 +434,7 @@ void QmlGraphicsGridViewPrivate::refill(qreal from, qreal to)
// Item creation and release is staggered in order to avoid
// creating/releasing multiple items in one frame
// while flicking (as much as possible).
- while (modelIndex < model->count() && rowPos <= to + rowSize()*(columns - colNum)/(columns+1)) {
+ while (modelIndex < model->count() && rowPos <= fillTo + rowSize()*(columns - colNum)/(columns+1)) {
//qDebug() << "refill: append item" << modelIndex;
if (!(item = createItem(modelIndex)))
break;
@@ -439,6 +449,8 @@ void QmlGraphicsGridViewPrivate::refill(qreal from, qreal to)
}
++modelIndex;
changed = true;
+ if (doBuffer) // never buffer more than one item per frame
+ break;
}
if (visibleItems.count()) {
@@ -450,7 +462,7 @@ void QmlGraphicsGridViewPrivate::refill(qreal from, qreal to)
}
}
colNum = colPos / colSize();
- while (visibleIndex > 0 && rowPos + rowSize() - 1 >= from - rowSize()*(colNum+1)/(columns+1)){
+ while (visibleIndex > 0 && rowPos + rowSize() - 1 >= fillFrom - rowSize()*(colNum+1)/(columns+1)){
//qDebug() << "refill: prepend item" << visibleIndex-1 << "top pos" << rowPos << colPos;
if (!(item = createItem(visibleIndex-1)))
break;
@@ -465,12 +477,14 @@ void QmlGraphicsGridViewPrivate::refill(qreal from, qreal to)
rowPos -= rowSize();
}
changed = true;
+ if (doBuffer) // never buffer more than one item per frame
+ break;
}
if (!lazyRelease || !changed) { // avoid destroying items in the same frame that we create
while (visibleItems.count() > 1
&& (item = visibleItems.first())
- && item->endRowPos() < from - rowSize()*(item->colPos()/colSize()+1)/(columns+1)) {
+ && item->endRowPos() < bufferFrom - rowSize()*(item->colPos()/colSize()+1)/(columns+1)) {
if (item->attached->delayRemove())
break;
//qDebug() << "refill: remove first" << visibleIndex << "top end pos" << item->endRowPos();
@@ -482,7 +496,7 @@ void QmlGraphicsGridViewPrivate::refill(qreal from, qreal to)
}
while (visibleItems.count() > 1
&& (item = visibleItems.last())
- && item->rowPos() > to + rowSize()*(columns - item->colPos()/colSize())/(columns+1)) {
+ && item->rowPos() > bufferTo + rowSize()*(columns - item->colPos()/colSize())/(columns+1)) {
if (item->attached->delayRemove())
break;
//qDebug() << "refill: remove last" << visibleIndex+visibleItems.count()-1;
@@ -496,6 +510,8 @@ void QmlGraphicsGridViewPrivate::refill(qreal from, qreal to)
q->setViewportHeight(endPosition() - startPosition());
else
q->setViewportWidth(endPosition() - startPosition());
+ } else if (!doBuffer && buffer && bufferMode != NoBuffer) {
+ refill(from, to, true);
}
lazyRelease = false;
}
@@ -1157,6 +1173,21 @@ void QmlGraphicsGridView::viewportMoved()
Q_D(QmlGraphicsGridView);
QmlGraphicsFlickable::viewportMoved();
d->lazyRelease = true;
+ if (d->flicked) {
+ if (yflick()) {
+ if (d->velocityY > 0)
+ d->bufferMode = QmlGraphicsGridViewPrivate::BufferBefore;
+ else if (d->velocityY < 0)
+ d->bufferMode = QmlGraphicsGridViewPrivate::BufferAfter;
+ }
+
+ if (xflick()) {
+ if (d->velocityX > 0)
+ d->bufferMode = QmlGraphicsGridViewPrivate::BufferBefore;
+ else if (d->velocityX < 0)
+ d->bufferMode = QmlGraphicsGridViewPrivate::BufferAfter;
+ }
+ }
refill();
}
diff --git a/src/declarative/graphicsitems/qmlgraphicsitem_p.h b/src/declarative/graphicsitems/qmlgraphicsitem_p.h
index d5dbe1d..ca850f3 100644
--- a/src/declarative/graphicsitems/qmlgraphicsitem_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicsitem_p.h
@@ -173,8 +173,7 @@ public:
QmlGraphicsAnchors *anchors() {
if (!_anchors) {
Q_Q(QmlGraphicsItem);
- _anchors = new QmlGraphicsAnchors;
- _anchors->setItem(q);
+ _anchors = new QmlGraphicsAnchors(q);
if (!_componentComplete)
_anchors->classBegin();
}
diff --git a/src/declarative/graphicsitems/qmlgraphicstext.cpp b/src/declarative/graphicsitems/qmlgraphicstext.cpp
index 459541e..ce86b8f 100644
--- a/src/declarative/graphicsitems/qmlgraphicstext.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicstext.cpp
@@ -41,6 +41,7 @@
#include "qmlgraphicstext_p.h"
#include "qmlgraphicstext_p_p.h"
+#include <qmlstyledtext_p.h>
#include <qfxperf_p_p.h>
@@ -143,7 +144,7 @@ void QmlGraphicsText::setFont(const QFont &font)
Q_D(QmlGraphicsText);
d->font = font;
- d->updateSize();
+ d->updateLayout();
d->markImgDirty();
}
@@ -166,7 +167,7 @@ void QmlGraphicsText::setText(const QString &n)
}
d->text = n;
- d->updateSize();
+ d->updateLayout();
d->markImgDirty();
emit textChanged(d->text);
}
@@ -336,7 +337,7 @@ void QmlGraphicsText::setWrap(bool w)
d->wrap = w;
- d->updateSize();
+ d->updateLayout();
d->markImgDirty();
}
@@ -387,12 +388,13 @@ void QmlGraphicsText::setTextFormat(TextFormat format)
Q_D(QmlGraphicsText);
if (format == d->format)
return;
+ d->format = format;
bool wasRich = d->richText;
d->richText = format == RichText || (format == AutoText && Qt::mightBeRichText(d->text));
if (wasRich && !d->richText) {
//### delete control? (and vice-versa below)
- d->updateSize();
+ d->updateLayout();
d->markImgDirty();
} else if (!wasRich && d->richText) {
if (!d->doc) {
@@ -400,10 +402,9 @@ void QmlGraphicsText::setTextFormat(TextFormat format)
d->doc->setDocumentMargin(0);
}
d->doc->setHtml(d->text);
- d->updateSize();
+ d->updateLayout();
d->markImgDirty();
}
- d->format = format;
}
/*!
@@ -436,7 +437,7 @@ void QmlGraphicsText::setElideMode(QmlGraphicsText::TextElideMode mode)
d->elideMode = mode;
- d->updateSize();
+ d->updateLayout();
d->markImgDirty();
}
@@ -453,6 +454,34 @@ void QmlGraphicsText::geometryChanged(const QRectF &newGeometry,
QmlGraphicsItem::geometryChanged(newGeometry, oldGeometry);
}
+void QmlGraphicsTextPrivate::updateLayout()
+{
+ Q_Q(QmlGraphicsText);
+ if (q->isComponentComplete()) {
+ //setup instance of QTextLayout for all cases other than richtext
+ if (!richText) {
+ layout.clearLayout();
+ layout.setFont(font);
+ if (format != QmlGraphicsText::StyledText) {
+ QString tmp = text;
+ tmp.replace(QLatin1Char('\n'), QChar::LineSeparator);
+ singleline = !tmp.contains(QChar::LineSeparator);
+ if (singleline && elideMode != QmlGraphicsText::ElideNone && q->widthValid()) {
+ QFontMetrics fm(font);
+ tmp = fm.elidedText(tmp,(Qt::TextElideMode)elideMode,q->width()); // XXX still worth layout...?
+ }
+ layout.setText(tmp);
+ } else {
+ singleline = false;
+ QmlStyledText::parse(text, layout);
+ }
+ }
+ updateSize();
+ } else {
+ dirty = true;
+ }
+}
+
void QmlGraphicsTextPrivate::updateSize()
{
Q_Q(QmlGraphicsText);
@@ -464,20 +493,10 @@ void QmlGraphicsTextPrivate::updateSize()
}
int dy = q->height();
- QString tmp;
QSize size(0, 0);
//setup instance of QTextLayout for all cases other than richtext
- if (!richText)
- {
- tmp = text;
- tmp.replace(QLatin1Char('\n'), QChar::LineSeparator);
- singleline = !tmp.contains(QChar::LineSeparator);
- if (singleline && elideMode != QmlGraphicsText::ElideNone && q->widthValid())
- tmp = fm.elidedText(tmp,(Qt::TextElideMode)elideMode,q->width()); // XXX still worth layout...?
- layout.clearLayout();
- layout.setFont(font);
- layout.setText(tmp);
+ if (!richText) {
size = setupTextLayout(&layout);
cachedLayoutSize = size;
dy -= size.height();
@@ -769,7 +788,7 @@ void QmlGraphicsText::componentComplete()
#endif
QmlGraphicsItem::componentComplete();
if (d->dirty) {
- d->updateSize();
+ d->updateLayout();
d->dirty = false;
}
}
diff --git a/src/declarative/graphicsitems/qmlgraphicstext_p.h b/src/declarative/graphicsitems/qmlgraphicstext_p.h
index 6ca460b..717fcb4 100644
--- a/src/declarative/graphicsitems/qmlgraphicstext_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicstext_p.h
@@ -86,7 +86,8 @@ public:
Sunken };
enum TextFormat { PlainText = Qt::PlainText,
RichText = Qt::RichText,
- AutoText = Qt::AutoText };
+ AutoText = Qt::AutoText,
+ StyledText = 4 };
enum TextElideMode { ElideLeft = Qt::ElideLeft,
ElideRight = Qt::ElideRight,
ElideMiddle = Qt::ElideMiddle,
diff --git a/src/declarative/graphicsitems/qmlgraphicstext_p_p.h b/src/declarative/graphicsitems/qmlgraphicstext_p_p.h
index 79d1a4f..73c3dd7 100644
--- a/src/declarative/graphicsitems/qmlgraphicstext_p_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicstext_p_p.h
@@ -80,6 +80,7 @@ public:
~QmlGraphicsTextPrivate();
void updateSize();
+ void updateLayout();
void markImgDirty() {
Q_Q(QmlGraphicsText);
imgDirty = true;
diff --git a/src/declarative/qml/qmlbasicscript.cpp b/src/declarative/qml/qmlbasicscript.cpp
index b596437..ebdd348 100644
--- a/src/declarative/qml/qmlbasicscript.cpp
+++ b/src/declarative/qml/qmlbasicscript.cpp
@@ -737,23 +737,6 @@ int QmlBasicScript::singleIdFetchIndex() const
return d->instructions()[0].fetch.idx;
}
-bool QmlBasicScript::isSingleContextProperty() const
-{
- if (!isValid())
- return false;
-
- return d->instructionCount == 1 &&
- d->instructions()[0].type == ScriptInstruction::FetchContextConstant;
-}
-
-int QmlBasicScript::singleContextPropertyIndex() const
-{
- if (!isSingleContextProperty())
- return -1;
-
- return d->instructions()[0].constant.idx;
-}
-
/*!
Return a pointer to the script's compile data, or null if there is no data.
*/
diff --git a/src/declarative/qml/qmlbasicscript_p.h b/src/declarative/qml/qmlbasicscript_p.h
index 3af09c2..c4b436d 100644
--- a/src/declarative/qml/qmlbasicscript_p.h
+++ b/src/declarative/qml/qmlbasicscript_p.h
@@ -104,8 +104,6 @@ public:
bool isSingleIdFetch() const;
int singleIdFetchIndex() const;
- bool isSingleContextProperty() const;
- int singleContextPropertyIndex() const;
private:
int flags;
QmlBasicScriptPrivate *d;
diff --git a/src/declarative/qml/qmlbinding.h b/src/declarative/qml/qmlbinding.h
index 177a0fd..242742a 100644
--- a/src/declarative/qml/qmlbinding.h
+++ b/src/declarative/qml/qmlbinding.h
@@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class QmlAbstractBinding
+class Q_DECLARATIVE_EXPORT QmlAbstractBinding
{
public:
QmlAbstractBinding();
diff --git a/src/declarative/qml/qmlbindingoptimizations.cpp b/src/declarative/qml/qmlbindingoptimizations.cpp
index d8a2de0..d7105b2 100644
--- a/src/declarative/qml/qmlbindingoptimizations.cpp
+++ b/src/declarative/qml/qmlbindingoptimizations.cpp
@@ -255,75 +255,4 @@ void QmlBinding_Id::reset()
m_propertyIdx, a);
}
-/*
- The QmlBinding_ObjectProperty optimization handles expressions of the type:
-
- property: objectProperty
-
- where both property and objectProperty are object properties on the target
- object. Coercian between the two must be checked outside the
- QmlBinding_ObjectProperty - it assumes that they coerce successfully.
-
- Due to dot properties, property does not have to be on the same object as
- objectProperty. For example:
-
- anchors.fill: parent
-*/
-QmlBinding_ObjProperty::QmlBinding_ObjProperty(QObject *object, int propertyIdx,
- QObject *context, int contextIdx,
- int notifyIdx)
-: m_enabled(false), m_object(object), m_propertyIdx(propertyIdx),
- m_context(context), m_contextIdx(contextIdx), m_notifyIdx(notifyIdx)
-{
-}
-
-void QmlBinding_ObjProperty::setEnabled(bool e, QmlMetaProperty::WriteFlags flags)
-{
- m_enabled = e;
- if (e) {
- addToObject(m_object);
- update(flags);
- } else {
- removeFromObject();
- }
-
- QmlAbstractBinding::setEnabled(e, flags);
-}
-
-int QmlBinding_ObjProperty::propertyIndex()
-{
- return m_propertyIdx;
-}
-
-void QmlBinding_ObjProperty::update(QmlMetaProperty::WriteFlags flags)
-{
- if (!m_enabled)
- return;
-
- QObject *value = 0;
- int status = -1;
- void *ra[] = { &value, 0, &status };
-
- // Read
- QMetaObject::metacall(m_context, QMetaObject::ReadProperty,
- m_contextIdx, ra);
-
- void *wa[] = { &value, 0, &status, &flags };
-
- // Write
- QMetaObject::metacall(m_object, QMetaObject::WriteProperty,
- m_propertyIdx, wa);
-
- // Connect notify if needed. Only need to connect once, so we set
- // m_notifyIdx back to -1 afterwards
- static int slotIdx = -1;
- if (m_notifyIdx != -1) {
- if (slotIdx == -1)
- slotIdx = QmlBinding_ObjProperty::staticMetaObject.indexOfMethod("update()");
-
- QMetaObject::connect(m_context, m_notifyIdx, this, slotIdx);
- m_notifyIdx = -1;
- }
-}
-
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlbindingoptimizations_p.h b/src/declarative/qml/qmlbindingoptimizations_p.h
index 6289cc0..feb753e 100644
--- a/src/declarative/qml/qmlbindingoptimizations_p.h
+++ b/src/declarative/qml/qmlbindingoptimizations_p.h
@@ -128,32 +128,6 @@ private:
int m_id;
};
-class QmlBinding_ObjProperty : public QObject,
- public QmlAbstractExpression,
- public QmlAbstractBinding
-{
- Q_OBJECT
-public:
- QmlBinding_ObjProperty(QObject *object, int propertyIdx,
- QObject *context, int contextIdx, int notifyIdx);
-
- // Inherited from QmlAbstractBinding
- virtual void setEnabled(bool, QmlMetaProperty::WriteFlags flags);
- virtual int propertyIndex();
- virtual void update(QmlMetaProperty::WriteFlags flags);
-
-private Q_SLOTS:
- void update() { update(QmlMetaProperty::DontRemoveBinding); }
-
-private:
- bool m_enabled;
- QObject *m_object;
- int m_propertyIdx;
- QObject *m_context;
- int m_contextIdx;
- int m_notifyIdx;
-};
-
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/declarative/qml/qmlbindingvme.cpp b/src/declarative/qml/qmlbindingvme.cpp
index 01c7a4b..552dd55 100644
--- a/src/declarative/qml/qmlbindingvme.cpp
+++ b/src/declarative/qml/qmlbindingvme.cpp
@@ -480,8 +480,9 @@ static bool findgeneric(Register *output, // val
if (contextPropertyIndex != -1) {
- subscribe(QmlContextPrivate::get(context), contextPropertyIndex + context->notifyIndex,
- subIdx, config);
+ if (subIdx != -1)
+ subscribe(QmlContextPrivate::get(context), contextPropertyIndex + context->notifyIndex,
+ subIdx, config);
if (contextPropertyIndex < context->idValueCount) {
output->setQObject(context->idValues[contextPropertyIndex]);
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp
index 3ebefea..7f11a23 100644
--- a/src/declarative/qml/qmlcompiler.cpp
+++ b/src/declarative/qml/qmlcompiler.cpp
@@ -2545,24 +2545,7 @@ void QmlCompiler::genBindingAssignment(QmlParser::Value *binding,
output->bytecode << store;
return;
}
- } else if (bs.isSingleContextProperty()) {
- int propIndex = bs.singleContextPropertyIndex();
-
- QMetaProperty p =
- ref.bindingContext.object->metaObject()->property(propIndex);
- if ((p.notifySignalIndex() != -1 || p.isConstant()) &&
- canCoerce(prop->type, p.userType())) {
-
- store.type = QmlInstruction::StoreObjPropBinding;
- store.assignObjPropBinding.property = prop->index;
- store.assignObjPropBinding.contextIdx = propIndex;
- store.assignObjPropBinding.context = ref.bindingContext.stack;
- store.assignObjPropBinding.notifyIdx = p.notifySignalIndex();
-
- output->bytecode << store;
- return;
- }
- }
+ }
store.type = QmlInstruction::StoreBinding;
store.assignBinding.value = output->indexForByteArray(ref.compiledData);
@@ -2634,7 +2617,7 @@ bool QmlCompiler::completeComponentBuild()
bs.compile(expr);
- if (qmlExperimental() && (!bs.isValid() || (!bs.isSingleIdFetch() && !bs.isSingleContextProperty()))) {
+ if (qmlExperimental() && (!bs.isValid() || !bs.isSingleIdFetch())) {
int index = bindingCompiler.compile(expr, QmlEnginePrivate::get(engine));
if (index != -1) {
qWarning() << "Accepted for optimization:" << qPrintable(expr.expression.asScript());
diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp
index 705c0cf..e46ea96 100644
--- a/src/declarative/qml/qmldom.cpp
+++ b/src/declarative/qml/qmldom.cpp
@@ -462,6 +462,11 @@ QByteArray QmlDomDynamicProperty::propertyName() const
return QByteArray();
}
+/*!
+ Returns the type of the dynamic property. Note that when the property is an
+ alias property, this will return -1. Use QmlDomProperty::isAlias() to check
+ if the property is an alias.
+*/
int QmlDomDynamicProperty::propertyType() const
{
if (isValid()) {
@@ -546,6 +551,18 @@ QmlDomProperty QmlDomDynamicProperty::defaultValue() const
}
/*!
+ Returns true if this dynamic property is an alias for another property,
+ false otherwise.
+*/
+bool QmlDomDynamicProperty::isAlias() const
+{
+ if (isValid())
+ return d->property.type == QmlParser::Object::DynamicProperty::Alias;
+ else
+ return false;
+}
+
+/*!
Returns the position in the input data where the property ID startd, or 0 if
the property is invalid.
*/
diff --git a/src/declarative/qml/qmldom.h b/src/declarative/qml/qmldom.h
index 24710f1..8442f49 100644
--- a/src/declarative/qml/qmldom.h
+++ b/src/declarative/qml/qmldom.h
@@ -127,9 +127,10 @@ public:
QByteArray propertyTypeName() const;
bool isDefaultProperty() const;
-
QmlDomProperty defaultValue() const;
+ bool isAlias() const;
+
int position() const;
int length() const;
diff --git a/src/declarative/qml/qmlinstruction.cpp b/src/declarative/qml/qmlinstruction.cpp
index c873803..2ddad49 100644
--- a/src/declarative/qml/qmlinstruction.cpp
+++ b/src/declarative/qml/qmlinstruction.cpp
@@ -164,9 +164,6 @@ void QmlCompiledData::dump(QmlInstruction *instr, int idx)
case QmlInstruction::StoreIdOptBinding:
qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_ID_OPT_BINDING\t" << instr->assignIdOptBinding.property << "\t" << instr->assignIdOptBinding.id;
break;
- case QmlInstruction::StoreObjPropBinding:
- qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_OBJ_PROP_BINDING\t" << instr->assignObjPropBinding.property << "\t" << instr->assignObjPropBinding.contextIdx << "\t" << instr->assignObjPropBinding.context << "\t" << instr->assignObjPropBinding.notifyIdx;
- break;
case QmlInstruction::StoreValueSource:
qWarning().nospace() << idx << "\t\t" << line << "\t" << "STORE_VALUE_SOURCE\t" << instr->assignValueSource.property << "\t" << instr->assignValueSource.castValue;
break;
diff --git a/src/declarative/qml/qmlinstruction_p.h b/src/declarative/qml/qmlinstruction_p.h
index 6e2b452..44fa196 100644
--- a/src/declarative/qml/qmlinstruction_p.h
+++ b/src/declarative/qml/qmlinstruction_p.h
@@ -130,7 +130,6 @@ public:
StoreBinding, /* assignBinding */
StoreCompiledBinding, /* assignBinding */
StoreIdOptBinding, /* assignIdOptBinding */
- StoreObjPropBinding, /* assignObjPropBinding */
StoreValueSource, /* assignValueSource */
StoreValueInterceptor, /* assignValueInterceptor */
diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp
index f1abd7d..06795a8 100644
--- a/src/declarative/qml/qmlvme.cpp
+++ b/src/declarative/qml/qmlvme.cpp
@@ -644,25 +644,6 @@ QObject *QmlVME::run(QmlVMEStack<QObject *> &stack, QmlContext *ctxt,
}
break;
- case QmlInstruction::StoreObjPropBinding:
- {
- int coreIndex = instr.assignObjPropBinding.property;
- if (stack.count() == 1 && bindingSkipList.testBit(coreIndex))
- break;
-
- QObject *target = stack.top();
- QObject *context =
- stack.at(stack.count() - 1 - instr.assignObjPropBinding.context);
-
- QmlBinding_ObjProperty *bind =
- new QmlBinding_ObjProperty(target, instr.assignObjPropBinding.property, context, instr.assignObjPropBinding.contextIdx, instr.assignObjPropBinding.notifyIdx);
-
- bindValues.append(bind);
- bind->m_mePtr = &bindValues.values[bindValues.count - 1];
- bind->addToObject(target);
- }
- break;
-
case QmlInstruction::StoreValueSource:
{
QObject *obj = stack.pop();
diff --git a/src/declarative/qml/qpodvector_p.h b/src/declarative/qml/qpodvector_p.h
index add6e98..42d6017 100644
--- a/src/declarative/qml/qpodvector_p.h
+++ b/src/declarative/qml/qpodvector_p.h
@@ -92,10 +92,8 @@ public:
m_data = (T *)realloc(m_data, m_capacity * sizeof(T));
}
int moveCount = m_count - idx;
- if (moveCount) {
- qDebug() << "insert" << m_count << idx;
+ if (moveCount)
::memmove(m_data + idx + 1, m_data + idx, moveCount * sizeof(T));
- }
m_count++;
m_data[idx] = v;
}
diff --git a/src/declarative/util/qmlstyledtext.cpp b/src/declarative/util/qmlstyledtext.cpp
new file mode 100644
index 0000000..ce2b2ea
--- /dev/null
+++ b/src/declarative/util/qmlstyledtext.cpp
@@ -0,0 +1,356 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative 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 Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QXmlStreamReader>
+#include <QStack>
+#include <QVector>
+#include <QPainter>
+#include <QTextLayout>
+#include <QDebug>
+#include <qmath.h>
+#include "qmlstyledtext_p.h"
+
+/*
+ QmlStyledText supports few tags:
+
+ <b></b> - bold
+ <br> - new line
+ <font color="color_name"></font>
+
+ The opening and closing tags may be correctly nested.
+*/
+
+class QmlStyledTextPrivate
+{
+public:
+ QmlStyledTextPrivate(const QString &t, QTextLayout &l) : text(t), layout(l) {}
+
+ void parse();
+ bool parseTag(const QChar *&ch, const QString &textIn, QString &textOut, QTextCharFormat &format);
+ bool parseCloseTag(const QChar *&ch, const QString &textIn);
+ bool parseFontAttributes(const QChar *&ch, const QString &textIn, QTextCharFormat &format);
+ QPair<QStringRef,QStringRef> parseAttribute(const QChar *&ch, const QString &textIn);
+ QStringRef parseValue(const QChar *&ch, const QString &textIn);
+
+ inline void skipSpace(const QChar *&ch) {
+ while (ch->isSpace() && !ch->isNull())
+ ++ch;
+ }
+
+ QString text;
+ QTextLayout &layout;
+
+ static const QChar lessThan;
+ static const QChar greaterThan;
+ static const QChar equals;
+ static const QChar singleQuote;
+ static const QChar doubleQuote;
+ static const QChar slash;
+};
+
+const QChar QmlStyledTextPrivate::lessThan(QLatin1Char('<'));
+const QChar QmlStyledTextPrivate::greaterThan(QLatin1Char('>'));
+const QChar QmlStyledTextPrivate::equals(QLatin1Char('='));
+const QChar QmlStyledTextPrivate::singleQuote(QLatin1Char('\''));
+const QChar QmlStyledTextPrivate::doubleQuote(QLatin1Char('\"'));
+const QChar QmlStyledTextPrivate::slash(QLatin1Char('/'));
+
+QmlStyledText::QmlStyledText(const QString &string, QTextLayout &layout)
+: d(new QmlStyledTextPrivate(string, layout))
+{
+}
+
+QmlStyledText::~QmlStyledText()
+{
+ delete d;
+}
+
+void QmlStyledText::parse(const QString &string, QTextLayout &layout)
+{
+ QmlStyledText styledText(string, layout);
+ styledText.d->parse();
+}
+
+#define CUSTOM_PARSER
+
+#ifndef CUSTOM_PARSER
+void QmlStyledTextPrivate::parse()
+{
+ QList<QTextLayout::FormatRange> ranges;
+ QStack<QTextCharFormat> formatStack;
+
+ QString drawText;
+ drawText.reserve(text.count());
+
+ QXmlStreamReader xml("<html>" + text + "</html>");
+ while (!xml.atEnd()) {
+ xml.readNext();
+ if (xml.tokenType() == QXmlStreamReader::StartElement) {
+ QStringRef name = xml.name();
+ if (name == "b") {
+ QTextCharFormat format;
+ if (formatStack.count())
+ format = formatStack.top();
+ else
+ format.setFont(layout.font());
+ format.setFontWeight(QFont::Bold);
+ formatStack.push(format);
+ } else if (name == "br") {
+ drawText.append(QChar(QChar::LineSeparator));
+ } else if (name == "font") {
+ QTextCharFormat format;
+ if (formatStack.count())
+ format = formatStack.top();
+ else
+ format.setFont(layout.font());
+ QStringRef col = xml.attributes().value("color");
+ if (!col.isEmpty()) {
+ format.setForeground(QColor(col.toString()));
+ formatStack.push(format);
+ }
+ }
+ } else if (xml.tokenType() == QXmlStreamReader::EndElement) {
+ if (formatStack.count() > 1) {
+ QStringRef name = xml.name();
+ if (name == "b" || name == "font" || name == "br")
+ formatStack.pop();
+ }
+ } else if (xml.tokenType() == QXmlStreamReader::Characters) {
+ if (formatStack.count() > 1) {
+ QTextLayout::FormatRange formatRange;
+ formatRange.format = formatStack.top();
+ formatRange.start = drawText.length();
+ formatRange.length = xml.text().length();
+ ranges.append(formatRange);
+ }
+ drawText.append(xml.text());
+ }
+ }
+
+ layout.setText(drawText);
+ layout.setAdditionalFormats(ranges);
+}
+#else
+void QmlStyledTextPrivate::parse()
+{
+ QList<QTextLayout::FormatRange> ranges;
+ QStack<QTextCharFormat> formatStack;
+
+ QString drawText;
+ drawText.reserve(text.count());
+
+ int textStart = 0;
+ int textLength = 0;
+ const QChar *ch = text.constData();
+ while (!ch->isNull()) {
+ if (*ch == lessThan) {
+ if (textLength) {
+ if (formatStack.count()) {
+ QTextLayout::FormatRange formatRange;
+ formatRange.format = formatStack.top();
+ formatRange.start = drawText.length();
+ formatRange.length = textLength;
+ ranges.append(formatRange);
+ }
+ drawText.append(QStringRef(&text, textStart, textLength));
+ }
+ ++ch;
+ if (*ch == slash) {
+ ++ch;
+ if (parseCloseTag(ch, text))
+ formatStack.pop();
+ } else {
+ QTextCharFormat format;
+ if (formatStack.count())
+ format = formatStack.top();
+ else
+ format.setFont(layout.font());
+ if (parseTag(ch, text, drawText, format))
+ formatStack.push(format);
+ }
+ textStart = ch - text.constData() + 1;
+ textLength = 0;
+ } else {
+ ++textLength;
+ }
+ ++ch;
+ }
+ if (textLength) {
+ if (formatStack.count()) {
+ QTextLayout::FormatRange formatRange;
+ formatRange.format = formatStack.top();
+ formatRange.start = drawText.length();
+ formatRange.length = textLength;
+ ranges.append(formatRange);
+ }
+ drawText.append(QStringRef(&text, textStart, textLength));
+ }
+
+ layout.setText(drawText);
+ layout.setAdditionalFormats(ranges);
+}
+#endif
+
+
+bool QmlStyledTextPrivate::parseTag(const QChar *&ch, const QString &textIn, QString &textOut, QTextCharFormat &format)
+{
+ skipSpace(ch);
+
+ int tagStart = ch - textIn.constData();
+ int tagLength = 0;
+ while (!ch->isNull()) {
+ if (*ch == greaterThan) {
+ QStringRef tag(&textIn, tagStart, tagLength);
+ if (tag.at(0) == QLatin1Char('b')) {
+ if (tagLength == 1) {
+ format.setFontWeight(QFont::Bold);
+ return true;
+ } else if (tagLength == 2 && tag.at(1) == QLatin1Char('r')) {
+ textOut.append(QChar(QChar::LineSeparator));
+ return true;
+ }
+ }
+ return false;
+ } else if (ch->isSpace()) {
+ // may have params.
+ QStringRef tag(&textIn, tagStart, tagLength);
+ if (tag == QLatin1String("font"))
+ return parseFontAttributes(ch, textIn, format);
+ if (*ch == greaterThan || ch->isNull())
+ continue;
+ } else if (*ch != slash){
+ tagLength++;
+ }
+ ++ch;
+ }
+
+ return false;
+}
+
+bool QmlStyledTextPrivate::parseCloseTag(const QChar *&ch, const QString &textIn)
+{
+ skipSpace(ch);
+
+ int tagStart = ch - textIn.constData();
+ int tagLength = 0;
+ while (!ch->isNull()) {
+ if (*ch == greaterThan) {
+ QStringRef tag(&textIn, tagStart, tagLength);
+ if (tag.at(0) == QLatin1Char('b')) {
+ if (tagLength == 1)
+ return true;
+ else if (tag.at(1) == QLatin1Char('r') && tagLength == 2)
+ return true;
+ } else if (tag == QLatin1String("font")) {
+ return true;
+ }
+ return false;
+ } else if (!ch->isSpace()){
+ tagLength++;
+ }
+ ++ch;
+ }
+
+ return false;
+}
+
+bool QmlStyledTextPrivate::parseFontAttributes(const QChar *&ch, const QString &textIn, QTextCharFormat &format)
+{
+ bool valid = false;
+ QPair<QStringRef,QStringRef> attr;
+ do {
+ attr = parseAttribute(ch, textIn);
+ if (attr.first == QLatin1String("color")) {
+ valid = true;
+ format.setForeground(QColor(attr.second.toString()));
+ }
+ } while (!ch->isNull() && !attr.first.isEmpty());
+
+ return valid;
+}
+
+QPair<QStringRef,QStringRef> QmlStyledTextPrivate::parseAttribute(const QChar *&ch, const QString &textIn)
+{
+ skipSpace(ch);
+
+ int attrStart = ch - textIn.constData();
+ int attrLength = 0;
+ while (!ch->isNull()) {
+ if (*ch == greaterThan) {
+ break;
+ } else if (*ch == equals) {
+ ++ch;
+ if (*ch != singleQuote && *ch != doubleQuote) {
+ while (*ch != greaterThan && !ch->isNull())
+ ++ch;
+ break;
+ }
+ ++ch;
+ if (!attrLength)
+ break;
+ QStringRef attr(&textIn, attrStart, attrLength);
+ QStringRef val = parseValue(ch, textIn);
+ if (!val.isEmpty())
+ return QPair<QStringRef,QStringRef>(attr,val);
+ break;
+ } else {
+ ++attrLength;
+ }
+ ++ch;
+ }
+
+ return QPair<QStringRef,QStringRef>();
+}
+
+QStringRef QmlStyledTextPrivate::parseValue(const QChar *&ch, const QString &textIn)
+{
+ int valStart = ch - textIn.constData();
+ int valLength = 0;
+ while (*ch != singleQuote && *ch != doubleQuote && !ch->isNull()) {
+ ++valLength;
+ ++ch;
+ }
+ if (ch->isNull())
+ return QStringRef();
+ ++ch; // skip quote
+
+ return QStringRef(&textIn, valStart, valLength);
+}
diff --git a/src/declarative/util/qmlstyledtext_p.h b/src/declarative/util/qmlstyledtext_p.h
new file mode 100644
index 0000000..0cfb43e
--- /dev/null
+++ b/src/declarative/util/qmlstyledtext_p.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative 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 Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMLSTYLEDTEXT_H
+#define QMLSTYLEDTEXT_H
+
+#include <QSizeF>
+
+class QPainter;
+class QPointF;
+class QString;
+class QmlStyledTextPrivate;
+class Q_DECLARATIVE_EXPORT QmlStyledText
+{
+public:
+ static void parse(const QString &string, QTextLayout &layout);
+
+private:
+ QmlStyledText(const QString &string, QTextLayout &layout);
+ ~QmlStyledText();
+
+ QmlStyledTextPrivate *d;
+};
+
+#endif
diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri
index b3418c7..b6a5c90 100644
--- a/src/declarative/util/util.pri
+++ b/src/declarative/util/util.pri
@@ -28,7 +28,8 @@ SOURCES += \
$$PWD/qmlnumberformatter.cpp \
$$PWD/qmldatetimeformatter.cpp \
$$PWD/qmlbehavior.cpp \
- $$PWD/qmlfontloader.cpp
+ $$PWD/qmlfontloader.cpp \
+ $$PWD/qmlstyledtext.cpp
HEADERS += \
$$PWD/qmlview.h \
@@ -61,7 +62,8 @@ HEADERS += \
$$PWD/qmlnumberformatter_p.h \
$$PWD/qmldatetimeformatter_p.h \
$$PWD/qmlbehavior_p.h \
- $$PWD/qmlfontloader_p.h
+ $$PWD/qmlfontloader_p.h \
+ $$PWD/qmlstyledtext_p.h
contains(QT_CONFIG, xmlpatterns) {
QT+=xmlpatterns
diff --git a/tests/benchmarks/declarative/creation/tst_creation.cpp b/tests/benchmarks/declarative/creation/tst_creation.cpp
index 61033e2..ae50309 100644
--- a/tests/benchmarks/declarative/creation/tst_creation.cpp
+++ b/tests/benchmarks/declarative/creation/tst_creation.cpp
@@ -65,7 +65,9 @@ private slots:
void objects_qmltype();
void qgraphicsitem();
- void qgraphicsitem_tree();
+ void qgraphicsobject();
+ void qgraphicsitem14();
+ void qgraphicsitem_tree14();
void itemtree_notree_cpp();
void itemtree_objtree_cpp();
@@ -169,9 +171,32 @@ public:
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {}
};
+class QGraphicsObjectDummy : public QGraphicsObject
+{
+public:
+ virtual QRectF boundingRect() const { return QRectF(); }
+ virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {}
+};
+
void tst_creation::qgraphicsitem()
{
QBENCHMARK {
+ QGraphicsItemDummy *i = new QGraphicsItemDummy();
+ delete i;
+ }
+}
+
+void tst_creation::qgraphicsobject()
+{
+ QBENCHMARK {
+ QGraphicsObjectDummy *i = new QGraphicsObjectDummy();
+ delete i;
+ }
+}
+
+void tst_creation::qgraphicsitem14()
+{
+ QBENCHMARK {
QGraphicsItemDummy *i1 = new QGraphicsItemDummy();
QGraphicsItemDummy *i2 = new QGraphicsItemDummy();
QGraphicsItemDummy *i3 = new QGraphicsItemDummy();
@@ -204,7 +229,7 @@ void tst_creation::qgraphicsitem()
}
}
-void tst_creation::qgraphicsitem_tree()
+void tst_creation::qgraphicsitem_tree14()
{
QBENCHMARK {
// i1