Qt 4.8
Classes | Public Types | Signals | Public Functions | Protected Functions | Private Types | Private Slots | Private Functions | Properties | List of all members
QLineControl Class Reference

#include <qlinecontrol_p.h>

Inheritance diagram for QLineControl:
QObject

Classes

struct  Command
 
struct  MaskInputData
 

Public Types

enum  DrawFlags { DrawText = 0x01, DrawSelections = 0x02, DrawCursor = 0x04, DrawAll = DrawText | DrawSelections | DrawCursor }
 

Signals

void accepted ()
 
void cursorPositionChanged (int, int)
 
void displayTextChanged (const QString &)
 
void editingFinished ()
 
void resetInputContext ()
 
void selectionChanged ()
 
void textChanged (const QString &)
 
void textEdited (const QString &)
 
void updateMicroFocus ()
 
void updateNeeded (const QRect &)
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

bool allSelected () const
 
int ascent () const
 
void backspace ()
 Handles the behavior for the backspace key or function. More...
 
QString cancelText () const
 
void clear ()
 Clears the line control text. More...
 
void clearUndo ()
 
void complete (int key)
 
QCompletercompleter () const
 
bool composeMode () const
 
void copy (QClipboard::Mode mode=QClipboard::Clipboard) const
 Copies the currently selected text into the clipboard using the given mode. More...
 
int cursor () const
 
int cursorBlinkPeriod () const
 
void cursorForward (bool mark, int steps)
 
Qt::CursorMoveStyle cursorMoveStyle () const
 
int cursorPosition () const
 
QRect cursorRect () const
 Returns the bounds of the current cursor, as defined as a between characters cursor. More...
 
qreal cursorToX (int cursor) const
 
qreal cursorToX () const
 
int cursorWidth () const
 
void cursorWordBackward (bool mark)
 
void cursorWordForward (bool mark)
 
void del ()
 Handles the behavior for the delete key or function. More...
 
void deselect ()
 
QString displayText () const
 
void draw (QPainter *, const QPoint &, const QRect &, int flags=DrawAll)
 Draws the display text for the line control using the given painter, clip, and offset. More...
 
uint echoMode () const
 
int end () const
 
void end (bool mark)
 
bool fixup ()
 Fixes the current text so that it is valid given any set validators. More...
 
bool hasAcceptableInput () const
 
bool hasSelectedText () const
 
int height () const
 
void home (bool mark)
 
QString inputMask () const
 
bool inSelection (int x) const
 
void insert (const QString &)
 Inserts the given newText at the current cursor position. More...
 
bool isModified () const
 
bool isReadOnly () const
 
bool isRedoAvailable () const
 
bool isUndoAvailable () const
 
Qt::LayoutDirection layoutDirection () const
 
int maxLength () const
 
void moveCursor (int pos, bool mark=false)
 Moves the cursor to the given position pos. More...
 
qreal naturalTextWidth () const
 
int nextMaskBlank (int pos)
 
const QPalettepalette () const
 
QChar passwordCharacter () const
 
bool passwordEchoEditing () const
 
void paste (QClipboard::Mode mode=QClipboard::Clipboard)
 Inserts the text stored in the application clipboard into the line control. More...
 
QString preeditAreaText () const
 
int preeditCursor () const
 
int prevMaskBlank (int pos)
 
bool processEvent (QEvent *ev)
 
void processInputMethodEvent (QInputMethodEvent *event)
 
void processKeyEvent (QKeyEvent *ev)
 
void processMouseEvent (QMouseEvent *ev)
 
 QLineControl (const QString &txt=QString())
 
void redo ()
 
void removeSelection ()
 
void resetCursorBlinkTimer ()
 
void selectAll ()
 
QString selectedText () const
 
int selectionEnd () const
 
int selectionStart () const
 
void selectWordAtPos (int)
 Sets the selection to cover the word at the given cursor position. More...
 
void setCancelText (const QString &text)
 
void setCompleter (const QCompleter *c)
 
void setCursorBlinkPeriod (int msec)
 
void setCursorMoveStyle (Qt::CursorMoveStyle style)
 
void setCursorPosition (int pos)
 
void setCursorWidth (int value)
 
void setEchoMode (uint mode)
 
void setFont (const QFont &font)
 
void setInputMask (const QString &mask)
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setMaxLength (int maxLength)
 
void setModified (bool modified)
 
void setPalette (const QPalette &p)
 
void setPasswordCharacter (const QChar &character)
 
void setPreeditArea (int cursor, const QString &text)
 
void setReadOnly (bool enable)
 
void setSelection (int start, int length)
 Sets length characters from the given start position as selected. More...
 
void setText (const QString &txt)
 
void setValidator (const QValidator *v)
 
int start () const
 
QString text () const
 
QString textAfterSelection () const
 
QString textBeforeSelection () const
 
void undo ()
 
void updatePasswordEchoEditing (bool editing)
 Sets the password echo editing to editing. More...
 
const QValidatorvalidator () const
 
int width () const
 
int xToPos (int x, QTextLine::CursorPosition=QTextLine::CursorBetweenCharacters) const
 Returns the cursor position of the given x pixel value in relation to the displayed text. More...
 
 ~QLineControl ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 

Private Types

enum  CommandType {
  Separator, Insert, Remove, Delete,
  RemoveSelection, DeleteSelection, SetSelection
}
 

Private Slots

void _q_clipboardChanged ()
 
void _q_deleteSelected ()
 

Private Functions

void addCommand (const Command &cmd)
 Adds the given command to the undo history of the line control. More...
 
bool advanceToEnabledItem (int dir)
 
void cancelPasswordEchoTimer ()
 
QString clearString (uint pos, uint len) const
 Returns a "cleared" string with only separators and blank chars. More...
 
void emitCursorPositionChanged ()
 If the current cursor position differs from the last emitted cursor position, emits cursorPositionChanged(). More...
 
int findInMask (int pos, bool forward, bool findSeparator, QChar searchChar=QChar()) const
 
bool finishChange (int validateFromState=-1, bool update=false, bool edited=true)
 Completes a change to the line control text. More...
 
bool hasAcceptableInput (const QString &text) const
 Returns true if the given text str is valid for any validator or input mask set for the line control. More...
 
void init (const QString &txt)
 Initializes the line control with a starting text value of txt. More...
 
void internalDelete (bool wasBackspace=false)
 Also adds the appropriate commands into the undo history. More...
 
void internalDeselect ()
 
void internalInsert (const QString &s)
 Inserts the given string s into the line control. More...
 
void internalRedo ()
 
void internalRemove (int pos)
 
void internalSetText (const QString &txt, int pos=-1, bool edited=true)
 An internal function for setting the text of the line control. More...
 
void internalUndo (int until=-1)
 
bool isValidInput (QChar key, QChar mask) const
 
QString maskString (uint pos, const QString &str, bool clear=false) const
 Applies the inputMask on str starting from position pos in the mask. More...
 
void parseInputMask (const QString &maskFields)
 Parses the input mask specified by maskFields to generate the mask data used to handle input masks. More...
 
void removeSelectedText ()
 Also adds the appropriate commands into the undo history. More...
 
void separate ()
 
QString stripString (const QString &str) const
 Strips blank parts of the input in a QLineControl when an inputMask is set, separators are still included. More...
 
void updateDisplayText (bool forceUpdate=false)
 

Properties

int m_ascent
 
QChar m_blank
 
int m_blinkPeriod
 
uint m_blinkStatus: 1
 
int m_blinkTimer
 
QString m_cancelText
 
QPointer< QCompleterm_completer
 
int m_cursor
 
int m_cursorWidth
 
int m_deleteAllTimer
 
uint m_dragEnabled: 1
 
uint m_echoMode: 2
 
uint m_hideCursor: 1
 
QVector< Commandm_history
 
QString m_inputMask
 
int m_lastCursorPos
 
Qt::LayoutDirection m_layoutDirection
 
MaskInputDatam_maskData
 
int m_maxLength
 
int m_modifiedState
 
QPalette m_palette
 
QChar m_passwordCharacter
 
bool m_passwordEchoEditing
 
int m_preeditCursor
 
uint m_readOnly: 1
 
uint m_selDirty: 1
 
int m_selend
 
int m_selstart
 
uint m_separator: 1
 
QString m_text
 
uint m_textDirty: 1
 
QTextLayout m_textLayout
 
QList< int > m_transactions
 
QPoint m_tripleClick
 
int m_tripleClickTimer
 
int m_undoState
 
QPointer< QValidatorm_validator
 
uint m_validInput: 1
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Static Public Functions inherited from QObject
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 receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 77 of file qlinecontrol_p.h.

Enumerations

◆ CommandType

◆ DrawFlags

Enumerator
DrawText 
DrawSelections 
DrawCursor 
DrawAll 

Definition at line 323 of file qlinecontrol_p.h.

Constructors and Destructors

◆ QLineControl()

QLineControl::QLineControl ( const QString txt = QString())
inline

Definition at line 82 of file qlinecontrol_p.h.

84  m_hideCursor(false), m_separator(0), m_readOnly(0),
87  m_ascent(0), m_maxLength(32767), m_lastCursorPos(-1),
90 #ifdef QT_GUI_PASSWORD_ECHO_DELAY
91  , m_passwordEchoTimer(0)
92 #endif
93  {
94  init(txt);
95  }
Qt::LayoutDirection m_layoutDirection
void init(const QString &txt)
Initializes the line control with a starting text value of txt.
MaskInputData * m_maskData
bool m_passwordEchoEditing

◆ ~QLineControl()

QLineControl::~QLineControl ( )
inline

Definition at line 97 of file qlinecontrol_p.h.

98  {
99  delete [] m_maskData;
100  }
MaskInputData * m_maskData

Functions

◆ _q_clipboardChanged

void QLineControl::_q_clipboardChanged ( )
privateslot

Definition at line 330 of file qlinecontrol.cpp.

Referenced by copy().

331 {
332 }

◆ _q_deleteSelected

void QLineControl::_q_deleteSelected ( )
privateslot

Definition at line 334 of file qlinecontrol.cpp.

335 {
336  if (!hasSelectedText())
337  return;
338 
339  int priorState = m_undoState;
342  separate();
343  finishChange(priorState);
344 }
void resetInputContext()
void removeSelectedText()
Also adds the appropriate commands into the undo history.
#define emit
Definition: qobjectdefs.h:76
bool finishChange(int validateFromState=-1, bool update=false, bool edited=true)
Completes a change to the line control text.
bool hasSelectedText() const

◆ accepted

void QLineControl::accepted ( )
signal

Referenced by processKeyEvent().

◆ addCommand()

void QLineControl::addCommand ( const Command cmd)
private

Adds the given command to the undo history of the line control.

Warning
This function is not part of the public interface.

Does not apply the command.

Definition at line 778 of file qlinecontrol.cpp.

Referenced by internalDelete(), internalInsert(), and removeSelectedText().

779 {
781  m_history.resize(m_undoState + 2);
783  } else {
784  m_history.resize(m_undoState + 1);
785  }
786  m_separator = false;
787  m_history[m_undoState++] = cmd;
788 }
int type
Definition: qmetatype.cpp:239
QVector< Command > m_history

◆ advanceToEnabledItem()

bool QLineControl::advanceToEnabledItem ( int  dir)
private

Definition at line 1408 of file qlinecontrol.cpp.

Referenced by complete().

1409 {
1410  int start = m_completer->currentRow();
1411  if (start == -1)
1412  return false;
1413  int i = start + dir;
1414  if (dir == 0) dir = 1;
1415  do {
1416  if (!m_completer->setCurrentRow(i)) {
1417  if (!m_completer->wrapAround())
1418  break;
1419  i = i > 0 ? 0 : m_completer->completionCount() - 1;
1420  } else {
1421  QModelIndex currentIndex = m_completer->currentIndex();
1422  if (m_completer->completionModel()->flags(currentIndex) & Qt::ItemIsEnabled)
1423  return true;
1424  i += dir;
1425  }
1426  } while (i != start);
1427 
1428  m_completer->setCurrentRow(start); // restore
1429  return false;
1430 }
QAbstractItemModel * completionModel() const
Returns the completion model.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
bool setCurrentRow(int row)
Sets the current row to the row specified.
int start() const
int currentRow() const
Returns the current row.
QPointer< QCompleter > m_completer
bool wrapAround
the completions wrap around when navigating through items
Definition: qcompleter.h:74
The QModelIndex class is used to locate data in a data model.
int completionCount() const
Returns the number of completions for the current prefix.
QModelIndex currentIndex() const
Returns the model index of the current completion in the completionModel().

◆ allSelected()

bool QLineControl::allSelected ( ) const
inline

Definition at line 123 of file qlinecontrol_p.h.

123 { return !m_text.isEmpty() && m_selstart == 0 && m_selend == (int)m_text.length(); }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704

◆ ascent()

int QLineControl::ascent ( ) const
inline

Definition at line 128 of file qlinecontrol_p.h.

128 { return m_ascent; }

◆ backspace()

void QLineControl::backspace ( )

Handles the behavior for the backspace key or function.

Warning
This function is not part of the public interface.

Removes the current selection if there is a selection, otherwise removes the character prior to the cursor position.

See also
del()

Definition at line 204 of file qlinecontrol.cpp.

Referenced by processEvent(), and processKeyEvent().

