diff options
Diffstat (limited to 'src/declarative/graphicsitems')
7 files changed, 138 insertions, 10 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativelayoutitem.cpp b/src/declarative/graphicsitems/qdeclarativelayoutitem.cpp index c8ecbb6..4add66d 100644 --- a/src/declarative/graphicsitems/qdeclarativelayoutitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativelayoutitem.cpp @@ -50,20 +50,21 @@ QT_BEGIN_NAMESPACE /*! \qmlclass LayoutItem QDeclarativeLayoutItem \since 4.7 - \brief The LayoutItem element allows you to place your declarative UI elements inside a classical Qt layout. + \brief The LayoutItem element allows declarative UI elements to be placed inside Qt's Graphics View layouts. - LayoutItem is a variant of Item with a couple of additional properties. These properties provide the size hints - needed for items to work in conjunction with Qt Layouts. The Qt Layout will resize the LayoutItem as appropriate, + LayoutItem is a variant of \l Item with additional size hint properties. These properties provide the size hints + necessary for items to work in conjunction with Qt \l{Graphics View Framework}{Graphics View} layout classes + such as QGraphicsLinearLayout and QGraphicsGridLayout. The Qt layout mechanisms will resize the LayoutItem as appropriate, taking its size hints into account, and you can propagate this to the other elements in your UI via anchors and bindings. - This is a QGraphicsLayoutItem subclass, and the properties merely expose the QGraphicsLayoutItem functionality to QML. + This is a QGraphicsLayoutItem subclass, and its properties merely expose the QGraphicsLayoutItem functionality to QML. See the QGraphicsLayoutItem documentation for further details. */ /*! \internal \class QDeclarativeLayoutItem - \brief The QDeclarativeLayoutItem class allows you to place your Fluid UI elements inside a classical Qt layout. + \brief The QDeclarativeLayoutItem class allows you to place your QML UI elements inside Qt's Graphics View layouts. */ diff --git a/src/declarative/graphicsitems/qdeclarativepath.cpp b/src/declarative/graphicsitems/qdeclarativepath.cpp index 2d08c7c..141a938 100644 --- a/src/declarative/graphicsitems/qdeclarativepath.cpp +++ b/src/declarative/graphicsitems/qdeclarativepath.cpp @@ -867,6 +867,9 @@ qreal QDeclarativePathPercent::value() const void QDeclarativePathPercent::setValue(qreal value) { - _value = value; + if (_value != value) { + _value = value; + emit changed(); + } } QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativepath_p.h b/src/declarative/graphicsitems/qdeclarativepath_p.h index 17a2ea3..dad43e6 100644 --- a/src/declarative/graphicsitems/qdeclarativepath_p.h +++ b/src/declarative/graphicsitems/qdeclarativepath_p.h @@ -175,7 +175,7 @@ private: class Q_DECLARATIVE_EXPORT QDeclarativePathPercent : public QDeclarativePathElement { Q_OBJECT - Q_PROPERTY(qreal value READ value WRITE setValue) + Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed) public: QDeclarativePathPercent(QObject *parent=0) : QDeclarativePathElement(parent) {} diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 997c666..15cdb05 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -89,6 +89,13 @@ TextEdit { A particular look-and-feel might use smooth scrolling (eg. using SmoothedFollow), might have a visible scrollbar, or a scrollbar that fades in to show location, etc. + Clipboard support is provided by the cut(), copy(), and paste() functions, and the selection can + be handled in a traditional "mouse" mechanism by setting selectByMouse, or handled completely + from QML by manipulating selectionStart and selectionEnd, or using selectAll() or selectWord(). + + You can translate between cursor positions (characters from the start of the document) and pixel + points using positionAt() and positionToRectangle(). + \sa Text */ @@ -541,6 +548,70 @@ qreal QDeclarativeTextEdit::paintedHeight() const return implicitHeight(); } +/*! + \qmlmethod rectangle TextEdit::positionToRectangle(position) + + Returns the rectangle at the given \a position in the text. The x, y, + and height properties correspond to the cursor that would describe + that position. +*/ +QRectF QDeclarativeTextEdit::positionToRectangle(int pos) const +{ + Q_D(const QDeclarativeTextEdit); + QTextCursor c(d->document); + c.setPosition(pos); + return d->control->cursorRect(c); + +} + +/*! + \qmlmethod int TextEdit::positionAt(x,y) + + Returns the text position closest to pixel position (\a x,\a y). + + Position 0 is before the first character, position 1 is after the first character + but before the second, and so on until position text.length, which is after all characters. +*/ +int QDeclarativeTextEdit::positionAt(int x, int y) const +{ + Q_D(const QDeclarativeTextEdit); + int r = d->document->documentLayout()->hitTest(QPoint(x,y-d->yoff), Qt::FuzzyHit); + return r; +} + +/*! + \qmlmethod int TextEdit::moveCursorSeletion(int pos) + + Moves the cursor to \a position and updates the selection accordingly. + (To only move the cursor, set the \l cursorPosition property.) + + When this method is called it additionally sets either the + selectionStart or the selectionEnd (whichever was at the previous cursor position) + to the specified position. This allows you to easily extend and contract the selected + text range. + + For example, take this sequence of calls: + + \code + cursorPosition = 5 + moveCursorSelection(9) + moveCursorSelection(7) + \endcode + + This moves the cursor to position 5, extend the selection end from 5 to 9 + and then retract the selection end from 9 to 7, leaving the text from position 5 to 7 + selected (the 6th and 7th characters). +*/ +void QDeclarativeTextEdit::moveCursorSelection(int pos) +{ + //Note that this is the same as setCursorPosition but with the KeepAnchor flag set + Q_D(QDeclarativeTextEdit); + QTextCursor cursor = d->control->textCursor(); + if (cursor.position() == pos) + return; + cursor.setPosition(pos, QTextCursor::KeepAnchor); + d->control->setTextCursor(cursor); +} /*! \qmlproperty bool TextEdit::cursorVisible @@ -966,6 +1037,51 @@ void QDeclarativeTextEdit::selectAll() } /*! + Causes the word closest to the current cursor position to be selected. +*/ +void QDeclarativeTextEdit::selectWord() +{ + Q_D(QDeclarativeTextEdit); + QTextCursor c = d->control->textCursor(); + c.select(QTextCursor::WordUnderCursor); + d->control->setTextCursor(c); +} + +/*! + \qmlmethod TextEdit::cut() + + Moves the currently selected text to the system clipboard. +*/ +void QDeclarativeTextEdit::cut() +{ + Q_D(QDeclarativeTextEdit); + d->control->cut(); +} + +/*! + \qmlmethod TextEdit::copy() + + Copies the currently selected text to the system clipboard. +*/ +void QDeclarativeTextEdit::copy() +{ + Q_D(QDeclarativeTextEdit); + d->control->copy(); +} + +/*! + \qmlmethod TextEdit::paste() + + Relaces the currently selected text by the contents of the system clipboard. +*/ +void QDeclarativeTextEdit::paste() +{ + Q_D(QDeclarativeTextEdit); + d->control->paste(); +} + + +/*! \overload Handles the given mouse \a event. */ diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h index 47174f4..a83b3db 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h @@ -198,6 +198,10 @@ public: qreal paintedWidth() const; qreal paintedHeight() const; + Q_INVOKABLE QRectF positionToRectangle(int) const; + Q_INVOKABLE int positionAt(int x, int y) const; + Q_INVOKABLE void moveCursorSelection(int pos); + Q_SIGNALS: void textChanged(const QString &); void paintedSizeChanged(); @@ -225,6 +229,10 @@ Q_SIGNALS: public Q_SLOTS: void selectAll(); + void selectWord(); + void cut(); + void copy(); + void paste(); private Q_SLOTS: void updateImgCache(const QRectF &rect); diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 305540f..ea958ef 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -835,7 +835,7 @@ void QDeclarativeTextInput::moveCursor() } /*! - \qmlmethod int TextInput::xToPosition(int x) + \qmlmethod int TextInput::positionAt(int x) This function returns the character position at x pixels from the left of the textInput. Position 0 is before the @@ -845,7 +845,7 @@ void QDeclarativeTextInput::moveCursor() This means that for all x values before the first character this function returns 0, and for all x values after the last character this function returns text.length. */ -int QDeclarativeTextInput::xToPosition(int x) +int QDeclarativeTextInput::positionAt(int x) { Q_D(const QDeclarativeTextInput); return d->control->xToPos(x - d->hscroll); diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h index 3dba844..9d58f13 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h @@ -112,7 +112,7 @@ public: }; //Auxilliary functions needed to control the TextInput from QML - Q_INVOKABLE int xToPosition(int x); + Q_INVOKABLE int positionAt(int x); Q_INVOKABLE void moveCursorSelection(int pos); Q_INVOKABLE void openSoftwareInputPanel(); |