Initial import from qtquick2.
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgtextinput_p_p.h
1 // Commit: 27e4302b7f45f22180693d26747f419177c81e27
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 ** No Commercial Usage
12 ** This file contains pre-release code and may not be distributed.
13 ** You may use this file in accordance with the terms and conditions
14 ** contained in the Technology Preview License Agreement accompanying
15 ** this package.
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, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **
33 **
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/qpointer.h>
54
55
56 //
57 //  W A R N I N G
58 //  -------------
59 //
60 // This file is not part of the Qt API.  It exists purely as an
61 // implementation detail.  This header file may change from version to
62 // version without notice, or even be removed.
63 //
64 // We mean it.
65
66 QT_BEGIN_NAMESPACE
67
68 class Q_AUTOTEST_EXPORT QSGTextInputPrivate : public QSGImplicitSizePaintedItemPrivate
69 {
70     Q_DECLARE_PUBLIC(QSGTextInput)
71 public:
72     QSGTextInputPrivate() : control(new QLineControl(QString())),
73                  color((QRgb)0), style(QSGText::Normal),
74                  styleColor((QRgb)0), hAlign(QSGTextInput::AlignLeft),
75                  mouseSelectionMode(QSGTextInput::SelectCharacters),
76                  hscroll(0), oldScroll(0), oldValidity(false), focused(false), focusOnPress(true),
77                  showInputPanelOnFocus(true), clickCausedFocus(false), cursorVisible(false),
78                  autoScroll(true), selectByMouse(false), canPaste(false), hAlignImplicit(true)
79     {
80 #ifdef Q_OS_SYMBIAN
81         if (QSysInfo::symbianVersion() == QSysInfo::SV_SF_1 || QSysInfo::symbianVersion() == QSysInfo::SV_SF_3) {
82             showInputPanelOnFocus = false;
83         }
84 #endif
85
86     }
87
88     ~QSGTextInputPrivate()
89     {
90         delete control;
91     }
92
93     int xToPos(int x, QTextLine::CursorPosition betweenOrOn = QTextLine::CursorBetweenCharacters) const
94     {
95         Q_Q(const QSGTextInput);
96         QRect cr = q->boundingRect().toRect();
97         x-= cr.x() - hscroll;
98         return control->xToPos(x, betweenOrOn);
99     }
100
101     void init();
102     void startCreatingCursor();
103     void updateHorizontalScroll();
104     bool determineHorizontalAlignment();
105     bool setHAlign(QSGTextInput::HAlignment, bool forceAlign = false);
106     void mirrorChange();
107     int calculateTextWidth();
108     bool sendMouseEventToInputContext(QGraphicsSceneMouseEvent *event, QEvent::Type eventType);
109
110     QLineControl* control;
111
112     QFont font;
113     QFont sourceFont;
114     QColor  color;
115     QColor  selectionColor;
116     QColor  selectedTextColor;
117     QSGText::TextStyle style;
118     QColor  styleColor;
119     QSGTextInput::HAlignment hAlign;
120     QSGTextInput::SelectionMode mouseSelectionMode;
121     QPointer<QDeclarativeComponent> cursorComponent;
122     QPointer<QSGItem> cursorItem;
123     QPointF pressPos;
124
125     int lastSelectionStart;
126     int lastSelectionEnd;
127     int oldHeight;
128     int oldWidth;
129     int hscroll;
130     int oldScroll;
131
132     bool oldValidity:1;
133     bool focused:1;
134     bool focusOnPress:1;
135     bool showInputPanelOnFocus:1;
136     bool clickCausedFocus:1;
137     bool cursorVisible:1;
138     bool autoScroll:1;
139     bool selectByMouse:1;
140     bool canPaste:1;
141     bool hAlignImplicit:1;
142
143     static inline QSGTextInputPrivate *get(QSGTextInput *t) {
144         return t->d_func();
145     }
146 };
147
148 QT_END_NAMESPACE
149
150 #endif // QSGTEXTINPUT_P_P_H