205 {
206  int priorState = m_undoState;
207  if (hasSelectedText()) {
209  } else if (m_cursor) {
210  --m_cursor;
211  if (m_maskData)
213  if (m_cursor > 0 && m_text.at(m_cursor).isLowSurrogate()) {
214  // second half of a surrogate, check if we have the first half as well,
215  // if yes delete both at once
216  if (m_text.at(m_cursor - 1).isHighSurrogate()) {
217  internalDelete(true);
218  --m_cursor;
219  }
220  }
221  internalDelete(true);
222  }
223  finishChange(priorState);
224 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
bool isLowSurrogate() const
Returns true if the QChar is the low part of a utf16 surrogate (ie.
Definition: qchar.h:279
void removeSelectedText()
Also adds the appropriate commands into the undo history.
bool isHighSurrogate() const
Returns true if the QChar is the high part of a utf16 surrogate (ie.
Definition: qchar.h:276
void internalDelete(bool wasBackspace=false)
Also adds the appropriate commands into the undo history.
bool finishChange(int validateFromState=-1, bool update=false, bool edited=true)
Completes a change to the line control text.
int prevMaskBlank(int pos)
MaskInputData * m_maskData
bool hasSelectedText() const

◆ cancelPasswordEchoTimer()

void QLineControl::cancelPasswordEchoTimer ( )
inlineprivate

Definition at line 437 of file qlinecontrol_p.h.

Referenced by internalDelete(), internalSetText(), internalUndo(), removeSelectedText(), and updatePasswordEchoEditing().

438  {
439 #ifdef QT_GUI_PASSWORD_ECHO_DELAY
440  if (m_passwordEchoTimer != 0) {
441  killTimer(m_passwordEchoTimer);
442  m_passwordEchoTimer = 0;
443  }
444 #endif
445  }
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650

◆ cancelText()

QString QLineControl::cancelText ( ) const
inline

Definition at line 317 of file qlinecontrol_p.h.

317 { return m_cancelText; }
QString m_cancelText

◆ clear()

void QLineControl::clear ( )

Clears the line control text.

Warning
This function is not part of the public interface.

Definition at line 277 of file qlinecontrol.cpp.

Referenced by internalUndo(), processKeyEvent(), and timerEvent().

278 {
279  int priorState = m_undoState;
280  m_selstart = 0;
281  m_selend = m_text.length();
283  separate();
284  finishChange(priorState, /*update*/false, /*edited*/false);
285 }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void removeSelectedText()
Also adds the appropriate commands into the undo history.
bool finishChange(int validateFromState=-1, bool update=false, bool edited=true)
Completes a change to the line control text.

◆ clearString()

QString QLineControl::clearString ( uint  pos,
uint  len 
) const
private

Returns a "cleared" string with only separators and blank chars.

Warning
This function is not part of the public interface.

Calling this when no inputMask is set is undefined.

Definition at line 1220 of file qlinecontrol.cpp.

Referenced by internalDelete(), internalSetText(), maskString(), and removeSelectedText().

1221 {
1222  if (pos >= (uint)m_maxLength)
1223  return QString();
1224 
1225  QString s;
1226  int end = qMin((uint)m_maxLength, pos + len);
1227  for (int i = pos; i < end; ++i)
1228  if (m_maskData[i].separator)
1229  s += m_maskData[i].maskChar;
1230  else
1231  s += m_blank;
1232 
1233  return s;
1234 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QString class provides a Unicode character string.
Definition: qstring.h:83
unsigned int uint
Definition: qglobal.h:996
MaskInputData * m_maskData
int end() const

◆ clearUndo()

void QLineControl::clearUndo ( )
inline

Definition at line 118 of file qlinecontrol_p.h.

118 { m_history.clear(); m_modifiedState = m_undoState = 0; }
QVector< Command > m_history

◆ complete()

void QLineControl::complete ( int  key)

Definition at line 1432 of file qlinecontrol.cpp.

Referenced by QLineEditPrivate::_q_textEdited(), and processKeyEvent().

1433 {
1435  return;
1436 
1437  QString text = this->text();
1439  if (key == Qt::Key_Backspace)
1440  return;
1441  int n = 0;
1442  if (key == Qt::Key_Up || key == Qt::Key_Down) {
1443  if (textAfterSelection().length())
1444  return;
1446  : text;
1450  } else {
1451  n = (key == Qt::Key_Up) ? -1 : +1;
1452  }
1453  } else {
1455  }
1456  if (!advanceToEnabledItem(n))
1457  return;
1458  } else {
1459 #ifndef QT_KEYPAD_NAVIGATION
1460  if (text.isEmpty()) {
1461  m_completer->popup()->hide();
1462  return;
1463  }
1464 #endif
1466  }
1467 
1468  m_completer->complete();
1469 }
QString textAfterSelection() const
QString currentCompletion() const
Returns the current completion string.
QString text() const
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
CompletionMode completionMode
how the completions are provided to the user
Definition: qcompleter.h:69
QString textBeforeSelection() const
Qt::CaseSensitivity caseSensitivity
the case sensitivity of the matching
Definition: qcompleter.h:73
uint echoMode() const
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void setCompletionPrefix(const QString &prefix)
QPointer< QCompleter > m_completer
void hide()
Hides the widget.
Definition: qwidget.h:501
QString completionPrefix
the completion prefix used to provide completions.
Definition: qcompleter.h:67
bool isReadOnly() const
int compare(const QString &s) const
Definition: qstring.cpp:5037
int key
void complete(const QRect &rect=QRect())
For QCompleter::PopupCompletion and QCompletion::UnfilteredPopupCompletion modes, calling this functi...
bool advanceToEnabledItem(int dir)
bool hasSelectedText() const
QAbstractItemView * popup() const
Returns the popup used to display completions.

◆ completer()

QCompleter* QLineControl::completer ( ) const
inline

Definition at line 251 of file qlinecontrol_p.h.

Referenced by QLineEditPrivate::_q_completionHighlighted(), and QLineEditPrivate::_q_textEdited().

251 { return m_completer; }
QPointer< QCompleter > m_completer

◆ composeMode()

bool QLineControl::composeMode ( ) const
inline

Definition at line 273 of file qlinecontrol_p.h.

Referenced by QLineEditPrivate::sendMouseEventToInputContext().

273 { return !m_textLayout.preeditAreaText().isEmpty(); }
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString preeditAreaText() const
Returns the text that is inserted in the layout before editing occurs.
QTextLayout m_textLayout

◆ copy()

void QLineControl::copy ( QClipboard::Mode  mode = QClipboard::Clipboard) const

Copies the currently selected text into the clipboard using the given mode.

Warning
This function is not part of the public interface.
Note
If the echo mode is set to a mode other than Normal then copy will not work. This is to prevent using copy as a method of bypassing password features of the line control.

Definition at line 158 of file qlinecontrol.cpp.

Referenced by processKeyEvent(), and processMouseEvent().

159 {
160  QString t = selectedText();
161  if (!t.isEmpty() && m_echoMode == QLineEdit::Normal) {
163  QApplication::clipboard()->setText(t, mode);
165  this, SLOT(_q_clipboardChanged()));
166  }
167 }
#define SLOT(a)
Definition: qobjectdefs.h:226
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setText(const QString &, Mode mode=Clipboard)
Copies text into the clipboard as plain text.
Definition: qclipboard.cpp:375
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static QClipboard * clipboard()
Returns a pointer to the application global clipboard.
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
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
QString selectedText() const
void _q_clipboardChanged()
void selectionChanged()

◆ cursor()

int QLineControl::cursor ( ) const
inline

◆ cursorBlinkPeriod()

int QLineControl::cursorBlinkPeriod ( ) const
inline

Definition at line 313 of file qlinecontrol_p.h.

313 { return m_blinkPeriod; }

◆ cursorForward()

void QLineControl::cursorForward ( bool  mark,
int  steps 
)
inline

Definition at line 172 of file qlinecontrol_p.h.

Referenced by processKeyEvent().

173  {
174  int c = m_cursor;
175  if (steps > 0) {
176  while (steps--)
179  } else if (steps < 0) {
180  while (steps++)
183  }
184  moveCursor(c, mark);
185  }
Qt::CursorMoveStyle cursorMoveStyle() const
unsigned char c[8]
Definition: qnumeric_p.h:62
int nextCursorPosition(int oldPos, CursorMode mode=SkipCharacters) const
Returns the next valid cursor position after oldPos that respects the given cursor mode...
void moveCursor(int pos, bool mark=false)
Moves the cursor to the given position pos.
int rightCursorPosition(int oldPos) const
Returns the cursor position to the right of oldPos, next to it.
QTextLayout m_textLayout
int leftCursorPosition(int oldPos) const
Returns the cursor position to the left of oldPos, next to it.
int previousCursorPosition(int oldPos, CursorMode mode=SkipCharacters) const
Returns the first valid cursor position before oldPos that respects the given cursor mode...

◆ cursorMoveStyle()

Qt::CursorMoveStyle QLineControl::cursorMoveStyle ( ) const
inline

Definition at line 168 of file qlinecontrol_p.h.

Referenced by processKeyEvent().

168 { return m_textLayout.cursorMoveStyle(); }
Qt::CursorMoveStyle cursorMoveStyle() const
The cursor movement style of this QTextLayout.
QTextLayout m_textLayout

◆ cursorPosition()

int QLineControl::cursorPosition ( ) const
inline

Definition at line 257 of file qlinecontrol_p.h.

257 { return m_cursor; }

◆ cursorPositionChanged

void QLineControl::cursorPositionChanged ( int  ,
int   
)
signal

◆ cursorRect()

QRect QLineControl::cursorRect ( ) const

Returns the bounds of the current cursor, as defined as a between characters cursor.

Warning
This function is not part of the public interface.

Definition at line 403 of file qlinecontrol.cpp.

Referenced by QLineEditPrivate::cursorRect(), setCursorBlinkPeriod(), and timerEvent().

404 {
406  int c = m_cursor;
407  if (m_preeditCursor != -1)
408  c += m_preeditCursor;
409  int cix = qRound(l.cursorToX(c));
410  int w = m_cursorWidth;
411  int ch = l.height() + 1;
412 
413  return QRect(cix-5, 0, w+9, ch);
414 }
unsigned char c[8]
Definition: qnumeric_p.h:62
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
qreal cursorToX(int *cursorPos, Edge edge=Leading) const
Converts the cursor position cursorPos to the corresponding x position inside the line...
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QFactoryLoader * l
QTextLayout m_textLayout
qreal height() const
Returns the line&#39;s height.
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ cursorToX() [1/2]

qreal QLineControl::cursorToX ( int  cursor) const
inline

Definition at line 196 of file qlinecontrol_p.h.

196 { return m_textLayout.lineAt(0).cursorToX(cursor); }
int cursor() const
qreal cursorToX(int *cursorPos, Edge edge=Leading) const
Converts the cursor position cursorPos to the corresponding x position inside the line...
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
QTextLayout m_textLayout

◆ cursorToX() [2/2]

qreal QLineControl::cursorToX ( ) const
inline

Definition at line 197 of file qlinecontrol_p.h.

198  {
199  int cursor = m_cursor;
200  if (m_preeditCursor != -1)
201  cursor += m_preeditCursor;
202  return cursorToX(cursor);
203  }
int cursor() const
qreal cursorToX() const

◆ cursorWidth()

int QLineControl::cursorWidth ( ) const
inline

Definition at line 165 of file qlinecontrol_p.h.

165 { return m_cursorWidth; }

◆ cursorWordBackward()

void QLineControl::cursorWordBackward ( bool  mark)
inline

Definition at line 188 of file qlinecontrol_p.h.

Referenced by processKeyEvent().

void moveCursor(int pos, bool mark=false)
Moves the cursor to the given position pos.
QTextLayout m_textLayout
int previousCursorPosition(int oldPos, CursorMode mode=SkipCharacters) const
Returns the first valid cursor position before oldPos that respects the given cursor mode...

◆ cursorWordForward()

void QLineControl::cursorWordForward ( bool  mark)
inline

Definition at line 187 of file qlinecontrol_p.h.

Referenced by processKeyEvent().

int nextCursorPosition(int oldPos, CursorMode mode=SkipCharacters) const
Returns the next valid cursor position after oldPos that respects the given cursor mode...
void moveCursor(int pos, bool mark=false)
Moves the cursor to the given position pos.
QTextLayout m_textLayout

◆ del()

void QLineControl::del ( )

Handles the behavior for the delete key or function.

Warning
This function is not part of the public interface.

Removes the current selection if there is a selection, otherwise removes the character after the cursor position.

See also
del()

Definition at line 238 of file qlinecontrol.cpp.

Referenced by processKeyEvent().

239 {
240  int priorState = m_undoState;
241  if (hasSelectedText()) {
243  } else {
245  while (n--)
246  internalDelete();
247  }
248  finishChange(priorState);
249 }
int nextCursorPosition(int oldPos, CursorMode mode=SkipCharacters) const
Returns the next valid cursor position after oldPos that respects the given cursor mode...
void removeSelectedText()
Also adds the appropriate commands into the undo history.
void internalDelete(bool wasBackspace=false)
Also adds the appropriate commands into the undo history.
bool finishChange(int validateFromState=-1, bool update=false, bool edited=true)
Completes a change to the line control text.
QTextLayout m_textLayout
bool hasSelectedText() const

◆ deselect()

void QLineControl::deselect ( )
inline

Definition at line 218 of file qlinecontrol_p.h.

Referenced by QLineEditPrivate::_q_handleWindowActivate(), and processMouseEvent().

void internalDeselect()
bool finishChange(int validateFromState=-1, bool update=false, bool edited=true)
Completes a change to the line control text.

◆ displayText()

QString QLineControl::displayText ( ) const
inline

Definition at line 214 of file qlinecontrol_p.h.

214 { return m_textLayout.text(); }
QString text() const
Returns the layout&#39;s text.
QTextLayout m_textLayout

◆ displayTextChanged

void QLineControl::displayTextChanged ( const QString )
signal

Referenced by updateDisplayText().

◆ draw()

void QLineControl::draw ( QPainter painter,
const QPoint offset,
const QRect clip,
int  flags = DrawAll 
)

Draws the display text for the line control using the given painter, clip, and offset.

Warning
This function is not part of the public interface.

Which aspects of the display text are drawn is specified by the given flags.

If the flags contain DrawSelections, then the selection or input mask backgrounds and foregrounds will be applied before drawing the text.

If the flags contain DrawCursor a cursor of the current cursorWidth() will be drawn after drawing the text.

The display text will only be drawn if the flags contain DrawText

Definition at line 608 of file qlinecontrol.cpp.

609 {
611  if (flags & DrawSelections) {
613  if (m_selstart < m_selend) {
614  o.start = m_selstart;
615  o.length = m_selend - m_selstart;
618  } else {
619  // mask selection
621  o.start = m_cursor;
622  o.length = 1;
625  }
626  }
627  selections.append(o);
628  }
629 
630  if (flags & DrawText)
631  m_textLayout.draw(painter, offset, selections, clip);
632 
633  if (flags & DrawCursor){
634  int cursor = m_cursor;
635  if (m_preeditCursor != -1)
636  cursor += m_preeditCursor;
638  m_textLayout.drawCursor(painter, offset, cursor, m_cursorWidth);
639  }
640 }
The QTextLayout::FormatRange structure is used to apply extra formatting information for a specified ...
Definition: qtextlayout.h:128
int cursor() const
void drawCursor(QPainter *p, const QPointF &pos, int cursorPosition) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
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
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
void draw(QPainter *p, const QPointF &pos, const QVector< FormatRange > &selections=QVector< FormatRange >(), const QRectF &clip=QRectF()) const
Draws the whole layout on the painter p at the position specified by pos.
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874
QPalette m_palette
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
QTextLayout m_textLayout
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
Definition: qtextformat.h:350

◆ echoMode()

uint QLineControl::echoMode ( ) const
inline

Definition at line 227 of file qlinecontrol_p.h.

Referenced by complete(), processInputMethodEvent(), and processKeyEvent().

227 { return m_echoMode; }

