diff options
author | Bea Lam <bea.lam@nokia.com> | 2009-10-06 23:33:22 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2009-10-06 23:33:22 (GMT) |
commit | e0eca3530d566200da46bb5d52abb76fcd98a2f8 (patch) | |
tree | c1ecb90f95a60b9fc5645eb498985d73277b251a /src/declarative | |
parent | 681a278c7108c2bd87be6279694875cdb391e3db (diff) | |
parent | 396a06a52a0f00639c9e528caf80ae2294e80bd2 (diff) | |
download | Qt-e0eca3530d566200da46bb5d52abb76fcd98a2f8.zip Qt-e0eca3530d566200da46bb5d52abb76fcd98a2f8.tar.gz Qt-e0eca3530d566200da46bb5d52abb76fcd98a2f8.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/fx/qfxgridview.cpp | 162 | ||||
-rw-r--r-- | src/declarative/fx/qfxgridview.h | 6 | ||||
-rw-r--r-- | src/declarative/fx/qfxlistview.cpp | 63 | ||||
-rw-r--r-- | src/declarative/fx/qfxlistview.h | 11 | ||||
-rw-r--r-- | src/declarative/fx/qfxpathview.cpp | 2 | ||||
-rw-r--r-- | src/declarative/fx/qfxrepeater.cpp | 24 | ||||
-rw-r--r-- | src/declarative/fx/qfxrepeater.h | 5 | ||||
-rw-r--r-- | src/declarative/fx/qfxvisualitemmodel.cpp | 6 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 42 | ||||
-rw-r--r-- | src/declarative/util/qmllistaccessor.cpp | 2 |
10 files changed, 237 insertions, 86 deletions
diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index 1095dc1..9aa1198 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -593,11 +593,11 @@ void QFxGridViewPrivate::createHighlight() highlight = new FxGridItem(item, q); highlightXAnimator = new QmlEaseFollow(q); highlightXAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("x"))); - highlightXAnimator->setVelocity(400); + highlightXAnimator->setDuration(150); highlightXAnimator->setEnabled(autoHighlight); highlightYAnimator = new QmlEaseFollow(q); highlightYAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("y"))); - highlightYAnimator->setVelocity(400); + highlightYAnimator->setDuration(150); highlightYAnimator->setEnabled(autoHighlight); } else { delete highlightContext; @@ -710,6 +710,8 @@ QFxGridView::~QFxGridView() for the view. For large or dynamic datasets the model is usually provided by a C++ model object. The C++ model object must be a \l {QAbstractItemModel} subclass, a VisualModel, or a simple list. + + \sa {qmlmodels}{Data Models} */ QVariant QFxGridView::model() const { @@ -1064,54 +1066,134 @@ qreal QFxGridView::maxXExtent() const Q_D(const QFxGridView); if (d->flow == QFxGridView::LeftToRight) return QFxFlickable::maxXExtent(); - return -(d->endPosition() - height()); + return -(d->endPosition() - width()); } void QFxGridView::keyPressEvent(QKeyEvent *event) { Q_D(QFxGridView); + QFxFlickable::keyPressEvent(event); + if (event->isAccepted()) + return; + if (d->model && d->model->count() && d->interactive) { - if ((d->flow == QFxGridView::LeftToRight && event->key() == Qt::Key_Up) - || (d->flow == QFxGridView::TopToBottom && event->key() == Qt::Key_Left)) { - if (currentIndex() >= d->columns || d->wrap) { - d->moveReason = QFxGridViewPrivate::Key; - int index = currentIndex() - d->columns; - setCurrentIndex(index >= 0 ? index : d->model->count()-1); - event->accept(); - return; - } - } else if ((d->flow == QFxGridView::LeftToRight && event->key() == Qt::Key_Down) - || (d->flow == QFxGridView::TopToBottom && event->key() == Qt::Key_Right)) { - if (currentIndex() < d->model->count() - d->columns || d->wrap) { - d->moveReason = QFxGridViewPrivate::Key; - int index = currentIndex()+d->columns; - setCurrentIndex(index < d->model->count() ? index : 0); - event->accept(); - return; - } - } else if ((d->flow == QFxGridView::LeftToRight && event->key() == Qt::Key_Left) - || (d->flow == QFxGridView::TopToBottom && event->key() == Qt::Key_Up)) { - if (currentIndex() > 0 || d->wrap) { - d->moveReason = QFxGridViewPrivate::Key; - int index = currentIndex() - 1; - setCurrentIndex(index >= 0 ? index : d->model->count()-1); - event->accept(); - return; - } - } else if ((d->flow == QFxGridView::LeftToRight && event->key() == Qt::Key_Right) - || (d->flow == QFxGridView::TopToBottom && event->key() == Qt::Key_Down)) { - if (currentIndex() < d->model->count() - 1 || d->wrap) { - d->moveReason = QFxGridViewPrivate::Key; - int index = currentIndex() + 1; - setCurrentIndex(index < d->model->count() ? index : 0); - event->accept(); - return; - } + d->moveReason = QFxGridViewPrivate::Key; + int oldCurrent = currentIndex(); + switch (event->key()) { + case Qt::Key_Up: + moveCurrentIndexUp(); + break; + case Qt::Key_Down: + moveCurrentIndexDown(); + break; + case Qt::Key_Left: + moveCurrentIndexLeft(); + break; + case Qt::Key_Right: + moveCurrentIndexRight(); + break; + default: + break; + } + if (oldCurrent != currentIndex()) { + event->accept(); + return; } } d->moveReason = QFxGridViewPrivate::Other; event->ignore(); - QFxFlickable::keyPressEvent(event); +} + +/*! + \qmlmethod GridView::moveCurrentIndexUp + + 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. +*/ +void QFxGridView::moveCurrentIndexUp() +{ + Q_D(QFxGridView); + if (d->flow == QFxGridView::LeftToRight) { + if (currentIndex() >= d->columns || d->wrap) { + int index = currentIndex() - d->columns; + setCurrentIndex(index >= 0 ? index : d->model->count()-1); + } + } else { + if (currentIndex() > 0 || d->wrap) { + int index = currentIndex() - 1; + setCurrentIndex(index >= 0 ? index : d->model->count()-1); + } + } +} + +/*! + \qmlmethod GridView::moveCurrentIndexDown + + 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. +*/ +void QFxGridView::moveCurrentIndexDown() +{ + Q_D(QFxGridView); + if (d->flow == QFxGridView::LeftToRight) { + if (currentIndex() < d->model->count() - d->columns || d->wrap) { + int index = currentIndex()+d->columns; + setCurrentIndex(index < d->model->count() ? index : 0); + } + } else { + if (currentIndex() < d->model->count() - 1 || d->wrap) { + int index = currentIndex() + 1; + setCurrentIndex(index < d->model->count() ? index : 0); + } + } +} + +/*! + \qmlmethod GridView::moveCurrentIndexLeft + + 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. +*/ +void QFxGridView::moveCurrentIndexLeft() +{ + Q_D(QFxGridView); + if (d->flow == QFxGridView::LeftToRight) { + if (currentIndex() > 0 || d->wrap) { + int index = currentIndex() - 1; + setCurrentIndex(index >= 0 ? index : d->model->count()-1); + } + } else { + if (currentIndex() >= d->columns || d->wrap) { + int index = currentIndex() - d->columns; + setCurrentIndex(index >= 0 ? index : d->model->count()-1); + } + } +} + +/*! + \qmlmethod GridView::moveCurrentIndexRight + + 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. +*/ +void QFxGridView::moveCurrentIndexRight() +{ + Q_D(QFxGridView); + if (d->flow == QFxGridView::LeftToRight) { + if (currentIndex() < d->model->count() - 1 || d->wrap) { + int index = currentIndex() + 1; + setCurrentIndex(index < d->model->count() ? index : 0); + } + } else { + if (currentIndex() < d->model->count() - d->columns || d->wrap) { + int index = currentIndex()+d->columns; + setCurrentIndex(index < d->model->count() ? index : 0); + } + } } void QFxGridView::componentComplete() diff --git a/src/declarative/fx/qfxgridview.h b/src/declarative/fx/qfxgridview.h index 996141f..08a7565 100644 --- a/src/declarative/fx/qfxgridview.h +++ b/src/declarative/fx/qfxgridview.h @@ -112,6 +112,12 @@ public: static QFxGridViewAttached *qmlAttachedProperties(QObject *); +public Q_SLOTS: + void moveCurrentIndexUp(); + void moveCurrentIndexDown(); + void moveCurrentIndexLeft(); + void moveCurrentIndexRight(); + Q_SIGNALS: void countChanged(); void currentIndexChanged(); diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 3584892..1247021 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -178,6 +178,7 @@ public: , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0.0) , ownModel(false), wrap(false), autoHighlight(true) , haveHighlightRange(false), strictHighlightRange(false) + , highlightMoveSpeed(400), highlightResizeSpeed(400) {} void init(); @@ -390,6 +391,8 @@ public: QString sectionExpression; QString currentSection; qreal spacing; + qreal highlightMoveSpeed; + qreal highlightResizeSpeed; bool ownModel : 1; bool wrap : 1; @@ -667,11 +670,11 @@ void QFxListViewPrivate::createHighlight() const QLatin1String posProp(orient == Qt::Vertical ? "y" : "x"); highlightPosAnimator = new QmlEaseFollow(q); highlightPosAnimator->setTarget(QmlMetaProperty(highlight->item, posProp)); - highlightPosAnimator->setVelocity(400); + highlightPosAnimator->setVelocity(highlightMoveSpeed); highlightPosAnimator->setEnabled(autoHighlight); const QLatin1String sizeProp(orient == Qt::Vertical ? "height" : "width"); highlightSizeAnimator = new QmlEaseFollow(q); - highlightSizeAnimator->setVelocity(400); + highlightSizeAnimator->setVelocity(highlightResizeSpeed); highlightSizeAnimator->setTarget(QmlMetaProperty(highlight->item, sizeProp)); highlightSizeAnimator->setEnabled(autoHighlight); } @@ -876,6 +879,8 @@ QFxListView::~QFxListView() Models can also be created directly in QML, using a \l{ListModel}, \l{XmlListModel} or \l{VisualItemModel}. + + \sa {qmlmodels}{Data Models} */ QVariant QFxListView::model() const { @@ -1257,6 +1262,48 @@ QString QFxListView::currentSection() const return d->currentSection; } +/*! + \qmlproperty real ListView::highlightMoveSpeed + + This property holds the moving animation speed of the highlight delegate. +*/ +qreal QFxListView::highlightMoveSpeed() const +{ + Q_D(const QFxListView);\ + return d->highlightMoveSpeed; +} + +void QFxListView::setHighlightMoveSpeed(qreal speed) +{ + Q_D(QFxListView);\ + if (d->highlightMoveSpeed != speed) + { + d->highlightMoveSpeed = speed; + emit highlightMoveSpeedChanged(); + } +} + +/*! + \qmlproperty real ListView::highlightResizeSpeed + + This property holds the resizing animation speed of the highlight delegate. +*/ +qreal QFxListView::highlightResizeSpeed() const +{ + Q_D(const QFxListView);\ + return d->highlightResizeSpeed; +} + +void QFxListView::setHighlightResizeSpeed(qreal speed) +{ + Q_D(QFxListView);\ + if (d->highlightResizeSpeed != speed) + { + d->highlightResizeSpeed = speed; + emit highlightResizeSpeedChanged(); + } +} + void QFxListView::viewportMoved() { Q_D(QFxListView); @@ -1372,6 +1419,12 @@ void QFxListView::keyPressEvent(QKeyEvent *event) event->ignore(); } +/*! + \qmlmethod ListView::incrementCurrentIndex + + Increments the current index. The current index will wrap + if keyNavigationWraps is true and it is currently at the end. +*/ void QFxListView::incrementCurrentIndex() { Q_D(QFxListView); @@ -1381,6 +1434,12 @@ void QFxListView::incrementCurrentIndex() } } +/*! + \qmlmethod ListView::decrementCurrentIndex + + Decrements the current index. The current index will wrap + if keyNavigationWraps is true and it is currently at the beginning. +*/ void QFxListView::decrementCurrentIndex() { Q_D(QFxListView); diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index fc15967..3cff422 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -77,6 +77,9 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) Q_PROPERTY(QString sectionExpression READ sectionExpression WRITE setSectionExpression NOTIFY sectionExpressionChanged) Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged) + + Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged) + Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged) Q_CLASSINFO("DefaultProperty", "data") public: @@ -126,6 +129,12 @@ public: void setSectionExpression(const QString &); QString currentSection() const; + qreal highlightMoveSpeed() const; + void setHighlightMoveSpeed(qreal); + + qreal highlightResizeSpeed() const; + void setHighlightResizeSpeed(qreal); + static QFxListViewAttached *qmlAttachedProperties(QObject *); public Q_SLOTS: @@ -138,6 +147,8 @@ Q_SIGNALS: void currentIndexChanged(); void currentSectionChanged(); void sectionExpressionChanged(); + void highlightMoveSpeedChanged(); + void highlightResizeSpeedChanged(); protected: virtual void viewportMoved(); diff --git a/src/declarative/fx/qfxpathview.cpp b/src/declarative/fx/qfxpathview.cpp index 86bc9a2..b127f39 100644 --- a/src/declarative/fx/qfxpathview.cpp +++ b/src/declarative/fx/qfxpathview.cpp @@ -140,6 +140,8 @@ QFxPathView::~QFxPathView() The model provides a set of data that is used to create the items for the view. For large or dynamic datasets the model is usually provided by a C++ model object. Models can also be created directly in XML, using the ListModel element. + + \sa {qmlmodels}{Data Models} */ QVariant QFxPathView::model() const { diff --git a/src/declarative/fx/qfxrepeater.cpp b/src/declarative/fx/qfxrepeater.cpp index bc34839..182dcc7 100644 --- a/src/declarative/fx/qfxrepeater.cpp +++ b/src/declarative/fx/qfxrepeater.cpp @@ -143,6 +143,8 @@ QFxRepeater::~QFxRepeater() based on the order they are created. Models can also be created directly in QML, using a \l{ListModel} or \l{XmlListModel}. + + \sa {qmlmodels}{Data Models} */ QVariant QFxRepeater::model() const { @@ -154,15 +156,15 @@ void QFxRepeater::setModel(const QVariant &model) { Q_D(QFxRepeater); clear(); - /* if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); disconnect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); + /* disconnect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*))); disconnect(d->model, SIGNAL(destroyingItem(QFxItem*)), this, SLOT(destroyingItem(QFxItem*))); - } */ + } d->dataSource = model; QObject *object = qvariant_cast<QObject*>(model); QFxVisualModel *vim = 0; @@ -181,10 +183,10 @@ void QFxRepeater::setModel(const QVariant &model) dataModel->setModel(model); } if (d->model) { - /* connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); + /* connect(d->model, SIGNAL(createdItem(int, QFxItem*)), this, SLOT(createdItem(int,QFxItem*))); connect(d->model, SIGNAL(destroyingItem(QFxItem*)), this, SLOT(destroyingItem(QFxItem*))); */ @@ -291,4 +293,20 @@ void QFxRepeater::regenerate() } } } + +void QFxRepeater::itemsInserted(int, int) +{ + regenerate(); +} + +void QFxRepeater::itemsRemoved(int, int) +{ + regenerate(); +} + +void QFxRepeater::itemsMoved(int,int,int) +{ + regenerate(); +} + QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxrepeater.h b/src/declarative/fx/qfxrepeater.h index 7d64d86..7a0318b 100644 --- a/src/declarative/fx/qfxrepeater.h +++ b/src/declarative/fx/qfxrepeater.h @@ -84,6 +84,11 @@ protected: QVariant itemChange(GraphicsItemChange change, const QVariant &value); QFxRepeater(QFxRepeaterPrivate &dd, QFxItem *parent); +private Q_SLOTS: + void itemsInserted(int,int); + void itemsRemoved(int,int); + void itemsMoved(int,int,int); + private: Q_DISABLE_COPY(QFxRepeater) Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxRepeater) diff --git a/src/declarative/fx/qfxvisualitemmodel.cpp b/src/declarative/fx/qfxvisualitemmodel.cpp index 45166de..fb1cfcf 100644 --- a/src/declarative/fx/qfxvisualitemmodel.cpp +++ b/src/declarative/fx/qfxvisualitemmodel.cpp @@ -132,7 +132,11 @@ public: \brief The VisualItemModel allows items to be provided to a view. The children of the VisualItemModel are provided in a model which - can be used in a view. An item can determine its index within the + can be used in a view. Note that no delegate should be + provided to a view since the VisualItemModel contains the + visual delegate (items). + + An item can determine its index within the model via the VisualItemModel.index attached property. The example below places three colored rectangles in a ListView. diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 72603ed..f34d790 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -114,43 +114,9 @@ QScriptValue desktopOpenUrl(QScriptContext *ctxt, QScriptEngine *e) return e->newVariant(QVariant(ret)); } -// XXX Something like this should be exported by Qt. static QString userLocalDataPath(const QString& app) { - QString result; - -#ifdef Q_OS_WIN -#ifndef Q_OS_WINCE - QLibrary library(QLatin1String("shell32")); -#else - QLibrary library(QLatin1String("coredll")); -#endif // Q_OS_WINCE - typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPWSTR, int, BOOL); - GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW"); - if (SHGetSpecialFolderPath) { - wchar_t path[MAX_PATH]; - SHGetSpecialFolderPath(0, path, CSIDL_APPDATA, FALSE); - result = QString::fromWCharArray(path); - } -#endif // Q_OS_WIN - -#ifdef Q_OS_MAC - result = QLatin1String(qgetenv("HOME")); - result += "/Library/Application Support"; -#else - if (result.isEmpty()) { - // Fallback: UNIX style - result = QLatin1String(qgetenv("XDG_DATA_HOME")); - if (result.isEmpty()) { - result = QLatin1String(qgetenv("HOME")); - result += QLatin1String("/.local/share"); - } - } -#endif - - result += QLatin1Char('/'); - result += app; - return result; + return QDesktopServices::storageLocation(QDesktopServices::DataLocation) + QLatin1String("/") + app; } QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) @@ -166,7 +132,7 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) qtObject.setProperty(QLatin1String("DesktopServices"), desktopObject); scriptEngine.globalObject().setProperty(QLatin1String("Qt"), qtObject); - offlineStoragePath = userLocalDataPath(QLatin1String("Nokia/Qt/QML/OfflineStorage")); + offlineStoragePath = userLocalDataPath(QLatin1String("QML/OfflineStorage")); qt_add_qmlxmlhttprequest(&scriptEngine); qt_add_qmlsqldatabase(&scriptEngine); @@ -1602,7 +1568,7 @@ public: if (s->find(unqualifiedtype,vmajor,vminor,type_return,url_return)) return true; if (s->urls.count() == 1 && !s->isBuiltin[0] && !s->isLibrary[0] && url_return) { - *url_return = QUrl(s->urls[0]+"/").resolved(QUrl(QLatin1String(unqualifiedtype + ".qml"))); + *url_return = QUrl(s->urls[0]+QLatin1String("/")).resolved(QUrl(QLatin1String(unqualifiedtype + ".qml"))); return true; } } @@ -1697,7 +1663,7 @@ void QmlEngine::addImportPath(const QString& path) QFxWebView and the SQL databases created with openDatabase() are stored here. - The default is Nokia/Qt/QML/Databases/ in the platform-standard + The default is QML/OfflineStorage/ in the platform-standard user application data directory. */ void QmlEngine::setOfflineStoragePath(const QString& dir) diff --git a/src/declarative/util/qmllistaccessor.cpp b/src/declarative/util/qmllistaccessor.cpp index ef21ebf..578646b 100644 --- a/src/declarative/util/qmllistaccessor.cpp +++ b/src/declarative/util/qmllistaccessor.cpp @@ -76,7 +76,6 @@ void QmlListAccessor::setList(const QVariant &v, QmlEngine *engine) } else if (d.type() == QMetaType::QVariantList) { m_type = VariantList; } else if (d.canConvert(QVariant::Int)) { - qDebug() << "integer"; m_type = Integer; } else if (d.type() != QVariant::UserType) { m_type = Instance; @@ -90,7 +89,6 @@ void QmlListAccessor::setList(const QVariant &v, QmlEngine *engine) (enginePrivate && enginePrivate->isQmlList(d.userType()))) { m_type = QmlList; } else if (QmlMetaType::isList(d.userType())) { - qDebug() << "list"; m_type = QList; } else { m_type = Invalid; |