Qt 4.8
Public Functions | Public Variables | List of all members
QTextControlPrivate Class Reference

#include <qtextcontrol_p_p.h>

Inheritance diagram for QTextControlPrivate:
QObjectPrivate QObjectData

Public Functions

void _q_copyLink ()
 
void _q_deleteSelected ()
 
void _q_documentLayoutChanged ()
 
void _q_emitCursorPosChanged (const QTextCursor &someCursor)
 
void _q_setCursorAfterUndoRedo (int undoPosition, int charsAdded, int charsRemoved)
 
void _q_updateBlock (const QTextBlock &)
 
void _q_updateCurrentCharFormatAndSelection ()
 
void activateLinkUnderCursor (QString href=QString())
 
QString anchorForCursor (const QTextCursor &anchor) const
 
void append (const QString &text, Qt::TextFormat format=Qt::AutoText)
 
void contextMenuEvent (const QPoint &screenPos, const QPointF &docPos, QWidget *contextWidget)
 
void createAutoBulletList ()
 
bool cursorMoveKeyEvent (QKeyEvent *e)
 
QRectF cursorRectPlusUnicodeDirectionMarkers (const QTextCursor &cursor) const
 
bool dragEnterEvent (QEvent *e, const QMimeData *mimeData)
 
void dragLeaveEvent ()
 
bool dragMoveEvent (QEvent *e, const QMimeData *mimeData, const QPointF &pos)
 
bool dropEvent (const QMimeData *mimeData, const QPointF &pos, Qt::DropAction dropAction, QWidget *source)
 
void extendBlockwiseSelection (int suggestedNewPosition)
 
void extendWordwiseSelection (int suggestedNewPosition, qreal mouseXPosition)
 
void focusEvent (QFocusEvent *e)
 
void gotoNextTableCell ()
 
void gotoPreviousTableCell ()
 
void indent ()
 
void init (Qt::TextFormat format=Qt::RichText, const QString &text=QString(), QTextDocument *document=0)
 
QInputContextinputContext ()
 
void inputMethodEvent (QInputMethodEvent *)
 
void keyPressEvent (QKeyEvent *e)
 
void mouseDoubleClickEvent (QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos)
 
void mouseMoveEvent (QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos)
 
void mousePressEvent (QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos)
 
void mouseReleaseEvent (QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos)
 
void outdent ()
 
void paste (const QMimeData *source)
 
 QTextControlPrivate ()
 
QRectF rectForPosition (int position) const
 
void repaintCursor ()
 
void repaintOldAndNewSelection (const QTextCursor &oldSelection)
 
void repaintSelection ()
 
void selectionChanged (bool forceEmitSelectionChanged=false)
 
QRectF selectionRect (const QTextCursor &cursor) const
 
QRectF selectionRect () const
 
bool sendMouseEventToInputContext (QEvent *e, QEvent::Type eventType, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos)
 
void setBlinkingCursorEnabled (bool enable)
 
void setClipboardSelection ()
 
void setContent (Qt::TextFormat format=Qt::RichText, const QString &text=QString(), QTextDocument *document=0)
 
void setCursorPosition (const QPointF &pos)
 
void setCursorPosition (int pos, QTextCursor::MoveMode mode=QTextCursor::MoveAnchor)
 
void showToolTip (const QPoint &globalPos, const QPointF &pos, QWidget *contextWidget)
 
void startDrag ()
 
void updateCurrentCharFormat ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Public Variables

bool acceptRichText
 
QString anchorOnMousePress
 
QPointer< QWidgetcontextWidget
 
QTextCursor cursor
 
QBasicTimer cursorBlinkTimer
 
bool cursorIsFocusIndicator
 
bool cursorOn
 
QTextCursor dndFeedbackCursor
 
QTextDocumentdoc
 
bool dragEnabled
 
QPoint dragStartPos
 
QVector< QAbstractTextDocumentLayout::SelectionextraSelections
 
bool hadSelectionOnMousePress
 
bool hasFocus
 
bool hideCursor
 
QString highlightedAnchor
 
bool ignoreAutomaticScrollbarAdjustement
 
bool ignoreUnusedNavigationEvents
 
Qt::TextInteractionFlags interactionFlags
 
bool isEnabled
 
QTextCharFormat lastCharFormat
 
bool lastSelectionState
 
QString linkToCopy
 
bool mightStartDrag
 
bool mousePressed
 
bool openExternalLinks
 
bool overwriteMode
 
QPalette palette
 
int preeditCursor
 
QTextCursor selectedBlockOnTrippleClick
 
QTextCursor selectedWordOnDoubleClick
 
QPointF trippleClickPoint
 
QBasicTimer trippleClickTimer
 
bool wordSelectionEnabled
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Detailed Description

Definition at line 72 of file qtextcontrol_p_p.h.

Constructors and Destructors

◆ QTextControlPrivate()

QTextControlPrivate::QTextControlPrivate ( )

Definition at line 117 of file qtextcontrol.cpp.

118  : doc(0), cursorOn(false), cursorIsFocusIndicator(false),
120  dragEnabled(true),
121 #ifndef QT_NO_DRAGANDDROP
122  mousePressed(false), mightStartDrag(false),
123 #endif
125  overwriteMode(false),
126  acceptRichText(true),
127  preeditCursor(0), hideCursor(false),
128  hasFocus(false),
129 #ifdef QT_KEYPAD_NAVIGATION
130  hasEditFocus(false),
131 #endif
132  isEnabled(true),
135  openExternalLinks(false),
136  wordSelectionEnabled(false)
137 {}
bool ignoreAutomaticScrollbarAdjustement
QTextDocument * doc
Qt::TextInteractionFlags interactionFlags

Functions

◆ _q_copyLink()

void QTextControlPrivate::_q_copyLink ( )

Definition at line 3050 of file qtextcontrol.cpp.

3051 {
3052 #ifndef QT_NO_CLIPBOARD
3053  QMimeData *md = new QMimeData;
3054  md->setText(linkToCopy);
3056 #endif
3057 }
void setMimeData(QMimeData *data, Mode mode=Clipboard)
Sets the clipboard data to src.
static QClipboard * clipboard()
Returns a pointer to the application global clipboard.
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
void setText(const QString &text)
Sets text as the plain text (MIME type text/plain) used to represent the data.
Definition: qmimedata.cpp:377

◆ _q_deleteSelected()

void QTextControlPrivate::_q_deleteSelected ( )

Definition at line 756 of file qtextcontrol.cpp.

Referenced by repaintSelection().

757 {
759  return;
761 }
Qt::TextInteractionFlags interactionFlags
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
void removeSelectedText()
If there is a selection, its content is deleted; otherwise does nothing.

◆ _q_documentLayoutChanged()

void QTextControlPrivate::_q_documentLayoutChanged ( )

Definition at line 628 of file qtextcontrol.cpp.

Referenced by setContent().

629 {
630  Q_Q(QTextControl);
632  QObject::connect(layout, SIGNAL(update(QRectF)), q, SIGNAL(updateRequest(QRectF)));
633  QObject::connect(layout, SIGNAL(updateBlock(QTextBlock)), q, SLOT(_q_updateBlock(QTextBlock)));
634  QObject::connect(layout, SIGNAL(documentSizeChanged(QSizeF)), q, SIGNAL(documentSizeChanged(QSizeF)));
635 
636 }
QTextDocument * doc
#define SLOT(a)
Definition: qobjectdefs.h:226
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
#define Q_Q(Class)
Definition: qglobal.h:2483
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
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...
Definition: qobject.cpp:2580
const char * layout
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
void _q_updateBlock(const QTextBlock &)
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for ...

◆ _q_emitCursorPosChanged()

void QTextControlPrivate::_q_emitCursorPosChanged ( const QTextCursor someCursor)

Definition at line 619 of file qtextcontrol.cpp.

Referenced by repaintSelection(), and setContent().

620 {
621  Q_Q(QTextControl);
622  if (someCursor.isCopyOf(cursor)) {
623  emit q->cursorPositionChanged();
624  emit q->microFocusChanged();
625  }
626 }
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
bool isCopyOf(const QTextCursor &other) const
Returns true if this cursor and other are copies of each other, i.e.

◆ _q_setCursorAfterUndoRedo()

void QTextControlPrivate::_q_setCursorAfterUndoRedo ( int  undoPosition,
int  charsAdded,
int  charsRemoved 
)

Referenced by repaintSelection().

◆ _q_updateBlock()

void QTextControlPrivate::_q_updateBlock ( const QTextBlock block)

Definition at line 1339 of file qtextcontrol.cpp.

Referenced by _q_documentLayoutChanged().

