From 113d7a6a1eab75ad5673f9b50ccf8df456b5d628 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 26 May 2010 11:24:37 +1000 Subject: Fix Gradient doc snippet. --- doc/src/snippets/declarative/gradient.qml | 2 ++ src/declarative/graphicsitems/qdeclarativerectangle.cpp | 6 +----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/doc/src/snippets/declarative/gradient.qml b/doc/src/snippets/declarative/gradient.qml index d25352b..7a68233 100644 --- a/doc/src/snippets/declarative/gradient.qml +++ b/doc/src/snippets/declarative/gradient.qml @@ -41,6 +41,7 @@ import Qt 4.7 +//![code] Rectangle { width: 100; height: 100 gradient: Gradient { @@ -49,3 +50,4 @@ Rectangle { GradientStop { position: 1.0; color: "green" } } } +//![code] diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp index d098aa0..4f7a722 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp +++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp @@ -114,11 +114,7 @@ void QDeclarativeGradientStop::updateGradient() rectangle with a gradient starting with red, blending to yellow at 1/3 of the size of the rectangle, and ending with Green: - \table - \row - \o \image gradient.png - \o \quotefile doc/src/snippets/declarative/gradient.qml - \endtable + \snippet doc/src/snippets/declarative/gradient.qml code \sa GradientStop */ -- cgit v0.12 From 5a6a5b1b83e2196b4cad11fbb0f175682b6f7e8e Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 26 May 2010 11:30:20 +1000 Subject: Replace QTime with QElapsedTimer --- src/declarative/util/qdeclarativeview.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp index e68ef94..b7ce9c9 100644 --- a/src/declarative/util/qdeclarativeview.cpp +++ b/src/declarative/util/qdeclarativeview.cpp @@ -116,7 +116,7 @@ public: void frameBreak() { ++breaks; } private: - QTime timer; + QElapsedTimer timer; int breaks; }; @@ -152,7 +152,7 @@ public: QBasicTimer resizetimer; QDeclarativeView::ResizeMode resizeMode; - QTime frameTimer; + QElapsedTimer frameTimer; void init(); -- cgit v0.12 From 4fe568ffb7a59909b0c72bed7da959fd36702f19 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Wed, 26 May 2010 12:42:36 +1000 Subject: Add a way to control when software input panels are shown in TextInput and TextEdit elements Task-number: QTBUG-10841 Reviewed-by: Warwick Allison --- .../graphicsitems/qdeclarativetextedit.cpp | 131 +++++++++++++++++++-- .../graphicsitems/qdeclarativetextedit_p.h | 10 ++ .../graphicsitems/qdeclarativetextedit_p_p.h | 8 +- .../graphicsitems/qdeclarativetextinput.cpp | 131 +++++++++++++++++++-- .../graphicsitems/qdeclarativetextinput_p.h | 10 ++ .../graphicsitems/qdeclarativetextinput_p_p.h | 4 +- .../tst_qdeclarativetextedit.cpp | 85 ++++++++++--- .../tst_qdeclarativetextinput.cpp | 86 +++++++++++--- 8 files changed, 413 insertions(+), 52 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index a154d53..d4fbb8b 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -940,7 +940,6 @@ Handles the given mouse \a event. void QDeclarativeTextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativeTextEdit); - bool hadFocus = hasFocus(); if (d->focusOnPress){ QGraphicsItem *p = parentItem();//###Is there a better way to find my focus scope? while(p) { @@ -950,8 +949,6 @@ void QDeclarativeTextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) } setFocus(true); } - if (!hadFocus && hasFocus()) - d->clickCausedFocus = true; if (event->type() != QEvent::GraphicsSceneMouseDoubleClick || d->selectByMouse) d->control->processEvent(event, QPointF(0, -d->yoff)); if (!event->isAccepted()) @@ -965,11 +962,6 @@ Handles the given mouse \a event. void QDeclarativeTextEdit::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativeTextEdit); - QWidget *widget = event->widget(); - if (widget && (d->control->textInteractionFlags() & Qt::TextEditable) && boundingRect().contains(event->pos())) - qt_widget_private(widget)->handleSoftwareInputPanel(event->button(), d->clickCausedFocus); - d->clickCausedFocus = false; - d->control->processEvent(event, QPointF(0, -d->yoff)); if (!event->isAccepted()) QDeclarativePaintedItem::mouseReleaseEvent(event); @@ -1205,4 +1197,127 @@ void QDeclarativeTextEditPrivate::updateDefaultTextOption() document->setDefaultTextOption(opt); } + +/*! + \qmlmethod void TextEdit::openSoftwareInputPanel() + + Opens software input panels like virtual keyboards for typing, useful for + customizing when you want the input keyboard to be shown and hidden in + your application. + + By default input panels are shown when TextEdit element gains focus and hidden + when the focus is lost. You can disable the automatic behavior by setting the + property showInputPanelOnFocus to false and use functions openSoftwareInputPanel() + and closeSoftwareInputPanel() to implement the behavior you want. + + Only relevant on platforms, which provide virtual keyboards. + + \code + import Qt 4.7 + TextEdit { + id: textEdit + text: "Hello world!" + showInputPanelOnFocus: false + MouseArea { + anchors.fill: parent + onClicked: textEdit.openSoftwareInputPanel() + } + onFocusChanged: if (!focus) closeSoftwareInputpanel() + } + \endcode +*/ +void QDeclarativeTextEdit::openSoftwareInputPanel() +{ + QEvent event(QEvent::RequestSoftwareInputPanel); + if (qApp) { + if (QGraphicsView * view = qobject_cast(qApp->focusWidget())) { + if (view->scene() && view->scene() == scene()) { + QApplication::sendEvent(view, &event); + } + } + } +} + +/*! + \qmlmethod void TextEdit::closeSoftwareInputPanel() + + Closes a software input panel like a virtual keyboard shown on the screen, useful + for customizing when you want the input keyboard to be shown and hidden in + your application. + + By default input panels are shown when TextEdit element gains focus and hidden + when the focus is lost. You can disable the automatic behavior by setting the + property showInputPanelOnFocus to false and use functions openSoftwareInputPanel() + and closeSoftwareInputPanel() to implement the behavior you want. + + Only relevant on platforms, which provide virtual keyboards. + + \code + import Qt 4.7 + TextEdit { + id: textEdit + text: "Hello world!" + showInputPanelOnFocus: false + MouseArea { + anchors.fill: parent + onClicked: textEdit.openSoftwareInputPanel() + } + onFocusChanged: if (!focus) closeSoftwareInputpanel() + } + \endcode +*/ +void QDeclarativeTextEdit::closeSoftwareInputPanel() +{ + QEvent event(QEvent::CloseSoftwareInputPanel); + if (qApp) { + if (QGraphicsView * view = qobject_cast(qApp->focusWidget())) { + if (view->scene() && view->scene() == scene()) { + QApplication::sendEvent(view, &event); + } + } + } +} + +/*! + \qmlproperty bool TextEdit::showInputPanelOnFocus + Whether input panels are automatically shown when TextEdit element gains + focus and hidden when focus is lost. By default this is set to true. + + Only relevant on platforms, which provide virtual keyboards. +*/ +bool QDeclarativeTextEdit::showInputPanelOnFocus() const +{ + Q_D(const QDeclarativeTextEdit); + return d->showInputPanelOnFocus; +} + +void QDeclarativeTextEdit::setShowInputPanelOnFocus(bool showOnFocus) +{ + Q_D(QDeclarativeTextEdit); + if (d->showInputPanelOnFocus == showOnFocus) + return; + + d->showInputPanelOnFocus = showOnFocus; + + emit showInputPanelOnFocusChanged(d->showInputPanelOnFocus); +} + +void QDeclarativeTextEdit::focusInEvent(QFocusEvent *event) +{ + Q_D(const QDeclarativeTextEdit); + if (d->showInputPanelOnFocus && !isReadOnly()) { + openSoftwareInputPanel(); + } + QDeclarativePaintedItem::focusInEvent(event); +} + +void QDeclarativeTextEdit::focusOutEvent(QFocusEvent *event) +{ + Q_D(const QDeclarativeTextEdit); + if (d->showInputPanelOnFocus && !isReadOnly()) { + closeSoftwareInputPanel(); + } + QDeclarativePaintedItem::focusOutEvent(event); +} + QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h index 891b868..fdac5cf 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h @@ -84,6 +84,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTextEdit : public QDeclarativePaintedItem Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectionChanged) Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY focusOnPressChanged) + Q_PROPERTY(bool showInputPanelOnFocus READ showInputPanelOnFocus WRITE setShowInputPanelOnFocus NOTIFY showInputPanelOnFocusChanged) Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged) Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin NOTIFY textMarginChanged) Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints) @@ -116,6 +117,9 @@ public: WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere }; + Q_INVOKABLE void openSoftwareInputPanel(); + Q_INVOKABLE void closeSoftwareInputPanel(); + QString text() const; void setText(const QString &); @@ -163,6 +167,9 @@ public: bool focusOnPress() const; void setFocusOnPress(bool on); + bool showInputPanelOnFocus() const; + void setShowInputPanelOnFocus(bool showOnFocus); + bool persistentSelection() const; void setPersistentSelection(bool on); @@ -207,6 +214,7 @@ Q_SIGNALS: void persistentSelectionChanged(bool isPersistentSelection); void textMarginChanged(qreal textMargin); void selectByMouseChanged(bool selectByMouse); + void showInputPanelOnFocusChanged(bool showOnFocus); public Q_SLOTS: void selectAll(); @@ -228,6 +236,8 @@ protected: bool event(QEvent *); void keyPressEvent(QKeyEvent *); void keyReleaseEvent(QKeyEvent *); + void focusInEvent(QFocusEvent *event); + void focusOutEvent(QFocusEvent *event); // mouse filter? void mousePressEvent(QGraphicsSceneMouseEvent *event); diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h index d96796c..8e1d630 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h @@ -70,9 +70,9 @@ public: QDeclarativeTextEditPrivate() : color("black"), hAlign(QDeclarativeTextEdit::AlignLeft), vAlign(QDeclarativeTextEdit::AlignTop), imgDirty(true), dirty(false), richText(false), cursorVisible(false), focusOnPress(true), - persistentSelection(true), clickCausedFocus(false), textMargin(0.0), lastSelectionStart(0), lastSelectionEnd(0), - cursorComponent(0), cursor(0), format(QDeclarativeTextEdit::AutoText), document(0), - wrapMode(QDeclarativeTextEdit::NoWrap), + showInputPanelOnFocus(true), persistentSelection(true), textMargin(0.0), lastSelectionStart(0), + lastSelectionEnd(0), cursorComponent(0), cursor(0), format(QDeclarativeTextEdit::AutoText), + document(0), wrapMode(QDeclarativeTextEdit::NoWrap), selectByMouse(false), yoff(0) { @@ -101,8 +101,8 @@ public: bool richText : 1; bool cursorVisible : 1; bool focusOnPress : 1; + bool showInputPanelOnFocus : 1; bool persistentSelection : 1; - bool clickCausedFocus : 1; qreal textMargin; int lastSelectionStart; int lastSelectionEnd; diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 1ac1b4e..47cd110 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -886,7 +886,6 @@ void QDeclarativeTextInput::keyPressEvent(QKeyEvent* ev) void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativeTextInput); - bool hadFocus = hasFocus(); if(d->focusOnPress){ QGraphicsItem *p = parentItem();//###Is there a better way to find my focus scope? while(p) { @@ -896,8 +895,6 @@ void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) } setFocus(true); } - if (!hadFocus && hasFocus()) - d->clickCausedFocus = true; bool mark = event->modifiers() & Qt::ShiftModifier; int cursor = d->xToPos(event->pos().x()); @@ -923,10 +920,7 @@ Handles the given mouse \a event. void QDeclarativeTextInput::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativeTextInput); - QWidget *widget = event->widget(); - if (widget && !d->control->isReadOnly() && boundingRect().contains(event->pos())) - qt_widget_private(widget)->handleSoftwareInputPanel(event->button(), d->clickCausedFocus); - d->clickCausedFocus = false; + d->control->processEvent(event); if (!event->isAccepted()) QDeclarativePaintedItem::mouseReleaseEvent(event); } @@ -1175,6 +1169,129 @@ void QDeclarativeTextInput::moveCursorSelection(int position) d->control->moveCursor(position, true); } +/*! + \qmlmethod void TextInput::openSoftwareInputPanel() + + Opens software input panels like virtual keyboards for typing, useful for + customizing when you want the input keyboard to be shown and hidden in + your application. + + By default input panels are shown when TextInput element gains focus and hidden + when the focus is lost. You can disable the automatic behavior by setting the + property showInputPanelOnFocus to false and use functions openSoftwareInputPanel() + and closeSoftwareInputPanel() to implement the behavior you want. + + Only relevant on platforms, which provide virtual keyboards. + + \code + import Qt 4.7 + TextInput { + id: textInput + text: "Hello world!" + showInputPanelOnFocus: false + MouseArea { + anchors.fill: parent + onClicked: textInput.openSoftwareInputPanel() + } + onFocusChanged: if (!focus) closeSoftwareInputPanel() + } + \endcode +*/ +void QDeclarativeTextInput::openSoftwareInputPanel() +{ + QEvent event(QEvent::RequestSoftwareInputPanel); + if (qApp) { + if (QGraphicsView * view = qobject_cast(qApp->focusWidget())) { + if (view->scene() && view->scene() == scene()) { + QApplication::sendEvent(view, &event); + } + } + } +} + +/*! + \qmlmethod void TextInput::closeSoftwareInputPanel() + + Closes a software input panel like a virtual keyboard shown on the screen, useful + for customizing when you want the input keyboard to be shown and hidden in + your application. + + By default input panels are shown when TextInput element gains focus and hidden + when the focus is lost. You can disable the automatic behavior by setting the + property showInputPanelOnFocus to false and use functions openSoftwareInputPanel() + and closeSoftwareInputPanel() to implement the behavior you want. + + Only relevant on platforms, which provide virtual keyboards. + + \code + import Qt 4.7 + TextInput { + id: textInput + text: "Hello world!" + showInputPanelOnFocus: false + MouseArea { + anchors.fill: parent + onClicked: textInput.openSoftwareInputPanel() + } + onFocusChanged: if (!focus) closeSoftwareInputPanel() + } + \endcode +*/ +void QDeclarativeTextInput::closeSoftwareInputPanel() +{ + QEvent event(QEvent::CloseSoftwareInputPanel); + if (qApp) { + QEvent event(QEvent::CloseSoftwareInputPanel); + if (QGraphicsView * view = qobject_cast(qApp->focusWidget())) { + if (view->scene() && view->scene() == scene()) { + QApplication::sendEvent(view, &event); + } + } + } +} + +/*! + \qmlproperty bool TextInput::showInputPanelOnFocus + Whether input panels are automatically shown when TextInput element gains + focus and hidden when focus is lost. By default this is set to true. + + Only relevant on platforms, which provide virtual keyboards. +*/ +bool QDeclarativeTextInput::showInputPanelOnFocus() const +{ + Q_D(const QDeclarativeTextInput); + return d->showInputPanelOnFocus; +} + +void QDeclarativeTextInput::setShowInputPanelOnFocus(bool showOnFocus) +{ + Q_D(QDeclarativeTextInput); + if (d->showInputPanelOnFocus == showOnFocus) + return; + + d->showInputPanelOnFocus = showOnFocus; + + emit showInputPanelOnFocusChanged(d->showInputPanelOnFocus); +} + +void QDeclarativeTextInput::focusInEvent(QFocusEvent *event) +{ + Q_D(const QDeclarativeTextInput); + if (d->showInputPanelOnFocus && !isReadOnly()) { + openSoftwareInputPanel(); + } + QDeclarativePaintedItem::focusInEvent(event); +} + +void QDeclarativeTextInput::focusOutEvent(QFocusEvent *event) +{ + Q_D(const QDeclarativeTextInput); + if (d->showInputPanelOnFocus && !isReadOnly()) { + closeSoftwareInputPanel(); + } + QDeclarativePaintedItem::focusOutEvent(event); +} + void QDeclarativeTextInputPrivate::init() { Q_Q(QDeclarativeTextInput); diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h index b2fd057..438293a 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h @@ -86,6 +86,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTextInput : public QDeclarativePaintedIte Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged) Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged) Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY focusOnPressChanged) + Q_PROPERTY(bool showInputPanelOnFocus READ showInputPanelOnFocus WRITE setShowInputPanelOnFocus NOTIFY showInputPanelOnFocusChanged) Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged) Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged) Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged) @@ -112,6 +113,9 @@ public: Q_INVOKABLE int xToPosition(int x); Q_INVOKABLE void moveCursorSelection(int pos); + Q_INVOKABLE void openSoftwareInputPanel(); + Q_INVOKABLE void closeSoftwareInputPanel(); + QString text() const; void setText(const QString &); @@ -172,6 +176,9 @@ public: bool focusOnPress() const; void setFocusOnPress(bool); + bool showInputPanelOnFocus() const; + void setShowInputPanelOnFocus(bool showOnFocus); + bool autoScroll() const; void setAutoScroll(bool); @@ -208,6 +215,7 @@ Q_SIGNALS: void focusOnPressChanged(bool focusOnPress); void autoScrollChanged(bool autoScroll); void selectByMouseChanged(bool selectByMouse); + void showInputPanelOnFocusChanged(bool showOnFocus); protected: virtual void geometryChanged(const QRectF &newGeometry, @@ -218,6 +226,8 @@ protected: void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void keyPressEvent(QKeyEvent* ev); bool event(QEvent *e); + void focusInEvent(QFocusEvent *event); + void focusOutEvent(QFocusEvent *event); public Q_SLOTS: void selectAll(); diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h index 1d8e0f7..f44d014 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h @@ -72,7 +72,7 @@ public: color((QRgb)0), style(QDeclarativeText::Normal), styleColor((QRgb)0), hAlign(QDeclarativeTextInput::AlignLeft), hscroll(0), oldScroll(0), focused(false), focusOnPress(true), - cursorVisible(false), autoScroll(true), clickCausedFocus(false), + showInputPanelOnFocus(true), cursorVisible(false), autoScroll(true), selectByMouse(false) { } @@ -115,9 +115,9 @@ public: int oldScroll; bool focused; bool focusOnPress; + bool showInputPanelOnFocus; bool cursorVisible; bool autoScroll; - bool clickCausedFocus; bool selectByMouse; }; diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index b07849d..2b6f2aa 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ #include +#include #include "../../../shared/util.h" #include "../shared/testhttpserver.h" #include @@ -811,7 +812,7 @@ QDeclarativeView *tst_qdeclarativetextedit::createView(const QString &filename) class MyInputContext : public QInputContext { public: - MyInputContext() : softwareInputPanelEventReceived(false) {} + MyInputContext() : openInputPanelReceived(false), closeInputPanelReceived(false) {} ~MyInputContext() {} QString identifierName() { return QString(); } @@ -824,10 +825,13 @@ public: bool filterEvent( const QEvent *event ) { if (event->type() == QEvent::RequestSoftwareInputPanel) - softwareInputPanelEventReceived = true; + openInputPanelReceived = true; + if (event->type() == QEvent::CloseSoftwareInputPanel) + closeInputPanelReceived = true; return QInputContext::filterEvent(event); } - bool softwareInputPanelEventReceived; + bool openInputPanelReceived; + bool closeInputPanelReceived; }; void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() @@ -835,10 +839,9 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() QGraphicsScene scene; QGraphicsView view(&scene); MyInputContext ic; - view.viewport()->setInputContext(&ic); - QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel( - view.style()->styleHint(QStyle::SH_RequestSoftwareInputPanel)); + view.setInputContext(&ic); QDeclarativeTextEdit edit; + QSignalSpy inputPanelonFocusSpy(&edit, SIGNAL(showInputPanelOnFocusChanged(bool))); edit.setText("Hello world"); edit.setPos(0, 0); scene.addItem(&edit); @@ -847,16 +850,68 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() QApplication::setActiveWindow(&view); QTest::qWaitForWindowShown(&view); QTRY_COMPARE(QApplication::activeWindow(), static_cast(&view)); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); + + QVERIFY(edit.showInputPanelOnFocus()); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, false); + + // focus on press, input panel on focus + QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); QApplication::processEvents(); - if (behavior == QStyle::RSIP_OnMouseClickAndAlreadyFocused) { - QCOMPARE(ic.softwareInputPanelEventReceived, false); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); - QApplication::processEvents(); - QCOMPARE(ic.softwareInputPanelEventReceived, true); - } else if (behavior == QStyle::RSIP_OnMouseClick) { - QCOMPARE(ic.softwareInputPanelEventReceived, true); - } + QCOMPARE(ic.openInputPanelReceived, true); + QCOMPARE(ic.closeInputPanelReceived, false); + ic.openInputPanelReceived = false; + + // no events on release + QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, false); + ic.openInputPanelReceived = false; + + // input panel closed on focus lost + edit.setFocus(false); + QApplication::processEvents(); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, true); + ic.closeInputPanelReceived = false; + + // no input panel events if showInputPanelOnFocus is false + edit.setShowInputPanelOnFocus(false); + QCOMPARE(inputPanelonFocusSpy.count(),1); + QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); + QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); + edit.setFocus(false); + edit.setFocus(true); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, false); + + edit.setShowInputPanelOnFocus(false); + QCOMPARE(inputPanelonFocusSpy.count(),1); + + // one show input panel event when openSoftwareInputPanel is called + edit.openSoftwareInputPanel(); + QCOMPARE(ic.openInputPanelReceived, true); + QCOMPARE(ic.closeInputPanelReceived, false); + ic.openInputPanelReceived = false; + + // one close input panel event when closeSoftwareInputPanel is called + edit.closeSoftwareInputPanel(); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, true); + ic.openInputPanelReceived = false; + + // set showInputPanelOnFocus back to true + edit.setShowInputPanelOnFocus(true); + QCOMPARE(inputPanelonFocusSpy.count(),2); + edit.setFocus(false); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, true); + edit.setFocus(true); + QCOMPARE(ic.openInputPanelReceived, true); + QCOMPARE(ic.closeInputPanelReceived, true); + + edit.setShowInputPanelOnFocus(true); + QCOMPARE(inputPanelonFocusSpy.count(),2); } void tst_qdeclarativetextedit::geometrySignals() diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index ac80edb..b3e16c4 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ #include +#include #include "../../../shared/util.h" #include #include @@ -712,11 +713,10 @@ QDeclarativeView *tst_qdeclarativetextinput::createView(const QString &filename) return canvas; } - class MyInputContext : public QInputContext { public: - MyInputContext() : softwareInputPanelEventReceived(false) {} + MyInputContext() : openInputPanelReceived(false), closeInputPanelReceived(false) {} ~MyInputContext() {} QString identifierName() { return QString(); } @@ -729,10 +729,13 @@ public: bool filterEvent( const QEvent *event ) { if (event->type() == QEvent::RequestSoftwareInputPanel) - softwareInputPanelEventReceived = true; + openInputPanelReceived = true; + if (event->type() == QEvent::CloseSoftwareInputPanel) + closeInputPanelReceived = true; return QInputContext::filterEvent(event); } - bool softwareInputPanelEventReceived; + bool openInputPanelReceived; + bool closeInputPanelReceived; }; void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent() @@ -740,10 +743,9 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent() QGraphicsScene scene; QGraphicsView view(&scene); MyInputContext ic; - view.viewport()->setInputContext(&ic); - QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel( - view.style()->styleHint(QStyle::SH_RequestSoftwareInputPanel)); + view.setInputContext(&ic); QDeclarativeTextInput input; + QSignalSpy inputPanelonFocusSpy(&input, SIGNAL(showInputPanelOnFocusChanged(bool))); input.setText("Hello world"); input.setPos(0, 0); scene.addItem(&input); @@ -752,16 +754,68 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent() QApplication::setActiveWindow(&view); QTest::qWaitForWindowShown(&view); QTRY_COMPARE(QApplication::activeWindow(), static_cast(&view)); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); + + QVERIFY(input.showInputPanelOnFocus()); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, false); + + // focus on press, input panel on focus + QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); QApplication::processEvents(); - if (behavior == QStyle::RSIP_OnMouseClickAndAlreadyFocused) { - QCOMPARE(ic.softwareInputPanelEventReceived, false); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); - QApplication::processEvents(); - QCOMPARE(ic.softwareInputPanelEventReceived, true); - } else if (behavior == QStyle::RSIP_OnMouseClick) { - QCOMPARE(ic.softwareInputPanelEventReceived, true); - } + QCOMPARE(ic.openInputPanelReceived, true); + QCOMPARE(ic.closeInputPanelReceived, false); + ic.openInputPanelReceived = false; + + // no events on release + QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, false); + ic.openInputPanelReceived = false; + + // input panel closed on focus lost + input.setFocus(false); + QApplication::processEvents(); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, true); + ic.closeInputPanelReceived = false; + + // no input panel events if showInputPanelOnFocus is false + input.setShowInputPanelOnFocus(false); + QCOMPARE(inputPanelonFocusSpy.count(),1); + QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); + QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); + input.setFocus(false); + input.setFocus(true); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, false); + + input.setShowInputPanelOnFocus(false); + QCOMPARE(inputPanelonFocusSpy.count(),1); + + // one show input panel event when openSoftwareInputPanel is called + input.openSoftwareInputPanel(); + QCOMPARE(ic.openInputPanelReceived, true); + QCOMPARE(ic.closeInputPanelReceived, false); + ic.openInputPanelReceived = false; + + // one close input panel event when closeSoftwareInputPanel is called + input.closeSoftwareInputPanel(); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, true); + ic.openInputPanelReceived = false; + + // set showInputPanelOnFocus back to true + input.setShowInputPanelOnFocus(true); + QCOMPARE(inputPanelonFocusSpy.count(),2); + input.setFocus(false); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, true); + input.setFocus(true); + QCOMPARE(ic.openInputPanelReceived, true); + QCOMPARE(ic.closeInputPanelReceived, true); + + input.setShowInputPanelOnFocus(true); + QCOMPARE(inputPanelonFocusSpy.count(),2); } class MyTextInput : public QDeclarativeTextInput -- cgit v0.12 From 3e3a5a2a2eece6e0eff934c34f25c41699a45b78 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Wed, 26 May 2010 13:35:53 +1000 Subject: Unify naming of import plugin targets Task-number: QTBUG-10834 Reviewed-by: Warwick Allison --- demos/declarative/minehunt/MinehuntCore/qmldir | 2 +- demos/declarative/minehunt/minehunt.pro | 6 +++--- .../cppextensions/imageprovider/ImageProviderCore/qmldir | 2 +- .../declarative/cppextensions/imageprovider/imageprovider.pro | 9 +++++++-- .../cppextensions/plugins/com/nokia/TimeExample/qmldir | 2 +- examples/declarative/cppextensions/plugins/plugin.cpp | 2 +- examples/declarative/cppextensions/plugins/plugins.pro | 2 +- examples/declarative/cppextensions/qwidgets/QWidgets/qmldir | 2 +- examples/declarative/cppextensions/qwidgets/qwidgets.cpp | 2 +- examples/declarative/cppextensions/qwidgets/qwidgets.pro | 10 ++++++++-- src/imports/gestures/gestures.pro | 4 ++-- src/imports/gestures/plugin.cpp | 2 +- src/imports/gestures/qmldir | 2 +- src/imports/particles/particles.cpp | 2 +- src/imports/particles/particles.pro | 4 ++-- src/imports/particles/qmldir | 2 +- src/imports/webkit/plugin.cpp | 2 +- src/imports/webkit/qmldir | 2 +- src/imports/webkit/webkit.pro | 4 ++-- 19 files changed, 37 insertions(+), 26 deletions(-) diff --git a/demos/declarative/minehunt/MinehuntCore/qmldir b/demos/declarative/minehunt/MinehuntCore/qmldir index 95bccc8..2beccf9 100644 --- a/demos/declarative/minehunt/MinehuntCore/qmldir +++ b/demos/declarative/minehunt/MinehuntCore/qmldir @@ -1,3 +1,3 @@ -plugin minehunt +plugin qmlminehuntplugin Explosion 1.0 Explosion.qml Tile 1.0 Tile.qml diff --git a/demos/declarative/minehunt/minehunt.pro b/demos/declarative/minehunt/minehunt.pro index 41640f5..91d02cf 100644 --- a/demos/declarative/minehunt/minehunt.pro +++ b/demos/declarative/minehunt/minehunt.pro @@ -1,5 +1,5 @@ TEMPLATE = lib -TARGET = minehunt +TARGET = qmlminehuntplugin QT += declarative CONFIG += qt plugin @@ -28,11 +28,11 @@ symbian:{ TARGET.EPOCALLOWDLLDATA = 1 include($$QT_SOURCE_TREE/demos/symbianpkgrules.pri) TARGET.CAPABILITY = NetworkServices ReadUserData - importFiles.sources = minehunt.dll \ + importFiles.sources = qmlminehuntplugin.dll \ MinehuntCore/Explosion.qml \ MinehuntCore/pics \ MinehuntCore/qmldir - importFiles.path = $$QT_IMPORTS_BASE_DIR/MinehuntCore + importFiles.path = MinehuntCore DEPLOYMENT = importFiles } diff --git a/examples/declarative/cppextensions/imageprovider/ImageProviderCore/qmldir b/examples/declarative/cppextensions/imageprovider/ImageProviderCore/qmldir index 1028590..6be88bc 100644 --- a/examples/declarative/cppextensions/imageprovider/ImageProviderCore/qmldir +++ b/examples/declarative/cppextensions/imageprovider/ImageProviderCore/qmldir @@ -1,2 +1,2 @@ -plugin imageprovider +plugin qmlimageproviderplugin diff --git a/examples/declarative/cppextensions/imageprovider/imageprovider.pro b/examples/declarative/cppextensions/imageprovider/imageprovider.pro index 462f7d9d..f218c30 100644 --- a/examples/declarative/cppextensions/imageprovider/imageprovider.pro +++ b/examples/declarative/cppextensions/imageprovider/imageprovider.pro @@ -3,7 +3,7 @@ CONFIG += qt plugin QT += declarative DESTDIR = ImageProviderCore -TARGET = imageprovider +TARGET = qmlimageproviderplugin SOURCES += imageprovider.cpp @@ -18,7 +18,12 @@ ImageProviderCore_sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/imageprovid INSTALLS = sources ImageProviderCore_sources target -symbian { +symbian:{ + load(data_caging_paths) include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) TARGET.EPOCALLOWDLLDATA = 1 + + importFiles.sources = qmlimageproviderplugin.dll ImageProviderCore/qmldir + importFiles.path = ImageProviderCore + DEPLOYMENT = importFiles } diff --git a/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/qmldir b/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/qmldir index e9ef115..e1288cf 100644 --- a/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/qmldir +++ b/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/qmldir @@ -1,2 +1,2 @@ Clock 1.0 Clock.qml -plugin qtimeexampleqmlplugin +plugin qmlqtimeexampleplugin diff --git a/examples/declarative/cppextensions/plugins/plugin.cpp b/examples/declarative/cppextensions/plugins/plugin.cpp index 2b1b320..355ca3f 100644 --- a/examples/declarative/cppextensions/plugins/plugin.cpp +++ b/examples/declarative/cppextensions/plugins/plugin.cpp @@ -148,4 +148,4 @@ public: #include "plugin.moc" -Q_EXPORT_PLUGIN2(qtimeexampleqmlplugin, QExampleQmlPlugin); +Q_EXPORT_PLUGIN2(qmlqtimeexampleplugin, QExampleQmlPlugin); diff --git a/examples/declarative/cppextensions/plugins/plugins.pro b/examples/declarative/cppextensions/plugins/plugins.pro index d37ff40..b7610a8 100644 --- a/examples/declarative/cppextensions/plugins/plugins.pro +++ b/examples/declarative/cppextensions/plugins/plugins.pro @@ -3,7 +3,7 @@ CONFIG += qt plugin QT += declarative DESTDIR = com/nokia/TimeExample -TARGET = qtimeexampleqmlplugin +TARGET = qmlqtimeexampleplugin SOURCES += plugin.cpp diff --git a/examples/declarative/cppextensions/qwidgets/QWidgets/qmldir b/examples/declarative/cppextensions/qwidgets/QWidgets/qmldir index e55267c..a7c1d95 100644 --- a/examples/declarative/cppextensions/qwidgets/QWidgets/qmldir +++ b/examples/declarative/cppextensions/qwidgets/QWidgets/qmldir @@ -1 +1 @@ -plugin proxywidgetsplugin +plugin qmlqwidgetsplugin diff --git a/examples/declarative/cppextensions/qwidgets/qwidgets.cpp b/examples/declarative/cppextensions/qwidgets/qwidgets.cpp index 228f9f1..47d3932 100644 --- a/examples/declarative/cppextensions/qwidgets/qwidgets.cpp +++ b/examples/declarative/cppextensions/qwidgets/qwidgets.cpp @@ -94,4 +94,4 @@ public: #include "qwidgets.moc" -Q_EXPORT_PLUGIN2(qwidgetsplugin, QWidgetsPlugin); +Q_EXPORT_PLUGIN2(qmlqwidgetsplugin, QWidgetsPlugin); diff --git a/examples/declarative/cppextensions/qwidgets/qwidgets.pro b/examples/declarative/cppextensions/qwidgets/qwidgets.pro index c5f8bcf..8d87804 100644 --- a/examples/declarative/cppextensions/qwidgets/qwidgets.pro +++ b/examples/declarative/cppextensions/qwidgets/qwidgets.pro @@ -3,7 +3,7 @@ CONFIG += qt plugin QT += declarative DESTDIR = QWidgets -TARGET = qwidgetsplugin +TARGET = qmlqwidgetsplugin SOURCES += qwidgets.cpp @@ -13,7 +13,13 @@ target.path += $$[QT_INSTALL_EXAMPLES]/declarative/plugins INSTALLS += sources target -symbian { +symbian:{ + load(data_caging_paths) include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) TARGET.EPOCALLOWDLLDATA = 1 + + importFiles.sources = qmlqwidgetsplugin.dll QWidgets/qmldir + importFiles.path = QWidgets + + DEPLOYMENT = importFiles } diff --git a/src/imports/gestures/gestures.pro b/src/imports/gestures/gestures.pro index f55c00e..4ef7931 100644 --- a/src/imports/gestures/gestures.pro +++ b/src/imports/gestures/gestures.pro @@ -1,4 +1,4 @@ -TARGET = gesturesqmlplugin +TARGET = qmlgesturesplugin TARGETPATH = Qt/labs/gestures include(../qimportbase.pri) @@ -17,7 +17,7 @@ symbian:{ load(data_caging_paths) include($$QT_SOURCE_TREE/demos/symbianpkgrules.pri) - importFiles.sources = gesturesqmlplugin.dll qmldir + importFiles.sources = qmlgesturesplugin.dll qmldir importFiles.path = $$QT_IMPORTS_BASE_DIR/$$TARGETPATH DEPLOYMENT = importFiles diff --git a/src/imports/gestures/plugin.cpp b/src/imports/gestures/plugin.cpp index b8a9751..11f2392 100644 --- a/src/imports/gestures/plugin.cpp +++ b/src/imports/gestures/plugin.cpp @@ -61,5 +61,5 @@ QT_END_NAMESPACE #include "plugin.moc" -Q_EXPORT_PLUGIN2(gesturesqmlplugin, QT_PREPEND_NAMESPACE(GestureAreaQmlPlugin)); +Q_EXPORT_PLUGIN2(qmlgesturesplugin, QT_PREPEND_NAMESPACE(GestureAreaQmlPlugin)); diff --git a/src/imports/gestures/qmldir b/src/imports/gestures/qmldir index 9d9d587..2a31920 100644 --- a/src/imports/gestures/qmldir +++ b/src/imports/gestures/qmldir @@ -1 +1 @@ -plugin gesturesqmlplugin +plugin qmlgesturesplugin diff --git a/src/imports/particles/particles.cpp b/src/imports/particles/particles.cpp index ae3f318..ca2b060 100644 --- a/src/imports/particles/particles.cpp +++ b/src/imports/particles/particles.cpp @@ -65,5 +65,5 @@ QT_END_NAMESPACE #include "particles.moc" -Q_EXPORT_PLUGIN2(particlesqmlmodule, QT_PREPEND_NAMESPACE(QParticlesQmlModule)); +Q_EXPORT_PLUGIN2(qmlparticlesplugin, QT_PREPEND_NAMESPACE(QParticlesQmlModule)); diff --git a/src/imports/particles/particles.pro b/src/imports/particles/particles.pro index 79ac543..9fd4db5 100644 --- a/src/imports/particles/particles.pro +++ b/src/imports/particles/particles.pro @@ -1,4 +1,4 @@ -TARGET = particles +TARGET = qmlparticlesplugin TARGETPATH = Qt/labs/particles include(../qimportbase.pri) @@ -21,7 +21,7 @@ symbian:{ load(data_caging_paths) include($$QT_SOURCE_TREE/demos/symbianpkgrules.pri) - importFiles.sources = particles.dll qmldir + importFiles.sources = qmlparticlesplugin.dll qmldir importFiles.path = $$QT_IMPORTS_BASE_DIR/$$TARGETPATH DEPLOYMENT = importFiles diff --git a/src/imports/particles/qmldir b/src/imports/particles/qmldir index 15456bb..aeebd2c 100644 --- a/src/imports/particles/qmldir +++ b/src/imports/particles/qmldir @@ -1 +1 @@ -plugin particles +plugin qmlparticlesplugin diff --git a/src/imports/webkit/plugin.cpp b/src/imports/webkit/plugin.cpp index e3d73ec..c8e56ba 100644 --- a/src/imports/webkit/plugin.cpp +++ b/src/imports/webkit/plugin.cpp @@ -63,5 +63,5 @@ QT_END_NAMESPACE #include "plugin.moc" -Q_EXPORT_PLUGIN2(webkitqmlplugin, QT_PREPEND_NAMESPACE(WebKitQmlPlugin)); +Q_EXPORT_PLUGIN2(qmlwebkitplugin, QT_PREPEND_NAMESPACE(WebKitQmlPlugin)); diff --git a/src/imports/webkit/qmldir b/src/imports/webkit/qmldir index 258aa2c..dcfdd06 100644 --- a/src/imports/webkit/qmldir +++ b/src/imports/webkit/qmldir @@ -1 +1 @@ -plugin webkitqmlplugin +plugin qmlwebkitplugin diff --git a/src/imports/webkit/webkit.pro b/src/imports/webkit/webkit.pro index 77cbc4d..7b2ac66 100644 --- a/src/imports/webkit/webkit.pro +++ b/src/imports/webkit/webkit.pro @@ -1,4 +1,4 @@ -TARGET = webkitqmlplugin +TARGET = qmlwebkitplugin TARGETPATH = org/webkit include(../qimportbase.pri) @@ -18,7 +18,7 @@ symbian:{ load(data_caging_paths) include($$QT_SOURCE_TREE/demos/symbianpkgrules.pri) - importFiles.sources = webkitqmlplugin.dll qmldir + importFiles.sources = qmlwebkitplugin.dll qmldir importFiles.path = $$QT_IMPORTS_BASE_DIR/$$TARGETPATH DEPLOYMENT = importFiles -- cgit v0.12 From dc08c8bc7aba55ff4762d70b193a053ad210fb60 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Wed, 26 May 2010 14:31:08 +1000 Subject: Fix for qml reloaded in qml viewer not being maximized properly on a device Task-number: Reviewed-by: Martin Jones --- tools/qml/qmlruntime.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 5308e98..fe323c1 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -808,7 +808,9 @@ void QDeclarativeViewer::statusChanged() initialSize = canvas->sizeHint(); if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) { updateSizeHints(); - resize(QSize(initialSize.width(), initialSize.height()+menuBarHeight())); + if (!isFullScreen() && !isMaximized()) { + resize(QSize(initialSize.width(), initialSize.height()+menuBarHeight())); + } } } } -- cgit v0.12 From e9a25332df933227c6b71a1654260d8421f56415 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 26 May 2010 15:15:45 +1000 Subject: Fix TextEdit clipping when not wrapped. Rename most-useful-wrap-mode to "Wrap". --- .../twitter/TwitterCore/HomeTitleBar.qml | 2 +- doc/src/snippets/declarative/texteditor.qml | 8 ++-- .../graphicsitems/qdeclarativepainteditem.cpp | 17 ++++++-- .../graphicsitems/qdeclarativepainteditem_p.h | 1 + src/declarative/graphicsitems/qdeclarativetext.cpp | 37 ++++++++++++++---- src/declarative/graphicsitems/qdeclarativetext_p.h | 9 ++++- .../graphicsitems/qdeclarativetextedit.cpp | 45 +++++++++++++++++----- .../graphicsitems/qdeclarativetextedit_p.h | 9 ++++- .../qmlvisual/qdeclarativetext/font/plaintext.qml | 2 +- .../qmlvisual/qdeclarativetext/font/richtext.qml | 2 +- .../qmlvisual/qdeclarativetextedit/wrap.qml | 2 +- 11 files changed, 104 insertions(+), 30 deletions(-) diff --git a/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml b/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml index 2eaa40c..3828a40 100644 --- a/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml +++ b/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml @@ -129,7 +129,7 @@ Item { width: parent.width - 12 height: parent.height - 8 font.pointSize: 10 - wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere + wrapMode: TextEdit.Wrap color: "#151515"; selectionColor: "green" } Keys.forwardTo: [(returnKey), (editor)] diff --git a/doc/src/snippets/declarative/texteditor.qml b/doc/src/snippets/declarative/texteditor.qml index 0bd79b5..6735c6c 100644 --- a/doc/src/snippets/declarative/texteditor.qml +++ b/doc/src/snippets/declarative/texteditor.qml @@ -45,7 +45,8 @@ Flickable { id: flick width: 300; height: 200; - contentHeight: edit.height + contentWidth: edit.paintedWidth + contentHeight: edit.paintedHeight clip: true function ensureVisible(r) @@ -62,9 +63,10 @@ Flickable { TextEdit { id: edit - width: parent.width + width: flick.width + height: flick.height focus: true - wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere + wrapMode: TextEdit.Wrap onCursorRectangleChanged: flick.ensureVisible(cursorRectangle) } } diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp index c4f0b86..13d1b61 100644 --- a/src/declarative/graphicsitems/qdeclarativepainteditem.cpp +++ b/src/declarative/graphicsitems/qdeclarativepainteditem.cpp @@ -152,8 +152,6 @@ void QDeclarativePaintedItem::setContentsSize(const QSize &size) Q_D(QDeclarativePaintedItem); if (d->contentsSize == size) return; d->contentsSize = size; - setImplicitWidth(size.width()*d->contentsScale); - setImplicitHeight(size.height()*d->contentsScale); clearCache(); update(); emit contentsSizeChanged(); @@ -170,8 +168,6 @@ void QDeclarativePaintedItem::setContentsScale(qreal scale) Q_D(QDeclarativePaintedItem); if (d->contentsScale == scale) return; d->contentsScale = scale; - setImplicitWidth(d->contentsSize.width()*scale); - setImplicitHeight(d->contentsSize.height()*scale); clearCache(); update(); emit contentsScaleChanged(); @@ -232,6 +228,19 @@ void QDeclarativePaintedItem::setCacheFrozen(bool frozen) // XXX clear cache? } +QRectF QDeclarativePaintedItem::boundingRect() const +{ + Q_D(const QDeclarativePaintedItem); + qreal w = d->mWidth; + QSizeF sz = d->contentsSize * d->contentsScale; + if (w < sz.width()) + w = sz.width(); + qreal h = d->mHeight; + if (h < sz.height()) + h = sz.height(); + return QRectF(0.0,0.0,w,h); +} + /*! \internal */ diff --git a/src/declarative/graphicsitems/qdeclarativepainteditem_p.h b/src/declarative/graphicsitems/qdeclarativepainteditem_p.h index 8d08ba2..86f065a 100644 --- a/src/declarative/graphicsitems/qdeclarativepainteditem_p.h +++ b/src/declarative/graphicsitems/qdeclarativepainteditem_p.h @@ -93,6 +93,7 @@ protected: const QVariant &value); void setCacheFrozen(bool); + QRectF boundingRect() const; Q_SIGNALS: void fillColorChanged(); diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 4e7e0fd..2c1eb67 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -499,13 +499,10 @@ void QDeclarativeText::setVAlign(VAlignment align) wrap if an explicit width has been set. wrapMode can be one of: \list - \o Text.NoWrap - no wrapping will be performed. - \o Text.WordWrap - wrapping is done on word boundaries. If the text cannot be - word-wrapped to the specified width it will be partially drawn outside of the item's bounds. - If this is undesirable then enable clipping on the item (Item::clip). - \o Text.WrapAnywhere - Text can be wrapped at any point on a line, even if it occurs in the middle of a word. - \o Text.WrapAtWordBoundaryOrAnywhere - If possible, wrapping occurs at a word boundary; otherwise it - will occur at the appropriate point on the line, even in the middle of a word. + \o Text.NoWrap - no wrapping will be performed. If the text contains insufficient newlines, then implicitWidth will exceed a set width. + \o Text.WordWrap - wrapping is done on word boundaries only. If a word is too long, implicitWidth will exceed a set width. + \o Text.WrapAnywhere - wrapping is done at any point on a line, even if it occurs in the middle of a word. + \o Text.Wrap - if possible, wrapping occurs at a word boundary; otherwise it will occur at the appropriate point on the line, even in the middle of a word. \endlist The default is Text.NoWrap. @@ -715,6 +712,7 @@ void QDeclarativeTextPrivate::updateSize() QFontMetrics fm(font); if (text.isEmpty()) { q->setImplicitHeight(fm.height()); + emit q->paintedSizeChanged(); return; } @@ -753,11 +751,36 @@ void QDeclarativeTextPrivate::updateSize() //### 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()); + emit q->paintedSizeChanged(); } else { dirty = true; } } +/*! + \qmlproperty real Text::paintedWidth + + Returns the width of the text, including width past the width + which is covered due to insufficient wrapping if WrapMode is set. +*/ +qreal QDeclarativeText::paintedWidth() const +{ + return implicitWidth(); +} + +/*! + \qmlproperty real Text::paintedHeight + + Returns the height of the text, including height past the height + which is covered due to there being more text than fits in the set height. +*/ +qreal QDeclarativeText::paintedHeight() const +{ + return implicitHeight(); +} + + + // ### text layout handling should be profiled and optimized as needed // what about QStackTextEngine engine(tmp, d->font.font()); QTextLayout textLayout(&engine); diff --git a/src/declarative/graphicsitems/qdeclarativetext_p.h b/src/declarative/graphicsitems/qdeclarativetext_p.h index 00ce126..db21140 100644 --- a/src/declarative/graphicsitems/qdeclarativetext_p.h +++ b/src/declarative/graphicsitems/qdeclarativetext_p.h @@ -71,6 +71,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativeText : public QDeclarativeItem Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged) Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged) Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode NOTIFY elideModeChanged) //### elideMode? + Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged) + Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged) public: QDeclarativeText(QDeclarativeItem *parent=0); @@ -98,7 +100,8 @@ public: enum WrapMode { NoWrap = QTextOption::NoWrap, WordWrap = QTextOption::WordWrap, WrapAnywhere = QTextOption::WrapAnywhere, - WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere + WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT + Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere }; QString text() const; @@ -137,6 +140,9 @@ public: int resourcesLoading() const; // mainly for testing + qreal paintedWidth() const; + qreal paintedHeight() const; + Q_SIGNALS: void textChanged(const QString &text); void linkActivated(const QString &link); @@ -149,6 +155,7 @@ Q_SIGNALS: void wrapModeChanged(); void textFormatChanged(TextFormat textFormat); void elideModeChanged(TextElideMode mode); + void paintedSizeChanged(); protected: void mousePressEvent(QGraphicsSceneMouseEvent *event); diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index a154d53..f105171 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -484,14 +484,13 @@ void QDeclarativeTextEdit::setVAlign(QDeclarativeTextEdit::VAlignment alignment) The text will only wrap if an explicit width has been set. \list - \o TextEdit.NoWrap - no wrapping will be performed. - \o TextEdit.WordWrap - wrapping is done on word boundaries. - \o TextEdit.WrapAnywhere - Text can be wrapped at any point on a line, even if it occurs in the middle of a word. - \o TextEdit.WrapAtWordBoundaryOrAnywhere - If possible, wrapping occurs at a word boundary; otherwise it - will occur at the appropriate point on the line, even in the middle of a word. + \o TextEdit.NoWrap - no wrapping will be performed. If the text contains insufficient newlines, then implicitWidth will exceed a set width. + \o TextEdit.WordWrap - wrapping is done on word boundaries only. If a word is too long, implicitWidth will exceed a set width. + \o TextEdit.WrapAnywhere - wrapping is done at any point on a line, even if it occurs in the middle of a word. + \o TextEdit.Wrap - if possible, wrapping occurs at a word boundary; otherwise it will occur at the appropriate point on the line, even in the middle of a word. \endlist - The default is TextEdit.NoWrap. + The default is TextEdit.NoWrap. If you set a width, consider using TextEdit.Wrap. */ QDeclarativeTextEdit::WrapMode QDeclarativeTextEdit::wrapMode() const { @@ -511,6 +510,29 @@ void QDeclarativeTextEdit::setWrapMode(WrapMode mode) } /*! + \qmlproperty real TextEdit::paintedWidth + + Returns the width of the text, including width past the width + which is covered due to insufficient wrapping if WrapMode is set. +*/ +qreal QDeclarativeTextEdit::paintedWidth() const +{ + return implicitWidth(); +} + +/*! + \qmlproperty real TextEdit::paintedHeight + + Returns the height of the text, including height past the height + which is covered due to there being more text than fits in the set height. +*/ +qreal QDeclarativeTextEdit::paintedHeight() const +{ + return implicitHeight(); +} + + +/*! \qmlproperty bool TextEdit::cursorVisible If true the text edit shows a cursor. @@ -1156,7 +1178,7 @@ void QDeclarativeTextEdit::updateSize() int dy = height(); // ### assumes that if the width is set, the text will fill to edges // ### (unless wrap is false, then clipping will occur) - if (widthValid()) + if (widthValid() && d->document->textWidth() != width()) d->document->setTextWidth(width()); dy -= (int)d->document->size().height(); @@ -1172,7 +1194,7 @@ void QDeclarativeTextEdit::updateSize() //### need to comfirm cost of always setting these int newWidth = qCeil(d->document->idealWidth()); - if (!widthValid()) + if (!widthValid() && d->document->textWidth() != newWidth) d->document->setTextWidth(newWidth); // ### Text does not align if width is not set (QTextDoc bug) int cursorWidth = 1; if(d->cursor) @@ -1182,9 +1204,12 @@ void QDeclarativeTextEdit::updateSize() newWidth += 3;// ### Need a better way of accounting for space between char and cursor // ### Setting the implicitWidth triggers another updateSize(), and unless there are bindings nothing has changed. setImplicitWidth(newWidth); - setImplicitHeight(d->document->isEmpty() ? fm.height() : (int)d->document->size().height()); + qreal newHeight = d->document->isEmpty() ? fm.height() : (int)d->document->size().height(); + setImplicitHeight(newHeight); + + setContentsSize(QSize(newWidth, newHeight)); - setContentsSize(QSize(width(), height())); + emit paintedSizeChanged(); } else { d->dirty = true; } diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h index 891b868..51bb974 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h @@ -74,6 +74,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTextEdit : public QDeclarativePaintedItem Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign NOTIFY horizontalAlignmentChanged) Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged) Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged) + Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged) + Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged) Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged) Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged) Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged) @@ -113,7 +115,8 @@ public: enum WrapMode { NoWrap = QTextOption::NoWrap, WordWrap = QTextOption::WordWrap, WrapAnywhere = QTextOption::WrapAnywhere, - WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere + WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT + Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere }; QString text() const; @@ -185,8 +188,12 @@ public: QVariant inputMethodQuery(Qt::InputMethodQuery property) const; + qreal paintedWidth() const; + qreal paintedHeight() const; + Q_SIGNALS: void textChanged(const QString &); + void paintedSizeChanged(); void cursorPositionChanged(); void cursorRectangleChanged(); void selectionStartChanged(); diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml index d948e4a..73dd4d7 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml @@ -85,7 +85,7 @@ Rectangle { text: s.text + " thisisaverylongstringwithnospaces"; width: 150; wrapMode: Text.WrapAnywhere } Text { - text: s.text + " thisisaverylongstringwithnospaces"; width: 150; wrapMode: Text.WrapAtWordBoundaryOrAnywhere + text: s.text + " thisisaverylongstringwithnospaces"; width: 150; wrapMode: Text.Wrap } } } diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml index d10cfd3..b41b93a 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml @@ -85,7 +85,7 @@ Rectangle { text: s.text + " thisisaverylongstringwithnospaces"; width: 150; wrapMode: Text.WrapAnywhere } Text { - text: s.text + " thisisaverylongstringwithnospaces"; width: 150; wrapMode: Text.WrapAtWordBoundaryOrAnywhere + text: s.text + " thisisaverylongstringwithnospaces"; width: 150; wrapMode: Text.Wrap } } } diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml index abb4464..a1dc5bf 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml @@ -27,7 +27,7 @@ Item { TextEdit { width: 150 height: 100 - wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere + wrapMode: TextEdit.Wrap text: "This is a test that text edit wraps correctly. thisisaverylongstringwithnospaces" y:300 } -- cgit v0.12 From ef2bc487ab9b66e052920b671e947abc4a6d8ef4 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 26 May 2010 14:28:23 +1000 Subject: Fix horizontal/verticalCenter anchors bug. Task-number: QTBUG-10999 Reviewed-by: Michael Brasser --- .../graphicsitems/qdeclarativeanchors.cpp | 34 +++++++++++----------- .../graphicsitems/qdeclarativeanchors_p_p.h | 2 +- .../qdeclarativeanchors/data/hvCenter.qml | 11 +++++++ .../tst_qdeclarativeanchors.cpp | 14 +++++++++ 4 files changed, 43 insertions(+), 18 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeanchors/data/hvCenter.qml diff --git a/src/declarative/graphicsitems/qdeclarativeanchors.cpp b/src/declarative/graphicsitems/qdeclarativeanchors.cpp index ef07cbb..aa53aba 100644 --- a/src/declarative/graphicsitems/qdeclarativeanchors.cpp +++ b/src/declarative/graphicsitems/qdeclarativeanchors.cpp @@ -92,17 +92,17 @@ static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine //position when origin is 0,0 static qreal adjustedPosition(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine) { - int ret = 0; + qreal ret = 0.0; QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(item); switch(anchorLine) { case QDeclarativeAnchorLine::Left: - ret = 0; + ret = 0.0; break; case QDeclarativeAnchorLine::Right: ret = d->width(); break; case QDeclarativeAnchorLine::Top: - ret = 0; + ret = 0.0; break; case QDeclarativeAnchorLine::Bottom: ret = d->height(); @@ -459,10 +459,10 @@ void QDeclarativeAnchors::resetCenterIn() bool QDeclarativeAnchorsPrivate::calcStretch(const QDeclarativeAnchorLine &edge1, const QDeclarativeAnchorLine &edge2, - int offset1, - int offset2, + qreal offset1, + qreal offset2, QDeclarativeAnchorLine::AnchorLine line, - int &stretch) + qreal &stretch) { bool edge1IsParent = (edge1.item == item->parentItem()); bool edge2IsParent = (edge2.item == item->parentItem()); @@ -471,15 +471,15 @@ bool QDeclarativeAnchorsPrivate::calcStretch(const QDeclarativeAnchorLine &edge1 bool invalid = false; if ((edge2IsParent && edge1IsParent) || (edge2IsSibling && edge1IsSibling)) { - stretch = ((int)position(edge2.item, edge2.anchorLine) + offset2) - - ((int)position(edge1.item, edge1.anchorLine) + offset1); + stretch = (position(edge2.item, edge2.anchorLine) + offset2) + - (position(edge1.item, edge1.anchorLine) + offset1); } else if (edge2IsParent && edge1IsSibling) { - stretch = ((int)position(edge2.item, edge2.anchorLine) + offset2) - - ((int)position(item->parentObject(), line) - + (int)position(edge1.item, edge1.anchorLine) + offset1); + stretch = (position(edge2.item, edge2.anchorLine) + offset2) + - (position(item->parentObject(), line) + + position(edge1.item, edge1.anchorLine) + offset1); } else if (edge2IsSibling && edge1IsParent) { - stretch = ((int)position(item->parentObject(), line) + (int)position(edge2.item, edge2.anchorLine) + offset2) - - ((int)position(edge1.item, edge1.anchorLine) + offset1); + stretch = (position(item->parentObject(), line) + position(edge2.item, edge2.anchorLine) + offset2) + - (position(edge1.item, edge1.anchorLine) + offset1); } else invalid = true; @@ -497,7 +497,7 @@ void QDeclarativeAnchorsPrivate::updateVerticalAnchors() if (usedAnchors & QDeclarativeAnchors::TopAnchor) { //Handle stretching bool invalid = true; - int height = 0; + qreal height = 0.0; if (usedAnchors & QDeclarativeAnchors::BottomAnchor) { invalid = calcStretch(top, bottom, topMargin, -bottomMargin, QDeclarativeAnchorLine::Top, height); } else if (usedAnchors & QDeclarativeAnchors::VCenterAnchor) { @@ -516,7 +516,7 @@ void QDeclarativeAnchorsPrivate::updateVerticalAnchors() } else if (usedAnchors & QDeclarativeAnchors::BottomAnchor) { //Handle stretching (top + bottom case is handled above) if (usedAnchors & QDeclarativeAnchors::VCenterAnchor) { - int height = 0; + qreal height = 0.0; bool invalid = calcStretch(vCenter, bottom, vCenterOffset, -bottomMargin, QDeclarativeAnchorLine::Top, height); if (!invalid) @@ -569,7 +569,7 @@ void QDeclarativeAnchorsPrivate::updateHorizontalAnchors() if (usedAnchors & QDeclarativeAnchors::LeftAnchor) { //Handle stretching bool invalid = true; - int width = 0; + qreal width = 0.0; if (usedAnchors & QDeclarativeAnchors::RightAnchor) { invalid = calcStretch(left, right, leftMargin, -rightMargin, QDeclarativeAnchorLine::Left, width); } else if (usedAnchors & QDeclarativeAnchors::HCenterAnchor) { @@ -588,7 +588,7 @@ void QDeclarativeAnchorsPrivate::updateHorizontalAnchors() } else if (usedAnchors & QDeclarativeAnchors::RightAnchor) { //Handle stretching (left + right case is handled in updateLeftAnchor) if (usedAnchors & QDeclarativeAnchors::HCenterAnchor) { - int width = 0; + qreal width = 0.0; bool invalid = calcStretch(hCenter, right, hCenterOffset, -rightMargin, QDeclarativeAnchorLine::Left, width); if (!invalid) diff --git a/src/declarative/graphicsitems/qdeclarativeanchors_p_p.h b/src/declarative/graphicsitems/qdeclarativeanchors_p_p.h index 05be6c5..1bbea36 100644 --- a/src/declarative/graphicsitems/qdeclarativeanchors_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeanchors_p_p.h @@ -131,7 +131,7 @@ public: bool checkVValid() const; bool checkHAnchorValid(QDeclarativeAnchorLine anchor) const; bool checkVAnchorValid(QDeclarativeAnchorLine anchor) const; - bool calcStretch(const QDeclarativeAnchorLine &edge1, const QDeclarativeAnchorLine &edge2, int offset1, int offset2, QDeclarativeAnchorLine::AnchorLine line, int &stretch); + bool calcStretch(const QDeclarativeAnchorLine &edge1, const QDeclarativeAnchorLine &edge2, qreal offset1, qreal offset2, QDeclarativeAnchorLine::AnchorLine line, qreal &stretch); void updateHorizontalAnchors(); void updateVerticalAnchors(); diff --git a/tests/auto/declarative/qdeclarativeanchors/data/hvCenter.qml b/tests/auto/declarative/qdeclarativeanchors/data/hvCenter.qml new file mode 100644 index 0000000..7cd4f26 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeanchors/data/hvCenter.qml @@ -0,0 +1,11 @@ +import Qt 4.7 + +Rectangle { + width: 77; height: 95 + Rectangle { + objectName: "centered" + width: 57; height: 57; color: "blue" + anchors.verticalCenter: parent.verticalCenter + anchors.horizontalCenter: parent.horizontalCenter + } +} diff --git a/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp b/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp index e169fa2..22f7966 100644 --- a/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp +++ b/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp @@ -77,6 +77,7 @@ private slots: void nullItem_data(); void crash1(); void centerIn(); + void hvCenter(); void fill(); void margins(); }; @@ -526,6 +527,19 @@ void tst_qdeclarativeanchors::centerIn() delete view; } +void tst_qdeclarativeanchors::hvCenter() +{ + QDeclarativeView *view = new QDeclarativeView(QUrl::fromLocalFile(SRCDIR "/data/hvCenter.qml")); + + qApp->processEvents(); + QDeclarativeRectangle* rect = findItem(view->rootObject(), QLatin1String("centered")); + QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect); + // test QTBUG-10999 + QCOMPARE(rect->x(), 10.0); + QCOMPARE(rect->y(), 19.0); + delete view; +} + void tst_qdeclarativeanchors::margins() { QDeclarativeView *view = new QDeclarativeView(QUrl::fromLocalFile(SRCDIR "/data/margins.qml")); -- cgit v0.12 From 1256a212460438462367b48de086ab690f722be5 Mon Sep 17 00:00:00 2001 From: Joona Petrell Date: Wed, 26 May 2010 16:26:19 +1000 Subject: Open input panel on press if TextInput or TextEdit are already focused but panel has been closed Task-number: Reviewed-by: Martin Jones --- src/declarative/graphicsitems/qdeclarativetextedit.cpp | 5 +++++ src/declarative/graphicsitems/qdeclarativetextinput.cpp | 5 +++++ .../qdeclarativetextedit/tst_qdeclarativetextedit.cpp | 9 +++++++++ .../qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 9 +++++++++ 4 files changed, 28 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 348a8bd..167db77 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -963,6 +963,7 @@ void QDeclarativeTextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativeTextEdit); if (d->focusOnPress){ + bool hadFocus = hasFocus(); QGraphicsItem *p = parentItem();//###Is there a better way to find my focus scope? while(p) { if (p->flags() & QGraphicsItem::ItemIsFocusScope) @@ -970,6 +971,10 @@ void QDeclarativeTextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) p = p->parentItem(); } setFocus(true); + if (hasFocus() == hadFocus && d->showInputPanelOnFocus && !isReadOnly()) { + // re-open input panel on press if already focused + openSoftwareInputPanel(); + } } if (event->type() != QEvent::GraphicsSceneMouseDoubleClick || d->selectByMouse) d->control->processEvent(event, QPointF(0, -d->yoff)); diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 47cd110..18e3595 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -887,6 +887,7 @@ void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativeTextInput); if(d->focusOnPress){ + bool hadFocus = hasFocus(); QGraphicsItem *p = parentItem();//###Is there a better way to find my focus scope? while(p) { if (p->flags() & QGraphicsItem::ItemIsFocusScope) @@ -894,6 +895,10 @@ void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) p = p->parentItem(); } setFocus(true); + if (hasFocus() == hadFocus && d->showInputPanelOnFocus && !isReadOnly()) { + // re-open input panel on press w already focused + openSoftwareInputPanel(); + } } bool mark = event->modifiers() & Qt::ShiftModifier; diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 2b6f2aa..0df28d0 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -858,6 +858,7 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() // focus on press, input panel on focus QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); QApplication::processEvents(); + QVERIFY(edit.hasFocus()); QCOMPARE(ic.openInputPanelReceived, true); QCOMPARE(ic.closeInputPanelReceived, false); ic.openInputPanelReceived = false; @@ -868,6 +869,14 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() QCOMPARE(ic.closeInputPanelReceived, false); ic.openInputPanelReceived = false; + // Even with focus already gained, user needs + // to be able to open panel by pressing on the editor + QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); + QApplication::processEvents(); + QCOMPARE(ic.openInputPanelReceived, true); + QCOMPARE(ic.closeInputPanelReceived, false); + ic.openInputPanelReceived = false; + // input panel closed on focus lost edit.setFocus(false); QApplication::processEvents(); diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index b3e16c4..155223d 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -762,6 +762,7 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent() // focus on press, input panel on focus QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); QApplication::processEvents(); + QVERIFY(input.hasFocus()); QCOMPARE(ic.openInputPanelReceived, true); QCOMPARE(ic.closeInputPanelReceived, false); ic.openInputPanelReceived = false; @@ -772,6 +773,14 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent() QCOMPARE(ic.closeInputPanelReceived, false); ic.openInputPanelReceived = false; + // Even with focus already gained, user needs + // to be able to open panel by pressing on the editor + QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); + QApplication::processEvents(); + QCOMPARE(ic.openInputPanelReceived, true); + QCOMPARE(ic.closeInputPanelReceived, false); + ic.openInputPanelReceived = false; + // input panel closed on focus lost input.setFocus(false); QApplication::processEvents(); -- cgit v0.12 From b930d1a26b0c5999c205f224d75d7de6fa40699c Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 26 May 2010 13:35:11 +1000 Subject: Add more examples of XPath expressions to XmlRole. Task-number: QTBUG-10852 --- doc/src/snippets/declarative/xmlrole.qml | 81 +++++++++++++++++++++++ doc/src/snippets/declarative/xmlrole.xml | 14 ++++ src/declarative/util/qdeclarativexmllistmodel.cpp | 33 ++++++--- 3 files changed, 118 insertions(+), 10 deletions(-) create mode 100644 doc/src/snippets/declarative/xmlrole.qml create mode 100644 doc/src/snippets/declarative/xmlrole.xml diff --git a/doc/src/snippets/declarative/xmlrole.qml b/doc/src/snippets/declarative/xmlrole.qml new file mode 100644 index 0000000..6d04daf --- /dev/null +++ b/doc/src/snippets/declarative/xmlrole.qml @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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 QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt 4.7 + +Rectangle { + width: 300; height: 200 + +//![0] +XmlListModel { + id: model +//![0] + source: "xmlrole.xml" + +//![1] + // XmlRole queries will be made on elements + query: "/catalogue/book" + + // query the book title + XmlRole { name: "title"; query: "title/string()" } + + // query the book's year + XmlRole { name: "year"; query: "year/number()" } + + // query the book's type (the '@' indicates 'type' is an attribute, not an element) + XmlRole { name: "type"; query: "@type/string()" } + + // query the book's first listed author (note in XPath the first index is 1, not 0) + XmlRole { name: "first_author"; query: "author[1]/string()" } +} +//![1] + +ListView { + width: 300; height: 200 + model: model + delegate: Column { + Text { text: title + " (" + type + ")"; font.bold: true } + Text { text: first_author } + Text { text: year } + } +} + +} diff --git a/doc/src/snippets/declarative/xmlrole.xml b/doc/src/snippets/declarative/xmlrole.xml new file mode 100644 index 0000000..c9f999e --- /dev/null +++ b/doc/src/snippets/declarative/xmlrole.xml @@ -0,0 +1,14 @@ + + + + C++ GUI Programming with Qt 4 + 2006 + Jasmin Blanchette + Mark Summerfield + + + Programming with Qt + 2002 + Matthias Kalle Dalheimer + + diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index d08e37b..4f9355b 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -80,7 +80,11 @@ typedef QPair QDeclarativeXmlListRange; /*! \qmlproperty string XmlRole::name - The name for the role. This name is used to access the model data for this role from Qml. + + The name for the role. This name is used to access the model data for this role. + + For example, the following model has a role named "title", which can be accessed + from the view's delegate: \qml XmlListModel { @@ -91,19 +95,27 @@ typedef QPair QDeclarativeXmlListRange; ListView { model: xmlModel - Text { text: title } + delegate: Text { text: title } } \endqml */ /*! \qmlproperty string XmlRole::query - The relative XPath query for this role. The query should not start with a '/' (i.e. it must be - relative). + The relative XPath expression query for this role. The query must be relative; it cannot start + with a '/'. - \qml - XmlRole { name: "title"; query: "title/string()" } - \endqml + For example, if there is an XML document like this: + + \quotefile doc/src/snippets/declarative/xmlrole.xml + + Here are some valid XPath expressions for XmlRole queries on this document: + + \snippet doc/src/snippets/declarative/xmlrole.qml 0 + \dots 4 + \snippet doc/src/snippets/declarative/xmlrole.qml 1 + + See the \l{http://www.w3.org/TR/xpath20/}{W3C XPath 2.0 specification} for more information. */ /*! @@ -521,9 +533,12 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty in the XML document. The XmlRole objects define the + a model item for each \c in the XML document. + + The XmlRole objects define the model item attributes; here, each model item will have \c title and \c pubDate attributes that match the \c title and \c pubDate values of its corresponding \c . + (See \l XmlRole::query for more examples of valid XPath expressions for XmlRole.) The model could be used in a ListView, like this: @@ -559,8 +574,6 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty Date: Wed, 26 May 2010 14:47:11 +1000 Subject: Allow js files with '.pragma library' to be used from WorkerScript --- src/declarative/qml/qdeclarativeworkerscript.cpp | 1 + .../qdeclarativeworkerscript/data/BaseWorker.qml | 24 ++++++++++++ .../qdeclarativeworkerscript/data/script.js | 1 - .../data/script_fixed_return.js | 4 ++ .../qdeclarativeworkerscript/data/script_pragma.js | 6 +++ .../qdeclarativeworkerscript/data/worker.qml | 21 +---------- .../data/worker_pragma.qml | 6 +++ .../tst_qdeclarativeworkerscript.cpp | 43 ++++++++++++++++++---- 8 files changed, 77 insertions(+), 29 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeworkerscript/data/BaseWorker.qml create mode 100644 tests/auto/declarative/qdeclarativeworkerscript/data/script_fixed_return.js create mode 100644 tests/auto/declarative/qdeclarativeworkerscript/data/script_pragma.js create mode 100644 tests/auto/declarative/qdeclarativeworkerscript/data/worker_pragma.qml diff --git a/src/declarative/qml/qdeclarativeworkerscript.cpp b/src/declarative/qml/qdeclarativeworkerscript.cpp index 1550351..2ca030e 100644 --- a/src/declarative/qml/qdeclarativeworkerscript.cpp +++ b/src/declarative/qml/qdeclarativeworkerscript.cpp @@ -295,6 +295,7 @@ void QDeclarativeWorkerScriptEnginePrivate::processLoad(int id, const QUrl &url) ctxt->pushScope(urlContext); ctxt->pushScope(activation); ctxt->setActivationObject(activation); + QDeclarativeScriptParser::extractPragmas(script); workerEngine->baseUrl = url; workerEngine->evaluate(script); diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/BaseWorker.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/BaseWorker.qml new file mode 100644 index 0000000..d275ca8 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/BaseWorker.qml @@ -0,0 +1,24 @@ +import Qt 4.7 + +WorkerScript { + id: worker + + property variant response + + signal done() + + function testSend(value) { + worker.sendMessage(value) + } + + function compareLiteralResponse(expected) { + var e = eval('(' + expected + ')') + return worker.response == e + } + + onMessage: { + worker.response = messageObject + worker.done() + } +} + diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/script.js b/tests/auto/declarative/qdeclarativeworkerscript/data/script.js index 09199de..90aae26 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/data/script.js +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/script.js @@ -2,4 +2,3 @@ WorkerScript.onMessage = function(msg) { WorkerScript.sendMessage(msg) } - diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/script_fixed_return.js b/tests/auto/declarative/qdeclarativeworkerscript/data/script_fixed_return.js new file mode 100644 index 0000000..14f6f17 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/script_fixed_return.js @@ -0,0 +1,4 @@ +WorkerScript.onMessage = function(msg) { + WorkerScript.sendMessage('Hello_World') +} + diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/script_pragma.js b/tests/auto/declarative/qdeclarativeworkerscript/data/script_pragma.js new file mode 100644 index 0000000..cb3b6d3 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/script_pragma.js @@ -0,0 +1,6 @@ +.pragma library + +WorkerScript.onMessage = function(msg) { + WorkerScript.sendMessage(msg) +} + diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml index 5c7a5ff..1a20098 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/worker.qml @@ -1,24 +1,5 @@ import Qt 4.7 -WorkerScript { - id: worker +BaseWorker { source: "script.js" - - property variant response - - signal done() - - function testSend(value) { - worker.sendMessage(value) - } - - function compareLiteralResponse(expected) { - var e = eval('(' + expected + ')') - return worker.response == e - } - - onMessage: { - worker.response = messageObject - worker.done() - } } diff --git a/tests/auto/declarative/qdeclarativeworkerscript/data/worker_pragma.qml b/tests/auto/declarative/qdeclarativeworkerscript/data/worker_pragma.qml new file mode 100644 index 0000000..3b720ef --- /dev/null +++ b/tests/auto/declarative/qdeclarativeworkerscript/data/worker_pragma.qml @@ -0,0 +1,6 @@ +import Qt 4.7 + +BaseWorker { + source: "script_pragma.js" +} + diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp index a1dae24..7a4315a 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp +++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp @@ -64,6 +64,7 @@ private slots: void messaging_data(); void messaging_sendQObjectList(); void messaging_sendJsObject(); + void script_with_pragma(); private: void waitForEchoMessage(QDeclarativeWorkerScript *worker) { @@ -82,18 +83,25 @@ private: void tst_QDeclarativeWorkerScript::source() { - QUrl source = QUrl::fromLocalFile(SRCDIR "/data/worker.qml"); - - QDeclarativeComponent component(&m_engine); - component.setData("import Qt 4.7\nWorkerScript { source: '" + source.toString().toUtf8() + "'; }", QUrl()); + QDeclarativeComponent component(&m_engine, SRCDIR "/data/worker.qml"); + QDeclarativeWorkerScript *worker = qobject_cast(component.create()); + QVERIFY(worker != 0); + const QMetaObject *mo = worker->metaObject(); - QDeclarativeWorkerScript *item = qobject_cast(component.create()); - QVERIFY(item != 0); + QVariant value(100); + QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value))); + waitForEchoMessage(worker); + QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value(), value); - QCOMPARE(item->source(), source); + QUrl source = QUrl::fromLocalFile(SRCDIR "/data/script_fixed_return.js"); + worker->setSource(source); + QCOMPARE(worker->source(), source); + QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value))); + waitForEchoMessage(worker); + QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value(), qVariantFromValue(QString("Hello_World"))); qApp->processEvents(); - delete item; + delete worker; } void tst_QDeclarativeWorkerScript::messaging() @@ -177,6 +185,25 @@ void tst_QDeclarativeWorkerScript::messaging_sendJsObject() delete worker; } +void tst_QDeclarativeWorkerScript::script_with_pragma() +{ + QVariant value(100); + + QDeclarativeComponent component(&m_engine, SRCDIR "/data/worker_pragma.qml"); + QDeclarativeWorkerScript *worker = qobject_cast(component.create()); + QVERIFY(worker != 0); + + QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value))); + waitForEchoMessage(worker); + + const QMetaObject *mo = worker->metaObject(); + QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value(), value); + + qApp->processEvents(); + delete worker; +} + + QTEST_MAIN(tst_QDeclarativeWorkerScript) #include "tst_qdeclarativeworkerscript.moc" -- cgit v0.12 From b08165d372e60c0c61b25dbaf5d0340ce8f985bc Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 26 May 2010 17:23:41 +1000 Subject: Doc fixes, improvements --- doc/src/declarative/advtutorial.qdoc | 4 +- doc/src/declarative/dynamicobjects.qdoc | 14 +-- doc/src/declarative/examples.qdoc | 23 +++-- doc/src/declarative/globalobject.qdoc | 2 +- doc/src/declarative/qtdeclarative.qdoc | 4 +- .../ui-components/dialcontrol/dial.qmlproject | 16 ---- .../dialcontrol/dialcontrol.qmlproject | 16 ++++ src/declarative/qml/qdeclarativeengine.cpp | 102 +++++++++------------ 8 files changed, 88 insertions(+), 93 deletions(-) delete mode 100644 examples/declarative/ui-components/dialcontrol/dial.qmlproject create mode 100644 examples/declarative/ui-components/dialcontrol/dialcontrol.qmlproject diff --git a/doc/src/declarative/advtutorial.qdoc b/doc/src/declarative/advtutorial.qdoc index 47504ae..abfeadb 100644 --- a/doc/src/declarative/advtutorial.qdoc +++ b/doc/src/declarative/advtutorial.qdoc @@ -178,7 +178,7 @@ The \c createBlock() function creates a block from the \c Block.qml file and moves the new block to its position on the game canvas. This involves several steps: \list -\o \l {Qt.createComponent(url file)}{Qt.createComponent()} is called to generate an element from \c Block.qml. +\o \l {Qt::createComponent()}{Qt.createComponent()} is called to generate an element from \c Block.qml. If the component is ready, we can call \c createObject() to create an instance of the \c Block item. \o If \c createObject() returned null (i.e. if there was an error while loading the object), print the error information. @@ -468,6 +468,6 @@ By following this tutorial you've seen how you can write a fully functional appl \endlist There is so much more to learn about QML that we haven't been able to cover in this tutorial. Check out all the -demos and examples and the \l {Declarative UI Using QML}{documentation} to find out all the things you can do with QML! +demos and examples and the \l {Qt Quick}{documentation} to find out all the things you can do with QML! */ diff --git a/doc/src/declarative/dynamicobjects.qdoc b/doc/src/declarative/dynamicobjects.qdoc index 633489b..5e606f4 100644 --- a/doc/src/declarative/dynamicobjects.qdoc +++ b/doc/src/declarative/dynamicobjects.qdoc @@ -56,15 +56,15 @@ application, and there are no C++ components involved. \section1 Creating Objects Dynamically There are two ways to create objects dynamically from JavaScript. You can either call -\l {Qt.createComponent(url file)}{Qt.createComponent()} to create -a component which instantiates items, or use \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()} +\l {Qt::createComponent()}{Qt.createComponent()} to create +a component which instantiates items, or use \l{Qt::createQmlObject()}{Qt.createQmlObject()} to create an item from a string of QML. Creating a component is better if you have a predefined item, and you want to create dynamic instances of that item; creating an item from a string of QML is useful when the item QML itself is generated at runtime. If you have a component specified in a QML file, you can dynamically load it with -the \l {Qt.createComponent(url file)}{Qt.createComponent()} function on the \l{QML Global Object}. +the \l {Qt::createComponent()}{Qt.createComponent()} function on the \l{QML Global Object}. This function takes the URL of the QML file as its only argument and returns a component object which can be used to create and load that QML file. @@ -98,10 +98,10 @@ in \c main.qml). After creating an item, you must set its parent to an item with Otherwise your dynamically created item will not appear in the scene. When using files with relative paths, the path should -be relative to the file where \l {Qt.createComponent(url file)}{Qt.createComponent()} is executed. +be relative to the file where \l {Qt::createComponent()}{Qt.createComponent()} is executed. If the QML component does not exist until runtime, you can create a QML item from -a string of QML using the \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()} function, as in the following example: +a string of QML using the \l{Qt::createQmlObject()}{Qt.createQmlObject()} function, as in the following example: \snippet doc/src/snippets/declarative/createQmlObject.qml 0 @@ -121,9 +121,9 @@ the bindings in the dynamic item will no longer work. The actual creation context depends on how an item is created: \list -\o If \l {Qt.createComponent(url file)}{Qt.createComponent()} is used, the creation context +\o If \l {Qt::createComponent()}{Qt.createComponent()} is used, the creation context is the QDeclarativeContext in which this method is called -\o If \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()} +\o If \l{Qt::createQmlObject()}{Qt.createQmlObject()} if called, it is the context of the item used as the second argument to this method \o If a \c {Component{}} item is defined and \l {Component::createObject()}{createObject()} is called on that item, it is the context in which the \c Component is defined diff --git a/doc/src/declarative/examples.qdoc b/doc/src/declarative/examples.qdoc index 6e0426c..5cb83fa 100644 --- a/doc/src/declarative/examples.qdoc +++ b/doc/src/declarative/examples.qdoc @@ -84,7 +84,10 @@ For example, from your build directory, run: \o \l{declarative/imageelements/borderimage}{BorderImage} \endlist -\section2 \l{declarative/positioners}{Positioners} +\section2 Positioners +\list +\o \l{declarative/positioners}{Example} +\endlist \section2 Key Interaction \list @@ -99,6 +102,7 @@ For example, from your build directory, run: \section2 UI Components \list +\o \l{declarative/ui-components/dialcontrol}{Dial control} \o \l{declarative/ui-components/flipable}{Flipable} \o \l{declarative/ui-components/progressbar}{Progress bar} \o \l{declarative/ui-components/scrollbar}{Scroll bar} @@ -112,10 +116,10 @@ For example, from your build directory, run: \list \o \l{declarative/modelviews/gridview}{GridView} \o \l{declarative/modelviews/listview}{ListView} -\o \l{declarative/modelviews/objectlistmodel}{Object list model} +\o \l{declarative/modelviews/objectlistmodel}{Object ListModel} \o \l{declarative/modelviews/package}{Package} \o \l{declarative/modelviews/parallax}{Parallax} -\o \l{declarative/modelviews/stringlistmodel}{String list model} +\o \l{declarative/modelviews/stringlistmodel}{String ListModel} \o \l{declarative/modelviews/webview}{WebView} \endlist @@ -124,7 +128,10 @@ For example, from your build directory, run: \o \l{declarative/xml/xmlhttprequest}{XmlHttpRequest} \endlist -\section2 \l{declarative/i18n}{Internationalization (i18n)} +\section2 Internationalization (i18n) +\list +\o \l{declarative/i18n}{Example} +\endlist \section2 Threading \list @@ -132,11 +139,14 @@ For example, from your build directory, run: \o \l{declarative/threading/workerscript}{WorkerScript} \endlist -\section2 \l{declarative/sqllocalstorage}{SQL Local Storage} +\section2 SQL Local Storage +\list +\o \l{declarative/sqllocalstorage}{Example} +\endlist \section2 C++ Extensions \list -\o \l{declarative-cppextensions-reference.html}{Reference examples} (discussed in \l {Extending QML in C++}) +\o \l{declarative-cppextensions-reference.html}{Reference examples} \o \l{declarative/cppextensions/plugins}{Plugins} \o \l{declarative-cppextensions-qgraphicslayouts.html}{QGraphicsLayouts} \o \l{declarative/cppextensions/qwidgets}{QWidgets} @@ -148,7 +158,6 @@ For example, from your build directory, run: \list \o \l{declarative/toys/clocks}{Clocks} \o \l{declarative/toys/corkboards}{Corkboards} -\o \l{declarative/toys/dial}{Dial} \o \l{declarative/toys/dynamicscene}{Dynamic Scene} \o \l{declarative/toys/tic-tac-toe}{Tic Tac Toe} \o \l{declarative/toys/tvtennis}{TV Tennis} diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index 2885dd5..3a2ad81 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -49,7 +49,7 @@ Contains all the properties of the JavaScript global object, plus: \section1 Qt Object -The \l{qt-qml.html}{Qt object} provides useful enums and functions from Qt, for use in all QML +The \l{qml-qt.html}{Qt object} provides useful enums and functions from Qt, for use in all QML files. \section1 XMLHttpRequest diff --git a/doc/src/declarative/qtdeclarative.qdoc b/doc/src/declarative/qtdeclarative.qdoc index c47ab23..f7cb722 100644 --- a/doc/src/declarative/qtdeclarative.qdoc +++ b/doc/src/declarative/qtdeclarative.qdoc @@ -112,7 +112,7 @@ Returns the QML type id. - \sa qmlRegisterTypeNotAvailable + \sa qmlRegisterTypeNotAvailable() */ /*! @@ -147,7 +147,7 @@ fun.qml: Get back to work, slacker! Without this, a generic "Game is not a type" message would be given. - \sa qmlRegisterUncreatableType + \sa qmlRegisterUncreatableType() */ /*! diff --git a/examples/declarative/ui-components/dialcontrol/dial.qmlproject b/examples/declarative/ui-components/dialcontrol/dial.qmlproject deleted file mode 100644 index d4909f8..0000000 --- a/examples/declarative/ui-components/dialcontrol/dial.qmlproject +++ /dev/null @@ -1,16 +0,0 @@ -import QmlProject 1.0 - -Project { - /* Include .qml, .js, and image files from current directory and subdirectories */ - QmlFiles { - directory: "." - } - JavaScriptFiles { - directory: "." - } - ImageFiles { - directory: "." - } - /* List of plugin directories passed to QML runtime */ - // importPaths: [ " ../exampleplugin " ] -} diff --git a/examples/declarative/ui-components/dialcontrol/dialcontrol.qmlproject b/examples/declarative/ui-components/dialcontrol/dialcontrol.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/ui-components/dialcontrol/dialcontrol.qmlproject @@ -0,0 +1,16 @@ +import QmlProject 1.0 + +Project { + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } + /* List of plugin directories passed to QML runtime */ + // importPaths: [ " ../exampleplugin " ] +} diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index a7384a9..8679e76 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -153,11 +153,11 @@ void QDeclarativeEnginePrivate::defineModule() /*! \qmlclass Qt QDeclarativeEnginePrivate -\brief The QML Global Qt Object +\brief The QML global Qt object provides useful enums and functions from Qt. -The Qt object provides useful enums and functions from Qt, for use in all QML -files. Note that you do note create instances of this type, but instead use -the members of the global "Qt" object. +The Qt object provides useful enums and functions from Qt, for use in all QML files. + +You do not create instances of this type, but instead use the members of the global "Qt" object. \section1 Enums @@ -172,23 +172,23 @@ data types. This is primarily useful when setting the properties of an item when the property has one of the following types: \list -\o Color -\o Rect -\o Point -\o Size -\o Vector3D +\o \c color - use \l{Qt::rgba()}{Qt.rgba()}, \l{Qt::darker()}{Qt.darker()}, \l{Qt::lighter()}{Qt.lighter()} or \l{Qt::tint()}{Qt.tint()} +\o \c rect - use \l{Qt::rect()}{Qt.rect()} +\o \c point - use \l{Qt::point()}{Qt.point()} +\o \c size - use \l{Qt::size()}{Qt.size()} +\o \c vector3d - use \l{Qt::vector3d()}{Qt.vector3d()} \endlist -There are also string based constructors for these types, see \l{qdeclarativebasictypes.html}{Qml Types}. +There are also string based constructors for these types, see \l{qdeclarativebasictypes.html}{QML Basic Types}. \section1 Date/Time Formatters The Qt object contains several functions for formatting dates and times. \list - \o \l{Qt::formatDateTime}{string Qt.formatDateTime(datetime date, variant format) - \o \l{Qt::formatDate}{string Qt.formatDate(datetime date, variant format) - \o \l{Qt::formatTime}{string Qt.formatTime(datetime date, variant format) + \o \l{Qt::formatDateTime}{string Qt.formatDateTime(datetime date, variant format)} + \o \l{Qt::formatDate}{string Qt.formatDate(datetime date, variant format)} + \o \l{Qt::formatTime}{string Qt.formatTime(datetime date, variant format)} \endlist The format specification is described at \l{Qt::formatDateTime}{Qt.formatDateTime}. @@ -226,8 +226,7 @@ QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e) /*! \qmlmethod url Qt::resolvedUrl(url) -This function returns \c url resolved relative to the URL of the -caller. +Returns \c url resolved relative to the URL of the caller. */ QUrl QDeclarativeScriptEngine::resolvedUrl(QScriptContext *context, const QUrl& url) { @@ -1035,8 +1034,11 @@ QString QDeclarativeEnginePrivate::urlToLocalFileOrQrc(const QUrl& url) /*! \qmlmethod object Qt::createComponent(url) -This function takes the URL of a QML file as its only argument. It returns -a component object which can be used to create and load that QML file. +Returns a \l Component object created from the QML file at the specified \a url, +or \c null if there was an error in creating the component. + +Call \l {Component::createObject()}{Component.createObject()} on the returned +component to create an object instance of the component. Here is an example. Remember that QML files that might be loaded over the network cannot be expected to be ready immediately. @@ -1049,17 +1051,8 @@ If you are certain the files will be local, you could simplify to: \snippet doc/src/snippets/declarative/componentCreation.js 2 -The methods and properties of the \l {Component} element are defined in its own -page, but when using it dynamically only two methods are usually used. - \l {Component::createObject()}{Component.createObject()} returns the created object or \c null if there is an error. -If there is an error, \l {Component::errorString()}{Component.errorString()} describes -the error that occurred. Note that createObject() takes exactly one argument, which is set -to the parent of the created object. Graphical objects without a parent will not appear -on the scene, but if you do not wish to parent the item at this point you can safely pass -in null. - -If you want to just create an arbitrary string of QML, instead of -loading a QML file, consider the \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()} function. +To create a QML object from an arbitrary string of QML (instead of a file), +use \l{Qt::createQmlObject()}{Qt.createQmlObject()}. */ QScriptValue QDeclarativeEnginePrivate::createComponent(QScriptContext *ctxt, QScriptEngine *engine) @@ -1088,29 +1081,22 @@ QScriptValue QDeclarativeEnginePrivate::createComponent(QScriptContext *ctxt, QS /*! \qmlmethod object Qt::createQmlObject(string qml, object parent, string filepath) -Creates a new object from the specified string of QML. It requires a -second argument, which is the id of an existing QML object to use as -the new object's parent. If a third argument is provided, this is used -for error reporting as the filepath that the QML came from. +Returns a new object created from the given \a string of QML with the specified \a parent, +or \c null if there was an error in creating the object. + +If \a filepath is specified, it will be used for error reporting for the created object. Example (where \c targetItem is the id of an existing QML item): \snippet doc/src/snippets/declarative/createQmlObject.qml 0 -This function is intended for use inside QML only. It is intended to behave -similarly to eval, but for creating QML elements. - -Returns the created object, \c or null if there is an error. In the case of an -error, a QtScript Error object is thrown. This object has the additional property, -qmlErrors, which is an array of all the errors encountered when trying to execute the -QML. Each object in the array has the members \c lineNumber, \c columnNumber, \c fileName and \c message. +In the case of an error, a QtScript Error object is thrown. This object has an additional property, +\c qmlErrors, which is an array of the errors encountered. +Each object in this array has the members \c lineNumber, \c columnNumber, \c fileName and \c message. Note that this function returns immediately, and therefore may not work if -the QML loads new components. If you are trying to load a new component, -for example from a QML file, consider the \l{Qt.createComponent(url file)}{Qt.createComponent()} function -instead. 'New components' refers to external QML files that have not yet -been loaded, and so it is safe to use \c Qt.createQmlObject() to load built-in -components. +the \a qml string loads new components (that is, external QML files that have not yet been loaded). +If this is the case, consider using \l{Qt::createComponent()}{Qt.createComponent()} instead. */ QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngine *engine) @@ -1217,7 +1203,7 @@ QScriptValue QDeclarativeEnginePrivate::isQtObject(QScriptContext *ctxt, QScript /*! \qmlmethod Qt::vector3d(real x, real y, real z) -This function returns a Vector3D with the specified \c x, \c y and \c z. +Returns a Vector3D with the specified \c x, \c y and \c z. */ QScriptValue QDeclarativeEnginePrivate::vector3d(QScriptContext *ctxt, QScriptEngine *engine) { @@ -1231,7 +1217,7 @@ QScriptValue QDeclarativeEnginePrivate::vector3d(QScriptContext *ctxt, QScriptEn /*! \qmlmethod string Qt::formatDate(datetime date, variant format) -This function returns the string representation of \c date, formatted according to \c format. +Returns the string representation of \c date, formatted according to \c format. */ QScriptValue QDeclarativeEnginePrivate::formatDate(QScriptContext*ctxt, QScriptEngine*engine) { @@ -1256,7 +1242,7 @@ QScriptValue QDeclarativeEnginePrivate::formatDate(QScriptContext*ctxt, QScriptE /*! \qmlmethod string Qt::formatTime(datetime time, variant format) -This function returns the string representation of \c time, formatted according to \c format. +Returns the string representation of \c time, formatted according to \c format. See Qt::formatDateTime for how to define \c format. */ @@ -1283,7 +1269,7 @@ QScriptValue QDeclarativeEnginePrivate::formatTime(QScriptContext*ctxt, QScriptE /*! \qmlmethod string Qt::formatDateTime(datetime dateTime, variant format) -This function returns the string representation of \c dateTime, formatted according to \c format. +Returns the string representation of \c dateTime, formatted according to \c format. \c format for the date/time formatting functions is be specified as follows. @@ -1374,7 +1360,7 @@ QScriptValue QDeclarativeEnginePrivate::formatDateTime(QScriptContext*ctxt, QScr /*! \qmlmethod color Qt::rgba(real red, real green, real blue, real alpha) -This function returns a Color with the specified \c red, \c green, \c blue and \c alpha components. +Returns a Color with the specified \c red, \c green, \c blue and \c alpha components. All components should be in the range 0-1 inclusive. */ QScriptValue QDeclarativeEnginePrivate::rgba(QScriptContext *ctxt, QScriptEngine *engine) @@ -1402,7 +1388,7 @@ QScriptValue QDeclarativeEnginePrivate::rgba(QScriptContext *ctxt, QScriptEngine /*! \qmlmethod color Qt::hsla(real hue, real saturation, real lightness, real alpha) -This function returns a Color with the specified \c hue, \c saturation, \c lightness and \c alpha components. +Returns a Color with the specified \c hue, \c saturation, \c lightness and \c alpha components. All components should be in the range 0-1 inclusive. */ QScriptValue QDeclarativeEnginePrivate::hsla(QScriptContext *ctxt, QScriptEngine *engine) @@ -1430,7 +1416,7 @@ QScriptValue QDeclarativeEnginePrivate::hsla(QScriptContext *ctxt, QScriptEngine /*! \qmlmethod rect Qt::rect(int x, int y, int width, int height) -This function returns a Rect with the top-left corner at \c x, \c y and the specified \c width and \c height. +Returns a Rect with the top-left corner at \c x, \c y and the specified \c width and \c height. */ QScriptValue QDeclarativeEnginePrivate::rect(QScriptContext *ctxt, QScriptEngine *engine) { @@ -1450,7 +1436,7 @@ QScriptValue QDeclarativeEnginePrivate::rect(QScriptContext *ctxt, QScriptEngine /*! \qmlmethod point Qt::point(int x, int y) -This function returns a Point with the specified \c x and \c y coordinates. +Returns a Point with the specified \c x and \c y coordinates. */ QScriptValue QDeclarativeEnginePrivate::point(QScriptContext *ctxt, QScriptEngine *engine) { @@ -1463,7 +1449,7 @@ QScriptValue QDeclarativeEnginePrivate::point(QScriptContext *ctxt, QScriptEngin /*! \qmlmethod Qt::size(int width, int height) -This function returns as Size with the specified \c width and \c height. +Returns a Size with the specified \c width and \c height. */ QScriptValue QDeclarativeEnginePrivate::size(QScriptContext *ctxt, QScriptEngine *engine) { @@ -1476,7 +1462,7 @@ QScriptValue QDeclarativeEnginePrivate::size(QScriptContext *ctxt, QScriptEngine /*! \qmlmethod color Qt::lighter(color baseColor, real factor) -This function returns a color lighter than \c baseColor by the \c factor provided. +Returns a color lighter than \c baseColor by the \c factor provided. If the factor is greater than 1.0, this functions returns a lighter color. Setting factor to 1.5 returns a color that is 50% brighter. If the factor is less than 1.0, @@ -1512,7 +1498,7 @@ QScriptValue QDeclarativeEnginePrivate::lighter(QScriptContext *ctxt, QScriptEng /*! \qmlmethod color Qt::darker(color baseColor, real factor) -This function returns a color darker than \c baseColor by the \c factor provided. +Returns a color darker than \c baseColor by the \c factor provided. If the factor is greater than 1.0, this function returns a darker color. Setting factor to 3.0 returns a color that has one-third the brightness. @@ -1549,7 +1535,7 @@ QScriptValue QDeclarativeEnginePrivate::darker(QScriptContext *ctxt, QScriptEngi /*! \qmlmethod bool Qt::openUrlExternally(url target) -This function attempts to open the specified \c target url in an external application, based on the user's desktop preferences. It will return true if it succeeds, and false otherwise. +Attempts to open the specified \c target url in an external application, based on the user's desktop preferences. Returns true if it succeeds, and false otherwise. */ QScriptValue QDeclarativeEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QScriptEngine *e) { @@ -1564,7 +1550,7 @@ QScriptValue QDeclarativeEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QSc /*! \qmlmethod list Qt::fontFamilies() -This function returns a list of the font families available to the application. +Returns a list of the font families available to the application. */ QScriptValue QDeclarativeEnginePrivate::fontFamilies(QScriptContext *ctxt, QScriptEngine *e) @@ -1579,7 +1565,7 @@ QScriptValue QDeclarativeEnginePrivate::fontFamilies(QScriptContext *ctxt, QScri /*! \qmlmethod string Qt::md5(data) -This function returns a hex string of the md5 hash of \c data. +Returns a hex string of the md5 hash of \c data. */ QScriptValue QDeclarativeEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine *) { -- cgit v0.12 From 058fa44c7aba859c3383f912da4f976c896f921d Mon Sep 17 00:00:00 2001 From: David Faure Date: Wed, 26 May 2010 11:43:39 +0200 Subject: Update the state of the keyboard modifiers on drop events. In the case of drag-n-drop between processes we do not get key events for the pressed modifiers, so we need to update the state of the modifiers (using XQueryPointer) to get a correct value of QApplication::keyboardModifiers() and QDropEvent::keyboardModifiers() at drop time. This is necessary for fixing KDE bug 178679. Merge-request: 590 Reviewed-by: Bradley T. Hughes Reviewed-by: Andreas Aardal Hanssen --- src/gui/kernel/qdnd_x11.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/gui/kernel/qdnd_x11.cpp b/src/gui/kernel/qdnd_x11.cpp index 2b12317..92dd0a1 100644 --- a/src/gui/kernel/qdnd_x11.cpp +++ b/src/gui/kernel/qdnd_x11.cpp @@ -64,6 +64,7 @@ #include "qtextcodec.h" #include "qdnd_p.h" +#include "qapplication_p.h" #include "qt_x11_p.h" #include "qx11info_x11.h" @@ -1111,7 +1112,20 @@ void qt_xdnd_send_leave() waiting_for_status = false; } - +// TODO: remove and use QApplication::currentKeyboardModifiers() in Qt 4.8. +static Qt::KeyboardModifiers currentKeyboardModifiers() +{ + Window root; + Window child; + int root_x, root_y, win_x, win_y; + uint keybstate; + for (int i = 0; i < ScreenCount(X11->display); ++i) { + if (XQueryPointer(X11->display, QX11Info::appRootWindow(i), &root, &child, + &root_x, &root_y, &win_x, &win_y, &keybstate)) + return X11->translateModifiers(keybstate & 0x00ff); + } + return 0; +} void QX11Data::xdndHandleDrop(QWidget *, const XEvent * xe, bool passive) { @@ -1159,6 +1173,11 @@ void QX11Data::xdndHandleDrop(QWidget *, const XEvent * xe, bool passive) if (!dropData) dropData = (manager->object) ? manager->dragPrivate()->data : manager->dropData; + // Drop coming from another app? Update keyboard modifiers. + if (!qt_xdnd_dragging) { + QApplicationPrivate::modifier_buttons = currentKeyboardModifiers(); + } + QDropEvent de(qt_xdnd_current_position, possible_actions, dropData, QApplication::mouseButtons(), QApplication::keyboardModifiers()); QApplication::sendEvent(qt_xdnd_current_widget, &de); -- cgit v0.12 From e0dc3b88abc9c4bcd6c3710c458c4948e5b8a912 Mon Sep 17 00:00:00 2001 From: Jakub Wieczorek Date: Wed, 26 May 2010 11:50:57 +0200 Subject: QXmlStreamWriter: Auto-formatting does not behave properly with processing instructions. When writing a processing instruction with auto-formatting enabled, it should put it in a new line for readability and apply the indentation properly. Merge-request: 620 Reviewed-by: Olivier Goffart --- src/corelib/xml/qxmlstream.cpp | 3 ++- tests/auto/qxmlstream/tst_qxmlstream.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/corelib/xml/qxmlstream.cpp b/src/corelib/xml/qxmlstream.cpp index 1bf00b8..ae12007 100644 --- a/src/corelib/xml/qxmlstream.cpp +++ b/src/corelib/xml/qxmlstream.cpp @@ -3716,7 +3716,8 @@ void QXmlStreamWriter::writeProcessingInstruction(const QString &target, const Q { Q_D(QXmlStreamWriter); Q_ASSERT(!data.contains(QLatin1String("?>"))); - d->finishStartElement(); + if (!d->finishStartElement(false) && d->autoFormatting) + d->indent(d->tagStack.size()); d->write("write(target); if (!data.isNull()) { diff --git a/tests/auto/qxmlstream/tst_qxmlstream.cpp b/tests/auto/qxmlstream/tst_qxmlstream.cpp index 3c5358c..f93d4fc 100644 --- a/tests/auto/qxmlstream/tst_qxmlstream.cpp +++ b/tests/auto/qxmlstream/tst_qxmlstream.cpp @@ -546,6 +546,7 @@ private slots: void writerHangs() const; void writerAutoFormattingWithComments() const; void writerAutoFormattingWithTabs() const; + void writerAutoFormattingWithProcessingInstructions() const; void writerAutoEmptyTags() const; void writeAttributesWithSpace() const; void addExtraNamespaceDeclarations(); @@ -1030,6 +1031,22 @@ void tst_QXmlStream::writerAutoFormattingWithTabs() const QCOMPARE(buffer.buffer().data(), str); } +void tst_QXmlStream::writerAutoFormattingWithProcessingInstructions() const +{ + QBuffer buffer; + buffer.open(QIODevice::WriteOnly); + + QXmlStreamWriter writer(&buffer); + writer.setAutoFormatting(true); + writer.writeStartDocument(); + writer.writeProcessingInstruction("B", "C"); + writer.writeStartElement("A"); + writer.writeEndElement(); + writer.writeEndDocument(); + const char *str = "\n\n\n"; + QCOMPARE(buffer.buffer().data(), str); +} + /*! Task 204822 */ -- cgit v0.12 From 2eedb392048fdebbb29615345ea3716cebabd451 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 26 May 2010 11:59:48 +0200 Subject: tst_qxmlstream: fix in shadowbuild --- tests/auto/qxmlstream/qxmlstream.pro | 5 ++++- tests/auto/qxmlstream/tst_qxmlstream.cpp | 9 ++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/auto/qxmlstream/qxmlstream.pro b/tests/auto/qxmlstream/qxmlstream.pro index ac03d42..f82a7b3 100644 --- a/tests/auto/qxmlstream/qxmlstream.pro +++ b/tests/auto/qxmlstream/qxmlstream.pro @@ -1,5 +1,5 @@ load(qttest_p4) -SOURCES += tst_qxmlstream.cpp +SOURCES += tst_qxmlstream.cpp QT = core xml network @@ -8,4 +8,7 @@ wince*|symbian*: { addFiles.sources = data XML-Test-Suite addFiles.path = . DEPLOYMENT += addFiles + DEFINES += SRCDIR=\\\"\\\" +} else { + DEFINES += SRCDIR=\\\"$$PWD/\\\" } diff --git a/tests/auto/qxmlstream/tst_qxmlstream.cpp b/tests/auto/qxmlstream/tst_qxmlstream.cpp index f93d4fc..7d5e3b7 100644 --- a/tests/auto/qxmlstream/tst_qxmlstream.cpp +++ b/tests/auto/qxmlstream/tst_qxmlstream.cpp @@ -57,7 +57,7 @@ Q_DECLARE_METATYPE(QXmlStreamReader::ReadElementTextBehaviour) -static const char *const catalogFile = "XML-Test-Suite/xmlconf/finalCatalog.xml"; +static const char *const catalogFile = SRCDIR "XML-Test-Suite/xmlconf/finalCatalog.xml"; static const int expectedRunCount = 1646; static const int expectedSkipCount = 532; @@ -527,8 +527,7 @@ class tst_QXmlStream: public QObject { Q_OBJECT public: - tst_QXmlStream() : m_handler(QUrl::fromLocalFile(QDir::currentPath() + QLatin1Char('/')) - .resolved(QUrl(QLatin1String(catalogFile)))) + tst_QXmlStream() : m_handler(QUrl::fromLocalFile(QLatin1String(catalogFile))) { } @@ -806,7 +805,7 @@ void tst_QXmlStream::testReader_data() const QTest::addColumn("xml"); QTest::addColumn("ref"); QDir dir; - dir.cd("data/"); + dir.cd(SRCDIR "data/"); foreach(QString filename , dir.entryList(QStringList() << "*.xml")) { QString reference = QFileInfo(filename).baseName() + ".ref"; QTest::newRow(dir.filePath(filename).toLatin1().data()) << dir.filePath(filename) << dir.filePath(reference); @@ -1201,7 +1200,7 @@ void tst_QXmlStream::crashInUTF16Codec() const QEventLoop eventLoop; QNetworkAccessManager networkManager; - QNetworkRequest request(QUrl::fromLocalFile(QLatin1String("data/051reduced.xml"))); + QNetworkRequest request(QUrl::fromLocalFile(QLatin1String(SRCDIR "data/051reduced.xml"))); QNetworkReply *const reply = networkManager.get(request); eventLoop.connect(reply, SIGNAL(finished()), SLOT(quit())); -- cgit v0.12 From cf1e3150247d6694e8c00b924627c66e798f2382 Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Tue, 6 Apr 2010 19:59:08 +0200 Subject: Fixes a proxymodel sorting odity. Sort order was modified when sorted according to an empty column always in the same order Reviewed-by: Thierry --- src/gui/itemviews/qsortfilterproxymodel.cpp | 2 +- .../tst_qsortfilterproxymodel.cpp | 36 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/gui/itemviews/qsortfilterproxymodel.cpp b/src/gui/itemviews/qsortfilterproxymodel.cpp index b12cd45..f9b6b94 100644 --- a/src/gui/itemviews/qsortfilterproxymodel.cpp +++ b/src/gui/itemviews/qsortfilterproxymodel.cpp @@ -2392,7 +2392,7 @@ bool QSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex QVariant r = (right.model() ? right.model()->data(right, d->sort_role) : QVariant()); switch (l.userType()) { case QVariant::Invalid: - return (r.type() == QVariant::Invalid); + return (r.type() != QVariant::Invalid); case QVariant::Int: return l.toInt() < r.toInt(); case QVariant::UInt: diff --git a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 992c95e..53fefee 100644 --- a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -127,6 +127,8 @@ private slots: void sortColumnTracking1(); void sortColumnTracking2(); + void sortStable(); + void task236755_hiddenColumns(); void task247867_insertRowsSort(); void task248868_staticSorting(); @@ -2442,6 +2444,40 @@ void tst_QSortFilterProxyModel::sortColumnTracking2() QCOMPARE(proxyModel.data(proxyModel.index(strings.count()-1,0)).toString(),QString::fromLatin1("zz")); } +void tst_QSortFilterProxyModel::sortStable() +{ + QStandardItemModel* model = new QStandardItemModel(5, 2); + for (int r=0; r<5; r++) { + for (int c=0; c<2; c++) { + QStandardItem* item = new QStandardItem( + QString("Row:%0, Column:%1").arg(r).arg(c) ); + for( int i=0; i<3; i++ ) { + QStandardItem* child = new QStandardItem( + QString("Item %0").arg(i) ); + item->appendRow( child ); + } + model->setItem(r, c, item); + } + } + model->setHorizontalHeaderItem( 0, new QStandardItem( "Name" )); + model->setHorizontalHeaderItem( 1, new QStandardItem( "Value" ) ); + + + QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(model); + filterModel->setSourceModel(model); + + QTreeView *view = new QTreeView; + view->setModel(filterModel); + QModelIndex firstRoot = filterModel->index(0,0); + view->expand(firstRoot); + view->setSortingEnabled(true); + + view->model()->sort(1, Qt::DescendingOrder); + QVariant lastItemData =filterModel->index(2,0, firstRoot).data(); + view->model()->sort(1, Qt::DescendingOrder); + QCOMPARE(lastItemData, filterModel->index(2,0, firstRoot).data()); +} + void tst_QSortFilterProxyModel::task236755_hiddenColumns() { class MyStandardItemModel : public QStandardItemModel -- cgit v0.12 From 11a8c52498e8dc74fdfef48e953055338c8f18d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 26 May 2010 15:53:06 +0200 Subject: Redraw issues when removing a fully transparent QGraphicsItem from the scene. This only happened with fully transparent ancestors (item's effectiveOpacity() == 0.0). Problem was that we didn't take into account the ancestors' opacity when removing an item from the scene. More specifically: The calculated effective opacity for the item was zero and we ignored update requests. We have to ignore the opacity if any of the ancestors' ignoreOpacity bit is 1, which means the opacity is set to 0 and the update request has not yet been processed. Auto test included. Task-number: QTBUG-10778 --- src/gui/graphicsview/qgraphicsscene.cpp | 18 ++++++++++ tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp | 43 ++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index ae0abf9..22c3f92 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -4889,6 +4889,24 @@ void QGraphicsScenePrivate::markDirty(QGraphicsItem *item, const QRectF &rect, b if (updateAll) return; + if (removingItemFromScene && !ignoreOpacity && !item->d_ptr->ignoreOpacity) { + // If any of the item's ancestors ignore opacity, it means that the opacity + // was set to 0 (and the update request has not yet been processed). That + // also means that we have to ignore the opacity for the item itself; otherwise + // things like: parent->setOpacity(0); scene->removeItem(child) won't work. + // Note that we only do this when removing items from the scene. In all other + // cases the ignoreOpacity bit propagates properly in processDirtyItems, but + // since the item is removed immediately it won't be processed there. + QGraphicsItem *p = item->d_ptr->parent; + while (p) { + if (p->d_ptr->ignoreOpacity) { + item->d_ptr->ignoreOpacity = true; + break; + } + p = p->d_ptr->parent; + } + } + if (item->d_ptr->discardUpdateRequest(/*ignoreVisibleBit=*/force, /*ignoreDirtyBit=*/removingItemFromScene || invalidateChildren, /*ignoreOpacity=*/ignoreOpacity)) { diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp index a155222..67a41ca 100644 --- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp @@ -275,6 +275,7 @@ private slots: void polishItems2(); void isActive(); void siblingIndexAlwaysValid(); + void removeFullyTransparentItem(); // task specific tests below me void task139710_bspTreeCrash(); @@ -4333,6 +4334,48 @@ void tst_QGraphicsScene::siblingIndexAlwaysValid() } +void tst_QGraphicsScene::removeFullyTransparentItem() +{ + QGraphicsScene scene; + + QGraphicsItem *parent = scene.addRect(0, 0, 100, 100); + parent->setFlag(QGraphicsItem::ItemHasNoContents); + + QGraphicsItem *child = scene.addRect(0, 0, 100, 100); + child->setParentItem(parent); + + CustomView view; + view.setScene(&scene); + view.show(); + QTest::qWaitForWindowShown(&view); + + // NB! The parent has the ItemHasNoContents flag set, which means + // the parent itself doesn't generate any update requests, only the + // child can possibly trigger an update. Also note that the child + // is removed before processing events. + view.repaints = 0; + parent->setOpacity(0); + QVERIFY(qFuzzyIsNull(child->effectiveOpacity())); + scene.removeItem(child); + QVERIFY(!scene.items().contains(child)); + QTRY_VERIFY(view.repaints > 0); + + // Re-add child. There's nothing new to display (child is still + // effectively hidden), so it shouldn't trigger an update. + view.repaints = 0; + child->setParentItem(parent); + QVERIFY(scene.items().contains(child)); + QVERIFY(qFuzzyIsNull(child->effectiveOpacity())); + QApplication::processEvents(); + QCOMPARE(view.repaints, 0); + + // Nothing is visible on the screen, removing child item shouldn't trigger an update. + scene.removeItem(child); + QApplication::processEvents(); + QCOMPARE(view.repaints, 0); + delete child; +} + void tst_QGraphicsScene::taskQTBUG_5904_crashWithDeviceCoordinateCache() { QGraphicsScene scene; -- cgit v0.12