Qt 4.8
qlinecontrol.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qlinecontrol_p.h"
43 
44 #ifndef QT_NO_LINEEDIT
45 
46 #include "qabstractitemview.h"
47 #include "qclipboard.h"
48 #ifndef QT_NO_ACCESSIBILITY
49 #include "qaccessible.h"
50 #endif
51 #ifndef QT_NO_IM
52 #include "qinputcontext.h"
53 #include "qlist.h"
54 #endif
55 #include "qapplication.h"
56 #ifndef QT_NO_GRAPHICSVIEW
57 #include "qgraphicssceneevent.h"
58 #endif
59 
61 
62 #ifdef QT_GUI_PASSWORD_ECHO_DELAY
63 static const int qt_passwordEchoDelay = QT_GUI_PASSWORD_ECHO_DELAY;
64 #endif
65 
87 void QLineControl::updateDisplayText(bool forceUpdate)
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 }
143 
144 #ifndef QT_NO_CLIPBOARD
145 
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 }
168 
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 }
189 
190 #endif // !QT_NO_CLIPBOARD
191 
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 }
225 
239 {
240  int priorState = m_undoState;
241  if (hasSelectedText()) {
243  } else {
245  while (n--)
246  internalDelete();
247  }
248  finishChange(priorState);
249 }
250 
261 void QLineControl::insert(const QString &newText)
262 {
263  int priorState = m_undoState;
265  internalInsert(newText);
266  finishChange(priorState);
267 }
268 
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 }
286 
298 void QLineControl::setSelection(int start, int length)
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 }
329 
331 {
332 }
333 
335 {
336  if (!hasSelectedText())
337  return;
338 
339  int priorState = m_undoState;
342  separate();
343  finishChange(priorState);
344 }
345 
354 void QLineControl::init(const QString &txt)
355 {
356  m_text = txt;
358  m_cursor = m_text.length();
359 }
360 
373 {
375  m_passwordEchoEditing = editing;
377 }
378 
389 int QLineControl::xToPos(int x, QTextLine::CursorPosition betweenOrOn) const
390 {
391  return m_textLayout.lineAt(0).xToCursor(x, betweenOrOn);
392 }
393 
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 }
415 
426 bool QLineControl::fixup() // this function assumes that validate currently returns != Acceptable
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 }
442 
452 void QLineControl::moveCursor(int pos, bool mark)
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 }
480 
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 }
589 
608 void QLineControl::draw(QPainter *painter, const QPoint &offset, const QRect &clip, int flags)
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 }
641 
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 }
665 
681 bool QLineControl::finishChange(int validateFromState, bool update, bool edited)
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 }
733 
742 void QLineControl::internalSetText(const QString &txt, int pos, bool edited)
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 }
767 
768 
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 }
789 
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) {
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 }
834 
849 void QLineControl::internalDelete(bool wasBackspace)
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) {
860  } else {
861  m_text.remove(m_cursor, 1);
862  }
863  m_textDirty = true;
864  }
865 }
866 
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 {
903  }
904  if (m_cursor > m_selstart)
907  m_textDirty = true;
908  }
909 }
910 
920 void QLineControl::parseInputMask(const QString &maskFields)
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;
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 }
1016 
1017 
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 }
1091 
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 }
1130 
1142 QString QLineControl::maskString(uint pos, const QString &str, bool clear) const
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 }
1208 
1209 
1210 
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 }
1235 
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 }
1261 
1266 int QLineControl::findInMask(int pos, bool forward, bool findSeparator, QChar searchChar) const
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 }
1291 
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 }
1340 
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 }
1383 
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 }
1404 
1405 #ifndef QT_NO_COMPLETER
1406 // iterating forward(dir=1)/backward(dir=-1) from the
1407 // current row based. dir=0 indicates a new completion prefix was set.
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 }
1431 
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 }
1470 #endif
1471 
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 }
1489 
1491 {
1492  if (m_blinkPeriod == 0 || m_blinkTimer == 0)
1493  return;
1496  m_blinkStatus = 1;
1497 }
1498 
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 }
1519 
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 }
1616 
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 }
1670 
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
1799  else if (event == QKeySequence::MoveToStartOfLine || event == QKeySequence::MoveToStartOfBlock) {
1800  home(0);
1801  }
1802  else if (event == QKeySequence::MoveToEndOfLine || event == QKeySequence::MoveToEndOfBlock) {
1803  end(0);
1804  }
1805  else if (event == QKeySequence::SelectStartOfLine || event == QKeySequence::SelectStartOfBlock) {
1806  home(1);
1807  }
1808  else if (event == QKeySequence::SelectEndOfLine || event == QKeySequence::SelectEndOfBlock) {
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  }
1826  else if (event == QKeySequence::MoveToPreviousChar) {
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  }
1838  else if (event == QKeySequence::SelectPreviousChar) {
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  }
1847  else if (event == QKeySequence::MoveToPreviousWord) {
1848  if (echoMode() == QLineEdit::Normal)
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)
1857  else
1858  layoutDirection() == Qt::LeftToRight ? end(1) : home(1);
1859  }
1860  else if (event == QKeySequence::SelectPreviousWord) {
1861  if (echoMode() == QLineEdit::Normal)
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 }
1996 
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 }
2004 
2006 {
2007  // Same as with undo. Disabled for password modes.
2008  return !m_readOnly
2010  && m_undoState < m_history.size();
2011 }
2012 
2014 
2015 #endif
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
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
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
CompletionMode
This enum specifies how completions are provided to the user.
Definition: qcompleter.h:77
void setText(const QString &string)
Sets the layout&#39;s text to the given string.
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
virtual void timerEvent(QTimerEvent *event)
This event handler can be reimplemented in a subclass to receive timer events for the object...
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
QChar m_passwordCharacter
The QKeyEvent class describes a key event.
Definition: qevent.h:224
int type
Definition: qmetatype.cpp:239
bool isLetter() const
Returns true if the character is a letter (Letter_* categories); otherwise returns false...
Definition: qchar.cpp:653
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
Qt::CursorMoveStyle cursorMoveStyle() const
int selectionStart() const
int cursor() const
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
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
QString textAfterSelection() const
The QInputMethodEvent::Attribute class stores an input method attribute.
Definition: qevent.h:441
int digitValue() const
Returns the numeric value of the digit, or -1 if the character is not a digit.
Definition: qchar.cpp:817
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)
void processMouseEvent(QMouseEvent *ev)
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
QAbstractItemModel * completionModel() const
Returns the completion model.
bool isNull() const
Returns true if the character is the Unicode character 0x0000 (&#39;\0&#39;); otherwise returns false...
Definition: qchar.h:262
void resetInputContext()
void cursorPositionChanged(int, int)
void cancelPasswordEchoTimer()
QString currentCompletion() const
Returns the current completion string.
Qt::LayoutDirection m_layoutDirection
void home(bool mark)
bool isVisible() const
Definition: qwidget.h:1005
void setText(const QString &txt)
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
QString text() const
void setCursorBlinkPeriod(int msec)
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
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
#define SLOT(a)
Definition: qobjectdefs.h:226
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
bool processEvent(QEvent *ev)
void accepted()
void addCommand(const Command &cmd)
Adds the given command to the undo history of the line control.
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...
bool isLowSurrogate() const
Returns true if the QChar is the low part of a utf16 surrogate (ie.
Definition: qchar.h:279
Qt::MouseButton button() const
Returns the mouse button (if any) that caused the event.
QVector< Command > m_history
int nextCursorPosition(int oldPos, CursorMode mode=SkipCharacters) const
Returns the next valid cursor position after oldPos that respects the given cursor mode...
QString stripString(const QString &str) const
Strips blank parts of the input in a QLineControl when an inputMask is set, separators are still incl...
QPoint m_tripleClick
QString m_inputMask
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
bool isValidInput(QChar key, QChar mask) const
void removeSelectedText()
Also adds the appropriate commands into the undo history.
void resetCursorBlinkTimer()
void setFlags(Flags flags)
Sets the flags associated with the option to the given flags.
Definition: qtextoption.h:151
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
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
bool isValid() const
Returns true if this character format is valid; otherwise returns false.
Definition: qtextformat.h:397
QString m_cancelText
void internalSetText(const QString &txt, int pos=-1, bool edited=true)
An internal function for setting the text of the line control.
bool isHighSurrogate() const
Returns true if the QChar is the high part of a utf16 surrogate (ie.
Definition: qchar.h:276
void init(const QString &txt)
Initializes the line control with a starting text value of txt.
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
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
void internalUndo(int until=-1)
void _q_deleteSelected()
qreal ascent() const
Returns the line&#39;s ascent.
CompletionMode completionMode
how the completions are provided to the user
Definition: qcompleter.h:69
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
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
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
QString textBeforeSelection() const
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
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void insert(const QString &)
Inserts the given newText at the current cursor position.
Qt::CaseSensitivity caseSensitivity
the case sensitivity of the matching
Definition: qcompleter.h:73
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool setCurrentRow(int row)
Sets the current row to the row specified.
qreal cursorToX(int *cursorPos, Edge edge=Leading) const
Converts the cursor position cursorPos to the corresponding x position inside the line...
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
QString text() const
Returns the layout&#39;s text.
bool hasAcceptableInput() const
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void processInputMethodEvent(QInputMethodEvent *event)
static bool isEmpty(const char *str)
void editingFinished()
bool passwordEchoEditing() const
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
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
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
int start() const
void internalDelete(bool wasBackspace=false)
Also adds the appropriate commands into the undo history.
QList< int > m_transactions
#define emit
Definition: qobjectdefs.h:76
void setSelection(int start, int length)
Sets length characters from the given start position as selected.
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
virtual State validate(QString &, int &) const =0
This virtual function returns Invalid if input is invalid according to this validator&#39;s rules...
bool isRedoAvailable() const
Q_CORE_EXPORT void qWarning(const char *,...)
void setCompletionPrefix(const QString &prefix)
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
unsigned int uint
Definition: qglobal.h:996
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
int currentRow() const
Returns the current row.
void setTextDirection(Qt::LayoutDirection aDirection)
Sets the direction of the text layout defined by the option to the given direction.
Definition: qtextoption.h:99
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...
QRect cursorRect() const
Returns the bounds of the current cursor, as defined as a between characters cursor.
static int startDragDistance()
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.
void updateMicroFocus()
bool fixup()
Fixes the current text so that it is valid given any set validators.
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
int nextMaskBlank(int pos)
QPointer< QCompleter > m_completer
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
void hide()
Hides the widget.
Definition: qwidget.h:501
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
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
Q_GUI_EXPORT QString escape(const QString &plain)
Converts the plain text string plain to a HTML string with HTML metacharacters <, >...
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.
QString inputMask() const
bool wrapAround
the completions wrap around when navigating through items
Definition: qcompleter.h:74
void textEdited(const QString &)
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
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 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
QPointer< QValidator > m_validator
QString completionPrefix
the completion prefix used to provide completions.
Definition: qcompleter.h:67
void cursorWordBackward(bool mark)
bool isReadOnly() const
void moveCursor(int pos, bool mark=false)
Moves the cursor to the given position pos.
QString selectedText() const
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
int compare(const QString &s) const
Definition: qstring.cpp:5037
void _q_clipboardChanged()
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
QString clearString(uint pos, uint len) const
Returns a "cleared" string with only separators and blank chars.
void internalDeselect()
QString text() const
Returns the Unicode text that this key generated.
Definition: qevent.h:236
void copy(QClipboard::Mode mode=QClipboard::Clipboard) const
Copies the currently selected text into the clipboard using the given mode.
bool finishChange(int validateFromState=-1, bool update=false, bool edited=true)
Completes a change to the line control text.
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
void 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...
QPalette m_palette
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 setFontUnderline(bool underline)
If underline is true, sets the text format&#39;s font to be underlined; otherwise it is displayed non-und...
Definition: qtextformat.h:432
int prevMaskBlank(int pos)
void setTextOption(const QTextOption &option)
Sets the text option structure that controls the layout process to the given option.
void updateNeeded(const QRect &)
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
MaskInputData * m_maskData
void selectWordAtPos(int)
Sets the selection to cover the word at the given cursor position.
int key
Qt::LayoutDirection layoutDirection() const
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
void complete(const QRect &rect=QRect())
For QCompleter::PopupCompletion and QCompletion::UnfilteredPopupCompletion modes, calling this functi...
The QModelIndex class is used to locate data in a data model.
QString & fill(QChar c, int size=-1)
Sets every character in the string to character ch.
Definition: qstring.cpp:4641
void textChanged(const QString &)
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
QFactoryLoader * l
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
QString maskString(uint pos, const QString &str, bool clear=false) const
Applies the inputMask on str starting from position pos in the mask.
void selectionChanged()
The QTextOption class provides a description of general rich text properties.
Definition: qtextoption.h:59
int completionCount() const
Returns the number of completions for the current prefix.
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
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.
void updateDisplayText(bool forceUpdate=false)
bool advanceToEnabledItem(int dir)
quint16 index
bool isUndoAvailable() const
void cursorForward(bool mark, int steps)
void setLayoutDirection(Qt::LayoutDirection direction)
QPointF pos() const
Returns the mouse cursor position in item coordinates.
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.
void parseInputMask(const QString &maskFields)
Parses the input mask specified by maskFields to generate the mask data used to handle input masks...
QTextCharFormat format
Specifies the format to apply.
Definition: qtextlayout.h:131
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifiers in use at the time the event was sent.
QTextLayout m_textLayout
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
Definition: qtextformat.h:350
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
bool hasSelectedText() const
int replacementLength() const
Returns the number of characters to be replaced in the preedit string.
Definition: qevent.h:459
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
void endLayout()
Ends the layout process.
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
void del()
Handles the behavior for the delete key or function.
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition: qevent.h:79
void internalInsert(const QString &s)
Inserts the given string s into the line control.
void complete(int key)
int previousCursorPosition(int oldPos, CursorMode mode=SkipCharacters) const
Returns the first valid cursor position before oldPos that respects the given cursor mode...
int xToCursor(qreal x, CursorPosition=CursorBetweenCharacters) const
Converts the x-coordinate x, to the nearest matching cursor position, depending on the cursor positio...
int selectionEnd() const
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
void setUnderlineStyle(UnderlineStyle style)
Sets the style of underlining the text to style.
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
int end() const
static int doubleClickInterval()
QString & insert(int i, QChar c)
Definition: qstring.cpp:1671
bool m_passwordEchoEditing
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
void paste(QClipboard::Mode mode=QClipboard::Clipboard)
Inserts the text stored in the application clipboard into the line control.
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
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
qreal height() const
Returns the line&#39;s height.
bool isNumber() const
Returns true if the character is a number (Number_* categories, not just 0-9); otherwise returns fals...
Definition: qchar.cpp:669
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
QAbstractItemView * popup() const
Returns the popup used to display completions.
void beginLayout()
Begins the layout process.
QModelIndex currentIndex() const
Returns the model index of the current completion in the completionModel().
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
bool isLetterOrNumber() const
Returns true if the character is a letter or number (Letter_* or Number_* categories); otherwise retu...
Definition: qchar.cpp:681
int findInMask(int pos, bool forward, bool findSeparator, QChar searchChar=QChar()) const
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650
void processKeyEvent(QKeyEvent *ev)
void clear()
Clears the line control text.