1340 {
1341  Q_Q(QTextControl);
1342  QRectF br = q->blockBoundingRect(block);
1343  br.setRight(qreal(INT_MAX)); // the block might have shrunk
1344  emit q->updateRequest(br);
1345 }
double qreal
Definition: qglobal.h:1193
void setRight(qreal pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:672
#define Q_Q(Class)
Definition: qglobal.h:2483
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
#define emit
Definition: qobjectdefs.h:76
#define INT_MAX

◆ _q_updateCurrentCharFormatAndSelection()

void QTextControlPrivate::_q_updateCurrentCharFormatAndSelection ( )

Definition at line 601 of file qtextcontrol.cpp.

Referenced by repaintSelection(), and setContent().

602 {
605 }
void selectionChanged(bool forceEmitSelectionChanged=false)

◆ activateLinkUnderCursor()

void QTextControlPrivate::activateLinkUnderCursor ( QString  href = QString())

Definition at line 2675 of file qtextcontrol.cpp.

Referenced by selectionRect().

2676 {
2677  QTextCursor oldCursor = cursor;
2678 
2679  if (href.isEmpty()) {
2680  QTextCursor tmp = cursor;
2681  if (tmp.selectionStart() != tmp.position())
2682  tmp.setPosition(tmp.selectionStart());
2684  href = tmp.charFormat().anchorHref();
2685  }
2686  if (href.isEmpty())
2687  return;
2688 
2689  if (!cursor.hasSelection()) {
2690  QTextBlock block = cursor.block();
2691  const int cursorPos = cursor.position();
2692 
2693  QTextBlock::Iterator it = block.begin();
2694  QTextBlock::Iterator linkFragment;
2695 
2696  for (; !it.atEnd(); ++it) {
2697  QTextFragment fragment = it.fragment();
2698  const int fragmentPos = fragment.position();
2699  if (fragmentPos <= cursorPos &&
2700  fragmentPos + fragment.length() > cursorPos) {
2701  linkFragment = it;
2702  break;
2703  }
2704  }
2705 
2706  if (!linkFragment.atEnd()) {
2707  it = linkFragment;
2709  if (it != block.begin()) {
2710  do {
2711  --it;
2712  QTextFragment fragment = it.fragment();
2713  if (fragment.charFormat().anchorHref() != href)
2714  break;
2715  cursor.setPosition(fragment.position());
2716  } while (it != block.begin());
2717  }
2718 
2719  for (it = linkFragment; !it.atEnd(); ++it) {
2720  QTextFragment fragment = it.fragment();
2721  if (fragment.charFormat().anchorHref() != href)
2722  break;
2723  cursor.setPosition(fragment.position() + fragment.length(), QTextCursor::KeepAnchor);
2724  }
2725  }
2726  }
2727 
2728  if (hasFocus) {
2729  cursorIsFocusIndicator = true;
2730  } else {
2731  cursorIsFocusIndicator = false;
2733  }
2734  repaintOldAndNewSelection(oldCursor);
2735 
2736 #ifndef QT_NO_DESKTOPSERVICES
2737  if (openExternalLinks)
2739  else
2740 #endif
2741  emit q_func()->linkActivated(href);
2742 }
QTextCharFormat charFormat() const
Returns the format of the character immediately before the cursor position().
#define it(className, varName)
bool atEnd() const
Returns true if the current item is the last item in the text block.
Definition: qtextobject.h:264
iterator begin() const
Returns a text block iterator pointing to the beginning of the text block.
QString anchorHref() const
Returns the text format&#39;s hypertext link, or an empty string if none has been set.
Definition: qtextformat.h:506
QTextCharFormat charFormat() const
Returns the text fragment&#39;s character format.
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
#define emit
Definition: qobjectdefs.h:76
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
int position() const
Returns the absolute position of the cursor within the document.
int length() const
Returns the number of characters in the text fragment.
The QTextFragment class holds a piece of text in a QTextDocument with a single QTextCharFormat.
Definition: qtextobject.h:297
The QTextBlock::iterator class provides an iterator for reading the contents of a QTextBlock...
Definition: qtextobject.h:251
QTextBlock block() const
Returns the block that contains the cursor.
void clearSelection()
Clears the current selection by setting the anchor to the cursor position.
int position() const
Returns the position of this text fragment in the document.
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.
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
QTextFragment fragment() const
Returns the text fragment the iterator currently points to.
int selectionStart() const
Returns the start of the selection or position() if the cursor doesn&#39;t have a selection.
void repaintOldAndNewSelection(const QTextCursor &oldSelection)
static bool openUrl(const QUrl &url)
Opens the given url in the appropriate Web browser for the user&#39;s desktop environment, and returns true if successful; otherwise returns false.

◆ anchorForCursor()

QString QTextControlPrivate::anchorForCursor ( const QTextCursor anchor) const

Definition at line 2066 of file qtextcontrol.cpp.

Referenced by selectionRect().

2067 {
2068  if (anchorCursor.hasSelection()) {
2069  QTextCursor cursor = anchorCursor;
2070  if (cursor.selectionStart() != cursor.position())
2071  cursor.setPosition(cursor.selectionStart());
2073  QTextCharFormat fmt = cursor.charFormat();
2074  if (fmt.isAnchor() && fmt.hasProperty(QTextFormat::AnchorHref))
2076  }
2077  return QString();
2078 }
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
QTextCharFormat charFormat() const
Returns the format of the character immediately before the cursor position().
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false...
bool isAnchor() const
Returns true if the text is formatted as an anchor; otherwise returns false.
Definition: qtextformat.h:501
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
int position() const
Returns the absolute position of the cursor within the document.
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.
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
QString stringProperty(int propertyId) const
Returns the value of the property given by propertyId; if the property isn&#39;t of QVariant::String type...
int selectionStart() const
Returns the start of the selection or position() if the cursor doesn&#39;t have a selection.

◆ append()

void QTextControlPrivate::append ( const QString text,
Qt::TextFormat  format = Qt::AutoText 
)

Definition at line 2916 of file qtextcontrol.cpp.

Referenced by selectionRect().

2917 {
2918  QTextCursor tmp(doc);
2919  tmp.beginEditBlock();
2920  tmp.movePosition(QTextCursor::End);
2921 
2922  if (!doc->isEmpty())
2923  tmp.insertBlock(cursor.blockFormat(), cursor.charFormat());
2924  else
2925  tmp.setCharFormat(cursor.charFormat());
2926 
2927  // preserve the char format
2928  QTextCharFormat oldCharFormat = cursor.charFormat();
2929 
2930 #ifndef QT_NO_TEXTHTMLPARSER
2931  if (format == Qt::RichText || (format == Qt::AutoText && Qt::mightBeRichText(text))) {
2932  tmp.insertHtml(text);
2933  } else {
2934  tmp.insertText(text);
2935  }
2936 #else
2937  tmp.insertText(text);
2938 #endif // QT_NO_TEXTHTMLPARSER
2939  if (!cursor.hasSelection())
2940  cursor.setCharFormat(oldCharFormat);
2941 
2942  tmp.endEditBlock();
2943 }
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
QTextCharFormat charFormat() const
Returns the format of the character immediately before the cursor position().
QTextDocument * doc
bool isEmpty() const
Returns true if the document is empty; otherwise returns false.
Q_GUI_EXPORT bool mightBeRichText(const QString &)
Returns true if the string text is likely to be rich text; otherwise returns false.
QTextBlockFormat blockFormat() const
Returns the block format of the block the cursor is in.
void setCharFormat(const QTextCharFormat &format)
Sets the cursor&#39;s current character format to the given format.
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70

◆ contextMenuEvent()

void QTextControlPrivate::contextMenuEvent ( const QPoint screenPos,
const QPointF docPos,
QWidget contextWidget 
)

Definition at line 1843 of file qtextcontrol.cpp.

Referenced by selectionRect().

1844 {
1845 #ifdef QT_NO_CONTEXTMENU
1846  Q_UNUSED(screenPos);
1847  Q_UNUSED(docPos);
1848  Q_UNUSED(contextWidget);
1849 #else
1850  Q_Q(QTextControl);
1851  if (!hasFocus)
1852  return;
1853  QMenu *menu = q->createStandardContextMenu(docPos, contextWidget);
1854  if (!menu)
1855  return;
1857  menu->popup(screenPos);
1858 #endif
1859 }
void popup(const QPoint &pos, QAction *at=0)
Displays the menu so that the action atAction will be at the specified global position p...
Definition: qmenu.cpp:1847
#define Q_Q(Class)
Definition: qglobal.h:2483
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ createAutoBulletList()

void QTextControlPrivate::createAutoBulletList ( )

Definition at line 389 of file qtextcontrol.cpp.

390 {
392 
393  QTextBlockFormat blockFmt = cursor.blockFormat();
394 
395  QTextListFormat listFmt;
397  listFmt.setIndent(blockFmt.indent() + 1);
398 
399  blockFmt.setIndent(0);
400  cursor.setBlockFormat(blockFmt);
401 
402  cursor.createList(listFmt);
403 
405 }
void endEditBlock()
Indicates the end of a block of editing operations on the document that should appear as a single ope...
The QTextListFormat class provides formatting information for lists in a QTextDocument.
Definition: qtextformat.h:642
void setIndent(int indent)
Sets the list format&#39;s indentation.
Definition: qtextformat.h:685
QTextList * createList(const QTextListFormat &format)
Creates and returns a new list with the given format, and makes the current paragraph the cursor is i...
QTextBlockFormat blockFormat() const
Returns the block format of the block the cursor is in.
int indent() const
Returns the paragraph&#39;s indent.
Definition: qtextformat.h:590
void setBlockFormat(const QTextBlockFormat &format)
Sets the block format of the current block (or all blocks that are contained in the selection) to for...
void beginEditBlock()
Indicates the start of a block of editing operations on the document that should appear as a single o...
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
Definition: qtextformat.h:545
void setIndent(int indent)
Sets the paragraph&#39;s indentation.
Definition: qtextformat.h:622
void setStyle(Style style)
Sets the list format&#39;s style.
Definition: qtextformat.h:682

◆ cursorMoveKeyEvent()

bool QTextControlPrivate::cursorMoveKeyEvent ( QKeyEvent e)

Definition at line 139 of file qtextcontrol.cpp.

140 {
141 #ifdef QT_NO_SHORTCUT
142  Q_UNUSED(e);
143 #endif
144 
145  Q_Q(QTextControl);
146  if (cursor.isNull())
147  return false;
148 
149  const QTextCursor oldSelection = cursor;
150  const int oldCursorPos = cursor.position();
151 
154 
155  if (false) {
156  }
157 #ifndef QT_NO_SHORTCUT
158  if (e == QKeySequence::MoveToNextChar) {
159  op = QTextCursor::Right;
160  }
161  else if (e == QKeySequence::MoveToPreviousChar) {
162  op = QTextCursor::Left;
163  }
164  else if (e == QKeySequence::SelectNextChar) {
165  op = QTextCursor::Right;
167  }
168  else if (e == QKeySequence::SelectPreviousChar) {
169  op = QTextCursor::Left;
171  }
172  else if (e == QKeySequence::SelectNextWord) {
175  }
176  else if (e == QKeySequence::SelectPreviousWord) {
179  }
180  else if (e == QKeySequence::SelectStartOfLine) {
183  }
184  else if (e == QKeySequence::SelectEndOfLine) {
187  }
188  else if (e == QKeySequence::SelectStartOfBlock) {
191  }
192  else if (e == QKeySequence::SelectEndOfBlock) {
195  }
196  else if (e == QKeySequence::SelectStartOfDocument) {
197  op = QTextCursor::Start;
199  }
200  else if (e == QKeySequence::SelectEndOfDocument) {
201  op = QTextCursor::End;
203  }
204  else if (e == QKeySequence::SelectPreviousLine) {
205  op = QTextCursor::Up;
207  }
208  else if (e == QKeySequence::SelectNextLine) {
209  op = QTextCursor::Down;
211  {
212  QTextBlock block = cursor.block();
214  if (!block.next().isValid()
215  && line.isValid()
216  && line.lineNumber() == block.layout()->lineCount() - 1)
217  op = QTextCursor::End;
218  }
219  }
220  else if (e == QKeySequence::MoveToNextWord) {
222  }
223  else if (e == QKeySequence::MoveToPreviousWord) {
225  }
226  else if (e == QKeySequence::MoveToEndOfBlock) {
228  }
229  else if (e == QKeySequence::MoveToStartOfBlock) {
231  }
232  else if (e == QKeySequence::MoveToNextLine) {
233  op = QTextCursor::Down;
234  }
235  else if (e == QKeySequence::MoveToPreviousLine) {
236  op = QTextCursor::Up;
237  }
238  else if (e == QKeySequence::MoveToPreviousLine) {
239  op = QTextCursor::Up;
240  }
241  else if (e == QKeySequence::MoveToStartOfLine) {
243  }
244  else if (e == QKeySequence::MoveToEndOfLine) {
246  }
247  else if (e == QKeySequence::MoveToStartOfDocument) {
248  op = QTextCursor::Start;
249  }
250  else if (e == QKeySequence::MoveToEndOfDocument) {
251  op = QTextCursor::End;
252  }
253 #endif // QT_NO_SHORTCUT
254  else {
255  return false;
256  }
257 
258 // Except for pageup and pagedown, Mac OS X has very different behavior, we don't do it all, but
259 // here's the breakdown:
260 // Shift still works as an anchor, but only one of the other keys can be down Ctrl (Command),
261 // Alt (Option), or Meta (Control).
262 // Command/Control + Left/Right -- Move to left or right of the line
263 // + Up/Down -- Move to top bottom of the file. (Control doesn't move the cursor)
264 // Option + Left/Right -- Move one word Left/right.
265 // + Up/Down -- Begin/End of Paragraph.
266 // Home/End Top/Bottom of file. (usually don't move the cursor, but will select)
267 
268  bool visualNavigation = cursor.visualNavigation();
270  const bool moved = cursor.movePosition(op, mode);
271  cursor.setVisualNavigation(visualNavigation);
272  q->ensureCursorVisible();
273 
274  bool ignoreNavigationEvents = ignoreUnusedNavigationEvents;
275  bool isNavigationEvent = e->key() == Qt::Key_Up || e->key() == Qt::Key_Down;
276 
277 #ifdef QT_KEYPAD_NAVIGATION
278  ignoreNavigationEvents = ignoreNavigationEvents || QApplication::keypadNavigationEnabled();
279  isNavigationEvent = isNavigationEvent ||
280  (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional
281  && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right));
282 #else
283  isNavigationEvent = isNavigationEvent || e->key() == Qt::Key_Left || e->key() == Qt::Key_Right;
284 #endif
285 
286  if (moved) {
287  if (cursor.position() != oldCursorPos)
288  emit q->cursorPositionChanged();
289  emit q->microFocusChanged();
290  } else if (ignoreNavigationEvents && isNavigationEvent && oldSelection.anchor() == cursor.anchor()) {
291  return false;
292  }
293 
294  selectionChanged(/*forceEmitSelectionChanged =*/(mode == QTextCursor::KeepAnchor));
295 
296  repaintOldAndNewSelection(oldSelection);
297 
298  return true;
299 }
int anchor() const
Returns the anchor position; this is the same as position() unless there is a selection in which case...
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
QTextBlock next() const
Returns the text block in the document after this block, or an empty text block if this is the last o...
#define Q_Q(Class)
Definition: qglobal.h:2483
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
MoveMode
If the anchor() is kept where it is and the position() is moved, the text in between will be selected...
Definition: qtextcursor.h:85
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
#define emit
Definition: qobjectdefs.h:76
int lineNumber() const
Returns the position of the line in the text engine.
Definition: qtextlayout.h:243
bool visualNavigation() const
Returns true if the cursor does visual navigation; otherwise returns false.
static QTextLine currentTextLine(const QTextCursor &cursor)
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
int position() const
Returns the absolute position of the cursor within the document.
QTextBlock block() const
Returns the block that contains the cursor.
bool isNull() const
Returns true if the cursor is null; otherwise returns false.
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.
void setVisualNavigation(bool b)
Sets visual navigation to b.
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
void selectionChanged(bool forceEmitSelectionChanged=false)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
void repaintOldAndNewSelection(const QTextCursor &oldSelection)
int lineCount() const
Returns the number of lines in this text layout.
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block&#39;s contents. ...

