42 #include "private/qdeclarativetextedit_p.h" 43 #include "private/qdeclarativetextedit_p_p.h" 45 #include "private/qdeclarativeevents_p_p.h" 46 #include <private/qdeclarativeglobal_p.h> 49 #include <QtCore/qmath.h> 51 #include <private/qtextengine_p.h> 52 #include <QTextLayout> 54 #include <QTextDocument> 55 #include <QTextObject> 56 #include <QGraphicsSceneMouseEvent> 60 #include <private/qtextcontrol_p.h> 133 #ifndef QT_NO_TEXTHTMLPARSER 135 return d->document->toHtml();
138 return d->document->toPlainText();
298 #ifndef QT_NO_TEXTHTMLPARSER 299 d->control->setHtml(text);
301 d->control->setPlainText(text);
304 d->control->setPlainText(text);
359 if (format ==
d->format)
361 bool wasRich =
d->richText;
364 if (wasRich && !
d->richText) {
365 d->control->setPlainText(
d->text);
367 }
else if (!wasRich &&
d->richText) {
368 #ifndef QT_NO_TEXTHTMLPARSER 369 d->control->setHtml(
d->text);
371 d->control->setPlainText(
d->text);
376 d->control->setAcceptRichText(
d->format !=
PlainText);
383 return d->sourceFont;
389 if (
d->sourceFont == font)
392 d->sourceFont =
font;
395 if (
d->font.pointSizeF() != -1) {
398 d->font.setPointSizeF(size/2.0);
401 if (oldFont !=
d->font) {
403 d->document->setDefaultFont(
d->font);
441 if (
d->color == color)
448 d->control->setPalette(pal);
464 return d->selectionColor;
470 if (
d->selectionColor == color)
474 d->selectionColor =
color;
477 d->control->setPalette(pal);
493 return d->selectedTextColor;
499 if (
d->selectedTextColor == color)
503 d->selectedTextColor =
color;
506 d->control->setPalette(pal);
552 bool forceAlign =
d->hAlignImplicit &&
d->effectiveLayoutMirror;
553 d->hAlignImplicit =
false;
555 d->updateDefaultTextOption();
563 d->hAlignImplicit =
true;
565 d->updateDefaultTextOption();
574 if (!
d->hAlignImplicit &&
d->effectiveLayoutMirror) {
586 return effectiveAlignment;
592 if (
hAlign != alignment || forceAlign) {
594 emit q->horizontalAlignmentChanged(alignment);
603 if (hAlignImplicit && q->isComponentComplete()) {
605 if (
text.
isEmpty() && !control->textCursor().isNull()) {
606 const QString preeditText = control->textCursor().block().layout()->preeditAreaText();
607 alignToRight = preeditText.
isEmpty()
611 alignToRight = rightToLeftText;
621 if (q->isComponentComplete()) {
623 updateDefaultTextOption();
638 if (alignment ==
d->vAlign)
640 d->vAlign = alignment;
641 d->updateDefaultTextOption();
674 if (mode ==
d->wrapMode)
677 d->updateDefaultTextOption();
709 return d->paintedSize.width();
724 return d->paintedSize.height();
742 return d->control->cursorRect(c);
767 const int preeditLength = layout
770 if (preeditLength > 0
771 &&
d->document->documentLayout()->blockBoundingRect(cursor.
block()).
contains(x,y-
d->yoff)) {
772 r = r > cursor.
position() + preeditLength
788 d->control->setTextCursor(cursor);
878 d->control->setTextCursor(cursor);
894 return d->cursorVisible;
900 if (
d->cursorVisible == on)
902 d->cursorVisible = on;
904 if (!on && !
d->persistentSelection)
905 d->control->setCursorIsFocusIndicator(
true);
906 d->control->processEvent(&focusEvent,
QPointF(0, -
d->yoff));
920 return d->control->textCursor().position();
926 if (pos < 0 || pos >
d->text.length())
932 d->control->setTextCursor(cursor);
954 return d->cursorComponent;
960 if(
d->cursorComponent){
962 d->control->setCursorWidth(-1);
968 d->cursorComponent =
c;
983 if(
d->cursorComponent->isLoading())
987 d->control->setCursorWidth(0);
990 d->cursor->setParentItem(
this);
994 qmlInfo(
this) <<
"Error loading cursor delegate.";
1014 return d->control->textCursor().selectionStart();
1033 return d->control->textCursor().selectionEnd();
1056 return d->control->textCursor().selectedText();
1071 return d->focusOnPress;
1077 if (
d->focusOnPress == on)
1079 d->focusOnPress = on;
1095 return d->persistentSelection;
1101 if (
d->persistentSelection == on)
1103 d->persistentSelection = on;
1115 return d->textMargin;
1121 if (
d->textMargin == margin)
1123 d->textMargin = margin;
1124 d->document->setDocumentMargin(
d->textMargin);
1129 const QRectF &oldGeometry)
1131 if (newGeometry.
width() != oldGeometry.
width())
1145 d->determineHorizontalAlignment();
1146 d->updateDefaultTextOption();
1168 return d->selectByMouse;
1174 if (
d->selectByMouse != on) {
1175 d->selectByMouse = on;
1206 return d->mouseSelectionMode;
1212 if (
d->mouseSelectionMode != mode) {
1213 d->mouseSelectionMode = mode;
1214 d->control->setWordSelectionEnabled(mode ==
SelectWords);
1239 if (
d->selectByMouse)
1243 d->control->setTextInteractionFlags(flags);
1263 d->control->setTextInteractionFlags(flags);
1273 return d->control->textInteractionFlags();
1288 return d->control->cursorRect().toRect().translated(0,
d->yoff);
1300 d->control->processEvent(event,
QPointF(0, -
d->yoff));
1301 return event->isAccepted();
1315 d->control->processEvent(event,
QPointF(0, -
d->yoff));
1329 d->control->processEvent(event,
QPointF(0, -
d->yoff));
1355 d->control->setTextCursor(c);
1369 d->control->selectAll();
1385 d->control->setTextCursor(c);
1407 if (start < 0 || end < 0 || start >
d->text.length() || end >
d->text.length())
1414 d->control->setTextCursor(cursor);
1433 qmlInfo(
this) <<
"isRightToLeft(start, end) called with the end property being smaller than the start.";
1436 return d->text.mid(start, end - start).isRightToLeft();
1440 #ifndef QT_NO_CLIPBOARD 1480 d->control->paste();
1482 #endif // QT_NO_CLIPBOARD 1491 if (
d->focusOnPress){
1494 if (
d->showInputPanelOnFocus) {
1501 d->clickCausedFocus =
true;
1506 d->control->processEvent(event,
QPointF(0, -
d->yoff));
1518 d->control->processEvent(event,
QPointF(0, -
d->yoff));
1519 if (!
d->showInputPanelOnFocus) {
1522 if (view->scene() && view->scene() ==
scene()) {
1528 d->clickCausedFocus =
false;
1542 d->control->processEvent(event,
QPointF(0, -
d->yoff));
1555 d->control->processEvent(event,
QPointF(0, -
d->yoff));
1568 d->control->processEvent(event,
QPointF(0, -
d->yoff));
1580 return d->control->inputMethodQuery(property);
1594 d->control->drawContents(painter, bounds.
translated(0,-
d->yoff));
1672 return layout->preeditAreaText().length() > 0;
1686 control->setIgnoreUnusedNavigationEvents(
true);
1688 control->setDragEnabled(
false);
1696 control->setPalette(pal);
1708 #ifndef QT_NO_CLIPBOARD 1714 document = control->document();
1715 document->setDefaultFont(
font);
1717 document->setUndoRedoEnabled(
false);
1718 document->setUndoRedoEnabled(
true);
1719 updateDefaultTextOption();
1726 d->rightToLeftText =
d->document->begin().layout()->engine()->isRightToLeft();
1727 d->determineHorizontalAlignment();
1728 d->updateDefaultTextOption();
1737 d->determineHorizontalAlignment();
1743 d->cursor->setX(cursorRect.
x());
1744 d->cursor->setY(cursorRect.
y());
1751 bool startChange = (lastSelectionStart != cursor.
selectionStart());
1752 bool endChange = (lastSelectionEnd != cursor.
selectionEnd());
1757 control->setTextCursor(cursor);
1759 q->selectionStartChanged();
1761 q->selectionEndChanged();
1767 if(
d->lastSelectionStart !=
d->control->textCursor().selectionStart()){
1768 d->lastSelectionStart =
d->control->textCursor().selectionStart();
1771 if(
d->lastSelectionEnd !=
d->control->textCursor().selectionEnd()){
1772 d->lastSelectionEnd =
d->control->textCursor().selectionEnd();
1781 int cursorWidth = 1;
1783 cursorWidth =
d->cursor->width();
1784 if(!
d->document->isEmpty())
1796 if (!requireImplicitWidth) {
1802 return mImplicitWidth;
1811 qreal naturalWidth =
d->mImplicitWidth;
1815 if (!
d->requireImplicitWidth) {
1818 if (
d->requireImplicitWidth)
1821 if (
d->requireImplicitWidth) {
1822 d->document->setTextWidth(-1);
1823 naturalWidth =
d->document->idealWidth();
1825 if (
d->document->textWidth() !=
width())
1826 d->document->setTextWidth(
width());
1828 d->document->setTextWidth(-1);
1832 dy -= (int)
d->document->size().height();
1845 if (nyoff !=
d->yoff) {
1852 int newWidth =
qCeil(
d->document->idealWidth());
1853 if (!
widthValid() &&
d->document->textWidth() != newWidth)
1854 d->document->setTextWidth(newWidth);
1858 else if (
d->requireImplicitWidth)
1860 qreal newHeight =
d->document->size().height();
1865 d->paintedSize =
QSize(newWidth, newHeight);
1887 int newTotalLines =
d->document->lineCount() + subLines;
1888 if (
d->lineCount != newTotalLines) {
1889 d->lineCount = newTotalLines;
1901 if (rightToLeftText) {
1914 document->setDefaultTextOption(opt);
1965 if (view->scene() && view->scene() ==
scene()) {
2019 if (view->scene() && view->scene() ==
scene()) {
2029 if (
d->showInputPanelOnFocus) {
2040 bool old =
d->canPaste;
2041 d->canPaste =
d->control->canPaste();
2042 if(old!=
d->canPaste)
The QVariant class acts like a union for the most common Qt data types.
The QPainter class performs low-level painting on widgets and other paint devices.
The QColor class provides colors based on RGB, HSV or CMYK values.
void focusInEvent(QFocusEvent *event)
This event handler, for event event, can be reimplemented to receive focus in events for this item...
void mouseSelectionModeChanged(SelectionMode mode)
int anchor() const
Returns the anchor position; this is the same as position() unless there is a selection in which case...
qreal y() const
Returns the y-coordinate of the rectangle's top edge.
qreal right() const
Returns the x-coordinate of the rectangle's right edge.
void endEditBlock()
Indicates the end of a block of editing operations on the document that should appear as a single ope...
The QKeyEvent class describes a key event.
QDeclarativeComponent * cursorDelegate() const
void drawContents(QPainter *, const QRect &)
Draws the contents of the text edit using the given painter within the given bounds.
bool determineHorizontalAlignment()
void setBottom(int pos)
Sets the bottom edge of the rectangle to the given y coordinate.
void setText(const QString &)
The QFontMetrics class provides font metrics information.
Q_INVOKABLE QRectF positionToRectangle(int) const
void selectionStartChanged()
#define QT_END_NAMESPACE
This macro expands to.
QDeclarativeParserStatus ** d
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
void textFormatChanged(TextFormat textFormat)
void setCursorVisible(bool on)
HAlignment horizontalAlignment
void setMouseSelectionMode(SelectionMode mode)
#define it(className, varName)
bool widthValid() const
Returns whether the width property has been set explicitly.
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
WrapMode wrapMode() const
void keyReleaseEvent(QKeyEvent *)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void fontChanged(const QFont &font)
int selectionEnd() const
Returns the end of the selection or position() if the cursor doesn't have a selection.
virtual bool event(QEvent *)
void setContentsSize(const QSize &)
Sets the size of the contents to the given size.
int length() const
Returns the number of characters in this string.
void linkActivated(const QString &link)
void setBaselineOffset(qreal)
qreal paintedWidth() const
The QPointF class defines a point in the plane using floating point precision.
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
WrapMode
This enum describes how text is wrapped in a document.
Q_GUI_EXPORT bool mightBeRichText(const QString &)
Returns true if the string text is likely to be rich text; otherwise returns false.
Qt::MouseButton button() const
Returns the mouse button (if any) that caused the event.
QRectF boundingRect() const
bool heightValid() const
Returns whether the height property has been set explicitly.
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
bool isReady() const
Returns true if status() == QDeclarativeComponent::Ready.
virtual void keyPressEvent(QKeyEvent *event)
QVariant inputMethodQuery(Qt::InputMethodQuery property) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void keyPressEvent(QKeyEvent *)
This is an overloaded member function, provided for convenience. It differs from the above function o...
qreal implicitWidth() const
void selectionColorChanged(const QColor &color)
QPointF pos() const
Returns the position of the item in parent coordinates.
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
This function is called to handle this item's changes in geometry from oldGeometry to newGeometry...
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse doubleclick events for thi...
void updateMicroFocus()
Updates the item's micro focus.
Q_INVOKABLE void openSoftwareInputPanel()
int height() const
Returns the height of the rectangle.
The QString class provides a Unicode character string.
void readOnlyChanged(bool isReadOnly)
void setTextMargin(qreal margin)
T * qobject_cast(QObject *object)
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse press events for this item...
void update(const QRectF &rect=QRectF())
Schedules a redraw of the area covered by rect in this item.
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void selectByMouseChanged(bool selectByMouse)
Q_DECLARATIVE_EXPORT QDeclarativeContext * qmlContext(const QObject *)
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
void implicitWidthChanged()
void paintedSizeChanged()
void setSelectionColor(const QColor &c)
Qt::TextInteractionFlags textInteractionFlags() const
Returns the flags specifying how the text edit should interact with user input.
void setRight(qreal pos)
Sets the right edge of the rectangle to the given x coordinate.
void setSelectByMouse(bool)
void loadCursorDelegate()
void inputMethodEvent(QInputMethodEvent *e)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void select(int start, int end)
QDeclarativeTextEdit(QDeclarativeItem *parent=0)
This handler is called when the user clicks on a link embedded in the text.
bool isRightToLeft(int start, int end)
virtual void focusInEvent(QFocusEvent *event)
This event handler, for event event, can be reimplemented to receive focus in events for this item...
QString selectedText() const
QColor selectedTextColor() const
int ascent() const
Returns the ascent of the font.
QCursor cursor() const
Returns the current cursor shape for the item.
bool isCursorVisible() const
void cursorRectangleChanged()
void updateImgCache(const QRectF &rect)
void textChanged(const QString &)
QColor selectionColor() const
void setAlignment(Qt::Alignment alignment)
Sets the option's text alignment to the specified alignment.
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QRectF class defines a rectangle in the plane using floating point precision. ...
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void inputMethodComposingChanged()
The QDeclarativeComponent class encapsulates a QML component definition.
The QDeclarativeItem class provides the most basic of all visual items in QML.
static QClipboard * clipboard()
Returns a pointer to the application global clipboard.
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse move events for this item...
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
The QTextCursor class offers an API to access and modify QTextDocuments.
void verticalAlignmentChanged(VAlignment alignment)
void setTop(int pos)
Sets the top edge of the rectangle to the given y coordinate.
bool isRightToLeft() const
Returns true if the string is read right to left.
bool setHAlign(QDeclarativeTextEdit::HAlignment, bool forceAlign=false)
bool hasActiveFocus() const
The QTextBlock class provides a container for text fragments in a QTextDocument.
void textMarginChanged(qreal textMargin)
void colorChanged(const QColor &color)
QRect cursorRectangle() const
void activeFocusOnPressChanged(bool activeFocusOnPressed)
void setFont(const QFont &font)
qreal width() const
Returns the width of the rectangle.
bool persistentSelection() const
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
void select(SelectionType selection)
Selects text in the document according to the given selection.
void cursorVisibleChanged(bool isCursorVisible)
void dirtyCache(const QRect &)
Marks areas of the cache that intersect with the given rect as dirty and in need of being refreshed...
int position() const
Returns the absolute position of the cursor within the document.
bool selectByMouse() const
bool isInputMethodComposing() const
GraphicsItemFlags flags() const
Returns this item's flags.
TextFormat textFormat() const
void keyReleasePreHandler(QKeyEvent *)
void setImplicitWidth(qreal)
Sets the implied width of the item to w.
QRect toRect() const
Returns a QRect based on the values of this rectangle.
void setHAlign(HAlignment align)
QTextBlock block() const
Returns the block that contains the cursor.
HAlignment hAlign() const
void clearSelection()
Clears the current selection by setting the anchor to the cursor position.
virtual void focusChanged(bool)
virtual void keyReleaseEvent(QKeyEvent *event)
QString preeditAreaText() const
Returns the text that is inserted in the layout before editing occurs.
The QTextLayout class is used to lay out and render text.
virtual void componentComplete()
Ensures any delayed caching or data loading the class needs to performed is complete.
void beginEditBlock()
Indicates the start of a block of editing operations on the document that should appear as a single o...
void setWrapMode(WrapMode w)
void updateSelectionMarkers()
qreal y() const
This convenience function is equivalent to calling pos().
QRectF boundingRect() const
void selectionEndChanged()
void prepareGeometryChange()
Prepares the item for a geometry change.
The QFont class specifies a font used for drawing text.
int y() const
Returns the y-coordinate of the rectangle's top edge.
qreal x() const
Returns the x-coordinate of the rectangle's left edge.
void updateDefaultTextOption()
bool hasFocus() const
Returns true if the scene has focus; otherwise returns false.
void QDeclarative_setParent_noEvent(QObject *object, QObject *parent)
Makes the object a child of parent.
VAlignment vAlign() const
qreal x() const
This convenience function is equivalent to calling pos().
virtual void componentComplete()
The QPoint class defines a point in the plane using integer precision.
void setColor(ColorGroup cg, ColorRole cr, const QColor &color)
Sets the color in the specified color group, used for the given color role, to the specified solid co...
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
Sets how the text edit should interact with user input to the given flags.
void cursorPositionChanged()
void moveCursorDelegate()
void setPersistentSelection(bool on)
The QRect class defines a rectangle in the plane using integer precision.
void setCursorPosition(int pos)
WrapMode wrapMode() const
Returns the text wrap mode defined by the option.
void setCursorDelegate(QDeclarativeComponent *)
virtual bool contains(const QPointF &point) const
Returns true if this item contains point, which is in local coordinates; otherwise, false is returned.
void persistentSelectionChanged(bool isPersistentSelection)
The QTextOption class provides a description of general rich text properties.
bool event(QEvent *)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool movePosition(MoveOperation op, MoveMode=MoveAnchor, int n=1)
Moves the cursor by performing the given operation n times, using the specified mode, and returns true if all operations were completed successfully; otherwise returns false.
int cursorPosition() const
void mousePressEvent(QGraphicsSceneMouseEvent *event)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QVariant property(const char *name) const
Returns the value of the object's name property.
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
void clearCache()
Marks the entirety of the contents cache as dirty.
QPointF pos() const
Returns the mouse cursor position in item coordinates.
int selectionStart() const
Qt::Alignment alignment() const
Returns the text alignment defined by the option.
void setFocusOnPress(bool on)
void setWrapMode(WrapMode wrap)
Sets the option's text wrap mode to the given mode.
The QSize class defines the size of a two-dimensional object using integer point precision.
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
bool focusOnPress() const
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
QDeclarativeInfo qmlInfo(const QObject *me)
static Qt::LayoutDirection keyboardInputDirection()
Returns the current keyboard input direction.
int height() const
Returns the height of the font.
void setImplicitHeight(qreal)
Sets the implied height of the item to h.
static const KeyPair *const end
qreal paintedHeight() const
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setColor(const QColor &c)
void setSelectedTextColor(const QColor &c)
void setFlag(GraphicsItemFlag flag, bool enabled=true)
If enabled is true, the item flag flag is enabled; otherwise, it is disabled.
The QEvent class is the base class of all event classes.
SelectionMode mouseSelectionMode() const
Type type() const
Returns the event type.
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
This function is called to handle this item's changes in geometry from oldGeometry to newGeometry...
HAlignment effectiveHAlign() const
Q_INVOKABLE int positionAt(int x, int y) const
Q_INVOKABLE void forceActiveFocus()
Forces active focus on the item.
Q_INVOKABLE void moveCursorSelection(int pos)
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse release events for this it...
void setTextFormat(TextFormat format)
The QFocusEvent class contains event parameters for widget focus events.
Q_DECL_CONSTEXPR int qRound(qreal d)
int selectionStart() const
Returns the start of the selection or position() if the cursor doesn't have a selection.
Q_INVOKABLE void closeSoftwareInputPanel()
int lineCount() const
Returns the number of lines in this text layout.
void cursorDelegateChanged()
void setKeepMouseGrab(bool)
The flag indicating whether the mouse should remain with this item is set to keep.
void keyPressPreHandler(QKeyEvent *)
void setVAlign(VAlignment align)
void selectedTextColorChanged(const QColor &color)
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
The QPalette class contains color groups for each widget state.
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block's contents. ...