Added triple click on TextInput to select text.
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgtextinput_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 QSGTEXTINPUT_P_P_H
44 #define QSGTEXTINPUT_P_P_H
45
46 #include "qsgtextinput_p.h"
47 #include "qsgtext_p.h"
48 #include "qsgimplicitsizeitem_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 QSGTextNode;
72
73 class Q_AUTOTEST_EXPORT QSGTextInputPrivate : public QSGImplicitSizeItemPrivate
74 {
75     Q_DECLARE_PUBLIC(QSGTextInput)
76 public:
77     QSGTextInputPrivate()
78                  : control(new QLineControl(QString()))
79                  , color((QRgb)0)
80                  , style(QSGText::Normal)
81                  , styleColor((QRgb)0)
82                  , hAlign(QSGTextInput::AlignLeft)
83                  , mouseSelectionMode(QSGTextInput::SelectCharacters)
84                  , inputMethodHints(Qt::ImhNone)
85                  , textNode(0)
86                  , hscroll(0)
87                  , oldScroll(0)
88                  , oldValidity(false)
89                  , focused(false)
90                  , focusOnPress(true)
91                  , showInputPanelOnFocus(true)
92                  , clickCausedFocus(false)
93                  , cursorVisible(false)
94                  , autoScroll(true)
95                  , selectByMouse(false)
96                  , canPaste(false)
97                  , hAlignImplicit(true)
98                  , selectPressed(false)
99                  , textLayoutDirty(true)
100     {
101 #ifdef Q_OS_SYMBIAN
102         if (QSysInfo::symbianVersion() == QSysInfo::SV_SF_1 || QSysInfo::symbianVersion() == QSysInfo::SV_SF_3) {
103             showInputPanelOnFocus = false;
104         }
105 #endif
106     }
107
108     ~QSGTextInputPrivate()
109     {
110     }
111
112     int xToPos(int x, QTextLine::CursorPosition betweenOrOn = QTextLine::CursorBetweenCharacters) const
113     {
114         Q_Q(const QSGTextInput);
115         QRect cr = q->boundingRect().toRect();
116         x-= cr.x() - hscroll;
117         return control->xToPos(x, betweenOrOn);
118     }
119
120     void init();
121     void startCreatingCursor();
122     void updateHorizontalScroll();
123     bool determineHorizontalAlignment();
124     bool setHAlign(QSGTextInput::HAlignment, bool forceAlign = false);
125     void mirrorChange();
126     int calculateTextWidth();
127     bool sendMouseEventToInputContext(QMouseEvent *event);
128     void updateInputMethodHints();
129     void hideCursor();
130     void showCursor();
131
132     QLineControl* control;
133
134     QFont font;
135     QFont sourceFont;
136     QColor  color;
137     QColor  selectionColor;
138     QColor  selectedTextColor;
139     QSGText::TextStyle style;
140     QColor  styleColor;
141     QSGTextInput::HAlignment hAlign;
142     QSGTextInput::SelectionMode mouseSelectionMode;
143     Qt::InputMethodHints inputMethodHints;
144     QPointer<QDeclarativeComponent> cursorComponent;
145     QPointer<QSGItem> cursorItem;
146     QPointF pressPos;
147     QSGTextNode *textNode;
148     QElapsedTimer tripleClickTimer;
149     QPoint tripleClickStartPoint;
150
151     int lastSelectionStart;
152     int lastSelectionEnd;
153     int oldHeight;
154     int oldWidth;
155     int hscroll;
156     int oldScroll;
157
158     bool oldValidity:1;
159     bool focused:1;
160     bool focusOnPress:1;
161     bool showInputPanelOnFocus:1;
162     bool clickCausedFocus:1;
163     bool cursorVisible:1;
164     bool autoScroll:1;
165     bool selectByMouse:1;
166     bool canPaste:1;
167     bool hAlignImplicit:1;
168     bool selectPressed:1;
169     bool textLayoutDirty:1;
170
171     static inline QSGTextInputPrivate *get(QSGTextInput *t) {
172         return t->d_func();
173     }
174     bool hasPendingTripleClick() const {
175         return !tripleClickTimer.hasExpired(qApp->styleHints()->mouseDoubleClickInterval());
176     }
177 };
178
179 QT_END_NAMESPACE
180
181 #endif // QSGTEXTINPUT_P_P_H