From 6cfefeac5db91186027fc203cf9f8f354a0eedac Mon Sep 17 00:00:00 2001 From: Ian Walters Date: Fri, 8 May 2009 10:43:56 +1000 Subject: Don't assume will get non-0 item to send key to. Before this change was getting crashes when the window lost focus. This is because the target was non-0, but the focusItem stored for that target was 0. --- src/declarative/fx/qfxkeyproxy.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/declarative/fx/qfxkeyproxy.cpp b/src/declarative/fx/qfxkeyproxy.cpp index 1bb54ec..848b2d9 100644 --- a/src/declarative/fx/qfxkeyproxy.cpp +++ b/src/declarative/fx/qfxkeyproxy.cpp @@ -94,9 +94,9 @@ QList *QFxKeyProxy::targets() const void QFxKeyProxy::keyPressEvent(QKeyEvent *e) { for (int ii = 0; ii < d->targets.count(); ++ii) { - QSimpleCanvasItem *i = d->targets.at(ii); + QSimpleCanvasItem *i = canvas()->focusItem(d->targets.at(ii)); if (i) - canvas()->focusItem(i)->keyPressEvent(e); + i->keyPressEvent(e); if (e->isAccepted()) return; } @@ -105,9 +105,9 @@ void QFxKeyProxy::keyPressEvent(QKeyEvent *e) void QFxKeyProxy::keyReleaseEvent(QKeyEvent *e) { for (int ii = 0; ii < d->targets.count(); ++ii) { - QSimpleCanvasItem *i = d->targets.at(ii); + QSimpleCanvasItem *i = canvas()->focusItem(d->targets.at(ii)); if (i) - canvas()->focusItem(i)->keyReleaseEvent(e); + i->keyReleaseEvent(e); if (e->isAccepted()) return; } -- cgit v0.12 From bbf6d8ecaa896881f111be731a0718a124b6d21b Mon Sep 17 00:00:00 2001 From: Ian Walters Date: Fri, 8 May 2009 10:45:30 +1000 Subject: Add the ability to remove whole contacts. --- demos/declarative/contacts/Contact.qml | 69 ++++++++++++++++++----------- demos/declarative/contacts/ContactField.qml | 2 +- demos/declarative/contacts/RemoveButton.qml | 6 +++ demos/declarative/contacts/contacts.qml | 22 ++++++++- 4 files changed, 70 insertions(+), 29 deletions(-) diff --git a/demos/declarative/contacts/Contact.qml b/demos/declarative/contacts/Contact.qml index 7297fa6..50c9d1c 100644 --- a/demos/declarative/contacts/Contact.qml +++ b/demos/declarative/contacts/Contact.qml @@ -16,41 +16,53 @@ Item { id: updateContactQuery connection: contactDatabase query: "UPDATE contacts SET label = :l, email = :e, phone = :p WHERE recid = :r" - bindings: SqlBind { - name: ":r" - value: contactId - } - bindings: SqlBind { - name: ":l" - value: labelField.value - } - bindings: SqlBind { - name: ":e" - value: emailField.value - } - bindings: SqlBind { - name: ":p" - value: phoneField.value - } + bindings: [ + SqlBind { + name: ":r" + value: contactId + }, + SqlBind { + name: ":l" + value: labelField.value + }, + SqlBind { + name: ":e" + value: emailField.value + }, + SqlBind { + name: ":p" + value: phoneField.value + } + ] }, SqlQuery { id: insertContactQuery connection: contactDatabase query: "INSERT INTO contacts (label, email, phone) VALUES(:l, :e, :p)" + bindings: [ + SqlBind { + name: ":l" + value: labelField.value + }, + SqlBind { + name: ":e" + value: emailField.value + }, + SqlBind { + name: ":p" + value: phoneField.value + } + ] + }, + SqlQuery { + id: removeContactQuery + connection: contactDatabase + query: "DELETE FROM contacts WHERE recid = :r" bindings: SqlBind { - name: ":l" - value: labelField.value - } - bindings: SqlBind { - name: ":e" - value: emailField.value - } - bindings: SqlBind { - name: ":p" - value: phoneField.value + name: ":r" + value: contactId } } - ] function refresh() { labelField.value = label; @@ -63,6 +75,9 @@ Item { function insert() { insertContactQuery.exec(); } + function remove() { + removeContactQuery.exec(); + } VerticalLayout { id: layout anchors.fill: parent diff --git a/demos/declarative/contacts/ContactField.qml b/demos/declarative/contacts/ContactField.qml index cb319ae..003e723 100644 --- a/demos/declarative/contacts/ContactField.qml +++ b/demos/declarative/contacts/ContactField.qml @@ -3,7 +3,7 @@ Item { clip: true height: 30 property var label: "Name" - property var icon: "pics/phone.png" + property var icon: "" property var value: "" onValueChanged: { fieldText.text = contactField.value } RemoveButton { diff --git a/demos/declarative/contacts/RemoveButton.qml b/demos/declarative/contacts/RemoveButton.qml index 114db2e..59e3fcb 100644 --- a/demos/declarative/contacts/RemoveButton.qml +++ b/demos/declarative/contacts/RemoveButton.qml @@ -76,6 +76,12 @@ Rect { text: "Remove" opacity: 0 } + opacity: Behaviour { + NumericAnimation { + property: "opacity" + duration: 250 + } + } states: [ State { name: "opened" diff --git a/demos/declarative/contacts/contacts.qml b/demos/declarative/contacts/contacts.qml index 4582bd1..b38e02e 100644 --- a/demos/declarative/contacts/contacts.qml +++ b/demos/declarative/contacts/contacts.qml @@ -127,13 +127,26 @@ Rect { sender: cancelEditButton signal: "clicked()" script: { - if (wrapper.state == 'opened' && !contacts.mouseGrabbed) { + if (wrapper.state == 'opened' && !contacts.mouseGrabbed) { wrapper.state = ''; contacts.mode = 'list'; } } } + Connection { + sender: removeContactButton + signal: "confirmed()" + script: { + if (wrapper.state == 'opened' && !contacts.mouseGrabbed) { + Details.qmlItem.remove(); + wrapper.state = ''; + contacts.mode = 'list'; + contactList.exec(); + } + + } + } } } ] @@ -165,6 +178,13 @@ Rect { icon: "pics/cancel.png" opacity: contacts.mode == 'list' || contacts.mouseGrabbed ? 0 : 1 } + RemoveButton { + id: removeContactButton + anchors.top: parent.top + anchors.topMargin: 5 + anchors.horizontalCenter: parent.horizontalCenter + opacity: (contacts.mode == 'edit' && (!contacts.mouseGrabbed || removeContactButton.state =='opened')) ? 1 : 0 + } ListView { id: contactListView anchors.left: parent.left -- cgit v0.12 From cce83e2985bbdfe33d04162c3e20243e10ece46a Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 8 May 2009 12:06:19 +1000 Subject: setWidth() and setHeight() lost their virtual at some point :-/ --- src/declarative/fx/qfxflickable.cpp | 12 ++++++------ src/declarative/fx/qfxflickable.h | 4 ++-- src/declarative/fx/qfxgridview.cpp | 21 +++------------------ src/declarative/fx/qfxgridview.h | 4 +--- src/declarative/fx/qfxlistview.cpp | 24 ++---------------------- src/declarative/fx/qfxlistview.h | 7 +------ 6 files changed, 15 insertions(+), 57 deletions(-) diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index 52b142b..890bb31 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -116,6 +116,8 @@ void QFxFlickablePrivate::init() QObject::connect(_flick, SIGNAL(topChanged()), q, SIGNAL(positionChanged())); QObject::connect(&elasticX, SIGNAL(updated()), q, SLOT(ticked())); QObject::connect(&elasticY, SIGNAL(updated()), q, SLOT(ticked())); + QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(heightChange())); + QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(widthChange())); } void QFxFlickablePrivate::fixupX() @@ -914,23 +916,21 @@ void QFxFlickable::setViewportWidth(int w) d->updateBeginningEnd(); } -void QFxFlickable::setWidth(int w) +void QFxFlickable::widthChange() { Q_D(QFxFlickable); - QFxItem::setWidth(w); if (d->vWidth < 0) { - d->_flick->setWidth(w); + d->_flick->setWidth(width()); emit viewportWidthChanged(); d->updateBeginningEnd(); } } -void QFxFlickable::setHeight(int h) +void QFxFlickable::heightChange() { Q_D(QFxFlickable); - QFxItem::setHeight(h); if (d->vHeight < 0) { - d->_flick->setHeight(h); + d->_flick->setHeight(height()); emit viewportHeightChanged(); d->updateBeginningEnd(); } diff --git a/src/declarative/fx/qfxflickable.h b/src/declarative/fx/qfxflickable.h index 1281788..c5a0593 100644 --- a/src/declarative/fx/qfxflickable.h +++ b/src/declarative/fx/qfxflickable.h @@ -133,8 +133,6 @@ public: qreal pageYPosition() const; qreal pageHeight() const; - virtual void setWidth(int); - virtual void setHeight(int); QFxItem *viewport(); Q_SIGNALS: @@ -165,6 +163,8 @@ protected Q_SLOTS: virtual void ticked(); void movementStarting(); void movementEnding(); + void heightChange(); + void widthChange(); protected: virtual qreal minXExtent() const; diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index acfb57e..9e6f2c9 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -319,6 +319,8 @@ void QFxGridViewPrivate::init() { Q_Q(QFxGridView); q->setOptions(QFxGridView::IsFocusRealm); + QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(sizeChange())); + QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(sizeChange())); } void QFxGridViewPrivate::clear() @@ -996,26 +998,9 @@ void QFxGridView::setCellHeight(int cellHeight) } } -/*! - \reimp -*/ -void QFxGridView::setHeight(int height) -{ - Q_D(QFxGridView); - QFxFlickable::setHeight(height); - if (isComponentComplete()) { - d->updateGrid(); - d->layout(); - } -} - -/*! - \reimp -*/ -void QFxGridView::setWidth(int width) +void QFxGridView::sizeChange() { Q_D(QFxGridView); - QFxFlickable::setWidth(width); if (isComponentComplete()) { d->updateGrid(); d->layout(); diff --git a/src/declarative/fx/qfxgridview.h b/src/declarative/fx/qfxgridview.h index c612804..2bbfc40 100644 --- a/src/declarative/fx/qfxgridview.h +++ b/src/declarative/fx/qfxgridview.h @@ -109,9 +109,6 @@ public: int cellHeight() const; void setCellHeight(int); - virtual void setHeight(int height); - virtual void setWidth(int width); - static QObject *qmlAttachedProperties(QObject *); Q_SIGNALS: @@ -134,6 +131,7 @@ private Q_SLOTS: void itemsInserted(int index, int count); void itemsRemoved(int index, int count); void destroyRemoved(); + void sizeChange(); private: void refill(); diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index b256c4a..ad752a7 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -356,6 +356,8 @@ void QFxListViewPrivate::init() { Q_Q(QFxListView); q->setOptions(QFxListView::IsFocusRealm); + QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(refill())); + QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(refill())); } void QFxListViewPrivate::clear() @@ -1190,28 +1192,6 @@ QString QFxListView::currentSection() const return d->currentSection; } -/*! - \reimp -*/ -void QFxListView::setHeight(int height) -{ - Q_D(QFxListView); - QFxFlickable::setHeight(height); - if (d->orient == Qt::Vertical && isComponentComplete()) - refill(); -} - -/*! - \reimp -*/ -void QFxListView::setWidth(int width) -{ - Q_D(QFxListView); - QFxFlickable::setWidth(width); - if (d->orient == Qt::Horizontal && isComponentComplete()) - refill(); -} - void QFxListView::viewportMoved() { Q_D(QFxListView); diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index f15db0c..40c2496 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -116,9 +116,6 @@ public: void setSectionExpression(const QString &); QString currentSection() const; - virtual void setHeight(int height); - virtual void setWidth(int width); - static QObject *qmlAttachedProperties(QObject *); Q_SIGNALS: @@ -137,10 +134,8 @@ protected: virtual void keyReleaseEvent(QKeyEvent *); virtual void componentComplete(); -private: - void refill(); - private Q_SLOTS: + void refill(); void trackedPositionChanged(); void itemResized(); void itemsInserted(int index, int count); -- cgit v0.12 From 242410e288280b9bcf8f3b68fa362be44e4c8813 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 8 May 2009 12:22:17 +1000 Subject: Tweak debugger watches --- src/declarative/debugger/debugger.pri | 6 +- src/declarative/debugger/qmldebugger.cpp | 84 ++------- src/declarative/debugger/qmldebugger.h | 8 +- src/declarative/debugger/qmlpropertyview.cpp | 97 +++++++++- src/declarative/debugger/qmlpropertyview_p.h | 6 +- src/declarative/debugger/qmlwatches.cpp | 267 +++++++++++++++++++++++++++ src/declarative/debugger/qmlwatches_p.h | 99 ++++++++++ src/declarative/qml/qmlengine.cpp | 11 ++ src/declarative/qml/qmlexpression.h | 1 + 9 files changed, 499 insertions(+), 80 deletions(-) create mode 100644 src/declarative/debugger/qmlwatches.cpp create mode 100644 src/declarative/debugger/qmlwatches_p.h diff --git a/src/declarative/debugger/debugger.pri b/src/declarative/debugger/debugger.pri index 31a1d5b..bf693d9 100644 --- a/src/declarative/debugger/debugger.pri +++ b/src/declarative/debugger/debugger.pri @@ -1,7 +1,9 @@ SOURCES += debugger/qmldebugger.cpp \ debugger/qmldebuggerstatus.cpp \ - debugger/qmlpropertyview.cpp + debugger/qmlpropertyview.cpp \ + debugger/qmlwatches.cpp HEADERS += debugger/qmldebugger.h \ debugger/qmldebuggerstatus.h \ - debugger/qmlpropertyview_p.h + debugger/qmlpropertyview_p.h \ + debugger/qmlwatches_p.h diff --git a/src/declarative/debugger/qmldebugger.cpp b/src/declarative/debugger/qmldebugger.cpp index 634385b..250f451 100644 --- a/src/declarative/debugger/qmldebugger.cpp +++ b/src/declarative/debugger/qmldebugger.cpp @@ -58,10 +58,11 @@ #include #include #include +#include QmlDebugger::QmlDebugger(QWidget *parent) -: QWidget(parent), m_tree(0), m_warnings(0), m_watchers(0), m_properties(0), - m_text(0) +: QWidget(parent), m_tree(0), m_warnings(0), m_watchTable(0), m_watches(0), + m_properties(0), m_text(0) { QHBoxLayout *layout = new QHBoxLayout; setLayout(layout); @@ -75,7 +76,6 @@ QmlDebugger::QmlDebugger(QWidget *parent) splitter->addWidget(treeWid); m_tree = new QTreeWidget(treeWid); - m_tree->setSelectionMode(QTreeWidget::NoSelection); m_tree->setHeaderHidden(true); QObject::connect(m_tree, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(itemClicked(QTreeWidgetItem *))); QObject::connect(m_tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem *))); @@ -95,11 +95,13 @@ QmlDebugger::QmlDebugger(QWidget *parent) m_warnings->setHeaderHidden(true); tabs->addTab(m_warnings, "Warnings"); - m_watchers = new QTableWidget(this); - m_watchers->setSelectionMode(QTableWidget::NoSelection); - tabs->addTab(m_watchers, "Watchers"); + m_watches = new QmlWatches(this); + m_watchTable = new QTableView(this); + m_watchTable->setSelectionMode(QTableWidget::NoSelection); + m_watchTable->setModel(m_watches); + tabs->addTab(m_watchTable, "Watches"); - m_properties = new QmlPropertyView(this); + m_properties = new QmlPropertyView(m_watches, this); tabs->addTab(m_properties, "Properties"); splitter->addWidget(tabs); @@ -131,21 +133,6 @@ public: void QmlDebugger::itemDoubleClicked(QTreeWidgetItem *i) { - QmlDebuggerItem *item = static_cast(i); - - if(item->bindableValue) { - - QmlExpressionPrivate *p = item->bindableValue->d; - - if(m_watchedIds.contains(p->id)) { - m_watchedIds.remove(p->id); - item->setForeground(0, Qt::green); - } else { - m_watchedIds.insert(p->id); - item->setForeground(0, QColor("purple")); - } - - } } void QmlDebugger::itemClicked(QTreeWidgetItem *i) @@ -227,36 +214,16 @@ bool QmlDebugger::makeItem(QObject *obj, QmlDebuggerItem *item) QmlExpressionPrivate *p = bv->d; text = bv->property().name() + ": " + bv->expression(); - bool watched = m_watchedIds.contains(p->id); - if(watched) - item->setForeground(0, QColor("purple")); - else - item->setForeground(0, Qt::green); + item->setForeground(0, Qt::green); item->bindableValue = bv; if(p->log) { QTreeWidgetItem *warningItem = 0; - int column = m_watchers->columnCount(); - - if(watched) { - m_watchers->insertColumn(column); - QTableWidgetItem *tableheader = new QTableWidgetItem; - tableheader->setText(bv->expression()); - tableheader->setToolTip(bv->expression()); - m_watchers->setHorizontalHeaderItem(column, tableheader); - } - for(int ii = 0; ii < p->log->count(); ++ii) { const QmlExpressionLog &log = p->log->at(ii); QString variant; QDebug d(&variant); d << log.result(); - if(watched) { - QString str = log.result().toString(); - if(str.isEmpty()) - str = variant; - m_expressions << qMakePair(log.time(), qMakePair(column, str)); - } if(!log.warnings().isEmpty()) { @@ -280,14 +247,12 @@ bool QmlDebugger::makeItem(QObject *obj, QmlDebuggerItem *item) } + delete item; + return false; + } else if(QmlBoundSignal *bs = qobject_cast(obj)) { - QMetaMethod method = obj->parent()->metaObject()->method(bs->index()); - QByteArray sig = method.signature(); - if(!sig.isEmpty()) - text = sig + ": "; - text += bs->expression(); - item->setForeground(0, Qt::blue); - rv = false; + delete item; + return false; } else { QmlContext *context = qmlContext(obj); QmlContext *parentContext = qmlContext(obj->parent()); @@ -359,10 +324,6 @@ void QmlDebugger::setDebugObject(QObject *obj) { m_tree->clear(); m_warnings->clear(); - m_watchers->clear(); - m_watchers->setColumnCount(0); - m_watchers->setRowCount(0); - m_expressions.clear(); m_object = obj; if(!obj) @@ -372,20 +333,5 @@ void QmlDebugger::setDebugObject(QObject *obj) makeItem(obj, item); buildTree(obj, item); item->setExpanded(true); - - m_watchers->setRowCount(m_expressions.count()); - - qSort(m_expressions.begin(), m_expressions.end()); - - for(int ii = 0; ii < m_expressions.count(); ++ii) { - - const QPair > &expr = m_expressions.at(ii); - QTableWidgetItem *item = new QTableWidgetItem; - item->setText(expr.second.second); - m_watchers->setItem(ii, expr.second.first, item); - - } - - } diff --git a/src/declarative/debugger/qmldebugger.h b/src/declarative/debugger/qmldebugger.h index 35ff92c..776ded3 100644 --- a/src/declarative/debugger/qmldebugger.h +++ b/src/declarative/debugger/qmldebugger.h @@ -56,8 +56,9 @@ class QTreeWidget; class QTreeWidgetItem; class QPlainTextEdit; class QmlDebuggerItem; -class QTableWidget; +class QTableView; class QmlPropertyView; +class QmlWatches; class QmlDebugger : public QWidget { Q_OBJECT @@ -78,12 +79,11 @@ private: bool makeItem(QObject *obj, QmlDebuggerItem *item); QTreeWidget *m_tree; QTreeWidget *m_warnings; - QTableWidget *m_watchers; + QTableView *m_watchTable; + QmlWatches *m_watches; QmlPropertyView *m_properties; QPlainTextEdit *m_text; QPointer m_object; - QList > > m_expressions; - QSet m_watchedIds; QPointer m_selectedItem; }; diff --git a/src/declarative/debugger/qmlpropertyview.cpp b/src/declarative/debugger/qmlpropertyview.cpp index 2434c58..b46a1bf 100644 --- a/src/declarative/debugger/qmlpropertyview.cpp +++ b/src/declarative/debugger/qmlpropertyview.cpp @@ -43,9 +43,12 @@ #include #include #include +#include +#include +#include -QmlPropertyView::QmlPropertyView(QWidget *parent) -: QWidget(parent), m_tree(0) +QmlPropertyView::QmlPropertyView(QmlWatches *watches, QWidget *parent) +: QWidget(parent), m_tree(0), m_watches(watches) { QVBoxLayout *layout = new QVBoxLayout; layout->setContentsMargins(0, 0, 0, 0); @@ -54,6 +57,8 @@ QmlPropertyView::QmlPropertyView(QWidget *parent) m_tree = new QTreeWidget(this); m_tree->setHeaderLabels(QStringList() << "Property" << "Value"); + QObject::connect(m_tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), + this, SLOT(itemDoubleClicked(QTreeWidgetItem *))); m_tree->setColumnCount(2); @@ -65,16 +70,24 @@ class QmlPropertyViewItem : public QObject, public QTreeWidgetItem Q_OBJECT public: QmlPropertyViewItem(QTreeWidget *widget); + QmlPropertyViewItem(QTreeWidgetItem *parent); QObject *object; QMetaProperty property; + quint32 exprId; + public slots: void refresh(); }; QmlPropertyViewItem::QmlPropertyViewItem(QTreeWidget *widget) -: QTreeWidgetItem(widget) +: QTreeWidgetItem(widget), object(0), exprId(0) +{ +} + +QmlPropertyViewItem::QmlPropertyViewItem(QTreeWidgetItem *parent) +: QTreeWidgetItem(parent), object(0), exprId(0) { } @@ -83,6 +96,33 @@ void QmlPropertyViewItem::refresh() setText(1, property.read(object).toString()); } +void QmlPropertyView::itemDoubleClicked(QTreeWidgetItem *i) +{ + QmlPropertyViewItem *item = static_cast(i); + + if(item->object) { + quint32 objectId = m_watches->objectId(item->object); + + if(m_watches->hasWatch(objectId, item->property.name())) { + m_watches->remWatch(objectId, item->property.name()); + item->setForeground(0, Qt::black); + } else { + m_watches->addWatch(objectId, item->property.name()); + item->setForeground(0, Qt::red); + } + } else if(item->exprId) { + + if(m_watches->hasWatch(item->exprId)) { + m_watches->remWatch(item->exprId); + item->setForeground(1, Qt::green); + } else { + m_watches->addWatch(item->exprId); + item->setForeground(1, Qt::darkGreen); + } + + } +} + void QmlPropertyView::setObject(QObject *object) { m_object = object; @@ -91,15 +131,38 @@ void QmlPropertyView::setObject(QObject *object) if(!m_object) return; + QMultiHash > bindings; + QHash sigs; + QObjectList children = object->children(); + + foreach(QObject *child, children) { + if(QmlBindableValue *value = qobject_cast(child)) { + bindings.insert(value->property().name().toUtf8(), qMakePair(value->expression(), value->id())); + } else if(QmlBoundSignal *signal = qobject_cast(child)) { + QMetaMethod method = object->metaObject()->method(signal->index()); + QByteArray sig = method.signature(); + sigs.insert(sig, signal->expression()); + } + } + + quint32 objectId = m_watches->objectId(object); + const QMetaObject *mo = object->metaObject(); for(int ii = 0; ii < mo->propertyCount(); ++ii) { + QMetaProperty p = mo->property(ii); + + if(QmlMetaType::isList(p.userType()) || + QmlMetaType::isQmlList(p.userType())) + continue; + QmlPropertyViewItem *item = new QmlPropertyViewItem(m_tree); - QMetaProperty p = mo->property(ii); item->object = object; item->property = p; item->setText(0, QLatin1String(p.name())); + if(m_watches->hasWatch(objectId, p.name())) + item->setForeground(0, Qt::red); static int refreshIdx = -1; if(refreshIdx == -1) @@ -109,8 +172,34 @@ void QmlPropertyView::setObject(QObject *object) QMetaObject::connect(object, p.notifySignalIndex(), item, refreshIdx); + + QMultiHash >::Iterator iter = + bindings.find(p.name()); + + while(iter != bindings.end() && iter.key() == p.name()) { + QmlPropertyViewItem *binding = new QmlPropertyViewItem(item); + binding->exprId = iter.value().second; + binding->setText(1, iter.value().first); + if (m_watches->hasWatch(binding->exprId)) + binding->setForeground(1, Qt::darkGreen); + else + binding->setForeground(1, Qt::green); + ++iter; + } + + item->setExpanded(true); item->refresh(); } + + for(QHash::ConstIterator iter = sigs.begin(); + iter != sigs.end(); + ++iter) { + + QTreeWidgetItem *item = new QTreeWidgetItem(m_tree); + item->setText(0, iter.key()); + item->setForeground(0, Qt::blue); + item->setText(1, iter.value()); + } } void QmlPropertyView::refresh() diff --git a/src/declarative/debugger/qmlpropertyview_p.h b/src/declarative/debugger/qmlpropertyview_p.h index fce9941..a671ea1 100644 --- a/src/declarative/debugger/qmlpropertyview_p.h +++ b/src/declarative/debugger/qmlpropertyview_p.h @@ -44,24 +44,28 @@ #include #include +#include QT_BEGIN_NAMESPACE class QTreeWidget; +class QTreeWidgetItem; class QmlPropertyView : public QWidget { Q_OBJECT public: - QmlPropertyView(QWidget *parent = 0); + QmlPropertyView(QmlWatches *watches, QWidget *parent = 0); void setObject(QObject *); public slots: void refresh(); + void itemDoubleClicked(QTreeWidgetItem *); private: QPointer m_object; QTreeWidget *m_tree; + QmlWatches *m_watches; }; QT_END_NAMESPACE diff --git a/src/declarative/debugger/qmlwatches.cpp b/src/declarative/debugger/qmlwatches.cpp new file mode 100644 index 0000000..1b9befd --- /dev/null +++ b/src/declarative/debugger/qmlwatches.cpp @@ -0,0 +1,267 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlwatches_p.h" +#include +#include +#include +#include + +static QString objectToString(QObject *obj) +{ + if(!obj) + return QString(); + + QString objectName = obj->objectName(); + if(objectName.isEmpty()) + objectName = QLatin1String(""); + + QString rv = QLatin1String(obj->metaObject()->className()) + + QLatin1String(": ") + objectName; + + return rv; +} + +class QmlWatchesProxy : public QObject +{ + Q_OBJECT +public: + QmlWatchesProxy(QObject *object, + const QMetaProperty &prop, + int column, + QmlWatches *parent = 0); + +public slots: + void refresh(); + +private: + QmlWatches *m_watches; + QObject *m_object; + QMetaProperty m_property; + int m_column; +}; + +QmlWatchesProxy::QmlWatchesProxy(QObject *object, + const QMetaProperty &prop, + int column, + QmlWatches *parent) +: QObject(parent), m_watches(parent), m_object(object), m_property(prop), + m_column(column) +{ + static int refreshIdx = -1; + if(refreshIdx == -1) + refreshIdx = QmlWatchesProxy::staticMetaObject.indexOfMethod("refresh()"); + + QMetaObject::connect(m_object, prop.notifySignalIndex(), + this, refreshIdx); +} + +void QmlWatchesProxy::refresh() +{ + QVariant v = m_property.read(m_object); + m_watches->addValue(m_column, v); +} + +QmlWatches::QmlWatches(QObject *parent) +: QAbstractTableModel(parent), m_uniqueId(0) +{ +} + +bool QmlWatches::hasWatch(quint32 objectId, const QByteArray &property) +{ + return m_watches.contains(qMakePair(objectId, property)); +} + +void QmlWatches::addWatch(quint32 objectId, const QByteArray &property) +{ + if(hasWatch(objectId, property)) + return; + + int oldColumn = columnCount(QModelIndex()); + + + m_watches.append(qMakePair(objectId, property)); + + beginInsertColumns(QModelIndex(), oldColumn, oldColumn); + endInsertColumns(); + + QObject *obj = object(objectId); + m_columnNames.append(QLatin1String(property) + QLatin1String(" on ") + objectToString(obj)); + QMetaProperty prop = + obj->metaObject()->property(obj->metaObject()->indexOfProperty(property.constData())); + QmlWatchesProxy *proxy = new QmlWatchesProxy(obj, prop, oldColumn, this); + proxy->refresh(); + m_values[m_values.count() - 1].first = true; +} + +void QmlWatches::remWatch(quint32 objectId, const QByteArray &property) +{ + m_watches.removeAll(qMakePair(objectId, property)); +} + +bool QmlWatches::hasWatch(quint32 exprId) +{ + return m_exprWatches.contains(exprId); +} + +void QmlWatches::remWatch(quint32 exprId) +{ + m_exprWatches.removeAll(exprId); +} + +void QmlWatches::addWatch(quint32 exprId) +{ + if (hasWatch(exprId)) + return; + + int oldColumn = columnCount(QModelIndex()); + + m_exprWatches.append(exprId); + + beginInsertColumns(QModelIndex(), oldColumn, oldColumn); + endInsertColumns(); +} + +quint32 QmlWatches::objectId(QObject *object) +{ + Q_ASSERT(object); + + QHash, quint32> *>::Iterator iter = + m_objects.find(object); + if(iter == m_objects.end()) { + iter = m_objects.insert(object, new QPair, quint32>(QPointer(object), m_uniqueId++)); + m_objectIds.insert(iter.value()->second, iter.value()); + } + + if(iter.value()->first != object) { + iter.value()->first = object; + iter.value()->second = m_uniqueId++; + + m_objectIds.insert(iter.value()->second, iter.value()); + } + return iter.value()->second; +} + +QObject *QmlWatches::object(quint32 id) +{ + QHash, quint32> *>::Iterator iter = + m_objectIds.find(id); + if(iter == m_objectIds.end()) + return 0; + + if(!iter.value()->first) { + m_objectIds.erase(iter); + return 0; + } + + return iter.value()->first; +} + +void QmlWatches::addValue(int column, const QVariant &value) +{ + int row = m_values.count(); + + beginInsertRows(QModelIndex(), row, row); + Value v; + v.column = column; + v.variant = value; + v.first = false; + m_values.append(v); + endInsertRows(); +} + +int QmlWatches::columnCount(const QModelIndex &) const +{ + return m_watches.count() + m_exprWatches.count(); +} + +int QmlWatches::rowCount(const QModelIndex &) const +{ + return m_values.count(); +} + +QVariant QmlWatches::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && section < m_columnNames.count() && + role == Qt::DisplayRole) + return m_columnNames.at(section); + else + return QVariant(); +} + +QVariant QmlWatches::data(const QModelIndex &idx, int role) const +{ + if(m_values.at(idx.row()).column == idx.column()) { + if(role == Qt::DisplayRole) { + const QVariant &value = m_values.at(idx.row()).variant; + + QString str = value.toString(); + + if(str.isEmpty() && QmlMetaType::isObject(value.userType())) { + QObject *o = QmlMetaType::toQObject(value); + if(o) { + QString objectName = o->objectName(); + if(objectName.isEmpty()) + objectName = QLatin1String(""); + str = QLatin1String(o->metaObject()->className()) + + QLatin1String(": ") + objectName; + } + } + + if(str.isEmpty()) { + QDebug d(&str); + d << value; + } + return QVariant(str); + } else if(role == Qt::BackgroundRole) { + if(m_values.at(idx.row()).first) + return QColor(Qt::green); + else + return QVariant(); + } else { + return QVariant(); + } + } else { + return QVariant(); + } +} + +#include "qmlwatches.moc" diff --git a/src/declarative/debugger/qmlwatches_p.h b/src/declarative/debugger/qmlwatches_p.h new file mode 100644 index 0000000..12a6468 --- /dev/null +++ b/src/declarative/debugger/qmlwatches_p.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLWATCHES_P_H +#define QMLWATCHES_P_H + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QmlWatchesProxy; +class QmlWatches : public QAbstractTableModel +{ + Q_OBJECT +public: + QmlWatches(QObject *parent = 0); + + bool hasWatch(quint32 objectId, const QByteArray &property); + void addWatch(quint32 objectId, const QByteArray &property); + void remWatch(quint32 objectId, const QByteArray &property); + + bool hasWatch(quint32 exprId); + void remWatch(quint32 exprId); + void addWatch(quint32 exprId); + + quint32 objectId(QObject *); + QObject *object(quint32); + +protected: + int columnCount(const QModelIndex &) const; + int rowCount(const QModelIndex &) const; + QVariant data(const QModelIndex &, int) const; + QVariant headerData(int, Qt::Orientation, int) const; + +private: + friend class QmlWatchesProxy; + QList > m_watches; + QList m_exprWatches; + + void addValue(int, const QVariant &); + struct Value { + int column; + QVariant variant; + bool first; + }; + QList m_values; + QStringList m_columnNames; + + quint32 m_uniqueId; + QHash, quint32> *> m_objects; + QHash, quint32> *> m_objectIds; +}; + +QT_END_NAMESPACE + +#endif // QMLWATCHES_P_H diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 15b5879..50c0981 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -597,6 +597,9 @@ QNetworkAccessManager *QmlEngine::networkAccessManager() const */ QmlContext *QmlEngine::contextForObject(const QObject *object) { + if(!object) + return 0; + QObjectPrivate *priv = QObjectPrivate::get(const_cast(object)); QmlSimpleDeclarativeData *data = @@ -1093,6 +1096,14 @@ QObject *QmlExpression::scopeObject() const } /*! + \internal +*/ +quint32 QmlExpression::id() const +{ + return d->id; +} + +/*! \class QmlExpression \brief The QmlExpression class evaluates ECMAScript in a QML context. */ diff --git a/src/declarative/qml/qmlexpression.h b/src/declarative/qml/qmlexpression.h index 0ab5d9c..bb6980a 100644 --- a/src/declarative/qml/qmlexpression.h +++ b/src/declarative/qml/qmlexpression.h @@ -80,6 +80,7 @@ public: QObject *scopeObject() const; + quint32 id() const; protected: virtual void valueChanged(); -- cgit v0.12 From 1829f66c1564be7934aa400b78006a5f6ffc8dc9 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 8 May 2009 12:26:58 +1000 Subject: Allow control of cursor and of selection. This allows components to implement look&feel such as select-all-on-focus, and to blink the cursor even when it is a proxy that actually has focus. --- src/declarative/fx/qfxtextedit.cpp | 42 ++++++++++++++++++++++++++++++++------ src/declarative/fx/qfxtextedit.h | 8 ++++++++ src/declarative/fx/qfxtextedit_p.h | 3 ++- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/declarative/fx/qfxtextedit.cpp b/src/declarative/fx/qfxtextedit.cpp index bf7a16d..3bc9696 100644 --- a/src/declarative/fx/qfxtextedit.cpp +++ b/src/declarative/fx/qfxtextedit.cpp @@ -377,6 +377,28 @@ void QFxTextEdit::setWrap(bool w) updateSize(); } +/*! + \property QFxTextEdit::cursorVisible + \brief If true the text edit shows a cursor. + + This property is set and unset when the text edit gets focus, but it can also + be set directly (useful, for example, if a KeyProxy might forward keys to it). +*/ +bool QFxTextEdit::isCursorVisible() const +{ + Q_D(const QFxTextEdit); + return d->cursorVisible; +} + +void QFxTextEdit::setCursorVisible(bool on) +{ + Q_D(QFxTextEdit); + if (d->cursorVisible == on) + return; + d->cursorVisible = on; + QFocusEvent focusEvent(on ? QEvent::FocusIn : QEvent::FocusOut); + d->control->processEvent(&focusEvent, QPointF(0, 0)); +} void QFxTextEdit::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) @@ -591,8 +613,15 @@ void QFxTextEdit::keyReleaseEvent(QKeyEvent *event) void QFxTextEdit::focusChanged(bool hasFocus) { Q_D(QFxTextEdit); - QFocusEvent focusEvent(hasFocus ? QEvent::FocusIn : QEvent::FocusOut); - d->control->processEvent(&focusEvent, QPointF(0, 0)); +} + +/*! + Causes all text to be selected. +*/ +void QFxTextEdit::selectAll() +{ + Q_D(QFxTextEdit); + d->control->selectAll(); } static QMouseEvent *sceneMouseEventToMouseEvent(QGraphicsSceneMouseEvent *e) @@ -737,6 +766,7 @@ void QFxTextEditPrivate::init() document->setDocumentMargin(0); document->setUndoRedoEnabled(false); // flush undo buffer. document->setUndoRedoEnabled(true); + updateDefaultTextOption(); } void QFxTextEdit::q_textChanged() @@ -785,14 +815,13 @@ void QFxTextEdit::updateSize() void QFxTextEditPrivate::updateDefaultTextOption() { - QTextDocument *doc = control->document(); - - QTextOption opt = doc->defaultTextOption(); + QTextOption opt = document->defaultTextOption(); int oldAlignment = opt.alignment(); opt.setAlignment((Qt::Alignment)(int)(hAlign | vAlign)); QTextOption::WrapMode oldWrapMode = opt.wrapMode(); +qDebug() << "wrap mode is" << opt.wrapMode(); if (wrap) opt.setWrapMode(QTextOption::WordWrap); else @@ -800,7 +829,8 @@ void QFxTextEditPrivate::updateDefaultTextOption() if (oldWrapMode == opt.wrapMode() && oldAlignment == opt.alignment()) return; - doc->setDefaultTextOption(opt); +qDebug() << "wrap mode set to" << opt.wrapMode(); + document->setDefaultTextOption(opt); } QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxtextedit.h b/src/declarative/fx/qfxtextedit.h index e5e9421..068a25a 100644 --- a/src/declarative/fx/qfxtextedit.h +++ b/src/declarative/fx/qfxtextedit.h @@ -75,7 +75,9 @@ class Q_DECLARATIVE_EXPORT QFxTextEdit : public QFxPaintedItem Q_PROPERTY(bool wrap READ wrap WRITE setWrap) Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat) Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) + Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) Q_CLASSINFO("DefaultProperty", "text") + public: QFxTextEdit(QFxItem *parent=0); @@ -118,6 +120,9 @@ public: bool wrap() const; void setWrap(bool w); + bool isCursorVisible() const; + void setCursorVisible(bool on); + virtual void dump(int depth); virtual QString propertyInfo() const; @@ -145,6 +150,9 @@ Q_SIGNALS: void textChanged(const QString &); void cursorPositionChanged(); +public Q_SLOTS: + void selectAll(); + private Q_SLOTS: void fontChanged(); void updateImgCache(const QRectF &rect); diff --git a/src/declarative/fx/qfxtextedit_p.h b/src/declarative/fx/qfxtextedit_p.h index b583dbe..f4591f5 100644 --- a/src/declarative/fx/qfxtextedit_p.h +++ b/src/declarative/fx/qfxtextedit_p.h @@ -68,7 +68,7 @@ class QFxTextEditPrivate : public QFxPaintedItemPrivate public: QFxTextEditPrivate() - : font(0), color("black"), imgDirty(true), hAlign(QFxTextEdit::AlignLeft), vAlign(QFxTextEdit::AlignTop), dirty(false), wrap(false), richText(false), format(QFxTextEdit::AutoText), document(0) + : font(0), color("black"), imgDirty(true), hAlign(QFxTextEdit::AlignLeft), vAlign(QFxTextEdit::AlignTop), dirty(false), wrap(false), richText(false), cursorVisible(false), format(QFxTextEdit::AutoText), document(0) { } @@ -93,6 +93,7 @@ public: bool dirty; bool wrap; bool richText; + bool cursorVisible; QFxTextEdit::TextFormat format; QTextDocument *document; QTextControl *control; -- cgit v0.12 From 9a69890dee24a26efde615e18f1ed7aa79eb441c Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 8 May 2009 12:28:10 +1000 Subject: tag input --- demos/declarative/flickr/content/MediaLineEdit.qml | 110 +++++++++++++++++++++ .../flickr/content/pics/button-pressed.sci | 5 + demos/declarative/flickr/content/pics/button.sci | 5 + demos/declarative/flickr/flickr.qml | 17 +++- 4 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 demos/declarative/flickr/content/MediaLineEdit.qml create mode 100644 demos/declarative/flickr/content/pics/button-pressed.sci create mode 100644 demos/declarative/flickr/content/pics/button.sci diff --git a/demos/declarative/flickr/content/MediaLineEdit.qml b/demos/declarative/flickr/content/MediaLineEdit.qml new file mode 100644 index 0000000..28618e8 --- /dev/null +++ b/demos/declarative/flickr/content/MediaLineEdit.qml @@ -0,0 +1,110 @@ +Item { + id: Container + + property string label + property string text + + width: Label.width + Editor.width + 20 + height: Image.height + + states: [ + State { + name: "Edit" + SetProperties { + target: Label + text: Container.label + ": " + } + SetProperties { + target: Editor + cursorVisible: true + width: 100 + } + SetProperties { + target: Proxy + focus: true + } + RunScript { + script:"Editor.selectAll()" + } + }, + State { + // When returning to default state, typed text is propagated + RunScript { + script: "Container.text = Editor.text" + } + } + ] + transitions: [ + Transition { + ParallelAnimation { + NumericAnimation { properties: "width"; duration: 500; easing: "easeInOutQuad" } + SequentialAnimation { + PauseAnimation { duration: 100 } + SetPropertyAction { properties: "text" } + } + } + } + ] + + + Image { + id: Image + source: "pics/button.sci" + anchors.left: Container.left + anchors.right: Container.right + } + + Image { + id: Pressed + source: "pics/button-pressed.sci" + opacity: 0 + anchors.left: Container.left + anchors.right: Container.right + } + + MouseRegion { + id: MouseRegion + anchors.fill: Image + onClicked: { Container.state = Container.state=="Edit" ? "" : "Edit" } + states: [ + State { + when: MouseRegion.pressed == true + SetProperties { + target: Pressed + opacity: 1 + } + } + ] + } + + Text { + id: Label + font.bold: true + color: "white" + anchors.verticalCenter: Container.verticalCenter + anchors.left: Container.left + anchors.leftMargin: 10 + text: Container.label + "..." + } + + TextEdit { + id: Editor + font.bold: true + color: "white" + width: 0 + clip: true + anchors.left: Label.right + anchors.verticalCenter: Container.verticalCenter + } + KeyProxy { + id: Proxy + anchors.left: Container.left + anchors.fill: Container + focusable: true + targets: [(ReturnKey), (Editor)] + } + KeyActions { + id: ReturnKey + return: "Container.state = ''" + } +} diff --git a/demos/declarative/flickr/content/pics/button-pressed.sci b/demos/declarative/flickr/content/pics/button-pressed.sci new file mode 100644 index 0000000..d3b16e2 --- /dev/null +++ b/demos/declarative/flickr/content/pics/button-pressed.sci @@ -0,0 +1,5 @@ +gridLeft: 8 +gridTop: 4 +gridBottom: 4 +gridRight: 8 +imageFile: button.png diff --git a/demos/declarative/flickr/content/pics/button.sci b/demos/declarative/flickr/content/pics/button.sci new file mode 100644 index 0000000..d3b16e2 --- /dev/null +++ b/demos/declarative/flickr/content/pics/button.sci @@ -0,0 +1,5 @@ +gridLeft: 8 +gridTop: 4 +gridBottom: 4 +gridRight: 8 +imageFile: button.png diff --git a/demos/declarative/flickr/flickr.qml b/demos/declarative/flickr/flickr.qml index 85af8e3..8828651 100644 --- a/demos/declarative/flickr/flickr.qml +++ b/demos/declarative/flickr/flickr.qml @@ -8,7 +8,7 @@ Item { resources: [ XmlListModel { id: FeedModel - property string tags : "" + property string tags : TagsEdit.text source: "http://api.flickr.com/services/feeds/photos_public.gne?"+(tags ? "tags="+tags+"&" : "")+"format=rss2" query: "doc($src)/rss/channel/item" namespaceDeclarations: "declare namespace media=\"http://search.yahoo.com/mrss/\";" @@ -89,7 +89,7 @@ Item { SetProperties { target: ImageDetails; y: 20 } SetProperties { target: PhotoGridView; y: "-480" } SetProperties { target: PhotoPathView; y: "-480" } - SetProperties { target: CloseButton; opacity: 0 } + SetProperties { target: ViewModeButton; opacity: 0 } SetProperties { target: FetchButton; opacity: 0 } SetProperties { target: CategoryText; y: "-50" } } @@ -159,18 +159,25 @@ Item { ImageDetails { id: ImageDetails; width: 750; x: 25; y: 500; height: 410 } MediaButton { - id: CloseButton; x: 680; y: 410; text: "View Mode" + id: ViewModeButton; x: 680; y: 410; text: "View Mode" onClicked: { if (MainWindow.showPathView == true) MainWindow.showPathView = false; else MainWindow.showPathView = true } } MediaButton { id: FetchButton text: "Update" - anchors.right: CloseButton.left; anchors.rightMargin: 5 - anchors.top: CloseButton.top + anchors.right: ViewModeButton.left; anchors.rightMargin: 5 + anchors.top: ViewModeButton.top onClicked: { FeedModel.reload(); } } + MediaLineEdit { + id: TagsEdit; + label: "Tags" + anchors.right: FetchButton.left; anchors.rightMargin: 5 + anchors.top: ViewModeButton.top + } + states: [ State { name: "PathView" -- cgit v0.12 From 32df312db7c2088002c734a49cf9cc13b334af6e Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 8 May 2009 12:37:27 +1000 Subject: Minimal size is MediaButton size, center outside edit mode --- demos/declarative/flickr/content/MediaLineEdit.qml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/demos/declarative/flickr/content/MediaLineEdit.qml b/demos/declarative/flickr/content/MediaLineEdit.qml index 28618e8..37caf24 100644 --- a/demos/declarative/flickr/content/MediaLineEdit.qml +++ b/demos/declarative/flickr/content/MediaLineEdit.qml @@ -4,7 +4,7 @@ Item { property string label property string text - width: Label.width + Editor.width + 20 + width: Math.max(94,Label.width + Editor.width + 20) height: Image.height states: [ @@ -14,6 +14,11 @@ Item { target: Label text: Container.label + ": " } + SetProperty { + target: Label + property: "x" + binding: 10 + } SetProperties { target: Editor cursorVisible: true @@ -36,13 +41,7 @@ Item { ] transitions: [ Transition { - ParallelAnimation { - NumericAnimation { properties: "width"; duration: 500; easing: "easeInOutQuad" } - SequentialAnimation { - PauseAnimation { duration: 100 } - SetPropertyAction { properties: "text" } - } - } + NumericAnimation { properties: "x,width"; duration: 500; easing: "easeInOutQuad" } } ] @@ -82,8 +81,7 @@ Item { font.bold: true color: "white" anchors.verticalCenter: Container.verticalCenter - anchors.left: Container.left - anchors.leftMargin: 10 + x: (Container.width - width)/2 text: Container.label + "..." } -- cgit v0.12 From 6597cb980c484c11554314d8db63c6dd4edcd887 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 8 May 2009 13:01:02 +1000 Subject: Fade TagEdit properly --- demos/declarative/flickr/flickr.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/demos/declarative/flickr/flickr.qml b/demos/declarative/flickr/flickr.qml index cbe6534..092aef6 100644 --- a/demos/declarative/flickr/flickr.qml +++ b/demos/declarative/flickr/flickr.qml @@ -91,6 +91,7 @@ Item { SetProperties { target: PhotoGridView; y: "-480" } SetProperties { target: PhotoPathView; y: "-480" } SetProperties { target: ViewModeButton; opacity: 0 } + SetProperties { target: TagsEdit; opacity: 0 } SetProperties { target: FetchButton; opacity: 0 } SetProperties { target: CategoryText; y: "-50" } } -- cgit v0.12 From e4fb4f78ae18e3b5a538ce47b43136b4c666674e Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 8 May 2009 13:04:54 +1000 Subject: Cross link properties to the tree view --- src/declarative/debugger/qmldebugger.cpp | 24 +++++++++++++++++++++++- src/declarative/debugger/qmldebugger.h | 4 ++++ src/declarative/debugger/qmlpropertyview.cpp | 28 +++++++++++++++++++++++++++- src/declarative/debugger/qmlpropertyview_p.h | 4 ++++ src/declarative/debugger/qmlwatches.cpp | 4 ++-- src/declarative/debugger/qmlwatches_p.h | 1 + 6 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/declarative/debugger/qmldebugger.cpp b/src/declarative/debugger/qmldebugger.cpp index 250f451..907b91b 100644 --- a/src/declarative/debugger/qmldebugger.cpp +++ b/src/declarative/debugger/qmldebugger.cpp @@ -62,7 +62,7 @@ QmlDebugger::QmlDebugger(QWidget *parent) : QWidget(parent), m_tree(0), m_warnings(0), m_watchTable(0), m_watches(0), - m_properties(0), m_text(0) + m_properties(0), m_text(0), m_highlightedItem(0) { QHBoxLayout *layout = new QHBoxLayout; setLayout(layout); @@ -102,7 +102,10 @@ QmlDebugger::QmlDebugger(QWidget *parent) tabs->addTab(m_watchTable, "Watches"); m_properties = new QmlPropertyView(m_watches, this); + QObject::connect(m_properties, SIGNAL(objectClicked(quint32)), + this, SLOT(highlightObject(quint32))); tabs->addTab(m_properties, "Properties"); + tabs->setCurrentWidget(m_properties); splitter->addWidget(tabs); splitter->setStretchFactor(1, 2); @@ -135,6 +138,22 @@ void QmlDebugger::itemDoubleClicked(QTreeWidgetItem *i) { } +void QmlDebugger::highlightObject(quint32 id) +{ + QHash::ConstIterator iter = m_items.find(id); + if (m_highlightedItem) { + m_highlightedItem->setBackground(0, QPalette().base()); + m_highlightedItem = 0; + } + + if (iter != m_items.end()) { + m_highlightedItem = *iter; + m_highlightedItem->setBackground(0, QColor("cyan")); + m_tree->expandItem(m_highlightedItem); + m_tree->scrollToItem(m_highlightedItem); + } +} + void QmlDebugger::itemClicked(QTreeWidgetItem *i) { QmlDebuggerItem *item = static_cast(i); @@ -293,6 +312,7 @@ bool QmlDebugger::makeItem(QObject *obj, QmlDebuggerItem *item) item->setForeground(0, Qt::lightGray); } + m_items.insert(m_watches->objectId(obj), item); item->setText(0, text); return rv; @@ -324,6 +344,8 @@ void QmlDebugger::setDebugObject(QObject *obj) { m_tree->clear(); m_warnings->clear(); + m_items.clear(); + m_highlightedItem = 0; m_object = obj; if(!obj) diff --git a/src/declarative/debugger/qmldebugger.h b/src/declarative/debugger/qmldebugger.h index 776ded3..6495a49 100644 --- a/src/declarative/debugger/qmldebugger.h +++ b/src/declarative/debugger/qmldebugger.h @@ -73,6 +73,7 @@ public slots: private slots: void itemClicked(QTreeWidgetItem *); void itemDoubleClicked(QTreeWidgetItem *); + void highlightObject(quint32); private: void buildTree(QObject *obj, QmlDebuggerItem *parent); @@ -85,6 +86,9 @@ private: QPlainTextEdit *m_text; QPointer m_object; QPointer m_selectedItem; + + QTreeWidgetItem *m_highlightedItem; + QHash m_items; }; QT_END_NAMESPACE diff --git a/src/declarative/debugger/qmlpropertyview.cpp b/src/declarative/debugger/qmlpropertyview.cpp index b46a1bf..eda97b7 100644 --- a/src/declarative/debugger/qmlpropertyview.cpp +++ b/src/declarative/debugger/qmlpropertyview.cpp @@ -59,6 +59,8 @@ QmlPropertyView::QmlPropertyView(QmlWatches *watches, QWidget *parent) m_tree->setHeaderLabels(QStringList() << "Property" << "Value"); QObject::connect(m_tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem *))); + QObject::connect(m_tree, SIGNAL(itemClicked(QTreeWidgetItem *, int)), + this, SLOT(itemClicked(QTreeWidgetItem *))); m_tree->setColumnCount(2); @@ -93,7 +95,31 @@ QmlPropertyViewItem::QmlPropertyViewItem(QTreeWidgetItem *parent) void QmlPropertyViewItem::refresh() { - setText(1, property.read(object).toString()); + QVariant v = property.read(object); + QString str = v.toString(); + + if (QmlMetaType::isObject(v.userType())) + str = QmlWatches::objectToString(QmlMetaType::toQObject(v)); + + setText(1, str); +} + +void QmlPropertyView::itemClicked(QTreeWidgetItem *i) +{ + QmlPropertyViewItem *item = static_cast(i); + + if(item->object) { + QVariant v = item->property.read(item->object); + if (QmlMetaType::isObject(v.userType())) { + QObject *obj = QmlMetaType::toQObject(v); + + if(obj) { + quint32 id = m_watches->objectId(obj); + emit objectClicked(id); + } + } + } + } void QmlPropertyView::itemDoubleClicked(QTreeWidgetItem *i) diff --git a/src/declarative/debugger/qmlpropertyview_p.h b/src/declarative/debugger/qmlpropertyview_p.h index a671ea1..469a08d 100644 --- a/src/declarative/debugger/qmlpropertyview_p.h +++ b/src/declarative/debugger/qmlpropertyview_p.h @@ -58,9 +58,13 @@ public: void setObject(QObject *); +signals: + void objectClicked(quint32); + public slots: void refresh(); void itemDoubleClicked(QTreeWidgetItem *); + void itemClicked(QTreeWidgetItem *); private: QPointer m_object; diff --git a/src/declarative/debugger/qmlwatches.cpp b/src/declarative/debugger/qmlwatches.cpp index 1b9befd..1cc9469 100644 --- a/src/declarative/debugger/qmlwatches.cpp +++ b/src/declarative/debugger/qmlwatches.cpp @@ -45,10 +45,10 @@ #include #include -static QString objectToString(QObject *obj) +QString QmlWatches::objectToString(QObject *obj) { if(!obj) - return QString(); + return QLatin1String("NULL"); QString objectName = obj->objectName(); if(objectName.isEmpty()) diff --git a/src/declarative/debugger/qmlwatches_p.h b/src/declarative/debugger/qmlwatches_p.h index 12a6468..4570a4f 100644 --- a/src/declarative/debugger/qmlwatches_p.h +++ b/src/declarative/debugger/qmlwatches_p.h @@ -69,6 +69,7 @@ public: quint32 objectId(QObject *); QObject *object(quint32); + static QString objectToString(QObject *obj); protected: int columnCount(const QModelIndex &) const; int rowCount(const QModelIndex &) const; -- cgit v0.12