Initial import from the monolithic Qt.
[profile/ivi/qtdeclarative.git] / src / declarative / graphicsitems / qdeclarativetextinput_p_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QDECLARATIVETEXTINPUT_P_H
43 #define QDECLARATIVETEXTINPUT_P_H
44
45 #include "private/qdeclarativetextinput_p.h"
46
47 #include "private/qdeclarativeimplicitsizeitem_p_p.h"
48
49 #include <qdeclarative.h>
50
51 #include <QPointer>
52
53 #include <private/qlinecontrol_p.h>
54
55 //
56 //  W A R N I N G
57 //  -------------
58 //
59 // This file is not part of the Qt API.  It exists purely as an
60 // implementation detail.  This header file may change from version to
61 // version without notice, or even be removed.
62 //
63 // We mean it.
64
65 #ifndef QT_NO_LINEEDIT
66
67 QT_BEGIN_NAMESPACE
68
69 class Q_AUTOTEST_EXPORT QDeclarativeTextInputPrivate : public QDeclarativeImplicitSizePaintedItemPrivate
70 {
71     Q_DECLARE_PUBLIC(QDeclarativeTextInput)
72 public:
73     QDeclarativeTextInputPrivate() : control(new QLineControl(QString())),
74                  color((QRgb)0), style(QDeclarativeText::Normal),
75                  styleColor((QRgb)0), hAlign(QDeclarativeTextInput::AlignLeft),
76                  mouseSelectionMode(QDeclarativeTextInput::SelectCharacters), inputMethodHints(Qt::ImhNone),
77                  hscroll(0), oldScroll(0), oldValidity(false), focused(false), focusOnPress(true),
78                  showInputPanelOnFocus(true), clickCausedFocus(false), cursorVisible(false),
79                  autoScroll(true), selectByMouse(false), canPaste(false), hAlignImplicit(true),
80                  selectPressed(false)
81     {
82 #ifdef Q_OS_SYMBIAN
83         if (QSysInfo::symbianVersion() == QSysInfo::SV_SF_1 || QSysInfo::symbianVersion() == QSysInfo::SV_SF_3) {
84             showInputPanelOnFocus = false;
85         }
86 #endif
87
88     }
89
90     ~QDeclarativeTextInputPrivate()
91     {
92         delete control;
93     }
94
95     int xToPos(int x, QTextLine::CursorPosition betweenOrOn = QTextLine::CursorBetweenCharacters) const
96     {
97         Q_Q(const QDeclarativeTextInput);
98         QRect cr = q->boundingRect().toRect();
99         x-= cr.x() - hscroll;
100         return control->xToPos(x, betweenOrOn);
101     }
102
103     void init();
104     void startCreatingCursor();
105     void focusChanged(bool hasFocus);
106     void updateHorizontalScroll();
107     bool determineHorizontalAlignment();
108     bool setHAlign(QDeclarativeTextInput::HAlignment, bool forceAlign = false);
109     void mirrorChange();
110     int calculateTextWidth();
111     bool sendMouseEventToInputContext(QGraphicsSceneMouseEvent *event, QEvent::Type eventType);
112     void updateInputMethodHints();
113
114     QLineControl* control;
115
116     QFont font;
117     QFont sourceFont;
118     QColor  color;
119     QColor  selectionColor;
120     QColor  selectedTextColor;
121     QDeclarativeText::TextStyle style;
122     QColor  styleColor;
123     QDeclarativeTextInput::HAlignment hAlign;
124     QDeclarativeTextInput::SelectionMode mouseSelectionMode;
125     Qt::InputMethodHints inputMethodHints;
126     QPointer<QDeclarativeComponent> cursorComponent;
127     QPointer<QDeclarativeItem> cursorItem;
128     QPointF pressPos;
129
130     int lastSelectionStart;
131     int lastSelectionEnd;
132     int oldHeight;
133     int oldWidth;
134     int hscroll;
135     int oldScroll;
136     bool oldValidity:1;
137     bool focused:1;
138     bool focusOnPress:1;
139     bool showInputPanelOnFocus:1;
140     bool clickCausedFocus:1;
141     bool cursorVisible:1;
142     bool autoScroll:1;
143     bool selectByMouse:1;
144     bool canPaste:1;
145     bool hAlignImplicit:1;
146     bool selectPressed:1;
147
148     static inline QDeclarativeTextInputPrivate *get(QDeclarativeTextInput *t) {
149         return t->d_func();
150     }
151 };
152
153 QT_END_NAMESPACE
154
155 #endif // QT_NO_LINEEDIT
156
157 #endif
158