Changeset 846 for trunk/src/gui/widgets/qlinecontrol_p.h
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/widgets/qlinecontrol_p.h
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 79 79 public: 80 80 QLineControl(const QString &txt = QString()) 81 : m_cursor(0), m_preeditCursor(0), m_cursorWidth(0), m_layoutDirection(Qt::L eftToRight),81 : m_cursor(0), m_preeditCursor(0), m_cursorWidth(0), m_layoutDirection(Qt::LayoutDirectionAuto), 82 82 m_hideCursor(false), m_separator(0), m_readOnly(0), 83 83 m_dragEnabled(0), m_echoMode(0), m_textDirty(0), m_selDirty(0), … … 95 95 } 96 96 97 int nextMaskBlank(int pos); 98 int prevMaskBlank(int pos); 99 100 bool isUndoAvailable() const; 101 bool isRedoAvailable() const; 102 void clearUndo(); 103 bool isModified() const; 104 void setModified(bool modified); 105 106 bool allSelected() const; 107 bool hasSelectedText() const; 108 109 int width() const; 110 int height() const; 111 int ascent() const; 112 qreal naturalTextWidth() const; 97 int nextMaskBlank(int pos) 98 { 99 int c = findInMask(pos, true, false); 100 m_separator |= (c != pos); 101 return (c != -1 ? c : m_maxLength); 102 } 103 104 int prevMaskBlank(int pos) 105 { 106 int c = findInMask(pos, false, false); 107 m_separator |= (c != pos); 108 return (c != -1 ? c : 0); 109 } 110 111 bool isUndoAvailable() const { return !m_readOnly && m_undoState; } 112 bool isRedoAvailable() const { return !m_readOnly && m_undoState < (int)m_history.size(); } 113 void clearUndo() { m_history.clear(); m_modifiedState = m_undoState = 0; } 114 115 bool isModified() const { return m_modifiedState != m_undoState; } 116 void setModified(bool modified) { m_modifiedState = modified ? -1 : m_undoState; } 117 118 bool allSelected() const { return !m_text.isEmpty() && m_selstart == 0 && m_selend == (int)m_text.length(); } 119 bool hasSelectedText() const { return !m_text.isEmpty() && m_selend > m_selstart; } 120 121 int width() const { return qRound(m_textLayout.lineAt(0).width()) + 1; } 122 int height() const { return qRound(m_textLayout.lineAt(0).height()) + 1; } 123 int ascent() const { return m_ascent; } 124 qreal naturalTextWidth() const { return m_textLayout.lineAt(0).naturalTextWidth(); } 113 125 114 126 void setSelection(int start, int length); 115 127 116 QString selectedText() const; 117 QString textBeforeSelection() const; 118 QString textAfterSelection() const; 119 120 int selectionStart() const; 121 int selectionEnd() const; 122 bool inSelection(int x) const; 123 124 void removeSelection(); 125 126 int start() const; 127 int end() const; 128 inline QString selectedText() const { return hasSelectedText() ? m_text.mid(m_selstart, m_selend - m_selstart) : QString(); } 129 QString textBeforeSelection() const { return hasSelectedText() ? m_text.left(m_selstart) : QString(); } 130 QString textAfterSelection() const { return hasSelectedText() ? m_text.mid(m_selend) : QString(); } 131 132 int selectionStart() const { return hasSelectedText() ? m_selstart : -1; } 133 int selectionEnd() const { return hasSelectedText() ? m_selend : -1; } 134 bool inSelection(int x) const 135 { 136 if (m_selstart >= m_selend) 137 return false; 138 int pos = xToPos(x, QTextLine::CursorOnCharacter); 139 return pos >= m_selstart && pos < m_selend; 140 } 141 142 void removeSelection() 143 { 144 int priorState = m_undoState; 145 removeSelectedText(); 146 finishChange(priorState); 147 } 148 149 int start() const { return 0; } 150 int end() const { return m_text.length(); } 128 151 129 152 #ifndef QT_NO_CLIPBOARD 130 153 void copy(QClipboard::Mode mode = QClipboard::Clipboard) const; 131 void paste(); 132 #endif 133 134 int cursor() const; 135 int preeditCursor() const; 136 137 int cursorWidth() const; 138 void setCursorWidth(int value); 154 void paste(QClipboard::Mode mode = QClipboard::Clipboard); 155 #endif 156 157 int cursor() const{ return m_cursor; } 158 int preeditCursor() const { return m_preeditCursor; } 159 160 int cursorWidth() const { return m_cursorWidth; } 161 void setCursorWidth(int value) { m_cursorWidth = value; } 162 139 163 140 164 void moveCursor(int pos, bool mark = false); 141 void cursorForward(bool mark, int steps); 142 void cursorWordForward(bool mark); 143 void cursorWordBackward(bool mark); 144 void home(bool mark); 145 void end(bool mark); 165 void cursorForward(bool mark, int steps) 166 { 167 int c = m_cursor; 168 if (steps > 0) { 169 while (steps--) 170 c = m_textLayout.nextCursorPosition(c); 171 } else if (steps < 0) { 172 while (steps++) 173 c = m_textLayout.previousCursorPosition(c); 174 } 175 moveCursor(c, mark); 176 } 177 178 void cursorWordForward(bool mark) { moveCursor(m_textLayout.nextCursorPosition(m_cursor, QTextLayout::SkipWords), mark); } 179 void cursorWordBackward(bool mark) { moveCursor(m_textLayout.previousCursorPosition(m_cursor, QTextLayout::SkipWords), mark); } 180 181 void home(bool mark) { moveCursor(0, mark); } 182 void end(bool mark) { moveCursor(text().length(), mark); } 146 183 147 184 int xToPos(int x, QTextLine::CursorPosition = QTextLine::CursorBetweenCharacters) const; 148 185 QRect cursorRect() const; 149 186 150 qreal cursorToX(int cursor) const; 151 qreal cursorToX() const; 152 153 bool isReadOnly() const; 154 void setReadOnly(bool enable); 155 156 QString text() const; 157 void setText(const QString &txt); 158 159 QString displayText() const; 187 qreal cursorToX(int cursor) const { return m_textLayout.lineAt(0).cursorToX(cursor); } 188 qreal cursorToX() const 189 { 190 int cursor = m_cursor; 191 if (m_preeditCursor != -1) 192 cursor += m_preeditCursor; 193 return cursorToX(cursor); 194 } 195 196 bool isReadOnly() const { return m_readOnly; } 197 void setReadOnly(bool enable) { m_readOnly = enable; } 198 199 QString text() const 200 { 201 QString res = m_maskData ? stripString(m_text) : m_text; 202 return (res.isNull() ? QString::fromLatin1("") : res); 203 } 204 void setText(const QString &txt) { internalSetText(txt, -1, false); } 205 QString displayText() const { return m_textLayout.text(); } 160 206 161 207 void backspace(); 162 208 void del(); 163 void deselect(); 164 void selectAll(); 209 void deselect() { internalDeselect(); finishChange(); } 210 void selectAll() { m_selstart = m_selend = m_cursor = 0; moveCursor(m_text.length(), true); } 211 165 212 void insert(const QString &); 166 213 void clear(); 167 void undo() ;168 void redo() ;214 void undo() { internalUndo(); finishChange(-1, true); } 215 void redo() { internalRedo(); finishChange(); } 169 216 void selectWordAtPos(int); 170 217 171 uint echoMode() const; 172 void setEchoMode(uint mode); 173 174 void setMaxLength(int maxLength); 175 int maxLength() const; 218 uint echoMode() const { return m_echoMode; } 219 void setEchoMode(uint mode) 220 { 221 m_echoMode = mode; 222 m_passwordEchoEditing = false; 223 updateDisplayText(); 224 } 225 226 int maxLength() const { return m_maxLength; } 227 void setMaxLength(int maxLength) 228 { 229 if (m_maskData) 230 return; 231 m_maxLength = maxLength; 232 setText(m_text); 233 } 176 234 177 235 #ifndef QT_NO_VALIDATOR 178 const QValidator *validator() const ;179 void setValidator(const QValidator * );236 const QValidator *validator() const { return m_validator; } 237 void setValidator(const QValidator *v) { m_validator = const_cast<QValidator*>(v); } 180 238 #endif 181 239 182 240 #ifndef QT_NO_COMPLETER 183 QCompleter *completer() const; 184 void setCompleter(const QCompleter*); 241 QCompleter *completer() const { return m_completer; } 242 /* Note that you must set the widget for the completer separately */ 243 void setCompleter(const QCompleter *c) { m_completer = const_cast<QCompleter*>(c); } 185 244 void complete(int key); 186 245 #endif 187 246 188 void setCursorPosition(int pos);189 int cursorPosition() const;190 191 bool hasAcceptableInput() const ;247 int cursorPosition() const { return m_cursor; } 248 void setCursorPosition(int pos) { if (pos <= m_text.length()) moveCursor(qMax(0, pos)); } 249 250 bool hasAcceptableInput() const { return hasAcceptableInput(m_text); } 192 251 bool fixup(); 193 252 194 QString inputMask() const; 195 void setInputMask(const QString &mask); 253 QString inputMask() const { return m_maskData ? m_inputMask + QLatin1Char(';') + m_blank : QString(); } 254 void setInputMask(const QString &mask) 255 { 256 parseInputMask(mask); 257 if (m_maskData) 258 moveCursor(nextMaskBlank(0)); 259 } 196 260 197 261 // input methods 198 262 #ifndef QT_NO_IM 199 bool composeMode() const ;200 void setPreeditArea(int cursor, const QString &text) ;201 #endif 202 203 QString preeditAreaText() const ;263 bool composeMode() const { return !m_textLayout.preeditAreaText().isEmpty(); } 264 void setPreeditArea(int cursor, const QString &text) { m_textLayout.setPreeditArea(cursor, text); } 265 #endif 266 267 QString preeditAreaText() const { return m_textLayout.preeditAreaText(); } 204 268 205 269 void updatePasswordEchoEditing(bool editing); 206 bool passwordEchoEditing() const; 207 208 QChar passwordCharacter() const; 209 void setPasswordCharacter(const QChar &character); 210 211 Qt::LayoutDirection layoutDirection() const; 212 void setLayoutDirection(Qt::LayoutDirection direction); 213 void setFont(const QFont &font); 270 bool passwordEchoEditing() const { return m_passwordEchoEditing; } 271 272 QChar passwordCharacter() const { return m_passwordCharacter; } 273 void setPasswordCharacter(const QChar &character) { m_passwordCharacter = character; updateDisplayText(); } 274 275 Qt::LayoutDirection layoutDirection() const { 276 if (m_layoutDirection == Qt::LayoutDirectionAuto) { 277 if (m_text.isEmpty()) 278 return QApplication::keyboardInputDirection(); 279 return m_text.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight; 280 } 281 return m_layoutDirection; 282 } 283 void setLayoutDirection(Qt::LayoutDirection direction) 284 { 285 if (direction != m_layoutDirection) { 286 m_layoutDirection = direction; 287 updateDisplayText(); 288 } 289 } 290 291 void setFont(const QFont &font) { m_textLayout.setFont(font); updateDisplayText(); } 214 292 215 293 void processInputMethodEvent(QInputMethodEvent *event); … … 217 295 void processKeyEvent(QKeyEvent* ev); 218 296 219 int cursorBlinkPeriod() const ;297 int cursorBlinkPeriod() const { return m_blinkPeriod; } 220 298 void setCursorBlinkPeriod(int msec); 221 222 QString cancelText() const; 223 void setCancelText(const QString &text); 224 225 const QPalette &palette() const; 226 void setPalette(const QPalette &); 299 void resetCursorBlinkTimer(); 300 301 QString cancelText() const { return m_cancelText; } 302 void setCancelText(const QString &text) { m_cancelText = text; } 303 304 const QPalette &palette() const { return m_palette; } 305 void setPalette(const QPalette &p) { m_palette = p; } 227 306 228 307 enum DrawFlags { … … 364 443 }; 365 444 366 inline int QLineControl::nextMaskBlank(int pos)367 {368 int c = findInMask(pos, true, false);369 m_separator |= (c != pos);370 return (c != -1 ? c : m_maxLength);371 }372 373 inline int QLineControl::prevMaskBlank(int pos)374 {375 int c = findInMask(pos, false, false);376 m_separator |= (c != pos);377 return (c != -1 ? c : 0);378 }379 380 inline bool QLineControl::isUndoAvailable() const381 {382 return !m_readOnly && m_undoState;383 }384 385 inline bool QLineControl::isRedoAvailable() const386 {387 return !m_readOnly && m_undoState < (int)m_history.size();388 }389 390 inline void QLineControl::clearUndo()391 {392 m_history.clear();393 m_modifiedState = m_undoState = 0;394 }395 396 inline bool QLineControl::isModified() const397 {398 return m_modifiedState != m_undoState;399 }400 401 inline void QLineControl::setModified(bool modified)402 {403 m_modifiedState = modified ? -1 : m_undoState;404 }405 406 inline bool QLineControl::allSelected() const407 {408 return !m_text.isEmpty() && m_selstart == 0 && m_selend == (int)m_text.length();409 }410 411 inline bool QLineControl::hasSelectedText() const412 {413 return !m_text.isEmpty() && m_selend > m_selstart;414 }415 416 inline int QLineControl::width() const417 {418 return qRound(m_textLayout.lineAt(0).width()) + 1;419 }420 421 inline qreal QLineControl::naturalTextWidth() const422 {423 return m_textLayout.lineAt(0).naturalTextWidth();424 }425 426 inline int QLineControl::height() const427 {428 return qRound(m_textLayout.lineAt(0).height()) + 1;429 }430 431 inline int QLineControl::ascent() const432 {433 return m_ascent;434 }435 436 inline QString QLineControl::selectedText() const437 {438 if (hasSelectedText())439 return m_text.mid(m_selstart, m_selend - m_selstart);440 return QString();441 }442 443 inline QString QLineControl::textBeforeSelection() const444 {445 if (hasSelectedText())446 return m_text.left(m_selstart);447 return QString();448 }449 450 inline QString QLineControl::textAfterSelection() const451 {452 if (hasSelectedText())453 return m_text.mid(m_selend);454 return QString();455 }456 457 inline int QLineControl::selectionStart() const458 {459 return hasSelectedText() ? m_selstart : -1;460 }461 462 inline int QLineControl::selectionEnd() const463 {464 return hasSelectedText() ? m_selend : -1;465 }466 467 inline int QLineControl::start() const468 {469 return 0;470 }471 472 inline int QLineControl::end() const473 {474 return m_text.length();475 }476 477 inline void QLineControl::removeSelection()478 {479 int priorState = m_undoState;480 removeSelectedText();481 finishChange(priorState);482 }483 484 inline bool QLineControl::inSelection(int x) const485 {486 if (m_selstart >= m_selend)487 return false;488 int pos = xToPos(x, QTextLine::CursorOnCharacter);489 return pos >= m_selstart && pos < m_selend;490 }491 492 inline int QLineControl::cursor() const493 {494 return m_cursor;495 }496 497 inline int QLineControl::preeditCursor() const498 {499 return m_preeditCursor;500 }501 502 inline int QLineControl::cursorWidth() const503 {504 return m_cursorWidth;505 }506 507 inline void QLineControl::setCursorWidth(int value)508 {509 m_cursorWidth = value;510 }511 512 inline void QLineControl::cursorForward(bool mark, int steps)513 {514 int c = m_cursor;515 if (steps > 0) {516 while (steps--)517 c = m_textLayout.nextCursorPosition(c);518 } else if (steps < 0) {519 while (steps++)520 c = m_textLayout.previousCursorPosition(c);521 }522 moveCursor(c, mark);523 }524 525 inline void QLineControl::cursorWordForward(bool mark)526 {527 moveCursor(m_textLayout.nextCursorPosition(m_cursor, QTextLayout::SkipWords), mark);528 }529 530 inline void QLineControl::home(bool mark)531 {532 moveCursor(0, mark);533 }534 535 inline void QLineControl::end(bool mark)536 {537 moveCursor(text().length(), mark);538 }539 540 inline void QLineControl::cursorWordBackward(bool mark)541 {542 moveCursor(m_textLayout.previousCursorPosition(m_cursor, QTextLayout::SkipWords), mark);543 }544 545 inline qreal QLineControl::cursorToX(int cursor) const546 {547 return m_textLayout.lineAt(0).cursorToX(cursor);548 }549 550 inline qreal QLineControl::cursorToX() const551 {552 int cursor = m_cursor;553 if (m_preeditCursor != -1)554 cursor += m_preeditCursor;555 return cursorToX(cursor);556 }557 558 inline bool QLineControl::isReadOnly() const559 {560 return m_readOnly;561 }562 563 inline void QLineControl::setReadOnly(bool enable)564 {565 m_readOnly = enable;566 }567 568 inline QString QLineControl::text() const569 {570 QString res = m_maskData ? stripString(m_text) : m_text;571 return (res.isNull() ? QString::fromLatin1("") : res);572 }573 574 inline void QLineControl::setText(const QString &txt)575 {576 internalSetText(txt, -1, false);577 }578 579 inline QString QLineControl::displayText() const580 {581 return m_textLayout.text();582 }583 584 inline void QLineControl::deselect()585 {586 internalDeselect();587 finishChange();588 }589 590 inline void QLineControl::selectAll()591 {592 m_selstart = m_selend = m_cursor = 0;593 moveCursor(m_text.length(), true);594 }595 596 inline void QLineControl::undo()597 {598 internalUndo();599 finishChange(-1, true);600 }601 602 inline void QLineControl::redo()603 {604 internalRedo();605 finishChange();606 }607 608 inline uint QLineControl::echoMode() const609 {610 return m_echoMode;611 }612 613 inline void QLineControl::setEchoMode(uint mode)614 {615 m_echoMode = mode;616 m_passwordEchoEditing = false;617 updateDisplayText();618 }619 620 inline void QLineControl::setMaxLength(int maxLength)621 {622 if (m_maskData)623 return;624 m_maxLength = maxLength;625 setText(m_text);626 }627 628 inline int QLineControl::maxLength() const629 {630 return m_maxLength;631 }632 633 #ifndef QT_NO_VALIDATOR634 inline const QValidator *QLineControl::validator() const635 {636 return m_validator;637 }638 639 inline void QLineControl::setValidator(const QValidator *v)640 {641 m_validator = const_cast<QValidator*>(v);642 }643 #endif644 645 #ifndef QT_NO_COMPLETER646 inline QCompleter *QLineControl::completer() const647 {648 return m_completer;649 }650 651 /* Note that you must set the widget for the completer seperately */652 inline void QLineControl::setCompleter(const QCompleter* c)653 {654 m_completer = const_cast<QCompleter*>(c);655 }656 #endif657 658 inline void QLineControl::setCursorPosition(int pos)659 {660 if (pos < 0)661 pos = 0;662 if (pos <= m_text.length())663 moveCursor(pos);664 }665 666 inline int QLineControl::cursorPosition() const667 {668 return m_cursor;669 }670 671 inline bool QLineControl::hasAcceptableInput() const672 {673 return hasAcceptableInput(m_text);674 }675 676 inline QString QLineControl::inputMask() const677 {678 return m_maskData ? m_inputMask + QLatin1Char(';') + m_blank : QString();679 }680 681 inline void QLineControl::setInputMask(const QString &mask)682 {683 parseInputMask(mask);684 if (m_maskData)685 moveCursor(nextMaskBlank(0));686 }687 688 // input methods689 #ifndef QT_NO_IM690 inline bool QLineControl::composeMode() const691 {692 return !m_textLayout.preeditAreaText().isEmpty();693 }694 695 inline void QLineControl::setPreeditArea(int cursor, const QString &text)696 {697 m_textLayout.setPreeditArea(cursor, text);698 }699 #endif700 701 inline QString QLineControl::preeditAreaText() const702 {703 return m_textLayout.preeditAreaText();704 }705 706 inline bool QLineControl::passwordEchoEditing() const707 {708 return m_passwordEchoEditing;709 }710 711 inline QChar QLineControl::passwordCharacter() const712 {713 return m_passwordCharacter;714 }715 716 inline void QLineControl::setPasswordCharacter(const QChar &character)717 {718 m_passwordCharacter = character;719 updateDisplayText();720 }721 722 inline Qt::LayoutDirection QLineControl::layoutDirection() const723 {724 return m_layoutDirection;725 }726 727 inline void QLineControl::setLayoutDirection(Qt::LayoutDirection direction)728 {729 if (direction != m_layoutDirection) {730 m_layoutDirection = direction;731 updateDisplayText();732 }733 }734 735 inline void QLineControl::setFont(const QFont &font)736 {737 m_textLayout.setFont(font);738 updateDisplayText();739 }740 741 inline int QLineControl::cursorBlinkPeriod() const742 {743 return m_blinkPeriod;744 }745 746 inline QString QLineControl::cancelText() const747 {748 return m_cancelText;749 }750 751 inline void QLineControl::setCancelText(const QString &text)752 {753 m_cancelText = text;754 }755 756 inline const QPalette & QLineControl::palette() const757 {758 return m_palette;759 }760 761 inline void QLineControl::setPalette(const QPalette &p)762 {763 m_palette = p;764 }765 766 445 QT_END_NAMESPACE 767 446
Note:
See TracChangeset
for help on using the changeset viewer.