diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-05-27 00:25:04 (GMT) |
---|---|---|
committer | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-05-27 00:25:04 (GMT) |
commit | fb5d338236976690312660bc017a8fe1e199326f (patch) | |
tree | f126ea5dfb367fc5212a62652162b84e86513aa4 /src | |
parent | 487c05895751985a695f117fd984d1ecfe7b1252 (diff) | |
parent | 84f35321b867894470391d4997b5d58e34bce0ed (diff) | |
download | Qt-fb5d338236976690312660bc017a8fe1e199326f.zip Qt-fb5d338236976690312660bc017a8fe1e199326f.tar.gz Qt-fb5d338236976690312660bc017a8fe1e199326f.tar.bz2 |
Merge remote branch 'origin/4.7' into oslo-staging-1
Conflicts:
doc/src/declarative/advtutorial.qdoc
Diffstat (limited to 'src')
30 files changed, 520 insertions, 152 deletions
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("<?"); d->write(target); if (!data.isNull()) { 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/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/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 */ 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..167db77 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. @@ -940,8 +962,8 @@ Handles the given mouse \a event. void QDeclarativeTextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativeTextEdit); - bool hadFocus = hasFocus(); 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) @@ -949,9 +971,11 @@ 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 (!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 +989,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); @@ -1156,7 +1175,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 +1191,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 +1201,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(width(), height())); + setContentsSize(QSize(newWidth, newHeight)); + + emit paintedSizeChanged(); } else { d->dirty = true; } @@ -1205,4 +1227,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<QGraphicsView*>(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<QGraphicsView*>(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..47174f4 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) @@ -84,6 +86,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) @@ -113,9 +116,13 @@ public: enum WrapMode { NoWrap = QTextOption::NoWrap, WordWrap = QTextOption::WordWrap, WrapAnywhere = QTextOption::WrapAnywhere, - WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere + WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT + Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere }; + Q_INVOKABLE void openSoftwareInputPanel(); + Q_INVOKABLE void closeSoftwareInputPanel(); + QString text() const; void setText(const QString &); @@ -163,6 +170,9 @@ public: bool focusOnPress() const; void setFocusOnPress(bool on); + bool showInputPanelOnFocus() const; + void setShowInputPanelOnFocus(bool showOnFocus); + bool persistentSelection() const; void setPersistentSelection(bool on); @@ -185,8 +195,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(); @@ -207,6 +221,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 +243,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..18e3595 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -886,8 +886,8 @@ void QDeclarativeTextInput::keyPressEvent(QKeyEvent* ev) void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_D(QDeclarativeTextInput); - bool hadFocus = hasFocus(); 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) @@ -895,9 +895,11 @@ 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(); + } } - if (!hadFocus && hasFocus()) - d->clickCausedFocus = true; bool mark = event->modifiers() & Qt::ShiftModifier; int cursor = d->xToPos(event->pos().x()); @@ -923,10 +925,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 +1174,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<QGraphicsView*>(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<QGraphicsView*>(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/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<string> 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 *) { 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/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(); 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<int, int> 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<int, int> 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<QDecla \endqml The \l {XmlListModel::query}{query} value of "/rss/channel/item" specifies that the XmlListModel should generate - a model item for each \c <item> in the XML document. The XmlRole objects define the + a model item for each \c <item> 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 <item>. + (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<QDecla If multiple key roles are specified, the model only adds and reload items with a combined value of all key roles that is not already present in the model. - - \sa {declarative/xml/xmldata}{XML data example} */ QDeclarativeXmlListModel::QDeclarativeXmlListModel(QObject *parent) 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/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/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); 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 |