◆ cursorRectPlusUnicodeDirectionMarkers()

QRectF QTextControlPrivate::cursorRectPlusUnicodeDirectionMarkers ( const QTextCursor cursor) const

Definition at line 2215 of file qtextcontrol.cpp.

Referenced by repaintCursor(), repaintOldAndNewSelection(), and repaintSelection().

2216 {
2217  if (cursor.isNull())
2218  return QRectF();
2219 
2220  return rectForPosition(cursor.position()).adjusted(-4, 0, 4, 0);
2221 }
QRectF rectForPosition(int position) const
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
int position() const
Returns the absolute position of the cursor within the document.
bool isNull() const
Returns true if the cursor is null; otherwise returns false.

◆ dragEnterEvent()

bool QTextControlPrivate::dragEnterEvent ( QEvent e,
const QMimeData mimeData 
)

Definition at line 1861 of file qtextcontrol.cpp.

Referenced by selectionRect().

1862 {
1863  Q_Q(QTextControl);
1864  if (!(interactionFlags & Qt::TextEditable) || !q->canInsertFromMimeData(mimeData)) {
1865  e->ignore();
1866  return false;
1867  }
1868 
1870 
1871  return true; // accept proposed action
1872 }
QTextCursor dndFeedbackCursor
Qt::TextInteractionFlags interactionFlags
#define Q_Q(Class)
Definition: qglobal.h:2483
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310

◆ dragLeaveEvent()

void QTextControlPrivate::dragLeaveEvent ( )

Definition at line 1874 of file qtextcontrol.cpp.

Referenced by selectionRect().

1875 {
1876  Q_Q(QTextControl);
1877 
1878  const QRectF crect = q->cursorRect(dndFeedbackCursor);
1880 
1881  if (crect.isValid())
1882  emit q->updateRequest(crect);
1883 }
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:661
QTextCursor dndFeedbackCursor
#define Q_Q(Class)
Definition: qglobal.h:2483
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
#define emit
Definition: qobjectdefs.h:76

◆ dragMoveEvent()

bool QTextControlPrivate::dragMoveEvent ( QEvent e,
const QMimeData mimeData,
const QPointF pos 
)

Definition at line 1885 of file qtextcontrol.cpp.

Referenced by selectionRect().

1886 {
1887  Q_Q(QTextControl);
1888  if (!(interactionFlags & Qt::TextEditable) || !q->canInsertFromMimeData(mimeData)) {
1889  e->ignore();
1890  return false;
1891  }
1892 
1893  const int cursorPos = q->hitTest(pos, Qt::FuzzyHit);
1894  if (cursorPos != -1) {
1895  QRectF crect = q->cursorRect(dndFeedbackCursor);
1896  if (crect.isValid())
1897  emit q->updateRequest(crect);
1898 
1900  dndFeedbackCursor.setPosition(cursorPos);
1901 
1902  crect = q->cursorRect(dndFeedbackCursor);
1903  emit q->updateRequest(crect);
1904  }
1905 
1906  return true; // accept proposed action
1907 }
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:661
QTextCursor dndFeedbackCursor
Qt::TextInteractionFlags interactionFlags
#define Q_Q(Class)
Definition: qglobal.h:2483
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
#define emit
Definition: qobjectdefs.h:76
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310

◆ dropEvent()

bool QTextControlPrivate::dropEvent ( const QMimeData mimeData,
const QPointF pos,
Qt::DropAction  dropAction,
QWidget source 
)

Definition at line 1909 of file qtextcontrol.cpp.

Referenced by selectionRect().

1910 {
1911  Q_Q(QTextControl);
1913 
1914  if (!(interactionFlags & Qt::TextEditable) || !q->canInsertFromMimeData(mimeData))
1915  return false;
1916 
1917  repaintSelection();
1918 
1919  QTextCursor insertionCursor = q->cursorForPosition(pos);
1920  insertionCursor.beginEditBlock();
1921 
1922  if (dropAction == Qt::MoveAction && source == contextWidget)
1924 
1925  cursor = insertionCursor;
1926  q->insertFromMimeData(mimeData);
1927  insertionCursor.endEditBlock();
1928  q->ensureCursorVisible();
1929  return true; // accept proposed action
1930 }
void endEditBlock()
Indicates the end of a block of editing operations on the document that should appear as a single ope...
QTextCursor dndFeedbackCursor
QPointer< QWidget > contextWidget
Qt::TextInteractionFlags interactionFlags
#define Q_Q(Class)
Definition: qglobal.h:2483
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
void removeSelectedText()
If there is a selection, its content is deleted; otherwise does nothing.
void beginEditBlock()
Indicates the start of a block of editing operations on the document that should appear as a single o...

◆ extendBlockwiseSelection()

void QTextControlPrivate::extendBlockwiseSelection ( int  suggestedNewPosition)

Definition at line 726 of file qtextcontrol.cpp.

Referenced by repaintSelection().

727 {
728  Q_Q(QTextControl);
729 
730  // if inside the initial selected line keep that
731  if (suggestedNewPosition >= selectedBlockOnTrippleClick.selectionStart()
732  && suggestedNewPosition <= selectedBlockOnTrippleClick.selectionEnd()) {
733  q->setTextCursor(selectedBlockOnTrippleClick);
734  return;
735  }
736 
737  if (suggestedNewPosition < selectedBlockOnTrippleClick.position()) {
739  cursor.setPosition(suggestedNewPosition, QTextCursor::KeepAnchor);
741  } else {
743  cursor.setPosition(suggestedNewPosition, QTextCursor::KeepAnchor);
746  }
747 
749 #ifndef QT_NO_CLIPBOARD
751 #endif
752  selectionChanged(true);
753  }
754 }
int selectionEnd() const
Returns the end of the selection or position() if the cursor doesn&#39;t have a selection.
Qt::TextInteractionFlags interactionFlags
#define Q_Q(Class)
Definition: qglobal.h:2483
int position() const
Returns the absolute position of the cursor within the document.
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.
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
void selectionChanged(bool forceEmitSelectionChanged=false)
QTextCursor selectedBlockOnTrippleClick
int selectionStart() const
Returns the start of the selection or position() if the cursor doesn&#39;t have a selection.

◆ extendWordwiseSelection()

void QTextControlPrivate::extendWordwiseSelection ( int  suggestedNewPosition,
qreal  mouseXPosition 
)

Definition at line 652 of file qtextcontrol.cpp.

Referenced by repaintSelection().

653 {
654  Q_Q(QTextControl);
655 
656  // if inside the initial selected word keep that
657  if (suggestedNewPosition >= selectedWordOnDoubleClick.selectionStart()
658  && suggestedNewPosition <= selectedWordOnDoubleClick.selectionEnd()) {
659  q->setTextCursor(selectedWordOnDoubleClick);
660  return;
661  }
662 
664  curs.setPosition(suggestedNewPosition, QTextCursor::KeepAnchor);
665 
667  return;
668  const int wordStartPos = curs.position();
669 
670  const int blockPos = curs.block().position();
671  const QPointF blockCoordinates = q->blockBoundingRect(curs.block()).topLeft();
672 
673  QTextLine line = currentTextLine(curs);
674  if (!line.isValid())
675  return;
676 
677  const qreal wordStartX = line.cursorToX(curs.position() - blockPos) + blockCoordinates.x();
678 
680  return;
681  const int wordEndPos = curs.position();
682 
683  const QTextLine otherLine = currentTextLine(curs);
684  if (otherLine.textStart() != line.textStart()
685  || wordEndPos == wordStartPos)
686  return;
687 
688  const qreal wordEndX = line.cursorToX(curs.position() - blockPos) + blockCoordinates.x();
689 
690  if (!wordSelectionEnabled && (mouseXPosition < wordStartX || mouseXPosition > wordEndX))
691  return;
692 
693  if (wordSelectionEnabled) {
694  if (suggestedNewPosition < selectedWordOnDoubleClick.position()) {
697  } else {
700  }
701  } else {
702  // keep the already selected word even when moving to the left
703  // (#39164)
704  if (suggestedNewPosition < selectedWordOnDoubleClick.position())
706  else
708 
709  const qreal differenceToStart = mouseXPosition - wordStartX;
710  const qreal differenceToEnd = wordEndX - mouseXPosition;
711 
712  if (differenceToStart < differenceToEnd)
714  else
716  }
717 
719 #ifndef QT_NO_CLIPBOARD
721 #endif
722  selectionChanged(true);
723  }
724 }
double qreal
Definition: qglobal.h:1193
QTextCursor selectedWordOnDoubleClick
int selectionEnd() const
Returns the end of the selection or position() if the cursor doesn&#39;t have a selection.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
Qt::TextInteractionFlags interactionFlags
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
#define Q_Q(Class)
Definition: qglobal.h:2483
int position() const
Returns the index of the block&#39;s first character within the document.
void setCursorPosition(const QPointF &pos)
qreal cursorToX(int *cursorPos, Edge edge=Leading) const
Converts the cursor position cursorPos to the corresponding x position inside the line...
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
static QTextLine currentTextLine(const QTextCursor &cursor)
int position() const
Returns the absolute position of the cursor within the document.
QTextBlock block() const
Returns the block that contains the cursor.
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.
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
void selectionChanged(bool forceEmitSelectionChanged=false)
int selectionStart() const
Returns the start of the selection or position() if the cursor doesn&#39;t have a selection.
int textStart() const
Returns the start of the line from the beginning of the string passed to the QTextLayout.

◆ focusEvent()

void QTextControlPrivate::focusEvent ( QFocusEvent e)

Definition at line 2037 of file qtextcontrol.cpp.

Referenced by selectionRect().

2038 {
2039  Q_Q(QTextControl);
2040  emit q->updateRequest(q->selectionRect());
2041  if (e->gotFocus()) {
2042 #ifdef QT_KEYPAD_NAVIGATION
2043  if (!QApplication::keypadNavigationEnabled() || (hasEditFocus && (e->reason() == Qt::PopupFocusReason
2044 #ifdef Q_OS_SYMBIAN
2046 #endif
2047  ))) {
2048 #endif
2050 #ifdef QT_KEYPAD_NAVIGATION
2051  }
2052 #endif
2053  } else {
2054  setBlinkingCursorEnabled(false);
2055 
2058  && e->reason() != Qt::PopupFocusReason
2059  && cursor.hasSelection()) {
2061  }
2062  }
2063  hasFocus = e->gotFocus();
2064 }
Qt::TextInteractionFlags interactionFlags
#define Q_Q(Class)
Definition: qglobal.h:2483
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
#define emit
Definition: qobjectdefs.h:76
void clearSelection()
Clears the current selection by setting the anchor to the cursor position.
Qt::FocusReason reason()
Definition: qevent.cpp:1197
void setBlinkingCursorEnabled(bool enable)
bool gotFocus() const
Returns true if type() is QEvent::FocusIn; otherwise returns false.
Definition: qevent.h:281

◆ gotoNextTableCell()

void QTextControlPrivate::gotoNextTableCell ( )

Definition at line 351 of file qtextcontrol.cpp.

