From: Andrew den Exter Date: Mon, 20 Feb 2012 07:18:20 +0000 (+1000) Subject: Reduce the size of QQuickTextInputPrivate. X-Git-Tag: qt-v5.0.0-alpha1~342 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d70b27dd681f5f7715e6b30c4e4857d60b583236;p=profile%2Fivi%2Fqtdeclarative.git Reduce the size of QQuickTextInputPrivate. Remove some redundant or obsolete member and reorder members to minimise padding for alignment. Change-Id: I2660007baa07bea076e9ad307061af87c07e37cf Reviewed-by: Yann Bodson --- diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index bcdef31..9b11e2e 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -330,7 +330,7 @@ void QQuickTextInput::setColor(const QColor &c) d->textLayoutDirty = true; d->updateType = QQuickTextInputPrivate::UpdatePaintNode; update(); - emit colorChanged(c); + emit colorChanged(); } } @@ -353,13 +353,12 @@ void QQuickTextInput::setSelectionColor(const QColor &color) return; d->selectionColor = color; - d->m_palette.setColor(QPalette::Highlight, d->selectionColor); if (d->hasSelectedText()) { d->textLayoutDirty = true; d->updateType = QQuickTextInputPrivate::UpdatePaintNode; update(); } - emit selectionColorChanged(color); + emit selectionColorChanged(); } /*! \qmlproperty color QtQuick2::TextInput::selectedTextColor @@ -379,13 +378,12 @@ void QQuickTextInput::setSelectedTextColor(const QColor &color) return; d->selectedTextColor = color; - d->m_palette.setColor(QPalette::HighlightedText, d->selectedTextColor); if (d->hasSelectedText()) { d->textLayoutDirty = true; d->updateType = QQuickTextInputPrivate::UpdatePaintNode; update(); } - emit selectedTextColorChanged(color); + emit selectedTextColorChanged(); } /*! @@ -694,7 +692,7 @@ QRect QQuickTextInput::cursorRectangle() const return QRect( qRound(l.cursorToX(c) - d->hscroll), qRound(l.y() - d->vscroll), - d->m_cursorWidth, + 1, qCeil(l.height())); } @@ -1100,9 +1098,8 @@ bool QQuickTextInput::hasAcceptableInput() const state. */ -void QQuickTextInputPrivate::updateInputMethodHints() +Qt::InputMethodHints QQuickTextInputPrivate::effectiveInputMethodHints() const { - Q_Q(QQuickTextInput); Qt::InputMethodHints hints = inputMethodHints; if (m_echoMode == QQuickTextInput::Password || m_echoMode == QQuickTextInput::NoEcho) hints |= Qt::ImhHiddenText; @@ -1110,8 +1107,7 @@ void QQuickTextInputPrivate::updateInputMethodHints() hints &= ~Qt::ImhHiddenText; if (m_echoMode != QQuickTextInput::Normal) hints |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData); - effectiveInputMethodHints = hints; - q->updateInputMethod(Qt::ImHints); + return hints; } /*! \qmlproperty enumeration QtQuick2::TextInput::echoMode @@ -1139,7 +1135,7 @@ void QQuickTextInput::setEchoMode(QQuickTextInput::EchoMode echo) d->cancelPasswordEchoTimer(); d->m_echoMode = echo; d->m_passwordEchoEditing = false; - d->updateInputMethodHints(); + updateInputMethod(Qt::ImHints); d->updateDisplayText(); updateCursorRectangle(); @@ -1205,7 +1201,7 @@ void QQuickTextInput::setInputMethodHints(Qt::InputMethodHints hints) return; d->inputMethodHints = hints; - d->updateInputMethodHints(); + updateInputMethod(Qt::ImHints); emit inputMethodHintsChanged(); } @@ -1238,6 +1234,7 @@ void QQuickTextInput::setCursorDelegate(QDeclarativeComponent* c) if (!c) { //note that the components are owned by something else delete d->cursorItem; + d->cursorItem = 0; } else { d->startCreatingCursor(); } @@ -1309,7 +1306,7 @@ QRectF QQuickTextInput::positionToRectangle(int pos) const pos += d->preeditAreaText().length(); QTextLine l = d->m_textLayout.lineForTextPosition(pos); return l.isValid() - ? QRectF(l.cursorToX(pos) - d->hscroll, l.y() - d->vscroll, d->m_cursorWidth, l.height()) + ? QRectF(l.cursorToX(pos) - d->hscroll, l.y() - d->vscroll, 1, l.height()) : QRectF(); } @@ -1461,7 +1458,7 @@ void QQuickTextInput::mousePressEvent(QMouseEvent *event) if (d->selectByMouse) { setKeepMouseGrab(false); d->selectPressed = true; - QPoint distanceVector = d->pressPos.toPoint() - d->tripleClickStartPoint; + QPointF distanceVector = d->pressPos - d->tripleClickStartPoint; if (d->hasPendingTripleClick() && distanceVector.manhattanLength() < qApp->styleHints()->startDragDistance()) { event->setAccepted(true); @@ -1746,10 +1743,10 @@ QSGNode *QQuickTextInput::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData node->setMatrix(QMatrix4x4()); QPoint offset = QPoint(0,0); - QFontMetrics fm = QFontMetrics(d->font); - if (d->autoScroll) { + if (d->autoScroll && d->m_textLayout.lineCount() > 0) { + QFontMetrics fm = QFontMetrics(d->font); // the y offset is there to keep the baseline constant in case we have script changes in the text. - offset = -QPoint(d->hscroll, d->vscroll + d->m_ascent - fm.ascent()); + offset = -QPoint(d->hscroll, d->vscroll + qRound(d->m_textLayout.lineAt(0).ascent()) - fm.ascent()); } else { offset = -QPoint(d->hscroll, d->vscroll); } @@ -1785,7 +1782,7 @@ QVariant QQuickTextInput::inputMethodQuery(Qt::InputMethodQuery property) const case Qt::ImEnabled: return QVariant((bool)(flags() & ItemAcceptsInputMethod)); case Qt::ImHints: - return QVariant((int) d->effectiveInputMethodHints); + return QVariant((int) d->effectiveInputMethodHints()); case Qt::ImCursorRectangle: return cursorRectangle(); case Qt::ImFont: @@ -2480,7 +2477,6 @@ void QQuickTextInput::itemChange(ItemChange change, const ItemChangeData &value) Q_D(QQuickTextInput); if (change == ItemActiveFocusHasChanged) { bool hasFocus = value.boolValue; - d->focused = hasFocus; setCursorVisible(hasFocus); // ### refactor: && d->canvas && d->canvas->hasFocus() #ifdef QT_GUI_PASSWORD_ECHO_DELAY if (!hasFocus && (d->m_passwordEchoEditing || d->m_passwordEchoTimer.isActive())) { @@ -2537,8 +2533,6 @@ void QQuickTextInputPrivate::init() lastSelectionStart = 0; lastSelectionEnd = 0; - selectedTextColor = m_palette.color(QPalette::HighlightedText); - selectionColor = m_palette.color(QPalette::Highlight); determineHorizontalAlignment(); if (!qmlDisableDistanceField()) { @@ -2605,7 +2599,7 @@ QRectF QQuickTextInput::boundingRect() const { Q_D(const QQuickTextInput); - int cursorWidth = d->cursorItem ? d->cursorItem->width() : d->m_cursorWidth; + int cursorWidth = d->cursorItem ? d->cursorItem->width() : 1; // Could include font max left/right bearings to either side of rectangle. QRectF r = QQuickImplicitSizeItem::boundingRect(); @@ -2734,7 +2728,6 @@ void QQuickTextInputPrivate::updateLayout() option.setWrapMode(QTextOption::NoWrap); m_textLayout.setTextOption(option); - m_ascent = qRound(firstLine.ascent()); textLayoutDirty = true; updateType = UpdatePaintNode; @@ -3222,8 +3215,6 @@ bool QQuickTextInputPrivate::finishChange(int validateFromState, bool update, bo return false; internalUndo(validateFromState); m_history.resize(m_undoState); - if (m_modifiedState > m_undoState) - m_modifiedState = -1; m_validInput = true; m_acceptableInput = wasAcceptable; m_textDirty = false; @@ -3282,7 +3273,7 @@ void QQuickTextInputPrivate::internalSetText(const QString &txt, int pos, bool e m_text = txt.isEmpty() ? txt : txt.left(m_maxLength); } m_history.clear(); - m_modifiedState = m_undoState = 0; + m_undoState = 0; m_cursor = (pos < 0 || pos > m_text.length()) ? m_text.length() : pos; m_textDirty = (oldText != m_text); @@ -3904,10 +3895,6 @@ bool QQuickTextInputPrivate::emitCursorPositionChanged() q->updateCursorRectangle(); emit q->cursorPositionChanged(); - // XXX todo - not in 4.8? - #if 0 - resetCursorBlinkTimer(); - #endif if (!hasSelectedText()) { if (lastSelectionStart != m_cursor) { @@ -3951,16 +3938,6 @@ void QQuickTextInputPrivate::setCursorBlinkPeriod(int msec) m_blinkPeriod = msec; } -void QQuickTextInputPrivate::resetCursorBlinkTimer() -{ - Q_Q(QQuickTextInput); - if (m_blinkPeriod == 0 || m_blinkTimer == 0) - return; - q->killTimer(m_blinkTimer); - m_blinkTimer = q->startTimer(m_blinkPeriod / 2); - m_blinkStatus = 1; -} - void QQuickTextInput::timerEvent(QTimerEvent *event) { Q_D(QQuickTextInput); @@ -3968,10 +3945,6 @@ void QQuickTextInput::timerEvent(QTimerEvent *event) d->m_blinkStatus = !d->m_blinkStatus; d->updateType = QQuickTextInputPrivate::UpdatePaintNode; update(); - } else if (event->timerId() == d->m_deleteAllTimer) { - killTimer(d->m_deleteAllTimer); - d->m_deleteAllTimer = 0; - d->clear(); #ifdef QT_GUI_PASSWORD_ECHO_DELAY } else if (event->timerId() == d->m_passwordEchoTimer.timerId()) { d->m_passwordEchoTimer.stop(); diff --git a/src/quick/items/qquicktextinput_p.h b/src/quick/items/qquicktextinput_p.h index 3843b29..0e60cf6 100644 --- a/src/quick/items/qquicktextinput_p.h +++ b/src/quick/items/qquicktextinput_p.h @@ -267,9 +267,9 @@ Q_SIGNALS: void selectedTextChanged(); void accepted(); void acceptableInputChanged(); - void colorChanged(const QColor &color); - void selectionColorChanged(const QColor &color); - void selectedTextColorChanged(const QColor &color); + void colorChanged(); + void selectionColorChanged(); + void selectedTextColorChanged(); void fontChanged(const QFont &font); void horizontalAlignmentChanged(HAlignment alignment); void verticalAlignmentChanged(VAlignment alignment); diff --git a/src/quick/items/qquicktextinput_p_p.h b/src/quick/items/qquicktextinput_p_p.h index 18e2e9f..e48b000 100644 --- a/src/quick/items/qquicktextinput_p_p.h +++ b/src/quick/items/qquicktextinput_p_p.h @@ -77,35 +77,32 @@ class Q_AUTOTEST_EXPORT QQuickTextInputPrivate : public QQuickImplicitSizeItemPr Q_DECLARE_PUBLIC(QQuickTextInput) public: QQuickTextInputPrivate() - : color((QRgb)0) - , styleColor((QRgb)0) + : cursorItem(0) , textNode(0) , m_maskData(0) + , color(QRgb(0xFF000000)) + , selectionColor(QRgb(0xFF000080)) + , selectedTextColor(QRgb(0xFFFFFFFF)) , hscroll(0) , vscroll(0) , m_cursor(0) , m_preeditCursor(0) - , m_cursorWidth(1) , m_blinkPeriod(0) , m_blinkTimer(0) - , m_deleteAllTimer(0) - , m_ascent(0) , m_maxLength(32767) , m_lastCursorPos(-1) - , m_modifiedState(0) , m_undoState(0) , m_selstart(0) , m_selend(0) - , style(QQuickText::Normal) + , inputMethodHints(Qt::ImhNone) , hAlign(QQuickTextInput::AlignLeft) , vAlign(QQuickTextInput::AlignTop) , wrapMode(QQuickTextInput::NoWrap) + , m_echoMode(QQuickTextInput::Normal) + , updateType(UpdatePaintNode) , mouseSelectionMode(QQuickTextInput::SelectCharacters) - , inputMethodHints(Qt::ImhNone) - , effectiveInputMethodHints(Qt::ImhNone) , m_layoutDirection(Qt::LayoutDirectionAuto) , m_passwordCharacter(QLatin1Char('*')) - , focused(false) , focusOnPress(true) , cursorVisible(false) , autoScroll(true) @@ -121,7 +118,6 @@ public: , m_hideCursor(false) , m_separator(0) , m_readOnly(0) - , m_echoMode(QQuickTextInput::Normal) , m_textDirty(0) , m_preeditDirty(0) , m_selDirty(0) @@ -129,7 +125,6 @@ public: , m_acceptableInput(1) , m_blinkStatus(0) , m_passwordEchoEditing(false) - , updateType(UpdatePaintNode) { } @@ -145,10 +140,11 @@ public: bool setHAlign(QQuickTextInput::HAlignment, bool forceAlign = false); void mirrorChange(); bool sendMouseEventToInputContext(QMouseEvent *event); - void updateInputMethodHints(); + Qt::InputMethodHints effectiveInputMethodHints() const; void hideCursor(); void showCursor(); + struct MaskInputData { enum Casemode { NoCaseMode, Upper, Lower }; QChar maskChar; // either the separator char or the inputmask @@ -173,68 +169,70 @@ public: DrawAll = DrawText | DrawSelections | DrawCursor }; + QElapsedTimer tripleClickTimer; + QRectF boundingRect; + QPointF pressPos; + QPointF tripleClickStartPoint; + + QDeclarativeGuard cursorComponent; +#ifndef QT_NO_VALIDATOR + QDeclarativeGuard m_validator; +#endif + QTextLayout m_textLayout; QString m_text; QString m_inputMask; QString m_cancelText; QString m_tentativeCommit; - QPalette m_palette; QFont font; QFont sourceFont; - QColor color; - QColor selectionColor; - QColor selectedTextColor; - QColor styleColor; - QPointer cursorComponent; - QPointer cursorItem; -#ifndef QT_NO_VALIDATOR - QPointer m_validator; -#endif - QPointF pressPos; + + QQuickItem *cursorItem; QQuickTextNode *textNode; MaskInputData *m_maskData; - QElapsedTimer tripleClickTimer; - QPoint tripleClickStartPoint; + QList m_transactions; QVector m_history; - QRectF boundingRect; + QColor color; + QColor selectionColor; + QColor selectedTextColor; + +#ifdef QT_GUI_PASSWORD_ECHO_DELAY + QBasicTimer m_passwordEchoTimer; +#endif int lastSelectionStart; int lastSelectionEnd; - int oldHeight; - int oldWidth; int hscroll; int vscroll; int m_cursor; int m_preeditCursor; - int m_cursorWidth; int m_blinkPeriod; // 0 for non-blinking cursor int m_blinkTimer; - int m_deleteAllTimer; -#ifdef QT_GUI_PASSWORD_ECHO_DELAY - QBasicTimer m_passwordEchoTimer; -#endif - int m_ascent; int m_maxLength; int m_lastCursorPos; - int m_modifiedState; int m_undoState; int m_selstart; int m_selend; - QQuickText::TextStyle style; + enum UpdateType { + UpdateNone, + UpdateOnlyPreprocess, + UpdatePaintNode + }; + + Qt::InputMethodHints inputMethodHints; QQuickTextInput::HAlignment hAlign; QQuickTextInput::VAlignment vAlign; QQuickTextInput::WrapMode wrapMode; + QQuickTextInput::EchoMode m_echoMode; + UpdateType updateType; QQuickTextInput::SelectionMode mouseSelectionMode; - Qt::InputMethodHints inputMethodHints; - Qt::InputMethodHints effectiveInputMethodHints; Qt::LayoutDirection m_layoutDirection; QChar m_blank; QChar m_passwordCharacter; - bool focused:1; bool focusOnPress:1; bool cursorVisible:1; bool autoScroll:1; @@ -247,25 +245,17 @@ public: bool selectPressed:1; bool textLayoutDirty:1; bool persistentSelection:1; + bool m_hideCursor : 1; // used to hide the m_cursor inside preedit areas + bool m_separator : 1; + bool m_readOnly : 1; + bool m_textDirty : 1; + bool m_preeditDirty : 1; + bool m_selDirty : 1; + bool m_validInput : 1; + bool m_acceptableInput : 1; + bool m_blinkStatus : 1; + bool m_passwordEchoEditing : 1; - uint m_hideCursor : 1; // used to hide the m_cursor inside preedit areas - uint m_separator : 1; - uint m_readOnly : 1; - uint m_echoMode : 2; - uint m_textDirty : 1; - uint m_preeditDirty : 1; - uint m_selDirty : 1; - uint m_validInput : 1; - uint m_acceptableInput : 1; - uint m_blinkStatus : 1; - uint m_passwordEchoEditing; - - enum UpdateType { - UpdateNone, - UpdateOnlyPreprocess, - UpdatePaintNode - }; - UpdateType updateType; static inline QQuickTextInputPrivate *get(QQuickTextInput *t) { return t->d_func(); @@ -291,10 +281,7 @@ public: bool isUndoAvailable() const { return !m_readOnly && m_undoState; } bool isRedoAvailable() const { return !m_readOnly && m_undoState < (int)m_history.size(); } - void clearUndo() { m_history.clear(); m_modifiedState = m_undoState = 0; } - - bool isModified() const { return m_modifiedState != m_undoState; } - void setModified(bool modified) { m_modifiedState = modified ? -1 : m_undoState; } + void clearUndo() { m_history.clear(); m_undoState = 0; } bool allSelected() const { return !m_text.isEmpty() && m_selstart == 0 && m_selend == (int)m_text.length(); } bool hasSelectedText() const { return !m_text.isEmpty() && m_selend > m_selstart; } @@ -413,7 +400,6 @@ public: void processKeyEvent(QKeyEvent* ev); void setCursorBlinkPeriod(int msec); - void resetCursorBlinkTimer(); void updateLayout();