util/src/gui/widgets/qlineedit.h
changeset 7 f7bc934e204c
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 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 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 QLINEEDIT_H
       
    43 #define QLINEEDIT_H
       
    44 
       
    45 #include <QtGui/qframe.h>
       
    46 #include <QtCore/qstring.h>
       
    47 #include <QtCore/qmargins.h>
       
    48 
       
    49 QT_BEGIN_HEADER
       
    50 
       
    51 QT_BEGIN_NAMESPACE
       
    52 
       
    53 QT_MODULE(Gui)
       
    54 
       
    55 #ifndef QT_NO_LINEEDIT
       
    56 
       
    57 class QValidator;
       
    58 class QMenu;
       
    59 class QLineEditPrivate;
       
    60 class QCompleter;
       
    61 class QStyleOptionFrame;
       
    62 class QAbstractSpinBox;
       
    63 class QDateTimeEdit;
       
    64 
       
    65 class Q_GUI_EXPORT QLineEdit : public QWidget
       
    66 {
       
    67     Q_OBJECT
       
    68 
       
    69     Q_ENUMS(EchoMode)
       
    70     Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask)
       
    71     Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true)
       
    72     Q_PROPERTY(int maxLength READ maxLength WRITE setMaxLength)
       
    73     Q_PROPERTY(bool frame READ hasFrame WRITE setFrame)
       
    74     Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode)
       
    75     Q_PROPERTY(QString displayText READ displayText)
       
    76     Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition)
       
    77     Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
       
    78     Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
       
    79     Q_PROPERTY(bool hasSelectedText READ hasSelectedText)
       
    80     Q_PROPERTY(QString selectedText READ selectedText)
       
    81     Q_PROPERTY(bool dragEnabled READ dragEnabled WRITE setDragEnabled)
       
    82     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
       
    83     Q_PROPERTY(bool undoAvailable READ isUndoAvailable)
       
    84     Q_PROPERTY(bool redoAvailable READ isRedoAvailable)
       
    85     Q_PROPERTY(bool acceptableInput READ hasAcceptableInput)
       
    86 // ### Qt 4.7: remove this #if guard
       
    87 #if (QT_VERSION >= 0x407000) || defined(Q_WS_MAEMO_5)
       
    88     Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
       
    89 #endif
       
    90 
       
    91 public:
       
    92     explicit QLineEdit(QWidget* parent=0);
       
    93     explicit QLineEdit(const QString &, QWidget* parent=0);
       
    94 #ifdef QT3_SUPPORT
       
    95     QT3_SUPPORT_CONSTRUCTOR QLineEdit(QWidget* parent, const char* name);
       
    96     QT3_SUPPORT_CONSTRUCTOR QLineEdit(const QString &, QWidget* parent, const char* name);
       
    97     QT3_SUPPORT_CONSTRUCTOR QLineEdit(const QString &, const QString &, QWidget* parent=0, const char* name=0);
       
    98 #endif
       
    99     ~QLineEdit();
       
   100 
       
   101     QString text() const;
       
   102 
       
   103     QString displayText() const;
       
   104 
       
   105 // ### Qt 4.7: remove this #if guard
       
   106 #if (QT_VERSION >= 0x407000) || defined(Q_WS_MAEMO_5)
       
   107     QString placeholderText() const;
       
   108     void setPlaceholderText(const QString &);
       
   109 #endif
       
   110 
       
   111     int maxLength() const;
       
   112     void setMaxLength(int);
       
   113 
       
   114     void setFrame(bool);
       
   115     bool hasFrame() const;
       
   116 
       
   117     enum EchoMode { Normal, NoEcho, Password, PasswordEchoOnEdit };
       
   118     EchoMode echoMode() const;
       
   119     void setEchoMode(EchoMode);
       
   120 
       
   121     bool isReadOnly() const;
       
   122     void setReadOnly(bool);
       
   123 
       
   124 #ifndef QT_NO_VALIDATOR
       
   125     void setValidator(const QValidator *);
       
   126     const QValidator * validator() const;
       
   127 #endif
       
   128 
       
   129 #ifndef QT_NO_COMPLETER
       
   130     void setCompleter(QCompleter *completer);
       
   131     QCompleter *completer() const;
       
   132 #endif
       
   133 
       
   134     QSize sizeHint() const;
       
   135     QSize minimumSizeHint() const;
       
   136 
       
   137     int cursorPosition() const;
       
   138     void setCursorPosition(int);
       
   139     int cursorPositionAt(const QPoint &pos);
       
   140 
       
   141     void setAlignment(Qt::Alignment flag);
       
   142     Qt::Alignment alignment() const;
       
   143 
       
   144     void cursorForward(bool mark, int steps = 1);
       
   145     void cursorBackward(bool mark, int steps = 1);
       
   146     void cursorWordForward(bool mark);
       
   147     void cursorWordBackward(bool mark);
       
   148     void backspace();
       
   149     void del();
       
   150     void home(bool mark);
       
   151     void end(bool mark);
       
   152 
       
   153     bool isModified() const;
       
   154     void setModified(bool);
       
   155 
       
   156     void setSelection(int, int);
       
   157     bool hasSelectedText() const;
       
   158     QString selectedText() const;
       
   159     int selectionStart() const;
       
   160 
       
   161     bool isUndoAvailable() const;
       
   162     bool isRedoAvailable() const;
       
   163 
       
   164     void setDragEnabled(bool b);
       
   165     bool dragEnabled() const;
       
   166 
       
   167     QString inputMask() const;
       
   168     void setInputMask(const QString &inputMask);
       
   169     bool hasAcceptableInput() const;
       
   170 
       
   171     void setTextMargins(int left, int top, int right, int bottom);
       
   172     void setTextMargins(const QMargins &margins);
       
   173     void getTextMargins(int *left, int *top, int *right, int *bottom) const;
       
   174     QMargins textMargins() const;
       
   175 
       
   176 public Q_SLOTS:
       
   177     void setText(const QString &);
       
   178     void clear();
       
   179     void selectAll();
       
   180     void undo();
       
   181     void redo();
       
   182 #ifndef QT_NO_CLIPBOARD
       
   183     void cut();
       
   184     void copy() const;
       
   185     void paste();
       
   186 #endif
       
   187 
       
   188 public:
       
   189     void deselect();
       
   190     void insert(const QString &);
       
   191 #ifndef QT_NO_CONTEXTMENU
       
   192     QMenu *createStandardContextMenu();
       
   193 #endif
       
   194 
       
   195 Q_SIGNALS:
       
   196     void textChanged(const QString &);
       
   197     void textEdited(const QString &);
       
   198     void cursorPositionChanged(int, int);
       
   199     void returnPressed();
       
   200     void editingFinished();
       
   201     void selectionChanged();
       
   202 
       
   203 protected:
       
   204     void mousePressEvent(QMouseEvent *);
       
   205     void mouseMoveEvent(QMouseEvent *);
       
   206     void mouseReleaseEvent(QMouseEvent *);
       
   207     void mouseDoubleClickEvent(QMouseEvent *);
       
   208     void keyPressEvent(QKeyEvent *);
       
   209     void focusInEvent(QFocusEvent *);
       
   210     void focusOutEvent(QFocusEvent *);
       
   211     void paintEvent(QPaintEvent *);
       
   212 #ifndef QT_NO_DRAGANDDROP
       
   213     void dragEnterEvent(QDragEnterEvent *);
       
   214     void dragMoveEvent(QDragMoveEvent *e);
       
   215     void dragLeaveEvent(QDragLeaveEvent *e);
       
   216     void dropEvent(QDropEvent *);
       
   217 #endif
       
   218     void changeEvent(QEvent *);
       
   219 #ifndef QT_NO_CONTEXTMENU
       
   220     void contextMenuEvent(QContextMenuEvent *);
       
   221 #endif
       
   222 #ifdef QT3_SUPPORT
       
   223     inline QT3_SUPPORT void repaintArea(int, int) { update(); }
       
   224 #endif
       
   225 
       
   226     void inputMethodEvent(QInputMethodEvent *);
       
   227     void initStyleOption(QStyleOptionFrame *option) const;
       
   228 public:
       
   229     QVariant inputMethodQuery(Qt::InputMethodQuery) const;
       
   230     bool event(QEvent *);
       
   231 protected:
       
   232     QRect cursorRect() const;
       
   233 
       
   234 public:
       
   235 #ifdef QT3_SUPPORT
       
   236     inline QT3_SUPPORT void clearModified() { setModified(false); }
       
   237     inline QT3_SUPPORT void cursorLeft(bool mark, int steps = 1) { cursorForward(mark, -steps); }
       
   238     inline QT3_SUPPORT void cursorRight(bool mark, int steps = 1) { cursorForward(mark, steps); }
       
   239     QT3_SUPPORT bool validateAndSet(const QString &, int, int, int);
       
   240     inline QT3_SUPPORT bool frame() const { return hasFrame(); }
       
   241 #ifndef QT_NO_VALIDATOR
       
   242     inline QT3_SUPPORT void clearValidator() { setValidator(0); }
       
   243 #endif
       
   244     inline QT3_SUPPORT bool hasMarkedText() const { return hasSelectedText(); }
       
   245     inline QT3_SUPPORT QString markedText() const { return selectedText(); }
       
   246     QT3_SUPPORT bool edited() const;
       
   247     QT3_SUPPORT void setEdited(bool);
       
   248     QT3_SUPPORT int characterAt(int, QChar*) const;
       
   249     QT3_SUPPORT bool getSelection(int *, int *);
       
   250 
       
   251     QT3_SUPPORT void setFrameRect(QRect) {}
       
   252     QT3_SUPPORT QRect frameRect() const { return QRect(); }
       
   253     enum DummyFrame { Box, Sunken, Plain, Raised, MShadow, NoFrame, Panel, StyledPanel,
       
   254                       HLine, VLine, GroupBoxPanel, WinPanel, ToolBarPanel, MenuBarPanel,
       
   255                       PopupPanel, LineEditPanel, TabWidgetPanel, MShape };
       
   256     QT3_SUPPORT void setFrameShadow(DummyFrame) {}
       
   257     QT3_SUPPORT DummyFrame frameShadow() const { return Plain; }
       
   258     QT3_SUPPORT void setFrameShape(DummyFrame) {}
       
   259     QT3_SUPPORT DummyFrame frameShape() const { return NoFrame; }
       
   260     QT3_SUPPORT void setFrameStyle(int) {}
       
   261     QT3_SUPPORT int frameStyle() const  { return 0; }
       
   262     QT3_SUPPORT int frameWidth() const { return 0; }
       
   263     QT3_SUPPORT void setLineWidth(int) {}
       
   264     QT3_SUPPORT int lineWidth() const { return 0; }
       
   265     QT3_SUPPORT void setMargin(int margin) { setContentsMargins(margin, margin, margin, margin); }
       
   266     QT3_SUPPORT int margin() const
       
   267     { int margin; int dummy; getContentsMargins(&margin, &dummy, &dummy, &dummy);  return margin; }
       
   268     QT3_SUPPORT void setMidLineWidth(int) {}
       
   269     QT3_SUPPORT int midLineWidth() const { return 0; }
       
   270 
       
   271 Q_SIGNALS:
       
   272     QT_MOC_COMPAT void lostFocus();
       
   273 #endif
       
   274 
       
   275 private:
       
   276     friend class QAbstractSpinBox;
       
   277 #ifdef QT_KEYPAD_NAVIGATION
       
   278     friend class QDateTimeEdit;
       
   279 #endif
       
   280     Q_DISABLE_COPY(QLineEdit)
       
   281     Q_DECLARE_PRIVATE(QLineEdit)
       
   282     Q_PRIVATE_SLOT(d_func(), void _q_handleWindowActivate())
       
   283     Q_PRIVATE_SLOT(d_func(), void _q_textEdited(const QString &))
       
   284     Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged(int, int))
       
   285 #ifndef QT_NO_COMPLETER
       
   286     Q_PRIVATE_SLOT(d_func(), void _q_completionHighlighted(QString))
       
   287 #endif
       
   288 #ifdef QT_KEYPAD_NAVIGATION
       
   289     Q_PRIVATE_SLOT(d_func(), void _q_editFocusChange(bool))
       
   290 #endif
       
   291     Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged())
       
   292 };
       
   293 
       
   294 #endif // QT_NO_LINEEDIT
       
   295 
       
   296 QT_END_NAMESPACE
       
   297 
       
   298 QT_END_HEADER
       
   299 
       
   300 #endif // QLINEEDIT_H