f25722972b658642d33117681c01929f5b1818d7
[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/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), inputMethodHints(Qt::ImhNone),
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                  selectPressed(false)
80     {
81 #ifdef Q_OS_SYMBIAN
82         if (QSysInfo::symbianVersion() == QSysInfo::SV_SF_1 || QSysInfo::symbianVersion() == QSysInfo::SV_SF_3) {
83             showInputPanelOnFocus = false;
84         }
85 #endif
86     }
87
88     ~QSGTextInputPrivate()
89     {
90     }
91
92     int xToPos(int x, QTextLine::CursorPosition betweenOrOn = QTextLine::CursorBetweenCharacters) const
93     {
94         Q_Q(const QSGTextInput);
95         QRect cr = q->boundingRect().toRect();
96         x-= cr.x() - hscroll;
97         return control->xToPos(x, betweenOrOn);
98     }
99
100     void init();
101     void startCreatingCursor();
102     void updateHorizontalScroll();
103     bool determineHorizontalAlignment();
104     bool setHAlign(QSGTextInput::HAlignment, bool forceAlign = false);
105     void mirrorChange();
106     int calculateTextWidth();
107     bool sendMouseEventToInputContext(QGraphicsSceneMouseEvent *event, QEvent::Type eventType);
108     void updateInputMethodHints();
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     Qt::InputMethodHints inputMethodHints;
122     QPointer<QDeclarativeComponent> cursorComponent;
123     QPointer<QSGItem> cursorItem;
124     QPointF pressPos;
125
126     int lastSelectionStart;
127     int lastSelectionEnd;
128     int oldHeight;
129     int oldWidth;
130     int hscroll;
131     int oldScroll;
132
133     bool oldValidity:1;
134     bool focused:1;
135     bool focusOnPress:1;
136     bool showInputPanelOnFocus:1;
137     bool clickCausedFocus:1;
138     bool cursorVisible:1;
139     bool autoScroll:1;
140     bool selectByMouse:1;
141     bool canPaste:1;
142     bool hAlignImplicit:1;
143     bool selectPressed:1;
144
145     static inline QSGTextInputPrivate *get(QSGTextInput *t) {
146         return t->d_func();
147     }
148 };
149
150 QT_END_NAMESPACE
151
152 #endif // QSGTEXTINPUT_P_P_H