352 {
353  QTextTable *table = cursor.currentTable();
354  QTextTableCell cell = table->cellAt(cursor);
355 
356  int newColumn = cell.column() + cell.columnSpan();
357  int newRow = cell.row();
358 
359  if (newColumn >= table->columns()) {
360  newColumn = 0;
361  ++newRow;
362  if (newRow >= table->rows())
363  table->insertRows(table->rows(), 1);
364  }
365 
366  cell = table->cellAt(newRow, newColumn);
367  cursor = cell.firstCursorPosition();
368 }
int columns() const
Returns the number of columns in the table.
void insertRows(int pos, int num)
Inserts a number of rows before the row with the specified index.
Definition: qtexttable.cpp:732
QTextTableCell cellAt(int row, int col) const
Returns the table cell at the given row and column in the table.
Definition: qtexttable.cpp:630
int column() const
Returns the number of the column in the table that contains this cell.
Definition: qtexttable.cpp:201
QTextTable * currentTable() const
Returns a pointer to the current table if the cursor position() is inside a block that is part of a t...
int row() const
Returns the number of the row in the table that contains this cell.
Definition: qtexttable.cpp:184
The QTextTable class represents a table in a QTextDocument.
Definition: qtexttable.h:103
int rows() const
Returns the number of rows in the table.
The QTextTableCell class represents the properties of a cell in a QTextTable.
Definition: qtexttable.h:59
QTextCursor firstCursorPosition() const
Returns the first valid cursor position in this cell.
Definition: qtexttable.cpp:249
int columnSpan() const
Returns the number of columns this cell spans.
Definition: qtexttable.cpp:228
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Appends a new row to the current test data.
Definition: qtestcase.cpp:2183

◆ gotoPreviousTableCell()

void QTextControlPrivate::gotoPreviousTableCell ( )

Definition at line 370 of file qtextcontrol.cpp.

371 {
372  QTextTable *table = cursor.currentTable();
373  QTextTableCell cell = table->cellAt(cursor);
374 
375  int newColumn = cell.column() - 1;
376  int newRow = cell.row();
377 
378  if (newColumn < 0) {
379  newColumn = table->columns() - 1;
380  --newRow;
381  if (newRow < 0)
382  return;
383  }
384 
385  cell = table->cellAt(newRow, newColumn);
386  cursor = cell.firstCursorPosition();
387 }
int columns() const
Returns the number of columns in the table.
QTextTableCell cellAt(int row, int col) const
Returns the table cell at the given row and column in the table.
Definition: qtexttable.cpp:630
int column() const
Returns the number of the column in the table that contains this cell.
Definition: qtexttable.cpp:201
QTextTable * currentTable() const
Returns a pointer to the current table if the cursor position() is inside a block that is part of a t...
int row() const
Returns the number of the row in the table that contains this cell.
Definition: qtexttable.cpp:184
The QTextTable class represents a table in a QTextDocument.
Definition: qtexttable.h:103
The QTextTableCell class represents the properties of a cell in a QTextTable.
Definition: qtexttable.h:59
QTextCursor firstCursorPosition() const
Returns the first valid cursor position in this cell.
Definition: qtexttable.cpp:249
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Appends a new row to the current test data.
Definition: qtestcase.cpp:2183

◆ indent()

void QTextControlPrivate::indent ( )

Definition at line 314 of file qtextcontrol.cpp.

315 {
316  QTextBlockFormat blockFmt = cursor.blockFormat();
317 
318  QTextList *list = cursor.currentList();
319  if (!list) {
320  QTextBlockFormat modifier;
321  modifier.setIndent(blockFmt.indent() + 1);
322  cursor.mergeBlockFormat(modifier);
323  } else {
324  QTextListFormat format = list->format();
325  format.setIndent(format.indent() + 1);
326 
327  if (list->itemNumber(cursor.block()) == 1)
328  list->setFormat(format);
329  else
330  cursor.createList(format);
331  }
332 }
The QTextListFormat class provides formatting information for lists in a QTextDocument.
Definition: qtextformat.h:642
void setIndent(int indent)
Sets the list format&#39;s indentation.
Definition: qtextformat.h:685
QTextList * createList(const QTextListFormat &format)
Creates and returns a new list with the given format, and makes the current paragraph the cursor is i...
QTextBlockFormat blockFormat() const
Returns the block format of the block the cursor is in.
void setFormat(const QTextListFormat &format)
Sets the list&#39;s format to format.
Definition: qtextlist.h:87
int indent() const
Returns the paragraph&#39;s indent.
Definition: qtextformat.h:590
void mergeBlockFormat(const QTextBlockFormat &modifier)
Modifies the block format of the current block (or all blocks that are contained in the selection) wi...
int itemNumber(const QTextBlock &) const
Returns the index of the list item that corresponds to the given block.
Definition: qtextlist.cpp:185
QTextList * currentList() const
Returns the current list if the cursor position() is inside a block that is part of a list; otherwise...
QTextBlock block() const
Returns the block that contains the cursor.
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
Definition: qtextformat.h:545
void setIndent(int indent)
Sets the paragraph&#39;s indentation.
Definition: qtextformat.h:622
The QTextList class provides a decorated list of items in a QTextDocument.
Definition: qtextlist.h:57
int indent() const
Returns the list format&#39;s indentation.
Definition: qtextformat.h:666
QTextListFormat format() const
Returns the list&#39;s format.
Definition: qtextlist.h:80

◆ init()

void QTextControlPrivate::init ( Qt::TextFormat  format = Qt::RichText,
const QString text = QString(),
QTextDocument document = 0 
)

Definition at line 407 of file qtextcontrol.cpp.

408 {
409  setContent(format, text, document);
410 
412 }
QTextDocument * doc
Qt::TextInteractionFlags interactionFlags
void setContent(Qt::TextFormat format=Qt::RichText, const QString &text=QString(), QTextDocument *document=0)
void setUndoRedoEnabled(bool enable)

◆ inputContext()

QInputContext * QTextControlPrivate::inputContext ( )

Definition at line 3060 of file qtextcontrol.cpp.

Referenced by selectionRect().

3061 {
3063  if (!ctx && contextWidget->parentWidget())
3065  return ctx;
3066 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
QPointer< QWidget > contextWidget
QInputContext * inputContext()
This function returns the QInputContext for this widget.
Definition: qwidget.cpp:474
#define ctx
Definition: qgl.cpp:6094
The QInputContext class abstracts the input method dependent data and composing state.
Definition: qinputcontext.h:83

◆ inputMethodEvent()

void QTextControlPrivate::inputMethodEvent ( QInputMethodEvent e)

Definition at line 1932 of file qtextcontrol.cpp.

Referenced by selectionRect().

1933 {
1934  Q_Q(QTextControl);
1936  e->ignore();
1937  return;
1938  }
1939  bool isGettingInput = !e->commitString().isEmpty()
1940  || e->preeditString() != cursor.block().layout()->preeditAreaText()
1941  || e->replacementLength() > 0;
1942 
1944  if (isGettingInput) {
1946  }
1947 
1948  // insert commit string
1949  if (!e->commitString().isEmpty() || e->replacementLength()) {
1950  QTextCursor c = cursor;
1951  c.setPosition(c.position() + e->replacementStart());
1953  c.insertText(e->commitString());
1954  }
1955 
1956  for (int i = 0; i < e->attributes().size(); ++i) {
1957  const QInputMethodEvent::Attribute &a = e->attributes().at(i);
1959  QTextCursor oldCursor = cursor;
1960  int blockStart = a.start + cursor.block().position();
1963  q->ensureCursorVisible();
1964  repaintOldAndNewSelection(oldCursor);
1965  }
1966  }
1967 
1968  QTextBlock block = cursor.block();
1969  QTextLayout *layout = block.layout();
1970  if (isGettingInput)
1971  layout->setPreeditArea(cursor.position() - block.position(), e->preeditString());
1973  const int oldPreeditCursor = preeditCursor;
1975  hideCursor = false;
1976  for (int i = 0; i < e->attributes().size(); ++i) {
1977  const QInputMethodEvent::Attribute &a = e->attributes().at(i);
1978  if (a.type == QInputMethodEvent::Cursor) {
1979  preeditCursor = a.start;
1980  hideCursor = !a.length;
1981  } else if (a.type == QInputMethodEvent::TextFormat) {
1982  QTextCharFormat f = qvariant_cast<QTextFormat>(a.value).toCharFormat();
1983  if (f.isValid()) {
1984  if (f.background().color().alphaF() == 1 && f.background().style() == Qt::SolidPattern) {
1985  f.setForeground(f.background().color());
1988  f.setFontUnderline(true);
1989  }
1991  o.start = a.start + cursor.position() - block.position();
1992  o.length = a.length;
1993  o.format = f;
1994  overrides.append(o);
1995  }
1996  }
1997  }
1998  layout->setAdditionalFormats(overrides);
1999  cursor.endEditBlock();
2000  if (cursor.d)
2001  cursor.d->setX();
2002  if (oldPreeditCursor != preeditCursor)
2003  emit q->microFocusChanged();
2004 }
void setAdditionalFormats(const QList< FormatRange > &overrides)
Sets the additional formats supported by the text layout to formatList.
const QString & preeditString() const
Returns the preedit text, i.
Definition: qevent.h:455
The QTextLayout::FormatRange structure is used to apply extra formatting information for a specified ...
Definition: qtextlayout.h:128
qreal alphaF() const
Returns the alpha color component of this color.
Definition: qcolor.cpp:1106
void endEditBlock()
Indicates the end of a block of editing operations on the document that should appear as a single ope...
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
unsigned char c[8]
Definition: qnumeric_p.h:62
int replacementStart() const
Returns the position at which characters are to be replaced relative from the start of the preedit st...
Definition: qevent.h:458
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
The QInputMethodEvent::Attribute class stores an input method attribute.
Definition: qevent.h:441
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
long ASN1_INTEGER_get ASN1_INTEGER * a
int start
Specifies the beginning of the format range within the text layout&#39;s text.
Definition: qtextlayout.h:129
void setBackground(const QBrush &brush)
Sets the brush use to paint the document&#39;s background to the brush specified.
Definition: qtextformat.h:343
bool isValid() const
Returns true if this character format is valid; otherwise returns false.
Definition: qtextformat.h:397
QSharedDataPointer< QTextCursorPrivate > d
Definition: qtextcursor.h:230
Qt::TextInteractionFlags interactionFlags
void insertText(const QString &text)
Inserts text at the current position, using the current character format.
#define Q_Q(Class)
Definition: qglobal.h:2483
int position() const
Returns the index of the block&#39;s first character within the document.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const QString & commitString() const
Returns the text that should get added to (or replace parts of) the text of the editor widget...
Definition: qevent.h:457
The QTextFormat class provides formatting information for a QTextDocument.
Definition: qtextformat.h:129
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
const char * layout
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
const QList< Attribute > & attributes() const
Returns the list of attributes passed to the QInputMethodEvent constructor.
Definition: qevent.h:454
int position() const
Returns the absolute position of the cursor within the document.
QBrush background() const
Returns the brush used to paint the document&#39;s background.
Definition: qtextformat.h:345
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
void removeSelectedText()
If there is a selection, its content is deleted; otherwise does nothing.
QTextBlock block() const
Returns the block that contains the cursor.
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.
Definition: qtextlayout.h:105
void beginEditBlock()
Indicates the start of a block of editing operations on the document that should appear as a single o...
void setFontUnderline(bool underline)
If underline is true, sets the text format&#39;s font to be underlined; otherwise it is displayed non-und...
Definition: qtextformat.h:432
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool isNull() const
Returns true if the cursor is null; otherwise returns false.
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
int length
Specifies the numer of characters the format range spans.
Definition: qtextlayout.h:130
QTextCharFormat format
Specifies the format to apply.
Definition: qtextlayout.h:131
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
Definition: qtextformat.h:350
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
int replacementLength() const
Returns the number of characters to be replaced in the preedit string.
Definition: qevent.h:459
void setUnderlineStyle(UnderlineStyle style)
Sets the style of underlining the text to style.
void setPreeditArea(int position, const QString &text)
Sets the position and text of the area in the layout that is processed before editing occurs...
void repaintOldAndNewSelection(const QTextCursor &oldSelection)
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block&#39;s contents. ...

◆ keyPressEvent()

void QTextControlPrivate::keyPressEvent ( QKeyEvent e)

