Fix test fails related to QTBUG-22237
[profile/ivi/qtdeclarative.git] / src / declarative / items / qquicktextinput_p_p.h
1 // Commit: 47712d1f330e4b22ce6dd30e7557288ef7f7fca0
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this
15 ** file. Please review the following information to ensure the GNU Lesser
16 ** General Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** GNU General Public License Usage
24 ** Alternatively, this file may be used under the terms of the GNU General
25 ** Public License version 3.0 as published by the Free Software Foundation
26 ** and appearing in the file LICENSE.GPL included in the packaging of this
27 ** file. Please review the following information to ensure the GNU General
28 ** Public License version 3.0 requirements will be met:
29 ** http://www.gnu.org/copyleft/gpl.html.
30 **
31 ** Other Usage
32 ** Alternatively, this file may be used in accordance with the terms and
33 ** conditions contained in a signed written agreement between you and Nokia.
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QQUICKTEXTINPUT_P_P_H
44 #define QQUICKTEXTINPUT_P_P_H
45
46 #include "qquicktextinput_p.h"
47 #include "qquicktext_p.h"
48 #include "qquickimplicitsizeitem_p_p.h"
49
50 #include <private/qlinecontrol_p.h>
51
52 #include <QtDeclarative/qdeclarative.h>
53 #include <QtCore/qelapsedtimer.h>
54 #include <QtCore/qpointer.h>
55 #include <QtGui/qguiapplication.h>
56 #include <QtGui/qstylehints.h>
57
58
59 //
60 //  W A R N I N G
61 //  -------------
62 //
63 // This file is not part of the Qt API.  It exists purely as an
64 // implementation detail.  This header file may change from version to
65 // version without notice, or even be removed.
66 //
67 // We mean it.
68
69 QT_BEGIN_NAMESPACE
70
71 class QQuickTextNode;
72
73 class Q_AUTOTEST_EXPORT QQuickTextInputPrivate : public QQuickImplicitSizeItemPrivate
74 {
75     Q_DECLARE_PUBLIC(QQuickTextInput)
76 public:
77     QQuickTextInputPrivate()
78                  : control(new QLineControl(QString()))
79                  , color((QRgb)0)
80                  , style(QQuickText::Normal)
81                  , styleColor((QRgb)0)
82                  , hAlign(QQuickTextInput::AlignLeft)
83                  , mouseSelectionMode(QQuickTextInput::SelectCharacters)
84                  , inputMethodHints(Qt::ImhNone)
85                  , textNode(0)
86                  , hscroll(0)
87                  , oldScroll(0)
88                  , oldValidity(false)
89                  , focused(false)
90                  , focusOnPress(true)
91                  , cursorVisible(false)
92                  , autoScroll(true)
93                  , selectByMouse(false)
94                  , canPaste(false)
95                  , hAlignImplicit(true)
96                  , selectPressed(false)
97                  , textLayoutDirty(true)
98     {
99     }
100
101     ~QQuickTextInputPrivate()
102     {
103     }
104
105     int xToPos(int x, QTextLine::CursorPosition betweenOrOn = QTextLine::CursorBetweenCharacters) const
106     {
107         Q_Q(const QQuickTextInput);
108         QRect cr = q->boundingRect().toRect();
109         x-= cr.x() - hscroll;
110         return control->xToPos(x, betweenOrOn);
111     }
112
113     void init();
114     void startCreatingCursor();
115     void updateHorizontalScroll();
116     bool determineHorizontalAlignment();
117     bool setHAlign(QQuickTextInput::HAlignment, bool forceAlign = false);
118     void mirrorChange();
119     int calculateTextWidth();
120     bool sendMouseEventToInputContext(QMouseEvent *event);
121     void updateInputMethodHints();
122     void hideCursor();
123     void showCursor();
124
125     QLineControl* control;
126
127     QFont font;
128     QFont sourceFont;
129     QColor  color;
130     QColor  selectionColor;
131     QColor  selectedTextColor;
132     QQuickText::TextStyle style;
133     QColor  styleColor;
134     QQuickTextInput::HAlignment hAlign;
135     QQuickTextInput::SelectionMode mouseSelectionMode;
136     Qt::InputMethodHints inputMethodHints;
137     QPointer<QDeclarativeComponent> cursorComponent;
138     QPointer<QQuickItem> cursorItem;
139     QPointF pressPos;
140     QQuickTextNode *textNode;
141     QElapsedTimer tripleClickTimer;
142     QPoint tripleClickStartPoint;
143
144     int lastSelectionStart;
145     int lastSelectionEnd;
146     int oldHeight;
147     int oldWidth;
148     int hscroll;
149     int oldScroll;
150
151     bool oldValidity:1;
152     bool focused:1;
153     bool focusOnPress:1;
154     bool cursorVisible:1;
155     bool autoScroll:1;
156     bool selectByMouse:1;
157     bool canPaste:1;
158     bool hAlignImplicit:1;
159     bool selectPressed:1;
160     bool textLayoutDirty:1;
161
162     static inline QQuickTextInputPrivate *get(QQuickTextInput *t) {
163         return t->d_func();
164     }
165     bool hasPendingTripleClick() const {
166         return !tripleClickTimer.hasExpired(qApp->styleHints()->mouseDoubleClickInterval());
167     }
168 };
169
170 QT_END_NAMESPACE
171
172 #endif // QQUICKTEXTINPUT_P_P_H