diff options
155 files changed, 2969 insertions, 969 deletions
diff --git a/demos/declarative/rssnews/content/NewsDelegate.qml b/demos/declarative/rssnews/content/NewsDelegate.qml index 040dadc..cfe9b00 100644 --- a/demos/declarative/rssnews/content/NewsDelegate.qml +++ b/demos/declarative/rssnews/content/NewsDelegate.qml @@ -43,10 +43,11 @@ import Qt 4.7 Item { id: delegate - height: childrenRect.height + 20 + height: column.height + 40 width: delegate.ListView.view.width Column { + id: column x: 20; y: 20 width: parent.width - 40 diff --git a/demos/declarative/snake/content/snake.js b/demos/declarative/snake/content/snake.js index 4d05e33..0f0dbf7 100644 --- a/demos/declarative/snake/content/snake.js +++ b/demos/declarative/snake/content/snake.js @@ -150,7 +150,7 @@ function move() { snake.push(newLink); } else { var lastLink = snake[snake.length-1]; - board[lastLink.row * numColumns + lastLink.column] = Undefined; + board[lastLink.row * numColumns + lastLink.column] = undefined; } if (waitForCookie > 0) { @@ -186,7 +186,7 @@ function move() { function isFree(row, column) { - return board[row * numColumns + column] == Undefined; + return board[row * numColumns + column] == undefined; } function isHead(row, column) @@ -214,7 +214,7 @@ function moveSkull() --linksToDie; var link = snake.pop(); link.dying = true; - board[link.row * numColumns + link.column] = Undefined; + board[link.row * numColumns + link.column] = undefined; if (score > 0) --score; if (snake.length == 0) { diff --git a/demos/qtdemo/menumanager.cpp b/demos/qtdemo/menumanager.cpp index a2ceb0e..15561ab 100644 --- a/demos/qtdemo/menumanager.cpp +++ b/demos/qtdemo/menumanager.cpp @@ -369,10 +369,10 @@ void MenuManager::launchQmlExample(const QString &name) dir = QDir(QLibraryInfo::location(QLibraryInfo::DemosPath)); else dir = QDir(QLibraryInfo::location(QLibraryInfo::ExamplesPath)); - QFile file(dir.path() + "/" + dirName + "/" + fileName + "/" + fileName.split('/').last() + ".qml"); + QFile file(dir.path() + "/" + dirName + "/" + fileName + "/" + "main.qml"); if(!file.exists()){ - //try main.qml as well - file.setFileName(dir.path() + "/" + dirName + "/" + fileName + "/" + "main.qml"); + //try dirname.qml as well + file.setFileName(dir.path() + "/" + dirName + "/" + fileName + "/" + fileName.split('/').last() + ".qml"); if(!file.exists()){ exampleError(QProcess::UnknownError); return; diff --git a/demos/qtdemo/qmlShell.qml b/demos/qtdemo/qmlShell.qml index 5c5f96c..e15d33c 100644 --- a/demos/qtdemo/qmlShell.qml +++ b/demos/qtdemo/qmlShell.qml @@ -99,6 +99,7 @@ Item { } MouseArea{ anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton onClicked: loader.focus=true;/* and don't propogate to the 'exit' area*/ } @@ -130,7 +131,7 @@ Item { textFormat: Text.RichText //Note that if loader is Error, it is because the file was found but there was an error creating the component //This means either we have a bug in our demos, or the required modules (which ship with Qt) did not deploy correctly - text: "The example has failed to load.<br />If you installed Qt's QML modules this is a bug!<br />" + text: "The example has failed to load.<br />If you installed all Qt's C++ and QML modules then this is a bug!<br />" + 'Report it at <a href="http://bugreports.qt.nokia.com">http://bugreports.qt.nokia.com</a>'; onLinkActivated: Qt.openUrlExternally(link); } @@ -145,6 +146,7 @@ Item { z: 8 enabled: main.show hoverEnabled: main.show //To steal focus from the buttons + acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton anchors.fill: parent onClicked: main.show=false; } diff --git a/doc/src/declarative/animation.qdoc b/doc/src/declarative/animation.qdoc index 13202ee..c5333df 100644 --- a/doc/src/declarative/animation.qdoc +++ b/doc/src/declarative/animation.qdoc @@ -71,13 +71,15 @@ to explicitly set the \c target and \c property to animate. Animations can be joined into a group using SequentialAnimation and ParallelAnimation. +See the \l {declarative/animation/basics}{Animation basics example} for a demonstration of creating and combining multiple animations in QML. + \target state-transitions \section1 Transitions -QML transitions describe animations to perform when \l{qmlstates}{state} changes occur. A transition +\l Transition elements describe the animations to perform when \l{qmlstates}{state} changes occur. A transition can only be triggered by a state change. -For example, a transition could describe how an item moves from its initial position to its new position: +For example, a \l Transition could describe how an item moves from its initial position to its new position: \snippet doc/src/snippets/declarative/animation.qml transitions-1 @@ -108,9 +110,13 @@ making use of both sequential and parallel animations: \snippet doc/src/snippets/declarative/animation.qml transitions-3 + +See \l {declarative/animation/states}{States and Transitions example} for a simple example of how transitions can be applied. + + \section1 Property Behaviors -A \l{Behavior}{property behavior} specifies a default animation to run whenever the property's value changes, regardless +A property \l {Behavior}{behavior} specifies a default animation to run whenever the property's value changes, regardless of what caused the change. The \c enabled property can be used to force a \l Behavior to only apply under certain circumstances. @@ -119,7 +125,7 @@ whenever it changes. The animation will last 300 milliseconds and use an \l{Prop \snippet doc/src/snippets/declarative/animation.qml behavior -Like using an animation as a value source, when used in a Behavior and animation does not need to specify +Like using an animation as a value source, when used in a \l Behavior and animation does not need to specify a \c target or \c property. To trigger this behavior, we could enter a state that changes \c x: @@ -149,4 +155,6 @@ If \c x were bound to another property, triggering the binding would also trigge If a state change has a transition animation matching a property with a \l Behavior, the transition animation will override the \l Behavior for that state change. +The \l {declarative/animation/behaviors}{Behaviors example} shows how behaviors can be used to provide animations. + */ diff --git a/doc/src/declarative/declarativeui.qdoc b/doc/src/declarative/declarativeui.qdoc index f113147..4235c27 100644 --- a/doc/src/declarative/declarativeui.qdoc +++ b/doc/src/declarative/declarativeui.qdoc @@ -104,6 +104,7 @@ application or to build completely new applications. QML is fully \l \o \l {QML Security} \o \l {QtDeclarative Module} \o \l {Debugging QML} +\o \l {QML Viewer} \o \l {QML Performance} \o \l {QML Coding Conventions} \endlist diff --git a/doc/src/declarative/dynamicobjects.qdoc b/doc/src/declarative/dynamicobjects.qdoc index de65a12..a5e53a9 100644 --- a/doc/src/declarative/dynamicobjects.qdoc +++ b/doc/src/declarative/dynamicobjects.qdoc @@ -39,8 +39,12 @@ QML also supports the dynamic creation of objects from within JavaScript code. This is useful if the existing QML elements do not fit the needs of your application, and there are no C++ components involved. +See the {declarative/toys/dynamicscene}{Dynamic Scene example} for a demonstration +of the concepts discussed on this page. + \section1 Creating Objects Dynamically + There are two ways to create objects dynamically from JavaScript. You can either call \l {QML:Qt::createComponent()}{Qt.createComponent()} to create a component which instantiates items, or use \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()} diff --git a/doc/src/declarative/focus.qdoc b/doc/src/declarative/focus.qdoc index 699ebcb..cc546c0 100644 --- a/doc/src/declarative/focus.qdoc +++ b/doc/src/declarative/focus.qdoc @@ -266,6 +266,10 @@ When a QML item explicitly relinquishes focus (by setting its does not automatically select another element to receive focus. That is, it is possible for there to be no currently \e {active focus}. +See the {declarative/keyinteraction/focus}{Keyboard Focus example} for a +demonstration of moving keyboard focus between multiple areas using FocusScope +elements. + \section1 Advanced uses of Focus Scopes Focus scopes allow focus to allocation to be easily partitioned. Several diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index ecbaa9e..40fc3eb 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -114,6 +114,8 @@ browser. The following objects and properties are supported by the QML implemen \endtable +\sa {declarative/xml/xmlhttprequest}{XMLHttpRequest example} + \section1 Offline Storage API \section2 Database API @@ -132,6 +134,8 @@ The API can be used from JavaScript functions in your QML: The API conforms to the Synchronous API of the HTML5 Web Database API, \link http://www.w3.org/TR/2009/WD-webdatabase-20091029/ W3C Working Draft 29 October 2009\endlink. +\sa {declarative/sqllocalstorage}{SQL Local Storage example} + \section3 db = openDatabaseSync(identifier, version, description, estimated_size, callback(db)) Returns the database identified by \e identifier. If the database does not already exist, it diff --git a/doc/src/declarative/qdeclarativei18n.qdoc b/doc/src/declarative/qdeclarativei18n.qdoc index c16dea3..40f7919 100644 --- a/doc/src/declarative/qdeclarativei18n.qdoc +++ b/doc/src/declarative/qdeclarativei18n.qdoc @@ -78,4 +78,7 @@ Finally, we can test the translation: \code qml -translation hello.qm hello.qml \endcode + + +You can see a complete example and source code in the {declarative/i18n}{QML Internationalization example}. */ diff --git a/doc/src/declarative/qdeclarativemodels.qdoc b/doc/src/declarative/qdeclarativemodels.qdoc index bb17896..7671eb3 100644 --- a/doc/src/declarative/qdeclarativemodels.qdoc +++ b/doc/src/declarative/qdeclarativemodels.qdoc @@ -279,6 +279,8 @@ ListView { \endcode \endtable +The complete example is available in \l {declarative/modelviews/stringlistmodel}. + \note There is no way for the view to know that the contents of a QStringList have changed. If the QStringList is changed, it will be necessary to reset the model by calling QDeclarativeContext::setContextProperty() again. @@ -329,6 +331,8 @@ ListView { } \endcode +The complete example is available in \l {declarative/modelviews/objectlistmodel}. + Note the use of the fully qualified access to the \c color property. The properties of the object are not replicated in the \c model object, since they are easily available via the modelData diff --git a/doc/src/declarative/qdeclarativestates.qdoc b/doc/src/declarative/qdeclarativestates.qdoc index ef5bf98..6461925 100644 --- a/doc/src/declarative/qdeclarativestates.qdoc +++ b/doc/src/declarative/qdeclarativestates.qdoc @@ -82,4 +82,7 @@ Other things you can do in a state change: \o Run some script with StateChangeScript \endlist + +The {declarative/animation/states}{States and Transitions example} demonstrates how to declare a basic set of states and then apply animated transitions between them. + */ diff --git a/doc/src/declarative/qmlruntime.qdoc b/doc/src/declarative/qmlruntime.qdoc index 15d8567..d44e774 100644 --- a/doc/src/declarative/qmlruntime.qdoc +++ b/doc/src/declarative/qmlruntime.qdoc @@ -26,172 +26,117 @@ ****************************************************************************/ /*! - \page qmlruntime.html - \title Qt Declarative UI Runtime - \keyword QML Viewer - \ingroup qttools - - This page documents the \e{Declarative UI Runtime} for the Qt GUI - toolkit, and the \QQV which can be used to run apps - written for the runtime. The \QQV reads a declarative - user interface definition (\c .qml) file and displays the user interface it describes. - - QML is a runtime, as you can run plain QML files which pull in their required modules. - To run apps with the QML runtime, you can either start the runtime - from your own application (using a QDeclarativeView) or with the simple \QQV. - The launcher can be installed in a production environment, assuming that it is not already - present in the system. It is generally packaged alongside Qt. - - To deploy an application using the QML runtime, you have two options: - - \list - \o Write your own Qt application including a QDeclarative view and deploy it the same as - any other Qt application (not discussed further on this page), or - \o Write a main QML file for your application, and run your application using the included \QQV. - \endlist - - To run an application with the \QQV, pass the filename as an argument: - - \code - qmlviewer myQmlFile.qml - \endcode - - Deploying a QML application via the \QQV allows for QML only deployments, but can also - include custom C++ modules just as easily. Below is an example of how you might structure - a complex application deployed via the QML runtime, it is a listing of the files that would - be included in the deployment package. - - \code - MyApp.qml - MyAppCore/qmldir - MyAppCore/libMyAppCore.so - MyAppCore/MyAppCore.dll - MyAppCore/AnAppElement.qml - MyAppCore/AnotherElement.qml - MyAppCore/images/Logo.png - OtherModule/qmldir - OtherModule/OtherElement.qml - \endcode - - Note that this example is for deploying the example to both windows and linux. You will still need to compile the C++ - modules for each target platform, but you can deploy multiple versions of the modules across platforms with different naming conventions, - as the appropriate module file is chosen based on platform naming conventions. The C++ - modules must contain a QDeclarativeExtentionPlugin subclass. - - The application would be executed either with your own application, the command 'qmlviewer MyApp.qml' or by - opening the file if your system has the \QQV registered as the handler for QML files. The MyApp.qml file would have access - to all of the deployed types using the import statements such as the following: - - \code - import "MyAppCore" - import "OtherModule" 1.0 as Other - \endcode - - \section1 Qt QML Viewer functionality - The \QQV implements some additional functionality to help it supporting - myriad applications. If you implement your own application, you may also wish to reimplement - some or all of this functionality. However, much of this functionality is intended to aid the prototyping of - QML applications and may not be necessary for a deployed application. - - \section2 Options - - When run with the \c -help option, \c qmlviewer shows available options. - - \section2 Translations - - When the launcher loads an initial QML file, it will install a translation file from - a "i18n" subdirectory relative to that initial QML file. The actual translation file - loaded will be according to the system locale and have the form - "qml_<language>.qm", where <language> is a two-letter ISO 639 language, - such as "qml_fr.qm", optionally followed by an underscore and an uppercase two-letter ISO 3166 country - code, such as "qml_fr_FR.qm" or "qml_fr_CA.qm". - - Such files can be created using \l{Qt Linguist}. - - See the \l{scripting.html#internationalization}{Qt Internationalization} documentation for information about how to make - the JavaScript in QML files use translatable strings. - - Additionally, the launcher will load translation files specified on the - command line via the \c -translation option. - - \section2 Dummy Data - - The secondary use of the launcher is to allow QML files to be viewed with - dummy data. This is useful when prototyping the UI, as the dummy data can - be later replaced with actual data and bindings from a C++ plugin. - To provide dummy data: create a directory called "dummydata" in the same directory as - the target QML file and create files there with the "qml" extension. - All such files will be loaded as QML objects and bound to the root - context as a property with the name of the file (without ".qml"). - - To replace this with real data, you simply bind the real object to - the root context in C++. - - For example, if the Qt application has a "clock.time" property - that is a qreal from 0 to 86400 representing the number of seconds since - midnight, dummy data for this could be provided by \c dummydata/clock.qml: - \code - QtObject { property real time: 12345 } - \endcode - Any QML can be used in the dummy data files. You could even animate the - fictional data! - - \section2 Runtime Object - - All applications using the launcher will have access to the \c runtime - property on the root context. This property contains several pieces of - information about the runtime environment of the application. - - \section3 Screen Orientation - - A special piece of dummy data which is integrated into the launcher is - a simple orientation property. The orientation can be set via the - settings menu in the application, or by pressing Ctrl+T to rotate it. - - To use this from within your QML file, access \c runtime.orientation, - which can be one of the following values: - - \list - \o \c Orientation.Portrait - \o \c Orientation.Landscape - \o \c Orientation.PortraitInverted (Portrait orientation, upside-down) - \o \c Orientation.LandscapeInverted (Landscape orientation, upside-down) - \endlist - - These values can be bound to in your application. For example: - - \code - Item { - state: (runtime.orientation == Orientation.Landscape) ? 'landscape' : '' +\page qmlruntime.html +\title Qt Declarative UI Runtime + +QML documents are loaded and executed by the QML runtime. This includes the +Declarative UI engine along with the built-in QML elements and plugin modules, +and it also provides access to third-party QML elements and modules. + +Applications that use QML need to invoke the QML runtime in order to +execute QML documents. This can be done by creating a QDeclarativeView +or a QDeclarativeEngine, as described below. In addition, the Declarative UI +package includes the \QQV tool, which loads \c .qml files. This tool is +useful for developing and testing QML code without the need to write +a C++ application to load the QML runtime. + + + +\section1 Deploying QML-based applications + +To deploy an application that uses QML, the QML runtime must be invoked by +the application. This is done by writing a Qt C++ application that loads the +QDeclarativeEngine by either: + +\list +\o Loading the QML file through a QDeclarativeView instance, or +\o Creating a QDeclarativeEngine instance and loading QML files with QDeclarativeComponent +\endlist + + +\section2 Deploying with QDeclarativeView + +QDeclarativeView is a QWidget-based class that is able to load QML files. +For example, if there is a QML file, \c application.qml, like this: + +\qml + import Qt 4.7 + + Rectangle { width: 100; height: 100; color: "red" } +\endqml + +It can be loaded in a Qt application's \c main.cpp file like this: + +\code + #include <QApplication> + #include <QDeclarativeView> + + int main(int argc, char *argv[]) + { + QApplication app(argc, argv); + + QDeclarativeView view; + view.setSource(QUrl::fromLocalFile("application.qml")); + view.show(); + + return app.exec(); } - \endcode - - This allows your application to respond to changes in the screen's orientation. The launcher - will automatically update this on some platforms (currently the N900 only) to match the physical - screen's orientation. On other plaforms orientation changes will only happen when explictly asked for. - - \section3 Window Active - - The \c runtime.isActiveWindow property tells whether the main window of the launcher is currently active - or not. This is especially useful for embedded devices when you want to pause parts of your application, - including animations, when your application loses focus or goes to the background. - - The example below, stops the animation when the application's window is deactivated and resumes on activation: - - \code - Item { - width: 300; height: 200 - Rectangle { - width: 100; height: 100 - color: "green" - SequentialAnimation on x { - running: runtime.isActiveWindow - loops: Animation.Infinite - NumberAnimation {to: 200} - NumberAnimation {to: 0} - } - } +\endcode + +This creates a QWidget-based view that displays the contents of +\c application.qml. + +The application's \c .pro \l{qmake Project Files}{project file} must specify +the \c declarative module for the \c QT variable. For example: + +\code + TEMPLATE += app + QT += gui declarative + SOURCES += main.cpp +\endcode + + +\section2 Creating a QDeclarativeEngine directly + +If \c application.qml does not have any graphical components, or if it is +preferred to avoid QDeclarativeView for other reasons, the QDeclarativeEngine +can be constructed directly instead. In this case, \c application.qml is +loaded as a QDeclarativeComponent instance rather than placed into a view: + +\code + #include <QCoreApplication> + #include <QDeclarativeEngine> + + int main(int argc, char *argv[]) + { + QCoreApplication app(argc, argv); + + QDeclarativeEngine engine; + QDeclarativeContext *windowContext = new QDeclarativeContext(engine.rootContext()); + + QDeclarativeComponent component(&engine, "application.qml"); + QObject *window = component.create(windowContext); + + // ... delete window and windowContext when necessary + + return app.exec(); } - \endcode +\endcode + +See \l {Using QML in C++ Applications} for more information about using +QDeclarativeEngine, QDeclarativeContext and QDeclarativeComponent, as well +as details on including QML files through \l{The Qt Resource System}{Qt's Resource system}. + + + +\section1 Developing and prototyping with QML Viewer + +The Declarative UI package includes a QML runtime tool, the \QQV, which loads +and displays QML documents. This is useful during the application development +phase for prototyping QML-based applications without writing your own C++ +applications to invoke the QML runtime. + +See the \l{QML Viewer} documentation for more details. */ + diff --git a/doc/src/declarative/qmlviewer.qdoc b/doc/src/declarative/qmlviewer.qdoc new file mode 100644 index 0000000..efff9cc --- /dev/null +++ b/doc/src/declarative/qmlviewer.qdoc @@ -0,0 +1,234 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial Usage +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in a +** written agreement between you and Nokia. +** +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of this +** file. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + +\page qmlviewer.html +\title QML Viewer +\ingroup qttools + +The Declarative UI package includes \QQV, a tool for loading QML documents that +makes it easy to quickly develop and debug QML applications. It invokes the QML +runtime to load QML documents and also includes additional features useful for +the development of QML-based applications. + +The QML Viewer is a tool for testing and developing QML applications. It is +\e not intended for use in a production environment and should not be used for the +deployment of QML applications. In those cases, the QML runtime should be invoked +from a Qt application instead; see \l {Qt Declarative UI Runtime} for more +information. + +The viewer is located at QTDIR/bin/qmlviewer. To load a \c .qml file +with the viewer, run the viewer and select the file to be opened, or provide the +file path on the command line: + +\code + qmlviewer myqmlfile.qml +\endcode + +On Mac OS X, the QML Viewer application is named \c QMLViewer.app instead. You +can launch the viewer by opening the QMLViewer application from the Finder, or +from the command line: + +\code + QMLViewer.app/Contents/MacOS/QMLViewer myqmlfile.qml +\endcode + +The QML Viewer has a number of configuration options involving features such as +fullscreen display, module import path configurations, video recording of QML +animations, and OpenGL support. + +To see the configuration options, run \c qmlviewer with the \c -help argument. + + +\section1 Adding module import paths + +Additional module import paths can be provided using the \c -I flag. +For example, the \l{declarative/cppextensions/plugins}{QML plugins example} creates +a C++ plugin identified as \c com.nokia.TimeExample. Since this has a namespaced +identifier, the viewer has to be run with the \c -I flag from the example's +base directory: + +\code +qmlviewer -I . plugins.qml +\endcode + +This adds the current directory to the import path so that the viewer will +find the plugin in the \c com/nokia/TimeExample directory. + +Note by default, the current directory is included in the import search path, +but namespaced modules like \c com.nokia.TimeExample are not found unless +the path is explicitly added. + + +\section1 Loading translation files + +When the QML Viewer loads a QML file, it installs a translation file from a +"i18n" subdirectory relative to that initial file. This directory should contain +translation files named "qml_<language>.qm", where <language> is a two-letter +ISO 639 language, such as "qml_fr.qm", optionally followed by an underscore and +an uppercase two-letter ISO 3166 country code, such as "qml_fr_FR.qm" or +"qml_fr_CA.qm". + +Such files can be created using \l {Qt Linguist}. + +The actual translation file that is loaded depends on the system locale. +Additionally, the viewer will load any translation files specified on the command +line via the \c -translation option. + +See the \l{declarative/i18n}{QML i18n example} for an example. Also, the +\l{scripting.html#internationalization}{Qt Internationalization} documentation +shows how JavaScript code in QML files can be made to use translatable strings. + + +\section1 Loading placeholder data with QML Viewer + +Often, QML applications are prototyped with fake data that is later replaced +by real data sources from C++ plugins. QML Viewer assists in this aspect by +loading fake data into the application context: it looks for a directory named +"dummydata" in the same directory as the target QML file, and any \c .qml +files in that directory are loaded as QML objects and bound to the root context +as properties named after the files. + +For example, this QML document refers to a \c lottoNumbers property which does +not actually exist within the document: + +\qml +import Qt 4.7 + +ListView { + width: 200; height: 300 + model: lottoNumbers + delegate: Text { text: number } +} +\endqml + +If within the document's directory, there is a "dummydata" directory which +contains a \c lottoNumbers.qml file like this: + +\qml +import Qt 4.7 + +ListModel { + ListElement { number: 23 } + ListElement { number: 44 } + ListElement { number: 78 } +} +\endqml + +Then this model would be automatically loaded into the ListView in the previous document. + +Child properties are included when loaded from dummy data. The following document +refers to a \c clock.time property: + +\qml +import Qt 4.7 +Text { text: clock.time } +\endqml + +The text value could be filled by a \c dummydata/clock.qml file with a \c time +property in the root context: + +\qml +import Qt 4.7 +QtObject { property int time: 54321 } +\endqml + +To replace this with real data, you can simply bind the real data object to +the root context in C++ using QDeclarativeContext::setContextProperty(). This +is detailed in \l {Using QML in C++ Applications}. + +\section1 Using the \c runtime object + +QML applications that are loaded with the QML Viewer have access to a special +\c runtime property on the root context. This property provides additional +information about the application's runtime environment through the following properties: + +\table +\row + +\o \c runtime.isActiveWindow + +\o This property indicates whether the QML Viewer window is the current active +window on the system. It is useful for "pausing" an application, particularly +animations, when the QML Viewer loses focus or moves to the background. + +For example, the following animation is only played when the QML Viewer is +the active window: + +\qml +Rectangle { + width: 200; height: 200 + + ColorAnimation on color { + running: runtime.isActiveWindow + loops: Animation.Infinite + from: "green"; to: "blue"; duration: 2000 + } +} +\endqml + +\row + +\o \c runtime.orientation + +\o This property indicates the current orientation of the QML Viewer. On the +N900 platform, this property automatically updates to reflect the device's +actual orientation; on other platforms, this indicates the orientation currently +selected in the QML Viewer's \e {Settings -> Properties} menu. The +\c orientation value can be one of the following: + +\list +\o \c Orientation.Portrait +\o \c Orientation.Landscape +\o \c Orientation.PortraitInverted (Portrait orientation, upside-down) +\o \c Orientation.LandscapeInverted (Landscape orientation, upside-down) +\endlist + +When the viewer's orientation changes, the appearance of the loaded QML document +does not change unless it has been set to respond to changes in +\c runtime.orientation. For example, the following Rectangle changes its +aspect ratio depending on the orientation of the QML Viewer: + +\qml +Rectangle { + id: window + width: 640; height: 480 + + states: State { + name: "landscape" + PropertyChanges { target: window; width: 480; height: 640 } + } + state: (runtime.orientation == Orientation.Landscape + || runtime.orientation == Orientation.LandscapeInverted) ? 'landscape' : '' +} +\endqml + +\endtable + +*/ + diff --git a/doc/src/declarative/tutorial.qdoc b/doc/src/declarative/tutorial.qdoc index 252c11e..c884486 100644 --- a/doc/src/declarative/tutorial.qdoc +++ b/doc/src/declarative/tutorial.qdoc @@ -222,5 +222,5 @@ This is equivalent to writing the two transitions separately. The \l ParallelAnimation element makes sure that the two types of animations (number and color) start at the same time. We could also run them one after the other by using \l SequentialAnimation instead. -For more details on states and transitions, see \l {QML States}. +For more details on states and transitions, see \l {QML States} and the {declarative/animation/states}{states and transitions example}. */ diff --git a/doc/src/images/qml-focus-example.png b/doc/src/images/qml-focus-example.png Binary files differindex 0ec2bff..107d2cb 100644 --- a/doc/src/images/qml-focus-example.png +++ b/doc/src/images/qml-focus-example.png diff --git a/doc/src/images/qml-xmlhttprequest-example.png b/doc/src/images/qml-xmlhttprequest-example.png Binary files differindex 68e7d27..f585613 100644 --- a/doc/src/images/qml-xmlhttprequest-example.png +++ b/doc/src/images/qml-xmlhttprequest-example.png diff --git a/examples/declarative/animation/behaviors/behavior-example.qml b/examples/declarative/animation/behaviors/behavior-example.qml index d187fbf..adefb9e 100644 --- a/examples/declarative/animation/behaviors/behavior-example.qml +++ b/examples/declarative/animation/behaviors/behavior-example.qml @@ -82,7 +82,7 @@ Rectangle { property string text - x: 62.5; y: 75; width: 75; height: 50 + x: 62; y: 75; width: 75; height: 50 radius: 6 border.width: 4; border.color: "white" color: "firebrick" diff --git a/examples/declarative/cppextensions/cppextensions.qmlproject b/examples/declarative/cppextensions/cppextensions.qmlproject index d4909f8..6b36284 100644 --- a/examples/declarative/cppextensions/cppextensions.qmlproject +++ b/examples/declarative/cppextensions/cppextensions.qmlproject @@ -12,5 +12,5 @@ Project { directory: "." } /* List of plugin directories passed to QML runtime */ - // importPaths: [ " ../exampleplugin " ] + importPaths: [ "plugins" ] } diff --git a/examples/declarative/keyinteraction/focus/Core/GridMenu.qml b/examples/declarative/keyinteraction/focus/Core/GridMenu.qml index d0b45f5..9a8d3f3 100644 --- a/examples/declarative/keyinteraction/focus/Core/GridMenu.qml +++ b/examples/declarative/keyinteraction/focus/Core/GridMenu.qml @@ -55,10 +55,11 @@ FocusScope { GridView { id: gridView - x: 20; width: parent.width - 40; height: parent.height + anchors.fill: parent; anchors.leftMargin: 20; anchors.rightMargin: 20 cellWidth: 152; cellHeight: 152 focus: true model: 12 + KeyNavigation.down: listViews KeyNavigation.left: contextMenu @@ -70,9 +71,9 @@ FocusScope { id: content color: "transparent" smooth: true - anchors.centerIn: parent; width: container.width - 40; height: container.height - 40; radius: 10 + anchors.fill: parent; anchors.margins: 20; radius: 10 - Rectangle { color: "#91AA9D"; x: 3; y: 3; width: parent.width - 6; height: parent.height - 6; radius: 8 } + Rectangle { color: "#91AA9D"; anchors.fill: parent; anchors.margins: 3; radius: 8; smooth: true } Image { source: "images/qt-logo.png"; anchors.centerIn: parent; smooth: true } } diff --git a/examples/declarative/keyinteraction/focus/Core/ListViewDelegate.qml b/examples/declarative/keyinteraction/focus/Core/ListViewDelegate.qml index fba9b05..cc13637 100644 --- a/examples/declarative/keyinteraction/focus/Core/ListViewDelegate.qml +++ b/examples/declarative/keyinteraction/focus/Core/ListViewDelegate.qml @@ -42,7 +42,7 @@ import Qt 4.7 Item { id: container - x: 5; width: ListView.view.width - 10; height: 60 + width: ListView.view.width; height: 60; anchors.leftMargin: 10; anchors.rightMargin: 10 Rectangle { id: content @@ -51,11 +51,15 @@ Item { smooth: true radius: 10 - Rectangle { color: "#91AA9D"; x: 3; y: 3; width: parent.width - 6; height: parent.height - 6; radius: 8 } - Text { - text: "List element " + (index + 1); color: "#193441"; font.bold: false; anchors.centerIn: parent - font.pixelSize: 14 - } + Rectangle { anchors.fill: parent; anchors.margins: 3; color: "#91AA9D"; smooth: true; radius: 8 } + } + + Text { + id: label + anchors.centerIn: content + text: "List element " + (index + 1) + color: "#193441" + font.pixelSize: 14 } MouseArea { @@ -72,6 +76,7 @@ Item { states: State { name: "active"; when: container.focus == true PropertyChanges { target: content; color: "#FCFFF5"; scale: 1.1 } + PropertyChanges { target: label; font.pixelSize: 16 } } transitions: Transition { diff --git a/examples/declarative/keyinteraction/focus/Core/ListViews.qml b/examples/declarative/keyinteraction/focus/Core/ListViews.qml index 670a3fa..6f9ceb4 100644 --- a/examples/declarative/keyinteraction/focus/Core/ListViews.qml +++ b/examples/declarative/keyinteraction/focus/Core/ListViews.qml @@ -60,7 +60,7 @@ FocusScope { ListView { id: list2 - y: wantsFocus ? 10 : 40; x: parent.width / 3; width: parent.width / 3; height: parent.height - 20 + y: wantsFocus ? 10 : 40; x: parseInt(parent.width / 3); width: parent.width / 3; height: parent.height - 20 KeyNavigation.up: gridMenu; KeyNavigation.left: list1; KeyNavigation.right: list3 model: 10; cacheBuffer: 200 delegate: ListViewDelegate {} @@ -72,7 +72,7 @@ FocusScope { ListView { id: list3 - y: wantsFocus ? 10 : 40; x: 2 * parent.width / 3; width: parent.width / 3; height: parent.height - 20 + y: wantsFocus ? 10 : 40; x: parseInt(2 * parent.width / 3); width: parent.width / 3; height: parent.height - 20 KeyNavigation.up: gridMenu; KeyNavigation.left: list2 model: 10; cacheBuffer: 200 delegate: ListViewDelegate {} diff --git a/examples/declarative/keyinteraction/focus/focus.qml b/examples/declarative/keyinteraction/focus/focus.qml index 068ba1d..8b2af70 100644 --- a/examples/declarative/keyinteraction/focus/focus.qml +++ b/examples/declarative/keyinteraction/focus/focus.qml @@ -68,7 +68,8 @@ Rectangle { Rectangle { id: shade - color: "black"; opacity: 0; anchors.fill: parent + anchors.fill: parent + color: "black"; opacity: 0 } states: State { @@ -88,7 +89,7 @@ Rectangle { anchors.verticalCenter: parent.verticalCenter MouseArea { - anchors { fill: parent; leftMargin: -10; topMargin: -10; rightMargin: -10; bottomMargin: -10 } + anchors.fill: parent; anchors.margins: -10 onClicked: window.state = "contextMenuOpen" } } diff --git a/examples/declarative/ui-components/progressbar/content/ProgressBar.qml b/examples/declarative/ui-components/progressbar/content/ProgressBar.qml index 829ab9b..6aa6765 100644 --- a/examples/declarative/ui-components/progressbar/content/ProgressBar.qml +++ b/examples/declarative/ui-components/progressbar/content/ProgressBar.qml @@ -66,7 +66,7 @@ Item { width: highlight.widthDest Behavior on width { SmoothedAnimation { velocity: 1200 } } - anchors { left: parent.left; top: parent.top; bottom: parent.bottom; leftMargin: 3; topMargin: 3; bottomMargin: 3 } + anchors { left: parent.left; top: parent.top; bottom: parent.bottom; margins: 3 } radius: 1 gradient: Gradient { GradientStop { id: gradient1; position: 0.0 } diff --git a/examples/declarative/ui-components/searchbox/SearchBox.qml b/examples/declarative/ui-components/searchbox/SearchBox.qml index e6b9c8f..6d87837 100644 --- a/examples/declarative/ui-components/searchbox/SearchBox.qml +++ b/examples/declarative/ui-components/searchbox/SearchBox.qml @@ -73,7 +73,7 @@ FocusScope { TextInput { id: textInput - anchors { left: parent.left; leftMargin: 8; verticalCenter: parent.verticalCenter } + anchors { left: parent.left; leftMargin: 8; right: clear.left; rightMargin: 8; verticalCenter: parent.verticalCenter } focus: true } diff --git a/examples/declarative/ui-components/tabwidget/main.qml b/examples/declarative/ui-components/tabwidget/main.qml index e11902a..4a27806 100644 --- a/examples/declarative/ui-components/tabwidget/main.qml +++ b/examples/declarative/ui-components/tabwidget/main.qml @@ -50,7 +50,7 @@ TabWidget { color: "#e3e3e3" Rectangle { - anchors { fill: parent; topMargin: 20; leftMargin: 20; rightMargin: 20; bottomMargin: 20 } + anchors.fill: parent; anchors.margins: 20 color: "#ff7f7f" Text { width: parent.width - 20 @@ -68,7 +68,7 @@ TabWidget { color: "#e3e3e3" Rectangle { - anchors { fill: parent; topMargin: 20; leftMargin: 20; rightMargin: 20; bottomMargin: 20 } + anchors.fill: parent; anchors.margins: 20 color: "#7fff7f" Text { width: parent.width - 20 @@ -85,7 +85,7 @@ TabWidget { anchors.fill: parent; color: "#e3e3e3" Rectangle { - anchors { fill: parent; topMargin: 20; leftMargin: 20; rightMargin: 20; bottomMargin: 20 } + anchors.fill: parent; anchors.margins: 20 color: "#7f7fff" Text { width: parent.width - 20 diff --git a/src/3rdparty/webkit/WebKit/qt/declarative/qdeclarativewebview.cpp b/src/3rdparty/webkit/WebKit/qt/declarative/qdeclarativewebview.cpp index a349bec..0342c9f 100644 --- a/src/3rdparty/webkit/WebKit/qt/declarative/qdeclarativewebview.cpp +++ b/src/3rdparty/webkit/WebKit/qt/declarative/qdeclarativewebview.cpp @@ -180,6 +180,8 @@ void GraphicsWebView::mouseMoveEvent(QGraphicsSceneMouseEvent* event) When this item has keyboard focus, all keyboard input will be sent directly to the web page within. + + \sa {declarative/modelviews/webview}{WebView example}, {demos/declarative/webbrowser}{Web Browser demo} */ /*! diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 432b5d6..336fbbf 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -14,6 +14,8 @@ Component: - isReady, isLoading, isError and isNull properties removed, use status property instead - errorsString() renamed to errorString() +ListView: + - ListView.prevSection property changed to ListView.previousSection TextInput xToPosition -> positionAt (to match TextEdit.positionAt) diff --git a/src/declarative/debugger/qdeclarativedebug.cpp b/src/declarative/debugger/qdeclarativedebug.cpp index cd5340b..e4a991b 100644 --- a/src/declarative/debugger/qdeclarativedebug.cpp +++ b/src/declarative/debugger/qdeclarativedebug.cpp @@ -562,6 +562,33 @@ QDeclarativeDebugExpressionQuery *QDeclarativeEngineDebug::queryExpressionResult return query; } +QDeclarativeDebugExpressionQuery *QDeclarativeEngineDebug::setBindingForObject(int objectDebugId, + const QString &propertyName, + const QVariant &bindingExpression, + bool isLiteralValue, + QObject *parent) +{ + Q_D(QDeclarativeEngineDebug); + + QDeclarativeDebugExpressionQuery *query = new QDeclarativeDebugExpressionQuery(parent); + if (d->client->isConnected() && objectDebugId != -1) { + query->m_client = this; + query->m_expr = bindingExpression; + int queryId = d->getId(); + query->m_queryId = queryId; + d->expressionQuery.insert(queryId, query); + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + ds << QByteArray("SET_BINDING") << queryId << objectDebugId << propertyName << bindingExpression << isLiteralValue; + d->client->sendMessage(message); + } else { + query->m_state = QDeclarativeDebugQuery::Error; + } + + return query; +} + QDeclarativeDebugWatch::QDeclarativeDebugWatch(QObject *parent) : QObject(parent), m_state(Waiting), m_queryId(-1), m_client(0), m_objectDebugId(-1) { @@ -698,7 +725,7 @@ QDeclarativeDebugExpressionQuery::~QDeclarativeDebugExpressionQuery() QDeclarativeEngineDebugPrivate::remove(m_client, this); } -QString QDeclarativeDebugExpressionQuery::expression() const +QVariant QDeclarativeDebugExpressionQuery::expression() const { return m_expr; } diff --git a/src/declarative/debugger/qdeclarativedebug_p.h b/src/declarative/debugger/qdeclarativedebug_p.h index 4ead232..007cbd7 100644 --- a/src/declarative/debugger/qdeclarativedebug_p.h +++ b/src/declarative/debugger/qdeclarativedebug_p.h @@ -94,7 +94,11 @@ public: QDeclarativeDebugExpressionQuery *queryExpressionResult(int objectDebugId, const QString &expr, QObject *parent = 0); - + QDeclarativeDebugExpressionQuery *setBindingForObject(int objectDebugId, + const QString &propertyName, + const QVariant &bindingExpression, + bool isLiteralValue, + QObject *parent = 0); private: Q_DECLARE_PRIVATE(QDeclarativeEngineDebug) }; @@ -198,6 +202,11 @@ public: private: friend class QDeclarativeEngineDebugPrivate; + QDeclarativeDebugExpressionQuery *setBindingForObject(int objectDebugId, + const QString &propertyName, + const QVariant &bindingExpression, + bool isLiteralValue, + QObject *parent); QUrl m_url; int m_lineNumber; int m_columnNumber; @@ -215,6 +224,11 @@ public: QString name() const; private: + QDeclarativeDebugExpressionQuery *setBindingForObject(int objectDebugId, + const QString &propertyName, + const QVariant &bindingExpression, + bool isLiteralValue, + QObject *parent); friend class QDeclarativeEngineDebugPrivate; int m_debugId; QString m_name; @@ -348,7 +362,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeDebugExpressionQuery : public QDeclarativ Q_OBJECT public: virtual ~QDeclarativeDebugExpressionQuery(); - QString expression() const; + QVariant expression() const; QVariant result() const; private: friend class QDeclarativeEngineDebug; @@ -356,7 +370,7 @@ private: QDeclarativeDebugExpressionQuery(QObject *); QDeclarativeEngineDebug *m_client; int m_queryId; - QString m_expr; + QVariant m_expr; QVariant m_result; }; diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 3f681b7..65bc233 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -122,7 +122,7 @@ void QDeclarativeFlickableVisibleArea::updateVisible() QDeclarativeFlickablePrivate::QDeclarativeFlickablePrivate() - : viewport(new QDeclarativeItem) + : contentItem(new QDeclarativeItem) , hData(this, &QDeclarativeFlickablePrivate::setRoundedViewportX) , vData(this, &QDeclarativeFlickablePrivate::setRoundedViewportY) , flickingHorizontally(false), flickingVertically(false) @@ -140,8 +140,8 @@ QDeclarativeFlickablePrivate::QDeclarativeFlickablePrivate() void QDeclarativeFlickablePrivate::init() { Q_Q(QDeclarativeFlickable); - QDeclarative_setParent_noEvent(viewport, q); - viewport->setParentItem(q); + QDeclarative_setParent_noEvent(contentItem, q); + contentItem->setParentItem(q); static int timelineUpdatedIdx = -1; static int timelineCompletedIdx = -1; static int flickableTickedIdx = -1; @@ -158,7 +158,7 @@ void QDeclarativeFlickablePrivate::init() q, flickableMovementEndingIdx, Qt::DirectConnection); q->setAcceptedMouseButtons(Qt::LeftButton); q->setFiltersChildEvents(true); - QDeclarativeItemPrivate *viewportPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(viewport)); + QDeclarativeItemPrivate *viewportPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(contentItem)); viewportPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); lastPosTime.invalidate(); } @@ -182,7 +182,7 @@ qreal QDeclarativeFlickablePrivate::overShootDistance(qreal velocity, qreal size void QDeclarativeFlickablePrivate::itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeom, const QRectF &oldGeom) { Q_Q(QDeclarativeFlickable); - if (item == viewport) { + if (item == contentItem) { if (newGeom.x() != oldGeom.x()) emit q->contentXChanged(); if (newGeom.y() != oldGeom.y()) @@ -579,10 +579,28 @@ void QDeclarativeFlickable::ticked() viewportMoved(); } -QDeclarativeItem *QDeclarativeFlickable::viewport() +/*! + \qmlproperty Item Flickable::contentItem + + The internal item that contains the Items to be moved in the Flickable. + + Items declared as children of a Flickable are automatically parented to the Flickable's contentItem. + + Items created dynamically need to be explicitly parented to the \e contentItem: + \code + Flickable { + id: myFlickable + function addItem(file) { + var component = Qt.createComponent(file) + component.createObject(myFlickable.contentItem); + } + } + \endcode +*/ +QDeclarativeItem *QDeclarativeFlickable::contentItem() { Q_D(QDeclarativeFlickable); - return d->viewport; + return d->contentItem; } QDeclarativeFlickableVisibleArea *QDeclarativeFlickable::visibleArea() @@ -899,12 +917,12 @@ void QDeclarativeFlickablePrivate::clearDelayedPress() void QDeclarativeFlickablePrivate::setRoundedViewportX(qreal x) { - viewport->setX(qRound(x)); + contentItem->setX(qRound(x)); } void QDeclarativeFlickablePrivate::setRoundedViewportY(qreal y) { - viewport->setY(qRound(y)); + contentItem->setY(qRound(y)); } void QDeclarativeFlickable::timerEvent(QTimerEvent *event) @@ -991,13 +1009,13 @@ void QDeclarativeFlickable::geometryChanged(const QRectF &newGeometry, bool changed = false; if (newGeometry.width() != oldGeometry.width()) { if (d->hData.viewSize < 0) { - d->viewport->setWidth(width()); + d->contentItem->setWidth(width()); emit contentWidthChanged(); } } if (newGeometry.height() != oldGeometry.height()) { if (d->vData.viewSize < 0) { - d->viewport->setHeight(height()); + d->contentItem->setHeight(height()); emit contentHeightChanged(); } } @@ -1018,7 +1036,7 @@ void QDeclarativeFlickablePrivate::data_append(QDeclarativeListProperty<QObject> { QDeclarativeItem *i = qobject_cast<QDeclarativeItem *>(o); if (i) - i->setParentItem(static_cast<QDeclarativeFlickablePrivate*>(prop->data)->viewport); + i->setParentItem(static_cast<QDeclarativeFlickablePrivate*>(prop->data)->contentItem); else o->setParent(prop->object); } @@ -1032,7 +1050,7 @@ QDeclarativeListProperty<QObject> QDeclarativeFlickable::flickableData() QDeclarativeListProperty<QGraphicsObject> QDeclarativeFlickable::flickableChildren() { Q_D(QDeclarativeFlickable); - return QGraphicsItemPrivate::get(d->viewport)->childrenList(); + return QGraphicsItemPrivate::get(d->contentItem)->childrenList(); } /*! @@ -1102,9 +1120,9 @@ void QDeclarativeFlickable::setContentWidth(qreal w) return; d->hData.viewSize = w; if (w < 0) - d->viewport->setWidth(width()); + d->contentItem->setWidth(width()); else - d->viewport->setWidth(w); + d->contentItem->setWidth(w); // Make sure that we're entirely in view. if (!d->pressed && !d->movingHorizontally && !d->movingVertically) { int oldDuration = d->fixupDuration; @@ -1129,9 +1147,9 @@ void QDeclarativeFlickable::setContentHeight(qreal h) return; d->vData.viewSize = h; if (h < 0) - d->viewport->setHeight(height()); + d->contentItem->setHeight(height()); else - d->viewport->setHeight(h); + d->contentItem->setHeight(h); // Make sure that we're entirely in view. if (!d->pressed && !d->movingHorizontally && !d->movingVertically) { int oldDuration = d->fixupDuration; diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p.h index d40a0dc..eb738d9 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p.h @@ -60,6 +60,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeFlickable : public QDeclarativeItem Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged) Q_PROPERTY(qreal contentX READ contentX WRITE setContentX NOTIFY contentXChanged) Q_PROPERTY(qreal contentY READ contentY WRITE setContentY NOTIFY contentYChanged) + Q_PROPERTY(QDeclarativeItem *contentItem READ contentItem CONSTANT) Q_PROPERTY(qreal horizontalVelocity READ horizontalVelocity NOTIFY horizontalVelocityChanged) Q_PROPERTY(qreal verticalVelocity READ verticalVelocity NOTIFY verticalVelocityChanged) @@ -111,10 +112,10 @@ public: void setContentHeight(qreal); qreal contentX() const; - void setContentX(qreal pos); + virtual void setContentX(qreal pos); qreal contentY() const; - void setContentY(qreal pos); + virtual void setContentY(qreal pos); bool isMoving() const; bool isMovingHorizontally() const; @@ -143,7 +144,7 @@ public: bool isAtYEnd() const; bool isAtYBeginning() const; - QDeclarativeItem *viewport(); + QDeclarativeItem *contentItem(); enum FlickableDirection { AutoFlickDirection=0x00, HorizontalFlick=0x01, VerticalFlick=0x02, HorizontalAndVerticalFlick=0x03 }; FlickableDirection flickDirection() const; // deprecated diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h index 66d2678..b919e1b 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h @@ -125,7 +125,7 @@ public: void itemGeometryChanged(QDeclarativeItem *, const QRectF &, const QRectF &); public: - QDeclarativeItem *viewport; + QDeclarativeItem *contentItem; AxisData hData; AxisData vData; diff --git a/src/declarative/graphicsitems/qdeclarativefocusscope.cpp b/src/declarative/graphicsitems/qdeclarativefocusscope.cpp index 4bd2a86..e8e6fa2 100644 --- a/src/declarative/graphicsitems/qdeclarativefocusscope.cpp +++ b/src/declarative/graphicsitems/qdeclarativefocusscope.cpp @@ -54,6 +54,8 @@ QT_BEGIN_NAMESPACE Focus scopes assist in keyboard focus handling when building reusable QML components. All the details are covered in the \l {qmlfocus}{keyboard focus documentation}. + + \sa {declarative/keyinteraction/focus}{Keyboard focus example} */ /*! diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 3792595..cb99129 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -151,9 +151,9 @@ public: void setPosition(qreal pos) { Q_Q(QDeclarativeGridView); if (flow == QDeclarativeGridView::LeftToRight) - q->setContentY(pos); + q->QDeclarativeFlickable::setContentY(pos); else - q->setContentX(pos); + q->QDeclarativeFlickable::setContentX(pos); } int size() const { Q_Q(const QDeclarativeGridView); @@ -421,10 +421,10 @@ FxGridItem *QDeclarativeGridViewPrivate::createItem(int modelIndex) if (model->completePending()) { // complete listItem->item->setZValue(1); - listItem->item->setParentItem(q->viewport()); + listItem->item->setParentItem(q->contentItem()); model->completeItem(); } else { - listItem->item->setParentItem(q->viewport()); + listItem->item->setParentItem(q->contentItem()); } unrequestedItems.remove(listItem->item); } @@ -716,12 +716,12 @@ void QDeclarativeGridViewPrivate::createHighlight() } } else { item = new QDeclarativeItem; - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); } if (item) { - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); highlight = new FxGridItem(item, q); highlightXAnimator = new QSmoothedAnimation(q); highlightXAnimator->target = QDeclarativeProperty(highlight->item, QLatin1String("x")); @@ -808,8 +808,8 @@ void QDeclarativeGridViewPrivate::updateFooter() delete context; } if (item) { - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); item->setZValue(1); QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item)); itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); @@ -854,8 +854,8 @@ void QDeclarativeGridViewPrivate::updateHeader() delete context; } if (item) { - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); item->setZValue(1); QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item)); itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); @@ -1099,6 +1099,8 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m is not clipped by another item or the screen, it will be necessary to set \e {clip: true} in order to have the out of view items clipped nicely. + + \sa {declarative/modelviews/gridview}{GridView example} */ QDeclarativeGridView::QDeclarativeGridView(QDeclarativeItem *parent) : QDeclarativeFlickable(*(new QDeclarativeGridViewPrivate), parent) @@ -1742,6 +1744,22 @@ void QDeclarativeGridView::setHeader(QDeclarativeComponent *header) } } +void QDeclarativeGridView::setContentX(qreal pos) +{ + Q_D(QDeclarativeGridView); + // Positioning the view manually should override any current movement state + d->moveReason = QDeclarativeGridViewPrivate::Other; + QDeclarativeFlickable::setContentX(pos); +} + +void QDeclarativeGridView::setContentY(qreal pos) +{ + Q_D(QDeclarativeGridView); + // Positioning the view manually should override any current movement state + d->moveReason = QDeclarativeGridViewPrivate::Other; + QDeclarativeFlickable::setContentY(pos); +} + bool QDeclarativeGridView::event(QEvent *event) { Q_D(QDeclarativeGridView); @@ -1919,6 +1937,8 @@ void QDeclarativeGridView::keyPressEvent(QKeyEvent *event) Move the currentIndex up one item in the view. The current index will wrap if keyNavigationWraps is true and it is currently at the end. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativeGridView::moveCurrentIndexUp() { @@ -1942,6 +1962,8 @@ void QDeclarativeGridView::moveCurrentIndexUp() Move the currentIndex down one item in the view. The current index will wrap if keyNavigationWraps is true and it is currently at the end. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativeGridView::moveCurrentIndexDown() { @@ -1965,6 +1987,8 @@ void QDeclarativeGridView::moveCurrentIndexDown() Move the currentIndex left one item in the view. The current index will wrap if keyNavigationWraps is true and it is currently at the end. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativeGridView::moveCurrentIndexLeft() { @@ -1988,6 +2012,8 @@ void QDeclarativeGridView::moveCurrentIndexLeft() Move the currentIndex right one item in the view. The current index will wrap if keyNavigationWraps is true and it is currently at the end. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativeGridView::moveCurrentIndexRight() { @@ -2028,6 +2054,14 @@ void QDeclarativeGridView::moveCurrentIndexRight() at a particular index. This is unreliable since removing items from the start of the view does not cause all other items to be repositioned. The correct way to bring an item into view is with \c positionViewAtIndex. + + \bold Note: methods should only be called after the Component has completed. To position + the view at startup, this method should be called by Component.onCompleted. For + example, to position the view at the end: + + \code + Component.onCompleted: positionViewAtIndex(count - 1, GridView.Beginning) + \endcode */ void QDeclarativeGridView::positionViewAtIndex(int index, int mode) { @@ -2037,6 +2071,8 @@ void QDeclarativeGridView::positionViewAtIndex(int index, int mode) if (mode < Beginning || mode > Contain) return; + if (d->layoutScheduled) + d->layout(); qreal pos = d->position(); FxGridItem *item = d->visibleItem(index); if (!item) { @@ -2079,6 +2115,8 @@ void QDeclarativeGridView::positionViewAtIndex(int index, int mode) pos = qMin(pos, maxExtent); qreal minExtent = d->flow == QDeclarativeGridView::LeftToRight ? -minYExtent() : -minXExtent(); pos = qMax(pos, minExtent); + d->moveReason = QDeclarativeGridViewPrivate::Other; + cancelFlick(); d->setPosition(pos); } d->fixupPosition(); @@ -2093,6 +2131,8 @@ void QDeclarativeGridView::positionViewAtIndex(int index, int mode) If the item is outside the visible area, -1 is returned, regardless of whether an item will exist at that point when scrolled into view. + + \bold Note: methods should only be called after the Component has completed. */ int QDeclarativeGridView::indexAt(int x, int y) const { @@ -2113,10 +2153,16 @@ void QDeclarativeGridView::componentComplete() d->updateGrid(); if (d->isValid()) { refill(); + d->moveReason = QDeclarativeGridViewPrivate::SetIndex; if (d->currentIndex < 0) d->updateCurrent(0); else d->updateCurrent(d->currentIndex); + if (d->highlight) { + d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos()); + d->updateTrackedItem(); + } + d->moveReason = QDeclarativeGridViewPrivate::Other; d->fixupPosition(); } } diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h index 021aad9..64b91d8 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview_p.h +++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h @@ -151,6 +151,9 @@ public: QDeclarativeComponent *header() const; void setHeader(QDeclarativeComponent *); + virtual void setContentX(qreal pos); + virtual void setContentY(qreal pos); + enum PositionMode { Beginning, Center, End, Visible, Contain }; Q_INVOKABLE void positionViewAtIndex(int index, int mode); diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index ec08517..ff61302 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -199,6 +199,7 @@ void QDeclarativeImagePrivate::setPixmap(const QPixmap &pixmap) fillMode: Image.PreserveAspectCrop smooth: true source: "qtlogo.png" + clip: true } \endqml @@ -220,6 +221,7 @@ void QDeclarativeImagePrivate::setPixmap(const QPixmap &pixmap) Image { width: 120; height: 120 fillMode: Image.TileVertically + smooth: true source: "qtlogo.png" } \endqml @@ -231,11 +233,14 @@ void QDeclarativeImagePrivate::setPixmap(const QPixmap &pixmap) Image { width: 120; height: 120 fillMode: Image.TileHorizontally + smooth: true source: "qtlogo.png" } \endqml \endtable + + \sa {declarative/imageelements/image}{Image example} */ QDeclarativeImage::FillMode QDeclarativeImage::fillMode() const { diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 336010f..9a17d78 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -149,7 +149,7 @@ QT_BEGIN_NAMESPACE } \endqml - \sa Rotate, Translate + \sa Rotation, Translate */ /*! @@ -196,6 +196,8 @@ QT_BEGIN_NAMESPACE \snippet doc/src/snippets/declarative/rotation.qml 0 \image axisrotation.png + + \sa {declarative/ui-components/dialcontrol}{Dial Control example}, {declarative/toys/clocks}{Clocks example} */ /*! diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 06a3239..4be8705 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -105,7 +105,7 @@ public: else return (view->orientation() == QDeclarativeListView::Vertical ? item->y() : item->x()); } - int size() const { + qreal size() const { if (section) return (view->orientation() == QDeclarativeListView::Vertical ? item->height()+section->height() : item->width()+section->height()); else @@ -216,9 +216,9 @@ public: void setPosition(qreal pos) { Q_Q(QDeclarativeListView); if (orient == QDeclarativeListView::Vertical) - q->setContentY(pos); + q->QDeclarativeFlickable::setContentY(pos); else - q->setContentX(pos); + q->QDeclarativeFlickable::setContentX(pos); } qreal size() const { Q_Q(const QDeclarativeListView); @@ -421,7 +421,7 @@ public: void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) { Q_Q(QDeclarativeListView); QDeclarativeFlickablePrivate::itemGeometryChanged(item, newGeometry, oldGeometry); - if (item != viewport && (!highlight || item != highlight->item)) { + if (item != contentItem && (!highlight || item != highlight->item)) { if ((orient == QDeclarativeListView::Vertical && newGeometry.height() != oldGeometry.height()) || (orient == QDeclarativeListView::Horizontal && newGeometry.width() != oldGeometry.width())) { scheduleLayout(); @@ -476,7 +476,7 @@ public: QHash<QDeclarativeItem*,int> unrequestedItems; FxListItem *currentItem; QDeclarativeListView::Orientation orient; - int visiblePos; + qreal visiblePos; int visibleIndex; qreal averageSize; int currentIndex; @@ -575,15 +575,19 @@ FxListItem *QDeclarativeListViewPrivate::createItem(int modelIndex) listItem->attached->m_prevSection = item->attached->section(); else listItem->attached->m_prevSection = sectionAt(modelIndex-1); + if (FxListItem *item = visibleItem(modelIndex+1)) + listItem->attached->m_nextSection = item->attached->section(); + else + listItem->attached->m_nextSection = sectionAt(modelIndex+1); } } if (model->completePending()) { // complete listItem->item->setZValue(1); - listItem->item->setParentItem(q->viewport()); + listItem->item->setParentItem(q->contentItem()); model->completeItem(); } else { - listItem->item->setParentItem(q->viewport()); + listItem->item->setParentItem(q->contentItem()); } QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item)); itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); @@ -655,7 +659,7 @@ void QDeclarativeListViewPrivate::refill(qreal from, qreal to, bool doBuffer) bool changed = false; FxListItem *item = 0; - int pos = itemEnd + 1; + qreal pos = itemEnd + 1; while (modelIndex < model->count() && pos <= fillTo) { // qDebug() << "refill: append item" << modelIndex << "pos" << pos; if (!(item = createItem(modelIndex))) @@ -744,8 +748,8 @@ void QDeclarativeListViewPrivate::layout() } updateSections(); if (!visibleItems.isEmpty()) { - int oldEnd = visibleItems.last()->endPosition(); - int pos = visibleItems.first()->endPosition() + spacing + 1; + qreal oldEnd = visibleItems.last()->endPosition(); + qreal pos = visibleItems.first()->endPosition() + spacing + 1; for (int i=1; i < visibleItems.count(); ++i) { FxListItem *item = visibleItems.at(i); item->setPosition(pos); @@ -840,8 +844,8 @@ void QDeclarativeListViewPrivate::createHighlight() item = new QDeclarativeItem; } if (item) { - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); highlight = new FxListItem(item, q); if (currentItem && autoHighlight) { if (orient == QDeclarativeListView::Vertical) { @@ -921,8 +925,8 @@ void QDeclarativeListViewPrivate::createSection(FxListItem *listItem) delete nobj; } else { listItem->section->setZValue(1); - QDeclarative_setParent_noEvent(listItem->section, q->viewport()); - listItem->section->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(listItem->section, q->contentItem()); + listItem->section->setParentItem(q->contentItem()); } } else { delete context; @@ -951,14 +955,26 @@ void QDeclarativeListViewPrivate::updateSections() QString prevSection; if (visibleIndex > 0) prevSection = sectionAt(visibleIndex-1); + QDeclarativeListViewAttached *prevAtt = 0; + int idx = -1; for (int i = 0; i < visibleItems.count(); ++i) { if (visibleItems.at(i)->index != -1) { QDeclarativeListViewAttached *attached = visibleItems.at(i)->attached; attached->setPrevSection(prevSection); + if (prevAtt) + prevAtt->setNextSection(attached->section()); createSection(visibleItems.at(i)); prevSection = attached->section(); + prevAtt = attached; + idx = visibleItems.at(i)->index; } } + if (prevAtt) { + if (idx > 0 && idx < model->count()-1) + prevAtt->setNextSection(sectionAt(idx+1)); + else + prevAtt->setNextSection(QString()); + } } } @@ -1027,7 +1043,7 @@ void QDeclarativeListViewPrivate::updateAverage() qreal sum = 0.0; for (int i = 0; i < visibleItems.count(); ++i) sum += visibleItems.at(i)->size(); - averageSize = sum / visibleItems.count(); + averageSize = qRound(sum / visibleItems.count()); } void QDeclarativeListViewPrivate::updateFooter() @@ -1046,8 +1062,8 @@ void QDeclarativeListViewPrivate::updateFooter() delete context; } if (item) { - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); item->setZValue(1); QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item)); itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); @@ -1086,8 +1102,8 @@ void QDeclarativeListViewPrivate::updateHeader() delete context; } if (item) { - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); item->setZValue(1); QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item)); itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); @@ -1418,7 +1434,7 @@ QDeclarativeListView::~QDeclarativeListView() */ /*! - \qmlattachedproperty string ListView::prevSection + \qmlattachedproperty string ListView::previousSection This attached property holds the section of the previous element. It is attached to each instance of the delegate. @@ -1427,6 +1443,15 @@ QDeclarativeListView::~QDeclarativeListView() */ /*! + \qmlattachedproperty string ListView::nextSection + This attached property holds the section of the next element. + + It is attached to each instance of the delegate. + + The section is evaluated using the \l {ListView::section.property}{section} properties. +*/ + +/*! \qmlattachedproperty string ListView::section This attached property holds the section of this element. @@ -1547,9 +1572,12 @@ void QDeclarativeListView::setModel(const QVariant &model) that is not needed for the normal display of the delegate in a \l Loader which can load additional elements when needed. - Tthe ListView will lay out the items based on the size of the root item + The ListView will lay out the items based on the size of the root item in the delegate. + It is recommended that the delagate's size be a whole number to avoid sub-pixel + alignment of items. + \note Delegates are instantiated as needed and may be destroyed at any time. State should \e never be stored in a delegate. */ @@ -1960,9 +1988,9 @@ void QDeclarativeListView::setCacheBuffer(int b) \c section.delegate holds the delegate component for each section. - Each item in the list has attached properties named \c ListView.section and - \c ListView.prevSection. These may be used to place a section header for - related items. + Each item in the list has attached properties named \c ListView.section, + \c ListView.previousSection and \c ListView.nextSection. These may be + used to place a section header for related items. For example, here is a ListView that displays a list of animals, separated into sections. Each item in the ListView is placed in a different section @@ -2182,6 +2210,22 @@ void QDeclarativeListView::setHeader(QDeclarativeComponent *header) } } +void QDeclarativeListView::setContentX(qreal pos) +{ + Q_D(QDeclarativeListView); + // Positioning the view manually should override any current movement state + d->moveReason = QDeclarativeListViewPrivate::Other; + QDeclarativeFlickable::setContentX(pos); +} + +void QDeclarativeListView::setContentY(qreal pos) +{ + Q_D(QDeclarativeListView); + // Positioning the view manually should override any current movement state + d->moveReason = QDeclarativeListViewPrivate::Other; + QDeclarativeFlickable::setContentY(pos); +} + bool QDeclarativeListView::event(QEvent *event) { Q_D(QDeclarativeListView); @@ -2386,6 +2430,8 @@ void QDeclarativeListView::keyPressEvent(QKeyEvent *event) Increments the current index. The current index will wrap if keyNavigationWraps is true and it is currently at the end. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativeListView::incrementCurrentIndex() { @@ -2403,6 +2449,8 @@ void QDeclarativeListView::incrementCurrentIndex() Decrements the current index. The current index will wrap if keyNavigationWraps is true and it is currently at the beginning. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativeListView::decrementCurrentIndex() { @@ -2439,6 +2487,14 @@ void QDeclarativeListView::decrementCurrentIndex() of the list does not cause all other items to be repositioned, and because the actual start of the view can vary based on the size of the delegates. The correct way to bring an item into view is with \c positionViewAtIndex. + + \bold Note: methods should only be called after the Component has completed. To position + the view at startup, this method should be called by Component.onCompleted. For + example, to position the view at the end: + + \code + Component.onCompleted: positionViewAtIndex(count - 1, ListView.Beginning) + \endcode */ void QDeclarativeListView::positionViewAtIndex(int index, int mode) { @@ -2448,6 +2504,8 @@ void QDeclarativeListView::positionViewAtIndex(int index, int mode) if (mode < Beginning || mode > Contain) return; + if (d->layoutScheduled) + d->layout(); qreal pos = d->position(); FxListItem *item = d->visibleItem(index); if (!item) { @@ -2491,6 +2549,8 @@ void QDeclarativeListView::positionViewAtIndex(int index, int mode) pos = qMin(pos, maxExtent); qreal minExtent = d->orient == QDeclarativeListView::Vertical ? -minYExtent() : -minXExtent(); pos = qMax(pos, minExtent); + d->moveReason = QDeclarativeListViewPrivate::Other; + cancelFlick(); d->setPosition(pos); } d->fixupPosition(); @@ -2505,6 +2565,8 @@ void QDeclarativeListView::positionViewAtIndex(int index, int mode) If the item is outside the visible area, -1 is returned, regardless of whether an item will exist at that point when scrolled into view. + + \bold Note: methods should only be called after the Component has completed. */ int QDeclarativeListView::indexAt(int x, int y) const { @@ -2529,6 +2591,11 @@ void QDeclarativeListView::componentComplete() d->updateCurrent(0); else d->updateCurrent(d->currentIndex); + if (d->highlight) { + d->highlight->setPosition(d->currentItem->position()); + d->updateTrackedItem(); + } + d->moveReason = QDeclarativeListViewPrivate::Other; d->fixupPosition(); } } @@ -2961,7 +3028,7 @@ void QDeclarativeListView::createdItem(int index, QDeclarativeItem *item) { Q_D(QDeclarativeListView); if (d->requestedIndex != index) { - item->setParentItem(viewport()); + item->setParentItem(contentItem()); d->unrequestedItems.insert(item, index); if (d->orient == QDeclarativeListView::Vertical) item->setY(d->positionAt(index)); diff --git a/src/declarative/graphicsitems/qdeclarativelistview_p.h b/src/declarative/graphicsitems/qdeclarativelistview_p.h index d6e8023..f55db9b 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview_p.h +++ b/src/declarative/graphicsitems/qdeclarativelistview_p.h @@ -198,6 +198,9 @@ public: QDeclarativeComponent *header() const; void setHeader(QDeclarativeComponent *); + virtual void setContentX(qreal pos); + virtual void setContentY(qreal pos); + static QDeclarativeListViewAttached *qmlAttachedProperties(QObject *); enum PositionMode { Beginning, Center, End, Visible, Contain }; @@ -276,7 +279,7 @@ public: } } - Q_PROPERTY(QString prevSection READ prevSection NOTIFY prevSectionChanged) + Q_PROPERTY(QString previousSection READ prevSection NOTIFY prevSectionChanged) QString prevSection() const { return m_prevSection; } void setPrevSection(const QString §) { if (m_prevSection != sect) { @@ -285,6 +288,15 @@ public: } } + Q_PROPERTY(QString nextSection READ nextSection NOTIFY nextSectionChanged) + QString nextSection() const { return m_nextSection; } + void setNextSection(const QString §) { + if (m_nextSection != sect) { + m_nextSection = sect; + emit nextSectionChanged(); + } + } + Q_PROPERTY(QString section READ section NOTIFY sectionChanged) QString section() const { return m_section; } void setSection(const QString §) { @@ -310,6 +322,7 @@ Q_SIGNALS: void currentItemChanged(); void sectionChanged(); void prevSectionChanged(); + void nextSectionChanged(); void delayRemoveChanged(); void add(); void remove(); @@ -318,6 +331,7 @@ public: QDeclarativeListView *m_view; mutable QString m_section; QString m_prevSection; + QString m_nextSection; bool m_isCurrent : 1; bool m_delayRemove : 1; }; diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index 25b1119..c8c9e44 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -174,7 +174,7 @@ void QDeclarativeLoaderPrivate::initResize() QDeclarativeLoader::QDeclarativeLoader(QDeclarativeItem *parent) : QDeclarativeItem(*(new QDeclarativeLoaderPrivate), parent) { - Q_D(QDeclarativeItem); + Q_D(QDeclarativeLoader); d->flags |= QGraphicsItem::ItemIsFocusScope; } @@ -183,6 +183,14 @@ QDeclarativeLoader::QDeclarativeLoader(QDeclarativeItem *parent) */ QDeclarativeLoader::~QDeclarativeLoader() { + Q_D(QDeclarativeLoader); + if (d->item) { + if (QDeclarativeItem *qmlItem = qobject_cast<QDeclarativeItem*>(d->item)) { + QDeclarativeItemPrivate *p = + static_cast<QDeclarativeItemPrivate *>(QGraphicsItemPrivate::get(qmlItem)); + p->removeItemChangeListener(d, QDeclarativeItemPrivate::Geometry); + } + } } /*! diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index 0bed41b..caf251d 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -192,7 +192,7 @@ QDeclarativeMouseAreaPrivate::~QDeclarativeMouseAreaPrivate() MouseArea is an invisible item: it is never painted. - \sa MouseEvent + \sa MouseEvent, {declarative/touchinteraction/mousearea}{MouseArea example} */ /*! diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp index 13d1b61..3b9b8df 100644 --- a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp +++ b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp @@ -151,6 +151,7 @@ void QDeclarativePaintedItem::setContentsSize(const QSize &size) { Q_D(QDeclarativePaintedItem); if (d->contentsSize == size) return; + prepareGeometryChange(); d->contentsSize = size; clearCache(); update(); @@ -247,8 +248,7 @@ QRectF QDeclarativePaintedItem::boundingRect() const void QDeclarativePaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { Q_D(QDeclarativePaintedItem); - const QRect content(0,0,qCeil(d->contentsSize.width()*d->contentsScale), - qCeil(d->contentsSize.height()*d->contentsScale)); + const QRect content = boundingRect().toRect(); if (content.width() <= 0 || content.height() <= 0) return; diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index 0c2d249..0e980b3 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -552,6 +552,8 @@ void QDeclarativePathView::setCurrentIndex(int idx) \qmlmethod PathView::incrementCurrentIndex() Increments the current index. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativePathView::incrementCurrentIndex() { @@ -563,6 +565,8 @@ void QDeclarativePathView::incrementCurrentIndex() \qmlmethod PathView::decrementCurrentIndex() Decrements the current index. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativePathView::decrementCurrentIndex() { diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index b9231a1..179f13d 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -1027,13 +1027,13 @@ void QDeclarativeFlow::doPositioning(QSizeF *contentSize) continue; if (d->flow == LeftToRight) { - if (hoffset && hoffset + child.item->width() > width()) { + if (widthValid() && hoffset && hoffset + child.item->width() > width()) { hoffset = 0; voffset += linemax + spacing(); linemax = 0; } } else { - if (voffset && voffset + child.item->height() > height()) { + if (heightValid() && voffset && voffset + child.item->height() > height()) { voffset = 0; hoffset += linemax + spacing(); linemax = 0; diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp index 2756877..c49be46 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp +++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp @@ -446,6 +446,7 @@ void QDeclarativeRectangle::drawRect(QPainter &p) p.setRenderHint(QPainter::Antialiasing); if (d->pen && d->pen->isValid()) { QPen pn(QColor(d->pen->color()), d->pen->width()); + pn.setJoinStyle(Qt::MiterJoin); p.setPen(pn); } else { p.setPen(Qt::NoPen); diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index c2e0d67..0bd9a53 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -136,6 +136,8 @@ QSet<QUrl> QTextDocumentWithImageResources::errors; HTML img tags that load remote images, the text is reloaded. Text provides read-only text. For editable text, see \l TextEdit. + + \sa {declarative/text/fonts}{Fonts example} */ /*! @@ -225,12 +227,6 @@ QDeclarativeTextPrivate::~QDeclarativeTextPrivate() */ /*! - \qmlproperty bool Text::font.outline - - Sets whether the font has an outline style. -*/ - -/*! \qmlproperty bool Text::font.strikeout Sets whether the font has a strikeout style. @@ -441,6 +437,8 @@ void QDeclarativeText::setStyleColor(const QColor &color) \qml Text { font.pointSize: 18; text: "hello"; style: Text.Raised; styleColor: "gray" } \endqml + + \sa style */ QColor QDeclarativeText::styleColor() const { @@ -663,6 +661,71 @@ void QDeclarativeText::setElideMode(QDeclarativeText::TextElideMode mode) emit elideModeChanged(d->elideMode); } +QRectF QDeclarativeText::boundingRect() const +{ + Q_D(const QDeclarativeText); + + int w = width(); + int h = height(); + + int x = 0; + int y = 0; + + if (d->cache || d->style != Normal) { + switch (d->hAlign) { + case AlignLeft: + x = 0; + break; + case AlignRight: + x = w - d->imgCache.width(); + break; + case AlignHCenter: + x = (w - d->imgCache.width()) / 2; + break; + } + + switch (d->vAlign) { + case AlignTop: + y = 0; + break; + case AlignBottom: + y = h - d->imgCache.height(); + break; + case AlignVCenter: + y = (h - d->imgCache.height()) / 2; + break; + } + + return QRectF(x,y,d->imgCache.width(),d->imgCache.height()); + } else { + switch (d->hAlign) { + case AlignLeft: + x = 0; + break; + case AlignRight: + x = w - d->cachedLayoutSize.width(); + break; + case AlignHCenter: + x = (w - d->cachedLayoutSize.width()) / 2; + break; + } + + switch (d->vAlign) { + case AlignTop: + y = 0; + break; + case AlignBottom: + y = h - d->cachedLayoutSize.height(); + break; + case AlignVCenter: + y = (h - d->cachedLayoutSize.height()) / 2; + break; + } + + return QRectF(x,y,d->cachedLayoutSize.width(),d->cachedLayoutSize.height()); + } +} + void QDeclarativeText::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { @@ -713,6 +776,7 @@ void QDeclarativeTextPrivate::updateLayout() } } + void QDeclarativeTextPrivate::updateSize() { Q_Q(QDeclarativeText); @@ -730,7 +794,10 @@ void QDeclarativeTextPrivate::updateSize() //setup instance of QTextLayout for all cases other than richtext if (!richText) { size = setupTextLayout(&layout); - cachedLayoutSize = size; + if (cachedLayoutSize != size) { + q->prepareGeometryChange(); + cachedLayoutSize = size; + } dy -= size.height(); } else { singleline = false; // richtext can't elide or be optimized for single-line case @@ -744,7 +811,13 @@ void QDeclarativeTextPrivate::updateSize() else doc->setTextWidth(doc->idealWidth()); // ### Text does not align if width is not set (QTextDoc bug) dy -= (int)doc->size().height(); - cachedLayoutSize = doc->size().toSize(); + q->prepareGeometryChange(); + QSize dsize = doc->size().toSize(); + if (dsize != cachedLayoutSize) { + q->prepareGeometryChange(); + cachedLayoutSize = dsize; + } + size = QSize(int(doc->idealWidth()),dsize.height()); } int yoff = 0; @@ -757,8 +830,8 @@ void QDeclarativeTextPrivate::updateSize() q->setBaselineOffset(fm.ascent() + yoff); //### need to comfirm cost of always setting these for richText - q->setImplicitWidth(richText ? (int)doc->idealWidth() : size.width()); - q->setImplicitHeight(richText ? (int)doc->size().height() : size.height()); + q->setImplicitWidth(size.width()); + q->setImplicitHeight(size.height()); emit q->paintedSizeChanged(); } else { dirty = true; @@ -813,6 +886,8 @@ void QDeclarativeTextPrivate::drawOutline() ppm.drawPixmap(pos, imgCache); ppm.end(); + if (imgCache.size() != img.size()) + q_func()->prepareGeometryChange(); imgCache = img; } @@ -831,6 +906,8 @@ void QDeclarativeTextPrivate::drawOutline(int yOffset) ppm.drawPixmap(pos, imgCache); ppm.end(); + if (imgCache.size() != img.size()) + q_func()->prepareGeometryChange(); imgCache = img; } @@ -955,18 +1032,21 @@ void QDeclarativeTextPrivate::checkImgCache() return; bool empty = text.isEmpty(); + QPixmap newImgCache; if (empty) { - imgCache = QPixmap(); imgStyleCache = QPixmap(); } else if (richText) { - imgCache = richTextImage(false); + newImgCache = richTextImage(false); if (style != QDeclarativeText::Normal) imgStyleCache = richTextImage(true); //### should use styleColor } else { - imgCache = wrappedTextImage(false); + newImgCache = wrappedTextImage(false); if (style != QDeclarativeText::Normal) imgStyleCache = wrappedTextImage(true); //### should use styleColor } + if (imgCache.size() != newImgCache.size()) + q_func()->prepareGeometryChange(); + imgCache = newImgCache; if (!empty) switch (style) { case QDeclarativeText::Outline: @@ -1031,35 +1111,7 @@ void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid if (d->smooth) p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth); - int w = width(); - int h = height(); - - int x = 0; - int y = 0; - - switch (d->hAlign) { - case AlignLeft: - x = 0; - break; - case AlignRight: - x = w - d->imgCache.width(); - break; - case AlignHCenter: - x = (w - d->imgCache.width()) / 2; - break; - } - - switch (d->vAlign) { - case AlignTop: - y = 0; - break; - case AlignBottom: - y = h - d->imgCache.height(); - break; - case AlignVCenter: - y = (h - d->imgCache.height()) / 2; - break; - } + QRect br = boundingRect().toRect(); bool needClip = clip() && (d->imgCache.width() > width() || d->imgCache.height() > height()); @@ -1068,7 +1120,7 @@ void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid p->save(); p->setClipRect(boundingRect(), Qt::IntersectClip); } - p->drawPixmap(x, y, d->imgCache); + p->drawPixmap(br.x(), br.y(), d->imgCache); if (needClip) p->restore(); @@ -1077,20 +1129,8 @@ void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid p->setRenderHint(QPainter::SmoothPixmapTransform, oldSmooth); } } else { - int h = height(); - int y = 0; + qreal y = boundingRect().y(); - switch (d->vAlign) { - case AlignTop: - y = 0; - break; - case AlignBottom: - y = h - d->cachedLayoutSize.height(); - break; - case AlignVCenter: - y = (h - d->cachedLayoutSize.height()) / 2; - break; - } bool needClip = !clip() && (d->cachedLayoutSize.width() > width() || d->cachedLayoutSize.height() > height()); diff --git a/src/declarative/graphicsitems/qdeclarativetext_p.h b/src/declarative/graphicsitems/qdeclarativetext_p.h index db21140..cd97df3 100644 --- a/src/declarative/graphicsitems/qdeclarativetext_p.h +++ b/src/declarative/graphicsitems/qdeclarativetext_p.h @@ -143,6 +143,8 @@ public: qreal paintedWidth() const; qreal paintedHeight() const; + QRectF boundingRect() const; + Q_SIGNALS: void textChanged(const QString &text); void linkActivated(const QString &link); diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 3106daf..c6566ff 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -99,7 +99,7 @@ TextEdit { You can translate between cursor positions (characters from the start of the document) and pixel points using positionAt() and positionToRectangle(). - \sa Text, TextInput + \sa Text, TextInput, {declarative/text/textselection}{Text Selection example} */ /*! @@ -186,12 +186,6 @@ QString QDeclarativeTextEdit::text() const */ /*! - \qmlproperty bool TextEdit::font.outline - - Sets whether the font has an outline style. -*/ - -/*! \qmlproperty bool TextEdit::font.strikeout Sets whether the font has a strikeout style. @@ -1231,8 +1225,13 @@ void QDeclarativeTextEdit::updateImgCache(const QRectF &rf) r = QRect(0,0,INT_MAX,INT_MAX); } else { r = rf.toRect(); - if (r != QRect(0,0,INT_MAX,INT_MAX)) // Don't translate "everything" + if (r.height() > INT_MAX/2) { + // Take care of overflow when translating "everything" + r.setTop(r.y() + d->yoff); + r.setBottom(INT_MAX/2); + } else { r = r.translated(0,d->yoff); + } } dirtyCache(r); emit update(); @@ -1284,6 +1283,7 @@ void QDeclarativeTextEditPrivate::init() void QDeclarativeTextEdit::q_textChanged() { updateSize(); + updateMicroFocus(); emit textChanged(text()); } @@ -1325,8 +1325,17 @@ void QDeclarativeTextEdit::updateSelectionMarkers() d->lastSelectionEnd = d->control->textCursor().selectionEnd(); emit selectionEndChanged(); } + updateMicroFocus(); } +QRectF QDeclarativeTextEdit::boundingRect() const +{ + Q_D(const QDeclarativeTextEdit); + QRectF r = QDeclarativePaintedItem::boundingRect(); + return r.translated(0,d->yoff); +} + + //### we should perhaps be a bit smarter here -- depending on what has changed, we shouldn't // need to do all the calculations each time void QDeclarativeTextEdit::updateSize() @@ -1341,13 +1350,20 @@ void QDeclarativeTextEdit::updateSize() d->document->setTextWidth(width()); dy -= (int)d->document->size().height(); + int nyoff; if (heightValid()) { if (d->vAlign == AlignBottom) - d->yoff = dy; + nyoff = dy; else if (d->vAlign == AlignVCenter) - d->yoff = dy/2; + nyoff = dy/2; + else + nyoff = 0; } else { - d->yoff = 0; + nyoff = 0; + } + if (nyoff != d->yoff) { + prepareGeometryChange(); + d->yoff = nyoff; } setBaselineOffset(fm.ascent() + d->yoff + d->textMargin); diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h index d08f607..a6dd4a4 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h @@ -195,6 +195,8 @@ public: Q_INVOKABLE int positionAt(int x, int y) const; Q_INVOKABLE void moveCursorSelection(int pos); + QRectF boundingRect() const; + Q_SIGNALS: void textChanged(const QString &); void paintedSizeChanged(); diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index ec14c78..ed999a2 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -69,7 +69,7 @@ QT_BEGIN_NAMESPACE On Mac OS X, the Up/Down key bindings for Home/End are explicitly disabled. If you want such bindings (on any platform), you will need to construct them in QML. - \sa TextEdit, Text + \sa TextEdit, Text, {declarative/text/textselection}{Text Selection example} */ QDeclarativeTextInput::QDeclarativeTextInput(QDeclarativeItem* parent) : QDeclarativePaintedItem(*(new QDeclarativeTextInputPrivate), parent) @@ -152,12 +152,6 @@ void QDeclarativeTextInput::setText(const QString &s) */ /*! - \qmlproperty bool TextInput::font.outline - - Sets whether the font has an outline style. -*/ - -/*! \qmlproperty bool TextInput::font.strikeout Sets whether the font has a strikeout style. @@ -1398,18 +1392,11 @@ void QDeclarativeTextInputPrivate::init() q->connect(control, SIGNAL(selectionChanged()), q, SLOT(selectionChanged())); q->connect(control, SIGNAL(textChanged(const QString &)), - q, SIGNAL(displayTextChanged(const QString &))); - q->connect(control, SIGNAL(textChanged(const QString &)), q, SLOT(q_textChanged())); q->connect(control, SIGNAL(accepted()), q, SIGNAL(accepted())); q->connect(control, SIGNAL(updateNeeded(QRect)), q, SLOT(updateRect(QRect))); - q->connect(control, SIGNAL(cursorPositionChanged(int,int)), - q, SLOT(updateRect()));//TODO: Only update rect between pos's - q->connect(control, SIGNAL(selectionChanged()), - q, SLOT(updateRect()));//TODO: Only update rect in selection - //Note that above TODOs probably aren't that big a savings q->updateSize(); oldValidity = control->hasAcceptableInput(); lastSelectionStart = 0; @@ -1422,6 +1409,8 @@ void QDeclarativeTextInputPrivate::init() void QDeclarativeTextInput::cursorPosChanged() { Q_D(QDeclarativeTextInput); + updateRect();//TODO: Only update rect between pos's + updateMicroFocus(); emit cursorPositionChanged(); if(!d->control->hasSelectedText()){ @@ -1439,6 +1428,7 @@ void QDeclarativeTextInput::cursorPosChanged() void QDeclarativeTextInput::selectionChanged() { Q_D(QDeclarativeTextInput); + updateRect();//TODO: Only update rect in selection emit selectedTextChanged(); if(d->lastSelectionStart != d->control->selectionStart()){ @@ -1460,7 +1450,9 @@ void QDeclarativeTextInput::q_textChanged() Q_D(QDeclarativeTextInput); d->updateHorizontalScroll(); updateSize(); + updateMicroFocus(); emit textChanged(); + emit displayTextChanged(); if(hasAcceptableInput() != d->oldValidity){ d->oldValidity = hasAcceptableInput(); emit acceptableInputChanged(); diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h index 6934da4..52dd57d 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h @@ -208,7 +208,7 @@ Q_SIGNALS: void inputMaskChanged(const QString &inputMask); void echoModeChanged(EchoMode echoMode); void passwordCharacterChanged(); - void displayTextChanged(const QString &text); + void displayTextChanged(); void focusOnPressChanged(bool focusOnPress); void autoScrollChanged(bool autoScroll); void selectByMouseChanged(bool selectByMouse); diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 5092349..8071d7a 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -283,7 +283,7 @@ public: if (m_roles.count() == 1) m_roleNames.insert("modelData", m_roles.at(0)); if (m_roles.count()) - m_roleNames.insert("hasModelChildren", 0); + m_roleNames.insert("hasModelChildren", -1); } else if (m_listAccessor) { m_roleNames.insert("modelData", 0); if (m_listAccessor->type() == QDeclarativeListAccessor::Instance) { diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 80a1093..623e3df 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -815,6 +815,10 @@ bool QDeclarativeCompiler::buildObject(Object *obj, const BindingContext &ctxt) } } + QDeclarativeCustomParser *cp = 0; + if (isCustomParser) + cp = output->types.at(obj->type).type->customParser(); + // Build all explicit properties specified foreach(Property *prop, obj->properties) { @@ -825,7 +829,9 @@ bool QDeclarativeCompiler::buildObject(Object *obj, const BindingContext &ctxt) bool canDefer = false; if (isCustomParser) { - if (doesPropertyExist(prop, obj)) { + if (doesPropertyExist(prop, obj) && + (!(cp->flags() & QDeclarativeCustomParser::AcceptsAttachedProperties) || + !isAttachedPropertyName(prop->name))) { int ids = compileState.ids.count(); COMPILE_CHECK(buildProperty(prop, obj, objCtxt)); canDefer = ids == compileState.ids.count(); @@ -876,8 +882,7 @@ bool QDeclarativeCompiler::buildObject(Object *obj, const BindingContext &ctxt) defaultProperty->release(); // Compile custom parser parts - if (isCustomParser/* && !customProps.isEmpty()*/) { - QDeclarativeCustomParser *cp = output->types.at(obj->type).type->customParser(); + if (isCustomParser && !customProps.isEmpty()) { cp->clearErrors(); cp->compiler = this; cp->object = obj; @@ -1356,7 +1361,7 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl Returns true if (value) property \a prop exists on obj, false otherwise. */ bool QDeclarativeCompiler::doesPropertyExist(QDeclarativeParser::Property *prop, - QDeclarativeParser::Object *obj) + QDeclarativeParser::Object *obj) { if(isAttachedPropertyName(prop->name) || prop->name == "id") return true; @@ -2176,6 +2181,18 @@ int QDeclarativeCompiler::evaluateEnum(const QByteArray& script) const return -1; } +const QMetaObject *QDeclarativeCompiler::resolveType(const QByteArray& name) const +{ + QDeclarativeType *qmltype = 0; + if (!enginePrivate->importDatabase.resolveType(unit->imports, name, &qmltype, + 0, 0, 0, 0)) + return 0; + if (!qmltype) + return 0; + return qmltype->metaObject(); +} + + // Ensures that the dynamic meta specification on obj is valid bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj) { @@ -2199,6 +2216,10 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj) if (QString::fromUtf8(prop.name).at(0).isUpper()) COMPILE_EXCEPTION(&prop, tr("Property names cannot begin with an upper case letter")); + + if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(prop.name)) + COMPILE_EXCEPTION(&prop, tr("Illegal property name")); + propNames.insert(prop.name); } @@ -2208,6 +2229,8 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj) COMPILE_EXCEPTION(obj, tr("Duplicate signal name")); if (QString::fromUtf8(name).at(0).isUpper()) COMPILE_EXCEPTION(obj, tr("Signal names cannot begin with an upper case letter")); + if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(name)) + COMPILE_EXCEPTION(obj, tr("Illegal signal name")); methodNames.insert(name); } for (int ii = 0; ii < obj->dynamicSlots.count(); ++ii) { @@ -2216,6 +2239,8 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj) COMPILE_EXCEPTION(obj, tr("Duplicate method name")); if (QString::fromUtf8(name).at(0).isUpper()) COMPILE_EXCEPTION(obj, tr("Method names cannot begin with an upper case letter")); + if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(name)) + COMPILE_EXCEPTION(obj, tr("Illegal method name")); methodNames.insert(name); } diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h index 908c703..caad376 100644 --- a/src/declarative/qml/qdeclarativecompiler_p.h +++ b/src/declarative/qml/qdeclarativecompiler_p.h @@ -161,6 +161,7 @@ public: static bool isSignalPropertyName(const QByteArray &); int evaluateEnum(const QByteArray& script) const; // for QDeclarativeCustomParser::evaluateEnum + const QMetaObject *resolveType(const QByteArray& name) const; // for QDeclarativeCustomParser::resolveType private: static void reset(QDeclarativeCompiledData *); diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index b4919ff..9d3032c 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -572,7 +572,9 @@ QScriptValue QDeclarativeComponent::createObject(QObject* parent) { Q_D(QDeclarativeComponent); QDeclarativeContext* ctxt = creationContext(); - if(!ctxt) + if(!ctxt && d->engine) + ctxt = d->engine->rootContext(); + if (!ctxt) return QScriptValue(QScriptValue::NullValue); QObject* ret = create(ctxt); if (!ret) diff --git a/src/declarative/qml/qdeclarativecustomparser.cpp b/src/declarative/qml/qdeclarativecustomparser.cpp index 472a883..97a6a00 100644 --- a/src/declarative/qml/qdeclarativecustomparser.cpp +++ b/src/declarative/qml/qdeclarativecustomparser.cpp @@ -295,4 +295,14 @@ int QDeclarativeCustomParser::evaluateEnum(const QByteArray& script) const return compiler->evaluateEnum(script); } +/*! + Resolves \a name to a type, or 0 if it is not a type. This can be used + to type-check object nodes. +*/ +const QMetaObject *QDeclarativeCustomParser::resolveType(const QByteArray& name) const +{ + return compiler->resolveType(name); +} + + QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativecustomparser_p.h b/src/declarative/qml/qdeclarativecustomparser_p.h index 0e397c5..509e30a 100644 --- a/src/declarative/qml/qdeclarativecustomparser_p.h +++ b/src/declarative/qml/qdeclarativecustomparser_p.h @@ -113,10 +113,18 @@ private: class Q_DECLARATIVE_EXPORT QDeclarativeCustomParser { public: - QDeclarativeCustomParser() : compiler(0), object(0) {} + enum Flag { + NoFlag = 0x00000000, + AcceptsAttachedProperties = 0x00000001 + }; + Q_DECLARE_FLAGS(Flags, Flag); + + QDeclarativeCustomParser() : compiler(0), object(0), m_flags(NoFlag) {} + QDeclarativeCustomParser(Flags f) : compiler(0), object(0), m_flags(f) {} virtual ~QDeclarativeCustomParser() {} void clearErrors(); + Flags flags() const { return m_flags; } virtual QByteArray compile(const QList<QDeclarativeCustomParserProperty> &)=0; virtual void setCustomData(QObject *, const QByteArray &)=0; @@ -130,12 +138,16 @@ protected: int evaluateEnum(const QByteArray&) const; + const QMetaObject *resolveType(const QByteArray&) const; + private: QList<QDeclarativeError> exceptions; QDeclarativeCompiler *compiler; QDeclarativeParser::Object *object; + Flags m_flags; friend class QDeclarativeCompiler; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeCustomParser::Flags); #if 0 #define QML_REGISTER_CUSTOM_TYPE(URI, VERSION_MAJ, VERSION_MIN, NAME, TYPE, CUSTOMTYPE) \ diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 86053c4..8b15ae9 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1033,6 +1033,17 @@ QDeclarativeContextData *QDeclarativeEnginePrivate::getContext(QScriptContext *c return contextClass->contextFromValue(scopeNode); } +/*! + Returns the QUrl associated with the script \a ctxt for the case that there is + no QDeclarativeContext. +*/ +QUrl QDeclarativeEnginePrivate::getUrl(QScriptContext *ctxt) +{ + QScriptValue scopeNode = QScriptDeclarativeClass::scopeChainValue(ctxt, -3); + Q_ASSERT(scopeNode.isValid()); + Q_ASSERT(QScriptDeclarativeClass::scriptClass(scopeNode) == contextClass); + return contextClass->urlFromValue(scopeNode); +} QString QDeclarativeEnginePrivate::urlToLocalFileOrQrc(const QUrl& url) { @@ -1075,16 +1086,19 @@ QScriptValue QDeclarativeEnginePrivate::createComponent(QScriptContext *ctxt, QS static_cast<QDeclarativeScriptEngine*>(engine)->p; QDeclarativeEngine* activeEngine = activeEnginePriv->q_func(); - QDeclarativeContextData* context = activeEnginePriv->getContext(ctxt); - Q_ASSERT(context); - if(ctxt->argumentCount() != 1) { return ctxt->throwError(QLatin1String("Qt.createComponent(): Invalid arguments")); - }else{ + } else { + QString arg = ctxt->argument(0).toString(); if (arg.isEmpty()) return engine->nullValue(); - QUrl url = QUrl(context->resolvedUrl(QUrl(arg))); + QUrl url; + QDeclarativeContextData* context = activeEnginePriv->getContext(ctxt); + if (context) + url = QUrl(context->resolvedUrl(QUrl(arg))); + else + url = activeEnginePriv->getUrl(ctxt).resolved(QUrl(arg)); QDeclarativeComponent *c = new QDeclarativeComponent(activeEngine, url, activeEngine); QDeclarativeComponentPrivate::get(c)->creationContext = context; QDeclarativeData::get(c, true)->setImplicitDestructible(); diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 3269e98..cfa9d73 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -315,6 +315,7 @@ public: static QDeclarativeEnginePrivate *get(QScriptEngine *e) { return static_cast<QDeclarativeScriptEngine*>(e)->p; } static QDeclarativeEngine *get(QDeclarativeEnginePrivate *p) { return p->q_func(); } QDeclarativeContextData *getContext(QScriptContext *); + QUrl getUrl(QScriptContext *); static QString urlToLocalFileOrQrc(const QUrl& url); diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp index 7ae0050..d765649 100644 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ b/src/declarative/qml/qdeclarativeenginedebug.cpp @@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE QList<QDeclarativeEngine *> QDeclarativeEngineDebugServer::m_engines; QDeclarativeEngineDebugServer::QDeclarativeEngineDebugServer(QObject *parent) : QDeclarativeDebugService(QLatin1String("QDeclarativeEngine"), parent), - m_watch(new QDeclarativeWatcher(this)) + m_watch(new QDeclarativeWatcher(this)) { QObject::connect(m_watch, SIGNAL(propertyChanged(int,int,QMetaProperty,QVariant)), this, SLOT(propertyChanged(int,int,QMetaProperty,QVariant))); @@ -99,6 +99,29 @@ QDataStream &operator>>(QDataStream &ds, return ds; } +static inline bool isSignalPropertyName(const QString &signalName) +{ + // see QmlCompiler::isSignalPropertyName + return signalName.length() >= 3 && signalName.startsWith(QLatin1String("on")) && + signalName.at(2).isLetter() && signalName.at(2).isUpper(); +} + +static bool hasValidSignal(QObject *object, const QString &propertyName) +{ + if (!isSignalPropertyName(propertyName)) + return false; + + QString signalName = propertyName.mid(2); + signalName[0] = signalName.at(0).toLower(); + + int sigIdx = QDeclarativePropertyPrivate::findSignalByName(object->metaObject(), signalName.toLatin1()).methodIndex(); + + if (sigIdx == -1) + return false; + + return true; +} + QDeclarativeEngineDebugServer::QDeclarativeObjectProperty QDeclarativeEngineDebugServer::propertyData(QObject *obj, int propIdx) { @@ -396,7 +419,6 @@ void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message) QByteArray reply; QDataStream rs(&reply, QIODevice::WriteOnly); rs << QByteArray("WATCH_EXPR_OBJECT_R") << queryId << ok; - sendMessage(reply); } else if (type == "NO_WATCH") { int queryId; @@ -430,7 +452,48 @@ void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message) rs << QByteArray("EVAL_EXPRESSION_R") << queryId << result; sendMessage(reply); + } else if (type == "SET_BINDING") { + int queryId; + int objectId; + QString propertyName; + QVariant expr; + bool isLiteralValue; + ds >> queryId >> objectId >> propertyName >> expr >> isLiteralValue; + setBinding(objectId, propertyName, expr, isLiteralValue); + } +} + +void QDeclarativeEngineDebugServer::setBinding(int objectId, + const QString &propertyName, + const QVariant &expression, + bool isLiteralValue) +{ + QObject *object = objectForId(objectId); + QDeclarativeContext *context = qmlContext(object); + + if (object && context) { + + if (isLiteralValue) { + QDeclarativeProperty literalProperty(object, propertyName, context); + literalProperty.write(expression); + } else { + if (hasValidSignal(object, propertyName)) { + QDeclarativeProperty property(object, propertyName); + QDeclarativeExpression *declarativeExpression = new QDeclarativeExpression(context, object, expression.toString()); + QDeclarativePropertyPrivate::setSignalExpression(property, declarativeExpression); + } else { + QDeclarativeBinding *binding = new QDeclarativeBinding(expression.toString(), object, context); + QDeclarativeProperty property(object, propertyName); + binding->setTarget(property); + binding->setNotifyOnValueChanged(true); + QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding); + if (oldBinding) + oldBinding->destroy(); + binding->update(); + } + } } + } void QDeclarativeEngineDebugServer::propertyChanged(int id, int objectId, const QMetaProperty &property, const QVariant &value) diff --git a/src/declarative/qml/qdeclarativeenginedebug_p.h b/src/declarative/qml/qdeclarativeenginedebug_p.h index 9491411..b3c23bd 100644 --- a/src/declarative/qml/qdeclarativeenginedebug_p.h +++ b/src/declarative/qml/qdeclarativeenginedebug_p.h @@ -107,6 +107,7 @@ private: QDeclarativeObjectData objectData(QObject *); QDeclarativeObjectProperty propertyData(QObject *, int); QVariant valueContents(const QVariant &defaultValue) const; + void setBinding(int objectId, const QString &propertyName, const QVariant &expression, bool isLiteralValue); static QList<QDeclarativeEngine *> m_engines; QDeclarativeWatcher *m_watch; diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp index 39ea101..d43443d 100644 --- a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp @@ -41,6 +41,7 @@ #include "private/qdeclarativeglobalscriptclass_p.h" +#include <QtCore/qstringlist.h> #include <QtCore/qvector.h> #include <QtScript/qscriptstring.h> #include <QtScript/qscriptengine.h> @@ -57,6 +58,7 @@ QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass(QScriptEngine *engi : QScriptClass(engine) { QString eval = QLatin1String("eval"); + QString version = QLatin1String("version"); QScriptValue originalGlobalObject = engine->globalObject(); @@ -72,6 +74,9 @@ QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass(QScriptEngine *engi QString name = iter.name(); + if (name == version) + continue; + if (name != eval) { names.append(name); values.append(iter.value()); @@ -98,18 +103,7 @@ QDeclarativeGlobalScriptClass::queryProperty(const QScriptValue &object, Q_UNUSED(name); Q_UNUSED(flags); Q_UNUSED(id); - return HandlesReadAccess | HandlesWriteAccess; -} - -QScriptValue -QDeclarativeGlobalScriptClass::property(const QScriptValue &object, - const QScriptString &name, - uint id) -{ - Q_UNUSED(object); - Q_UNUSED(name); - Q_UNUSED(id); - return engine()->undefinedValue(); + return HandlesWriteAccess; } void QDeclarativeGlobalScriptClass::setProperty(QScriptValue &object, @@ -125,8 +119,9 @@ void QDeclarativeGlobalScriptClass::setProperty(QScriptValue &object, } /* This method is for the use of tst_qdeclarativeecmascript::callQtInvokables() only */ -void QDeclarativeGlobalScriptClass::explicitSetProperty(const QString &name, const QScriptValue &value) +void QDeclarativeGlobalScriptClass::explicitSetProperty(const QStringList &names, const QList<QScriptValue> &values) { + Q_ASSERT(names.count() == values.count()); QScriptValue globalObject = engine()->globalObject(); QScriptValue v = engine()->newObject(); @@ -137,7 +132,12 @@ void QDeclarativeGlobalScriptClass::explicitSetProperty(const QString &name, con v.setProperty(iter.scriptName(), iter.value()); } - v.setProperty(name, value); + for (int ii = 0; ii < names.count(); ++ii) { + const QString &name = names.at(ii); + const QScriptValue &value = values.at(ii); + v.setProperty(name, value); + } + v.setScriptClass(this); engine()->setGlobalObject(v); diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h index 414bf02..b42b7bd 100644 --- a/src/declarative/qml/qdeclarativeglobalscriptclass_p.h +++ b/src/declarative/qml/qdeclarativeglobalscriptclass_p.h @@ -67,13 +67,10 @@ public: const QScriptString &name, QueryFlags flags, uint *id); - virtual QScriptValue property(const QScriptValue &object, - const QScriptString &name, uint id); - virtual void setProperty(QScriptValue &object, const QScriptString &name, uint id, const QScriptValue &value); - void explicitSetProperty(const QString &, const QScriptValue &); + void explicitSetProperty(const QStringList &, const QList<QScriptValue> &); const QScriptValue &staticGlobalObject() const { return m_staticGlobalObject; } diff --git a/src/declarative/qml/qdeclarativeimageprovider.cpp b/src/declarative/qml/qdeclarativeimageprovider.cpp index 4be3472..f4a8588 100644 --- a/src/declarative/qml/qdeclarativeimageprovider.cpp +++ b/src/declarative/qml/qdeclarativeimageprovider.cpp @@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE \note the request() method may be called by multiple threads, so ensure the implementation of this method is reentrant. - \sa QDeclarativeEngine::addImageProvider() + \sa QDeclarativeEngine::addImageProvider(), {declarative/cppextensions/imageprovider}{ImageProvider example} */ /*! diff --git a/src/declarative/qml/qdeclarativelist.cpp b/src/declarative/qml/qdeclarativelist.cpp index 31ef4c2..7c89672 100644 --- a/src/declarative/qml/qdeclarativelist.cpp +++ b/src/declarative/qml/qdeclarativelist.cpp @@ -341,6 +341,8 @@ QML list properties are typesafe - in this case \c {Fruit} is a QObject type tha \note QDeclarativeListProperty can only be used for lists of QObject-derived object pointers. +\sa {Object and List Property Types} + */ /*! diff --git a/src/declarative/qml/qdeclarativenetworkaccessmanagerfactory.cpp b/src/declarative/qml/qdeclarativenetworkaccessmanagerfactory.cpp index 399831d..d22798d 100644 --- a/src/declarative/qml/qdeclarativenetworkaccessmanagerfactory.cpp +++ b/src/declarative/qml/qdeclarativenetworkaccessmanagerfactory.cpp @@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE Note: the create() method may be called by multiple threads, so ensure the implementation of this method is reentrant. - \sa QDeclarativeEngine::setNetworkAccessManagerFactory() + \sa QDeclarativeEngine::setNetworkAccessManagerFactory(), {declarative/cppextensions/networkaccessmanagerfactory}{NetworkAccessManagerFactory example} */ /*! diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index aca01b2..3af892d 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -797,6 +797,26 @@ QScriptDeclarativeClass::Value MetaCallArgument::toValue(QDeclarativeEngine *e) } } +int QDeclarativeObjectMethodScriptClass::enumType(const QMetaObject *meta, const QString &strname) +{ + QByteArray str = strname.toUtf8(); + QByteArray scope; + QByteArray name; + int scopeIdx = str.lastIndexOf("::"); + if (scopeIdx != -1) { + scope = str.left(scopeIdx); + name = str.mid(scopeIdx + 2); + } else { + name = str; + } + for (int i = meta->enumeratorCount() - 1; i >= 0; --i) { + QMetaEnum m = meta->enumerator(i); + if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope))) + return QVariant::Int; + } + return QVariant::Invalid; +} + QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass::call(Object *o, QScriptContext *ctxt) { MethodData *method = static_cast<MethodData *>(o); @@ -810,7 +830,9 @@ QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass:: // ### Cache for (int ii = 0; ii < argTypeNames.count(); ++ii) { argTypes[ii] = QMetaType::type(argTypeNames.at(ii)); - if (argTypes[ii] == QVariant::Invalid) + if (argTypes[ii] == QVariant::Invalid) + argTypes[ii] = enumType(method->object->metaObject(), argTypeNames.at(ii)); + if (argTypes[ii] == QVariant::Invalid) return Value(ctxt, ctxt->throwError(QString::fromLatin1("Unknown method parameter type: %1").arg(QLatin1String(argTypeNames.at(ii))))); } diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h index 4b27e53..75e384c 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h +++ b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h @@ -80,6 +80,8 @@ protected: virtual Value property(Object *, const Identifier &); private: + int enumType(const QMetaObject *, const QString &); + PersistentIdentifier m_connectId; PersistentIdentifier m_disconnectId; QScriptValue m_connect; diff --git a/src/declarative/qml/qdeclarativetypenamescriptclass.cpp b/src/declarative/qml/qdeclarativetypenamescriptclass.cpp index 2a3417a..764a8db 100644 --- a/src/declarative/qml/qdeclarativetypenamescriptclass.cpp +++ b/src/declarative/qml/qdeclarativetypenamescriptclass.cpp @@ -107,8 +107,7 @@ QDeclarativeTypeNameScriptClass::queryProperty(Object *obj, const Identifier &na return 0; } - } else { - Q_ASSERT(data->type); + } else if (data->type) { QString strName = toString(name); @@ -134,6 +133,7 @@ QDeclarativeTypeNameScriptClass::queryProperty(Object *obj, const Identifier &na if (!object) return 0; return ep->objectClass->queryProperty(object, name, flags, 0); } + } return 0; diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index f807866..add27f3 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -176,6 +176,8 @@ void QDeclarativeAbstractAnimation::setRunning(bool r) { Q_D(QDeclarativeAbstractAnimation); if (!d->componentComplete) { + if (d->running && r == d->running) //don't re-register + return; d->running = r; if (r == false) d->avoidPropertyValueSourceStart = true; diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp index 90e0ca3..047993e 100644 --- a/src/declarative/util/qdeclarativebehavior.cpp +++ b/src/declarative/util/qdeclarativebehavior.cpp @@ -94,7 +94,7 @@ public: Currently only a single Behavior may be specified for a property; this Behavior can be enabled and disabled via the \l{enabled} property. - \sa QtDeclarative + \sa {declarative/animation/behaviors}{Behavior example}, QtDeclarative */ diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp index 9ed21a6..deb835d 100644 --- a/src/declarative/util/qdeclarativelistmodel.cpp +++ b/src/declarative/util/qdeclarativelistmodel.cpp @@ -551,9 +551,13 @@ bool QDeclarativeListModelParser::compileProperty(const QDeclarativeCustomParser QDeclarativeCustomParserNode node = qvariant_cast<QDeclarativeCustomParserNode>(value); - if (node.name() != "ListElement") { - error(node, QDeclarativeListModel::tr("ListElement: cannot contain nested elements")); - return false; + if (node.name() != listElementTypeName) { + const QMetaObject *mo = resolveType(node.name()); + if (mo != &QDeclarativeListElement::staticMetaObject) { + error(node, QDeclarativeListModel::tr("ListElement: cannot contain nested elements")); + return false; + } + listElementTypeName = node.name(); // cache right name for next time } { @@ -650,6 +654,7 @@ QByteArray QDeclarativeListModelParser::compile(const QList<QDeclarativeCustomPa { QList<ListInstruction> instr; QByteArray data; + listElementTypeName = QByteArray(); // unknown for(int ii = 0; ii < customProps.count(); ++ii) { const QDeclarativeCustomParserProperty &prop = customProps.at(ii); diff --git a/src/declarative/util/qdeclarativelistmodel_p.h b/src/declarative/util/qdeclarativelistmodel_p.h index d09062e..6aff9c6 100644 --- a/src/declarative/util/qdeclarativelistmodel_p.h +++ b/src/declarative/util/qdeclarativelistmodel_p.h @@ -135,6 +135,8 @@ private: bool compileProperty(const QDeclarativeCustomParserProperty &prop, QList<ListInstruction> &instr, QByteArray &data); bool definesEmptyList(const QString &); + + QByteArray listElementTypeName; }; diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp index a4ddf46..0c2f23d 100644 --- a/src/declarative/util/qdeclarativepixmapcache.cpp +++ b/src/declarative/util/qdeclarativepixmapcache.cpp @@ -220,18 +220,20 @@ bool QDeclarativeImageRequestHandler::event(QEvent *event) if (reader->cancelled.count()) { for (int i = 0; i < reader->cancelled.count(); ++i) { QDeclarativePixmapReply *job = reader->cancelled.at(i); - // cancel any jobs already started QNetworkReply *reply = replies.key(job, 0); if (reply && reply->isRunning()) { + // cancel any jobs already started replies.remove(reply); reply->close(); - } - // remove from pending job list - for (int j = 0; j < reader->jobs.count(); ++j) { - if (reader->jobs.at(j) == job) { - reader->jobs.removeAt(j); - job->release(true); - break; + job->release(true); + } else { + // remove from pending job list + for (int j = 0; j < reader->jobs.count(); ++j) { + if (reader->jobs.at(j) == job) { + reader->jobs.removeAt(j); + job->release(true); + break; + } } } } @@ -306,27 +308,27 @@ void QDeclarativeImageRequestHandler::networkRequestDone() QNetworkReply *reply = static_cast<QNetworkReply *>(sender()); QDeclarativePixmapReply *job = replies.take(reply); - redirectCount++; - if (redirectCount < IMAGEREQUESTHANDLER_MAX_REDIRECT_RECURSION) { - QVariant redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); - if (redirect.isValid()) { - QUrl url = reply->url().resolved(redirect.toUrl()); - QNetworkRequest req(url); - req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); - - reply->deleteLater(); - reply = networkAccessManager()->get(req); - - QMetaObject::connect(reply, replyDownloadProgress, job, downloadProgress); - QMetaObject::connect(reply, replyFinished, this, thisNetworkRequestDone); - - replies.insert(reply, job); - return; + if (job) { + redirectCount++; + if (redirectCount < IMAGEREQUESTHANDLER_MAX_REDIRECT_RECURSION) { + QVariant redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); + if (redirect.isValid()) { + QUrl url = reply->url().resolved(redirect.toUrl()); + QNetworkRequest req(url); + req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); + + reply->deleteLater(); + reply = networkAccessManager()->get(req); + + QMetaObject::connect(reply, replyDownloadProgress, job, downloadProgress); + QMetaObject::connect(reply, replyFinished, this, thisNetworkRequestDone); + + replies.insert(reply, job); + return; + } } - } - redirectCount=0; + redirectCount=0; - if (job) { QImage image; QDeclarativeImageReaderEvent::ReadError error; QString errorString; @@ -510,6 +512,12 @@ bool QDeclarativePixmapReply::event(QEvent *event) else d->errorString = de->errorString; QByteArray key = d->url.toEncoded(QUrl::FormattingOption(0x100)); + if (d->forced_width > 0 || d->forced_height > 0) { + key += ':'; + key += QByteArray::number(d->forced_width); + key += 'x'; + key += QByteArray::number(d->forced_height); + } QString strKey = QString::fromLatin1(key.constData(), key.count()); QPixmapCache::insert(strKey, d->pixmap); // note: may fail (returns false) emit finished(); diff --git a/src/declarative/util/qdeclarativepropertychanges.cpp b/src/declarative/util/qdeclarativepropertychanges.cpp index 8e3ec82..12c6353 100644 --- a/src/declarative/util/qdeclarativepropertychanges.cpp +++ b/src/declarative/util/qdeclarativepropertychanges.cpp @@ -145,7 +145,7 @@ QT_BEGIN_NAMESPACE an Item's parent should be done using the associated change elements (ParentChange and AnchorChanges, respectively). - \sa {qmlstate}{States}, QtDeclarative + \sa {declarative/animation/states}{states example}, {qmlstate}{States}, QtDeclarative */ /*! diff --git a/src/declarative/util/qdeclarativepropertychanges_p.h b/src/declarative/util/qdeclarativepropertychanges_p.h index c2ed466..bb0f944 100644 --- a/src/declarative/util/qdeclarativepropertychanges_p.h +++ b/src/declarative/util/qdeclarativepropertychanges_p.h @@ -79,6 +79,9 @@ public: class QDeclarativePropertyChangesParser : public QDeclarativeCustomParser { public: + QDeclarativePropertyChangesParser() + : QDeclarativeCustomParser(AcceptsAttachedProperties) {} + void compileList(QList<QPair<QByteArray, QVariant> > &list, const QByteArray &pre, const QDeclarativeCustomParserProperty &prop); virtual QByteArray compile(const QList<QDeclarativeCustomParserProperty> &); diff --git a/src/declarative/util/qdeclarativetimer.cpp b/src/declarative/util/qdeclarativetimer.cpp index 9e18eb5..576995f 100644 --- a/src/declarative/util/qdeclarativetimer.cpp +++ b/src/declarative/util/qdeclarativetimer.cpp @@ -103,6 +103,8 @@ public: 1000ms has its \e repeat property changed 500ms after starting, the elapsed time will be reset to 0, and the Timer will be triggered 1000ms later. + + \sa {declarative/toys/clocks}{Clocks example} */ QDeclarativeTimer::QDeclarativeTimer(QObject *parent) diff --git a/src/declarative/util/qdeclarativetransition.cpp b/src/declarative/util/qdeclarativetransition.cpp index ab8b116..38ed97e 100644 --- a/src/declarative/util/qdeclarativetransition.cpp +++ b/src/declarative/util/qdeclarativetransition.cpp @@ -56,7 +56,7 @@ QT_BEGIN_NAMESPACE \since 4.7 \brief The Transition element defines animated transitions that occur on state changes. - \sa {qmlstates}{States}, {state-transitions}{Transitions}, {QtDeclarative} + \sa {declarative/animation/states}{states example}, {qmlstates}{States}, {state-transitions}{Transitions}, {QtDeclarative} */ /*! diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index bfd25be..0692aaa 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -588,6 +588,8 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla If multiple key roles are specified, the model only adds and reload items with a combined value of all key roles that is not already present in the model. + + \sa {declarative/rssnews}{RSS News demo} */ QDeclarativeXmlListModel::QDeclarativeXmlListModel(QObject *parent) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 2de3638..8a419b4 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -7312,10 +7312,13 @@ void QGraphicsItem::updateMicroFocus() { #if !defined(QT_NO_IM) && (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)) if (QWidget *fw = QApplication::focusWidget()) { - for (int i = 0 ; i < scene()->views().count() ; ++i) - if (scene()->views().at(i) == fw) - if (QInputContext *inputContext = fw->inputContext()) - inputContext->update(); + if (scene()) { + for (int i = 0 ; i < scene()->views().count() ; ++i) { + if (scene()->views().at(i) == fw) + if (QInputContext *inputContext = fw->inputContext()) + inputContext->update(); + } + } #ifndef QT_NO_ACCESSIBILITY // ##### is this correct QAccessible::updateAccessibility(fw, 0, QAccessible::StateChanged); diff --git a/src/imports/gestures/qdeclarativegesturearea.cpp b/src/imports/gestures/qdeclarativegesturearea.cpp index 22be2f1..e5647bd 100644 --- a/src/imports/gestures/qdeclarativegesturearea.cpp +++ b/src/imports/gestures/qdeclarativegesturearea.cpp @@ -130,7 +130,7 @@ public: GestureArea is an invisible item: it is never painted. - \sa Gesture, MouseArea + \sa Gesture, MouseArea, {declarative/touchinteraction/gestures}{Gestures example} */ /*! diff --git a/tests/auto/declarative/qdeclarativeanimations/data/runningTrueBug.qml b/tests/auto/declarative/qdeclarativeanimations/data/runningTrueBug.qml new file mode 100644 index 0000000..2c5207e --- /dev/null +++ b/tests/auto/declarative/qdeclarativeanimations/data/runningTrueBug.qml @@ -0,0 +1,30 @@ +import Qt 4.7 +Rectangle { + color: "skyblue" + width: 500 + height: 200 + Rectangle { + objectName: "cloud" + color: "white" + y: 50 + width: 100 + height: 100 + + SequentialAnimation on x { + loops: Animation.Infinite + running: true + NumberAnimation { + id: firstAnimation + from: 0 + to: 500 + duration: 5000 + } + NumberAnimation { + id: secondAnimation + from: -100 + to: 0 + duration: 1000 + } + } + } +} diff --git a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp index 5cf4c23..a965ef3 100644 --- a/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp +++ b/tests/auto/declarative/qdeclarativeanimations/tst_qdeclarativeanimations.cpp @@ -81,6 +81,7 @@ private slots: void dontStart(); void easingProperties(); void rotation(); + void runningTrueBug(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -733,6 +734,20 @@ void tst_qdeclarativeanimations::rotation() QTIMED_COMPARE(rr->rotation() + rr2->rotation() + rr3->rotation() + rr4->rotation(), qreal(370*4)); } +void tst_qdeclarativeanimations::runningTrueBug() +{ + //ensure we start correctly when "running: true" is explicitly set + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/runningTrueBug.qml")); + QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create()); + QVERIFY(rect); + + QDeclarativeRectangle *cloud = rect->findChild<QDeclarativeRectangle*>("cloud"); + QVERIFY(cloud); + QTest::qWait(1000); + QVERIFY(cloud->x() > qreal(0)); +} + QTEST_MAIN(tst_qdeclarativeanimations) #include "tst_qdeclarativeanimations.moc" diff --git a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp index e2d3ee4..dcd1a85 100644 --- a/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp +++ b/tests/auto/declarative/qdeclarativedebug/tst_qdeclarativedebug.cpp @@ -694,7 +694,7 @@ void tst_QDeclarativeDebug::queryExpressionResult() delete q_expr; q_expr = m_dbg->queryExpressionResult(objectId, expr, this); - QCOMPARE(q_expr->expression(), expr); + QCOMPARE(q_expr->expression().toString(), expr); waitForQuery(q_expr); QCOMPARE(q_expr->result(), result); diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml b/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml index bc2df98..aab39be 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/eval.qml @@ -16,7 +16,11 @@ QtObject { test1 = (eval("a") == 7); test2 = (eval("b") == 9); - test3 = (eval("c") == undefined); + try { + eval("c"); + } catch(e) { + test3 = true; + } test4 = (eval("console") == console); test5 = (eval("Qt") == Qt); } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/function.qml b/tests/auto/declarative/qdeclarativeecmascript/data/function.qml index b435f58..80d6ef4 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/function.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/function.qml @@ -14,6 +14,10 @@ QtObject { test1 = (func1(4) == 11); test2 = (func2("Hello World!") == Qt.atob("Hello World!")); - test3 = (func3() == undefined); + try { + func3(); + } catch(e) { + test3 = true; + } } } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.js b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.js new file mode 100644 index 0000000..092bc2b --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.js @@ -0,0 +1 @@ +; diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml new file mode 100644 index 0000000..56e7885 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11600.qml @@ -0,0 +1,8 @@ +import Qt 4.7 +import "qtbug_11600.js" as Test + +QtObject { + id: goo + + property bool test: undefined == goo.Test.foo +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11606.qml b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11606.qml new file mode 100644 index 0000000..6efb9c1 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_11606.qml @@ -0,0 +1,12 @@ +import Qt 4.7 + +QtObject { + property bool test: false + Component.onCompleted: { + try { + console.log(sorryNoSuchProperty); + } catch (e) { + test = true; + } + } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml index 4395ba3..2548005 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scope.3.qml @@ -1,10 +1,10 @@ import Qt 4.7 +import Qt.test 1.0 -Item { +MyQmlObject { id: root property int foo: 12 - property int console: 11 property bool test1: foo == 12 property bool test2: console != 11 diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml index e8f7b62..f601f49 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/scriptErrors.qml @@ -4,7 +4,7 @@ import "scriptErrors.js" as Script MyQmlObject { property int t: a.value property int w: Script.getValue(); - property int x: undefinedObject + property int x: undefined property int y: (a.value, undefinedObject) onBasicSignal: { console.log(a.value); } diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h index 7bb8a8e..849879e 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h +++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h @@ -86,6 +86,7 @@ class MyQmlObject : public QObject Q_PROPERTY(bool trueProperty READ trueProperty CONSTANT) Q_PROPERTY(bool falseProperty READ falseProperty CONSTANT) Q_PROPERTY(int value READ value WRITE setValue) + Q_PROPERTY(int console READ console CONSTANT) Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringChanged) Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectChanged) Q_PROPERTY(QDeclarativeListProperty<QObject> objectListProperty READ objectListProperty CONSTANT) @@ -142,6 +143,7 @@ public: QRegExp regExp() { return m_regExp; } void setRegExp(const QRegExp ®Exp) { m_regExp = regExp; } + int console() const { return 11; } signals: void basicSignal(); void argumentSignal(int a, QString b, qreal c); @@ -555,7 +557,9 @@ Q_DECLARE_METATYPE(QScriptValue); class MyInvokableObject : public QObject { Q_OBJECT + Q_ENUMS(TestEnum) public: + enum TestEnum { EnumValue1, EnumValue2 }; MyInvokableObject() { reset(); } int invoked() const { return m_invoked; } @@ -587,6 +591,8 @@ public: Q_INVOKABLE void method_overload(int a) { invoke(16); m_actuals << a; } Q_INVOKABLE void method_overload(int a, int b) { invoke(17); m_actuals << a << b; } + Q_INVOKABLE void method_with_enum(TestEnum e) { invoke(18); m_actuals << (int)e; } + private: void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;} int m_invoked; diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 16e7ec5..43900ae 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -155,6 +155,8 @@ private slots: void eval(); void function(); void qtbug_10696(); + void qtbug_11606(); + void qtbug_11600(); void include(); @@ -1002,10 +1004,10 @@ void tst_qdeclarativeecmascript::scriptErrors() QString url = component.url().toString(); QString warning1 = url.left(url.length() - 3) + "js:2: Error: Invalid write to global property \"a\""; - QString warning2 = url + ":5: TypeError: Result of expression 'a' [undefined] is not an object."; + QString warning2 = url + ":5: ReferenceError: Can't find variable: a"; QString warning3 = url.left(url.length() - 3) + "js:4: Error: Invalid write to global property \"a\""; - QString warning4 = url + ":10: TypeError: Result of expression 'a' [undefined] is not an object."; - QString warning5 = url + ":8: TypeError: Result of expression 'a' [undefined] is not an object."; + QString warning4 = url + ":10: ReferenceError: Can't find variable: a"; + QString warning5 = url + ":8: ReferenceError: Can't find variable: a"; QString warning6 = url + ":7: Unable to assign [undefined] to int x"; QString warning7 = url + ":12: Error: Cannot assign to read-only property \"trueProperty\""; QString warning8 = url + ":13: Error: Cannot assign to non-existent property \"fakeProperty\""; @@ -1322,7 +1324,12 @@ void tst_qdeclarativeecmascript::callQtInvokables() QDeclarativeEngine qmlengine; QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(&qmlengine); QScriptEngine *engine = &ep->scriptEngine; - ep->globalClass->explicitSetProperty("object", ep->objectClass->newQObject(&o)); + + QStringList names; QList<QScriptValue> values; + names << QLatin1String("object"); values << ep->objectClass->newQObject(&o); + names << QLatin1String("undefined"); values << engine->undefinedValue(); + + ep->globalClass->explicitSetProperty(names, values); // Non-existent methods o.reset(); @@ -1714,6 +1721,13 @@ void tst_qdeclarativeecmascript::callQtInvokables() QCOMPARE(o.actuals().count(), 2); QCOMPARE(o.actuals().at(0), QVariant(10)); QCOMPARE(o.actuals().at(1), QVariant(11)); + + o.reset(); + QCOMPARE(engine->evaluate("object.method_with_enum(9)").isUndefined(), true); + QCOMPARE(o.error(), false); + QCOMPARE(o.invoked(), 18); + QCOMPARE(o.actuals().count(), 1); + QCOMPARE(o.actuals().at(0), QVariant(9)); } // QTBUG-5675 @@ -2498,6 +2512,25 @@ void tst_qdeclarativeecmascript::qtbug_10696() delete o; } +void tst_qdeclarativeecmascript::qtbug_11606() +{ + QDeclarativeComponent component(&engine, TEST_FILE("qtbug_11606.qml")); + QObject *o = component.create(); + QVERIFY(o != 0); + QCOMPARE(o->property("test").toBool(), true); + delete o; +} + +void tst_qdeclarativeecmascript::qtbug_11600() +{ + QDeclarativeComponent component(&engine, TEST_FILE("qtbug_11600.qml")); + QObject *o = component.create(); + QVERIFY(o != 0); + QCOMPARE(o->property("test").toBool(), true); + delete o; +} + + QTEST_MAIN(tst_qdeclarativeecmascript) #include "tst_qdeclarativeecmascript.moc" diff --git a/tests/auto/declarative/qdeclarativeflickable/data/flickable04.qml b/tests/auto/declarative/qdeclarativeflickable/data/flickable04.qml index aa156ed..a840a01 100644 --- a/tests/auto/declarative/qdeclarativeflickable/data/flickable04.qml +++ b/tests/auto/declarative/qdeclarativeflickable/data/flickable04.qml @@ -1,6 +1,12 @@ import Qt 4.7 Flickable { + property bool ok: false + function check() { + if (column.parent == contentItem) + ok = true; + } + width: 100; height: 100 contentWidth: column.width; contentHeight: column.height pressDelay: 200; boundsBehavior: Flickable.StopAtBounds; interactive: false diff --git a/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp b/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp index 2ba5574..678996b 100644 --- a/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp +++ b/tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp @@ -147,6 +147,10 @@ void tst_qdeclarativeflickable::properties() QCOMPARE(obj->pressDelay(), 200); QCOMPARE(obj->maximumFlickVelocity(), 2000.); + QVERIFY(obj->property("ok").toBool() == false); + QMetaObject::invokeMethod(obj, "check"); + QVERIFY(obj->property("ok").toBool() == true); + delete obj; } diff --git a/tests/auto/declarative/qdeclarativegridview/data/gridview-initCurrent.qml b/tests/auto/declarative/qdeclarativegridview/data/gridview-initCurrent.qml index 9331243..a5d651d 100644 --- a/tests/auto/declarative/qdeclarativegridview/data/gridview-initCurrent.qml +++ b/tests/auto/declarative/qdeclarativegridview/data/gridview-initCurrent.qml @@ -43,7 +43,7 @@ Rectangle { focus: true width: 240 height: 320 - currentIndex: 5 + currentIndex: 35 cellWidth: 80 cellHeight: 60 delegate: myDelegate diff --git a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp index 4e35bc0..a67c56f 100644 --- a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp +++ b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp @@ -178,17 +178,17 @@ void tst_QDeclarativeGridView::items() QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); QTRY_COMPARE(gridview->count(), model.count()); - QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item for (int i = 0; i < model.count(); ++i) { - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", i); + QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "textName", i); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(i)); - QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", i); + QDeclarativeText *number = findItem<QDeclarativeText>(contentItem, "textNumber", i); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(i)); } @@ -197,7 +197,7 @@ void tst_QDeclarativeGridView::items() TestModel model2; ctxt->setContextProperty("testModel", &model2); - int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + int itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); QTRY_VERIFY(itemCount == 0); delete canvas; @@ -226,14 +226,14 @@ void tst_QDeclarativeGridView::changed() QDeclarativeFlickable *gridview = findItem<QDeclarativeFlickable>(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.modifyItem(1, "Will", "9876"); - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 1); + QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "textName", 1); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(1)); - QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 1); + QDeclarativeText *number = findItem<QDeclarativeText>(contentItem, "textNumber", 1); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(1)); @@ -259,17 +259,17 @@ void tst_QDeclarativeGridView::inserted() QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.insertItem(1, "Will", "9876"); - QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 1); + QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "textName", 1); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(1)); - QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 1); + QDeclarativeText *number = findItem<QDeclarativeText>(contentItem, "textNumber", 1); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(1)); @@ -279,19 +279,19 @@ void tst_QDeclarativeGridView::inserted() // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); QTRY_COMPARE(item->x(), (i%3)*80.0); QTRY_COMPARE(item->y(), (i/3)*60.0); } model.insertItem(0, "Foo", "1111"); // zero index, and current item - QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item - name = findItem<QDeclarativeText>(viewport, "textName", 0); + name = findItem<QDeclarativeText>(contentItem, "textName", 0); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(0)); - number = findItem<QDeclarativeText>(viewport, "textNumber", 0); + number = findItem<QDeclarativeText>(contentItem, "textNumber", 0); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(0)); @@ -299,7 +299,7 @@ void tst_QDeclarativeGridView::inserted() // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); QTRY_VERIFY(item->x() == (i%3)*80); QTRY_VERIFY(item->y() == (i/3)*60); } @@ -335,15 +335,15 @@ void tst_QDeclarativeGridView::removed() QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.removeItem(1); - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 1); + QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "textName", 1); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(1)); - QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 1); + QDeclarativeText *number = findItem<QDeclarativeText>(contentItem, "textNumber", 1); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(1)); @@ -352,9 +352,9 @@ void tst_QDeclarativeGridView::removed() QTRY_COMPARE(removed, QString("Item1")); // Confirm items positioned correctly - int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + int itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->x() == (i%3)*80); @@ -364,17 +364,17 @@ void tst_QDeclarativeGridView::removed() // Remove first item (which is the current item); model.removeItem(0); - name = findItem<QDeclarativeText>(viewport, "textName", 0); + name = findItem<QDeclarativeText>(contentItem, "textName", 0); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(0)); - number = findItem<QDeclarativeText>(viewport, "textNumber", 0); + number = findItem<QDeclarativeText>(contentItem, "textNumber", 0); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(0)); // Confirm items positioned correctly - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->x() == (i%3)*80); @@ -385,9 +385,9 @@ void tst_QDeclarativeGridView::removed() model.removeItem(25); // Confirm items positioned correctly - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->x() == (i%3)*80); @@ -405,7 +405,7 @@ void tst_QDeclarativeGridView::removed() // Confirm items positioned correctly for (int i = 6; i < 18; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->x() == (i%3)*80); @@ -424,9 +424,9 @@ void tst_QDeclarativeGridView::removed() QTest::qWait(100); // Confirm items positioned correctly - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->x() == (i%3)*80); @@ -478,29 +478,29 @@ void tst_QDeclarativeGridView::moved() QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.moveItem(1, 8); - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 1); + QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "textName", 1); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(1)); - QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 1); + QDeclarativeText *number = findItem<QDeclarativeText>(contentItem, "textNumber", 1); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(1)); - name = findItem<QDeclarativeText>(viewport, "textName", 8); + name = findItem<QDeclarativeText>(contentItem, "textName", 8); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(8)); - number = findItem<QDeclarativeText>(viewport, "textNumber", 8); + number = findItem<QDeclarativeText>(contentItem, "textNumber", 8); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(8)); // Confirm items positioned correctly - int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + int itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->x() == (i%3)*80); @@ -513,17 +513,17 @@ void tst_QDeclarativeGridView::moved() model.moveItem(1, 25); // Confirm items positioned correctly and indexes correct - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count()-1; + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count()-1; for (int i = 6; i < model.count()-6 && i < itemCount+6; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), qreal((i%3)*80)); QTRY_COMPARE(item->y(), qreal((i/3)*60)); - name = findItem<QDeclarativeText>(viewport, "textName", i); + name = findItem<QDeclarativeText>(contentItem, "textName", i); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(i)); - number = findItem<QDeclarativeText>(viewport, "textNumber", i); + number = findItem<QDeclarativeText>(contentItem, "textNumber", i); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(i)); } @@ -533,15 +533,15 @@ void tst_QDeclarativeGridView::moved() // Confirm items positioned correctly and indexes correct for (int i = 6; i < model.count()-6 && i < itemCount+6; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->x() == (i%3)*80); QTRY_VERIFY(item->y() == (i/3)*60); - name = findItem<QDeclarativeText>(viewport, "textName", i); + name = findItem<QDeclarativeText>(contentItem, "textName", i); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(i)); - number = findItem<QDeclarativeText>(viewport, "textNumber", i); + number = findItem<QDeclarativeText>(contentItem, "textNumber", i); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(i)); } @@ -557,7 +557,7 @@ void tst_QDeclarativeGridView::moved() void tst_QDeclarativeGridView::currentIndex() { TestModel model; - for (int i = 0; i < 30; i++) + for (int i = 0; i < 60; i++) model.addItem("Item" + QString::number(i), QString::number(i)); QDeclarativeView *canvas = new QDeclarativeView(0); @@ -572,57 +572,58 @@ void tst_QDeclarativeGridView::currentIndex() qApp->processEvents(); QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); - QTRY_VERIFY(gridview != 0); + QVERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QVERIFY(contentItem != 0); // current item should be third item - QTRY_COMPARE(gridview->currentIndex(), 5); - QTRY_COMPARE(gridview->currentItem(), findItem<QDeclarativeItem>(viewport, "wrapper", 5)); - QTRY_COMPARE(gridview->currentItem()->y(), gridview->highlightItem()->y()); + QCOMPARE(gridview->currentIndex(), 35); + QCOMPARE(gridview->currentItem(), findItem<QDeclarativeItem>(contentItem, "wrapper", 35)); + QCOMPARE(gridview->currentItem()->y(), gridview->highlightItem()->y()); + QCOMPARE(gridview->contentY(), 399.0); gridview->moveCurrentIndexRight(); - QTRY_COMPARE(gridview->currentIndex(), 6); + QCOMPARE(gridview->currentIndex(), 36); gridview->moveCurrentIndexDown(); - QTRY_COMPARE(gridview->currentIndex(), 9); + QCOMPARE(gridview->currentIndex(), 39); gridview->moveCurrentIndexUp(); - QTRY_COMPARE(gridview->currentIndex(), 6); + QCOMPARE(gridview->currentIndex(), 36); gridview->moveCurrentIndexLeft(); - QTRY_COMPARE(gridview->currentIndex(), 5); + QCOMPARE(gridview->currentIndex(), 35); // no wrap gridview->setCurrentIndex(0); - QTRY_COMPARE(gridview->currentIndex(), 0); + QCOMPARE(gridview->currentIndex(), 0); gridview->moveCurrentIndexUp(); - QTRY_COMPARE(gridview->currentIndex(), 0); + QCOMPARE(gridview->currentIndex(), 0); gridview->moveCurrentIndexLeft(); - QTRY_COMPARE(gridview->currentIndex(), 0); + QCOMPARE(gridview->currentIndex(), 0); gridview->setCurrentIndex(model.count()-1); - QTRY_COMPARE(gridview->currentIndex(), model.count()-1); + QCOMPARE(gridview->currentIndex(), model.count()-1); gridview->moveCurrentIndexRight(); - QTRY_COMPARE(gridview->currentIndex(), model.count()-1); + QCOMPARE(gridview->currentIndex(), model.count()-1); gridview->moveCurrentIndexDown(); - QTRY_COMPARE(gridview->currentIndex(), model.count()-1); + QCOMPARE(gridview->currentIndex(), model.count()-1); // with wrap gridview->setWrapEnabled(true); gridview->setCurrentIndex(0); - QTRY_COMPARE(gridview->currentIndex(), 0); + QCOMPARE(gridview->currentIndex(), 0); gridview->moveCurrentIndexLeft(); - QTRY_COMPARE(gridview->currentIndex(), model.count()-1); + QCOMPARE(gridview->currentIndex(), model.count()-1); - QTRY_COMPARE(gridview->contentY(), 279.0); + QTRY_COMPARE(gridview->contentY(), 879.0); gridview->moveCurrentIndexRight(); - QTRY_COMPARE(gridview->currentIndex(), 0); + QCOMPARE(gridview->currentIndex(), 0); QTRY_COMPARE(gridview->contentY(), 0.0); @@ -638,30 +639,30 @@ void tst_QDeclarativeGridView::currentIndex() qApp->processEvents(); QTest::keyClick(canvas, Qt::Key_Down); - QTRY_COMPARE(gridview->currentIndex(), 3); + QCOMPARE(gridview->currentIndex(), 3); QTest::keyClick(canvas, Qt::Key_Up); - QTRY_COMPARE(gridview->currentIndex(), 0); + QCOMPARE(gridview->currentIndex(), 0); gridview->setFlow(QDeclarativeGridView::TopToBottom); QTest::keyClick(canvas, Qt::Key_Right); - QTRY_COMPARE(gridview->currentIndex(), 5); + QCOMPARE(gridview->currentIndex(), 5); QTest::keyClick(canvas, Qt::Key_Left); - QTRY_COMPARE(gridview->currentIndex(), 0); + QCOMPARE(gridview->currentIndex(), 0); QTest::keyClick(canvas, Qt::Key_Down); - QTRY_COMPARE(gridview->currentIndex(), 1); + QCOMPARE(gridview->currentIndex(), 1); QTest::keyClick(canvas, Qt::Key_Up); - QTRY_COMPARE(gridview->currentIndex(), 0); + QCOMPARE(gridview->currentIndex(), 0); // turn off auto highlight gridview->setHighlightFollowsCurrentItem(false); - QTRY_VERIFY(gridview->highlightFollowsCurrentItem() == false); - QTRY_VERIFY(gridview->highlightItem()); + QVERIFY(gridview->highlightFollowsCurrentItem() == false); + QVERIFY(gridview->highlightItem()); qreal hlPosX = gridview->highlightItem()->x(); qreal hlPosY = gridview->highlightItem()->y(); @@ -695,21 +696,21 @@ void tst_QDeclarativeGridView::changeFlow() QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); // Confirm items positioned correctly and indexes correct - int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + int itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), qreal((i%3)*80)); QTRY_COMPARE(item->y(), qreal((i/3)*60)); - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", i); + QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "textName", i); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(i)); - QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", i); + QDeclarativeText *number = findItem<QDeclarativeText>(contentItem, "textNumber", i); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(i)); } @@ -717,17 +718,17 @@ void tst_QDeclarativeGridView::changeFlow() ctxt->setContextProperty("testTopToBottom", QVariant(true)); // Confirm items positioned correctly and indexes correct - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), qreal((i/5)*80)); QTRY_COMPARE(item->y(), qreal((i%5)*60)); - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", i); + QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "textName", i); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(i)); - QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", i); + QDeclarativeText *number = findItem<QDeclarativeText>(contentItem, "textNumber", i); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(i)); } @@ -913,13 +914,13 @@ void tst_QDeclarativeGridView::positionViewAtIndex() QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); // Confirm items positioned correctly - int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + int itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount-1; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), (i%3)*80.); @@ -931,9 +932,9 @@ void tst_QDeclarativeGridView::positionViewAtIndex() QTRY_COMPARE(gridview->contentY(), 60.); // Confirm items positioned correctly - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 3; i < model.count() && i < itemCount-3-1; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), (i%3)*80.); @@ -945,9 +946,9 @@ void tst_QDeclarativeGridView::positionViewAtIndex() QTRY_COMPARE(gridview->contentY(), 420.); // Confirm items positioned correctly - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 22; i < model.count() && i < itemCount-22-1; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), (i%3)*80.); @@ -959,9 +960,9 @@ void tst_QDeclarativeGridView::positionViewAtIndex() QTRY_COMPARE(gridview->contentY(), 520.); // Confirm items positioned correctly - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 24; i < model.count() && i < itemCount-24-1; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), (i%3)*80.); @@ -973,9 +974,9 @@ void tst_QDeclarativeGridView::positionViewAtIndex() QTRY_COMPARE(gridview->contentY(), 0.); // Confirm items positioned correctly - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount-1; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), (i%3)*80.); @@ -1043,13 +1044,13 @@ void tst_QDeclarativeGridView::resetModel() QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); QTRY_COMPARE(gridview->count(), model.rowCount()); for (int i = 0; i < model.rowCount(); ++i) { - QDeclarativeText *display = findItem<QDeclarativeText>(viewport, "displayText", i); + QDeclarativeText *display = findItem<QDeclarativeText>(contentItem, "displayText", i); QTRY_VERIFY(display != 0); QTRY_COMPARE(display->text(), strings.at(i)); } @@ -1061,7 +1062,7 @@ void tst_QDeclarativeGridView::resetModel() QTRY_COMPARE(gridview->count(), model.rowCount()); for (int i = 0; i < model.rowCount(); ++i) { - QDeclarativeText *display = findItem<QDeclarativeText>(viewport, "displayText", i); + QDeclarativeText *display = findItem<QDeclarativeText>(contentItem, "displayText", i); QTRY_VERIFY(display != 0); QTRY_COMPARE(display->text(), strings.at(i)); } @@ -1088,22 +1089,22 @@ void tst_QDeclarativeGridView::enforceRange() QTRY_COMPARE(gridview->preferredHighlightEnd(), 100.0); QTRY_COMPARE(gridview->highlightRangeMode(), QDeclarativeGridView::StrictlyEnforceRange); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); // view should be positioned at the top of the range. - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", 0); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", 0); QTRY_VERIFY(item); QTRY_COMPARE(gridview->contentY(), -100.0); - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 0); + QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "textName", 0); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(0)); - QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 0); + QDeclarativeText *number = findItem<QDeclarativeText>(contentItem, "textNumber", 0); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(0)); - // Check currentIndex is updated when viewport moves + // Check currentIndex is updated when contentItem moves gridview->setContentY(0); QTRY_COMPARE(gridview->currentIndex(), 2); @@ -1145,18 +1146,18 @@ void tst_QDeclarativeGridView::manualHighlight() QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid"); QTRY_VERIFY(gridview != 0); - QDeclarativeItem *viewport = gridview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); QTRY_COMPARE(gridview->currentIndex(), 0); - QTRY_COMPARE(gridview->currentItem(), findItem<QDeclarativeItem>(viewport, "wrapper", 0)); + QTRY_COMPARE(gridview->currentItem(), findItem<QDeclarativeItem>(contentItem, "wrapper", 0)); QTRY_COMPARE(gridview->highlightItem()->y(), gridview->currentItem()->y()); QTRY_COMPARE(gridview->highlightItem()->x(), gridview->currentItem()->x()); gridview->setCurrentIndex(2); QTRY_COMPARE(gridview->currentIndex(), 2); - QTRY_COMPARE(gridview->currentItem(), findItem<QDeclarativeItem>(viewport, "wrapper", 2)); + QTRY_COMPARE(gridview->currentItem(), findItem<QDeclarativeItem>(contentItem, "wrapper", 2)); QTRY_COMPARE(gridview->highlightItem()->y(), gridview->currentItem()->y()); QTRY_COMPARE(gridview->highlightItem()->x(), gridview->currentItem()->x()); } diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.errors.txt new file mode 100644 index 0000000..c83e5ae --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.errors.txt @@ -0,0 +1 @@ +4:5:Illegal property name diff --git a/tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.qml b/tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.qml new file mode 100644 index 0000000..6077de4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/invalidProperty.qml @@ -0,0 +1,5 @@ +import Qt 4.7 + +QtObject { + property int parseInt +} diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 413843a..3ce356e 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -370,6 +370,7 @@ void tst_qdeclarativelanguage::errors_data() QTest::newRow("destroyedSignal") << "destroyedSignal.qml" << "destroyedSignal.errors.txt" << false; QTest::newRow("assignToNamespace") << "assignToNamespace.qml" << "assignToNamespace.errors.txt" << false; QTest::newRow("invalidOn") << "invalidOn.qml" << "invalidOn.errors.txt" << false; + QTest::newRow("invalidProperty") << "invalidProperty.qml" << "invalidProperty.errors.txt" << false; } diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp index 3d66733..f15ac8f 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp +++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp @@ -559,6 +559,18 @@ void tst_qdeclarativelistmodel::error_data() QTest::newRow("QML elements not allowed in ListElement") << "import Qt 4.7\nListModel { ListElement { a: Item { } } }" << "ListElement: cannot contain nested elements"; + + QTest::newRow("qualified ListElement supported") + << "import Qt 4.7 as Foo\nFoo.ListModel { Foo.ListElement { a: 123 } }" + << ""; + + QTest::newRow("qualified ListElement required") + << "import Qt 4.7 as Foo\nFoo.ListModel { ListElement { a: 123 } }" + << "ListElement is not a type"; + + QTest::newRow("unknown qualified ListElement not allowed") + << "import Qt 4.7\nListModel { Foo.ListElement { a: 123 } }" + << "Foo.ListElement - Foo is not a namespace"; } void tst_qdeclarativelistmodel::error() diff --git a/tests/auto/declarative/qdeclarativelistview/data/listview-initCurrent.qml b/tests/auto/declarative/qdeclarativelistview/data/listview-initCurrent.qml index 0599ddd..f3c2910 100644 --- a/tests/auto/declarative/qdeclarativelistview/data/listview-initCurrent.qml +++ b/tests/auto/declarative/qdeclarativelistview/data/listview-initCurrent.qml @@ -40,7 +40,7 @@ Rectangle { id: list objectName: "list" focus: true - currentIndex: 3 + currentIndex: 20 width: 240 height: 320 keyNavigationWraps: testWrap diff --git a/tests/auto/declarative/qdeclarativelistview/data/listview-sections.qml b/tests/auto/declarative/qdeclarativelistview/data/listview-sections.qml index a6f3ab8..9a5ea55 100644 --- a/tests/auto/declarative/qdeclarativelistview/data/listview-sections.qml +++ b/tests/auto/declarative/qdeclarativelistview/data/listview-sections.qml @@ -10,10 +10,10 @@ Rectangle { Item { id: wrapper objectName: "wrapper" - height: ListView.prevSection != ListView.section ? 40 : 20; + height: ListView.previousSection != ListView.section ? 40 : 20; width: 240 Rectangle { - y: wrapper.ListView.prevSection != wrapper.ListView.section ? 20 : 0 + y: wrapper.ListView.previousSection != wrapper.ListView.section ? 20 : 0 height: 20 width: parent.width color: wrapper.ListView.isCurrentItem ? "lightsteelblue" : "white" @@ -27,21 +27,26 @@ Rectangle { text: name } Text { - x: 120 + x: 100 id: textNumber objectName: "textNumber" text: number } Text { + objectName: "nextSection" + x: 150 + text: wrapper.ListView.nextSection + } + Text { x: 200 text: wrapper.y } } Rectangle { color: "#99bb99" - height: wrapper.ListView.prevSection != wrapper.ListView.section ? 20 : 0 + height: wrapper.ListView.previousSection != wrapper.ListView.section ? 20 : 0 width: parent.width - visible: wrapper.ListView.prevSection != wrapper.ListView.section ? true : false + visible: wrapper.ListView.previousSection != wrapper.ListView.section ? true : false Text { text: wrapper.ListView.section } } } diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index cd42b63..e13bd94 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -336,24 +336,24 @@ void tst_QDeclarativeListView::items() QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties"); QTRY_VERIFY(testObject->error() == false); QTRY_VERIFY(listview->highlightItem() != 0); QTRY_COMPARE(listview->count(), model.count()); - QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item // current item should be first item - QTRY_COMPARE(listview->currentItem(), findItem<QDeclarativeItem>(viewport, "wrapper", 0)); + QTRY_COMPARE(listview->currentItem(), findItem<QDeclarativeItem>(contentItem, "wrapper", 0)); for (int i = 0; i < model.count(); ++i) { - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", i); + QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "textName", i); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(i)); - QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", i); + QDeclarativeText *number = findItem<QDeclarativeText>(contentItem, "textNumber", i); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(i)); } @@ -382,7 +382,7 @@ void tst_QDeclarativeListView::items() T model2; ctxt->setContextProperty("testModel", &model2); - int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + int itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); QTRY_VERIFY(itemCount == 0); QTRY_COMPARE(listview->highlightResizeSpeed(), 1000.0); @@ -414,14 +414,14 @@ void tst_QDeclarativeListView::changed() QDeclarativeFlickable *listview = findItem<QDeclarativeFlickable>(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.modifyItem(1, "Will", "9876"); - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 1); + QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "textName", 1); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(1)); - QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 1); + QDeclarativeText *number = findItem<QDeclarativeText>(contentItem, "textNumber", 1); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(1)); @@ -450,34 +450,34 @@ void tst_QDeclarativeListView::inserted() QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.insertItem(1, "Will", "9876"); - QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 1); + QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "textName", 1); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(1)); - QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 1); + QDeclarativeText *number = findItem<QDeclarativeText>(contentItem, "textNumber", 1); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(1)); // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); QTRY_COMPARE(item->y(), i*20.0); } model.insertItem(0, "Foo", "1111"); // zero index, and current item - QTRY_COMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item - name = findItem<QDeclarativeText>(viewport, "textName", 0); + name = findItem<QDeclarativeText>(contentItem, "textName", 0); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(0)); - number = findItem<QDeclarativeText>(viewport, "textNumber", 0); + number = findItem<QDeclarativeText>(contentItem, "textNumber", 0); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(0)); @@ -485,7 +485,7 @@ void tst_QDeclarativeListView::inserted() // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); QTRY_COMPARE(item->y(), i*20.0); } @@ -501,13 +501,13 @@ void tst_QDeclarativeListView::inserted() // Confirm items positioned correctly for (int i = 5; i < 5+15; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.0 - 20.0); } -// QTRY_COMPARE(listview->viewportHeight(), model.count() * 20.0); +// QTRY_COMPARE(listview->contentItemHeight(), model.count() * 20.0); delete canvas; } @@ -534,22 +534,22 @@ void tst_QDeclarativeListView::removed(bool animated) QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.removeItem(1); - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 1); + QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "textName", 1); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(1)); - QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 1); + QDeclarativeText *number = findItem<QDeclarativeText>(contentItem, "textNumber", 1); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(1)); // Confirm items positioned correctly - int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + int itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->y() == i*20); @@ -560,17 +560,17 @@ void tst_QDeclarativeListView::removed(bool animated) QTest::qWait(300); - name = findItem<QDeclarativeText>(viewport, "textName", 0); + name = findItem<QDeclarativeText>(contentItem, "textName", 0); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(0)); - number = findItem<QDeclarativeText>(viewport, "textNumber", 0); + number = findItem<QDeclarativeText>(contentItem, "textNumber", 0); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(0)); // Confirm items positioned correctly - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(),i*20.0 + 20.0); @@ -581,9 +581,9 @@ void tst_QDeclarativeListView::removed(bool animated) qApp->processEvents(); // Confirm items positioned correctly - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(),i*20.0+20.0); @@ -598,7 +598,7 @@ void tst_QDeclarativeListView::removed(bool animated) // Confirm items positioned correctly for (int i = 2; i < 18; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(),40+i*20.0); @@ -617,9 +617,9 @@ void tst_QDeclarativeListView::removed(bool animated) QTest::qWait(300); // Confirm items positioned correctly - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(),40+i*20.0); @@ -665,8 +665,8 @@ void tst_QDeclarativeListView::clear() QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.clear(); @@ -699,29 +699,29 @@ void tst_QDeclarativeListView::moved() QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); model.moveItem(1, 4); - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 1); + QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "textName", 1); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(1)); - QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 1); + QDeclarativeText *number = findItem<QDeclarativeText>(contentItem, "textNumber", 1); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(1)); - name = findItem<QDeclarativeText>(viewport, "textName", 4); + name = findItem<QDeclarativeText>(contentItem, "textName", 4); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(4)); - number = findItem<QDeclarativeText>(viewport, "textNumber", 4); + number = findItem<QDeclarativeText>(contentItem, "textNumber", 4); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(4)); // Confirm items positioned correctly - int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + int itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->y() == i*20); @@ -734,14 +734,14 @@ void tst_QDeclarativeListView::moved() // Confirm items positioned correctly and indexes correct for (int i = 3; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.0 + 20); - name = findItem<QDeclarativeText>(viewport, "textName", i); + name = findItem<QDeclarativeText>(contentItem, "textName", i); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(i)); - number = findItem<QDeclarativeText>(viewport, "textNumber", i); + number = findItem<QDeclarativeText>(contentItem, "textNumber", i); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(i)); } @@ -751,14 +751,14 @@ void tst_QDeclarativeListView::moved() // Confirm items positioned correctly and indexes correct for (int i = 3; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.0 + 20); - name = findItem<QDeclarativeText>(viewport, "textName", i); + name = findItem<QDeclarativeText>(contentItem, "textName", i); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(i)); - number = findItem<QDeclarativeText>(viewport, "textNumber", i); + number = findItem<QDeclarativeText>(contentItem, "textNumber", i); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(i)); } @@ -787,22 +787,22 @@ void tst_QDeclarativeListView::enforceRange() QTRY_COMPARE(listview->preferredHighlightEnd(), 100.0); QTRY_COMPARE(listview->highlightRangeMode(), QDeclarativeListView::StrictlyEnforceRange); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); // view should be positioned at the top of the range. - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", 0); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", 0); QTRY_VERIFY(item); QTRY_COMPARE(listview->contentY(), -100.0); - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "textName", 0); + QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "textName", 0); QTRY_VERIFY(name != 0); QTRY_COMPARE(name->text(), model.name(0)); - QDeclarativeText *number = findItem<QDeclarativeText>(viewport, "textNumber", 0); + QDeclarativeText *number = findItem<QDeclarativeText>(contentItem, "textNumber", 0); QTRY_VERIFY(number != 0); QTRY_COMPARE(number->text(), model.number(0)); - // Check currentIndex is updated when viewport moves + // Check currentIndex is updated when contentItem moves listview->setContentY(20); QTRY_COMPARE(listview->currentIndex(), 6); @@ -838,13 +838,13 @@ void tst_QDeclarativeListView::spacing() QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); // Confirm items positioned correctly - int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + int itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->y() == i*20); @@ -854,9 +854,9 @@ void tst_QDeclarativeListView::spacing() QTRY_VERIFY(listview->spacing() == 10); // Confirm items positioned correctly - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->y() == i*30); @@ -865,9 +865,9 @@ void tst_QDeclarativeListView::spacing() listview->setSpacing(0); // Confirm items positioned correctly - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.0); @@ -893,44 +893,46 @@ void tst_QDeclarativeListView::sections() QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); // Confirm items positioned correctly - int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + int itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); QTRY_VERIFY(item); QTRY_COMPARE(item->y(), qreal(i*20 + ((i+4)/5) * 20)); + QDeclarativeText *next = findItem<QDeclarativeText>(item, "nextSection"); + QCOMPARE(next->text().toInt(), (i+1)/5); } // Remove section boundary model.removeItem(5); // New section header created - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", 5); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", 5); QTRY_VERIFY(item); QTRY_COMPARE(item->height(), 40.0); model.insertItem(3, "New Item", "0"); // Section header moved - item = findItem<QDeclarativeItem>(viewport, "wrapper", 5); + item = findItem<QDeclarativeItem>(contentItem, "wrapper", 5); QTRY_VERIFY(item); QTRY_COMPARE(item->height(), 20.0); - item = findItem<QDeclarativeItem>(viewport, "wrapper", 6); + item = findItem<QDeclarativeItem>(contentItem, "wrapper", 6); QTRY_VERIFY(item); QTRY_COMPARE(item->height(), 40.0); // insert item which will become a section header model.insertItem(6, "Replace header", "1"); - item = findItem<QDeclarativeItem>(viewport, "wrapper", 6); + item = findItem<QDeclarativeItem>(contentItem, "wrapper", 6); QTRY_VERIFY(item); QTRY_COMPARE(item->height(), 40.0); - item = findItem<QDeclarativeItem>(viewport, "wrapper", 7); + item = findItem<QDeclarativeItem>(contentItem, "wrapper", 7); QTRY_VERIFY(item); QTRY_COMPARE(item->height(), 20.0); @@ -942,7 +944,7 @@ void tst_QDeclarativeListView::sections() listview->setContentY(20); QTRY_COMPARE(listview->currentSection(), QString("0")); - item = findItem<QDeclarativeItem>(viewport, "wrapper", 1); + item = findItem<QDeclarativeItem>(contentItem, "wrapper", 1); QTRY_VERIFY(item); QTRY_COMPARE(item->height(), 20.0); @@ -970,37 +972,39 @@ void tst_QDeclarativeListView::currentIndex() QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); - // current item should be third item - QTRY_COMPARE(listview->currentIndex(), 3); - QTRY_COMPARE(listview->currentItem(), findItem<QDeclarativeItem>(viewport, "wrapper", 3)); - QTRY_COMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); + // current item should be 20th item at startup + // and current item should be in view + QCOMPARE(listview->currentIndex(), 20); + QCOMPARE(listview->contentY(), 99.0); + QCOMPARE(listview->currentItem(), findItem<QDeclarativeItem>(contentItem, "wrapper", 20)); + QCOMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); // no wrap listview->setCurrentIndex(0); - QTRY_COMPARE(listview->currentIndex(), 0); + QCOMPARE(listview->currentIndex(), 0); listview->incrementCurrentIndex(); - QTRY_COMPARE(listview->currentIndex(), 1); + QCOMPARE(listview->currentIndex(), 1); listview->decrementCurrentIndex(); - QTRY_COMPARE(listview->currentIndex(), 0); + QCOMPARE(listview->currentIndex(), 0); listview->decrementCurrentIndex(); - QTRY_COMPARE(listview->currentIndex(), 0); + QCOMPARE(listview->currentIndex(), 0); // with wrap ctxt->setContextProperty("testWrap", QVariant(true)); - QTRY_VERIFY(listview->isWrapEnabled()); + QVERIFY(listview->isWrapEnabled()); listview->decrementCurrentIndex(); - QTRY_COMPARE(listview->currentIndex(), model.count()-1); + QCOMPARE(listview->currentIndex(), model.count()-1); QTRY_COMPARE(listview->contentY(), 279.0); listview->incrementCurrentIndex(); - QTRY_COMPARE(listview->currentIndex(), 0); + QCOMPARE(listview->currentIndex(), 0); QTRY_COMPARE(listview->contentY(), 0.0); @@ -1016,16 +1020,16 @@ void tst_QDeclarativeListView::currentIndex() qApp->processEvents(); QTest::keyClick(canvas, Qt::Key_Down); - QTRY_COMPARE(listview->currentIndex(), 1); + QCOMPARE(listview->currentIndex(), 1); QTest::keyClick(canvas, Qt::Key_Up); - QTRY_COMPARE(listview->currentIndex(), 0); + QCOMPARE(listview->currentIndex(), 0); // turn off auto highlight listview->setHighlightFollowsCurrentItem(false); - QTRY_VERIFY(listview->highlightFollowsCurrentItem() == false); + QVERIFY(listview->highlightFollowsCurrentItem() == false); - QTRY_VERIFY(listview->highlightItem()); + QVERIFY(listview->highlightItem()); qreal hlPos = listview->highlightItem()->y(); listview->setCurrentIndex(4); @@ -1049,8 +1053,8 @@ void tst_QDeclarativeListView::itemList() QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "view"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); QDeclarativeVisualItemModel *model = canvas->rootObject()->findChild<QDeclarativeVisualItemModel*>("itemModel"); QTRY_VERIFY(model != 0); @@ -1058,21 +1062,21 @@ void tst_QDeclarativeListView::itemList() QTRY_VERIFY(model->count() == 3); QTRY_COMPARE(listview->currentIndex(), 0); - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "item1"); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "item1"); QTRY_VERIFY(item); QTRY_COMPARE(item->x(), 0.0); - QDeclarativeText *text = findItem<QDeclarativeText>(viewport, "text1"); + QDeclarativeText *text = findItem<QDeclarativeText>(contentItem, "text1"); QTRY_VERIFY(text); QTRY_COMPARE(text->text(), QLatin1String("index: 0")); listview->setCurrentIndex(2); - item = findItem<QDeclarativeItem>(viewport, "item3"); + item = findItem<QDeclarativeItem>(contentItem, "item3"); QTRY_VERIFY(item); QTRY_COMPARE(item->x(), 480.0); - text = findItem<QDeclarativeText>(viewport, "text3"); + text = findItem<QDeclarativeText>(contentItem, "text3"); QTRY_VERIFY(text); QTRY_COMPARE(text->text(), QLatin1String("index: 2")); @@ -1099,16 +1103,16 @@ void tst_QDeclarativeListView::cacheBuffer() QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); QTRY_VERIFY(listview->delegate() != 0); QTRY_VERIFY(listview->model() != 0); QTRY_VERIFY(listview->highlight() != 0); // Confirm items positioned correctly - int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + int itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->y() == i*20); @@ -1117,12 +1121,12 @@ void tst_QDeclarativeListView::cacheBuffer() testObject->setCacheBuffer(400); QTRY_VERIFY(listview->cacheBuffer() == 400); - int newItemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + int newItemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); QTRY_VERIFY(newItemCount > itemCount); // Confirm items positioned correctly for (int i = 0; i < model.count() && i < newItemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->y() == i*20); @@ -1151,13 +1155,13 @@ void tst_QDeclarativeListView::positionViewAtIndex() QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); // Confirm items positioned correctly - int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + int itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.); @@ -1168,9 +1172,9 @@ void tst_QDeclarativeListView::positionViewAtIndex() QTRY_COMPARE(listview->contentY(), 60.); // Confirm items positioned correctly - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 3; i < model.count() && i < itemCount-3-1; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.); @@ -1181,9 +1185,9 @@ void tst_QDeclarativeListView::positionViewAtIndex() QTRY_COMPARE(listview->contentY(), 440.); // Confirm items positioned correctly - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 22; i < model.count() && i < itemCount-22-1; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.); @@ -1194,9 +1198,9 @@ void tst_QDeclarativeListView::positionViewAtIndex() QTRY_COMPARE(listview->contentY(), 480.); // Confirm items positioned correctly - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 24; i < model.count() && i < itemCount-24-1; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.); @@ -1207,9 +1211,9 @@ void tst_QDeclarativeListView::positionViewAtIndex() QTRY_COMPARE(listview->contentY(), 0.); // Confirm items positioned correctly - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount-1; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->y(), i*20.); @@ -1276,13 +1280,13 @@ void tst_QDeclarativeListView::resetModel() QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); QTRY_COMPARE(listview->count(), model.rowCount()); for (int i = 0; i < model.rowCount(); ++i) { - QDeclarativeText *display = findItem<QDeclarativeText>(viewport, "displayText", i); + QDeclarativeText *display = findItem<QDeclarativeText>(contentItem, "displayText", i); QTRY_VERIFY(display != 0); QTRY_COMPARE(display->text(), strings.at(i)); } @@ -1294,7 +1298,7 @@ void tst_QDeclarativeListView::resetModel() QTRY_COMPARE(listview->count(), model.rowCount()); for (int i = 0; i < model.rowCount(); ++i) { - QDeclarativeText *display = findItem<QDeclarativeText>(viewport, "displayText", i); + QDeclarativeText *display = findItem<QDeclarativeText>(contentItem, "displayText", i); QTRY_VERIFY(display != 0); QTRY_COMPARE(display->text(), strings.at(i)); } @@ -1453,8 +1457,8 @@ void tst_QDeclarativeListView::QTBUG_9791() QDeclarativeListView *listview = qobject_cast<QDeclarativeListView*>(canvas->rootObject()); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); QTRY_VERIFY(listview->delegate() != 0); QTRY_VERIFY(listview->model() != 0); @@ -1462,11 +1466,11 @@ void tst_QDeclarativeListView::QTBUG_9791() qApp->processEvents(); // Confirm items positioned correctly - int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + int itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); QVERIFY(itemCount == 3); for (int i = 0; i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_COMPARE(item->x(), i*300.0); @@ -1493,17 +1497,17 @@ void tst_QDeclarativeListView::manualHighlight() QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); QTRY_COMPARE(listview->currentIndex(), 0); - QTRY_COMPARE(listview->currentItem(), findItem<QDeclarativeItem>(viewport, "wrapper", 0)); + QTRY_COMPARE(listview->currentItem(), findItem<QDeclarativeItem>(contentItem, "wrapper", 0)); QTRY_COMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); listview->setCurrentIndex(2); QTRY_COMPARE(listview->currentIndex(), 2); - QTRY_COMPARE(listview->currentItem(), findItem<QDeclarativeItem>(viewport, "wrapper", 2)); + QTRY_COMPARE(listview->currentItem(), findItem<QDeclarativeItem>(contentItem, "wrapper", 2)); QTRY_COMPARE(listview->highlightItem()->y(), listview->currentItem()->y()); } @@ -1527,13 +1531,13 @@ void tst_QDeclarativeListView::QTBUG_11105() QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list"); QTRY_VERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QTRY_VERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); // Confirm items positioned correctly - int itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + int itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); for (int i = 0; i < model.count() && i < itemCount; ++i) { - QDeclarativeItem *item = findItem<QDeclarativeItem>(viewport, "wrapper", i); + QDeclarativeItem *item = findItem<QDeclarativeItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; QTRY_VERIFY(item); QTRY_VERIFY(item->y() == i*20); @@ -1548,7 +1552,7 @@ void tst_QDeclarativeListView::QTBUG_11105() ctxt->setContextProperty("testModel", &model2); - itemCount = findItems<QDeclarativeItem>(viewport, "wrapper").count(); + itemCount = findItems<QDeclarativeItem>(contentItem, "wrapper").count(); QCOMPARE(itemCount, 5); delete canvas; diff --git a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp index d047a2a..b0b7a3b 100644 --- a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp +++ b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp @@ -47,6 +47,7 @@ #include <QtDeclarative/qdeclarativecomponent.h> #include <private/qdeclarativeloader_p.h> #include "testhttpserver.h" +#include "../../../shared/util.h" #define SERVER_PORT 14450 @@ -176,9 +177,7 @@ void tst_QDeclarativeLoader::clear() QCOMPARE(loader->progress(), 1.0); QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); - QTest::qWait(500); - - QVERIFY(loader->item() == 0); + QTRY_VERIFY(loader->item() == 0); QCOMPARE(loader->progress(), 0.0); QCOMPARE(loader->status(), QDeclarativeLoader::Null); QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 0); @@ -239,8 +238,8 @@ void tst_QDeclarativeLoader::urlToComponent() "}" ) , TEST_FILE("")); QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create()); - QTest::qWait(500); - QVERIFY(loader != 0); + QTest::qWait(200); + QTRY_VERIFY(loader != 0); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); diff --git a/tests/auto/declarative/qdeclarativepositioners/data/flow-testimplicitsize.qml b/tests/auto/declarative/qdeclarativepositioners/data/flow-testimplicitsize.qml new file mode 100644 index 0000000..6dd108e --- /dev/null +++ b/tests/auto/declarative/qdeclarativepositioners/data/flow-testimplicitsize.qml @@ -0,0 +1,16 @@ +import Qt 4.7 + +Rectangle { + width: 300; height: 200; + + property bool leftToRight: false + + Flow { + objectName: "flow" + flow: leftToRight ? Flow.LeftToRight : Flow.TopToBottom + spacing: 20 + anchors.horizontalCenter: parent.horizontalCenter + Rectangle { color: "red"; width: 100; height: 50 } + Rectangle { color: "blue"; width: 100; height: 50 } + } +}
\ No newline at end of file diff --git a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp index 62ec707..0663991 100644 --- a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp +++ b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp @@ -75,6 +75,7 @@ private slots: void test_repeater(); void test_flow(); void test_flow_resize(); + void test_flow_implicit_resize(); void test_conflictinganchors(); private: QDeclarativeView *createView(const QString &filename); @@ -655,6 +656,28 @@ void tst_QDeclarativePositioners::test_flow_resize() delete canvas; } +void tst_QDeclarativePositioners::test_flow_implicit_resize() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/flow-testimplicitsize.qml"); + QVERIFY(canvas->rootObject() != 0); + + QDeclarativeFlow *flow = canvas->rootObject()->findChild<QDeclarativeFlow*>("flow"); + QVERIFY(flow != 0); + + QCOMPARE(flow->width(), 100.0); + QCOMPARE(flow->height(), 120.0); + + canvas->rootObject()->setProperty("leftToRight", true); + QCOMPARE(flow->width(), 220.0); + QCOMPARE(flow->height(), 50.0); + + canvas->rootObject()->setProperty("leftToRight", false); + QCOMPARE(flow->width(), 100.0); + QCOMPARE(flow->height(), 120.0); + + delete canvas; +} + QString warningMessage; void interceptWarnings(QtMsgType type, const char *msg) diff --git a/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.js b/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.js index c165e29..30499e9 100644 --- a/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.js +++ b/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.js @@ -5,3 +5,7 @@ function loadComponent() { return component.status; } +function createComponent() { + var component = Qt.createComponent("createComponentData.qml"); + return component.createObject(null); +} diff --git a/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.qml b/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.qml index aae7a91..33203c7 100644 --- a/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.qml +++ b/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.qml @@ -3,8 +3,10 @@ import "createComponent_lib.js" as Test Item { property int status: Component.Null + property int readValue: 0 Component.onCompleted: { status = Test.loadComponent() + readValue = Test.createComponent().test; } } diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp index fb100a5..895ee6c 100644 --- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp +++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp @@ -365,14 +365,12 @@ void tst_qdeclarativeqt::createComponent() void tst_qdeclarativeqt::createComponent_pragmaLibrary() { // Currently, just loading createComponent_lib.qml causes crash on some platforms - /* QDeclarativeComponent component(&engine, TEST_FILE("createComponent_lib.qml")); QObject *object = component.create(); QVERIFY(object != 0); - - QEXPECT_FAIL("", "QTBUG-11507", Continue); QCOMPARE(object->property("status").toInt(), int(QDeclarativeComponent::Ready)); - */ + QCOMPARE(object->property("readValue").toInt(), int(1913)); + delete object; } void tst_qdeclarativeqt::createQmlObject() diff --git a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp index 2913ddd..639b2f3 100644 --- a/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp +++ b/tests/auto/declarative/qdeclarativestates/tst_qdeclarativestates.cpp @@ -263,7 +263,6 @@ void tst_qdeclarativestates::attachedPropertyChanges() MyAttached *att = qobject_cast<MyAttached*>(attObj); QVERIFY(att); - QEXPECT_FAIL("", "QTBUG-11283", Abort); QCOMPARE(att->foo(), 1); } diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments.qml b/tests/auto/declarative/qdeclarativetext/data/alignments.qml new file mode 100644 index 0000000..b1f701b --- /dev/null +++ b/tests/auto/declarative/qdeclarativetext/data/alignments.qml @@ -0,0 +1,41 @@ +import Qt 4.7 + +Rectangle { + id: top + width: 70; height: 70; + + property alias horizontalAlignment: t.horizontalAlignment + property alias verticalAlignment: t.verticalAlignment + property alias wrapMode: t.wrapMode + property alias running: timer.running + property string txt: "Test" + + Rectangle { + anchors.centerIn: parent + width: 40 + height: 40 + color: "green" + + Text { + id: t + + anchors.fill: parent + horizontalAlignment: TextEdit.AlignRight + verticalAlignment: TextEdit.AlignBottom + wrapMode: TextEdit.WordWrap + text: top.txt + } + Timer { + id: timer + + interval: 1 + running: true + repeat: true + onTriggered: { + top.txt = top.txt + "<br>more " + top.txt.length; + if (top.txt.length > 50) + running = false + } + } + } +} diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_cb.png b/tests/auto/declarative/qdeclarativetext/data/alignments_cb.png Binary files differnew file mode 100644 index 0000000..99de219 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetext/data/alignments_cb.png diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_cc.png b/tests/auto/declarative/qdeclarativetext/data/alignments_cc.png Binary files differnew file mode 100644 index 0000000..cb85251 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetext/data/alignments_cc.png diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_ct.png b/tests/auto/declarative/qdeclarativetext/data/alignments_ct.png Binary files differnew file mode 100644 index 0000000..ddca549 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetext/data/alignments_ct.png diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_lb.png b/tests/auto/declarative/qdeclarativetext/data/alignments_lb.png Binary files differnew file mode 100644 index 0000000..1b50a81 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetext/data/alignments_lb.png diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_lc.png b/tests/auto/declarative/qdeclarativetext/data/alignments_lc.png Binary files differnew file mode 100644 index 0000000..f041b86 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetext/data/alignments_lc.png diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_lt.png b/tests/auto/declarative/qdeclarativetext/data/alignments_lt.png Binary files differnew file mode 100644 index 0000000..c75e0d1 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetext/data/alignments_lt.png diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_rb.png b/tests/auto/declarative/qdeclarativetext/data/alignments_rb.png Binary files differnew file mode 100644 index 0000000..b06a5da --- /dev/null +++ b/tests/auto/declarative/qdeclarativetext/data/alignments_rb.png diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_rc.png b/tests/auto/declarative/qdeclarativetext/data/alignments_rc.png Binary files differnew file mode 100644 index 0000000..e468857 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetext/data/alignments_rc.png diff --git a/tests/auto/declarative/qdeclarativetext/data/alignments_rt.png b/tests/auto/declarative/qdeclarativetext/data/alignments_rt.png Binary files differnew file mode 100644 index 0000000..576715f --- /dev/null +++ b/tests/auto/declarative/qdeclarativetext/data/alignments_rt.png diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp index 01120b1..8a4f152 100644 --- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp +++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp @@ -47,6 +47,7 @@ #include <QFontMetrics> #include <QGraphicsSceneMouseEvent> #include <qmath.h> +#include <QDeclarativeView> #include "../../../shared/util.h" #include "testhttpserver.h" @@ -70,6 +71,9 @@ private slots: void elide(); void textFormat(); + void alignments_data(); + void alignments(); + void embeddedImages_data(); void embeddedImages(); @@ -108,6 +112,8 @@ private: QStringList colorStrings; QDeclarativeEngine engine; + + QDeclarativeView *createView(const QString &filename); }; tst_qdeclarativetext::tst_qdeclarativetext() @@ -163,6 +169,14 @@ tst_qdeclarativetext::tst_qdeclarativetext() // } +QDeclarativeView *tst_qdeclarativetext::createView(const QString &filename) +{ + QDeclarativeView *canvas = new QDeclarativeView(0); + + canvas->setSource(QUrl::fromLocalFile(filename)); + return canvas; +} + void tst_qdeclarativetext::text() { { @@ -383,6 +397,65 @@ void tst_qdeclarativetext::textFormat() } } + +void tst_qdeclarativetext::alignments_data() +{ + QTest::addColumn<int>("hAlign"); + QTest::addColumn<int>("vAlign"); + QTest::addColumn<QString>("expectfile"); + + QTest::newRow("LT") << int(Qt::AlignLeft) << int(Qt::AlignTop) << SRCDIR "/data/alignments_lt.png"; + QTest::newRow("RT") << int(Qt::AlignRight) << int(Qt::AlignTop) << SRCDIR "/data/alignments_rt.png"; + QTest::newRow("CT") << int(Qt::AlignHCenter) << int(Qt::AlignTop) << SRCDIR "/data/alignments_ct.png"; + + QTest::newRow("LB") << int(Qt::AlignLeft) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_lb.png"; + QTest::newRow("RB") << int(Qt::AlignRight) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_rb.png"; + QTest::newRow("CB") << int(Qt::AlignHCenter) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_cb.png"; + + QTest::newRow("LC") << int(Qt::AlignLeft) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_lc.png"; + QTest::newRow("RC") << int(Qt::AlignRight) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_rc.png"; + QTest::newRow("CC") << int(Qt::AlignHCenter) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_cc.png"; +} + + +void tst_qdeclarativetext::alignments() +{ + QFETCH(int, hAlign); + QFETCH(int, vAlign); + QFETCH(QString, expectfile); + +#ifdef Q_WS_X11 + // Font-specific, but not likely platform-specific, so only test on one platform + QFont fn; + fn.setRawName("-misc-fixed-medium-r-*-*-8-*-*-*-*-*-*-*"); + QApplication::setFont(fn); +#endif + + QDeclarativeView *canvas = createView(SRCDIR "/data/alignments.qml"); + + canvas->show(); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(canvas)); + + QObject *ob = canvas->rootObject(); + QVERIFY(ob != 0); + ob->setProperty("horizontalAlignment",hAlign); + ob->setProperty("verticalAlignment",vAlign); + QTRY_COMPARE(ob->property("running").toBool(),false); + QImage actual(canvas->width(), canvas->height(), QImage::Format_RGB32); + actual.fill(qRgb(255,255,255)); + QPainter p(&actual); + canvas->render(&p); + + QImage expect(expectfile); + +#ifdef Q_WS_X11 + // Font-specific, but not likely platform-specific, so only test on one platform + QCOMPARE(actual,expect); +#endif +} + //the alignment tests may be trivial o.oa void tst_qdeclarativetext::horizontalAlignment() { diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments.qml b/tests/auto/declarative/qdeclarativetextedit/data/alignments.qml new file mode 100644 index 0000000..b1f701b --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/alignments.qml @@ -0,0 +1,41 @@ +import Qt 4.7 + +Rectangle { + id: top + width: 70; height: 70; + + property alias horizontalAlignment: t.horizontalAlignment + property alias verticalAlignment: t.verticalAlignment + property alias wrapMode: t.wrapMode + property alias running: timer.running + property string txt: "Test" + + Rectangle { + anchors.centerIn: parent + width: 40 + height: 40 + color: "green" + + Text { + id: t + + anchors.fill: parent + horizontalAlignment: TextEdit.AlignRight + verticalAlignment: TextEdit.AlignBottom + wrapMode: TextEdit.WordWrap + text: top.txt + } + Timer { + id: timer + + interval: 1 + running: true + repeat: true + onTriggered: { + top.txt = top.txt + "<br>more " + top.txt.length; + if (top.txt.length > 50) + running = false + } + } + } +} diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_cb.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_cb.png Binary files differnew file mode 100644 index 0000000..99de219 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/alignments_cb.png diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_cc.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_cc.png Binary files differnew file mode 100644 index 0000000..cb85251 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/alignments_cc.png diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_ct.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_ct.png Binary files differnew file mode 100644 index 0000000..ddca549 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/alignments_ct.png diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lb.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lb.png Binary files differnew file mode 100644 index 0000000..1b50a81 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lb.png diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lc.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lc.png Binary files differnew file mode 100644 index 0000000..f041b86 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lc.png diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_lt.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lt.png Binary files differnew file mode 100644 index 0000000..c75e0d1 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/alignments_lt.png diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rb.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rb.png Binary files differnew file mode 100644 index 0000000..b06a5da --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rb.png diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rc.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rc.png Binary files differnew file mode 100644 index 0000000..e468857 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rc.png diff --git a/tests/auto/declarative/qdeclarativetextedit/data/alignments_rt.png b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rt.png Binary files differnew file mode 100644 index 0000000..576715f --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/alignments_rt.png diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index f7ba7a1..f1a367f 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -73,6 +73,8 @@ private slots: void width(); void wrap(); void textFormat(); + void alignments(); + void alignments_data(); // ### these tests may be trivial void hAlign(); @@ -297,6 +299,65 @@ void tst_qdeclarativetextedit::textFormat() } } +void tst_qdeclarativetextedit::alignments_data() +{ + QTest::addColumn<int>("hAlign"); + QTest::addColumn<int>("vAlign"); + QTest::addColumn<QString>("expectfile"); + + QTest::newRow("LT") << int(Qt::AlignLeft) << int(Qt::AlignTop) << SRCDIR "/data/alignments_lt.png"; + QTest::newRow("RT") << int(Qt::AlignRight) << int(Qt::AlignTop) << SRCDIR "/data/alignments_rt.png"; + QTest::newRow("CT") << int(Qt::AlignHCenter) << int(Qt::AlignTop) << SRCDIR "/data/alignments_ct.png"; + + QTest::newRow("LB") << int(Qt::AlignLeft) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_lb.png"; + QTest::newRow("RB") << int(Qt::AlignRight) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_rb.png"; + QTest::newRow("CB") << int(Qt::AlignHCenter) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_cb.png"; + + QTest::newRow("LC") << int(Qt::AlignLeft) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_lc.png"; + QTest::newRow("RC") << int(Qt::AlignRight) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_rc.png"; + QTest::newRow("CC") << int(Qt::AlignHCenter) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_cc.png"; +} + + +void tst_qdeclarativetextedit::alignments() +{ + QFETCH(int, hAlign); + QFETCH(int, vAlign); + QFETCH(QString, expectfile); + +#ifdef Q_WS_X11 + // Font-specific, but not likely platform-specific, so only test on one platform + QFont fn; + fn.setRawName("-misc-fixed-medium-r-*-*-8-*-*-*-*-*-*-*"); + QApplication::setFont(fn); +#endif + + QDeclarativeView *canvas = createView(SRCDIR "/data/alignments.qml"); + + canvas->show(); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(canvas)); + + QObject *ob = canvas->rootObject(); + QVERIFY(ob != 0); + ob->setProperty("horizontalAlignment",hAlign); + ob->setProperty("verticalAlignment",vAlign); + QTRY_COMPARE(ob->property("running").toBool(),false); + QImage actual(canvas->width(), canvas->height(), QImage::Format_RGB32); + actual.fill(qRgb(255,255,255)); + QPainter p(&actual); + canvas->render(&p); + + QImage expect(expectfile); + +#ifdef Q_WS_X11 + // Font-specific, but not likely platform-specific, so only test on one platform + QCOMPARE(actual,expect); +#endif +} + + //the alignment tests may be trivial o.oa void tst_qdeclarativetextedit::hAlign() { diff --git a/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp b/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp index f30f758..9660430 100644 --- a/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp +++ b/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp @@ -43,6 +43,7 @@ #include <QtDeclarative/qdeclarativeengine.h> #include <QtDeclarative/qdeclarativeview.h> #include <QtDeclarative/qdeclarativeitem.h> +#include <QtGui/qmenubar.h> #include "../../../shared/util.h" #include "qmlruntime.h" #include "../../../shared/util.h" @@ -52,6 +53,12 @@ #define SRCDIR "." #endif +#if defined(Q_OS_MAC) || defined(Q_WS_MAEMO_5) || defined(Q_WS_S60) +# define MENUBAR_HEIGHT(mw) 0 +#else +# define MENUBAR_HEIGHT(mw) (mw->menuBar()->height()) +#endif + class tst_QDeclarativeViewer : public QObject { @@ -75,47 +82,55 @@ tst_QDeclarativeViewer::tst_QDeclarativeViewer() { } +#define TEST_INITIAL_SIZES(viewer) { \ + QDeclarativeItem* rootItem = qobject_cast<QDeclarativeItem*>(viewer->view()->rootObject()); \ + QVERIFY(rootItem); \ +\ + QCOMPARE(rootItem->width(), 200.0); \ + QCOMPARE(rootItem->height(), 300.0); \ + QTRY_COMPARE(viewer->view()->size(), QSize(200, 300)); \ + QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); \ + QCOMPARE(viewer->size(), QSize(200, 300 + MENUBAR_HEIGHT(viewer))); \ + QCOMPARE(viewer->size(), viewer->sizeHint()); \ +} + void tst_QDeclarativeViewer::orientation() { - QWidget window; - QDeclarativeViewer *viewer = new QDeclarativeViewer(&window); + QDeclarativeViewer *viewer = new QDeclarativeViewer(); QVERIFY(viewer); viewer->open(SRCDIR "/data/orientation.qml"); QVERIFY(viewer->view()); QVERIFY(viewer->menuBar()); QDeclarativeItem* rootItem = qobject_cast<QDeclarativeItem*>(viewer->view()->rootObject()); QVERIFY(rootItem); - window.show(); + viewer->show(); - QApplication::setActiveWindow(&window); - QTest::qWaitForWindowShown(&window); - QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&window)); + QApplication::setActiveWindow(viewer); + QTest::qWaitForWindowShown(viewer); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(viewer)); - QCOMPARE(rootItem->width(), 200.0); - QCOMPARE(rootItem->height(), 300.0); - QTRY_COMPARE(viewer->view()->size(), QSize(200, 300)); - QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); - QCOMPARE(viewer->size(), QSize(200, 300+viewer->menuBar()->height())); - QCOMPARE(viewer->size(), viewer->sizeHint()); + TEST_INITIAL_SIZES(viewer); viewer->rotateOrientation(); qApp->processEvents(); + qApp->processEvents(); // one extra round for the delayed updateSizeHints() call QCOMPARE(rootItem->width(), 300.0); QCOMPARE(rootItem->height(), 200.0); QTRY_COMPARE(viewer->view()->size(), QSize(300, 200)); QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(300, 200)); - QCOMPARE(viewer->size(), QSize(300, 200+viewer->menuBar()->height())); + QCOMPARE(viewer->size(), QSize(300, 200 + MENUBAR_HEIGHT(viewer))); QCOMPARE(viewer->size(), viewer->sizeHint()); viewer->rotateOrientation(); qApp->processEvents(); + qApp->processEvents(); // one extra round for the delayed updateSizeHints() call QCOMPARE(rootItem->width(), 200.0); QCOMPARE(rootItem->height(), 300.0); QTRY_COMPARE(viewer->view()->size(), QSize(200, 300)); QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); - QCOMPARE(viewer->size(), QSize(200, 300+viewer->menuBar()->height())); + QCOMPARE(viewer->size(), QSize(200, 300 + MENUBAR_HEIGHT(viewer))); QCOMPARE(viewer->size(), viewer->sizeHint()); } @@ -135,13 +150,7 @@ void tst_QDeclarativeViewer::loading() QTest::qWaitForWindowShown(viewer); QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(viewer)); - // initial size - QTRY_COMPARE(rootItem->width(), 200.0); - QTRY_COMPARE(rootItem->height(), 300.0); - QCOMPARE(viewer->view()->size(), QSize(200, 300)); - QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); - QCOMPARE(viewer->size(), QSize(200, 300+viewer->menuBar()->height())); - QCOMPARE(viewer->size(), viewer->sizeHint()); + TEST_INITIAL_SIZES(viewer); viewer->resize(QSize(400, 500)); qApp->processEvents(); @@ -243,14 +252,7 @@ void tst_QDeclarativeViewer::resizing() QTest::qWaitForWindowShown(viewer); QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(viewer)); - // initial size - QCOMPARE(rootItem->width(), 200.0); - QCOMPARE(rootItem->height(), 300.0); - QCOMPARE(viewer->view()->size(), QSize(200, 300)); - QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); - QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); - QCOMPARE(viewer->size(), QSize(200, 300+viewer->menuBar()->height())); - QCOMPARE(viewer->size(), viewer->sizeHint()); + TEST_INITIAL_SIZES(viewer); viewer->setSizeToView(false); @@ -261,7 +263,7 @@ void tst_QDeclarativeViewer::resizing() QCOMPARE(rootItem->width(), 150.0); QCOMPARE(rootItem->height(), 200.0); - QCOMPARE(viewer->view()->size(), QSize(150, 200)); + QTRY_COMPARE(viewer->view()->size(), QSize(150, 200)); QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(150, 200)); QCOMPARE(viewer->size(), QSize(150, 200+viewer->menuBar()->height())); @@ -279,7 +281,7 @@ void tst_QDeclarativeViewer::resizing() QTRY_COMPARE(rootItem->width(), 250.0); QTRY_COMPARE(rootItem->height(), 350.0-viewer->menuBar()->height()); - QCOMPARE(viewer->view()->size(), QSize(250, 350-viewer->menuBar()->height())); + QTRY_COMPARE(viewer->view()->size(), QSize(250, 350-viewer->menuBar()->height())); QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(250, 350-viewer->menuBar()->height())); QCOMPARE(viewer->size(), QSize(250, 350)); diff --git a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp index 90c9c6f..43d4d06 100644 --- a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp +++ b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp @@ -173,10 +173,10 @@ void tst_qdeclarativevisualdatamodel::objectListModel() QDeclarativeListView *listview = qobject_cast<QDeclarativeListView*>(view.rootObject()); QVERIFY(listview != 0); - QDeclarativeItem *viewport = listview->viewport(); - QVERIFY(viewport != 0); + QDeclarativeItem *contentItem = listview->contentItem(); + QVERIFY(contentItem != 0); - QDeclarativeText *name = findItem<QDeclarativeText>(viewport, "name", 0); + QDeclarativeText *name = findItem<QDeclarativeText>(contentItem, "name", 0); QCOMPARE(name->text(), QString("Item 1")); dataList[0]->setProperty("name", QLatin1String("Changed")); diff --git a/tests/benchmarks/declarative/script/data/block.qml b/tests/benchmarks/declarative/script/data/block.qml index 4e5006e..f7b2ab3 100644 --- a/tests/benchmarks/declarative/script/data/block.qml +++ b/tests/benchmarks/declarative/script/data/block.qml @@ -47,7 +47,7 @@ Rectangle { function doSomethingDirect() { theObject.prop1 = 0; - for (var i = 0; i < 60; ++i) + for (var i = 0; i < 1000; ++i) theObject.prop1 += theObject.prop2; theObject.prop3 = theObject.prop1; @@ -57,7 +57,7 @@ Rectangle { theObject.prop1 = 0; var incrementObj = theObject; - for (var i = 0; i < 60; ++i) + for (var i = 0; i < 1000; ++i) incrementObj.prop1 += incrementObj.prop2; incrementObj.prop3 = incrementObj.prop1; @@ -67,7 +67,7 @@ Rectangle { theObject.prop1 = 0; var increment = theObject.prop2; - for (var i = 0; i < 60; ++i) + for (var i = 0; i < 1000; ++i) theObject.prop1 += increment; theObject.prop3 = theObject.prop1; diff --git a/tests/benchmarks/declarative/script/data/global.js b/tests/benchmarks/declarative/script/data/global.js new file mode 100644 index 0000000..5b86b4d --- /dev/null +++ b/tests/benchmarks/declarative/script/data/global.js @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite 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$ +** +****************************************************************************/ + +var incVar = 1; +var total; + +function doSomething() { + for (var i = 0; i < 10000; ++i) + Math.sin(90); +} + +function doIncrement() { + total = 0; + for (var i = 0; i < 100000; ++i) + total += incVar; +} diff --git a/tests/benchmarks/declarative/script/data/global_prop.qml b/tests/benchmarks/declarative/script/data/global_prop.qml new file mode 100644 index 0000000..4fb7ee7 --- /dev/null +++ b/tests/benchmarks/declarative/script/data/global_prop.qml @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite 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$ +** +****************************************************************************/ + +import Qt 4.7 +import "global.js" as Program + +Rectangle { + width: 200; height: 200 + + signal triggered + signal incrementTriggered + + onTriggered: Program.doSomething(); + onIncrementTriggered: Program.doIncrement(); +} diff --git a/tests/benchmarks/declarative/script/tst_script.cpp b/tests/benchmarks/declarative/script/tst_script.cpp index 99f294c..5a7e151 100644 --- a/tests/benchmarks/declarative/script/tst_script.cpp +++ b/tests/benchmarks/declarative/script/tst_script.cpp @@ -92,7 +92,12 @@ private slots: void block_data(); void block(); -private: + + void global_property_js(); + void global_property_qml(); + void global_property_qml_js(); + + void scriptfile_property(); }; inline QUrl TEST_FILE(const QString &filename) @@ -625,6 +630,74 @@ void tst_script::block() delete rect; } +#define GLOBALPROPERTY_PROGRAM \ + "(function() { " \ + " for (var ii = 0; ii < 10000; ++ii) { " \ + " Math.sin(90); " \ + " } " \ + "})" + +void tst_script::global_property_js() +{ + QScriptEngine engine; + + QScriptValue prog = engine.evaluate(GLOBALPROPERTY_PROGRAM); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +void tst_script::global_property_qml() +{ + QDeclarativeEngine qmlengine; + + QScriptEngine *engine = QDeclarativeEnginePrivate::getScriptEngine(&qmlengine); + QScriptValue prog = engine->evaluate(GLOBALPROPERTY_PROGRAM); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +void tst_script::global_property_qml_js() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, TEST_FILE("global_prop.qml")); + QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle *>(component.create()); + QVERIFY(rect != 0); + + int index = rect->metaObject()->indexOfMethod("triggered()"); + QVERIFY(index != -1); + QMetaMethod method = rect->metaObject()->method(index); + + QBENCHMARK { + method.invoke(rect, Qt::DirectConnection); + } + + delete rect; +} + +void tst_script::scriptfile_property() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, TEST_FILE("global_prop.qml")); + QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle *>(component.create()); + QVERIFY(rect != 0); + + int index = rect->metaObject()->indexOfMethod("incrementTriggered()"); + QVERIFY(index != -1); + QMetaMethod method = rect->metaObject()->method(index); + + QBENCHMARK { + method.invoke(rect, Qt::DirectConnection); + } + + delete rect; +} + QTEST_MAIN(tst_script) #include "tst_script.moc" diff --git a/tools/linguist/lupdate/qdeclarative.cpp b/tools/linguist/lupdate/qdeclarative.cpp index a734e99..2377416 100644 --- a/tools/linguist/lupdate/qdeclarative.cpp +++ b/tools/linguist/lupdate/qdeclarative.cpp @@ -87,27 +87,31 @@ protected: virtual void endVisit(AST::CallExpression *node) { + m_bSource.clear(); if (AST::IdentifierExpression *idExpr = AST::cast<AST::IdentifierExpression *>(node->base)) { if (idExpr->name->asString() == QLatin1String("qsTr") || idExpr->name->asString() == QLatin1String("QT_TR_NOOP")) { - if (node->arguments && AST::cast<AST::StringLiteral *>(node->arguments->expression)) { - AST::StringLiteral *literal = AST::cast<AST::StringLiteral *>(node->arguments->expression); - const QString source = literal->value->asString(); + if (!node->arguments) + return; + AST::BinaryExpression *binary = AST::cast<AST::BinaryExpression *>(node->arguments->expression); + if (binary) { + if (!createString(binary)) + m_bSource.clear(); + } + AST::StringLiteral *literal = AST::cast<AST::StringLiteral *>(node->arguments->expression); + if (literal || !m_bSource.isEmpty()) { + const QString source = literal ? literal->value->asString() : m_bSource; QString comment; bool plural = false; AST::ArgumentList *commentNode = node->arguments->next; - if (commentNode) { + if (commentNode && AST::cast<AST::StringLiteral *>(commentNode->expression)) { literal = AST::cast<AST::StringLiteral *>(commentNode->expression); comment = literal->value->asString(); AST::ArgumentList *nNode = commentNode->next; - if (nNode) { - AST::NumericLiteral *numLiteral = AST::cast<AST::NumericLiteral *>(nNode->expression); - if (numLiteral) { - plural = true; - } - } + if (nNode) + plural = true; } TranslatorMessage msg(m_component, source, @@ -126,22 +130,25 @@ protected: QString comment; bool plural = false; AST::ArgumentList *sourceNode = node->arguments->next; - if (sourceNode) { - literal = AST::cast<AST::StringLiteral *>(sourceNode->expression); - source = literal->value->asString(); - AST::ArgumentList *commentNode = sourceNode->next; - if (commentNode) { - literal = AST::cast<AST::StringLiteral *>(commentNode->expression); - comment = literal->value->asString(); - - AST::ArgumentList *nNode = commentNode->next; - if (nNode) { - AST::NumericLiteral *numLiteral = AST::cast<AST::NumericLiteral *>(nNode->expression); - if (numLiteral) { - plural = true; - } - } - } + if (!sourceNode) + return; + literal = AST::cast<AST::StringLiteral *>(sourceNode->expression); + AST::BinaryExpression *binary = AST::cast<AST::BinaryExpression *>(sourceNode->expression); + if (binary) { + if (!createString(binary)) + m_bSource.clear(); + } + if (!literal && m_bSource.isEmpty()) + return; + source = literal ? literal->value->asString() : m_bSource; + AST::ArgumentList *commentNode = sourceNode->next; + if (commentNode && AST::cast<AST::StringLiteral *>(commentNode->expression)) { + literal = AST::cast<AST::StringLiteral *>(commentNode->expression); + comment = literal->value->asString(); + + AST::ArgumentList *nNode = commentNode->next; + if (nNode) + plural = true; } TranslatorMessage msg(context, source, @@ -156,9 +163,34 @@ protected: } private: + bool createString(AST::BinaryExpression *b) { + if (!b || b->op != 0) + return false; + AST::BinaryExpression *l = AST::cast<AST::BinaryExpression *>(b->left); + AST::BinaryExpression *r = AST::cast<AST::BinaryExpression *>(b->right); + AST::StringLiteral *ls = AST::cast<AST::StringLiteral *>(b->left); + AST::StringLiteral *rs = AST::cast<AST::StringLiteral *>(b->right); + if ((!l && !ls) || (!r && !rs)) + return false; + if (l) { + if (!createString(l)) + return false; + } else + m_bSource.prepend(ls->value->asString()); + + if (r) { + if (!createString(r)) + return false; + } else + m_bSource.append(rs->value->asString()); + + return true; + } + Translator *m_translator; QString m_fileName; QString m_component; + QString m_bSource; }; QString createErrorString(const QString &filename, const QString &code, Parser &parser) diff --git a/tools/qdoc3/test/qdeclarative.qdocconf b/tools/qdoc3/test/qdeclarative.qdocconf index 74fd802..0433c9f 100644 --- a/tools/qdoc3/test/qdeclarative.qdocconf +++ b/tools/qdoc3/test/qdeclarative.qdocconf @@ -6,7 +6,7 @@ include(qt-defines.qdocconf) project = Qml description = Qml Reference Documentation -url = http://qt.nokia.com/doc/4.6/ +url = http://qt.nokia.com/doc/4.7/ qmlonly = true edition.Console.modules = QtCore QtDBus QtNetwork QtScript QtSql QtXml \ @@ -21,7 +21,7 @@ edition.DesktopLight.groups = -graphicsview-api qhp.projects = Qml qhp.Qml.file = qml.qhp -qhp.Qml.namespace = com.trolltech.qml.460 +qhp.Qml.namespace = com.trolltech.qml.470 qhp.Qml.virtualFolder = qdoc qhp.Qml.indexTitle = Qml Reference diff --git a/tools/qml/deviceorientation_maemo.cpp b/tools/qml/deviceorientation_maemo5.cpp index 443edc8..e942579 100644 --- a/tools/qml/deviceorientation_maemo.cpp +++ b/tools/qml/deviceorientation_maemo5.cpp @@ -124,4 +124,4 @@ DeviceOrientation* DeviceOrientation::instance() return o; } -#include "deviceorientation_maemo.moc" +#include "deviceorientation_maemo5.moc" diff --git a/tools/qml/loggerwidget.cpp b/tools/qml/loggerwidget.cpp index 3ae2b5e..8aa029f 100644 --- a/tools/qml/loggerwidget.cpp +++ b/tools/qml/loggerwidget.cpp @@ -39,29 +39,48 @@ ** ****************************************************************************/ -#include "loggerwidget.h" #include <qglobal.h> #include <QDebug> #include <QSettings> #include <QActionGroup> #include <QMenu> +#include <QPlainTextEdit> +#ifdef Q_WS_MAEMO_5 +# include <QScrollArea> +# include <QVBoxLayout> +# include "texteditautoresizer_maemo5.h" +#endif + +#include "loggerwidget.h" QT_BEGIN_NAMESPACE LoggerWidget::LoggerWidget(QWidget *parent) : - QPlainTextEdit(parent), + QMainWindow(parent), m_visibilityOrigin(SettingsOrigin) { setAttribute(Qt::WA_QuitOnClose, false); setWindowTitle(tr("Warnings")); + m_plainTextEdit = new QPlainTextEdit(); + +#ifdef Q_WS_MAEMO_5 + new TextEditAutoResizer(m_plainTextEdit); + setAttribute(Qt::WA_Maemo5StackedWindow); + QScrollArea *area = new QScrollArea(); + area->setWidget(m_plainTextEdit); + area->setWidgetResizable(true); + setCentralWidget(area); +#else + setCentralWidget(m_plainTextEdit); +#endif readSettings(); setupPreferencesMenu(); } void LoggerWidget::append(const QString &msg) { - appendPlainText(msg); + m_plainTextEdit->appendPlainText(msg); if (!isVisible() && (defaultVisibility() == AutoShowWarnings)) setVisible(true); diff --git a/tools/qml/loggerwidget.h b/tools/qml/loggerwidget.h index fd20c41..13c319f 100644 --- a/tools/qml/loggerwidget.h +++ b/tools/qml/loggerwidget.h @@ -42,12 +42,17 @@ #ifndef LOGGERWIDGET_H #define LOGGERWIDGET_H -#include <QPlainTextEdit> +#include <QMainWindow> +#include <QMetaType> QT_BEGIN_NAMESPACE -class LoggerWidget : public QPlainTextEdit { -Q_OBJECT +class QPlainTextEdit; +class QMenu; +class QAction; + +class LoggerWidget : public QMainWindow { + Q_OBJECT public: LoggerWidget(QWidget *parent=0); @@ -80,6 +85,7 @@ private: QMenu *m_preferencesMenu; QAction *m_showWidgetAction; + QPlainTextEdit *m_plainTextEdit; enum ConfigOrigin { CommandLineOrigin, SettingsOrigin }; ConfigOrigin m_visibilityOrigin; diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index a75023b..900a464 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -119,7 +119,7 @@ void usage() qWarning(" -fullscreen............................... run fullscreen"); qWarning(" -stayontop................................ keep viewer window on top"); qWarning(" -sizeviewtorootobject .................... the view resizes to the changes in the content"); - qWarning(" -sizerootobjecttoview .................... the content resizes to the changes in the view"); + qWarning(" -sizerootobjecttoview .................... the content resizes to the changes in the view (default)"); qWarning(" -qmlbrowser .............................. use a QML-based file browser"); qWarning(" -warnings [show|hide]..................... show warnings in a separate log window"); qWarning(" -recordfile <output> ..................... set video recording file"); diff --git a/tools/qml/proxysettings.cpp b/tools/qml/proxysettings.cpp index 3255e42..ffaa4c0 100644 --- a/tools/qml/proxysettings.cpp +++ b/tools/qml/proxysettings.cpp @@ -48,11 +48,14 @@ QT_BEGIN_NAMESPACE ProxySettings::ProxySettings (QWidget * parent) - : QDialog (parent), Ui::ProxySettings() + : QDialog (parent), Ui::ProxySettings() { setupUi (this); +#if !defined Q_WS_MAEMO_5 + // the onscreen keyboard can't cope with masks proxyServerEdit->setInputMask ("000.000.000.000;_"); +#endif QIntValidator *validator = new QIntValidator (0, 9999, this); proxyPortEdit->setValidator (validator); diff --git a/tools/qml/proxysettings.h b/tools/qml/proxysettings.h index 325929a..5d4d137 100644 --- a/tools/qml/proxysettings.h +++ b/tools/qml/proxysettings.h @@ -44,7 +44,11 @@ #include <QDialog> #include <QNetworkProxy> +#ifdef Q_WS_MAEMO_5 +#include "ui_proxysettings_maemo5.h" +#else #include "ui_proxysettings.h" +#endif QT_BEGIN_NAMESPACE /** diff --git a/tools/qml/proxysettings_maemo5.ui b/tools/qml/proxysettings_maemo5.ui new file mode 100644 index 0000000..83f0c2a --- /dev/null +++ b/tools/qml/proxysettings_maemo5.ui @@ -0,0 +1,177 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ProxySettings</class> + <widget class="QDialog" name="ProxySettings"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>449</width> + <height>164</height> + </rect> + </property> + <property name="windowTitle"> + <string>HTTP Proxy</string> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <property name="leftMargin"> + <number>16</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>16</number> + </property> + <property name="bottomMargin"> + <number>8</number> + </property> + <property name="horizontalSpacing"> + <number>16</number> + </property> + <property name="verticalSpacing"> + <number>0</number> + </property> + <item row="0" column="0"> + <widget class="QCheckBox" name="proxyCheckBox"> + <property name="text"> + <string>Use HTTP Proxy</string> + </property> + </widget> + </item> + <item row="0" column="1" rowspan="2"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="0" rowspan="2"> + <widget class="QWidget" name="widget" native="true"> + <layout class="QGridLayout" name="gridLayout"> + <property name="horizontalSpacing"> + <number>16</number> + </property> + <property name="verticalSpacing"> + <number>0</number> + </property> + <property name="margin"> + <number>0</number> + </property> + <item row="0" column="0"> + <widget class="QLabel" name="serverAddressLabel"> + <property name="text"> + <string>Server</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="proxyServerEdit"> + <property name="placeholderText"> + <string>Name or IP</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Port</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="proxyPortEdit"> + <property name="text"> + <string>8080</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="usernameLabel"> + <property name="text"> + <string>Username</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLineEdit" name="usernameEdit"/> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="passwordLabel"> + <property name="text"> + <string>Password</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QLineEdit" name="passwordEdit"> + <property name="echoMode"> + <enum>QLineEdit::Password</enum> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="2" column="1"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <tabstops> + <tabstop>proxyCheckBox</tabstop> + <tabstop>proxyServerEdit</tabstop> + <tabstop>proxyPortEdit</tabstop> + <tabstop>usernameEdit</tabstop> + <tabstop>passwordEdit</tabstop> + <tabstop>buttonBox</tabstop> + </tabstops> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>ProxySettings</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>318</x> + <y>100</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>116</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>ProxySettings</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>318</x> + <y>100</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>116</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/tools/qml/qml.pri b/tools/qml/qml.pri index 58d8cc1..3e5a88b 100644 --- a/tools/qml/qml.pri +++ b/tools/qml/qml.pri @@ -19,10 +19,12 @@ SOURCES += $$PWD/qmlruntime.cpp \ RESOURCES = $$PWD/qmlruntime.qrc maemo5 { QT += dbus - SOURCES += $$PWD/deviceorientation_maemo.cpp + HEADERS += $$PWD/texteditautoresizer_maemo5.h + SOURCES += $$PWD/deviceorientation_maemo5.cpp + FORMS = $$PWD/recopts_maemo5.ui \ + $$PWD/proxysettings_maemo5.ui } else { SOURCES += $$PWD/deviceorientation.cpp + FORMS = $$PWD/recopts.ui \ + $$PWD/proxysettings.ui } - -FORMS = $$PWD/recopts.ui \ - $$PWD/proxysettings.ui diff --git a/tools/qml/qml.pro b/tools/qml/qml.pro index 9cdec77..63efff1 100644 --- a/tools/qml/qml.pro +++ b/tools/qml/qml.pro @@ -29,6 +29,9 @@ wince* { QT += webkit } } +maemo5 { + QT += maemo5 +} symbian { TARGET.UID3 = 0x20021317 include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 676881d..ec748b4 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -44,7 +44,15 @@ #ifdef hz #undef hz #endif -#include "ui_recopts.h" +#ifdef Q_WS_MAEMO_5 +# include <QMaemo5ValueButton> +# include <QMaemo5ListPickSelector> +# include <QWidgetAction> +# include <QStringListModel> +# include "ui_recopts_maemo5.h" +#else +# include "ui_recopts.h" +#endif #include "qmlruntime.h" #include <qdeclarativecontext.h> @@ -136,24 +144,59 @@ private: }; -class SizedMenuBar : public QMenuBar -{ + +#if defined(Q_WS_MAEMO_5) + +class Maemo5PickerAction : public QWidgetAction { Q_OBJECT public: - SizedMenuBar(QWidget *parent, QWidget *referenceWidget) - : QMenuBar(parent), refWidget(referenceWidget) + Maemo5PickerAction(const QString &text, QActionGroup *actions, QObject *parent) + : QWidgetAction(parent), m_text(text), m_actions(actions) + { } + + QWidget *createWidget(QWidget *parent) { + QMaemo5ValueButton *button = new QMaemo5ValueButton(m_text, parent); + button->setValueLayout(QMaemo5ValueButton::ValueUnderTextCentered); + QMaemo5ListPickSelector *pick = new QMaemo5ListPickSelector(button); + button->setPickSelector(pick); + if (m_actions) { + QStringList sl; + int curIdx = -1, idx = 0; + foreach (QAction *a, m_actions->actions()) { + sl << a->text(); + if (a->isChecked()) + curIdx = idx; + idx++; + } + pick->setModel(new QStringListModel(sl)); + pick->setCurrentIndex(curIdx); + } else { + button->setEnabled(false); + } + connect(pick, SIGNAL(selected(QString)), this, SLOT(emitTriggered())); + return button; } - virtual QSize sizeHint() const +private slots: + void emitTriggered() { - return QSize(refWidget->sizeHint().width(), QMenuBar::sizeHint().height()); + QMaemo5ListPickSelector *pick = qobject_cast<QMaemo5ListPickSelector *>(sender()); + if (!pick) + return; + int idx = pick->currentIndex(); + + if (m_actions && idx >= 0 && idx < m_actions->actions().count()) + m_actions->actions().at(idx)->trigger(); } private: - QWidget *refWidget; + QString m_text; + QPointer<QActionGroup> m_actions; }; +#endif // Q_WS_MAEMO_5 + static struct { const char *name, *args; } ffmpegprofiles[] = { {"Maximum Quality", "-sameq"}, {"High Quality", "-qmax 2"}, @@ -170,7 +213,9 @@ public: RecordingDialog(QWidget *parent) : QDialog(parent) { setupUi(this); +#ifndef Q_WS_MAEMO_5 hz->setValidator(new QDoubleValidator(hz)); +#endif for (int i=0; ffmpegprofiles[i].name; ++i) { profile->addItem(ffmpegprofiles[i].name); } @@ -197,6 +242,132 @@ public: return ffmpegprofiles[i].args[0] ? QLatin1String(ffmpegprofiles[i].args) : customargs; } + void setOriginalSize(const QSize &s) + { + QString str = tr("Original (%1x%2)").arg(s.width()).arg(s.height()); + +#ifdef Q_WS_MAEMO_5 + sizeCombo->setItemText(0, str); +#else + sizeOriginal->setText(str); + if (sizeWidth->value()<=1) { + sizeWidth->setValue(s.width()); + sizeHeight->setValue(s.height()); + } +#endif + } + + void showffmpegOptions(bool b) + { +#ifdef Q_WS_MAEMO_5 + profileLabel->setVisible(b); + profile->setVisible(b); + ffmpegHelp->setVisible(b); + args->setVisible(b); +#else + ffmpegOptions->setVisible(b); +#endif + } + + void showRateOptions(bool b) + { +#ifdef Q_WS_MAEMO_5 + rateLabel->setVisible(b); + rateCombo->setVisible(b); +#else + rateOptions->setVisible(b); +#endif + } + + void setVideoRate(int rate) + { +#ifdef Q_WS_MAEMO_5 + int idx; + if (rate >= 60) + idx = 0; + else if (rate >= 50) + idx = 2; + else if (rate >= 25) + idx = 3; + else if (rate >= 24) + idx = 4; + else if (rate >= 20) + idx = 5; + else if (rate >= 15) + idx = 6; + else + idx = 7; + rateCombo->setCurrentIndex(idx); +#else + if (rate == 24) + hz24->setChecked(true); + else if (rate == 25) + hz25->setChecked(true); + else if (rate == 50) + hz50->setChecked(true); + else if (rate == 60) + hz60->setChecked(true); + else { + hzCustom->setChecked(true); + hz->setText(QString::number(rate)); + } +#endif + } + + int videoRate() const + { +#ifdef Q_WS_MAEMO_5 + switch (rateCombo->currentIndex()) { + case 0: return 60; + case 1: return 50; + case 2: return 25; + case 3: return 24; + case 4: return 20; + case 5: return 15; + case 7: return 10; + default: return 60; + } +#else + if (hz24->isChecked()) + return 24; + else if (hz25->isChecked()) + return 25; + else if (hz50->isChecked()) + return 50; + else if (hz60->isChecked()) + return 60; + else { + return hz->text().toInt(); + } +#endif + } + + QSize videoSize() const + { +#ifdef Q_WS_MAEMO_5 + switch (sizeCombo->currentIndex()) { + case 0: return QSize(); + case 1: return QSize(640,480); + case 2: return QSize(320,240); + case 3: return QSize(1280,720); + default: return QSize(); + } +#else + if (sizeOriginal->isChecked()) + return QSize(); + else if (size720p->isChecked()) + return QSize(1280,720); + else if (sizeVGA->isChecked()) + return QSize(640,480); + else if (sizeQVGA->isChecked()) + return QSize(320,240); + else + return QSize(sizeWidth->value(), sizeHeight->value()); +#endif + } + + + private slots: void pickProfile(int i) { @@ -363,15 +534,10 @@ QString QDeclarativeViewer::getVideoFileName() return QFileDialog::getSaveFileName(this, title, "", types.join(";; ")); } - QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) -#if defined(Q_OS_SYMBIAN) : QMainWindow(parent, flags) -#else - : QWidget(parent, flags) -#endif - , loggerWindow(new LoggerWidget()) - , frame_stream(0), mb(0) + , loggerWindow(new LoggerWidget(this)) + , frame_stream(0) , orientation(0) , showWarningsWindow(0) , m_scriptOptions(0) @@ -381,6 +547,10 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) { QDeclarativeViewer::registerTypes(); setWindowTitle(tr("Qt QML Viewer")); +#ifdef Q_WS_MAEMO_5 + setAttribute(Qt::WA_Maemo5StackedWindow); +// setPalette(QApplication::palette("QLabel")); +#endif devicemode = false; canvas = 0; @@ -393,9 +563,9 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) senseFfmpeg(); senseImageMagick(); if (!ffmpegAvailable) - recdlg->ffmpegOptions->hide(); + recdlg->showffmpegOptions(false); if (!ffmpegAvailable && !convertAvailable) - recdlg->rateOptions->hide(); + recdlg->showRateOptions(false); QString warn; if (!ffmpegAvailable) { if (!convertAvailable) @@ -422,21 +592,14 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) QObject::connect(warningsWidget(), SIGNAL(closed()), this, SLOT(warningsWidgetClosed())); if (!(flags & Qt::FramelessWindowHint)) { - createMenu(menuBar(),0); + createMenu(); changeOrientation(orientation->actions().value(0)); + } else { + setMenuBar(0); } -#if !defined(Q_OS_SYMBIAN) - QVBoxLayout *layout = new QVBoxLayout; - layout->setMargin(0); - layout->setSpacing(0); - setLayout(layout); - if (mb) - layout->addWidget(mb); - layout->addWidget(canvas); -#else setCentralWidget(canvas); -#endif + namFactory = new NetworkAccessManagerFactory; canvas->engine()->setNetworkAccessManagerFactory(namFactory); @@ -449,6 +612,8 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) autoStopTimer.setRunning(false); recordTimer.setRunning(false); recordTimer.setRepeating(true); + + QObject::connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(appAboutToQuit())); } QDeclarativeViewer::~QDeclarativeViewer() @@ -468,26 +633,6 @@ void QDeclarativeViewer::enableExperimentalGestures() canvas->viewport()->setAttribute(Qt::WA_AcceptTouchEvents); } -int QDeclarativeViewer::menuBarHeight() const -{ - if (!(windowFlags() & Qt::FramelessWindowHint)) - return menuBar()->height(); - else - return 0; // don't create menu -} - -QMenuBar *QDeclarativeViewer::menuBar() const -{ -#if !defined(Q_OS_SYMBIAN) - if (!mb) - mb = new SizedMenuBar((QWidget*)this, canvas); -#else - mb = QMainWindow::menuBar(); -#endif - - return mb; -} - QDeclarativeView *QDeclarativeViewer::view() const { return canvas; @@ -498,120 +643,128 @@ LoggerWidget *QDeclarativeViewer::warningsWidget() const return loggerWindow; } -void QDeclarativeViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) +void QDeclarativeViewer::createMenu() { - QObject *parent = flatmenu ? (QObject*)flatmenu : (QObject*)menu; - - QMenu *fileMenu = flatmenu ? flatmenu : menu->addMenu(tr("&File")); - - QAction *openAction = new QAction(tr("&Open..."), parent); + QAction *openAction = new QAction(tr("&Open..."), this); openAction->setShortcut(QKeySequence("Ctrl+O")); connect(openAction, SIGNAL(triggered()), this, SLOT(openFile())); - fileMenu->addAction(openAction); - QAction *reloadAction = new QAction(tr("&Reload"), parent); + QAction *reloadAction = new QAction(tr("&Reload"), this); reloadAction->setShortcut(QKeySequence("Ctrl+R")); connect(reloadAction, SIGNAL(triggered()), this, SLOT(reload())); - fileMenu->addAction(reloadAction); - -#if !defined(Q_OS_SYMBIAN) - if (flatmenu) flatmenu->addSeparator(); - QMenu *recordMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Recording")); - - QAction *snapshotAction = new QAction(tr("&Take Snapshot\tF3"), parent); + QAction *snapshotAction = new QAction(tr("&Take Snapshot"), this); + snapshotAction->setShortcut(QKeySequence("F3")); connect(snapshotAction, SIGNAL(triggered()), this, SLOT(takeSnapShot())); - recordMenu->addAction(snapshotAction); - recordAction = new QAction(tr("Start Recording &Video\tF9"), parent); + recordAction = new QAction(tr("Start Recording &Video"), this); + recordAction->setShortcut(QKeySequence("F9")); connect(recordAction, SIGNAL(triggered()), this, SLOT(toggleRecordingWithSelection())); - recordMenu->addAction(recordAction); - QAction *recordOptions = new QAction(tr("Video &Options..."), parent); + QAction *recordOptions = new QAction(tr("Video &Options..."), this); connect(recordOptions, SIGNAL(triggered()), this, SLOT(chooseRecordingOptions())); - if (flatmenu) - flatmenu->addAction(recordOptions); - - if (flatmenu) flatmenu->addSeparator(); - - QMenu *debugMenu = flatmenu ? flatmenu->addMenu(tr("&Debugging")) : menu->addMenu(tr("&Debugging")); - - QAction *slowAction = new QAction(tr("&Slow Down Animations"), parent); + QAction *slowAction = new QAction(tr("&Slow Down Animations"), this); slowAction->setShortcut(QKeySequence("Ctrl+.")); slowAction->setCheckable(true); connect(slowAction, SIGNAL(triggered(bool)), this, SLOT(setSlowMode(bool))); - debugMenu->addAction(slowAction); - showWarningsWindow = new QAction(tr("Show Warnings"), parent); + showWarningsWindow = new QAction(tr("Show Warnings"), this); showWarningsWindow->setCheckable((true)); showWarningsWindow->setChecked(loggerWindow->isVisible()); connect(showWarningsWindow, SIGNAL(triggered(bool)), this, SLOT(showWarnings(bool))); -#if !defined(Q_OS_SYMBIAN) - debugMenu->addAction(showWarningsWindow); -#endif - - if (flatmenu) flatmenu->addSeparator(); - -#endif // Q_OS_SYMBIAN - - QMenu *settingsMenu = flatmenu ? flatmenu : menu->addMenu(tr("S&ettings")); - QAction *proxyAction = new QAction(tr("Http &proxy..."), parent); + QAction *proxyAction = new QAction(tr("HTTP &Proxy..."), this); connect(proxyAction, SIGNAL(triggered()), this, SLOT(showProxySettings())); - settingsMenu->addAction(proxyAction); -#if !defined(Q_OS_SYMBIAN) - if (!flatmenu) - settingsMenu->addAction(recordOptions); - settingsMenu->addMenu(loggerWindow->preferencesMenu()); -#else - QAction *fullscreenAction = new QAction(tr("Full Screen"), parent); + QAction *fullscreenAction = new QAction(tr("Full Screen"), this); fullscreenAction->setCheckable(true); connect(fullscreenAction, SIGNAL(triggered()), this, SLOT(toggleFullScreen())); - settingsMenu->addAction(fullscreenAction); -#endif - - if (flatmenu) flatmenu->addSeparator(); - - QMenu *propertiesMenu = settingsMenu->addMenu(tr("Properties")); - orientation = new QActionGroup(parent); - - QAction *rotateOrientation = new QAction(tr("Rotate orientation"), parent); + QAction *rotateOrientation = new QAction(tr("Rotate orientation"), this); rotateOrientation->setShortcut(QKeySequence("Ctrl+T")); - settingsMenu->addAction(rotateOrientation); connect(rotateOrientation, SIGNAL(triggered()), this, SLOT(rotateOrientation())); + orientation = new QActionGroup(this); orientation->setExclusive(true); connect(orientation, SIGNAL(triggered(QAction*)), this, SLOT(changeOrientation(QAction*))); - orientation->addAction(tr("orientation: Portrait")); - orientation->addAction(tr("orientation: Landscape")); - orientation->addAction(tr("orientation: Portrait (Inverted)")); - orientation->addAction(tr("orientation: Landscape (Inverted)")); - QList<QAction *> actions = orientation->actions(); - for (int i=0; i<actions.count(); i++) { - propertiesMenu->addAction(actions[i]); - actions[i]->setCheckable(true); - } - - if (flatmenu) flatmenu->addSeparator(); + QAction *portraitAction = new QAction(tr("Portrait"), this); + portraitAction->setCheckable(true); + QAction *landscapeAction = new QAction(tr("Landscape"), this); + landscapeAction->setCheckable(true); + QAction *portraitInvAction = new QAction(tr("Portrait (inverted)"), this); + portraitInvAction->setCheckable(true); + QAction *landscapeInvAction = new QAction(tr("Landscape (inverted)"), this); + landscapeInvAction->setCheckable(true); - QMenu *helpMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Help")); - QAction *aboutAction = new QAction(tr("&About Qt..."), parent); + QAction *aboutAction = new QAction(tr("&About Qt..."), this); connect(aboutAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); - helpMenu->addAction(aboutAction); - QAction *quitAction = new QAction(tr("&Quit"), parent); + QAction *quitAction = new QAction(tr("&Quit"), this); quitAction->setShortcut(QKeySequence("Ctrl+Q")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + + QMenuBar *menu = menuBar(); + if (!menu) + return; + +#if defined(Q_WS_MAEMO_5) + menu->addAction(openAction); + menu->addAction(reloadAction); + + menu->addAction(snapshotAction); + menu->addAction(recordAction); + + menu->addAction(recordOptions); + menu->addAction(proxyAction); + + menu->addAction(slowAction); + menu->addAction(showWarningsWindow); + + orientation->addAction(landscapeAction); + orientation->addAction(portraitAction); + menu->addAction(new Maemo5PickerAction(tr("Set orientation"), orientation, this)); + menu->addAction(fullscreenAction); + return; +#endif // Q_WS_MAEMO_5 + + QMenu *fileMenu = menu->addMenu(tr("&File")); + fileMenu->addAction(openAction); + fileMenu->addAction(reloadAction); fileMenu->addSeparator(); fileMenu->addAction(quitAction); - if (menu) { - menu->setFixedHeight(menu->sizeHint().height()); - menu->setMinimumWidth(10); - } + +#if !defined(Q_OS_SYMBIAN) + QMenu *recordMenu = menu->addMenu(tr("&Recording")); + recordMenu->addAction(snapshotAction); + recordMenu->addAction(recordAction); + + QMenu *debugMenu = menu->addMenu(tr("&Debugging")); + debugMenu->addAction(slowAction); + debugMenu->addAction(showWarningsWindow); +#endif // ! Q_OS_SYMBIAN + + QMenu *settingsMenu = menu->addMenu(tr("S&ettings")); + settingsMenu->addAction(proxyAction); +#if !defined(Q_OS_SYMBIAN) + settingsMenu->addAction(recordOptions); + settingsMenu->addMenu(loggerWindow->preferencesMenu()); +#else // ! Q_OS_SYMBIAN + settingsMenu->addAction(fullscreenAction); +#endif // Q_OS_SYMBIAN + settingsMenu->addAction(rotateOrientation); + + QMenu *propertiesMenu = settingsMenu->addMenu(tr("Properties")); + + orientation->addAction(portraitAction); + orientation->addAction(landscapeAction); + orientation->addAction(portraitInvAction); + orientation->addAction(landscapeInvAction); + propertiesMenu->addActions(orientation->actions()); + + QMenu *helpMenu = menu->addMenu(tr("&Help")); + helpMenu->addAction(aboutAction); } void QDeclarativeViewer::showProxySettings() @@ -685,25 +838,11 @@ void QDeclarativeViewer::chooseRecordingOptions() recdlg->file->setText(record_file); // Size - recdlg->sizeOriginal->setText(tr("Original (%1x%2)").arg(canvas->width()).arg(canvas->height())); - if (recdlg->sizeWidth->value()<=1) { - recdlg->sizeWidth->setValue(canvas->width()); - recdlg->sizeHeight->setValue(canvas->height()); - } + recdlg->setOriginalSize(canvas->size()); // Rate - if (record_rate == 24) - recdlg->hz24->setChecked(true); - else if (record_rate == 25) - recdlg->hz25->setChecked(true); - else if (record_rate == 50) - recdlg->hz50->setChecked(true); - else if (record_rate == 60) - recdlg->hz60->setChecked(true); - else { - recdlg->hzCustom->setChecked(true); - recdlg->hz->setText(QString::number(record_rate)); - } + recdlg->setVideoRate(record_rate); + // Profile recdlg->setArguments(record_args.join(" ")); @@ -711,28 +850,9 @@ void QDeclarativeViewer::chooseRecordingOptions() // File record_file = recdlg->file->text(); // Size - if (recdlg->sizeOriginal->isChecked()) - record_outsize = QSize(); - else if (recdlg->size720p->isChecked()) - record_outsize = QSize(1280,720); - else if (recdlg->sizeVGA->isChecked()) - record_outsize = QSize(640,480); - else if (recdlg->sizeQVGA->isChecked()) - record_outsize = QSize(320,240); - else - record_outsize = QSize(recdlg->sizeWidth->value(),recdlg->sizeHeight->value()); + record_outsize = recdlg->videoSize(); // Rate - if (recdlg->hz24->isChecked()) - record_rate = 24; - else if (recdlg->hz25->isChecked()) - record_rate = 25; - else if (recdlg->hz50->isChecked()) - record_rate = 50; - else if (recdlg->hz60->isChecked()) - record_rate = 60; - else { - record_rate = recdlg->hz->text().toDouble(); - } + record_rate = recdlg->videoRate(); // Profile record_args = recdlg->arguments().split(" ",QString::SkipEmptyParts); } @@ -807,8 +927,9 @@ void QDeclarativeViewer::statusChanged() initialSize = canvas->initialSize(); if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) { if (!isFullScreen() && !isMaximized()) { - resize(QSize(initialSize.width(), initialSize.height()+menuBarHeight())); - updateSizeHints(); + canvas->setFixedSize(initialSize); + resize(1, 1); // workaround for QMainWindowLayout NOT shrinking the window if the centralWidget() shrink + QTimer::singleShot(0, this, SLOT(updateSizeHints())); } } } @@ -1147,6 +1268,16 @@ void QDeclarativeViewer::ffmpegFinished(int code) qDebug() << "ffmpeg returned" << code << frame_stream->readAllStandardError(); } +void QDeclarativeViewer::appAboutToQuit() +{ + // avoid QGLContext errors about invalid contexts on exit + canvas->setViewport(0); + + // avoid crashes if messages are received after app has closed + delete loggerWindow; + loggerWindow = 0; +} + void QDeclarativeViewer::autoStartRecording() { setRecording(true); @@ -1181,14 +1312,14 @@ void QDeclarativeViewer::changeOrientation(QAction *action) return; action->setChecked(true); - QString o = action->text().split(QLatin1Char(':')).value(1).trimmed(); + QString o = action->text(); if (o == QLatin1String("Portrait")) DeviceOrientation::instance()->setOrientation(DeviceOrientation::Portrait); else if (o == QLatin1String("Landscape")) DeviceOrientation::instance()->setOrientation(DeviceOrientation::Landscape); - else if (o == QLatin1String("Portrait (Inverted)")) + else if (o == QLatin1String("Portrait (inverted)")) DeviceOrientation::instance()->setOrientation(DeviceOrientation::PortraitInverted); - else if (o == QLatin1String("Landscape (Inverted)")) + else if (o == QLatin1String("Landscape (inverted)")) DeviceOrientation::instance()->setOrientation(DeviceOrientation::LandscapeInverted); } @@ -1197,9 +1328,11 @@ void QDeclarativeViewer::orientationChanged() if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) { if (canvas->rootObject()) { QSizeF rootObjectSize = canvas->rootObject()->boundingRect().size(); - QSize newSize(rootObjectSize.width(), rootObjectSize.height()+menuBarHeight()); - if (size() != newSize) { - resize(newSize); + if (size() != rootObjectSize.toSize()) { + canvas->setMinimumSize(rootObjectSize.toSize()); + canvas->resize(rootObjectSize.toSize()); + resize(rootObjectSize.toSize()); + resize(1, 1); // workaround for QMainWindowLayout NOT shrinking the window if the centralWidget() shrinks } } } @@ -1253,16 +1386,15 @@ void QDeclarativeViewer::updateSizeHints() { if (canvas->resizeMode() == QDeclarativeView::SizeViewToRootObject) { QSize newWindowSize = canvas->sizeHint(); - newWindowSize.setHeight(newWindowSize.height()+menuBarHeight()); if (!isFullScreen() && !isMaximized()) { - resize(newWindowSize); - setFixedSize(newWindowSize); + canvas->setMinimumSize(newWindowSize); + canvas->resize(newWindowSize); + resize(1, 1); // workaround for QMainWindowLayout NOT shrinking the window if the centralWidget() shrinks + canvas->setMinimumSize(QSize(0, 0)); } } else { // QDeclarativeView::SizeRootObjectToView canvas->setMinimumSize(QSize(0,0)); canvas->setMaximumSize(QSize(16777215,16777215)); - setMinimumSize(QSize(0,0)); - setMaximumSize(QSize(16777215,16777215)); } } diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h index 27bd217..a3a9fb3 100644 --- a/tools/qml/qmlruntime.h +++ b/tools/qml/qmlruntime.h @@ -43,7 +43,6 @@ #define QDECLARATIVEVIEWER_H #include <QMainWindow> -#include <QMenuBar> #include <private/qdeclarativetimer_p.h> #include <QTime> #include <QList> @@ -62,17 +61,16 @@ class QNetworkReply; class QNetworkCookieJar; class NetworkAccessManagerFactory; class QTranslator; +class QActionGroup; +class QMenuBar; class QDeclarativeViewer -#if defined(Q_OS_SYMBIAN) : public QMainWindow -#else - : public QWidget -#endif { -Q_OBJECT + Q_OBJECT + public: - QDeclarativeViewer(QWidget *parent=0, Qt::WindowFlags flags=0); + QDeclarativeViewer(QWidget *parent = 0, Qt::WindowFlags flags = 0); ~QDeclarativeViewer(); static void registerTypes(); @@ -103,11 +101,8 @@ public: void addPluginPath(const QString& plugin); void setUseGL(bool use); void setUseNativeFileBrowser(bool); - void updateSizeHints(); void setSizeToView(bool sizeToView); - QMenuBar *menuBar() const; - QDeclarativeView *view() const; LoggerWidget *warningsWidget() const; @@ -132,9 +127,11 @@ public slots: protected: virtual void keyPressEvent(QKeyEvent *); virtual bool event(QEvent *); - void createMenu(QMenuBar *menu, QMenu *flatmenu); + void createMenu(); private slots: + void appAboutToQuit(); + void autoStartRecording(); void autoStopRecording(); void recordFrame(); @@ -148,9 +145,10 @@ private slots: void warningsWidgetOpened(); void warningsWidgetClosed(); + void updateSizeHints(); + private: QString getVideoFileName(); - int menuBarHeight() const; LoggerWidget *loggerWindow; QDeclarativeView *canvas; @@ -173,7 +171,6 @@ private: QAction *recordAction; QString currentSkin; bool scaleSkin; - mutable QMenuBar *mb; RecordingDialog *recdlg; void senseImageMagick(); diff --git a/tools/qml/recopts_maemo5.ui b/tools/qml/recopts_maemo5.ui new file mode 100644 index 0000000..3bb5eca --- /dev/null +++ b/tools/qml/recopts_maemo5.ui @@ -0,0 +1,254 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>RecordingOptions</class> + <widget class="QDialog" name="RecordingOptions"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>469</width> + <height>142</height> + </rect> + </property> + <property name="windowTitle"> + <string>Video options</string> + </property> + <layout class="QGridLayout" name="gridLayout" columnstretch="0,2,0"> + <property name="sizeConstraint"> + <enum>QLayout::SetMinAndMaxSize</enum> + </property> + <property name="leftMargin"> + <number>16</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>16</number> + </property> + <property name="bottomMargin"> + <number>8</number> + </property> + <property name="horizontalSpacing"> + <number>16</number> + </property> + <property name="verticalSpacing"> + <number>0</number> + </property> + <item row="0" column="1"> + <widget class="QLineEdit" name="file"/> + </item> + <item row="0" column="2" rowspan="3"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>72</width> + <height>56</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>Size</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QComboBox" name="sizeCombo"> + <item> + <property name="text"> + <string/> + </property> + </item> + <item> + <property name="text"> + <string>VGA</string> + </property> + </item> + <item> + <property name="text"> + <string>QVGA</string> + </property> + </item> + <item> + <property name="text"> + <string>720p</string> + </property> + </item> + </widget> + </item> + <item row="2" column="0" rowspan="2"> + <widget class="QLabel" name="rateLabel"> + <property name="text"> + <string>Rate</string> + </property> + </widget> + </item> + <item row="2" column="1" rowspan="2"> + <widget class="QComboBox" name="rateCombo"> + <item> + <property name="text"> + <string>60 Hz</string> + </property> + </item> + <item> + <property name="text"> + <string>50 Hz</string> + </property> + </item> + <item> + <property name="text"> + <string>25 Hz</string> + </property> + </item> + <item> + <property name="text"> + <string>24 Hz</string> + </property> + </item> + <item> + <property name="text"> + <string>20 Hz</string> + </property> + </item> + <item> + <property name="text"> + <string>15 Hz</string> + </property> + </item> + <item> + <property name="text"> + <string>10 Hz</string> + </property> + </item> + </widget> + </item> + <item row="5" column="1"> + <widget class="QLineEdit" name="args"/> + </item> + <item row="4" column="1"> + <widget class="QComboBox" name="profile"/> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="profileLabel"> + <property name="text"> + <string>Profile</string> + </property> + </widget> + </item> + <item row="6" column="0" colspan="2"> + <widget class="QLabel" name="warning"> + <property name="text"> + <string notr="true">warning</string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="4" column="2" rowspan="3"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QPushButton" name="pickfile"> + <property name="text"> + <string>File</string> + </property> + </widget> + </item> + <item row="5" column="0"> + <widget class="QPushButton" name="ffmpegHelp"> + <property name="text"> + <string>Options</string> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>RecordingOptions</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>258</x> + <y>424</y> + </hint> + <hint type="destinationlabel"> + <x>60</x> + <y>219</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>RecordingOptions</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>258</x> + <y>424</y> + </hint> + <hint type="destinationlabel"> + <x>92</x> + <y>219</y> + </hint> + </hints> + </connection> + <connection> + <sender>profile</sender> + <signal>activated(int)</signal> + <receiver>RecordingOptions</receiver> + <slot>pickProfile(int)</slot> + <hints> + <hint type="sourcelabel"> + <x>92</x> + <y>329</y> + </hint> + <hint type="destinationlabel"> + <x>48</x> + <y>194</y> + </hint> + </hints> + </connection> + <connection> + <sender>args</sender> + <signal>textEdited(QString)</signal> + <receiver>RecordingOptions</receiver> + <slot>storeCustomArgs(QString)</slot> + <hints> + <hint type="sourcelabel"> + <x>128</x> + <y>357</y> + </hint> + <hint type="destinationlabel"> + <x>102</x> + <y>189</y> + </hint> + </hints> + </connection> + </connections> + <slots> + <signal>filePicked(QString)</signal> + <signal>argumentsPicked(QString)</signal> + <slot>pickFile()</slot> + <slot>pickProfile(int)</slot> + <slot>storeCustomArgs(QString)</slot> + </slots> +</ui> diff --git a/tools/qml/texteditautoresizer_maemo5.h b/tools/qml/texteditautoresizer_maemo5.h new file mode 100644 index 0000000..bb5567a --- /dev/null +++ b/tools/qml/texteditautoresizer_maemo5.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 <QtGui/qplaintextedit.h> +#include <QtGui/qtextedit.h> +#include <QtGui/qabstractkineticscroller.h> +#include <QtGui/qscrollarea.h> +#include <QtDebug> + +#ifndef TEXTEDITAUTORESIZER_H +#define TEXTEDITAUTORESIZER_H + +class TextEditAutoResizer : public QObject +{ + Q_OBJECT +public: + TextEditAutoResizer(QWidget *parent) + : QObject(parent), plainTextEdit(qobject_cast<QPlainTextEdit *>(parent)), + textEdit(qobject_cast<QTextEdit *>(parent)), edit(qobject_cast<QFrame *>(parent)) + { + // parent must either inherit QPlainTextEdit or QTextEdit! + Q_ASSERT(plainTextEdit || textEdit); + + connect(parent, SIGNAL(textChanged()), this, SLOT(textEditChanged())); + connect(parent, SIGNAL(cursorPositionChanged()), this, SLOT(textEditChanged())); + + textEditChanged(); + } + +private Q_SLOTS: + inline void textEditChanged(); + +private: + QPlainTextEdit *plainTextEdit; + QTextEdit *textEdit; + QFrame *edit; +}; + +void TextEditAutoResizer::textEditChanged() +{ + QTextDocument *doc = textEdit ? textEdit->document() : plainTextEdit->document(); + QRect cursor = textEdit ? textEdit->cursorRect() : plainTextEdit->cursorRect(); + + QSize s = doc->size().toSize(); + if (plainTextEdit) + s.setHeight((s.height() + 2) * edit->fontMetrics().lineSpacing()); + + const QRect fr = edit->frameRect(); + const QRect cr = edit->contentsRect(); + + edit->setMinimumHeight(qMax(70, s.height() + (fr.height() - cr.height() - 1))); + + // make sure the cursor is visible in case we have a QAbstractScrollArea parent + QPoint pos = edit->pos(); + QWidget *pw = edit->parentWidget(); + while (pw) { + if (qobject_cast<QScrollArea *>(pw)) + break; + pw = pw->parentWidget(); + } + + if (pw) { + QScrollArea *area = static_cast<QScrollArea *>(pw); + QPoint scrollto = area->widget()->mapFrom(edit, cursor.center()); + QPoint margin(10 + cursor.width(), 2 * cursor.height()); + + if (QAbstractKineticScroller *scroller = area->property("kineticScroller").value<QAbstractKineticScroller *>()) { + scroller->ensureVisible(scrollto, margin.x(), margin.y()); + } else { + area->ensureVisible(scrollto.x(), scrollto.y(), margin.x(), margin.y()); + } + } +} + +#endif |