◆ editingFinished

void QLineControl::editingFinished ( )
signal

Referenced by processKeyEvent().

◆ emitCursorPositionChanged()

void QLineControl::emitCursorPositionChanged ( )
private

If the current cursor position differs from the last emitted cursor position, emits cursorPositionChanged().

Warning
This function is not part of the public interface.

Definition at line 1393 of file qlinecontrol.cpp.

Referenced by finishChange(), internalRedo(), internalUndo(), moveCursor(), processInputMethodEvent(), and setSelection().

1394 {
1395  if (m_cursor != m_lastCursorPos) {
1396  const int oldLast = m_lastCursorPos;
1398  cursorPositionChanged(oldLast, m_cursor);
1399 #ifndef QT_NO_ACCESSIBILITY
1401 #endif
1402  }
1403 }
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
void cursorPositionChanged(int, int)
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273

◆ end() [1/2]

int QLineControl::end ( ) const
inline

Definition at line 155 of file qlinecontrol_p.h.

Referenced by QLineEditPrivate::_q_completionHighlighted(), clearString(), findInMask(), processKeyEvent(), selectWordAtPos(), and stripString().

155 { return m_text.length(); }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696

◆ end() [2/2]

void QLineControl::end ( bool  mark)
inline

Definition at line 191 of file qlinecontrol_p.h.

191 { moveCursor(text().length(), mark); }
QString text() const
void moveCursor(int pos, bool mark=false)
Moves the cursor to the given position pos.

◆ findInMask()

int QLineControl::findInMask ( int  pos,
bool  forward,
bool  findSeparator,
QChar  searchChar = QChar() 
) const
private
Warning
This function is not part of the public interface. searches forward/backward in m_maskData for either a separator or a m_blank

Definition at line 1266 of file qlinecontrol.cpp.

Referenced by maskString().