Definition at line 1166 of file qtextcontrol.cpp.

Referenced by selectionRect().

1167 {
1168  Q_Q(QTextControl);
1169 #ifndef QT_NO_SHORTCUT
1170  if (e == QKeySequence::SelectAll) {
1171  e->accept();
1172  q->selectAll();
1173  return;
1174  }
1175 #ifndef QT_NO_CLIPBOARD
1176  else if (e == QKeySequence::Copy) {
1177  e->accept();
1178  q->copy();
1179  return;
1180  }
1181 #endif
1182 #endif // QT_NO_SHORTCUT
1183 
1185  && cursorMoveKeyEvent(e))
1186  goto accept;
1187 
1189  if ((e->key() == Qt::Key_Return
1190  || e->key() == Qt::Key_Enter
1191 #ifdef QT_KEYPAD_NAVIGATION
1192  || e->key() == Qt::Key_Select
1193 #endif
1194  )
1195  && cursor.hasSelection()) {
1196 
1197  e->accept();
1199  return;
1200  }
1201  }
1202 
1204  e->ignore();
1205  return;
1206  }
1207 
1208  if (e->key() == Qt::Key_Direction_L || e->key() == Qt::Key_Direction_R) {
1209  QTextBlockFormat fmt;
1211  cursor.mergeBlockFormat(fmt);
1212  goto accept;
1213  }
1214 
1215  // schedule a repaint of the region of the cursor, as when we move it we
1216  // want to make sure the old cursor disappears (not noticeable when moving
1217  // only a few pixels but noticeable when jumping between cells in tables for
1218  // example)
1219  repaintSelection();
1220 
1221  if (e->key() == Qt::Key_Backspace && !(e->modifiers() & ~Qt::ShiftModifier)) {
1222  QTextBlockFormat blockFmt = cursor.blockFormat();
1223  QTextList *list = cursor.currentList();
1224  if (list && cursor.atBlockStart() && !cursor.hasSelection()) {
1225  list->remove(cursor.block());
1226  } else if (cursor.atBlockStart() && blockFmt.indent() > 0) {
1227  blockFmt.setIndent(blockFmt.indent() - 1);
1228  cursor.setBlockFormat(blockFmt);
1229  } else {
1230  QTextCursor localCursor = cursor;
1231  localCursor.deletePreviousChar();
1232  }
1233  goto accept;
1234  }
1235 #ifndef QT_NO_SHORTCUT
1237  cursor.insertBlock();
1238  e->accept();
1239  goto accept;
1240  } else if (e == QKeySequence::InsertLineSeparator) {
1242  e->accept();
1243  goto accept;
1244  }
1245 #endif
1246  if (false) {
1247  }
1248 #ifndef QT_NO_SHORTCUT
1249  else if (e == QKeySequence::Undo) {
1250  q->undo();
1251  }
1252  else if (e == QKeySequence::Redo) {
1253  q->redo();
1254  }
1255 #ifndef QT_NO_CLIPBOARD
1256  else if (e == QKeySequence::Cut) {
1257  q->cut();
1258  }
1259  else if (e == QKeySequence::Paste) {
1261 #ifdef Q_WS_X11
1262  if (e->modifiers() == (Qt::CTRL | Qt::SHIFT) && e->key() == Qt::Key_Insert)
1263  mode = QClipboard::Selection;
1264 #endif
1265  q->paste(mode);
1266  }
1267 #endif
1268  else if (e == QKeySequence::Delete) {
1269  QTextCursor localCursor = cursor;
1270  localCursor.deleteChar();
1271  }
1272  else if (e == QKeySequence::DeleteEndOfWord) {
1273  if (!cursor.hasSelection())
1276  }
1277  else if (e == QKeySequence::DeleteStartOfWord) {
1278  if (!cursor.hasSelection())
1281  }
1282  else if (e == QKeySequence::DeleteEndOfLine) {
1283  QTextBlock block = cursor.block();
1284  if (cursor.position() == block.position() + block.length() - 2)
1286  else
1289  }
1290 #endif // QT_NO_SHORTCUT
1291  else {
1292  goto process;
1293  }
1294  goto accept;
1295 
1296 process:
1297  {
1298  QString text = e->text();
1299  if (!text.isEmpty() && (text.at(0).isPrint() || text.at(0) == QLatin1Char('\t'))) {
1300  if (overwriteMode
1301  // no need to call deleteChar() if we have a selection, insertText
1302  // does it already
1303  && !cursor.hasSelection()
1304  && !cursor.atBlockEnd())
1305  cursor.deleteChar();
1306 
1307  cursor.insertText(text);
1308  selectionChanged();
1309  } else {
1310  e->ignore();
1311  return;
1312  }
1313  }
1314 
1315  accept:
1316 
1317  e->accept();
1318  cursorOn = true;
1319 
1320  q->ensureCursorVisible();
1321 
1323 }
Mode
This enum type is used to control which part of the system clipboard is used by QClipboard::mimeData(...
Definition: qclipboard.h:71
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
QTextBlockFormat blockFormat() const
Returns the block format of the block the cursor is in.
bool atBlockStart() const
Returns true if the cursor is at the start of a block; otherwise returns false.
The QString class provides a Unicode character string.
Definition: qstring.h:83
int indent() const
Returns the paragraph&#39;s indent.
Definition: qtextformat.h:590
bool isPrint() const
Returns true if the character is a printable character; otherwise returns false.
Definition: qchar.cpp:598
void mergeBlockFormat(const QTextBlockFormat &modifier)
Modifies the block format of the current block (or all blocks that are contained in the selection) wi...
Qt::TextInteractionFlags interactionFlags
void insertText(const QString &text)
Inserts text at the current position, using the current character format.
#define Q_Q(Class)
Definition: qglobal.h:2483
int position() const
Returns the index of the block&#39;s first character within the document.
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
void activateLinkUnderCursor(QString href=QString())
bool cursorMoveKeyEvent(QKeyEvent *e)
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void setBlockFormat(const QTextBlockFormat &format)
Sets the block format of the current block (or all blocks that are contained in the selection) to for...
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
int position() const
Returns the absolute position of the cursor within the document.
int length() const
Returns the length of the block in characters.
void removeSelectedText()
If there is a selection, its content is deleted; otherwise does nothing.
QTextList * currentList() const
Returns the current list if the cursor position() is inside a block that is part of a list; otherwise...
QTextBlock block() const
Returns the block that contains the cursor.
void insertBlock()
Inserts a new empty block at the cursor position() with the current blockFormat() and charFormat()...
void remove(const QTextBlock &)
Removes the given block from the list.
Definition: qtextlist.cpp:319
QString text() const
Returns the Unicode text that this key generated.
Definition: qevent.h:236
void deletePreviousChar()
If there is no selected text, deletes the character before the current cursor position; otherwise del...
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
Definition: qtextformat.h:545
Definition: qnamespace.h:54
void setIndent(int indent)
Sets the paragraph&#39;s indentation.
Definition: qtextformat.h:622
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.
bool atBlockEnd() const
Returns true if the cursor is at the end of a block; otherwise returns false.
The QTextList class provides a decorated list of items in a QTextDocument.
Definition: qtextlist.h:57
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
void deleteChar()
If there is no selected text, deletes the character at the current cursor position; otherwise deletes...
void selectionChanged(bool forceEmitSelectionChanged=false)
void setLayoutDirection(Qt::LayoutDirection direction)
Sets the document&#39;s layout direction to the specified direction.
Definition: qtextformat.h:338
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
#define text
Definition: qobjectdefs.h:80

◆ mouseDoubleClickEvent()

void QTextControlPrivate::mouseDoubleClickEvent ( QEvent e,
Qt::MouseButton  button,
const QPointF pos,
Qt::KeyboardModifiers  modifiers,
Qt::MouseButtons  buttons,
const QPoint globalPos 
)

Definition at line 1761 of file qtextcontrol.cpp.

Referenced by selectionRect().

1763 {
1764  Q_Q(QTextControl);
1765 
1767  e, QEvent::MouseButtonDblClick, button, pos, modifiers, buttons, globalPos)) {
1768  return;
1769  }
1770 
1771  if (button != Qt::LeftButton
1773  e->ignore();
1774  return;
1775  }
1776 
1777 #ifndef QT_NO_DRAGANDDROP
1778  mightStartDrag = false;
1779 #endif
1780  const QTextCursor oldSelection = cursor;
1781  setCursorPosition(pos);
1783  bool doEmit = false;
1784  if (line.isValid() && line.textLength()) {
1786  doEmit = true;
1787  }
1788  repaintOldAndNewSelection(oldSelection);
1789 
1790  cursorIsFocusIndicator = false;
1792 
1793  trippleClickPoint = pos;
1795  if (doEmit) {
1796  selectionChanged();
1797 #ifndef QT_NO_CLIPBOARD
1799 #endif
1800  emit q->cursorPositionChanged();
1801  }
1802 }
QTextCursor selectedWordOnDoubleClick
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
static Qt::MouseButtons buttons
int textLength() const
Returns the length of the text in the line.
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
Qt::TextInteractionFlags interactionFlags
#define Q_Q(Class)
Definition: qglobal.h:2483
void setCursorPosition(const QPointF &pos)
bool sendMouseEventToInputContext(QEvent *e, QEvent::Type eventType, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos)
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
#define emit
Definition: qobjectdefs.h:76
static QTextLine currentTextLine(const QTextCursor &cursor)
void select(SelectionType selection)
Selects text in the document according to the given selection.
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void selectionChanged(bool forceEmitSelectionChanged=false)
static int doubleClickInterval()
void start(int msec, QObject *obj)
Starts (or restarts) the timer with a msec milliseconds timeout.
void repaintOldAndNewSelection(const QTextCursor &oldSelection)
QBasicTimer trippleClickTimer

◆ mouseMoveEvent()

void QTextControlPrivate::mouseMoveEvent ( QEvent e,
Qt::MouseButton  button,
const QPointF pos,
Qt::KeyboardModifiers  modifiers,
Qt::MouseButtons  buttons,
const QPoint globalPos 
)

Definition at line 1612 of file qtextcontrol.cpp.

Referenced by selectionRect().

1614 {
1615  Q_Q(QTextControl);
1616 
1618  e, QEvent::MouseMove, button, mousePos, modifiers, buttons, globalPos)) {
1619  return;
1620  }
1621 
1623  QString anchor = q->anchorAt(mousePos);
1624  if (anchor != highlightedAnchor) {
1625  highlightedAnchor = anchor;
1626  emit q->linkHovered(anchor);
1627  }
1628  }
1629 
1630  if (!(buttons & Qt::LeftButton))
1631  return;
1632 
1633  const bool editable = interactionFlags & Qt::TextEditable;
1634 
1635  if (!(mousePressed
1636  || editable
1637  || mightStartDrag
1640  return;
1641 
1642  const QTextCursor oldSelection = cursor;
1643  const int oldCursorPos = cursor.position();
1644 
1645  if (mightStartDrag) {
1646  if ((mousePos.toPoint() - dragStartPos).manhattanLength() > QApplication::startDragDistance())
1647  startDrag();
1648  return;
1649  }
1650 
1651  const qreal mouseX = qreal(mousePos.x());
1652 
1653  int newCursorPos = q->hitTest(mousePos, Qt::FuzzyHit);
1654  if (newCursorPos == -1)
1655  return;
1656 
1660  }
1661 
1663  extendBlockwiseSelection(newCursorPos);
1665  extendWordwiseSelection(newCursorPos, mouseX);
1666  else if (mousePressed)
1668 
1669  if (interactionFlags & Qt::TextEditable) {
1670  // don't call ensureVisible for the visible cursor to avoid jumping
1671  // scrollbars. the autoscrolling ensures smooth scrolling if necessary.
1672  //q->ensureCursorVisible();
1673  if (cursor.position() != oldCursorPos)
1674  emit q->cursorPositionChanged();
1676 #ifndef QT_NO_IM
1677  if (contextWidget) {
1678  if (QInputContext *ic = inputContext()) {
1679  ic->update();
1680  }
1681  }
1682 #endif //QT_NO_IM
1683  } else {
1684  //emit q->visibilityRequest(QRectF(mousePos, QSizeF(1, 1)));
1685  if (cursor.position() != oldCursorPos) {
1686  emit q->cursorPositionChanged();
1687  emit q->microFocusChanged();
1688  }
1689  }
1690  selectionChanged(true);
1691  repaintOldAndNewSelection(oldSelection);
1692 }
double qreal
Definition: qglobal.h:1193
void extendWordwiseSelection(int suggestedNewPosition, qreal mouseXPosition)
QTextCursor selectedWordOnDoubleClick
static Qt::MouseButtons buttons
The QString class provides a Unicode character string.
Definition: qstring.h:83
QPointer< QWidget > contextWidget
Qt::TextInteractionFlags interactionFlags
#define Q_Q(Class)
Definition: qglobal.h:2483
void setCursorPosition(const QPointF &pos)
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
bool sendMouseEventToInputContext(QEvent *e, QEvent::Type eventType, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos)
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
#define emit
Definition: qobjectdefs.h:76
void select(SelectionType selection)
Selects text in the document according to the given selection.
static int startDragDistance()
int position() const
Returns the absolute position of the cursor within the document.
QInputContext * inputContext()
void _q_updateCurrentCharFormatAndSelection()
void extendBlockwiseSelection(int suggestedNewPosition)
The QInputContext class abstracts the input method dependent data and composing state.
Definition: qinputcontext.h:83
void selectionChanged(bool forceEmitSelectionChanged=false)
QTextCursor selectedBlockOnTrippleClick
void repaintOldAndNewSelection(const QTextCursor &oldSelection)

