0
|
1 |
/****************************************************************************
|
|
2 |
**
|
18
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtGui 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 QLINECONTROL_P_H
|
|
43 |
#define QLINECONTROL_P_H
|
|
44 |
|
|
45 |
//
|
|
46 |
// W A R N I N G
|
|
47 |
// -------------
|
|
48 |
//
|
|
49 |
// This file is not part of the Qt API. It exists purely as an
|
|
50 |
// implementation detail. This header file may change from version to
|
|
51 |
// version without notice, or even be removed.
|
|
52 |
//
|
|
53 |
// We mean it.
|
|
54 |
//
|
|
55 |
|
|
56 |
#include "QtCore/qglobal.h"
|
|
57 |
|
|
58 |
#ifndef QT_NO_LINEEDIT
|
|
59 |
#include "private/qwidget_p.h"
|
|
60 |
#include "QtGui/qlineedit.h"
|
|
61 |
#include "QtGui/qtextlayout.h"
|
|
62 |
#include "QtGui/qstyleoption.h"
|
|
63 |
#include "QtCore/qpointer.h"
|
|
64 |
#include "QtGui/qlineedit.h"
|
|
65 |
#include "QtGui/qclipboard.h"
|
|
66 |
#include "QtCore/qpoint.h"
|
|
67 |
#include "QtGui/qcompleter.h"
|
|
68 |
|
|
69 |
QT_BEGIN_HEADER
|
|
70 |
|
|
71 |
QT_BEGIN_NAMESPACE
|
|
72 |
|
|
73 |
QT_MODULE(Gui)
|
|
74 |
|
|
75 |
class Q_GUI_EXPORT QLineControl : public QObject
|
|
76 |
{
|
|
77 |
Q_OBJECT
|
|
78 |
|
|
79 |
public:
|
|
80 |
QLineControl(const QString &txt = QString())
|
|
81 |
: m_cursor(0), m_preeditCursor(0), m_cursorWidth(0), m_layoutDirection(Qt::LeftToRight),
|
|
82 |
m_hideCursor(false), m_separator(0), m_readOnly(0),
|
|
83 |
m_dragEnabled(0), m_echoMode(0), m_textDirty(0), m_selDirty(0),
|
|
84 |
m_validInput(1), m_blinkStatus(0), m_blinkPeriod(0), m_blinkTimer(0), m_deleteAllTimer(0),
|
|
85 |
m_ascent(0), m_maxLength(32767), m_lastCursorPos(-1),
|
|
86 |
m_tripleClickTimer(0), m_maskData(0), m_modifiedState(0), m_undoState(0),
|
|
87 |
m_selstart(0), m_selend(0), m_passwordEchoEditing(false)
|
|
88 |
{
|
|
89 |
init(txt);
|
|
90 |
}
|
|
91 |
|
|
92 |
~QLineControl()
|
|
93 |
{
|
|
94 |
delete [] m_maskData;
|
|
95 |
}
|
|
96 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
97 |
int nextMaskBlank(int pos)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
98 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
99 |
int c = findInMask(pos, true, false);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
100 |
m_separator |= (c != pos);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
101 |
return (c != -1 ? c : m_maxLength);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
102 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
103 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
104 |
int prevMaskBlank(int pos)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
105 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
106 |
int c = findInMask(pos, false, false);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
107 |
m_separator |= (c != pos);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
108 |
return (c != -1 ? c : 0);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
109 |
}
|
0
|
110 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
111 |
bool isUndoAvailable() const { return !m_readOnly && m_undoState; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
112 |
bool isRedoAvailable() const { return !m_readOnly && m_undoState < (int)m_history.size(); }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
113 |
void clearUndo() { m_history.clear(); m_modifiedState = m_undoState = 0; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
114 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
115 |
bool isModified() const { return m_modifiedState != m_undoState; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
116 |
void setModified(bool modified) { m_modifiedState = modified ? -1 : m_undoState; }
|
0
|
117 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
118 |
bool allSelected() const { return !m_text.isEmpty() && m_selstart == 0 && m_selend == (int)m_text.length(); }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
119 |
bool hasSelectedText() const { return !m_text.isEmpty() && m_selend > m_selstart; }
|
0
|
120 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
121 |
int width() const { return qRound(m_textLayout.lineAt(0).width()) + 1; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
122 |
int height() const { return qRound(m_textLayout.lineAt(0).height()) + 1; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
123 |
int ascent() const { return m_ascent; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
124 |
qreal naturalTextWidth() const { return m_textLayout.lineAt(0).naturalTextWidth(); }
|
0
|
125 |
|
|
126 |
void setSelection(int start, int length);
|
|
127 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
128 |
inline QString selectedText() const { return hasSelectedText() ? m_text.mid(m_selstart, m_selend - m_selstart) : QString(); }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
129 |
QString textBeforeSelection() const { return hasSelectedText() ? m_text.left(m_selstart) : QString(); }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
130 |
QString textAfterSelection() const { return hasSelectedText() ? m_text.mid(m_selend) : QString(); }
|
0
|
131 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
132 |
int selectionStart() const { return hasSelectedText() ? m_selstart : -1; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
133 |
int selectionEnd() const { return hasSelectedText() ? m_selend : -1; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
134 |
bool inSelection(int x) const
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
135 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
136 |
if (m_selstart >= m_selend)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
137 |
return false;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
138 |
int pos = xToPos(x, QTextLine::CursorOnCharacter);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
139 |
return pos >= m_selstart && pos < m_selend;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
140 |
}
|
0
|
141 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
142 |
void removeSelection()
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
143 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
144 |
int priorState = m_undoState;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
145 |
removeSelectedText();
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
146 |
finishChange(priorState);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
147 |
}
|
0
|
148 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
149 |
int start() const { return 0; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
150 |
int end() const { return m_text.length(); }
|
0
|
151 |
|
|
152 |
#ifndef QT_NO_CLIPBOARD
|
|
153 |
void copy(QClipboard::Mode mode = QClipboard::Clipboard) const;
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
154 |
void paste(QClipboard::Mode mode = QClipboard::Clipboard);
|
0
|
155 |
#endif
|
|
156 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
157 |
int cursor() const{ return m_cursor; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
158 |
int preeditCursor() const { return m_preeditCursor; }
|
0
|
159 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
160 |
int cursorWidth() const { return m_cursorWidth; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
161 |
void setCursorWidth(int value) { m_cursorWidth = value; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
162 |
|
0
|
163 |
|
|
164 |
void moveCursor(int pos, bool mark = false);
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
165 |
void cursorForward(bool mark, int steps)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
166 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
167 |
int c = m_cursor;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
168 |
if (steps > 0) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
169 |
while (steps--)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
170 |
c = m_textLayout.nextCursorPosition(c);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
171 |
} else if (steps < 0) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
172 |
while (steps++)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
173 |
c = m_textLayout.previousCursorPosition(c);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
174 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
175 |
moveCursor(c, mark);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
176 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
177 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
178 |
void cursorWordForward(bool mark) { moveCursor(m_textLayout.nextCursorPosition(m_cursor, QTextLayout::SkipWords), mark); }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
179 |
void cursorWordBackward(bool mark) { moveCursor(m_textLayout.previousCursorPosition(m_cursor, QTextLayout::SkipWords), mark); }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
180 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
181 |
void home(bool mark) { moveCursor(0, mark); }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
182 |
void end(bool mark) { moveCursor(text().length(), mark); }
|
0
|
183 |
|
|
184 |
int xToPos(int x, QTextLine::CursorPosition = QTextLine::CursorBetweenCharacters) const;
|
|
185 |
QRect cursorRect() const;
|
|
186 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
187 |
qreal cursorToX(int cursor) const { return m_textLayout.lineAt(0).cursorToX(cursor); }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
188 |
qreal cursorToX() const
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
189 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
190 |
int cursor = m_cursor;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
191 |
if (m_preeditCursor != -1)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
192 |
cursor += m_preeditCursor;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
193 |
return cursorToX(cursor);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
194 |
}
|
0
|
195 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
196 |
bool isReadOnly() const { return m_readOnly; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
197 |
void setReadOnly(bool enable) { m_readOnly = enable; }
|
0
|
198 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
199 |
QString text() const
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
200 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
201 |
QString res = m_maskData ? stripString(m_text) : m_text;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
202 |
return (res.isNull() ? QString::fromLatin1("") : res);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
203 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
204 |
void setText(const QString &txt) { internalSetText(txt, -1, false); }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
205 |
QString displayText() const { return m_textLayout.text(); }
|
0
|
206 |
|
|
207 |
void backspace();
|
|
208 |
void del();
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
209 |
void deselect() { internalDeselect(); finishChange(); }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
210 |
void selectAll() { m_selstart = m_selend = m_cursor = 0; moveCursor(m_text.length(), true); }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
211 |
|
0
|
212 |
void insert(const QString &);
|
|
213 |
void clear();
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
214 |
void undo() { internalUndo(); finishChange(-1, true); }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
215 |
void redo() { internalRedo(); finishChange(); }
|
0
|
216 |
void selectWordAtPos(int);
|
|
217 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
218 |
uint echoMode() const { return m_echoMode; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
219 |
void setEchoMode(uint mode)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
220 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
221 |
m_echoMode = mode;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
222 |
m_passwordEchoEditing = false;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
223 |
updateDisplayText();
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
224 |
}
|
0
|
225 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
226 |
int maxLength() const { return m_maxLength; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
227 |
void setMaxLength(int maxLength)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
228 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
229 |
if (m_maskData)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
230 |
return;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
231 |
m_maxLength = maxLength;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
232 |
setText(m_text);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
233 |
}
|
0
|
234 |
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
235 |
#ifndef QT_NO_VALIDATOR
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
236 |
const QValidator *validator() const { return m_validator; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
237 |
void setValidator(const QValidator *v) { m_validator = const_cast<QValidator*>(v); }
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
238 |
#endif
|
0
|
239 |
|
|
240 |
#ifndef QT_NO_COMPLETER
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
241 |
QCompleter *completer() const { return m_completer; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
242 |
/* Note that you must set the widget for the completer seperately */
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
243 |
void setCompleter(const QCompleter *c) { m_completer = const_cast<QCompleter*>(c); }
|
0
|
244 |
void complete(int key);
|
|
245 |
#endif
|
|
246 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
247 |
int cursorPosition() const { return m_cursor; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
248 |
void setCursorPosition(int pos) { if (pos <= m_text.length()) moveCursor(qMax(0, pos)); }
|
0
|
249 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
250 |
bool hasAcceptableInput() const { return hasAcceptableInput(m_text); }
|
0
|
251 |
bool fixup();
|
|
252 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
253 |
QString inputMask() const { return m_maskData ? m_inputMask + QLatin1Char(';') + m_blank : QString(); }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
254 |
void setInputMask(const QString &mask)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
255 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
256 |
parseInputMask(mask);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
257 |
if (m_maskData)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
258 |
moveCursor(nextMaskBlank(0));
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
259 |
}
|
0
|
260 |
|
|
261 |
// input methods
|
|
262 |
#ifndef QT_NO_IM
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
263 |
bool composeMode() const { return !m_textLayout.preeditAreaText().isEmpty(); }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
264 |
void setPreeditArea(int cursor, const QString &text) { m_textLayout.setPreeditArea(cursor, text); }
|
0
|
265 |
#endif
|
|
266 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
267 |
QString preeditAreaText() const { return m_textLayout.preeditAreaText(); }
|
0
|
268 |
|
|
269 |
void updatePasswordEchoEditing(bool editing);
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
270 |
bool passwordEchoEditing() const { return m_passwordEchoEditing; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
271 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
272 |
QChar passwordCharacter() const { return m_passwordCharacter; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
273 |
void setPasswordCharacter(const QChar &character) { m_passwordCharacter = character; updateDisplayText(); }
|
0
|
274 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
275 |
Qt::LayoutDirection layoutDirection() const { return m_layoutDirection; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
276 |
void setLayoutDirection(Qt::LayoutDirection direction)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
277 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
278 |
if (direction != m_layoutDirection) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
279 |
m_layoutDirection = direction;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
280 |
updateDisplayText();
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
281 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
282 |
}
|
0
|
283 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
284 |
void setFont(const QFont &font) { m_textLayout.setFont(font); updateDisplayText(); }
|
0
|
285 |
|
|
286 |
void processInputMethodEvent(QInputMethodEvent *event);
|
|
287 |
void processMouseEvent(QMouseEvent* ev);
|
|
288 |
void processKeyEvent(QKeyEvent* ev);
|
|
289 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
290 |
int cursorBlinkPeriod() const { return m_blinkPeriod; }
|
0
|
291 |
void setCursorBlinkPeriod(int msec);
|
|
292 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
293 |
QString cancelText() const { return m_cancelText; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
294 |
void setCancelText(const QString &text) { m_cancelText = text; }
|
0
|
295 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
296 |
const QPalette &palette() const { return m_palette; }
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
297 |
void setPalette(const QPalette &p) { m_palette = p; }
|
0
|
298 |
|
|
299 |
enum DrawFlags {
|
|
300 |
DrawText = 0x01,
|
|
301 |
DrawSelections = 0x02,
|
|
302 |
DrawCursor = 0x04,
|
|
303 |
DrawAll = DrawText | DrawSelections | DrawCursor
|
|
304 |
};
|
|
305 |
void draw(QPainter *, const QPoint &, const QRect &, int flags = DrawAll);
|
|
306 |
|
|
307 |
bool processEvent(QEvent *ev);
|
|
308 |
|
|
309 |
private:
|
|
310 |
void init(const QString &txt);
|
|
311 |
void removeSelectedText();
|
|
312 |
void internalSetText(const QString &txt, int pos = -1, bool edited = true);
|
19
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
313 |
void updateDisplayText(bool forceUpdate = false);
|
0
|
314 |
|
|
315 |
void internalInsert(const QString &s);
|
|
316 |
void internalDelete(bool wasBackspace = false);
|
|
317 |
void internalRemove(int pos);
|
|
318 |
|
|
319 |
inline void internalDeselect()
|
|
320 |
{
|
|
321 |
m_selDirty |= (m_selend > m_selstart);
|
|
322 |
m_selstart = m_selend = 0;
|
|
323 |
}
|
|
324 |
|
|
325 |
void internalUndo(int until = -1);
|
|
326 |
void internalRedo();
|
|
327 |
|
|
328 |
QString m_text;
|
|
329 |
QPalette m_palette;
|
|
330 |
int m_cursor;
|
|
331 |
int m_preeditCursor;
|
|
332 |
int m_cursorWidth;
|
|
333 |
Qt::LayoutDirection m_layoutDirection;
|
|
334 |
uint m_hideCursor : 1; // used to hide the m_cursor inside preedit areas
|
|
335 |
uint m_separator : 1;
|
|
336 |
uint m_readOnly : 1;
|
|
337 |
uint m_dragEnabled : 1;
|
|
338 |
uint m_echoMode : 2;
|
|
339 |
uint m_textDirty : 1;
|
|
340 |
uint m_selDirty : 1;
|
|
341 |
uint m_validInput : 1;
|
|
342 |
uint m_blinkStatus : 1;
|
|
343 |
int m_blinkPeriod; // 0 for non-blinking cursor
|
|
344 |
int m_blinkTimer;
|
|
345 |
int m_deleteAllTimer;
|
|
346 |
int m_ascent;
|
|
347 |
int m_maxLength;
|
|
348 |
int m_lastCursorPos;
|
|
349 |
QList<int> m_transactions;
|
|
350 |
QPoint m_tripleClick;
|
|
351 |
int m_tripleClickTimer;
|
|
352 |
QString m_cancelText;
|
|
353 |
|
|
354 |
void emitCursorPositionChanged();
|
|
355 |
|
|
356 |
bool finishChange(int validateFromState = -1, bool update = false, bool edited = true);
|
|
357 |
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
358 |
#ifndef QT_NO_VALIDATOR
|
0
|
359 |
QPointer<QValidator> m_validator;
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
360 |
#endif
|
0
|
361 |
QPointer<QCompleter> m_completer;
|
|
362 |
#ifndef QT_NO_COMPLETER
|
|
363 |
bool advanceToEnabledItem(int dir);
|
|
364 |
#endif
|
|
365 |
|
|
366 |
struct MaskInputData {
|
|
367 |
enum Casemode { NoCaseMode, Upper, Lower };
|
|
368 |
QChar maskChar; // either the separator char or the inputmask
|
|
369 |
bool separator;
|
|
370 |
Casemode caseMode;
|
|
371 |
};
|
|
372 |
QString m_inputMask;
|
|
373 |
QChar m_blank;
|
|
374 |
MaskInputData *m_maskData;
|
|
375 |
|
|
376 |
// undo/redo handling
|
|
377 |
enum CommandType { Separator, Insert, Remove, Delete, RemoveSelection, DeleteSelection, SetSelection };
|
|
378 |
struct Command {
|
|
379 |
inline Command() {}
|
|
380 |
inline Command(CommandType t, int p, QChar c, int ss, int se) : type(t),uc(c),pos(p),selStart(ss),selEnd(se) {}
|
|
381 |
uint type : 4;
|
|
382 |
QChar uc;
|
|
383 |
int pos, selStart, selEnd;
|
|
384 |
};
|
|
385 |
int m_modifiedState;
|
|
386 |
int m_undoState;
|
|
387 |
QVector<Command> m_history;
|
|
388 |
void addCommand(const Command& cmd);
|
|
389 |
|
|
390 |
inline void separate() { m_separator = true; }
|
|
391 |
|
|
392 |
// selection
|
|
393 |
int m_selstart;
|
|
394 |
int m_selend;
|
|
395 |
|
|
396 |
// masking
|
|
397 |
void parseInputMask(const QString &maskFields);
|
|
398 |
bool isValidInput(QChar key, QChar mask) const;
|
|
399 |
bool hasAcceptableInput(const QString &text) const;
|
|
400 |
QString maskString(uint pos, const QString &str, bool clear = false) const;
|
|
401 |
QString clearString(uint pos, uint len) const;
|
|
402 |
QString stripString(const QString &str) const;
|
|
403 |
int findInMask(int pos, bool forward, bool findSeparator, QChar searchChar = QChar()) const;
|
|
404 |
|
|
405 |
// complex text layout
|
|
406 |
QTextLayout m_textLayout;
|
|
407 |
|
|
408 |
bool m_passwordEchoEditing;
|
|
409 |
QChar m_passwordCharacter;
|
|
410 |
|
|
411 |
Q_SIGNALS:
|
|
412 |
void cursorPositionChanged(int, int);
|
|
413 |
void selectionChanged();
|
|
414 |
|
|
415 |
void displayTextChanged(const QString &);
|
|
416 |
void textChanged(const QString &);
|
|
417 |
void textEdited(const QString &);
|
|
418 |
|
|
419 |
void resetInputContext();
|
|
420 |
|
|
421 |
void accepted();
|
|
422 |
void editingFinished();
|
|
423 |
void updateNeeded(const QRect &);
|
|
424 |
|
|
425 |
#ifdef QT_KEYPAD_NAVIGATION
|
|
426 |
void editFocusChange(bool);
|
|
427 |
#endif
|
|
428 |
protected:
|
|
429 |
virtual void timerEvent(QTimerEvent *event);
|
|
430 |
|
|
431 |
private Q_SLOTS:
|
|
432 |
void _q_clipboardChanged();
|
|
433 |
void _q_deleteSelected();
|
|
434 |
|
|
435 |
};
|
|
436 |
|
|
437 |
QT_END_NAMESPACE
|
|
438 |
|
|
439 |
QT_END_HEADER
|
|
440 |
|
|
441 |
#endif // QT_NO_LINEEDIT
|
|
442 |
|
|
443 |
#endif // QLINECONTROL_P_H
|