}
}
-void QQuickTextControlPrivate::_q_deleteSelected()
-{
- if (!(interactionFlags & Qt::TextEditable) || !cursor.hasSelection())
- return;
- cursor.removeSelectedText();
-}
-
void QQuickTextControl::undo()
{
Q_D(QQuickTextControl);
}
#endif
-void QQuickTextControl::clear()
-{
- Q_D(QQuickTextControl);
- // clears and sets empty content
- d->setContent();
-}
-
-
void QQuickTextControl::selectAll()
{
Q_D(QQuickTextControl);
}
}
-void QQuickTextControl::setFocus(bool focus, Qt::FocusReason reason)
-{
- QFocusEvent ev(focus ? QEvent::FocusIn : QEvent::FocusOut,
- reason);
- processEvent(&ev);
-}
-
void QQuickTextControlPrivate::focusEvent(QFocusEvent *e)
{
Q_Q(QQuickTextControl);
}
}
-QString QQuickTextControlPrivate::anchorForCursor(const QTextCursor &anchorCursor) const
-{
- if (anchorCursor.hasSelection()) {
- QTextCursor cursor = anchorCursor;
- if (cursor.selectionStart() != cursor.position())
- cursor.setPosition(cursor.selectionStart());
- cursor.movePosition(QTextCursor::NextCharacter);
- QTextCharFormat fmt = cursor.charFormat();
- if (fmt.isAnchor() && fmt.hasProperty(QTextFormat::AnchorHref))
- return fmt.stringProperty(QTextFormat::AnchorHref);
- }
- return QString();
-}
-
-QTextCursor QQuickTextControl::cursorForPosition(const QPointF &pos) const
-{
- Q_D(const QQuickTextControl);
- int cursorPos = hitTest(pos, Qt::FuzzyHit);
- if (cursorPos == -1)
- cursorPos = 0;
- QTextCursor c(d->doc);
- c.setPosition(cursorPos);
- return c;
-}
-
QRectF QQuickTextControl::cursorRect(const QTextCursor &cursor) const
{
Q_D(const QQuickTextControl);
return d->doc->documentLayout()->anchorAt(pos);
}
-QString QQuickTextControl::anchorAtCursor() const
-{
- Q_D(const QQuickTextControl);
-
- return d->anchorForCursor(d->cursor);
-}
-
-int QQuickTextControl::cursorWidth() const
-{
-#ifndef QT_NO_PROPERTIES
- Q_D(const QQuickTextControl);
- return d->doc->documentLayout()->property("cursorWidth").toInt();
-#else
- return 1;
-#endif
-}
-
void QQuickTextControl::setCursorWidth(int width)
{
Q_D(QQuickTextControl);
d->repaintCursor();
}
-bool QQuickTextControl::acceptRichText() const
-{
- Q_D(const QQuickTextControl);
- return d->acceptRichText;
-}
-
void QQuickTextControl::setAcceptRichText(bool accept)
{
Q_D(QQuickTextControl);
d->acceptRichText = accept;
}
-void QQuickTextControl::setTextWidth(qreal width)
-{
- Q_D(QQuickTextControl);
- d->doc->setTextWidth(width);
-}
-
-qreal QQuickTextControl::textWidth() const
-{
- Q_D(const QQuickTextControl);
- return d->doc->textWidth();
-}
-
-QSizeF QQuickTextControl::size() const
-{
- Q_D(const QQuickTextControl);
- return d->doc->size();
-}
-
void QQuickTextControl::moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode)
{
Q_D(QQuickTextControl);
d->repaintCursor();
}
-bool QQuickTextControl::cursorIsFocusIndicator() const
-{
- Q_D(const QQuickTextControl);
- return d->cursorIsFocusIndicator;
-}
-
void QQuickTextControl::setWordSelectionEnabled(bool enabled)
{
Q_D(QQuickTextControl);
d->wordSelectionEnabled = enabled;
}
-bool QQuickTextControl::isWordSelectionEnabled() const
-{
- Q_D(const QQuickTextControl);
- return d->wordSelectionEnabled;
-}
-
QMimeData *QQuickTextControl::createMimeDataFromSelection() const
{
Q_D(const QQuickTextControl);
{
Q_OBJECT
Q_DECLARE_PRIVATE(QQuickTextControl)
-#ifndef QT_NO_TEXTHTMLPARSER
- Q_PROPERTY(QString html READ toHtml WRITE setHtml NOTIFY textChanged USER true)
-#endif
- Q_PROPERTY(bool acceptRichText READ acceptRichText WRITE setAcceptRichText)
- Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
- Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
public:
explicit QQuickTextControl(QTextDocument *doc, QObject *parent = 0);
virtual ~QQuickTextControl();
QString toHtml() const;
#endif
- QTextCursor cursorForPosition(const QPointF &pos) const;
QRectF cursorRect(const QTextCursor &cursor) const;
QRectF cursorRect() const;
QRectF selectionRect(const QTextCursor &cursor) const;
QString anchorAt(const QPointF &pos) const;
- QString anchorAtCursor() const;
-
- int cursorWidth() const;
void setCursorWidth(int width);
- bool acceptRichText() const;
void setAcceptRichText(bool accept);
- void setTextWidth(qreal width);
- qreal textWidth() const;
- QSizeF size() const;
-
void moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
bool canPaste() const;
void setCursorIsFocusIndicator(bool b);
- bool cursorIsFocusIndicator() const;
-
- bool isWordSelectionEnabled() const;
void setWordSelectionEnabled(bool enabled);
virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const;
void undo();
void redo();
- void clear();
void selectAll();
Q_SIGNALS:
virtual void processEvent(QEvent *e, const QMatrix &matrix);
void processEvent(QEvent *e, const QPointF &coordinateOffset = QPointF());
- // control methods
- void setFocus(bool focus, Qt::FocusReason = Qt::OtherFocusReason);
-
virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
virtual QMimeData *createMimeDataFromSelection() const;
Q_DISABLE_COPY(QQuickTextControl)
Q_PRIVATE_SLOT(d_func(), void _q_updateCurrentCharFormatAndSelection())
Q_PRIVATE_SLOT(d_func(), void _q_emitCursorPosChanged(const QTextCursor &))
- Q_PRIVATE_SLOT(d_func(), void _q_deleteSelected())
Q_PRIVATE_SLOT(d_func(), void _q_updateBlock(const QTextBlock &))
Q_PRIVATE_SLOT(d_func(), void _q_documentLayoutChanged())
};
void extendWordwiseSelection(int suggestedNewPosition, qreal mouseXPosition);
void extendBlockwiseSelection(int suggestedNewPosition);
- void _q_deleteSelected();
-
void _q_setCursorAfterUndoRedo(int undoPosition, int charsAdded, int charsRemoved);
QRectF cursorRectPlusUnicodeDirectionMarkers(const QTextCursor &cursor) const;
inline QRectF selectionRect() const
{ return selectionRect(this->cursor); }
- QString anchorForCursor(const QTextCursor &anchor) const;
-
void keyPressEvent(QKeyEvent *e);
void mousePressEvent(QMouseEvent *event, const QPointF &pos);
void mouseMoveEvent(QMouseEvent *event, const QPointF &pos);