◆ mousePressEvent()

void QTextControlPrivate::mousePressEvent ( QEvent e,
Qt::MouseButton  button,
const QPointF pos,
Qt::KeyboardModifiers  modifiers,
Qt::MouseButtons  buttons,
const QPoint globalPos 
)

Definition at line 1513 of file qtextcontrol.cpp.

Referenced by selectionRect().

1515 {
1516  Q_Q(QTextControl);
1517 
1519  e, QEvent::MouseButtonPress, button, pos, modifiers, buttons, globalPos)) {
1520  return;
1521  }
1522 
1524  anchorOnMousePress = q->anchorAt(pos);
1525 
1526  if (cursorIsFocusIndicator) {
1527  cursorIsFocusIndicator = false;
1528  repaintSelection();
1530  }
1531  }
1532  if (!(button & Qt::LeftButton) ||
1534  e->ignore();
1535  return;
1536  }
1537 
1538  cursorIsFocusIndicator = false;
1539  const QTextCursor oldSelection = cursor;
1540  const int oldCursorPos = cursor.position();
1541 
1543 #ifndef QT_NO_DRAGANDDROP
1544  mightStartDrag = false;
1545 #endif
1546 
1548  && ((pos - trippleClickPoint).toPoint().manhattanLength() < QApplication::startDragDistance())) {
1549 
1554 
1556 
1558  } else {
1559  int cursorPos = q->hitTest(pos, Qt::FuzzyHit);
1560  if (cursorPos == -1) {
1561  e->ignore();
1562  return;
1563  }
1564 
1565  if (modifiers == Qt::ShiftModifier && (interactionFlags & Qt::TextSelectableByMouse)) {
1569  }
1570 
1572  extendBlockwiseSelection(cursorPos);
1574  extendWordwiseSelection(cursorPos, pos.x());
1575  else if (!wordSelectionEnabled)
1577  } else {
1578 
1579  if (dragEnabled
1580  && cursor.hasSelection()
1582  && cursorPos >= cursor.selectionStart()
1583  && cursorPos <= cursor.selectionEnd()
1584  && q->hitTest(pos, Qt::ExactHit) != -1) {
1585 #ifndef QT_NO_DRAGANDDROP
1586  mightStartDrag = true;
1587  dragStartPos = pos.toPoint();
1588 #endif
1589  return;
1590  }
1591 
1592  setCursorPosition(cursorPos);
1593  }
1594  }
1595 
1596  if (interactionFlags & Qt::TextEditable) {
1597  q->ensureCursorVisible();
1598  if (cursor.position() != oldCursorPos)
1599  emit q->cursorPositionChanged();
1601  } else {
1602  if (cursor.position() != oldCursorPos) {
1603  emit q->cursorPositionChanged();
1604  emit q->microFocusChanged();
1605  }
1606  selectionChanged();
1607  }
1608  repaintOldAndNewSelection(oldSelection);
1610 }
void extendWordwiseSelection(int suggestedNewPosition, qreal mouseXPosition)
QTextCursor selectedWordOnDoubleClick
int selectionEnd() const
Returns the end of the selection or position() if the cursor doesn&#39;t have a selection.
static Qt::MouseButtons buttons
bool isActive() const
Returns true if the timer is running and has not been stopped; otherwise returns false.
Definition: qbasictimer.h:62
The QString class provides a Unicode character string.
Definition: qstring.h:83
Qt::TextInteractionFlags interactionFlags
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
#define Q_Q(Class)
Definition: qglobal.h:2483
void setCursorPosition(const QPointF &pos)
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
bool sendMouseEventToInputContext(QEvent *e, QEvent::Type eventType, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos)
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
#define emit
Definition: qobjectdefs.h:76
void select(SelectionType selection)
Selects text in the document according to the given selection.
static int startDragDistance()
int position() const
Returns the absolute position of the cursor within the document.
void clearSelection()
Clears the current selection by setting the anchor to the cursor position.
void stop()
Stops the timer.
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
void _q_updateCurrentCharFormatAndSelection()
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.
void extendBlockwiseSelection(int suggestedNewPosition)
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void selectionChanged(bool forceEmitSelectionChanged=false)
QTextCursor selectedBlockOnTrippleClick
int selectionStart() const
Returns the start of the selection or position() if the cursor doesn&#39;t have a selection.
void repaintOldAndNewSelection(const QTextCursor &oldSelection)
QBasicTimer trippleClickTimer

◆ mouseReleaseEvent()

void QTextControlPrivate::mouseReleaseEvent ( QEvent e,
Qt::MouseButton  button,
const QPointF pos,
Qt::KeyboardModifiers  modifiers,
Qt::MouseButtons  buttons,
const QPoint globalPos 
)

Definition at line 1694 of file qtextcontrol.cpp.

Referenced by selectionRect().

1696 {
1697  Q_Q(QTextControl);
1698 
1700  e, QEvent::MouseButtonRelease, button, pos, modifiers, buttons, globalPos)) {
1701  return;
1702  }
1703 
1704  const QTextCursor oldSelection = cursor;
1705  const int oldCursorPos = cursor.position();
1706 
1707 #ifndef QT_NO_DRAGANDDROP
1708  if (mightStartDrag && (button & Qt::LeftButton)) {
1709  mousePressed = false;
1710  setCursorPosition(pos);
1712  selectionChanged();
1713  }
1714 #endif
1715  if (mousePressed) {
1716  mousePressed = false;
1717 #ifndef QT_NO_CLIPBOARD
1719  selectionChanged(true);
1720  } else if (button == Qt::MidButton
1722  && QApplication::clipboard()->supportsSelection()) {
1723  setCursorPosition(pos);
1725  if (md)
1726  q->insertFromMimeData(md);
1727 #endif
1728  }
1729 
1730  repaintOldAndNewSelection(oldSelection);
1731 
1732  if (cursor.position() != oldCursorPos) {
1733  emit q->cursorPositionChanged();
1734  emit q->microFocusChanged();
1735  }
1736 
1738  if (!(button & Qt::LeftButton))
1739  return;
1740 
1741  const QString anchor = q->anchorAt(pos);
1742 
1743  if (anchor.isEmpty())
1744  return;
1745 
1746  if (!cursor.hasSelection()
1747  || (anchor == anchorOnMousePress && hadSelectionOnMousePress)) {
1748 
1749  const int anchorPos = q->hitTest(pos, Qt::ExactHit);
1750  if (anchorPos != -1) {
1751  cursor.setPosition(anchorPos);
1752 
1753  QString anchor = anchorOnMousePress;
1755  activateLinkUnderCursor(anchor);
1756  }
1757  }
1758  }
1759 }
static Qt::MouseButtons buttons
The QString class provides a Unicode character string.
Definition: qstring.h:83
Qt::TextInteractionFlags interactionFlags
#define Q_Q(Class)
Definition: qglobal.h:2483
void setCursorPosition(const QPointF &pos)
void activateLinkUnderCursor(QString href=QString())
const QMimeData * mimeData(Mode mode=Clipboard) const
Returns a reference to a QMimeData representation of the current clipboard data.
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
bool sendMouseEventToInputContext(QEvent *e, QEvent::Type eventType, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint &globalPos)
static QClipboard * clipboard()
Returns a pointer to the application global clipboard.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
#define emit
Definition: qobjectdefs.h:76
int position() const
Returns the absolute position of the cursor within the document.
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
void clearSelection()
Clears the current selection by setting the anchor to the cursor position.
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
void selectionChanged(bool forceEmitSelectionChanged=false)
void repaintOldAndNewSelection(const QTextCursor &oldSelection)

◆ outdent()

void QTextControlPrivate::outdent ( )

Definition at line 334 of file qtextcontrol.cpp.

335 {
336  QTextBlockFormat blockFmt = cursor.blockFormat();
337 
338  QTextList *list = cursor.currentList();
339 
340  if (!list) {
341  QTextBlockFormat modifier;
342  modifier.setIndent(blockFmt.indent() - 1);
343  cursor.mergeBlockFormat(modifier);
344  } else {
345  QTextListFormat listFmt = list->format();
346  listFmt.setIndent(listFmt.indent() - 1);
347  list->setFormat(listFmt);
348  }
349 }
The QTextListFormat class provides formatting information for lists in a QTextDocument.
Definition: qtextformat.h:642
void setIndent(int indent)
Sets the list format&#39;s indentation.
Definition: qtextformat.h:685
QTextBlockFormat blockFormat() const
Returns the block format of the block the cursor is in.
void setFormat(const QTextListFormat &format)
Sets the list&#39;s format to format.
Definition: qtextlist.h:87
int indent() const
Returns the paragraph&#39;s indent.
Definition: qtextformat.h:590
void mergeBlockFormat(const QTextBlockFormat &modifier)
Modifies the block format of the current block (or all blocks that are contained in the selection) wi...
QTextList * currentList() const
Returns the current list if the cursor position() is inside a block that is part of a list; otherwise...
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
Definition: qtextformat.h:545
void setIndent(int indent)
Sets the paragraph&#39;s indentation.
Definition: qtextformat.h:622
The QTextList class provides a decorated list of items in a QTextDocument.
Definition: qtextlist.h:57
int indent() const
Returns the list format&#39;s indentation.
Definition: qtextformat.h:666
QTextListFormat format() const
Returns the list&#39;s format.
Definition: qtextlist.h:80

◆ paste()

void QTextControlPrivate::paste ( const QMimeData source)

◆ rectForPosition()

QRectF QTextControlPrivate::rectForPosition ( int  position) const

Definition at line 1347 of file qtextcontrol.cpp.

Referenced by repaintSelection().

