summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets/qlineedit_p.h
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-07-29 07:14:49 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-07-29 07:25:44 (GMT)
commitfb7d86cf23227302d48db279ec589221d11a1f6a (patch)
treefc3022e03fe9f56d568abc6df57f154b1a58c778 /src/gui/widgets/qlineedit_p.h
parenta45fe18569be1fc91e26f6e58d2f16bc8c6958de (diff)
downloadQt-fb7d86cf23227302d48db279ec589221d11a1f6a.zip
Qt-fb7d86cf23227302d48db279ec589221d11a1f6a.tar.gz
Qt-fb7d86cf23227302d48db279ec589221d11a1f6a.tar.bz2
Move QLineEdit logic into QLineControl
Manually merged from the kinetic repository, where it has been used for a while. Like QTextControl, there is no auto test for the control, just for the widgets built with it. The purpose of this change is so that we can build stuff like QLineEdit in other places (like kinetic). Also included is a trivial change to QValidator, needed to use it with QLineControl in QML. Reviewed-by: mbm
Diffstat (limited to 'src/gui/widgets/qlineedit_p.h')
-rw-r--r--src/gui/widgets/qlineedit_p.h175
1 files changed, 37 insertions, 138 deletions
diff --git a/src/gui/widgets/qlineedit_p.h b/src/gui/widgets/qlineedit_p.h
index 7a4ff26..230023d 100644
--- a/src/gui/widgets/qlineedit_p.h
+++ b/src/gui/widgets/qlineedit_p.h
@@ -65,6 +65,8 @@
#include "QtCore/qpointer.h"
#include "QtGui/qlineedit.h"
+#include "private/qlinecontrol_p.h"
+
QT_BEGIN_NAMESPACE
class QLineEditPrivate : public QWidgetPrivate
@@ -73,167 +75,64 @@ class QLineEditPrivate : public QWidgetPrivate
public:
QLineEditPrivate()
- : cursor(0), preeditCursor(0), cursorTimer(0), frame(1),
- cursorVisible(0), hideCursor(false), separator(0), readOnly(0),
- dragEnabled(0), contextMenuEnabled(1), echoMode(0), textDirty(0),
- selDirty(0), validInput(1), alignment(Qt::AlignLeading | Qt::AlignVCenter), ascent(0),
- maxLength(32767), hscroll(0), vscroll(0), lastCursorPos(-1), maskData(0),
- modifiedState(0), undoState(0), selstart(0), selend(0), userInput(false),
- emitingEditingFinished(false), passwordEchoEditing(false)
-#ifndef QT_NO_COMPLETER
- , completer(0)
-#endif
- , leftTextMargin(0), topTextMargin(0), rightTextMargin(0), bottomTextMargin(0)
- {
- }
+ : control(0), frame(1), contextMenuEnabled(1), cursorVisible(0),
+ dragEnabled(0), hscroll(0), vscroll(0),
+ alignment(Qt::AlignLeading | Qt::AlignVCenter),
+ leftTextMargin(0), topTextMargin(0), rightTextMargin(0), bottomTextMargin(0)
+ {
+ }
~QLineEditPrivate()
{
- delete [] maskData;
}
+
+ QLineControl *control;
+
+#ifndef QT_NO_CONTEXTMENU
+ QPointer<QAction> selectAllAction;
+#endif
void init(const QString&);
- QString text;
- int cursor;
- int preeditCursor;
- int cursorTimer; // -1 for non blinking cursor.
+ int xToPos(int x, QTextLine::CursorPosition = QTextLine::CursorBetweenCharacters) const;
+ QRect cursorRect() const;
+ void setCursorVisible(bool visible);
+
+ void updatePasswordEchoEditing(bool);
+
+ inline bool shouldEnableInputMethod() const
+ {
+ return !control->isReadOnly() && (control->echoMode() == QLineEdit::Normal || control->echoMode() == QLineEdit::PasswordEchoOnEdit);
+ }
+
QPoint tripleClick;
QBasicTimer tripleClickTimer;
uint frame : 1;
+ uint contextMenuEnabled : 1;
uint cursorVisible : 1;
- uint hideCursor : 1; // used to hide the cursor inside preedit areas
- uint separator : 1;
- uint readOnly : 1;
uint dragEnabled : 1;
- uint contextMenuEnabled : 1;
- uint echoMode : 2;
- uint textDirty : 1;
- uint selDirty : 1;
- uint validInput : 1;
- uint alignment;
- int ascent;
- int maxLength;
int hscroll;
int vscroll;
- int lastCursorPos;
-
-#ifndef QT_NO_CONTEXTMENU
- QPointer<QAction> selectAllAction;
-#endif
+ uint alignment;
+ static const int verticalMargin;
+ static const int horizontalMargin;
- inline void emitCursorPositionChanged();
bool sendMouseEventToInputContext(QMouseEvent *e);
- void finishChange(int validateFromState = -1, bool update = false, bool edited = true);
-
- QPointer<QValidator> validator;
- struct MaskInputData {
- enum Casemode { NoCaseMode, Upper, Lower };
- QChar maskChar; // either the separator char or the inputmask
- bool separator;
- Casemode caseMode;
- };
- QString inputMask;
- QChar blank;
- MaskInputData *maskData;
- inline int nextMaskBlank(int pos) {
- int c = findInMask(pos, true, false);
- separator |= (c != pos);
- return (c != -1 ? c : maxLength);
- }
- inline int prevMaskBlank(int pos) {
- int c = findInMask(pos, false, false);
- separator |= (c != pos);
- return (c != -1 ? c : 0);
- }
-
- void setCursorVisible(bool visible);
-
-
- // undo/redo handling
- enum CommandType { Separator, Insert, Remove, Delete, RemoveSelection, DeleteSelection, SetSelection };
- struct Command {
- inline Command() {}
- inline Command(CommandType t, int p, QChar c, int ss, int se) : type(t),uc(c),pos(p),selStart(ss),selEnd(se) {}
- uint type : 4;
- QChar uc;
- int pos, selStart, selEnd;
- };
- int modifiedState;
- int undoState;
- QVector<Command> history;
- void addCommand(const Command& cmd);
- void insert(const QString& s);
- void del(bool wasBackspace = false);
- void remove(int pos);
-
- inline void separate() { separator = true; }
- void undo(int until = -1);
- void redo();
- inline bool isUndoAvailable() const { return !readOnly && undoState; }
- inline bool isRedoAvailable() const { return !readOnly && undoState < (int)history.size(); }
-
- // selection
- int selstart, selend;
- inline bool allSelected() const { return !text.isEmpty() && selstart == 0 && selend == (int)text.length(); }
- inline bool hasSelectedText() const { return !text.isEmpty() && selend > selstart; }
- inline void deselect() { selDirty |= (selend > selstart); selstart = selend = 0; }
- void removeSelectedText();
-#ifndef QT_NO_CLIPBOARD
- void copy(bool clipboard = true) const;
-#endif
- inline bool inSelection(int x) const
- { if (selstart >= selend) return false;
- int pos = xToPos(x, QTextLine::CursorOnCharacter); return pos >= selstart && pos < selend; }
-
- // masking
- void parseInputMask(const QString &maskFields);
- bool isValidInput(QChar key, QChar mask) const;
- bool hasAcceptableInput(const QString &text) const;
- QString maskString(uint pos, const QString &str, bool clear = false) const;
- QString clearString(uint pos, uint len) const;
- QString stripString(const QString &str) const;
- int findInMask(int pos, bool forward, bool findSeparator, QChar searchChar = QChar()) const;
-
- // input methods
- bool composeMode() const { return !textLayout.preeditAreaText().isEmpty(); }
-
- // complex text layout
- QTextLayout textLayout;
- void updateTextLayout();
- void moveCursor(int pos, bool mark = false);
- void setText(const QString& txt, int pos = -1, bool edited = true);
- int xToPos(int x, QTextLine::CursorPosition = QTextLine::CursorBetweenCharacters) const;
- QRect cursorRect() const;
- bool fixup();
-
QRect adjustedContentsRect() const;
-#ifndef QT_NO_DRAGANDDROP
- // drag and drop
- QPoint dndPos;
- QBasicTimer dndTimer;
- void drag();
-#endif
-
+ void _q_clipboardChanged();
void _q_handleWindowActivate();
void _q_deleteSelected();
- bool userInput;
- bool emitingEditingFinished;
-
-#ifdef QT_KEYPAD_NAVIGATION
- QBasicTimer deleteAllTimer; // keypad navigation
- QString origText;
-#endif
-
- bool passwordEchoEditing;
- void updatePasswordEchoEditing(bool editing);
+ void _q_textEdited(const QString &);
+ void _q_cursorPositionChanged(int, int);
#ifndef QT_NO_COMPLETER
- QPointer<QCompleter> completer;
- void complete(int key = -1);
void _q_completionHighlighted(QString);
- bool advanceToEnabledItem(int n);
+#endif
+#ifndef QT_NO_DRAGANDDROP
+ QPoint dndPos;
+ QBasicTimer dndTimer;
+ void drag();
#endif
int leftTextMargin;