Qt 4.8
qlineedit.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 "qlineedit.h"
43 #include "qlineedit_p.h"
44 
45 #ifndef QT_NO_LINEEDIT
46 #include "qaction.h"
47 #include "qapplication.h"
48 #include "qclipboard.h"
49 #include "qdrag.h"
50 #include "qdrawutil.h"
51 #include "qevent.h"
52 #include "qfontmetrics.h"
53 #include "qmenu.h"
54 #include "qpainter.h"
55 #include "qpixmap.h"
56 #include "qpointer.h"
57 #include "qstringlist.h"
58 #include "qstyle.h"
59 #include "qstyleoption.h"
60 #include "qtimer.h"
61 #include "qvalidator.h"
62 #include "qvariant.h"
63 #include "qvector.h"
64 #include "qwhatsthis.h"
65 #include "qdebug.h"
66 #include "qtextedit.h"
67 #include <private/qtextedit_p.h>
68 #ifndef QT_NO_ACCESSIBILITY
69 #include "qaccessible.h"
70 #endif
71 #ifndef QT_NO_IM
72 #include "qinputcontext.h"
73 #include "qlist.h"
74 #endif
75 #include "qabstractitemview.h"
76 #include "private/qstylesheetstyle_p.h"
77 
78 #ifndef QT_NO_SHORTCUT
79 #include "private/qapplication_p.h"
80 #include "private/qshortcutmap_p.h"
81 #include "qkeysequence.h"
82 #define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? QLatin1Char('\t') + QString(QKeySequence(k)) : QString())
83 #else
84 #define ACCEL_KEY(k) QString()
85 #endif
86 
87 #include <limits.h>
88 
90 
91 #ifdef Q_WS_MAC
92 extern void qt_mac_secure_keyboard(bool); //qapplication_mac.cpp
93 #endif
94 
105 {
106  if (!option)
107  return;
108 
109  Q_D(const QLineEdit);
110  option->initFrom(this);
111  option->rect = contentsRect();
112  option->lineWidth = d->frame ? style()->pixelMetric(QStyle::PM_DefaultFrameWidth, option, this)
113  : 0;
114  option->midLineWidth = 0;
115  option->state |= QStyle::State_Sunken;
116  if (d->control->isReadOnly())
117  option->state |= QStyle::State_ReadOnly;
118 #ifdef QT_KEYPAD_NAVIGATION
119  if (hasEditFocus())
120  option->state |= QStyle::State_HasEditFocus;
121 #endif
122  if (QStyleOptionFrameV2 *optionV2 = qstyleoption_cast<QStyleOptionFrameV2 *>(option))
123  optionV2->features = QStyleOptionFrameV2::None;
124 }
125 
281  : QWidget(*new QLineEditPrivate, parent,0)
282 {
283  Q_D(QLineEdit);
284  d->init(QString());
285 }
286 
299  : QWidget(*new QLineEditPrivate, parent, 0)
300 {
301  Q_D(QLineEdit);
302  d->init(contents);
303 }
304 
305 
306 #ifdef QT3_SUPPORT
307 
317  : QWidget(*new QLineEditPrivate, parent,0)
318 {
319  Q_D(QLineEdit);
321  d->init(QString());
322 }
323 
336 QLineEdit::QLineEdit(const QString& contents, QWidget* parent, const char* name)
337  : QWidget(*new QLineEditPrivate, parent, 0)
338 {
339  Q_D(QLineEdit);
341  d->init(contents);
342 }
343 
357 QLineEdit::QLineEdit(const QString& contents, const QString &inputMask, QWidget* parent, const char* name)
358  : QWidget(*new QLineEditPrivate, parent, 0)
359 {
360  Q_D(QLineEdit);
362  d->init(contents);
363  d->control->setInputMask(inputMask);
364  d->control->moveCursor(d->control->nextMaskBlank(contents.length()));
365 }
366 #endif
367 
373 {
374 }
375 
376 
395 QString QLineEdit::text() const
396 {
397  Q_D(const QLineEdit);
398  return d->control->text();
399 }
400 
402 {
403  Q_D(QLineEdit);
404  d->control->setText(text);
405 }
406 
425 {
426  Q_D(const QLineEdit);
427  return d->placeholderText;
428 }
429 
431 {
432  Q_D(QLineEdit);
433  if (d->placeholderText != placeholderText) {
434  d->placeholderText = placeholderText;
435  if (!hasFocus())
436  update();
437  }
438 }
439 
458 {
459  Q_D(const QLineEdit);
460  return d->control->displayText();
461 }
462 
463 
485 int QLineEdit::maxLength() const
486 {
487  Q_D(const QLineEdit);
488  return d->control->maxLength();
489 }
490 
492 {
493  Q_D(QLineEdit);
494  d->control->setMaxLength(maxLength);
495 }
496 
508 {
509  Q_D(const QLineEdit);
510  return d->frame;
511 }
512 
513 
514 void QLineEdit::setFrame(bool enable)
515 {
516  Q_D(QLineEdit);
517  d->frame = enable;
518  update();
519  updateGeometry();
520 }
521 
522 
570 {
571  Q_D(const QLineEdit);
572  return (EchoMode) d->control->echoMode();
573 }
574 
576 {
577  Q_D(QLineEdit);
578  if (mode == (EchoMode)d->control->echoMode())
579  return;
580  Qt::InputMethodHints imHints = inputMethodHints();
581  if (mode == Password || mode == NoEcho) {
582  imHints |= Qt::ImhHiddenText;
583  } else {
584  imHints &= ~Qt::ImhHiddenText;
585  }
586  if (mode != Normal) {
588  } else {
590  }
591  setInputMethodHints(imHints);
592  d->control->setEchoMode(mode);
593  update();
594 #ifdef Q_WS_MAC
595  if (hasFocus())
596  qt_mac_secure_keyboard(mode == Password || mode == NoEcho);
597 #endif
598 }
599 
600 
601 #ifndef QT_NO_VALIDATOR
602 
610 {
611  Q_D(const QLineEdit);
612  return d->control->validator();
613 }
614 
628 {
629  Q_D(QLineEdit);
630  d->control->setValidator(v);
631 }
632 #endif // QT_NO_VALIDATOR
633 
634 #ifndef QT_NO_COMPLETER
635 
655 {
656  Q_D(QLineEdit);
657  if (c == d->control->completer())
658  return;
659  if (d->control->completer()) {
660  disconnect(d->control->completer(), 0, this, 0);
661  d->control->completer()->setWidget(0);
662  if (d->control->completer()->parent() == this)
663  delete d->control->completer();
664  }
665  d->control->setCompleter(c);
666  if (!c)
667  return;
668  if (c->widget() == 0)
669  c->setWidget(this);
670  if (hasFocus()) {
671  QObject::connect(d->control->completer(), SIGNAL(activated(QString)),
672  this, SLOT(setText(QString)));
673  QObject::connect(d->control->completer(), SIGNAL(highlighted(QString)),
674  this, SLOT(_q_completionHighlighted(QString)));
675  }
676 }
677 
687 {
688  Q_D(const QLineEdit);
689  return d->control->completer();
690 }
691 
692 #endif // QT_NO_COMPLETER
693 
702 {
703  Q_D(const QLineEdit);
704  ensurePolished();
705  QFontMetrics fm(font());
706  int h = qMax(fm.height(), 14) + 2*d->verticalMargin
707  + d->topTextMargin + d->bottomTextMargin
708  + d->topmargin + d->bottommargin;
709  int w = fm.width(QLatin1Char('x')) * 17 + 2*d->horizontalMargin
710  + d->leftTextMargin + d->rightTextMargin
711  + d->leftmargin + d->rightmargin; // "some"
713  initStyleOption(&opt);
714  return (style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h).
715  expandedTo(QApplication::globalStrut()), this));
716 }
717 
718 
726 {
727  Q_D(const QLineEdit);
728  ensurePolished();
729  QFontMetrics fm = fontMetrics();
730  int h = fm.height() + qMax(2*d->verticalMargin, fm.leading())
731  + d->topmargin + d->bottommargin;
732  int w = fm.maxWidth() + d->leftmargin + d->rightmargin;
734  initStyleOption(&opt);
735  return (style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h).
736  expandedTo(QApplication::globalStrut()), this));
737 }
738 
739 
752 int QLineEdit::cursorPosition() const
753 {
754  Q_D(const QLineEdit);
755  return d->control->cursorPosition();
756 }
757 
759 {
760  Q_D(QLineEdit);
761  d->control->setCursorPosition(pos);
762 }
763 
767 // ### What should this do if the point is outside of contentsRect? Currently returns 0.
769 {
770  Q_D(QLineEdit);
771  return d->xToPos(pos.x());
772 }
773 
774 
775 #ifdef QT3_SUPPORT
776 
783 bool QLineEdit::validateAndSet(const QString &newText, int newPos,
784  int newMarkAnchor, int newMarkDrag)
785 {
786  // The suggested functions above in the docs don't seem to validate,
787  // below code tries to mimic previous behaviour.
788  QString oldText = text();
789  setText(newText);
790  if(!hasAcceptableInput()){
791  setText(oldText);
792  return false;
793  }
794  int selstart = qMin(newMarkAnchor, newMarkDrag);
795  int sellength = qAbs(newMarkAnchor - newMarkDrag);
796  if (selstart == newPos) {
797  selstart = qMax(newMarkAnchor, newMarkDrag);
798  sellength = -sellength;
799  }
800  //setSelection also set the position
801  setSelection(selstart, sellength);
802  return true;
803 }
804 #endif //QT3_SUPPORT
805 
821 Qt::Alignment QLineEdit::alignment() const
822 {
823  Q_D(const QLineEdit);
824  return QFlag(d->alignment);
825 }
826 
828 {
829  Q_D(QLineEdit);
830  d->alignment = alignment;
831  update();
832 }
833 
834 
843 void QLineEdit::cursorForward(bool mark, int steps)
844 {
845  Q_D(QLineEdit);
846  d->control->cursorForward(mark, steps);
847 }
848 
849 
857 void QLineEdit::cursorBackward(bool mark, int steps)
858 {
859  cursorForward(mark, -steps);
860 }
861 
869 {
870  Q_D(QLineEdit);
871  d->control->cursorWordForward(mark);
872 }
873 
882 {
883  Q_D(QLineEdit);
884  d->control->cursorWordBackward(mark);
885 }
886 
887 
897 {
898  Q_D(QLineEdit);
899  d->control->backspace();
900 }
901 
911 {
912  Q_D(QLineEdit);
913  d->control->del();
914 }
915 
925 void QLineEdit::home(bool mark)
926 {
927  Q_D(QLineEdit);
928  d->control->home(mark);
929 }
930 
940 void QLineEdit::end(bool mark)
941 {
942  Q_D(QLineEdit);
943  d->control->end(mark);
944 }
945 
946 
969 {
970  Q_D(const QLineEdit);
971  return d->control->isModified();
972 }
973 
975 {
976  Q_D(QLineEdit);
977  d->control->setModified(modified);
978 }
979 
980 
1005 bool QLineEdit::hasSelectedText() const
1006 {
1007  Q_D(const QLineEdit);
1008  return d->control->hasSelectedText();
1009 }
1010 
1027 {
1028  Q_D(const QLineEdit);
1029  return d->control->selectedText();
1030 }
1031 
1040 {
1041  Q_D(const QLineEdit);
1042  return d->control->selectionStart();
1043 }
1044 
1045 
1046 #ifdef QT3_SUPPORT
1047 
1063 bool QLineEdit::edited() const { return isModified(); }
1067 void QLineEdit::setEdited(bool on) { setModified(on); }
1068 
1072 int QLineEdit::characterAt(int xpos, QChar *chr) const
1073 {
1074  Q_D(const QLineEdit);
1075  int pos = d->xToPos(xpos + contentsRect().x() - d->hscroll + d->horizontalMargin);
1076  QString txt = d->control->text();
1077  if (chr && pos < (int) txt.length())
1078  *chr = txt.at(pos);
1079  return pos;
1080 
1081 }
1082 
1086 bool QLineEdit::getSelection(int *start, int *end)
1087 {
1088  Q_D(QLineEdit);
1089  if (d->control->hasSelectedText() && start && end) {
1090  *start = selectionStart();
1091  *end = *start + selectedText().length();
1092  return true;
1093  }
1094  return false;
1095 }
1096 #endif
1097 
1098 
1106 void QLineEdit::setSelection(int start, int length)
1107 {
1108  Q_D(QLineEdit);
1109  if (start < 0 || start > (int)d->control->text().length()) {
1110  qWarning("QLineEdit::setSelection: Invalid start position (%d)", start);
1111  return;
1112  }
1113 
1114  d->control->setSelection(start, length);
1115 
1116  if (d->control->hasSelectedText()){
1117  QStyleOptionFrameV2 opt;
1118  initStyleOption(&opt);
1120  d->setCursorVisible(false);
1121  }
1122 }
1123 
1124 
1138 {
1139  Q_D(const QLineEdit);
1140  return d->control->isUndoAvailable();
1141 }
1142 
1157 {
1158  Q_D(const QLineEdit);
1159  return d->control->isRedoAvailable();
1160 }
1161 
1173 bool QLineEdit::dragEnabled() const
1174 {
1175  Q_D(const QLineEdit);
1176  return d->dragEnabled;
1177 }
1178 
1180 {
1181  Q_D(QLineEdit);
1182  d->dragEnabled = b;
1183 }
1184 
1185 
1214 {
1215  Q_D(const QLineEdit);
1216  return d->control->cursorMoveStyle();
1217 }
1218 
1229 {
1230  Q_D(QLineEdit);
1231  d->control->setCursorMoveStyle(style);
1232 }
1233 
1247 {
1248  Q_D(const QLineEdit);
1249  return d->control->hasAcceptableInput();
1250 }
1251 
1259 void QLineEdit::setTextMargins(int left, int top, int right, int bottom)
1260 {
1261  Q_D(QLineEdit);
1262  d->leftTextMargin = left;
1263  d->topTextMargin = top;
1264  d->rightTextMargin = right;
1265  d->bottomTextMargin = bottom;
1266  updateGeometry();
1267  update();
1268 }
1269 
1280 {
1281  setTextMargins(margins.left(), margins.top(), margins.right(), margins.bottom());
1282 }
1283 
1290 void QLineEdit::getTextMargins(int *left, int *top, int *right, int *bottom) const
1291 {
1292  Q_D(const QLineEdit);
1293  if (left)
1294  *left = d->leftTextMargin;
1295  if (top)
1296  *top = d->topTextMargin;
1297  if (right)
1298  *right = d->rightTextMargin;
1299  if (bottom)
1300  *bottom = d->bottomTextMargin;
1301 }
1302 
1313 {
1314  Q_D(const QLineEdit);
1315  return QMargins(d->leftTextMargin, d->topTextMargin, d->rightTextMargin, d->bottomTextMargin);
1316 }
1317 
1385 {
1386  Q_D(const QLineEdit);
1387  return d->control->inputMask();
1388 }
1389 
1390 void QLineEdit::setInputMask(const QString &inputMask)
1391 {
1392  Q_D(QLineEdit);
1393  d->control->setInputMask(inputMask);
1394 }
1395 
1406 {
1407  Q_D(QLineEdit);
1408  d->control->selectAll();
1409 }
1410 
1418 {
1419  Q_D(QLineEdit);
1420  d->control->deselect();
1421 }
1422 
1423 
1431 void QLineEdit::insert(const QString &newText)
1432 {
1433 // q->resetInputContext(); //#### FIX ME IN QT
1434  Q_D(QLineEdit);
1435  d->control->insert(newText);
1436 }
1437 
1444 {
1445  Q_D(QLineEdit);
1447  d->control->clear();
1448 }
1449 
1457 {
1458  Q_D(QLineEdit);
1460  d->control->undo();
1461 }
1462 
1468 {
1469  Q_D(QLineEdit);
1471  d->control->redo();
1472 }
1473 
1474 
1494 {
1495  Q_D(const QLineEdit);
1496  return d->control->isReadOnly();
1497 }
1498 
1499 void QLineEdit::setReadOnly(bool enable)
1500 {
1501  Q_D(QLineEdit);
1502  if (d->control->isReadOnly() != enable) {
1503  d->control->setReadOnly(enable);
1505  setAttribute(Qt::WA_InputMethodEnabled, d->shouldEnableInputMethod());
1506 #ifndef QT_NO_CURSOR
1508 #endif
1509  update();
1510  }
1511 }
1512 
1513 
1514 #ifndef QT_NO_CLIPBOARD
1515 
1526 {
1527  if (hasSelectedText()) {
1528  copy();
1529  del();
1530  }
1531 }
1532 
1533 
1541 void QLineEdit::copy() const
1542 {
1543  Q_D(const QLineEdit);
1544  d->control->copy();
1545 }
1546 
1559 {
1560  Q_D(QLineEdit);
1561  d->control->paste();
1562 }
1563 
1564 #endif // !QT_NO_CLIPBOARD
1565 
1569 {
1570  Q_D(QLineEdit);
1571  if (e->type() == QEvent::Timer) {
1572  // should be timerEvent, is here for binary compatibility
1573  int timerId = ((QTimerEvent*)e)->timerId();
1574  if (false) {
1575 #ifndef QT_NO_DRAGANDDROP
1576  } else if (timerId == d->dndTimer.timerId()) {
1577  d->drag();
1578 #endif
1579  }
1580  else if (timerId == d->tripleClickTimer.timerId())
1581  d->tripleClickTimer.stop();
1582  } else if (e->type() == QEvent::ContextMenu) {
1583 #ifndef QT_NO_IM
1584  if (d->control->composeMode())
1585  return true;
1586 #endif
1587  //d->separate();
1588  } else if (e->type() == QEvent::WindowActivate) {
1589  QTimer::singleShot(0, this, SLOT(_q_handleWindowActivate()));
1590  }else if(e->type() == QEvent::ShortcutOverride){
1591  d->control->processEvent(e);
1592  } else if (e->type() == QEvent::KeyRelease) {
1593  d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime());
1594  } else if (e->type() == QEvent::Show) {
1595  //In order to get the cursor blinking if QComboBox::setEditable is called when the combobox has focus
1596  if (hasFocus()) {
1597  d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime());
1598  QStyleOptionFrameV2 opt;
1599  initStyleOption(&opt);
1600  if ((!hasSelectedText() && d->control->preeditAreaText().isEmpty())
1602  d->setCursorVisible(true);
1603  }
1604  }
1605 
1606 #ifdef QT_KEYPAD_NAVIGATION
1607  if (QApplication::keypadNavigationEnabled()) {
1608  if (e->type() == QEvent::EnterEditFocus) {
1609  end(false);
1610  d->setCursorVisible(true);
1611  d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime());
1612  } else if (e->type() == QEvent::LeaveEditFocus) {
1613  d->setCursorVisible(false);
1614  d->control->setCursorBlinkPeriod(0);
1615  if (d->control->hasAcceptableInput() || d->control->fixup())
1617  }
1618  }
1619 #endif
1620  return QWidget::event(e);
1621 }
1622 
1626 {
1627  Q_D(QLineEdit);
1628  if (d->sendMouseEventToInputContext(e))
1629  return;
1630  if (e->button() == Qt::RightButton)
1631  return;
1632 #ifdef QT_KEYPAD_NAVIGATION
1633  if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
1634  setEditFocus(true);
1635  // Get the completion list to pop up.
1636  if (d->control->completer())
1637  d->control->completer()->complete();
1638  }
1639 #endif
1640  if (d->tripleClickTimer.isActive() && (e->pos() - d->tripleClick).manhattanLength() <
1642  selectAll();
1643  return;
1644  }
1645  bool mark = e->modifiers() & Qt::ShiftModifier;
1646  int cursor = d->xToPos(e->pos().x());
1647 #ifndef QT_NO_DRAGANDDROP
1648  if (!mark && d->dragEnabled && d->control->echoMode() == Normal &&
1649  e->button() == Qt::LeftButton && d->control->inSelection(e->pos().x())) {
1650  d->dndPos = e->pos();
1651  if (!d->dndTimer.isActive())
1652  d->dndTimer.start(QApplication::startDragTime(), this);
1653  } else
1654 #endif
1655  {
1656  d->control->moveCursor(cursor, mark);
1657  }
1658 }
1659 
1663 {
1664  Q_D(QLineEdit);
1665  if (d->sendMouseEventToInputContext(e))
1666  return;
1667 
1668  if (e->buttons() & Qt::LeftButton) {
1669 #ifndef QT_NO_DRAGANDDROP
1670  if (d->dndTimer.isActive()) {
1671  if ((d->dndPos - e->pos()).manhattanLength() > QApplication::startDragDistance())
1672  d->drag();
1673  } else
1674 #endif
1675  {
1676  d->control->moveCursor(d->xToPos(e->pos().x()), true);
1677  }
1678  }
1679 }
1680 
1684 {
1685  Q_D(QLineEdit);
1686  if (d->sendMouseEventToInputContext(e))
1687  return;
1688 #ifndef QT_NO_DRAGANDDROP
1689  if (e->button() == Qt::LeftButton) {
1690  if (d->dndTimer.isActive()) {
1691  d->dndTimer.stop();
1692  deselect();
1693  return;
1694  }
1695  }
1696 #endif
1697 #ifndef QT_NO_CLIPBOARD
1698  if (QApplication::clipboard()->supportsSelection()) {
1699  if (e->button() == Qt::LeftButton) {
1700  d->control->copy(QClipboard::Selection);
1701  } else if (!d->control->isReadOnly() && e->button() == Qt::MidButton) {
1702  deselect();
1704  }
1705  }
1706 #endif
1707 
1708  if (!isReadOnly() && rect().contains(e->pos()))
1709  d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
1710  d->clickCausedFocus = 0;
1711 }
1712 
1716 {
1717  Q_D(QLineEdit);
1718  if (d->sendMouseEventToInputContext(e))
1719  return;
1720  if (e->button() == Qt::LeftButton) {
1721  d->control->selectWordAtPos(d->xToPos(e->pos().x()));
1722  d->tripleClickTimer.start(QApplication::doubleClickInterval(), this);
1723  d->tripleClick = e->pos();
1724  }
1725 }
1726 
1765 {
1766  Q_D(QLineEdit);
1767  #ifdef QT_KEYPAD_NAVIGATION
1768  bool select = false;
1769  switch (event->key()) {
1770  case Qt::Key_Select:
1771  if (QApplication::keypadNavigationEnabled()) {
1772  if (hasEditFocus()) {
1773  setEditFocus(false);
1774  if (d->control->completer() && d->control->completer()->popup()->isVisible())
1775  d->control->completer()->popup()->hide();
1776  select = true;
1777  }
1778  }
1779  break;
1780  case Qt::Key_Back:
1781  case Qt::Key_No:
1782  if (!QApplication::keypadNavigationEnabled() || !hasEditFocus()) {
1783  event->ignore();
1784  return;
1785  }
1786  break;
1787  default:
1788  if (QApplication::keypadNavigationEnabled()) {
1789  if (!hasEditFocus() && !(event->modifiers() & Qt::ControlModifier)) {
1790  if (!event->text().isEmpty() && event->text().at(0).isPrint()
1791  && !isReadOnly())
1792  setEditFocus(true);
1793  else {
1794  event->ignore();
1795  return;
1796  }
1797  }
1798  }
1799  }
1800 
1801 
1802 
1803  if (QApplication::keypadNavigationEnabled() && !select && !hasEditFocus()) {
1804  setEditFocus(true);
1805  if (event->key() == Qt::Key_Select)
1806  return; // Just start. No action.
1807  }
1808 #endif
1809  d->control->processKeyEvent(event);
1810  if (event->isAccepted()) {
1811  if (layoutDirection() != d->control->layoutDirection())
1812  setLayoutDirection(d->control->layoutDirection());
1813  d->control->setCursorBlinkPeriod(0);
1814  }
1815 }
1816 
1826 {
1827  Q_D(const QLineEdit);
1828  return d->cursorRect();
1829 }
1830 
1834 {
1835  Q_D(QLineEdit);
1836  if (d->control->isReadOnly()) {
1837  e->ignore();
1838  return;
1839  }
1840 
1841  if (echoMode() == PasswordEchoOnEdit && !d->control->passwordEchoEditing()) {
1842  // Clear the edit and reset to normal echo mode while entering input
1843  // method data; the echo mode switches back when the edit loses focus.
1844  // ### changes a public property, resets current content.
1845  d->updatePasswordEchoEditing(true);
1846  clear();
1847  }
1848 
1849 #ifdef QT_KEYPAD_NAVIGATION
1850  // Focus in if currently in navigation focus on the widget
1851  // Only focus in on preedits, to allow input methods to
1852  // commit text as they focus out without interfering with focus
1853  if (QApplication::keypadNavigationEnabled()
1854  && hasFocus() && !hasEditFocus()
1855  && !e->preeditString().isEmpty())
1856  setEditFocus(true);
1857 #endif
1858 
1859  d->control->processInputMethodEvent(e);
1860 
1861 #ifndef QT_NO_COMPLETER
1862  if (!e->commitString().isEmpty())
1863  d->control->complete(Qt::Key_unknown);
1864 #endif
1865 }
1866 
1870 {
1871  Q_D(const QLineEdit);
1872  switch(property) {
1873  case Qt::ImMicroFocus:
1874  return d->cursorRect();
1875  case Qt::ImFont:
1876  return font();
1877  case Qt::ImCursorPosition:
1878  return QVariant(d->control->cursor());
1879  case Qt::ImSurroundingText:
1880  return QVariant(text());
1882  return QVariant(selectedText());
1884  return QVariant(maxLength());
1885  case Qt::ImAnchorPosition:
1886  if (d->control->selectionStart() == d->control->selectionEnd())
1887  return QVariant(d->control->cursor());
1888  else if (d->control->selectionStart() == d->control->cursor())
1889  return QVariant(d->control->selectionEnd());
1890  else
1891  return QVariant(d->control->selectionStart());
1892  default:
1893  return QVariant();
1894  }
1895 }
1896 
1901 {
1902  Q_D(QLineEdit);
1903  if (e->reason() == Qt::TabFocusReason ||
1904  e->reason() == Qt::BacktabFocusReason ||
1905  e->reason() == Qt::ShortcutFocusReason) {
1906  if (!d->control->inputMask().isEmpty())
1907  d->control->moveCursor(d->control->nextMaskBlank(0));
1908  else if (!d->control->hasSelectedText())
1909  selectAll();
1910  } else if (e->reason() == Qt::MouseFocusReason) {
1911  d->clickCausedFocus = 1;
1912  }
1913 #ifdef QT_KEYPAD_NAVIGATION
1914  if (!QApplication::keypadNavigationEnabled() || (hasEditFocus() && ( e->reason() == Qt::PopupFocusReason
1915 #ifdef Q_OS_SYMBIAN
1917 #endif
1918  ))) {
1919 #endif
1920  d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime());
1921  QStyleOptionFrameV2 opt;
1922  initStyleOption(&opt);
1923  if((!hasSelectedText() && d->control->preeditAreaText().isEmpty())
1925  d->setCursorVisible(true);
1926 #ifdef Q_WS_MAC
1927  if (d->control->echoMode() == Password || d->control->echoMode() == NoEcho)
1928  qt_mac_secure_keyboard(true);
1929 #endif
1930 #ifdef QT_KEYPAD_NAVIGATION
1931  d->control->setCancelText(d->control->text());
1932  }
1933 #endif
1934 #ifndef QT_NO_COMPLETER
1935  if (d->control->completer()) {
1936  d->control->completer()->setWidget(this);
1937  QObject::connect(d->control->completer(), SIGNAL(activated(QString)),
1938  this, SLOT(setText(QString)));
1939  QObject::connect(d->control->completer(), SIGNAL(highlighted(QString)),
1940  this, SLOT(_q_completionHighlighted(QString)));
1941  }
1942 #endif
1943  update();
1944 }
1945 
1950 {
1951  Q_D(QLineEdit);
1952  if (d->control->passwordEchoEditing()) {
1953  // Reset the echomode back to PasswordEchoOnEdit when the widget loses
1954  // focus.
1955  d->updatePasswordEchoEditing(false);
1956  }
1957 
1958  Qt::FocusReason reason = e->reason();
1959  if (reason != Qt::ActiveWindowFocusReason &&
1960  reason != Qt::PopupFocusReason)
1961  deselect();
1962 
1963  d->setCursorVisible(false);
1964  d->control->setCursorBlinkPeriod(0);
1965 #ifdef QT_KEYPAD_NAVIGATION
1966  // editingFinished() is already emitted on LeaveEditFocus
1967  if (!QApplication::keypadNavigationEnabled())
1968 #endif
1969  if (reason != Qt::PopupFocusReason
1971  if (hasAcceptableInput() || d->control->fixup())
1973 #ifdef QT3_SUPPORT
1974  emit lostFocus();
1975 #endif
1976  }
1977 #ifdef Q_WS_MAC
1978  if (d->control->echoMode() == Password || d->control->echoMode() == NoEcho)
1979  qt_mac_secure_keyboard(false);
1980 #endif
1981 #ifdef QT_KEYPAD_NAVIGATION
1982  d->control->setCancelText(QString());
1983 #endif
1984 #ifndef QT_NO_COMPLETER
1985  if (d->control->completer()) {
1986  QObject::disconnect(d->control->completer(), 0, this, 0);
1987  }
1988 #endif
1989  update();
1990 }
1991 
1995 {
1996  Q_D(QLineEdit);
1997  QPainter p(this);
1998 
1999  QRect r = rect();
2000  QPalette pal = palette();
2001 
2002  QStyleOptionFrameV2 panel;
2003  initStyleOption(&panel);
2004  style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this);
2005  r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this);
2006  r.setX(r.x() + d->leftTextMargin);
2007  r.setY(r.y() + d->topTextMargin);
2008  r.setRight(r.right() - d->rightTextMargin);
2009  r.setBottom(r.bottom() - d->bottomTextMargin);
2010  p.setClipRect(r);
2011 
2012  QFontMetrics fm = fontMetrics();
2013  Qt::Alignment va = QStyle::visualAlignment(d->control->layoutDirection(), QFlag(d->alignment));
2014  switch (va & Qt::AlignVertical_Mask) {
2015  case Qt::AlignBottom:
2016  d->vscroll = r.y() + r.height() - fm.height() - d->verticalMargin;
2017  break;
2018  case Qt::AlignTop:
2019  d->vscroll = r.y() + d->verticalMargin;
2020  break;
2021  default:
2022  //center
2023  d->vscroll = r.y() + (r.height() - fm.height() + 1) / 2;
2024  break;
2025  }
2026  QRect lineRect(r.x() + d->horizontalMargin, d->vscroll, r.width() - 2*d->horizontalMargin, fm.height());
2027 
2028  int minLB = qMax(0, -fm.minLeftBearing());
2029  int minRB = qMax(0, -fm.minRightBearing());
2030 
2031  if (d->control->text().isEmpty()) {
2032  if (!hasFocus() && !d->placeholderText.isEmpty()) {
2033  QColor col = pal.text().color();
2034  col.setAlpha(128);
2035  QPen oldpen = p.pen();
2036  p.setPen(col);
2037  lineRect.adjust(minLB, 0, 0, 0);
2038  QString elidedText = fm.elidedText(d->placeholderText, Qt::ElideRight, lineRect.width());
2039  p.drawText(lineRect, va, elidedText);
2040  p.setPen(oldpen);
2041  return;
2042  }
2043  }
2044 
2045  int cix = qRound(d->control->cursorToX());
2046 
2047  // horizontal scrolling. d->hscroll is the left indent from the beginning
2048  // of the text line to the left edge of lineRect. we update this value
2049  // depending on the delta from the last paint event; in effect this means
2050  // the below code handles all scrolling based on the textline (widthUsed,
2051  // minLB, minRB), the line edit rect (lineRect) and the cursor position
2052  // (cix).
2053  int widthUsed = qRound(d->control->naturalTextWidth()) + 1 + minRB;
2054  if ((minLB + widthUsed) <= lineRect.width()) {
2055  // text fits in lineRect; use hscroll for alignment
2056  switch (va & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) {
2057  case Qt::AlignRight:
2058  d->hscroll = widthUsed - lineRect.width() + 1;
2059  break;
2060  case Qt::AlignHCenter:
2061  d->hscroll = (widthUsed - lineRect.width()) / 2;
2062  break;
2063  default:
2064  // Left
2065  d->hscroll = 0;
2066  break;
2067  }
2068  d->hscroll -= minLB;
2069  } else if (cix - d->hscroll >= lineRect.width()) {
2070  // text doesn't fit, cursor is to the right of lineRect (scroll right)
2071  d->hscroll = cix - lineRect.width() + 1;
2072  } else if (cix - d->hscroll < 0 && d->hscroll < widthUsed) {
2073  // text doesn't fit, cursor is to the left of lineRect (scroll left)
2074  d->hscroll = cix;
2075  } else if (widthUsed - d->hscroll < lineRect.width()) {
2076  // text doesn't fit, text document is to the left of lineRect; align
2077  // right
2078  d->hscroll = widthUsed - lineRect.width() + 1;
2079  } else {
2080  //in case the text is bigger than the lineedit, the hscroll can never be negative
2081  d->hscroll = qMax(0, d->hscroll);
2082  }
2083 
2084  // the y offset is there to keep the baseline constant in case we have script changes in the text.
2085  QPoint topLeft = lineRect.topLeft() - QPoint(d->hscroll, d->control->ascent() - fm.ascent());
2086 
2087  // draw text, selections and cursors
2088 #ifndef QT_NO_STYLE_STYLESHEET
2089  if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style())) {
2090  cssStyle->styleSheetPalette(this, &panel, &pal);
2091  }
2092 #endif
2093  p.setPen(pal.text().color());
2094 
2095  int flags = QLineControl::DrawText;
2096 
2097 #ifdef QT_KEYPAD_NAVIGATION
2098  if (!QApplication::keypadNavigationEnabled() || hasEditFocus())
2099 #endif
2100  if (d->control->hasSelectedText() || (d->cursorVisible && !d->control->inputMask().isEmpty() && !d->control->isReadOnly())){
2102  // Palette only used for selections/mask and may not be in sync
2103  if (d->control->palette() != pal
2104  || d->control->palette().currentColorGroup() != pal.currentColorGroup())
2105  d->control->setPalette(pal);
2106  }
2107 
2108  // Asian users see an IM selection text as cursor on candidate
2109  // selection phase of input method, so the ordinary cursor should be
2110  // invisible if we have a preedit string.
2111  if (d->cursorVisible && !d->control->isReadOnly())
2112  flags |= QLineControl::DrawCursor;
2113 
2114  d->control->setCursorWidth(style()->pixelMetric(QStyle::PM_TextCursorWidth));
2115  d->control->draw(&p, topLeft, r, flags);
2116 
2117 }
2118 
2119 
2120 #ifndef QT_NO_DRAGANDDROP
2121 
2124 {
2125  Q_D(QLineEdit);
2126  if (!d->control->isReadOnly() && e->mimeData()->hasFormat(QLatin1String("text/plain"))) {
2127  e->acceptProposedAction();
2128  d->control->moveCursor(d->xToPos(e->pos().x()), false);
2129  d->cursorVisible = true;
2130  update();
2131  }
2132 }
2133 
2136 {
2138 }
2139 
2142 {
2143  Q_D(QLineEdit);
2144  if (d->cursorVisible) {
2145  d->cursorVisible = false;
2146  update();
2147  }
2148 }
2149 
2152 {
2153  Q_D(QLineEdit);
2154  QString str = e->mimeData()->text();
2155 
2156  if (!str.isNull() && !d->control->isReadOnly()) {
2157  if (e->source() == this && e->dropAction() == Qt::CopyAction)
2158  deselect();
2159  int cursorPos = d->xToPos(e->pos().x());
2160  int selStart = cursorPos;
2161  int oldSelStart = d->control->selectionStart();
2162  int oldSelEnd = d->control->selectionEnd();
2163  d->control->moveCursor(cursorPos, false);
2164  d->cursorVisible = false;
2165  e->acceptProposedAction();
2166  insert(str);
2167  if (e->source() == this) {
2168  if (e->dropAction() == Qt::MoveAction) {
2169  if (selStart > oldSelStart && selStart <= oldSelEnd)
2170  setSelection(oldSelStart, str.length());
2171  else if (selStart > oldSelEnd)
2172  setSelection(selStart - str.length(), str.length());
2173  else
2174  setSelection(selStart, str.length());
2175  } else {
2176  setSelection(selStart, str.length());
2177  }
2178  }
2179  } else {
2180  e->ignore();
2181  update();
2182  }
2183 }
2184 
2185 #endif // QT_NO_DRAGANDDROP
2186 
2187 #ifndef QT_NO_CONTEXTMENU
2188 
2206 {
2207  if (QMenu *menu = createStandardContextMenu()) {
2208  menu->setAttribute(Qt::WA_DeleteOnClose);
2209  menu->popup(event->globalPos());
2210  }
2211 }
2212 
2213 #if defined(Q_WS_WIN) || defined(Q_WS_X11)
2214  extern bool qt_use_rtl_extensions;
2215 #endif
2216 
2224 {
2225  Q_D(QLineEdit);
2226  QMenu *popup = new QMenu(this);
2227  popup->setObjectName(QLatin1String("qt_edit_menu"));
2228  QAction *action = 0;
2229 
2230  if (!isReadOnly()) {
2231  action = popup->addAction(QLineEdit::tr("&Undo") + ACCEL_KEY(QKeySequence::Undo));
2232  action->setEnabled(d->control->isUndoAvailable());
2233  connect(action, SIGNAL(triggered()), SLOT(undo()));
2234 
2235  action = popup->addAction(QLineEdit::tr("&Redo") + ACCEL_KEY(QKeySequence::Redo));
2236  action->setEnabled(d->control->isRedoAvailable());
2237  connect(action, SIGNAL(triggered()), SLOT(redo()));
2238 
2239  popup->addSeparator();
2240  }
2241 
2242 #ifndef QT_NO_CLIPBOARD
2243  if (!isReadOnly()) {
2244  action = popup->addAction(QLineEdit::tr("Cu&t") + ACCEL_KEY(QKeySequence::Cut));
2245  action->setEnabled(!d->control->isReadOnly() && d->control->hasSelectedText()
2246  && d->control->echoMode() == QLineEdit::Normal);
2247  connect(action, SIGNAL(triggered()), SLOT(cut()));
2248  }
2249 
2250  action = popup->addAction(QLineEdit::tr("&Copy") + ACCEL_KEY(QKeySequence::Copy));
2251  action->setEnabled(d->control->hasSelectedText()
2252  && d->control->echoMode() == QLineEdit::Normal);
2253  connect(action, SIGNAL(triggered()), SLOT(copy()));
2254 
2255  if (!isReadOnly()) {
2256  action = popup->addAction(QLineEdit::tr("&Paste") + ACCEL_KEY(QKeySequence::Paste));
2257  action->setEnabled(!d->control->isReadOnly() && !QApplication::clipboard()->text().isEmpty());
2258  connect(action, SIGNAL(triggered()), SLOT(paste()));
2259  }
2260 #endif
2261 
2262  if (!isReadOnly()) {
2263  action = popup->addAction(QLineEdit::tr("Delete"));
2264  action->setEnabled(!d->control->isReadOnly() && !d->control->text().isEmpty() && d->control->hasSelectedText());
2265  connect(action, SIGNAL(triggered()), d->control, SLOT(_q_deleteSelected()));
2266  }
2267 
2268  if (!popup->isEmpty())
2269  popup->addSeparator();
2270 
2271  action = popup->addAction(QLineEdit::tr("Select All") + ACCEL_KEY(QKeySequence::SelectAll));
2272  action->setEnabled(!d->control->text().isEmpty() && !d->control->allSelected());
2273  d->selectAllAction = action;
2274  connect(action, SIGNAL(triggered()), SLOT(selectAll()));
2275 
2276 #if !defined(QT_NO_IM)
2277  QInputContext *qic = inputContext();
2278  if (qic) {
2279  QList<QAction *> imActions = qic->actions();
2280  for (int i = 0; i < imActions.size(); ++i)
2281  popup->addAction(imActions.at(i));
2282  }
2283 #endif
2284 
2285 #if defined(Q_WS_WIN) || defined(Q_WS_X11)
2286  if (!d->control->isReadOnly() && qt_use_rtl_extensions) {
2287 #else
2288  if (!d->control->isReadOnly()) {
2289 #endif
2290  popup->addSeparator();
2291  QUnicodeControlCharacterMenu *ctrlCharacterMenu = new QUnicodeControlCharacterMenu(this, popup);
2292  popup->addMenu(ctrlCharacterMenu);
2293  }
2294  return popup;
2295 }
2296 #endif // QT_NO_CONTEXTMENU
2297 
2300 {
2301  Q_D(QLineEdit);
2302  switch(ev->type())
2303  {
2306  update();
2307  break;
2308  case QEvent::FontChange:
2309  d->control->setFont(font());
2310  break;
2311  case QEvent::StyleChange:
2312  {
2313  QStyleOptionFrameV2 opt;
2314  initStyleOption(&opt);
2315  d->control->setPasswordCharacter(style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, this));
2316  }
2317  update();
2318  break;
2319  default:
2320  break;
2321  }
2323 }
2324 
2500 
2501 #include "moc_qlineedit.cpp"
2502 
2503 #endif // QT_NO_LINEEDIT
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QPoint pos() const
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
void setReadOnly(bool)
Definition: qlineedit.cpp:1499
const QString & preeditString() const
Returns the preedit text, i.
Definition: qevent.h:455
void acceptProposedAction()
Sets the drop action to be the proposed action.
Definition: qevent.h:492
bool hasSelectedText() const
void undo()
Undoes the last operation if undo is available.
Definition: qlineedit.cpp:1456
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
void keyPressEvent(QKeyEvent *)
Converts the given key press event into a line edit action.
Definition: qlineedit.cpp:1764
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
int selectionStart() const
selectionStart() returns the index of the first selected character in the line edit or -1 if no text ...
Definition: qlineedit.cpp:1039
bool isRedoAvailable() const
Definition: qlineedit.cpp:1156
The QKeyEvent class describes a key event.
Definition: qevent.h:224
void changeEvent(QEvent *)
Reimplemented Function
Definition: qlineedit.cpp:2299
void setInputMethodHints(Qt::InputMethodHints hints)
Definition: qwidget.cpp:9736
void setTextMargins(int left, int top, int right, int bottom)
Sets the margins around the text inside the frame to have the sizes left, top, right, and bottom.
Definition: qlineedit.cpp:1259
void setAlignment(Qt::Alignment flag)
Definition: qlineedit.cpp:827
void setBottom(int pos)
Sets the bottom edge of the rectangle to the given y coordinate.
Definition: qrect.h:267
int cursorPositionAt(const QPoint &pos)
Returns the cursor position under the point pos.
Definition: qlineedit.cpp:768
void copy() const
Copies the selected text to the clipboard, if there is any, and if echoMode() is Normal ...
Definition: qlineedit.cpp:1541
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
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
QCursor cursor() const
int leading() const
Returns the leading of the font.
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
void resetInputContext()
This function can be called on the widget that currently has focus to reset the input method operatin...
Definition: qwidget.cpp:522
void cut()
Copies the selected text to the clipboard and deletes it, if there is any, and if echoMode() is Norma...
Definition: qlineedit.cpp:1525
void focusInEvent(QFocusEvent *)
em>Reimplemented Function
Definition: qlineedit.cpp:1900
int maxWidth() const
Returns the width of the widest character in the font.
bool isModified() const
Definition: qlineedit.cpp:968
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
The QFlag class is a helper data type for QFlags.
Definition: qglobal.h:2289
QRect contentsRect() const
Returns the area inside the widget&#39;s margins.
Definition: qwidget.cpp:7544
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition: qevent.h:396
static QSize globalStrut()
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void setCompleter(QCompleter *completer)
Sets this line edit to provide auto completions from the completer, c.
Definition: qlineedit.cpp:654
#define SLOT(a)
Definition: qobjectdefs.h:226
void qt_mac_secure_keyboard(bool)
void cursorWordBackward(bool mark)
Moves the cursor one word backward.
Definition: qlineedit.cpp:881
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void end(bool mark)
Moves the text cursor to the end of the line unless it is already there.
Definition: qlineedit.cpp:940
Qt::DropAction dropAction() const
Returns the action to be performed on the data by the target.
Definition: qevent.h:494
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
QMenu * createStandardContextMenu()
This function creates the standard context menu which is shown when the user clicks on the line edit ...
Definition: qlineedit.cpp:2223
void deselect()
Deselects any selected text.
Definition: qlineedit.cpp:1417
#define ACCEL_KEY(k)
Definition: qlineedit.cpp:82
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
The QCompleter class provides completions based on an item model.
Definition: qcompleter.h:64
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QSize minimumSizeHint() const
Returns a minimum size for the line edit.
Definition: qlineedit.cpp:725
static int cursorFlashTime()
void setPlaceholderText(const QString &)
Definition: qlineedit.cpp:430
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
void setY(int y)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:285
void paintEvent(QPaintEvent *)
em>Reimplemented Function
Definition: qlineedit.cpp:1994
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool hasFocus() const
Definition: qwidget.cpp:6583
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
Definition: qevent.h:530
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenu.cpp:1453
int minLeftBearing() const
Returns the minimum left bearing of the font.
void del()
If no text is selected, deletes the character to the right of the text cursor.
Definition: qlineedit.cpp:910
#define Q_D(Class)
Definition: qglobal.h:2482
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
void mouseMoveEvent(QMouseEvent *)
Reimplemented Function
Definition: qlineedit.cpp:1662
void dropEvent(QDropEvent *)
This event handler is called when the drag is dropped on this widget.
Definition: qlineedit.cpp:2151
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
virtual QList< QAction * > actions()
This is a preliminary interface for Qt 4.
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
QCompleter * completer() const
Returns the current QCompleter that provides completions.
Definition: qlineedit.cpp:686
void setLayoutDirection(Qt::LayoutDirection direction)
Definition: qwidget.cpp:5199
void cursorWordForward(bool mark)
Moves the cursor one word forward.
Definition: qlineedit.cpp:868
void setEnabled(bool)
Definition: qaction.cpp:1192
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags=0) const
If the string text is wider than width, returns an elided version of the string (i.
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
QStyle * style() const
Definition: qwidget.cpp:2742
int minRightBearing() const
Returns the minimum right bearing of the font.
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
ColorGroup currentColorGroup() const
Returns the palette&#39;s current color group.
Definition: qpalette.h:104
void mousePressEvent(QMouseEvent *)
Reimplemented Function
Definition: qlineedit.cpp:1625
int top() const
Returns the top margin.
Definition: qmargins.h:99
void cursorBackward(bool mark, int steps=1)
Moves the cursor back steps characters.
Definition: qlineedit.cpp:857
int ascent() const
Returns the ascent of the font.
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
void cursorForward(bool mark, int steps=1)
Moves the cursor forward steps characters.
Definition: qlineedit.cpp:843
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
int lineWidth
the line width for drawing the frame
Definition: qstyleoption.h:124
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position...
Definition: qpainter.cpp:6231
QString displayText() const
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
void inputMethodEvent(QInputMethodEvent *)
Reimplemented Function
Definition: qlineedit.cpp:1833
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QValidator class provides validation of input text.
Definition: qvalidator.h:60
bool isEmpty() const
Returns true if there are no visible actions inserted into the menu, false otherwise.
Definition: qmenu.cpp:1737
EchoMode
This enum type describes how a line edit should display its contents.
Definition: qlineedit.h:113
void setModified(bool)
Definition: qlineedit.cpp:974
bool isAccepted() const
Definition: qcoreevent.h:307
void setDragEnabled(bool b)
Definition: qlineedit.cpp:1179
QString selectedText() const
QString text() const
Returns a plain text (MIME type text/plain) representation of the data.
Definition: qmimedata.cpp:364
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
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189
void insert(const QString &)
Deletes any selected text, inserts newText, and validates the result.
Definition: qlineedit.cpp:1431
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
bool hasFrame() const
Definition: qlineedit.cpp:507
void backspace()
If no text is selected, deletes the character to the left of the text cursor and moves the cursor one...
Definition: qlineedit.cpp:896
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
void mouseDoubleClickEvent(QMouseEvent *)
Reimplemented Function
Definition: qlineedit.cpp:1715
void setSelection(int, int)
Selects text from position start and for length characters.
Definition: qlineedit.cpp:1106
void setRight(int pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:264
const QPalette & palette() const
static int startDragTime()
void setValidator(const QValidator *)
Sets this line edit to only accept input that the validator, v, will accept.
Definition: qlineedit.cpp:627
bool modified
whether the line edit&#39;s contents has been modified by the user
Definition: qlineedit.h:79
QFontMetrics fontMetrics() const
Returns the font metrics for the widget&#39;s current font.
Definition: qwidget.h:984
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
const char * styleHint(const QFontDef &request)
Q_CORE_EXPORT void qWarning(const char *,...)
void editingFinished()
This signal is emitted when the Return or Enter key is pressed or the line edit loses focus...
QAction * addSeparator()
This convenience function creates a new separator action, i.e.
Definition: qmenu.cpp:1583
The QStyleOptionFrame class is used to describe the parameters for drawing a frame.
Definition: qstyleoption.h:118
void dragMoveEvent(QDragMoveEvent *e)
em>Reimplemented Function
Definition: qlineedit.cpp:2123
void paste()
Inserts the clipboard&#39;s text at the cursor position, deleting any selected text, providing the line e...
Definition: qlineedit.cpp:1558
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
const QValidator * validator() const
Returns a pointer to the current input validator, or 0 if no validator has been set.
Definition: qlineedit.cpp:609
The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leav...
Definition: qevent.h:577
static int startDragDistance()
void mouseReleaseEvent(QMouseEvent *)
Reimplemented Function
Definition: qlineedit.cpp:1683
QSize sizeHint() const
Returns a recommended size for the widget.
Definition: qlineedit.cpp:701
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
void setX(int x)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:282
QRect rect() const
QInputContext * inputContext()
This function returns the QInputContext for this widget.
Definition: qwidget.cpp:474
bool isEqual(ColorGroup cr1, ColorGroup cr2) const
Returns true (usually quickly) if color group cg1 is equal to cg2; otherwise returns false...
Definition: qpalette.cpp:1035
void contextMenuEvent(QContextMenuEvent *)
Shows the standard context menu created with createStandardContextMenu().
Definition: qlineedit.cpp:2205
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
void setText(const QString &)
Definition: qlineedit.cpp:401
InputMethodQuery
Definition: qnamespace.h:1541
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
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
virtual bool hasFormat(const QString &mimetype) const
Returns true if the object can return data for the MIME type specified by mimeType; otherwise returns...
Definition: qmimedata.cpp:563
static Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
Transforms an alignment of Qt::AlignLeft or Qt::AlignRight without Qt::AlignAbsolute into Qt::AlignLe...
Definition: qstyle.cpp:2149
void home(bool mark)
Moves the text cursor to the beginning of the line unless it is already there.
Definition: qlineedit.cpp:925
virtual QRect subElementRect(SubElement subElement, const QStyleOption *option, const QWidget *widget=0) const =0
Returns the sub-area for the given element as described in the provided style option.
The QDropEvent class provides an event which is sent when a drag and drop action is completed...
Definition: qevent.h:476
static QWidget * activePopupWidget()
Returns the active popup widget.
bool isReadOnly() const
Definition: qlineedit.cpp:1493
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
int x() const
Qt::LayoutDirection layoutDirection() const
FocusReason
Definition: qnamespace.h:1521
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
void clear()
Clears the contents of the line edit.
Definition: qlineedit.cpp:1443
bool qt_use_rtl_extensions
void setInputMask(const QString &inputMask)
Definition: qlineedit.cpp:1390
CursorMoveStyle
This enum describes the movement style available to text cursors.
Definition: qnamespace.h:1790
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
QString text() const
Returns the Unicode text that this key generated.
Definition: qevent.h:236
int midLineWidth
the mid-line width for drawing the frame
Definition: qstyleoption.h:125
void setWidget(QWidget *widget)
Sets the widget for which completion are provided for to widget.
Definition: qcompleter.cpp:989
void focusOutEvent(QFocusEvent *)
em>Reimplemented Function
Definition: qlineedit.cpp:1949
QWidget * source() const
If the source of the drag operation is a widget in this application, this function returns that sourc...
Definition: qevent.cpp:2739
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QDragEnterEvent class provides an event which is sent to a widget when a drag and drop action ent...
Definition: qevent.h:555
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
bool singleShot
This static function calls a slot after a given time interval.
Definition: qtimer.h:59
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void setAlpha(int alpha)
Sets the alpha of this color to alpha.
Definition: qcolor.cpp:1094
QString inputMask() const
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
void setMaxLength(int)
Definition: qlineedit.cpp:491
QAction * addMenu(QMenu *menu)
This convenience function adds menu as a submenu to this menu.
Definition: qmenu.cpp:1541
Qt::FocusReason reason()
Definition: qevent.cpp:1197
void initStyleOption(QStyleOptionFrame *option) const
Initialize option with the values from this QLineEdit.
Definition: qlineedit.cpp:104
The QStyleOptionFrameV2 class is used to describe the parameters necessary for drawing a frame in Qt ...
Definition: qstyleoption.h:134
int maxLength() const
QLineEdit(QWidget *parent=0)
Constructs a line edit with no text.
Definition: qlineedit.cpp:280
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
~QLineEdit()
Destroys the line edit.
Definition: qlineedit.cpp:372
void setFrame(bool)
Definition: qlineedit.cpp:514
int left() const
Returns the left margin.
Definition: qmargins.h:96
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void setEchoMode(EchoMode)
Definition: qlineedit.cpp:575
const QFont & font() const
const QMimeData * mimeData() const
Returns the data that was dropped on the widget and its associated MIME type information.
Definition: qevent.h:498
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void redo()
Redoes the last operation if redo is available.
Definition: qlineedit.cpp:1467
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
const QPoint & globalPos() const
Returns the global position of the mouse pointer at the time of the event.
Definition: qevent.h:413
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372
void setCursorPosition(int)
Definition: qlineedit.cpp:758
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
void selectAll()
Selects all the text (i.e.
Definition: qlineedit.cpp:1405
The QInputContext class abstracts the input method dependent data and composing state.
Definition: qinputcontext.h:83
The QMargins class defines the four margins of a rectangle.
Definition: qmargins.h:53
int height() const
Returns the height of the font.
QRect cursorRect() const
Returns a rectangle that includes the lineedit cursor.
Definition: qlineedit.cpp:1825
QString placeholderText() const
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition: qevent.h:79
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
QVariant inputMethodQuery(Qt::InputMethodQuery) const
em>Reimplemented Function
Definition: qlineedit.cpp:1869
int cursorPosition() const
bool event(QEvent *)
Reimplemented Function
Definition: qlineedit.cpp:1568
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Qt::InputMethodHints inputMethodHints() const
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
Qt::Alignment alignment() const
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
static int doubleClickInterval()
int bottom() const
Returns the bottom margin.
Definition: qmargins.h:105
void dragLeaveEvent(QDragLeaveEvent *e)
em>Reimplemented Function
Definition: qlineedit.cpp:2141
bool hasAcceptableInput() const
Definition: qlineedit.cpp:1246
EchoMode echoMode() const
bool isUndoAvailable() const
Definition: qlineedit.cpp:1137
void setCursorMoveStyle(Qt::CursorMoveStyle style)
Sets the movement style for the cursor in the line edit to the given style.
Definition: qlineedit.cpp:1228
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
int right() const
Returns the right margin.
Definition: qmargins.h:102
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QMargins textMargins() const
Returns the widget&#39;s text margins.
Definition: qlineedit.cpp:1312
QWidget * widget() const
Returns the widget for which the completer object is providing completions.
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
void getTextMargins(int *left, int *top, int *right, int *bottom) const
Returns the widget&#39;s text margins for left, top, right, and bottom.
Definition: qlineedit.cpp:1290
void dragEnterEvent(QDragEnterEvent *)
em>Reimplemented Function
Definition: qlineedit.cpp:2135
const QPoint & pos() const
Returns the position where the drop was made.
Definition: qevent.h:486
const QBrush & text() const
Returns the text foreground brush of the current color group.
Definition: qpalette.h:129
bool dragEnabled() const
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
Qt::CursorMoveStyle cursorMoveStyle() const
QString text() const
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61