1348 {
1349  Q_Q(const QTextControl);
1350  const QTextBlock block = doc->findBlock(position);
1351  if (!block.isValid())
1352  return QRectF();
1353  const QAbstractTextDocumentLayout *docLayout = doc->documentLayout();
1354  const QTextLayout *layout = block.layout();
1355  const QPointF layoutPos = q->blockBoundingRect(block).topLeft();
1356  int relativePos = position - block.position();
1357  if (preeditCursor != 0) {
1358  int preeditPos = layout->preeditAreaPosition();
1359  if (relativePos == preeditPos)
1360  relativePos += preeditCursor;
1361  else if (relativePos > preeditPos)
1362  relativePos += layout->preeditAreaText().length();
1363  }
1364  QTextLine line = layout->lineForTextPosition(relativePos);
1365 
1366  int cursorWidth;
1367  {
1368  bool ok = false;
1369 #ifndef QT_NO_PROPERTIES
1370  cursorWidth = docLayout->property("cursorWidth").toInt(&ok);
1371 #endif
1372  if (!ok)
1373  cursorWidth = 1;
1374  }
1375 
1376  QRectF r;
1377 
1378  if (line.isValid()) {
1379  qreal x = line.cursorToX(relativePos);
1380  qreal w = 0;
1381  if (overwriteMode) {
1382  if (relativePos < line.textLength() - line.textStart())
1383  w = line.cursorToX(relativePos + 1) - x;
1384  else
1385  w = QFontMetrics(block.layout()->font()).width(QLatin1Char(' ')); // in sync with QTextLine::draw()
1386  }
1387  r = QRectF(layoutPos.x() + x, layoutPos.y() + line.y(),
1388  cursorWidth + w, line.height());
1389  } else {
1390  r = QRectF(layoutPos.x(), layoutPos.y(), cursorWidth, 10); // #### correct height
1391  }
1392 
1393  return r;
1394 }
double qreal
Definition: qglobal.h:1193
QTextDocument * doc
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
qreal y() const
Returns the line&#39;s y position.
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
int textLength() const
Returns the length of the text in the line.
QFont font() const
Returns the current font that is used for the layout, or a default font if none is set...
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
#define Q_Q(Class)
Definition: qglobal.h:2483
QTextLine lineForTextPosition(int pos) const
Returns the line that contains the cursor position specified by pos.
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
int position() const
Returns the index of the block&#39;s first character within the document.
qreal cursorToX(int *cursorPos, Edge edge=Leading) const
Converts the cursor position cursorPos to the corresponding x position inside the line...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
const char * layout
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
int preeditAreaPosition() const
Returns the position of the area in the text layout that will be processed before editing occurs...
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.
Definition: qtextlayout.h:105
QTextBlock findBlock(int pos) const
Returns the text block that contains the {pos}-th character.
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
qreal height() const
Returns the line&#39;s height.
int textStart() const
Returns the start of the line from the beginning of the string passed to the QTextLayout.
The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for ...
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block&#39;s contents. ...

◆ repaintCursor()

void QTextControlPrivate::repaintCursor ( )

Definition at line 547 of file qtextcontrol.cpp.

Referenced by setBlinkingCursorEnabled().

548 {
549  Q_Q(QTextControl);
551 }
QRectF cursorRectPlusUnicodeDirectionMarkers(const QTextCursor &cursor) const
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76

◆ repaintOldAndNewSelection()

void QTextControlPrivate::repaintOldAndNewSelection ( const QTextCursor oldSelection)

Definition at line 553 of file qtextcontrol.cpp.

Referenced by cursorMoveKeyEvent(), and repaintSelection().

554 {
555  Q_Q(QTextControl);
556  if (cursor.hasSelection()
557  && oldSelection.hasSelection()
558  && cursor.currentFrame() == oldSelection.currentFrame()
560  && !oldSelection.hasComplexSelection()
561  && cursor.anchor() == oldSelection.anchor()
562  ) {
563  QTextCursor differenceSelection(doc);
564  differenceSelection.setPosition(oldSelection.position());
565  differenceSelection.setPosition(cursor.position(), QTextCursor::KeepAnchor);
566  emit q->updateRequest(q->selectionRect(differenceSelection));
567  } else {
568  if (!oldSelection.isNull())
569  emit q->updateRequest(q->selectionRect(oldSelection) | cursorRectPlusUnicodeDirectionMarkers(oldSelection));
570  emit q->updateRequest(q->selectionRect() | cursorRectPlusUnicodeDirectionMarkers(cursor));
571  }
572 }
int anchor() const
Returns the anchor position; this is the same as position() unless there is a selection in which case...
QTextDocument * doc
QRectF cursorRectPlusUnicodeDirectionMarkers(const QTextCursor &cursor) const
#define Q_Q(Class)
Definition: qglobal.h:2483
QTextFrame * currentFrame() const
Returns a pointer to the current frame.
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
#define emit
Definition: qobjectdefs.h:76
int position() const
Returns the absolute position of the cursor within the document.
bool hasComplexSelection() const
Returns true if the cursor contains a selection that is not simply a range from selectionStart() to s...
bool isNull() const
Returns true if the cursor is null; otherwise returns false.

◆ repaintSelection()

void QTextControlPrivate::repaintSelection ( )
inline

Definition at line 102 of file qtextcontrol_p_p.h.

The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
void repaintOldAndNewSelection(const QTextCursor &oldSelection)

◆ selectionChanged()

void QTextControlPrivate::selectionChanged ( bool  forceEmitSelectionChanged = false)

Definition at line 574 of file qtextcontrol.cpp.

Referenced by _q_updateCurrentCharFormatAndSelection(), cursorMoveKeyEvent(), extendBlockwiseSelection(), extendWordwiseSelection(), and repaintSelection().

575 {
576  Q_Q(QTextControl);
577  if (forceEmitSelectionChanged) {
578  emit q->selectionChanged();
579 #ifndef QT_NO_ACCESSIBILITY
580  if (q->parent())
582 #endif
583  }
584 
585  bool current = cursor.hasSelection();
586  if (current == lastSelectionState)
587  return;
588 
589  lastSelectionState = current;
590  emit q->copyAvailable(current);
591  if (!forceEmitSelectionChanged) {
592  emit q->selectionChanged();
593 #ifndef QT_NO_ACCESSIBILITY
594  if (q->parent())
596 #endif
597  }
598  emit q->microFocusChanged();
599 }
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
#define Q_Q(Class)
Definition: qglobal.h:2483
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
#define emit
Definition: qobjectdefs.h:76

◆ selectionRect() [1/2]

QRectF QTextControlPrivate::selectionRect ( const QTextCursor cursor) const

◆ selectionRect() [2/2]

QRectF QTextControlPrivate::selectionRect ( ) const
inline

Definition at line 128 of file qtextcontrol_p_p.h.

Referenced by repaintSelection().

129  { return selectionRect(this->cursor); }
QRectF selectionRect() const

◆ sendMouseEventToInputContext()

bool QTextControlPrivate::sendMouseEventToInputContext ( QEvent e,
QEvent::Type  eventType,
Qt::MouseButton  button,
const QPointF pos,
Qt::KeyboardModifiers  modifiers,
Qt::MouseButtons  buttons,
const QPoint globalPos 
)

Definition at line 1804 of file qtextcontrol.cpp.

Referenced by selectionRect().

1807 {
1808 #if !defined(QT_NO_IM)
1809  Q_Q(QTextControl);
1810 
1812  if (contextWidget && layout && !layout->preeditAreaText().isEmpty()) {
1814  int cursorPos = q->hitTest(pos, Qt::FuzzyHit) - cursor.position();
1815 
1816  if (cursorPos < 0 || cursorPos > layout->preeditAreaText().length()) {
1817  cursorPos = -1;
1818  // don't send move events outside the preedit area
1819  if (eventType == QEvent::MouseMove)
1820  return true;
1821  }
1822  if (ctx) {
1823  QMouseEvent ev(eventType, contextWidget->mapFromGlobal(globalPos), globalPos,
1824  button, buttons, modifiers);
1825  ctx->mouseHandler(cursorPos, &ev);
1826  e->setAccepted(ev.isAccepted());
1827  }
1828  if (!layout->preeditAreaText().isEmpty())
1829  return true;
1830  }
1831 #else
1832  Q_UNUSED(e);
1833  Q_UNUSED(eventType);
1834  Q_UNUSED(button);
1835  Q_UNUSED(pos);
1836  Q_UNUSED(modifiers);
1837  Q_UNUSED(buttons);
1838  Q_UNUSED(globalPos);
1839 #endif
1840  return false;
1841 }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void setAccepted(bool accepted)
Definition: qcoreevent.h:306
static Qt::MouseButtons buttons
QPointer< QWidget > contextWidget
#define Q_Q(Class)
Definition: qglobal.h:2483
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const char * layout
int position() const
Returns the absolute position of the cursor within the document.
virtual void mouseHandler(int x, QMouseEvent *event)
This function can be reimplemented in a subclass to handle mouse press, release, double-click, and move events within the preedit text.
QTextBlock block() const
Returns the block that contains the cursor.
QInputContext * inputContext()
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
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.
Definition: qtextlayout.h:105
#define ctx
Definition: qgl.cpp:6094
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
The QInputContext class abstracts the input method dependent data and composing state.
Definition: qinputcontext.h:83
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QTextLayout * layout() const
Returns the QTextLayout that is used to lay out and display the block&#39;s contents. ...

◆ setBlinkingCursorEnabled()

void QTextControlPrivate::setBlinkingCursorEnabled ( bool  enable)

Definition at line 638 of file qtextcontrol.cpp.

Referenced by repaintSelection().

639 {
640  Q_Q(QTextControl);
641 
642  if (enable && QApplication::cursorFlashTime() > 0)
644  else
646 
647  cursorOn = enable;
648 
649  repaintCursor();
650 }
QBasicTimer cursorBlinkTimer
static int cursorFlashTime()
#define Q_Q(Class)
Definition: qglobal.h:2483
void stop()
Stops the timer.
void start(int msec, QObject *obj)
Starts (or restarts) the timer with a msec milliseconds timeout.

◆ setClipboardSelection()

void QTextControlPrivate::setClipboardSelection ( )

Definition at line 608 of file qtextcontrol.cpp.

Referenced by extendBlockwiseSelection(), extendWordwiseSelection(), and repaintSelection().

609 {
611  if (!cursor.hasSelection() || !clipboard->supportsSelection())
612  return;
613  Q_Q(QTextControl);
614  QMimeData *data = q->createMimeDataFromSelection();
615  clipboard->setMimeData(data, QClipboard::Selection);
616 }
static QWaylandClipboard * clipboard
void setMimeData(QMimeData *data, Mode mode=Clipboard)
Sets the clipboard data to src.
#define Q_Q(Class)
Definition: qglobal.h:2483
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
static QClipboard * clipboard()
Returns a pointer to the application global clipboard.
static const char * data(const QByteArray &arr)
The QClipboard class provides access to the window system clipboard.
Definition: qclipboard.h:62
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
bool supportsSelection() const
Returns true if the clipboard supports mouse selection; otherwise returns false.
Definition: qclipboard.cpp:567

◆ setContent()

void QTextControlPrivate::setContent ( Qt::TextFormat  format = Qt::RichText,
const QString text = QString(),
QTextDocument document = 0 
)

Definition at line 414 of file qtextcontrol.cpp.

Referenced by init().