1267 {
1268  if (pos >= m_maxLength || pos < 0)
1269  return -1;
1270 
1271  int end = forward ? m_maxLength : -1;
1272  int step = forward ? 1 : -1;
1273  int i = pos;
1274 
1275  while (i != end) {
1276  if (findSeparator) {
1277  if (m_maskData[i].separator && m_maskData[i].maskChar == searchChar)
1278  return i;
1279  } else {
1280  if (!m_maskData[i].separator) {
1281  if (searchChar.isNull())
1282  return i;
1283  else if (isValidInput(searchChar, m_maskData[i].maskChar))
1284  return i;
1285  }
1286  }
1287  i += step;
1288  }
1289  return -1;
1290 }
bool isNull() const
Returns true if the character is the Unicode character 0x0000 (&#39;\0&#39;); otherwise returns false...
Definition: qchar.h:262
bool isValidInput(QChar key, QChar mask) const
MaskInputData * m_maskData
int end() const

◆ finishChange()

bool QLineControl::finishChange ( int  validateFromState = -1,
bool  update = false,
bool  edited = true 
)
private

Completes a change to the line control text.

Warning
This function is not part of the public interface.

If the change is not valid will undo the line control state back to the given validateFromState.

If edited is true and the change is valid, will emit textEdited() in addition to textChanged(). Otherwise only emits textChanged() on a valid change.

The update value is currently unused.

Definition at line 681 of file qlinecontrol.cpp.

Referenced by _q_deleteSelected(), backspace(), clear(), del(), insert(), internalSetText(), and processInputMethodEvent().

682 {
683  Q_UNUSED(update)
684 
685  if (m_textDirty) {
686  // do validation
687  bool wasValidInput = m_validInput;
688  m_validInput = true;
689 #ifndef QT_NO_VALIDATOR
690  if (m_validator) {
691  m_validInput = false;
692  QString textCopy = m_text;
693  int cursorCopy = m_cursor;
694  m_validInput = (m_validator->validate(textCopy, cursorCopy) != QValidator::Invalid);
695  if (m_validInput) {
696  if (m_text != textCopy) {
697  internalSetText(textCopy, cursorCopy);
698  return true;
699  }
700  m_cursor = cursorCopy;
701  }
702  }
703 #endif
704  if (validateFromState >= 0 && wasValidInput && !m_validInput) {
705  if (m_transactions.count())
706  return false;
707  internalUndo(validateFromState);
708  m_history.resize(m_undoState);
710  m_modifiedState = -1;
711  m_validInput = true;
712  m_textDirty = false;
713  }
715 
716  if (m_textDirty) {
717  m_textDirty = false;
718  QString actualText = text();
719  if (edited)
720  emit textEdited(actualText);
721  emit textChanged(actualText);
722  }
723  }
724  if (m_selDirty) {
725  m_selDirty = false;
727  }
728  if (m_cursor == m_lastCursorPos)
731  return true;
732 }
QString text() const
QVector< Command > m_history
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void emitCursorPositionChanged()
If the current cursor position differs from the last emitted cursor position, emits cursorPositionCha...
The QString class provides a Unicode character string.
Definition: qstring.h:83
void internalSetText(const QString &txt, int pos=-1, bool edited=true)
An internal function for setting the text of the line control.
void internalUndo(int until=-1)
QList< int > m_transactions
#define emit
Definition: qobjectdefs.h:76
virtual State validate(QString &, int &) const =0
This virtual function returns Invalid if input is invalid according to this validator&#39;s rules...
void updateMicroFocus()
void textEdited(const QString &)
QPointer< QValidator > m_validator
void textChanged(const QString &)
void selectionChanged()
void updateDisplayText(bool forceUpdate=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

◆ fixup()

bool QLineControl::fixup ( )

Fixes the current text so that it is valid given any set validators.

Warning
This function is not part of the public interface.

Returns true if the text was changed. Otherwise returns false.

Definition at line 426 of file qlinecontrol.cpp.

Referenced by processKeyEvent().

427 {
428 #ifndef QT_NO_VALIDATOR
429  if (m_validator) {
430  QString textCopy = m_text;
431  int cursorCopy = m_cursor;
432  m_validator->fixup(textCopy);
433  if (m_validator->validate(textCopy, cursorCopy) == QValidator::Acceptable) {
434  if (textCopy != m_text || cursorCopy != m_cursor)
435  internalSetText(textCopy, cursorCopy);
436  return true;
437  }
438  }
439 #endif
440  return false;
441 }
virtual void fixup(QString &) const
This function attempts to change input to be valid according to this validator&#39;s rules.
Definition: qvalidator.cpp:246
The QString class provides a Unicode character string.
Definition: qstring.h:83
void internalSetText(const QString &txt, int pos=-1, bool edited=true)
An internal function for setting the text of the line control.
virtual State validate(QString &, int &) const =0
This virtual function returns Invalid if input is invalid according to this validator&#39;s rules...
QPointer< QValidator > m_validator

◆ hasAcceptableInput() [1/2]

bool QLineControl::hasAcceptableInput ( ) const
inline

Definition at line 260 of file qlinecontrol_p.h.

Referenced by hasAcceptableInput(), and processKeyEvent().

260 { return hasAcceptableInput(m_text); }
bool hasAcceptableInput() const

◆ hasAcceptableInput() [2/2]

bool QLineControl::hasAcceptableInput ( const QString str) const
private

Returns true if the given text str is valid for any validator or input mask set for the line control.

Warning
This function is not part of the public interface.

Otherwise returns false

Definition at line 1103 of file qlinecontrol.cpp.

1104 {
1105 #ifndef QT_NO_VALIDATOR
1106  QString textCopy = str;
1107  int cursorCopy = m_cursor;
1108  if (m_validator && m_validator->validate(textCopy, cursorCopy)
1110  return false;
1111 #endif
1112 
1113  if (!m_maskData)
1114  return true;
1115 
1116  if (str.length() != m_maxLength)
1117  return false;
1118 
1119  for (int i=0; i < m_maxLength; ++i) {
1120  if (m_maskData[i].separator) {
1121  if (str.at(i) != m_maskData[i].maskChar)
1122  return false;
1123  } else {
1124  if (!isValidInput(str.at(i), m_maskData[i].maskChar))
1125  return false;
1126  }
1127  }
1128  return true;
1129 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
bool isValidInput(QChar key, QChar mask) const
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual State validate(QString &, int &) const =0
This virtual function returns Invalid if input is invalid according to this validator&#39;s rules...
QPointer< QValidator > m_validator
MaskInputData * m_maskData

◆ hasSelectedText()

bool QLineControl::hasSelectedText ( ) const
inline

Definition at line 124 of file qlinecontrol_p.h.

Referenced by _q_deleteSelected(), QLineEditPrivate::_q_handleWindowActivate(), QLineEditPrivate::_q_selectionChanged(), backspace(), complete(), del(), internalDelete(), internalInsert(), paste(), and processKeyEvent().

124 { return !m_text.isEmpty() && m_selend > m_selstart; }
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704

◆ height()

int QLineControl::height ( ) const
inline

Definition at line 127 of file qlinecontrol_p.h.

127 { return qRound(m_textLayout.lineAt(0).height()) + 1; }
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
QTextLayout m_textLayout
qreal height() const
Returns the line&#39;s height.
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ home()

void QLineControl::home ( bool  mark)
inline

Definition at line 190 of file qlinecontrol_p.h.

Referenced by processKeyEvent().

190 { moveCursor(0, mark); }
void moveCursor(int pos, bool mark=false)
Moves the cursor to the given position pos.

◆ init()

void QLineControl::init ( const QString txt)
private

Initializes the line control with a starting text value of txt.

Warning
This function is not part of the public interface.

Definition at line 354 of file qlinecontrol.cpp.

355 {
356  m_text = txt;
358  m_cursor = m_text.length();
359 }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void updateDisplayText(bool forceUpdate=false)

◆ inputMask()

QString QLineControl::inputMask ( ) const
inline

Definition at line 263 of file qlinecontrol_p.h.

Referenced by setCursorBlinkPeriod(), QLineEditPrivate::setCursorVisible(), and timerEvent().

263 { return m_maskData ? m_inputMask + QLatin1Char(';') + m_blank : QString(); }
QString m_inputMask
The QString class provides a Unicode character string.
Definition: qstring.h:83
MaskInputData * m_maskData
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ inSelection()

bool QLineControl::inSelection ( int  x) const
inline

Definition at line 139 of file qlinecontrol_p.h.

140  {
141  if (m_selstart >= m_selend)
142  return false;
143  int pos = xToPos(x, QTextLine::CursorOnCharacter);
144  return pos >= m_selstart && pos < m_selend;
145  }
int xToPos(int x, QTextLine::CursorPosition=QTextLine::CursorBetweenCharacters) const
Returns the cursor position of the given x pixel value in relation to the displayed text...

◆ insert()

void QLineControl::insert ( const QString newText)

Inserts the given newText at the current cursor position.

Warning
This function is not part of the public interface.

If there is any selected text it is removed prior to insertion of the new text.

Definition at line 261 of file qlinecontrol.cpp.

Referenced by paste(), processKeyEvent(), and processMouseEvent().

262 {
263  int priorState = m_undoState;
265  internalInsert(newText);
266  finishChange(priorState);
267 }
void removeSelectedText()
Also adds the appropriate commands into the undo history.
bool finishChange(int validateFromState=-1, bool update=false, bool edited=true)
Completes a change to the line control text.
void internalInsert(const QString &s)
Inserts the given string s into the line control.

◆ internalDelete()

void QLineControl::internalDelete ( bool  wasBackspace = false)
private

Also adds the appropriate commands into the undo history.

Warning
This function is not part of the public interface.

deletes a single character from the current text. If wasBackspace, the character prior to the cursor is removed. Otherwise the character after the cursor is removed.

This function does not call finishChange(), and may leave the text in an invalid state.

Definition at line 849 of file qlinecontrol.cpp.

Referenced by backspace(), and del().

850 {
851  if (m_cursor < (int) m_text.length()) {
853  if (hasSelectedText())
855  addCommand(Command((CommandType)((m_maskData ? 2 : 0) + (wasBackspace ? Remove : Delete)),
856  m_cursor, m_text.at(m_cursor), -1, -1));
857  if (m_maskData) {
859  addCommand(Command(Insert, m_cursor, m_text.at(m_cursor), -1, -1));
860  } else {
861  m_text.remove(m_cursor, 1);
862  }
863  m_textDirty = true;
864  }
865 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
void cancelPasswordEchoTimer()
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void addCommand(const Command &cmd)
Adds the given command to the undo history of the line control.
QString clearString(uint pos, uint len) const
Returns a "cleared" string with only separators and blank chars.
MaskInputData * m_maskData
bool hasSelectedText() const
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867

◆ internalDeselect()

void QLineControl::internalDeselect ( )
inlineprivate

Definition at line 343 of file qlinecontrol_p.h.

Referenced by internalRedo(), internalSetText(), internalUndo(), moveCursor(), and removeSelectedText().

344  {
346  m_selstart = m_selend = 0;
347  }

◆ internalInsert()

void QLineControl::internalInsert ( const QString s)
private

Inserts the given string s into the line control.

Warning
This function is not part of the public interface.

Also adds the appropriate commands into the undo history. This function does not call finishChange(), and may leave the text in an invalid state.

Definition at line 803 of file qlinecontrol.cpp.

Referenced by insert(), and processInputMethodEvent().

804 {
805 #ifdef QT_GUI_PASSWORD_ECHO_DELAY
807  if (m_passwordEchoTimer != 0)
808  killTimer(m_passwordEchoTimer);
809  m_passwordEchoTimer = startTimer(qt_passwordEchoDelay);
810  }
811 #endif
812  if (hasSelectedText())
814  if (m_maskData) {
815  QString ms = maskString(m_cursor, s);
816  for (int i = 0; i < (int) ms.length(); ++i) {
817  addCommand (Command(DeleteSelection, m_cursor + i, m_text.at(m_cursor + i), -1, -1));
818  addCommand(Command(Insert, m_cursor + i, ms.at(i), -1, -1));
819  }
820  m_text.replace(m_cursor, ms.length(), ms);
821  m_cursor += ms.length();
823  m_textDirty = true;
824  } else {
825  int remaining = m_maxLength - m_text.length();
826  if (remaining != 0) {
827  m_text.insert(m_cursor, s.left(remaining));
828  for (int i = 0; i < (int) s.left(remaining).length(); ++i)
829  addCommand(Command(Insert, m_cursor++, s.at(i), -1, -1));
830  m_textDirty = true;
831  }
832  }
833 }
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void addCommand(const Command &cmd)
Adds the given command to the undo history of the line control.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
int nextMaskBlank(int pos)
MaskInputData * m_maskData
QString maskString(uint pos, const QString &str, bool clear=false) const
Applies the inputMask on str starting from position pos in the mask.
bool hasSelectedText() const
QString & insert(int i, QChar c)
Definition: qstring.cpp:1671
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650

◆ internalRedo()

void QLineControl::internalRedo ( )
private

Definition at line 1341 of file qlinecontrol.cpp.

1342 {
1343  if (!isRedoAvailable())
1344  return;
1345  internalDeselect();
1346  while (m_undoState < (int)m_history.size()) {
1347  Command& cmd = m_history[m_undoState++];
1348  switch (cmd.type) {
1349  case Insert:
1350  m_text.insert(cmd.pos, cmd.uc);
1351  m_cursor = cmd.pos + 1;
1352  break;
1353  case SetSelection:
1354  m_selstart = cmd.selStart;
1355  m_selend = cmd.selEnd;
1356  m_cursor = cmd.pos;
1357  break;
1358  case Remove:
1359  case Delete:
1360  case RemoveSelection:
1361  case DeleteSelection:
1362  m_text.remove(cmd.pos, 1);
1363  m_selstart = cmd.selStart;
1364  m_selend = cmd.selEnd;
1365  m_cursor = cmd.pos;
1366  break;
1367  case Separator:
1368  m_selstart = cmd.selStart;
1369  m_selend = cmd.selEnd;
1370  m_cursor = cmd.pos;
1371  break;
1372  }
1373  if (m_undoState < (int)m_history.size()) {
1374  Command& next = m_history[m_undoState];
1375  if (next.type != cmd.type && cmd.type < RemoveSelection && next.type != Separator
1376  && (next.type < RemoveSelection || cmd.type == Separator))
1377  break;
1378  }
1379  }
1380  m_textDirty = true;
1382 }
QVector< Command > m_history
void emitCursorPositionChanged()
If the current cursor position differs from the last emitted cursor position, emits cursorPositionCha...
bool isRedoAvailable() const
void internalDeselect()
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
QString & insert(int i, QChar c)
Definition: qstring.cpp:1671

◆ internalRemove()

void QLineControl::internalRemove ( int  pos)
private

◆ internalSetText()

void QLineControl::internalSetText ( const QString txt,
int  pos = -1,
bool  edited = true 
)
private

An internal function for setting the text of the line control.

Warning
This function is not part of the public interface.

Definition at line 742 of file qlinecontrol.cpp.

Referenced by finishChange(), fixup(), and parseInputMask().

743 {
747  QString oldText = m_text;
748  if (m_maskData) {
749  m_text = maskString(0, txt, true);
751  } else {
752  m_text = txt.isEmpty() ? txt : txt.left(m_maxLength);
753  }
754  m_history.clear();
756  m_cursor = (pos < 0 || pos > m_text.length()) ? m_text.length() : pos;
757  m_textDirty = (oldText != m_text);
758  bool changed = finishChange(-1, true, edited);
759 
760 #ifndef QT_NO_ACCESSIBILITY
761  if (changed)
763 #else
764  Q_UNUSED(changed);
765 #endif
766 }
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
void resetInputContext()
void cancelPasswordEchoTimer()
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QVector< Command > m_history
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define emit
Definition: qobjectdefs.h:76
QString clearString(uint pos, uint len) const
Returns a "cleared" string with only separators and blank chars.
void internalDeselect()
bool finishChange(int validateFromState=-1, bool update=false, bool edited=true)
Completes a change to the line control text.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
MaskInputData * m_maskData
QString maskString(uint pos, const QString &str, bool clear=false) const
Applies the inputMask on str starting from position pos in the mask.
#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

◆ internalUndo()

void QLineControl::internalUndo ( int  until = -1)
private

Definition at line 1292 of file qlinecontrol.cpp.

Referenced by finishChange().

1293 {
1294  if (!isUndoAvailable())
1295  return;
1297  internalDeselect();
1298 
1299  // Undo works only for clearing the line when in any of password the modes
1300  if (m_echoMode != QLineEdit::Normal) {
1301  clear();
1302  return;
1303  }
1304 
1305  while (m_undoState && m_undoState > until) {
1306  Command& cmd = m_history[--m_undoState];
1307  switch (cmd.type) {
1308  case Insert:
1309  m_text.remove(cmd.pos, 1);
1310  m_cursor = cmd.pos;
1311  break;
1312  case SetSelection:
1313  m_selstart = cmd.selStart;
1314  m_selend = cmd.selEnd;
1315  m_cursor = cmd.pos;
1316  break;
1317  case Remove:
1318  case RemoveSelection:
1319  m_text.insert(cmd.pos, cmd.uc);
1320  m_cursor = cmd.pos + 1;
1321  break;
1322  case Delete:
1323  case DeleteSelection:
1324  m_text.insert(cmd.pos, cmd.uc);
1325  m_cursor = cmd.pos;
1326  break;
1327  case Separator:
1328  continue;
1329  }
1330  if (until < 0 && m_undoState) {
1331  Command& next = m_history[m_undoState-1];
1332  if (next.type != cmd.type && next.type < RemoveSelection
1333  && (cmd.type < RemoveSelection || next.type == Separator))
1334  break;
1335  }
1336  }
1337  m_textDirty = true;
1339 }
void cancelPasswordEchoTimer()
QVector< Command > m_history
void emitCursorPositionChanged()
If the current cursor position differs from the last emitted cursor position, emits cursorPositionCha...
void internalDeselect()
bool isUndoAvailable() const
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
QString & insert(int i, QChar c)
Definition: qstring.cpp:1671
void clear()
Clears the line control text.

◆ isModified()

bool QLineControl::isModified ( ) const
inline

Definition at line 120 of file qlinecontrol_p.h.

120 { return m_modifiedState != m_undoState; }

◆ isReadOnly()

bool QLineControl::isReadOnly ( ) const
inline

◆ isRedoAvailable()

bool QLineControl::isRedoAvailable ( ) const

Definition at line 2005 of file qlinecontrol.cpp.

Referenced by internalRedo().

2006 {
2007  // Same as with undo. Disabled for password modes.
2008  return !m_readOnly
2010  && m_undoState < m_history.size();
2011 }
QVector< Command > m_history

◆ isUndoAvailable()

bool QLineControl::isUndoAvailable ( ) const

Definition at line 1997 of file qlinecontrol.cpp.

Referenced by internalUndo().

1998 {
1999  // For security reasons undo is not available in any password mode (NoEcho included)
2000  // with the exception that the user can clear the password with undo.
2001  return !m_readOnly && m_undoState
2003 }
QVector< Command > m_history

◆ isValidInput()

bool QLineControl::isValidInput ( QChar  key,
QChar  mask 
) const
private
Warning
This function is not part of the public interface.

checks if the key is valid compared to the inputMask

Definition at line 1023 of file qlinecontrol.cpp.

Referenced by findInMask(), hasAcceptableInput(), and maskString().

1024 {
1025  switch (mask.unicode()) {
1026  case 'A':
1027  if (key.isLetter())
1028  return true;
1029  break;
1030  case 'a':
1031  if (key.isLetter() || key == m_blank)
1032  return true;
1033  break;
1034  case 'N':
1035  if (key.isLetterOrNumber())
1036  return true;
1037  break;
1038  case 'n':
1039  if (key.isLetterOrNumber() || key == m_blank)
1040  return true;
1041  break;
1042  case 'X':
1043  if (key.isPrint())
1044  return true;
1045  break;
1046  case 'x':
1047  if (key.isPrint() || key == m_blank)
1048  return true;
1049  break;
1050  case '9':
1051  if (key.isNumber())
1052  return true;
1053  break;
1054  case '0':
1055  if (key.isNumber() || key == m_blank)
1056  return true;
1057  break;
1058  case 'D':
1059  if (key.isNumber() && key.digitValue() > 0)
1060  return true;
1061  break;
1062  case 'd':
1063  if ((key.isNumber() && key.digitValue() > 0) || key == m_blank)
1064  return true;
1065  break;
1066  case '#':
1067  if (key.isNumber() || key == QLatin1Char('+') || key == QLatin1Char('-') || key == m_blank)
1068  return true;
1069  break;
1070  case 'B':
1071  if (key == QLatin1Char('0') || key == QLatin1Char('1'))
1072  return true;
1073  break;
1074  case 'b':
1075  if (key == QLatin1Char('0') || key == QLatin1Char('1') || key == m_blank)
1076  return true;
1077  break;
1078  case 'H':
1079  if (key.isNumber() || (key >= QLatin1Char('a') && key <= QLatin1Char('f')) || (key >= QLatin1Char('A') && key <= QLatin1Char('F')))
1080  return true;
1081  break;
1082  case 'h':
1083  if (key.isNumber() || (key >= QLatin1Char('a') && key <= QLatin1Char('f')) || (key >= QLatin1Char('A') && key <= QLatin1Char('F')) || key == m_blank)
1084  return true;
1085  break;
1086  default:
1087  break;
1088  }
1089  return false;
1090 }
bool isLetter() const
Returns true if the character is a letter (Letter_* categories); otherwise returns false...
Definition: qchar.cpp:653
int digitValue() const
Returns the numeric value of the digit, or -1 if the character is not a digit.
Definition: qchar.cpp:817
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
bool isPrint() const
Returns true if the character is a printable character; otherwise returns false.
Definition: qchar.cpp:598
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool isNumber() const
Returns true if the character is a number (Number_* categories, not just 0-9); otherwise returns fals...
Definition: qchar.cpp:669
bool isLetterOrNumber() const
Returns true if the character is a letter or number (Letter_* or Number_* categories); otherwise retu...
Definition: qchar.cpp:681

◆ layoutDirection()

Qt::LayoutDirection QLineControl::layoutDirection ( ) const
inline

Definition at line 291 of file qlinecontrol_p.h.

Referenced by processKeyEvent().

291  {
293  if (m_text.isEmpty())
296  }
297  return m_layoutDirection;
298  }
Qt::LayoutDirection m_layoutDirection
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
bool isRightToLeft() const
Returns true if the string is read right to left.
Definition: qstring.cpp:7528
static Qt::LayoutDirection keyboardInputDirection()
Returns the current keyboard input direction.

◆ maskString()

QString QLineControl::maskString ( uint  pos,
const QString str,
bool  clear = false 
) const
private

Applies the inputMask on str starting from position pos in the mask.

Warning
This function is not part of the public interface.

clear specifies from where characters should be gotten when a separator is met in str - true means that blanks will be used, false that previous input is used. Calling this when no inputMask is set is undefined.

Definition at line 1142 of file qlinecontrol.cpp.

Referenced by internalInsert(), and internalSetText().

1143 {
1144  if (pos >= (uint)m_maxLength)
1145  return QString::fromLatin1("");
1146 
1147  QString fill;
1148  fill = clear ? clearString(0, m_maxLength) : m_text;
1149 
1150  int strIndex = 0;
1151  QString s = QString::fromLatin1("");
1152  int i = pos;
1153  while (i < m_maxLength) {
1154  if (strIndex < str.length()) {
1155  if (m_maskData[i].separator) {
1156  s += m_maskData[i].maskChar;
1157  if (str[(int)strIndex] == m_maskData[i].maskChar)
1158  strIndex++;
1159  ++i;
1160  } else {
1161  if (isValidInput(str[(int)strIndex], m_maskData[i].maskChar)) {
1162  switch (m_maskData[i].caseMode) {
1163  case MaskInputData::Upper:
1164  s += str[(int)strIndex].toUpper();
1165  break;
1166  case MaskInputData::Lower:
1167  s += str[(int)strIndex].toLower();
1168  break;
1169  default:
1170  s += str[(int)strIndex];
1171  }
1172  ++i;
1173  } else {
1174  // search for separator first
1175  int n = findInMask(i, true, true, str[(int)strIndex]);
1176  if (n != -1) {
1177  if (str.length() != 1 || i == 0 || (i > 0 && (!m_maskData[i-1].separator || m_maskData[i-1].maskChar != str[(int)strIndex]))) {
1178  s += fill.mid(i, n-i+1);
1179  i = n + 1; // update i to find + 1
1180  }
1181  } else {
1182  // search for valid m_blank if not
1183  n = findInMask(i, true, false, str[(int)strIndex]);
1184  if (n != -1) {
1185  s += fill.mid(i, n-i);
1186  switch (m_maskData[n].caseMode) {
1187  case MaskInputData::Upper:
1188  s += str[(int)strIndex].toUpper();
1189  break;
1190  case MaskInputData::Lower:
1191  s += str[(int)strIndex].toLower();
1192  break;
1193  default:
1194  s += str[(int)strIndex];
1195  }
1196  i = n + 1; // updates i to find + 1
1197  }
1198  }
1199  }
1200  ++strIndex;
1201  }
1202  } else
1203  break;
1204  }
1205 
1206  return s;
1207 }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
bool isValidInput(QChar key, QChar mask) const
The QString class provides a Unicode character string.
Definition: qstring.h:83
unsigned int uint
Definition: qglobal.h:996
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QString clearString(uint pos, uint len) const
Returns a "cleared" string with only separators and blank chars.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
MaskInputData * m_maskData
int findInMask(int pos, bool forward, bool findSeparator, QChar searchChar=QChar()) const
void clear()
Clears the line control text.

◆ maxLength()

int QLineControl::maxLength ( ) const
inline

Definition at line 236 of file qlinecontrol_p.h.

236 { return m_maxLength; }

◆ moveCursor()

void QLineControl::moveCursor ( int  pos,
bool  mark = false 
)

Moves the cursor to the given position pos.

Warning
This function is not part of the public interface.

If mark is true will adjust the currently selected text.

Definition at line 452 of file qlinecontrol.cpp.

Referenced by QLineEditPrivate::_q_completionHighlighted(), processKeyEvent(), processMouseEvent(), and selectWordAtPos().

453 {
454  if (pos != m_cursor) {
455  separate();
456  if (m_maskData)
457  pos = pos > m_cursor ? nextMaskBlank(pos) : prevMaskBlank(pos);
458  }
459  if (mark) {
460  int anchor;
462  anchor = m_selend;
463  else if (m_selend > m_selstart && m_cursor == m_selend)
464  anchor = m_selstart;
465  else
466  anchor = m_cursor;
467  m_selstart = qMin(anchor, pos);
468  m_selend = qMax(anchor, pos);
470  } else {
472  }
473  m_cursor = pos;
474  if (mark || m_selDirty) {
475  m_selDirty = false;
477  }
479 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
void emitCursorPositionChanged()
If the current cursor position differs from the last emitted cursor position, emits cursorPositionCha...
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
#define emit
Definition: qobjectdefs.h:76
int nextMaskBlank(int pos)
void internalDeselect()
int prevMaskBlank(int pos)
MaskInputData * m_maskData
void selectionChanged()
void updateDisplayText(bool forceUpdate=false)

◆ naturalTextWidth()

qreal QLineControl::naturalTextWidth ( ) const
inline

Definition at line 129 of file qlinecontrol_p.h.

129 { return m_textLayout.lineAt(0).naturalTextWidth(); }
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
qreal naturalTextWidth() const
Returns the width of the line that is occupied by text.
QTextLayout m_textLayout

◆ nextMaskBlank()

int QLineControl::nextMaskBlank ( int  pos)
inline

Definition at line 102 of file qlinecontrol_p.h.

Referenced by internalInsert(), and moveCursor().

103  {
104  int c = findInMask(pos, true, false);
105  m_separator |= (c != pos);
106  return (c != -1 ? c : m_maxLength);
107  }
unsigned char c[8]
Definition: qnumeric_p.h:62
int findInMask(int pos, bool forward, bool findSeparator, QChar searchChar=QChar()) const

◆ palette()

const QPalette& QLineControl::palette ( ) const
inline

Definition at line 320 of file qlinecontrol_p.h.

320 { return m_palette; }
QPalette m_palette

◆ parseInputMask()

void QLineControl::parseInputMask ( const QString maskFields)
private

Parses the input mask specified by maskFields to generate the mask data used to handle input masks.

Warning
This function is not part of the public interface.

Definition at line 920 of file qlinecontrol.cpp.

921 {
922  int delimiter = maskFields.indexOf(QLatin1Char(';'));
923  if (maskFields.isEmpty() || delimiter == 0) {
924  if (m_maskData) {
925  delete [] m_maskData;
926  m_maskData = 0;
927  m_maxLength = 32767;
929  }
930  return;
931  }
932 
933  if (delimiter == -1) {
934  m_blank = QLatin1Char(' ');
935  m_inputMask = maskFields;
936  } else {
937  m_inputMask = maskFields.left(delimiter);
938  m_blank = (delimiter + 1 < maskFields.length()) ? maskFields[delimiter + 1] : QLatin1Char(' ');
939  }
940 
941  // calculate m_maxLength / m_maskData length
942  m_maxLength = 0;
943  QChar c = 0;
944  for (int i=0; i<m_inputMask.length(); i++) {
945  c = m_inputMask.at(i);
946  if (i > 0 && m_inputMask.at(i-1) == QLatin1Char('\\')) {
947  m_maxLength++;
948  continue;
949  }
950  if (c != QLatin1Char('\\') && c != QLatin1Char('!') &&
951  c != QLatin1Char('<') && c != QLatin1Char('>') &&
952  c != QLatin1Char('{') && c != QLatin1Char('}') &&
953  c != QLatin1Char('[') && c != QLatin1Char(']'))
954  m_maxLength++;
955  }
956 
957  delete [] m_maskData;
958  m_maskData = new MaskInputData[m_maxLength];
959 
961  c = 0;
962  bool s;
963  bool escape = false;
964  int index = 0;
965  for (int i = 0; i < m_inputMask.length(); i++) {
966  c = m_inputMask.at(i);
967  if (escape) {
968  s = true;
972  index++;
973  escape = false;
974  } else if (c == QLatin1Char('<')) {
976  } else if (c == QLatin1Char('>')) {
978  } else if (c == QLatin1Char('!')) {
980  } else if (c != QLatin1Char('{') && c != QLatin1Char('}') && c != QLatin1Char('[') && c != QLatin1Char(']')) {
981  switch (c.unicode()) {
982  case 'A':
983  case 'a':
984  case 'N':
985  case 'n':
986  case 'X':
987  case 'x':
988  case '9':
989  case '0':
990  case 'D':
991  case 'd':
992  case '#':
993  case 'H':
994  case 'h':
995  case 'B':
996  case 'b':
997  s = false;
998  break;
999  case '\\':
1000  escape = true;
1001  default:
1002  s = true;
1003  break;
1004  }
1005 
1006  if (!escape) {
1008  m_maskData[index].separator = s;
1009  m_maskData[index].caseMode = m;
1010  index++;
1011  }
1012  }
1013  }
1015 }
unsigned char c[8]
Definition: qnumeric_p.h:62
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString m_inputMask
The QString class provides a Unicode character string.
Definition: qstring.h:83
void internalSetText(const QString &txt, int pos=-1, bool edited=true)
An internal function for setting the text of the line control.
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
Q_GUI_EXPORT QString escape(const QString &plain)
Converts the plain text string plain to a HTML string with HTML metacharacters <, >...
MaskInputData * m_maskData
quint16 index
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ passwordCharacter()

QChar QLineControl::passwordCharacter ( ) const
inline

Definition at line 288 of file qlinecontrol_p.h.

288 { return m_passwordCharacter; }
QChar m_passwordCharacter

◆ passwordEchoEditing()

bool QLineControl::passwordEchoEditing ( ) const
inline

Definition at line 280 of file qlinecontrol_p.h.

Referenced by processInputMethodEvent(), and processKeyEvent().

280  {
281 #ifdef QT_GUI_PASSWORD_ECHO_DELAY
282  if (m_passwordEchoTimer != 0)
283  return true;
284 #endif
285  return m_passwordEchoEditing ;
286  }
bool m_passwordEchoEditing

◆ paste()

void QLineControl::paste ( QClipboard::Mode  clipboardMode = QClipboard::Clipboard)

Inserts the text stored in the application clipboard into the line control.

Warning
This function is not part of the public interface.
See also
insert()

Definition at line 180 of file qlinecontrol.cpp.

Referenced by processKeyEvent().

181 {
182  QString clip = QApplication::clipboard()->text(clipboardMode);
183  if (!clip.isEmpty() || hasSelectedText()) {
184  separate(); //make it a separate undo/redo command
185  insert(clip);
186  separate();
187  }
188 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
void insert(const QString &)
Inserts the given newText at the current cursor position.
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
bool hasSelectedText() const
QString text(Mode mode=Clipboard) const
Returns the clipboard text as plain text, or an empty string if the clipboard does not contain any te...
Definition: qclipboard.cpp:357

◆ preeditAreaText()

QString QLineControl::preeditAreaText ( ) const
inline

Definition at line 277 of file qlinecontrol_p.h.

Referenced by QLineEditPrivate::_q_selectionChanged(), processInputMethodEvent(), and QLineEditPrivate::sendMouseEventToInputContext().

277 { return m_textLayout.preeditAreaText(); }
QString preeditAreaText() const
Returns the text that is inserted in the layout before editing occurs.
QTextLayout m_textLayout

◆ preeditCursor()

int QLineControl::preeditCursor ( ) const
inline

Definition at line 163 of file qlinecontrol_p.h.

163 { return m_preeditCursor; }

◆ prevMaskBlank()

int QLineControl::prevMaskBlank ( int  pos)
inline

Definition at line 109 of file qlinecontrol_p.h.

Referenced by backspace(), and moveCursor().

110  {
111  int c = findInMask(pos, false, false);
112  m_separator |= (c != pos);
113  return (c != -1 ? c : 0);
114  }
unsigned char c[8]
Definition: qnumeric_p.h:62
int findInMask(int pos, bool forward, bool findSeparator, QChar searchChar=QChar()) const

◆ processEvent()

bool QLineControl::processEvent ( QEvent ev)

Definition at line 1520 of file qlinecontrol.cpp.

1521 {
1522 #ifdef QT_KEYPAD_NAVIGATION
1523  if (QApplication::keypadNavigationEnabled()) {
1524  if ((ev->type() == QEvent::KeyPress) || (ev->type() == QEvent::KeyRelease)) {
1525  QKeyEvent *ke = (QKeyEvent *)ev;
1526  if (ke->key() == Qt::Key_Back) {
1527  if (ke->isAutoRepeat()) {
1528  // Swallow it. We don't want back keys running amok.
1529  ke->accept();
1530  return true;
1531  }
1532  if ((ev->type() == QEvent::KeyRelease)
1533  && !isReadOnly()
1534  && m_deleteAllTimer) {
1536  m_deleteAllTimer = 0;
1537  backspace();
1538  ke->accept();
1539  return true;
1540  }
1541  }
1542  }
1543  }
1544 #endif
1545  switch(ev->type()){
1546 #ifndef QT_NO_GRAPHICSVIEW
1551  QGraphicsSceneMouseEvent *gvEv = static_cast<QGraphicsSceneMouseEvent*>(ev);
1552  QMouseEvent mouse(ev->type(),
1553  gvEv->pos().toPoint(), gvEv->button(), gvEv->buttons(), gvEv->modifiers());
1554  processMouseEvent(&mouse); break;
1555  }
1556 #endif
1560  case QEvent::MouseMove:
1561  processMouseEvent(static_cast<QMouseEvent*>(ev)); break;
1562  case QEvent::KeyPress:
1563  case QEvent::KeyRelease:
1564  processKeyEvent(static_cast<QKeyEvent*>(ev)); break;
1565  case QEvent::InputMethod:
1566  processInputMethodEvent(static_cast<QInputMethodEvent*>(ev)); break;
1567 #ifndef QT_NO_SHORTCUT
1569  if (isReadOnly())
1570  return false;
1571  QKeyEvent* ke = static_cast<QKeyEvent*>(ev);
1572  if (ke == QKeySequence::Copy
1573  || ke == QKeySequence::Paste
1574  || ke == QKeySequence::Cut
1575  || ke == QKeySequence::Redo
1576  || ke == QKeySequence::Undo
1588  || ke == QKeySequence::SelectAll
1590  ke->accept();
1591  } else if (ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::ShiftModifier
1592  || ke->modifiers() == Qt::KeypadModifier) {
1593  if (ke->key() < Qt::Key_Escape) {
1594  ke->accept();
1595  } else {
1596  switch (ke->key()) {
1597  case Qt::Key_Delete:
1598  case Qt::Key_Home:
1599  case Qt::Key_End:
1600  case Qt::Key_Backspace:
1601  case Qt::Key_Left:
1602  case Qt::Key_Right:
1603  ke->accept();
1604  default:
1605  break;
1606  }
1607  }
1608  }
1609  }
1610 #endif
1611  default:
1612  return false;
1613  }
1614  return true;
1615 }
The QKeyEvent class describes a key event.
Definition: qevent.h:224
void processMouseEvent(QMouseEvent *ev)
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
Qt::MouseButton button() const
Returns the mouse button (if any) that caused the event.
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 processInputMethodEvent(QInputMethodEvent *event)
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
void backspace()
Handles the behavior for the backspace key or function.
bool isReadOnly() const
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
bool isAutoRepeat() const
Returns true if this event comes from an auto-repeating key; returns false if it comes from an initia...
Definition: qevent.h:237
QPointF pos() const
Returns the mouse cursor position in item coordinates.
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifiers in use at the time the event was sent.
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650
void processKeyEvent(QKeyEvent *ev)

◆ processInputMethodEvent()

void QLineControl::processInputMethodEvent ( QInputMethodEvent event)
Warning
This function is not part of the public interface.

Applies the given input method event event to the text of the line control

Definition at line 487 of file qlinecontrol.cpp.

Referenced by processEvent().

488 {
489  int priorState = 0;
490  int originalSelectionStart = m_selstart;
491  int originalSelectionEnd = m_selend;
492  bool isGettingInput = !event->commitString().isEmpty()
493  || event->preeditString() != preeditAreaText()
494  || event->replacementLength() > 0;
495  bool cursorPositionChanged = false;
496  bool selectionChange = false;
497 
498  if (isGettingInput) {
499  // If any text is being input, remove selected text.
500  priorState = m_undoState;
503  m_selstart = 0;
504  m_selend = m_text.length();
505  }
507  }
508 
509  int c = m_cursor; // cursor position after insertion of commit string
510  if (event->replacementStart() <= 0)
511  c += event->commitString().length() - qMin(-event->replacementStart(), event->replacementLength());
512 
513  m_cursor += event->replacementStart();
514  if (m_cursor < 0)
515  m_cursor = 0;
516 
517  // insert commit string
518  if (event->replacementLength()) {
520  m_selend = m_selstart + event->replacementLength();
522  }
523  if (!event->commitString().isEmpty()) {
524  internalInsert(event->commitString());
525  cursorPositionChanged = true;
526  }
527 
528  m_cursor = qBound(0, c, m_text.length());
529 
530  for (int i = 0; i < event->attributes().size(); ++i) {
531  const QInputMethodEvent::Attribute &a = event->attributes().at(i);
533  m_cursor = qBound(0, a.start + a.length, m_text.length());
534  if (a.length) {
535  m_selstart = qMax(0, qMin(a.start, m_text.length()));
536  m_selend = m_cursor;
537  if (m_selend < m_selstart) {
539  }
540  selectionChange = true;
541  } else {
542  m_selstart = m_selend = 0;
543  }
544  cursorPositionChanged = true;
545  }
546  }
547 #ifndef QT_NO_IM
548  setPreeditArea(m_cursor, event->preeditString());
549 #endif //QT_NO_IM
550  const int oldPreeditCursor = m_preeditCursor;
551  m_preeditCursor = event->preeditString().length();
552  m_hideCursor = false;
554  for (int i = 0; i < event->attributes().size(); ++i) {
555  const QInputMethodEvent::Attribute &a = event->attributes().at(i);
556  if (a.type == QInputMethodEvent::Cursor) {
558  m_hideCursor = !a.length;
559  } else if (a.type == QInputMethodEvent::TextFormat) {
560  QTextCharFormat f = qvariant_cast<QTextFormat>(a.value).toCharFormat();
561  if (f.isValid()) {
562  if (f.background().color().alphaF() == 1 && f.background().style() == Qt::SolidPattern) {
563  f.setForeground(f.background().color());
566  f.setFontUnderline(true);
567  }
569  o.start = a.start + m_cursor;
570  o.length = a.length;
571  o.format = f;
572  formats.append(o);
573  }
574  }
575  }
577  updateDisplayText(/*force*/ true);
578  if (originalSelectionStart != m_selstart || originalSelectionEnd != m_selend)
580  if (cursorPositionChanged)
582  else if (m_preeditCursor != oldPreeditCursor)
584  if (isGettingInput)
585  finishChange(priorState);
586  if (selectionChange)
588 }
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
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
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
void cursorPositionChanged(int, int)
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
long ASN1_INTEGER_get ASN1_INTEGER * a
void removeSelectedText()
Also adds the appropriate commands into the undo history.
void emitCursorPositionChanged()
If the current cursor position differs from the last emitted cursor position, emits cursorPositionCha...
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
void setPreeditArea(int cursor, const QString &text)
QString preeditAreaText() const
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
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
uint echoMode() const
bool passwordEchoEditing() const
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
#define emit
Definition: qobjectdefs.h:76
void updateMicroFocus()
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 qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
bool finishChange(int validateFromState=-1, bool update=false, bool edited=true)
Completes a change to the line control text.
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
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
void selectionChanged()
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
void updateDisplayText(bool forceUpdate=false)
int length
Specifies the numer of characters the format range spans.
Definition: qtextlayout.h:130
void updatePasswordEchoEditing(bool editing)
Sets the password echo editing to editing.
QTextCharFormat format
Specifies the format to apply.
Definition: qtextlayout.h:131
QTextLayout m_textLayout
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
Definition: qtextformat.h:350
int replacementLength() const
Returns the number of characters to be replaced in the preedit string.
Definition: qevent.h:459
void internalInsert(const QString &s)
Inserts the given string s into the line control.
void setUnderlineStyle(UnderlineStyle style)
Sets the style of underlining the text to style.

◆ processKeyEvent()

void QLineControl::processKeyEvent ( QKeyEvent ev)

Definition at line 1671 of file qlinecontrol.cpp.

Referenced by processEvent().

1672 {
1673  bool inlineCompletionAccepted = false;
1674 
1675 #ifndef QT_NO_COMPLETER
1676  if (m_completer) {
1678  if ((completionMode == QCompleter::PopupCompletion
1679  || completionMode == QCompleter::UnfilteredPopupCompletion)
1680  && m_completer->popup()
1681  && m_completer->popup()->isVisible()) {
1682  // The following keys are forwarded by the completer to the widget
1683  // Ignoring the events lets the completer provide suitable default behavior
1684  switch (event->key()) {
1685  case Qt::Key_Escape:
1686  event->ignore();
1687  return;
1688  case Qt::Key_Enter:
1689  case Qt::Key_Return:
1690  case Qt::Key_F4:
1691 #ifdef QT_KEYPAD_NAVIGATION
1692  case Qt::Key_Select:
1693  if (!QApplication::keypadNavigationEnabled())
1694  break;
1695 #endif
1696  m_completer->popup()->hide(); // just hide. will end up propagating to parent
1697  default:
1698  break; // normal key processing
1699  }
1700  } else if (completionMode == QCompleter::InlineCompletion) {
1701  switch (event->key()) {
1702  case Qt::Key_Enter:
1703  case Qt::Key_Return:
1704  case Qt::Key_F4:
1705 #ifdef QT_KEYPAD_NAVIGATION
1706  case Qt::Key_Select:
1707  if (!QApplication::keypadNavigationEnabled())
1708  break;
1709 #endif
1711  && textAfterSelection().isEmpty()) {
1713  inlineCompletionAccepted = true;
1714  }
1715  default:
1716  break; // normal key processing
1717  }
1718  }
1719  }
1720 #endif // QT_NO_COMPLETER
1721 
1722  if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
1723  if (hasAcceptableInput() || fixup()) {
1724  emit accepted();
1726  }
1727  if (inlineCompletionAccepted)
1728  event->accept();
1729  else
1730  event->ignore();
1731  return;
1732  }
1733 
1735  && !passwordEchoEditing()
1736  && !isReadOnly()
1737  && !event->text().isEmpty()
1738 #ifdef QT_KEYPAD_NAVIGATION
1739  && event->key() != Qt::Key_Select
1740  && event->key() != Qt::Key_Up
1741  && event->key() != Qt::Key_Down
1742  && event->key() != Qt::Key_Back
1743 #endif
1744  && !(event->modifiers() & Qt::ControlModifier)) {
1745  // Clear the edit and reset to normal echo mode while editing; the
1746  // echo mode switches back when the edit loses focus
1747  // ### resets current content. dubious code; you can
1748  // navigate with keys up, down, back, and select(?), but if you press
1749  // "left" or "right" it clears?
1751  clear();
1752  }
1753 
1754  bool unknown = false;
1755  bool visual = cursorMoveStyle() == Qt::VisualMoveStyle;
1756 
1757  if (false) {
1758  }
1759 #ifndef QT_NO_SHORTCUT
1760  else if (event == QKeySequence::Undo) {
1761  if (!isReadOnly())
1762  undo();
1763  }
1764  else if (event == QKeySequence::Redo) {
1765  if (!isReadOnly())
1766  redo();
1767  }
1768  else if (event == QKeySequence::SelectAll) {
1769  selectAll();
1770  }
1771 #ifndef QT_NO_CLIPBOARD
1772  else if (event == QKeySequence::Copy) {
1773  copy();
1774  }
1775  else if (event == QKeySequence::Paste) {
1776  if (!isReadOnly()) {
1778 #ifdef Q_WS_X11
1779  if (event->modifiers() == (Qt::CTRL | Qt::SHIFT) && event->key() == Qt::Key_Insert)
1780  mode = QClipboard::Selection;
1781 #endif
1782  paste(mode);
1783  }
1784  }
1785  else if (event == QKeySequence::Cut) {
1786  if (!isReadOnly()) {
1787  copy();
1788  del();
1789  }
1790  }
1791  else if (event == QKeySequence::DeleteEndOfLine) {
1792  if (!isReadOnly()) {
1793  setSelection(cursor(), end());
1794  copy();
1795  del();
1796  }
1797  }
1798 #endif //QT_NO_CLIPBOARD
1800  home(0);
1801  }
1803  end(0);
1804  }
1806  home(1);
1807  }
1809  end(1);
1810  }
1811  else if (event == QKeySequence::MoveToNextChar) {
1812 #if !defined(Q_WS_WIN) || defined(QT_NO_COMPLETER)
1813  if (hasSelectedText()) {
1814 #else
1815  if (hasSelectedText() && m_completer
1817 #endif
1818  moveCursor(selectionEnd(), false);
1819  } else {
1820  cursorForward(0, visual ? 1 : (layoutDirection() == Qt::LeftToRight ? 1 : -1));
1821  }
1822  }
1823  else if (event == QKeySequence::SelectNextChar) {
1824  cursorForward(1, visual ? 1 : (layoutDirection() == Qt::LeftToRight ? 1 : -1));
1825  }
1827 #if !defined(Q_WS_WIN) || defined(QT_NO_COMPLETER)
1828  if (hasSelectedText()) {
1829 #else
1830  if (hasSelectedText() && m_completer
1832 #endif
1833  moveCursor(selectionStart(), false);
1834  } else {
1835  cursorForward(0, visual ? -1 : (layoutDirection() == Qt::LeftToRight ? -1 : 1));
1836  }
1837  }
1839  cursorForward(1, visual ? -1 : (layoutDirection() == Qt::LeftToRight ? -1 : 1));
1840  }
1841  else if (event == QKeySequence::MoveToNextWord) {
1842  if (echoMode() == QLineEdit::Normal)
1844  else
1845  layoutDirection() == Qt::LeftToRight ? end(0) : home(0);
1846  }
1848  if (echoMode() == QLineEdit::Normal)
1849  layoutDirection() == Qt::LeftToRight ? cursorWordBackward(0) : cursorWordForward(0);
1850  else if (!isReadOnly()) {
1851  layoutDirection() == Qt::LeftToRight ? home(0) : end(0);
1852  }
1853  }
1854  else if (event == QKeySequence::SelectNextWord) {
1855  if (echoMode() == QLineEdit::Normal)
1856  layoutDirection() == Qt::LeftToRight ? cursorWordForward(1) : cursorWordBackward(1);
1857  else
1858  layoutDirection() == Qt::LeftToRight ? end(1) : home(1);
1859  }
1861  if (echoMode() == QLineEdit::Normal)
1862  layoutDirection() == Qt::LeftToRight ? cursorWordBackward(1) : cursorWordForward(1);
1863  else
1864  layoutDirection() == Qt::LeftToRight ? home(1) : end(1);
1865  }
1866  else if (event == QKeySequence::Delete) {
1867  if (!isReadOnly())
1868  del();
1869  }
1870  else if (event == QKeySequence::DeleteEndOfWord) {
1871  if (!isReadOnly()) {
1872  cursorWordForward(true);
1873  del();
1874  }
1875  }
1876  else if (event == QKeySequence::DeleteStartOfWord) {
1877  if (!isReadOnly()) {
1878  cursorWordBackward(true);
1879  del();
1880  }
1881  }
1882 #endif // QT_NO_SHORTCUT
1883  else {
1884  bool handled = false;
1885 #ifdef Q_WS_MAC
1886  if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down) {
1887  Qt::KeyboardModifiers myModifiers = (event->modifiers() & ~Qt::KeypadModifier);
1888  if (myModifiers & Qt::ShiftModifier) {
1889  if (myModifiers == (Qt::ControlModifier|Qt::ShiftModifier)
1890  || myModifiers == (Qt::AltModifier|Qt::ShiftModifier)
1891  || myModifiers == Qt::ShiftModifier) {
1892 
1893  event->key() == Qt::Key_Up ? home(1) : end(1);
1894  }
1895  } else {
1896  if ((myModifiers == Qt::ControlModifier
1897  || myModifiers == Qt::AltModifier
1898  || myModifiers == Qt::NoModifier)) {
1899  event->key() == Qt::Key_Up ? home(0) : end(0);
1900  }
1901  }
1902  handled = true;
1903  }
1904 #endif
1905  if (event->modifiers() & Qt::ControlModifier) {
1906  switch (event->key()) {
1907  case Qt::Key_Backspace:
1908  if (!isReadOnly()) {
1909  cursorWordBackward(true);
1910  del();
1911  }
1912  break;
1913 #ifndef QT_NO_COMPLETER
1914  case Qt::Key_Up:
1915  case Qt::Key_Down:
1916  complete(event->key());
1917  break;
1918 #endif
1919 #if defined(Q_WS_X11)
1920  case Qt::Key_E:
1921  end(0);
1922  break;
1923 
1924  case Qt::Key_U:
1925  if (!isReadOnly()) {
1926  setSelection(0, text().size());
1927 #ifndef QT_NO_CLIPBOARD
1928  copy();
1929 #endif
1930  del();
1931  }
1932  break;
1933 #endif
1934  default:
1935  if (!handled)
1936  unknown = true;
1937  }
1938  } else { // ### check for *no* modifier
1939  switch (event->key()) {
1940  case Qt::Key_Backspace:
1941  if (!isReadOnly()) {
1942  backspace();
1943 #ifndef QT_NO_COMPLETER
1945 #endif
1946  }
1947  break;
1948 #ifdef QT_KEYPAD_NAVIGATION
1949  case Qt::Key_Back:
1950  if (QApplication::keypadNavigationEnabled() && !event->isAutoRepeat()
1951  && !isReadOnly()) {
1952  if (text().length() == 0) {
1954 
1955  if (passwordEchoEditing())
1957 
1958  emit editFocusChange(false);
1959  } else if (!m_deleteAllTimer) {
1961  }
1962  } else {
1963  unknown = true;
1964  }
1965  break;
1966 #endif
1967  default:
1968  if (!handled)
1969  unknown = true;
1970  }
1971  }
1972  }
1973 
1974  if (event->key() == Qt::Key_Direction_L || event->key() == Qt::Key_Direction_R) {
1976  unknown = false;
1977  }
1978 
1979  if (unknown && !isReadOnly()) {
1980  QString t = event->text();
1981  if (!t.isEmpty() && t.at(0).isPrint()) {
1982  insert(t);
1983 #ifndef QT_NO_COMPLETER
1984  complete(event->key());
1985 #endif
1986  event->accept();
1987  return;
1988  }
1989  }
1990 
1991  if (unknown)
1992  event->ignore();
1993  else
1994  event->accept();
1995 }
Mode
This enum type is used to control which part of the system clipboard is used by QClipboard::mimeData(...
Definition: qclipboard.h:71
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
CompletionMode
This enum specifies how completions are provided to the user.
Definition: qcompleter.h:77
Qt::CursorMoveStyle cursorMoveStyle() const
int selectionStart() const
int cursor() const
QString textAfterSelection() const
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
void cursorWordForward(bool mark)
QString currentCompletion() const
Returns the current completion string.
void home(bool mark)
bool isVisible() const
Definition: qwidget.h:1005
void setText(const QString &txt)
QString text() const
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void accepted()
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString m_cancelText
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
bool isPrint() const
Returns true if the character is a printable character; otherwise returns false.
Definition: qchar.cpp:598
CompletionMode completionMode
how the completions are provided to the user
Definition: qcompleter.h:69
void insert(const QString &)
Inserts the given newText at the current cursor position.
uint echoMode() const
bool hasAcceptableInput() const
void editingFinished()
bool passwordEchoEditing() const
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define emit
Definition: qobjectdefs.h:76
void setSelection(int start, int length)
Sets length characters from the given start position as selected.
bool fixup()
Fixes the current text so that it is valid given any set validators.
QPointer< QCompleter > m_completer
void hide()
Hides the widget.
Definition: qwidget.h:501
void backspace()
Handles the behavior for the backspace key or function.
void cursorWordBackward(bool mark)
bool isReadOnly() const
void moveCursor(int pos, bool mark=false)
Moves the cursor to the given position pos.
void copy(QClipboard::Mode mode=QClipboard::Clipboard) const
Copies the currently selected text into the clipboard using the given mode.
Qt::LayoutDirection layoutDirection() const
Definition: qnamespace.h:54
void cursorForward(bool mark, int steps)
void setLayoutDirection(Qt::LayoutDirection direction)
void updatePasswordEchoEditing(bool editing)
Sets the password echo editing to editing.
bool hasSelectedText() const
void del()
Handles the behavior for the delete key or function.
void complete(int key)
int selectionEnd() const
int end() const
void paste(QClipboard::Mode mode=QClipboard::Clipboard)
Inserts the text stored in the application clipboard into the line control.
QAbstractItemView * popup() const
Returns the popup used to display completions.
void clear()
Clears the line control text.

◆ processMouseEvent()

void QLineControl::processMouseEvent ( QMouseEvent ev)

Definition at line 1617 of file qlinecontrol.cpp.

Referenced by processEvent().

1618 {
1619 
1620  switch (ev->type()) {
1623  if (m_tripleClickTimer
1624  && (ev->pos() - m_tripleClick).manhattanLength()
1626  selectAll();
1627  return;
1628  }
1629  if (ev->button() == Qt::RightButton)
1630  return;
1631 
1632  bool mark = ev->modifiers() & Qt::ShiftModifier;
1633  int cursor = xToPos(ev->pos().x());
1634  moveCursor(cursor, mark);
1635  break;
1636  }
1639  if (ev->button() == Qt::LeftButton) {
1640  selectWordAtPos(xToPos(ev->pos().x()));
1641  if (m_tripleClickTimer)
1644  m_tripleClick = ev->pos();
1645  }
1646  break;
1649 #ifndef QT_NO_CLIPBOARD
1650  if (QApplication::clipboard()->supportsSelection()) {
1651  if (ev->button() == Qt::LeftButton) {
1653  } else if (!isReadOnly() && ev->button() == Qt::MidButton) {
1654  deselect();
1656  }
1657  }
1658 #endif
1659  break;
1661  case QEvent::MouseMove:
1662  if (ev->buttons() & Qt::LeftButton) {
1663  moveCursor(xToPos(ev->pos().x()), true);
1664  }
1665  break;
1666  default:
1667  break;
1668  }
1669 }
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
int cursor() const
QString text() const
QPoint m_tripleClick
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
void insert(const QString &)
Inserts the given newText at the current cursor position.
static QClipboard * clipboard()
Returns a pointer to the application global clipboard.
int xToPos(int x, QTextLine::CursorPosition=QTextLine::CursorBetweenCharacters) const
Returns the cursor position of the given x pixel value in relation to the displayed text...
static int startDragDistance()
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
bool isReadOnly() const
void moveCursor(int pos, bool mark=false)
Moves the cursor to the given position pos.
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
void copy(QClipboard::Mode mode=QClipboard::Clipboard) const
Copies the currently selected text into the clipboard using the given mode.
void selectWordAtPos(int)
Sets the selection to cover the word at the given cursor position.
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition: qevent.h:79
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
static int doubleClickInterval()
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650

◆ redo()

void QLineControl::redo ( )
inline

Definition at line 224 of file qlinecontrol_p.h.

Referenced by processKeyEvent().

224 { internalRedo(); finishChange(); }
bool finishChange(int validateFromState=-1, bool update=false, bool edited=true)
Completes a change to the line control text.

◆ removeSelectedText()

void QLineControl::removeSelectedText ( )
private

Also adds the appropriate commands into the undo history.

Warning
This function is not part of the public interface.

removes the currently selected text from the line control.

This function does not call finishChange(), and may leave the text in an invalid state.

Definition at line 879 of file qlinecontrol.cpp.

Referenced by _q_deleteSelected(), backspace(), clear(), del(), insert(), and processInputMethodEvent().

880 {
881  if (m_selstart < m_selend && m_selend <= (int) m_text.length()) {
883  separate();
884  int i ;
886  if (m_selstart <= m_cursor && m_cursor < m_selend) {
887  // cursor is within the selection. Split up the commands
888  // to be able to restore the correct cursor position
889  for (i = m_cursor; i >= m_selstart; --i)
890  addCommand (Command(DeleteSelection, i, m_text.at(i), -1, 1));
891  for (i = m_selend - 1; i > m_cursor; --i)
892  addCommand (Command(DeleteSelection, i - m_cursor + m_selstart - 1, m_text.at(i), -1, -1));
893  } else {
894  for (i = m_selend-1; i >= m_selstart; --i)
895  addCommand (Command(RemoveSelection, i, m_text.at(i), -1, -1));
896  }
897  if (m_maskData) {
899  for (int i = 0; i < m_selend - m_selstart; ++i)
900  addCommand(Command(Insert, m_selstart + i, m_text.at(m_selstart + i), -1, -1));
901  } else {
902  m_text.remove(m_selstart, m_selend - m_selstart);
903  }
904  if (m_cursor > m_selstart)
905  m_cursor -= qMin(m_cursor, m_selend) - m_selstart;
907  m_textDirty = true;
908  }
909 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
void cancelPasswordEchoTimer()
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void addCommand(const Command &cmd)
Adds the given command to the undo history of the line control.
QString clearString(uint pos, uint len) const
Returns a "cleared" string with only separators and blank chars.
void internalDeselect()
MaskInputData * m_maskData
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867

◆ removeSelection()

void QLineControl::removeSelection ( )
inline

Definition at line 147 of file qlinecontrol_p.h.

Referenced by QLineEditPrivate::drag().

148  {
149  int priorState = m_undoState;
151  finishChange(priorState);
152  }
void removeSelectedText()
Also adds the appropriate commands into the undo history.
bool finishChange(int validateFromState=-1, bool update=false, bool edited=true)
Completes a change to the line control text.

◆ resetCursorBlinkTimer()

void QLineControl::resetCursorBlinkTimer ( )

Definition at line 1490 of file qlinecontrol.cpp.

1491 {
1492  if (m_blinkPeriod == 0 || m_blinkTimer == 0)
1493  return;
1496  m_blinkStatus = 1;
1497 }
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650

◆ resetInputContext

void QLineControl::resetInputContext ( )
signal

◆ selectAll()

void QLineControl::selectAll ( )
inline

Definition at line 219 of file qlinecontrol_p.h.

Referenced by processKeyEvent(), and processMouseEvent().

219 { m_selstart = m_selend = m_cursor = 0; moveCursor(m_text.length(), true); }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void moveCursor(int pos, bool mark=false)
Moves the cursor to the given position pos.

◆ selectedText()

QString QLineControl::selectedText ( ) const
inline

Definition at line 133 of file qlinecontrol_p.h.

Referenced by copy(), and QLineEditPrivate::drag().

The QString class provides a Unicode character string.
Definition: qstring.h:83
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
bool hasSelectedText() const

◆ selectionChanged

void QLineControl::selectionChanged ( )
signal

◆ selectionEnd()

int QLineControl::selectionEnd ( ) const
inline

Definition at line 138 of file qlinecontrol_p.h.

Referenced by processKeyEvent().

138 { return hasSelectedText() ? m_selend : -1; }
bool hasSelectedText() const

◆ selectionStart()

int QLineControl::selectionStart ( ) const
inline

Definition at line 137 of file qlinecontrol_p.h.

Referenced by processKeyEvent().

137 { return hasSelectedText() ? m_selstart : -1; }
bool hasSelectedText() const

◆ selectWordAtPos()

void QLineControl::selectWordAtPos ( int  cursor)

Sets the selection to cover the word at the given cursor position.

Warning
This function is not part of the public interface.

The word boundaries are defined by the behavior of QTextLayout::SkipWords cursor mode.

Definition at line 652 of file qlinecontrol.cpp.

Referenced by processMouseEvent().

653 {
654  int next = cursor + 1;
655  if(next > end())
656  --next;
658  moveCursor(c, false);
659  // ## text layout should support end of words.
661  while (end > cursor && m_text[end-1].isSpace())
662  --end;
663  moveCursor(end, true);
664 }
int cursor() const
unsigned char c[8]
Definition: qnumeric_p.h:62
int nextCursorPosition(int oldPos, CursorMode mode=SkipCharacters) const
Returns the next valid cursor position after oldPos that respects the given cursor mode...
void moveCursor(int pos, bool mark=false)
Moves the cursor to the given position pos.
QTextLayout m_textLayout
int previousCursorPosition(int oldPos, CursorMode mode=SkipCharacters) const
Returns the first valid cursor position before oldPos that respects the given cursor mode...
int end() const

◆ separate()

void QLineControl::separate ( )
inlineprivate

Definition at line 414 of file qlinecontrol_p.h.

Referenced by _q_deleteSelected(), clear(), moveCursor(), paste(), and removeSelectedText().

414 { m_separator = true; }

◆ setCancelText()

void QLineControl::setCancelText ( const QString text)
inline

Definition at line 318 of file qlinecontrol_p.h.

318 { m_cancelText = text; }
QString text() const
QString m_cancelText

◆ setCompleter()

void QLineControl::setCompleter ( const QCompleter c)
inline

Definition at line 253 of file qlinecontrol_p.h.

253 { m_completer = const_cast<QCompleter*>(c); }
unsigned char c[8]
Definition: qnumeric_p.h:62
The QCompleter class provides completions based on an item model.
Definition: qcompleter.h:64
QPointer< QCompleter > m_completer

◆ setCursorBlinkPeriod()

void QLineControl::setCursorBlinkPeriod ( int  msec)

Definition at line 1472 of file qlinecontrol.cpp.

1473 {
1474  if (msec == m_blinkPeriod)
1475  return;
1476  if (m_blinkTimer) {
1478  }
1479  if (msec) {
1480  m_blinkTimer = startTimer(msec / 2);
1481  m_blinkStatus = 1;
1482  } else {
1483  m_blinkTimer = 0;
1484  if (m_blinkStatus == 1)
1486  }
1487  m_blinkPeriod = msec;
1488 }
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
static bool isEmpty(const char *str)
#define emit
Definition: qobjectdefs.h:76
QRect cursorRect() const
Returns the bounds of the current cursor, as defined as a between characters cursor.
QString inputMask() const
void updateNeeded(const QRect &)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650

◆ setCursorMoveStyle()

void QLineControl::setCursorMoveStyle ( Qt::CursorMoveStyle  style)
inline

Definition at line 169 of file qlinecontrol_p.h.

void setCursorMoveStyle(Qt::CursorMoveStyle style)
Set the cursor movement style.
QTextLayout m_textLayout

◆ setCursorPosition()

void QLineControl::setCursorPosition ( int  pos)
inline

Definition at line 258 of file qlinecontrol_p.h.

258 { if (pos <= m_text.length()) moveCursor(qMax(0, pos)); }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void moveCursor(int pos, bool mark=false)
Moves the cursor to the given position pos.

◆ setCursorWidth()

void QLineControl::setCursorWidth ( int  value)
inline

Definition at line 166 of file qlinecontrol_p.h.

166 { m_cursorWidth = value; }

◆ setEchoMode()

void QLineControl::setEchoMode ( uint  mode)
inline

Definition at line 228 of file qlinecontrol_p.h.

229  {
231  m_echoMode = mode;
232  m_passwordEchoEditing = false;
234  }
void cancelPasswordEchoTimer()
void updateDisplayText(bool forceUpdate=false)
bool m_passwordEchoEditing

◆ setFont()

void QLineControl::setFont ( const QFont font)
inline

Definition at line 307 of file qlinecontrol_p.h.

Referenced by QLineEditPrivate::init().

void setFont(const QFont &f)
Sets the layout&#39;s font to the given font.
void updateDisplayText(bool forceUpdate=false)
QTextLayout m_textLayout

◆ setInputMask()

void QLineControl::setInputMask ( const QString mask)
inline

Definition at line 264 of file qlinecontrol_p.h.

265  {
266  parseInputMask(mask);
267  if (m_maskData)
269  }
int nextMaskBlank(int pos)
void moveCursor(int pos, bool mark=false)
Moves the cursor to the given position pos.
MaskInputData * m_maskData
void parseInputMask(const QString &maskFields)
Parses the input mask specified by maskFields to generate the mask data used to handle input masks...

◆ setLayoutDirection()

void QLineControl::setLayoutDirection ( Qt::LayoutDirection  direction)
inline

Definition at line 299 of file qlinecontrol_p.h.

Referenced by processKeyEvent().

300  {
301  if (direction != m_layoutDirection) {
304  }
305  }
Qt::LayoutDirection m_layoutDirection
void updateDisplayText(bool forceUpdate=false)
Qt::LayoutDirection direction

◆ setMaxLength()

void QLineControl::setMaxLength ( int  maxLength)
inline

Definition at line 237 of file qlinecontrol_p.h.

238  {
239  if (m_maskData)
240  return;
242  setText(m_text);
243  }
void setText(const QString &txt)
MaskInputData * m_maskData
int maxLength() const

◆ setModified()

void QLineControl::setModified ( bool  modified)
inline

Definition at line 121 of file qlinecontrol_p.h.

121 { m_modifiedState = modified ? -1 : m_undoState; }

◆ setPalette()

void QLineControl::setPalette ( const QPalette p)
inline

Definition at line 321 of file qlinecontrol_p.h.

321 { m_palette = p; }
QPalette m_palette

◆ setPasswordCharacter()

void QLineControl::setPasswordCharacter ( const QChar character)
inline

Definition at line 289 of file qlinecontrol_p.h.

Referenced by QLineEditPrivate::init().

289 { m_passwordCharacter = character; updateDisplayText(); }
QChar m_passwordCharacter
void updateDisplayText(bool forceUpdate=false)

◆ setPreeditArea()

void QLineControl::setPreeditArea ( int  cursor,
const QString text 
)
inline

Definition at line 274 of file qlinecontrol_p.h.

Referenced by processInputMethodEvent().

int cursor() const
QTextLayout m_textLayout
void setPreeditArea(int position, const QString &text)
Sets the position and text of the area in the layout that is processed before editing occurs...

◆ setReadOnly()

void QLineControl::setReadOnly ( bool  enable)
inline

Definition at line 206 of file qlinecontrol_p.h.

206 { m_readOnly = enable; }

◆ setSelection()

void QLineControl::setSelection ( int  start,
int  length 
)

Sets length characters from the given start position as selected.

Warning
This function is not part of the public interface.

The given start position must be within the current text for the line control. If length characters cannot be selected, then the selection will extend to the end of the current text.

Definition at line 298 of file qlinecontrol.cpp.

Referenced by processKeyEvent().

299 {
300  if(start < 0 || start > (int)m_text.length()){
301  qWarning("QLineControl::setSelection: Invalid start position");
302  return;
303  }
304 
305  if (length > 0) {
306  if (start == m_selstart && start + length == m_selend && m_cursor == m_selend)
307  return;
308  m_selstart = start;
309  m_selend = qMin(start + length, (int)m_text.length());
310  m_cursor = m_selend;
311  } else if (length < 0){
312  if (start == m_selend && start + length == m_selstart && m_cursor == m_selstart)
313  return;
314  m_selstart = qMax(start + length, 0);
315  m_selend = start;
317  } else if (m_selstart != m_selend) {
318  m_selstart = 0;
319  m_selend = 0;
320  m_cursor = start;
321  } else {
322  m_cursor = start;
324  return;
325  }
328 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void emitCursorPositionChanged()
If the current cursor position differs from the last emitted cursor position, emits cursorPositionCha...
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int start() const
#define emit
Definition: qobjectdefs.h:76
Q_CORE_EXPORT void qWarning(const char *,...)
void selectionChanged()

◆ setText()

void QLineControl::setText ( const QString txt)
inline

Definition at line 213 of file qlinecontrol_p.h.

Referenced by processKeyEvent().

213 { internalSetText(txt, -1, false); }
void internalSetText(const QString &txt, int pos=-1, bool edited=true)
An internal function for setting the text of the line control.

◆ setValidator()

void QLineControl::setValidator ( const QValidator v)
inline

Definition at line 247 of file qlinecontrol_p.h.

247 { m_validator = const_cast<QValidator*>(v); }
The QValidator class provides validation of input text.
Definition: qvalidator.h:60
QPointer< QValidator > m_validator

◆ start()

int QLineControl::start ( ) const
inline

Definition at line 154 of file qlinecontrol_p.h.

Referenced by advanceToEnabledItem(), and setSelection().

154 { return 0; }

◆ stripString()

QString QLineControl::stripString ( const QString str) const
private

Strips blank parts of the input in a QLineControl when an inputMask is set, separators are still included.

Warning
This function is not part of the public interface.

Typically "127.0__.0__.1__" becomes "127.0.0.1".

Definition at line 1245 of file qlinecontrol.cpp.

1246 {
1247  if (!m_maskData)
1248  return str;
1249 
1250  QString s;
1251  int end = qMin(m_maxLength, (int)str.length());
1252  for (int i = 0; i < end; ++i)
1253  if (m_maskData[i].separator)
1254  s += m_maskData[i].maskChar;
1255  else
1256  if (str[i] != m_blank)
1257  s += str[i];
1258 
1259  return s;
1260 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
MaskInputData * m_maskData
int end() const

◆ text()

QString QLineControl::text ( ) const
inline

Definition at line 208 of file qlinecontrol_p.h.

Referenced by QLineEditPrivate::_q_completionHighlighted(), complete(), finishChange(), processKeyEvent(), and processMouseEvent().

209  {
211  return (res.isNull() ? QString::fromLatin1("") : res);
212  }
QString stripString(const QString &str) const
Strips blank parts of the input in a QLineControl when an inputMask is set, separators are still incl...
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
MaskInputData * m_maskData

◆ textAfterSelection()

QString QLineControl::textAfterSelection ( ) const
inline

Definition at line 135 of file qlinecontrol_p.h.

Referenced by complete(), and processKeyEvent().

135 { return hasSelectedText() ? m_text.mid(m_selend) : QString(); }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
bool hasSelectedText() const

◆ textBeforeSelection()

QString QLineControl::textBeforeSelection ( ) const
inline

Definition at line 134 of file qlinecontrol_p.h.

Referenced by complete().

134 { return hasSelectedText() ? m_text.left(m_selstart) : QString(); }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
bool hasSelectedText() const

◆ textChanged

void QLineControl::textChanged ( const QString )
signal

Referenced by finishChange().

◆ textEdited

void QLineControl::textEdited ( const QString )
signal

Referenced by finishChange().

◆ timerEvent()

void QLineControl::timerEvent ( QTimerEvent event)
protectedvirtual

This event handler can be reimplemented in a subclass to receive timer events for the object.

QTimer provides a higher-level interface to the timer functionality, and also more general information about timers. The timer event is passed in the event parameter.

See also
startTimer(), killTimer(), event()

Reimplemented from QObject.

Definition at line 1499 of file qlinecontrol.cpp.

1500 {
1501  if (event->timerId() == m_blinkTimer) {
1504  } else if (event->timerId() == m_deleteAllTimer) {
1506  m_deleteAllTimer = 0;
1507  clear();
1508  } else if (event->timerId() == m_tripleClickTimer) {
1510  m_tripleClickTimer = 0;
1511 #ifdef QT_GUI_PASSWORD_ECHO_DELAY
1512  } else if (event->timerId() == m_passwordEchoTimer) {
1513  killTimer(m_passwordEchoTimer);
1514  m_passwordEchoTimer = 0;
1516 #endif
1517  }
1518 }
static bool isEmpty(const char *str)
#define emit
Definition: qobjectdefs.h:76
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
QRect cursorRect() const
Returns the bounds of the current cursor, as defined as a between characters cursor.
QString inputMask() const
void updateNeeded(const QRect &)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void updateDisplayText(bool forceUpdate=false)
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650
void clear()
Clears the line control text.

◆ undo()

void QLineControl::undo ( )
inline

Definition at line 223 of file qlinecontrol_p.h.

Referenced by processKeyEvent().

223 { internalUndo(); finishChange(-1, true); }
void internalUndo(int until=-1)
bool finishChange(int validateFromState=-1, bool update=false, bool edited=true)
Completes a change to the line control text.

◆ updateDisplayText()

void QLineControl::updateDisplayText ( bool  forceUpdate = false)
private
Warning
This function is not part of the public interface.

Updates the display text based of the current edit text If the text has changed will emit displayTextChanged()

Definition at line 87 of file qlinecontrol.cpp.

Referenced by finishChange(), init(), moveCursor(), processInputMethodEvent(), timerEvent(), and updatePasswordEchoEditing().

88 {
89  QString orig = m_textLayout.text();
90  QString str;
92  str = QString::fromLatin1("");
93  else
94  str = m_text;
95 
98 #ifdef QT_GUI_PASSWORD_ECHO_DELAY
99  if (m_passwordEchoTimer != 0 && m_cursor > 0 && m_cursor <= m_text.length()) {
100  int cursor = m_cursor - 1;
101  QChar uc = m_text.at(cursor);
102  str[cursor] = uc;
103  if (cursor > 0 && uc.unicode() >= 0xdc00 && uc.unicode() < 0xe000) {
104  // second half of a surrogate, check if we have the first half as well,
105  // if yes restore both at once
106  uc = m_text.at(cursor - 1);
107  if (uc.unicode() >= 0xd800 && uc.unicode() < 0xdc00)
108  str[cursor - 1] = uc;
109  }
110  }
111 #endif
114  }
115 
116  // replace certain non-printable characters with spaces (to avoid
117  // drawing boxes when using fonts that don't have glyphs for such
118  // characters)
119  QChar* uc = str.data();
120  for (int i = 0; i < (int)str.length(); ++i) {
121  if ((uc[i] < 0x20 && uc[i] != 0x09)
122  || uc[i] == QChar::LineSeparator
123  || uc[i] == QChar::ParagraphSeparator
125  uc[i] = QChar(0x0020);
126  }
127 
128  m_textLayout.setText(str);
129 
130  QTextOption option;
133  m_textLayout.setTextOption(option);
134 
138  m_ascent = qRound(l.ascent());
139 
140  if (str != orig || forceUpdate)
142 }
void setText(const QString &string)
Sets the layout&#39;s text to the given string.
QChar m_passwordCharacter
int cursor() const
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
Qt::LayoutDirection m_layoutDirection
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
void setFlags(Flags flags)
Sets the flags associated with the option to the given flags.
Definition: qtextoption.h:151
The QString class provides a Unicode character string.
Definition: qstring.h:83
qreal ascent() const
Returns the line&#39;s ascent.
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
QString text() const
Returns the layout&#39;s text.
#define emit
Definition: qobjectdefs.h:76
void setTextDirection(Qt::LayoutDirection aDirection)
Sets the direction of the text layout defined by the option to the given direction.
Definition: qtextoption.h:99
void displayTextChanged(const QString &)
QTextLine createLine()
Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise ret...
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void setTextOption(const QTextOption &option)
Sets the text option structure that controls the layout process to the given option.
QString & fill(QChar c, int size=-1)
Sets every character in the string to character ch.
Definition: qstring.cpp:4641
QFactoryLoader * l
The QTextOption class provides a description of general rich text properties.
Definition: qtextoption.h:59
QTextLayout m_textLayout
void endLayout()
Ends the layout process.
bool m_passwordEchoEditing
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
void beginLayout()
Begins the layout process.

◆ updateMicroFocus

void QLineControl::updateMicroFocus ( )
signal

◆ updateNeeded

void QLineControl::updateNeeded ( const QRect )
signal

Referenced by setCursorBlinkPeriod(), and timerEvent().

◆ updatePasswordEchoEditing()

void QLineControl::updatePasswordEchoEditing ( bool  editing)

Sets the password echo editing to editing.

Warning
This function is not part of the public interface.

If password echo editing is true, then the text of the password is displayed even if the echo mode is set to QLineEdit::PasswordEchoOnEdit. Password echoing editing does not affect other echo modes.

Definition at line 372 of file qlinecontrol.cpp.

Referenced by processInputMethodEvent(), processKeyEvent(), and QLineEditPrivate::updatePasswordEchoEditing().

373 {
375  m_passwordEchoEditing = editing;
377 }
void cancelPasswordEchoTimer()
void updateDisplayText(bool forceUpdate=false)
bool m_passwordEchoEditing

◆ validator()

const QValidator* QLineControl::validator ( ) const
inline

Definition at line 246 of file qlinecontrol_p.h.

246 { return m_validator; }
QPointer< QValidator > m_validator

◆ width()

int QLineControl::width ( ) const
inline

Definition at line 126 of file qlinecontrol_p.h.

126 { return qRound(m_textLayout.lineAt(0).width()) + 1; }
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
qreal width() const
Returns the line&#39;s width as specified by the layout() function.
QTextLayout m_textLayout
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ xToPos()

int QLineControl::xToPos ( int  x,
QTextLine::CursorPosition  betweenOrOn = QTextLine::CursorBetweenCharacters 
) const

Returns the cursor position of the given x pixel value in relation to the displayed text.

Warning
This function is not part of the public interface.

The given betweenOrOn specified what kind of cursor position is requested.

Definition at line 389 of file qlinecontrol.cpp.

Referenced by processMouseEvent(), and QLineEditPrivate::xToPos().

390 {
391  return m_textLayout.lineAt(0).xToCursor(x, betweenOrOn);
392 }
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
QTextLayout m_textLayout
int xToCursor(qreal x, CursorPosition=CursorBetweenCharacters) const
Converts the x-coordinate x, to the nearest matching cursor position, depending on the cursor positio...

Properties

◆ m_ascent

int QLineControl::m_ascent
private

Definition at line 370 of file qlinecontrol_p.h.

Referenced by updateDisplayText().

◆ m_blank

QChar QLineControl::m_blank
private

Definition at line 397 of file qlinecontrol_p.h.

Referenced by clearString(), isValidInput(), parseInputMask(), and stripString().

◆ m_blinkPeriod

int QLineControl::m_blinkPeriod
private

Definition at line 367 of file qlinecontrol_p.h.

Referenced by draw(), resetCursorBlinkTimer(), and setCursorBlinkPeriod().

◆ m_blinkStatus

uint QLineControl::m_blinkStatus
private

Definition at line 366 of file qlinecontrol_p.h.

Referenced by draw(), resetCursorBlinkTimer(), setCursorBlinkPeriod(), and timerEvent().

◆ m_blinkTimer

int QLineControl::m_blinkTimer
private

Definition at line 368 of file qlinecontrol_p.h.

Referenced by resetCursorBlinkTimer(), setCursorBlinkPeriod(), and timerEvent().

◆ m_cancelText

QString QLineControl::m_cancelText
private

Definition at line 376 of file qlinecontrol_p.h.

Referenced by processKeyEvent().

◆ m_completer

QPointer<QCompleter> QLineControl::m_completer
private

Definition at line 385 of file qlinecontrol_p.h.

Referenced by advanceToEnabledItem(), complete(), and processKeyEvent().

◆ m_cursor

int QLineControl::m_cursor
private

◆ m_cursorWidth

int QLineControl::m_cursorWidth
private

Definition at line 356 of file qlinecontrol_p.h.

Referenced by cursorRect(), and draw().

◆ m_deleteAllTimer

int QLineControl::m_deleteAllTimer
private

Definition at line 369 of file qlinecontrol_p.h.

Referenced by processEvent(), processKeyEvent(), and timerEvent().

◆ m_dragEnabled

uint QLineControl::m_dragEnabled
private

Definition at line 361 of file qlinecontrol_p.h.

◆ m_echoMode

uint QLineControl::m_echoMode
private

◆ m_hideCursor

uint QLineControl::m_hideCursor
private

Definition at line 358 of file qlinecontrol_p.h.

Referenced by draw(), and processInputMethodEvent().

◆ m_history

QVector<Command> QLineControl::m_history
private

◆ m_inputMask

QString QLineControl::m_inputMask
private

Definition at line 396 of file qlinecontrol_p.h.

Referenced by parseInputMask().

◆ m_lastCursorPos

int QLineControl::m_lastCursorPos
private

Definition at line 372 of file qlinecontrol_p.h.

Referenced by emitCursorPositionChanged(), and finishChange().

◆ m_layoutDirection

Qt::LayoutDirection QLineControl::m_layoutDirection
private

Definition at line 357 of file qlinecontrol_p.h.

Referenced by updateDisplayText().

◆ m_maskData

MaskInputData* QLineControl::m_maskData
private

◆ m_maxLength

int QLineControl::m_maxLength
private

◆ m_modifiedState

int QLineControl::m_modifiedState
private

Definition at line 409 of file qlinecontrol_p.h.

Referenced by finishChange(), and internalSetText().

◆ m_palette

QPalette QLineControl::m_palette
private

Definition at line 353 of file qlinecontrol_p.h.

Referenced by draw().

◆ m_passwordCharacter

QChar QLineControl::m_passwordCharacter
private

Definition at line 433 of file qlinecontrol_p.h.

Referenced by updateDisplayText().

◆ m_passwordEchoEditing

bool QLineControl::m_passwordEchoEditing
private

Definition at line 432 of file qlinecontrol_p.h.

Referenced by updateDisplayText(), and updatePasswordEchoEditing().

◆ m_preeditCursor

int QLineControl::m_preeditCursor
private

Definition at line 355 of file qlinecontrol_p.h.

Referenced by cursorRect(), draw(), and processInputMethodEvent().

◆ m_readOnly

uint QLineControl::m_readOnly
private

Definition at line 360 of file qlinecontrol_p.h.

Referenced by isRedoAvailable(), and isUndoAvailable().

◆ m_selDirty

uint QLineControl::m_selDirty
private

Definition at line 364 of file qlinecontrol_p.h.

Referenced by finishChange(), and moveCursor().

◆ m_selend

int QLineControl::m_selend
private

◆ m_selstart

int QLineControl::m_selstart
private

◆ m_separator

uint QLineControl::m_separator
private

Definition at line 359 of file qlinecontrol_p.h.

Referenced by addCommand().

◆ m_text

QString QLineControl::m_text
private

◆ m_textDirty

uint QLineControl::m_textDirty
private

◆ m_textLayout

QTextLayout QLineControl::m_textLayout
private

◆ m_transactions

QList<int> QLineControl::m_transactions
private

Definition at line 373 of file qlinecontrol_p.h.

Referenced by finishChange().

◆ m_tripleClick

QPoint QLineControl::m_tripleClick
private

Definition at line 374 of file qlinecontrol_p.h.

Referenced by processMouseEvent().

◆ m_tripleClickTimer

int QLineControl::m_tripleClickTimer
private

Definition at line 375 of file qlinecontrol_p.h.

Referenced by processMouseEvent(), and timerEvent().

◆ m_undoState

int QLineControl::m_undoState
private

◆ m_validator

QPointer<QValidator> QLineControl::m_validator
private

Definition at line 383 of file qlinecontrol_p.h.

Referenced by finishChange(), fixup(), and hasAcceptableInput().

◆ m_validInput

uint QLineControl::m_validInput
private

Definition at line 365 of file qlinecontrol_p.h.

Referenced by finishChange().


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