415 {
416  Q_Q(QTextControl);
417 
418  // for use when called from setPlainText. we may want to re-use the currently
419  // set char format then.
420  const QTextCharFormat charFormatForInsertion = cursor.charFormat();
421 
422  bool clearDocument = true;
423  if (!doc) {
424  if (document) {
425  doc = document;
426  clearDocument = false;
427  } else {
428  palette = QApplication::palette("QTextControl");
429  doc = new QTextDocument(q);
430  }
433 
434 // #### doc->documentLayout()->setPaintDevice(viewport);
435 
438  QObject::connect(doc, SIGNAL(documentLayoutChanged()), q, SLOT(_q_documentLayoutChanged()));
439 
440  // convenience signal forwards
441  QObject::connect(doc, SIGNAL(undoAvailable(bool)), q, SIGNAL(undoAvailable(bool)));
442  QObject::connect(doc, SIGNAL(redoAvailable(bool)), q, SIGNAL(redoAvailable(bool)));
443  QObject::connect(doc, SIGNAL(modificationChanged(bool)), q, SIGNAL(modificationChanged(bool)));
444  QObject::connect(doc, SIGNAL(blockCountChanged(int)), q, SIGNAL(blockCountChanged(int)));
445  }
446 
447  bool previousUndoRedoState = doc->isUndoRedoEnabled();
448  if (!document)
449  doc->setUndoRedoEnabled(false);
450 
451  //Saving the index save some time.
452  static int contentsChangedIndex = QTextDocument::staticMetaObject.indexOfSignal("contentsChanged()");
453  static int textChangedIndex = QTextControl::staticMetaObject.indexOfSignal("textChanged()");
454  // avoid multiple textChanged() signals being emitted
455  QMetaObject::disconnect(doc, contentsChangedIndex, q, textChangedIndex);
456 
457  if (!text.isEmpty()) {
458  // clear 'our' cursor for insertion to prevent
459  // the emission of the cursorPositionChanged() signal.
460  // instead we emit it only once at the end instead of
461  // at the end of the document after loading and when
462  // positioning the cursor again to the start of the
463  // document.
464  cursor = QTextCursor();
465  if (format == Qt::PlainText) {
466  QTextCursor formatCursor(doc);
467  // put the setPlainText and the setCharFormat into one edit block,
468  // so that the syntax highlight triggers only /once/ for the entire
469  // document, not twice.
470  formatCursor.beginEditBlock();
471  doc->setPlainText(text);
472  doc->setUndoRedoEnabled(false);
473  formatCursor.select(QTextCursor::Document);
474  formatCursor.setCharFormat(charFormatForInsertion);
475  formatCursor.endEditBlock();
476  } else {
477 #ifndef QT_NO_TEXTHTMLPARSER
478  doc->setHtml(text);
479 #else
480  doc->setPlainText(text);
481 #endif
482  doc->setUndoRedoEnabled(false);
483  }
485  } else if (clearDocument) {
486  doc->clear();
487  }
488  cursor.setCharFormat(charFormatForInsertion);
489 
490  QMetaObject::connect(doc, contentsChangedIndex, q, textChangedIndex);
491  emit q->textChanged();
492  if (!document)
493  doc->setUndoRedoEnabled(previousUndoRedoState);
495  if (!document)
496  doc->setModified(false);
497 
498  q->ensureCursorVisible();
499  emit q->cursorPositionChanged();
500 }
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
static bool connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, int type=0, int *types=0)
Definition: qobject.cpp:3194
QTextCharFormat charFormat() const
Returns the format of the character immediately before the cursor position().
QTextDocument * doc
void setModified(bool m=true)
#define SLOT(a)
Definition: qobjectdefs.h:226
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
void _q_emitCursorPosChanged(const QTextCursor &someCursor)
static QPalette palette()
Returns the application palette.
void setCharFormat(const QTextCharFormat &format)
Sets the cursor&#39;s current character format to the given format.
#define Q_Q(Class)
Definition: qglobal.h:2483
void setPlainText(const QString &text)
Replaces the entire contents of the document with the given plain text.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
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...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
#define emit
Definition: qobjectdefs.h:76
bool isUndoRedoEnabled() const
static bool disconnect(const QObject *sender, int signal_index, const QObject *receiver, int method_index)
Definition: qobject.cpp:3276
void setHtml(const QString &html)
Replaces the entire contents of the document with the given HTML-formatted text in the html string...
int indexOfSignal(const char *signal) const
Finds signal and returns its index; otherwise returns -1.
void setUndoRedoEnabled(bool enable)
void _q_updateCurrentCharFormatAndSelection()
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
virtual void clear()
Clears the document.

◆ setCursorPosition() [1/2]

void QTextControlPrivate::setCursorPosition ( const QPointF pos)

Definition at line 528 of file qtextcontrol.cpp.

Referenced by extendWordwiseSelection().

529 {
530  Q_Q(QTextControl);
531  const int cursorPos = q->hitTest(pos, Qt::FuzzyHit);
532  if (cursorPos == -1)
533  return;
534  cursor.setPosition(cursorPos);
535 }
#define Q_Q(Class)
Definition: qglobal.h:2483
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...

◆ setCursorPosition() [2/2]

void QTextControlPrivate::setCursorPosition ( int  pos,
QTextCursor::MoveMode  mode = QTextCursor::MoveAnchor 
)

Definition at line 537 of file qtextcontrol.cpp.

538 {
539  cursor.setPosition(pos, mode);
540 
541  if (mode != QTextCursor::KeepAnchor) {
544  }
545 }
QTextCursor selectedWordOnDoubleClick
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
QTextCursor selectedBlockOnTrippleClick

◆ showToolTip()

void QTextControlPrivate::showToolTip ( const QPoint globalPos,
const QPointF pos,
QWidget contextWidget 
)

Definition at line 2745 of file qtextcontrol.cpp.

Referenced by selectionRect().

2746 {
2747  const QString toolTip = q_func()->cursorForPosition(pos).charFormat().toolTip();
2748  if (toolTip.isEmpty())
2749  return;
2750  QToolTip::showText(globalPos, toolTip, contextWidget);
2751 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtooltip.cpp:497

◆ startDrag()

void QTextControlPrivate::startDrag ( )

Definition at line 502 of file qtextcontrol.cpp.

503 {
504 #ifndef QT_NO_DRAGANDDROP
505  Q_Q(QTextControl);
506  mousePressed = false;
507  if (!contextWidget)
508  return;
509  QMimeData *data = q->createMimeDataFromSelection();
510 
511  QDrag *drag = new QDrag(contextWidget);
512  drag->setMimeData(data);
513 
514  Qt::DropActions actions = Qt::CopyAction;
515  Qt::DropAction action;
517  actions |= Qt::MoveAction;
518  action = drag->exec(actions, Qt::MoveAction);
519  } else {
520  action = drag->exec(actions, Qt::CopyAction);
521  }
522 
523  if (action == Qt::MoveAction && drag->target() != contextWidget)
525 #endif
526 }
The QDrag class provides support for MIME-based drag and drop data transfer.
Definition: qdrag.h:61
void setMimeData(QMimeData *data)
Sets the data to be sent to the given MIME data.
Definition: qdrag.cpp:142
Qt::DropAction exec(Qt::DropActions supportedActions=Qt::MoveAction)
Starts the drag and drop operation and returns a value indicating the requested drop action when it i...
Definition: qdrag.cpp:243
QPointer< QWidget > contextWidget
Qt::TextInteractionFlags interactionFlags
#define Q_Q(Class)
Definition: qglobal.h:2483
static const char * data(const QByteArray &arr)
DropAction
Definition: qnamespace.h:1597
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
void removeSelectedText()
If there is a selection, its content is deleted; otherwise does nothing.
QWidget * target() const
Returns the target of the drag and drop operation.
Definition: qdrag.cpp:219

◆ updateCurrentCharFormat()

void QTextControlPrivate::updateCurrentCharFormat ( )

Definition at line 301 of file qtextcontrol.cpp.

Referenced by _q_updateCurrentCharFormatAndSelection().

302 {
303  Q_Q(QTextControl);
304 
306  if (fmt == lastCharFormat)
307  return;
308  lastCharFormat = fmt;
309 
310  emit q->currentCharFormatChanged(fmt);
311  emit q->microFocusChanged();
312 }
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
QTextCharFormat charFormat() const
Returns the format of the character immediately before the cursor position().
QTextCharFormat lastCharFormat
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76

Properties

◆ acceptRichText

bool QTextControlPrivate::acceptRichText

Definition at line 207 of file qtextcontrol_p_p.h.

◆ anchorOnMousePress

QString QTextControlPrivate::anchorOnMousePress

Definition at line 222 of file qtextcontrol_p_p.h.

◆ contextWidget

QPointer<QWidget> QTextControlPrivate::contextWidget

Definition at line 197 of file qtextcontrol_p_p.h.

Referenced by selectionRect(), and startDrag().

◆ cursor

QTextCursor QTextControlPrivate::cursor

◆ cursorBlinkTimer

QBasicTimer QTextControlPrivate::cursorBlinkTimer

Definition at line 187 of file qtextcontrol_p_p.h.

Referenced by setBlinkingCursorEnabled().

◆ cursorIsFocusIndicator

bool QTextControlPrivate::cursorIsFocusIndicator

Definition at line 180 of file qtextcontrol_p_p.h.

◆ cursorOn

bool QTextControlPrivate::cursorOn

Definition at line 178 of file qtextcontrol_p_p.h.

Referenced by setBlinkingCursorEnabled().

◆ dndFeedbackCursor

QTextCursor QTextControlPrivate::dndFeedbackCursor

Definition at line 183 of file qtextcontrol_p_p.h.

◆ doc

QTextDocument* QTextControlPrivate::doc

◆ dragEnabled

bool QTextControlPrivate::dragEnabled

Definition at line 191 of file qtextcontrol_p_p.h.

◆ dragStartPos

QPoint QTextControlPrivate::dragStartPos

Definition at line 196 of file qtextcontrol_p_p.h.

◆ extraSelections

QVector<QAbstractTextDocumentLayout::Selection> QTextControlPrivate::extraSelections

Definition at line 212 of file qtextcontrol_p_p.h.

◆ hadSelectionOnMousePress

bool QTextControlPrivate::hadSelectionOnMousePress

Definition at line 223 of file qtextcontrol_p_p.h.

◆ hasFocus

bool QTextControlPrivate::hasFocus

Definition at line 215 of file qtextcontrol_p_p.h.

◆ hideCursor

bool QTextControlPrivate::hideCursor

Definition at line 210 of file qtextcontrol_p_p.h.

◆ highlightedAnchor

QString QTextControlPrivate::highlightedAnchor

Definition at line 221 of file qtextcontrol_p_p.h.

◆ ignoreAutomaticScrollbarAdjustement

bool QTextControlPrivate::ignoreAutomaticScrollbarAdjustement

Definition at line 201 of file qtextcontrol_p_p.h.

◆ ignoreUnusedNavigationEvents

bool QTextControlPrivate::ignoreUnusedNavigationEvents

Definition at line 225 of file qtextcontrol_p_p.h.

Referenced by cursorMoveKeyEvent().

◆ interactionFlags

Qt::TextInteractionFlags QTextControlPrivate::interactionFlags

◆ isEnabled

bool QTextControlPrivate::isEnabled

Definition at line 219 of file qtextcontrol_p_p.h.

◆ lastCharFormat

QTextCharFormat QTextControlPrivate::lastCharFormat

Definition at line 181 of file qtextcontrol_p_p.h.

Referenced by updateCurrentCharFormat().

◆ lastSelectionState

bool QTextControlPrivate::lastSelectionState

Definition at line 199 of file qtextcontrol_p_p.h.

Referenced by selectionChanged().

◆ linkToCopy

QString QTextControlPrivate::linkToCopy

Definition at line 230 of file qtextcontrol_p_p.h.

◆ mightStartDrag

bool QTextControlPrivate::mightStartDrag

Definition at line 195 of file qtextcontrol_p_p.h.

◆ mousePressed

bool QTextControlPrivate::mousePressed

Definition at line 193 of file qtextcontrol_p_p.h.

Referenced by startDrag().

◆ openExternalLinks

bool QTextControlPrivate::openExternalLinks

Definition at line 226 of file qtextcontrol_p_p.h.

◆ overwriteMode

bool QTextControlPrivate::overwriteMode

Definition at line 206 of file qtextcontrol_p_p.h.

◆ palette

QPalette QTextControlPrivate::palette

Definition at line 214 of file qtextcontrol_p_p.h.

Referenced by setContent().

◆ preeditCursor

int QTextControlPrivate::preeditCursor

Definition at line 209 of file qtextcontrol_p_p.h.

◆ selectedBlockOnTrippleClick

QTextCursor QTextControlPrivate::selectedBlockOnTrippleClick

Definition at line 204 of file qtextcontrol_p_p.h.

Referenced by extendBlockwiseSelection(), and setCursorPosition().

◆ selectedWordOnDoubleClick

QTextCursor QTextControlPrivate::selectedWordOnDoubleClick

Definition at line 203 of file qtextcontrol_p_p.h.

Referenced by extendWordwiseSelection(), and setCursorPosition().

◆ trippleClickPoint

QPointF QTextControlPrivate::trippleClickPoint

Definition at line 189 of file qtextcontrol_p_p.h.

◆ trippleClickTimer

QBasicTimer QTextControlPrivate::trippleClickTimer

Definition at line 188 of file qtextcontrol_p_p.h.

◆ wordSelectionEnabled

bool QTextControlPrivate::wordSelectionEnabled

Definition at line 228 of file qtextcontrol_p_p.h.

Referenced by extendWordwiseSelection().


The documentation for this class was generated from the following files: