qlineedit.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QLINEEDIT_H
00043 #define QLINEEDIT_H
00044 
00045 #include <QtGui/qframe.h>
00046 #include <QtCore/qstring.h>
00047 #include <QtCore/qmargins.h>
00048 
00049 QT_BEGIN_HEADER
00050 
00051 QT_BEGIN_NAMESPACE
00052 
00053 QT_MODULE(Gui)
00054 
00055 #ifndef QT_NO_LINEEDIT
00056 
00057 class QValidator;
00058 class QMenu;
00059 class QLineEditPrivate;
00060 class QCompleter;
00061 class QStyleOptionFrame;
00062 class QAbstractSpinBox;
00063 class QDateTimeEdit;
00064 
00065 class Q_GUI_EXPORT QLineEdit : public QWidget
00066 {
00067     Q_OBJECT
00068 
00069     Q_ENUMS(EchoMode)
00070     Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask)
00071     Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true)
00072     Q_PROPERTY(int maxLength READ maxLength WRITE setMaxLength)
00073     Q_PROPERTY(bool frame READ hasFrame WRITE setFrame)
00074     Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode)
00075     Q_PROPERTY(QString displayText READ displayText)
00076     Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition)
00077     Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
00078     Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
00079     Q_PROPERTY(bool hasSelectedText READ hasSelectedText)
00080     Q_PROPERTY(QString selectedText READ selectedText)
00081     Q_PROPERTY(bool dragEnabled READ dragEnabled WRITE setDragEnabled)
00082     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
00083     Q_PROPERTY(bool undoAvailable READ isUndoAvailable)
00084     Q_PROPERTY(bool redoAvailable READ isRedoAvailable)
00085     Q_PROPERTY(bool acceptableInput READ hasAcceptableInput)
00086     Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
00087 
00088 public:
00089     explicit QLineEdit(QWidget* parent=0);
00090     explicit QLineEdit(const QString &, QWidget* parent=0);
00091 #ifdef QT3_SUPPORT
00092     QT3_SUPPORT_CONSTRUCTOR QLineEdit(QWidget* parent, const char* name);
00093     QT3_SUPPORT_CONSTRUCTOR QLineEdit(const QString &, QWidget* parent, const char* name);
00094     QT3_SUPPORT_CONSTRUCTOR QLineEdit(const QString &, const QString &, QWidget* parent=0, const char* name=0);
00095 #endif
00096     ~QLineEdit();
00097 
00098     QString text() const;
00099 
00100     QString displayText() const;
00101 
00102     QString placeholderText() const;
00103     void setPlaceholderText(const QString &);
00104 
00105     int maxLength() const;
00106     void setMaxLength(int);
00107 
00108     void setFrame(bool);
00109     bool hasFrame() const;
00110 
00111     enum EchoMode { Normal, NoEcho, Password, PasswordEchoOnEdit };
00112     EchoMode echoMode() const;
00113     void setEchoMode(EchoMode);
00114 
00115     bool isReadOnly() const;
00116     void setReadOnly(bool);
00117 
00118 #ifndef QT_NO_VALIDATOR
00119     void setValidator(const QValidator *);
00120     const QValidator * validator() const;
00121 #endif
00122 
00123 #ifndef QT_NO_COMPLETER
00124     void setCompleter(QCompleter *completer);
00125     QCompleter *completer() const;
00126 #endif
00127 
00128     QSize sizeHint() const;
00129     QSize minimumSizeHint() const;
00130 
00131     int cursorPosition() const;
00132     void setCursorPosition(int);
00133     int cursorPositionAt(const QPoint &pos);
00134 
00135     void setAlignment(Qt::Alignment flag);
00136     Qt::Alignment alignment() const;
00137 
00138     void cursorForward(bool mark, int steps = 1);
00139     void cursorBackward(bool mark, int steps = 1);
00140     void cursorWordForward(bool mark);
00141     void cursorWordBackward(bool mark);
00142     void backspace();
00143     void del();
00144     void home(bool mark);
00145     void end(bool mark);
00146 
00147     bool isModified() const;
00148     void setModified(bool);
00149 
00150     void setSelection(int, int);
00151     bool hasSelectedText() const;
00152     QString selectedText() const;
00153     int selectionStart() const;
00154 
00155     bool isUndoAvailable() const;
00156     bool isRedoAvailable() const;
00157 
00158     void setDragEnabled(bool b);
00159     bool dragEnabled() const;
00160 
00161     QString inputMask() const;
00162     void setInputMask(const QString &inputMask);
00163     bool hasAcceptableInput() const;
00164 
00165     void setTextMargins(int left, int top, int right, int bottom);
00166     void setTextMargins(const QMargins &margins);
00167     void getTextMargins(int *left, int *top, int *right, int *bottom) const;
00168     QMargins textMargins() const;
00169 
00170 public Q_SLOTS:
00171     void setText(const QString &);
00172     void clear();
00173     void selectAll();
00174     void undo();
00175     void redo();
00176 #ifndef QT_NO_CLIPBOARD
00177     void cut();
00178     void copy() const;
00179     void paste();
00180 #endif
00181 
00182 public:
00183     void deselect();
00184     void insert(const QString &);
00185 #ifndef QT_NO_CONTEXTMENU
00186     QMenu *createStandardContextMenu();
00187 #endif
00188 
00189 Q_SIGNALS:
00190     void textChanged(const QString &);
00191     void textEdited(const QString &);
00192     void cursorPositionChanged(int, int);
00193     void returnPressed();
00194     void editingFinished();
00195     void selectionChanged();
00196 
00197 protected:
00198     void mousePressEvent(QMouseEvent *);
00199     void mouseMoveEvent(QMouseEvent *);
00200     void mouseReleaseEvent(QMouseEvent *);
00201     void mouseDoubleClickEvent(QMouseEvent *);
00202     void keyPressEvent(QKeyEvent *);
00203     void focusInEvent(QFocusEvent *);
00204     void focusOutEvent(QFocusEvent *);
00205     void paintEvent(QPaintEvent *);
00206 #ifndef QT_NO_DRAGANDDROP
00207     void dragEnterEvent(QDragEnterEvent *);
00208     void dragMoveEvent(QDragMoveEvent *e);
00209     void dragLeaveEvent(QDragLeaveEvent *e);
00210     void dropEvent(QDropEvent *);
00211 #endif
00212     void changeEvent(QEvent *);
00213 #ifndef QT_NO_CONTEXTMENU
00214     void contextMenuEvent(QContextMenuEvent *);
00215 #endif
00216 #ifdef QT3_SUPPORT
00217     inline QT3_SUPPORT void repaintArea(int, int) { update(); }
00218 #endif
00219 
00220     void inputMethodEvent(QInputMethodEvent *);
00221     void initStyleOption(QStyleOptionFrame *option) const;
00222 public:
00223     QVariant inputMethodQuery(Qt::InputMethodQuery) const;
00224     bool event(QEvent *);
00225 protected:
00226     QRect cursorRect() const;
00227 
00228 public:
00229 #ifdef QT3_SUPPORT
00230     inline QT3_SUPPORT void clearModified() { setModified(false); }
00231     inline QT3_SUPPORT void cursorLeft(bool mark, int steps = 1) { cursorForward(mark, -steps); }
00232     inline QT3_SUPPORT void cursorRight(bool mark, int steps = 1) { cursorForward(mark, steps); }
00233     QT3_SUPPORT bool validateAndSet(const QString &, int, int, int);
00234     inline QT3_SUPPORT bool frame() const { return hasFrame(); }
00235 #ifndef QT_NO_VALIDATOR
00236     inline QT3_SUPPORT void clearValidator() { setValidator(0); }
00237 #endif
00238     inline QT3_SUPPORT bool hasMarkedText() const { return hasSelectedText(); }
00239     inline QT3_SUPPORT QString markedText() const { return selectedText(); }
00240     QT3_SUPPORT bool edited() const;
00241     QT3_SUPPORT void setEdited(bool);
00242     QT3_SUPPORT int characterAt(int, QChar*) const;
00243     QT3_SUPPORT bool getSelection(int *, int *);
00244 
00245     QT3_SUPPORT void setFrameRect(QRect) {}
00246     QT3_SUPPORT QRect frameRect() const { return QRect(); }
00247     enum DummyFrame { Box, Sunken, Plain, Raised, MShadow, NoFrame, Panel, StyledPanel,
00248                       HLine, VLine, GroupBoxPanel, WinPanel, ToolBarPanel, MenuBarPanel,
00249                       PopupPanel, LineEditPanel, TabWidgetPanel, MShape };
00250     QT3_SUPPORT void setFrameShadow(DummyFrame) {}
00251     QT3_SUPPORT DummyFrame frameShadow() const { return Plain; }
00252     QT3_SUPPORT void setFrameShape(DummyFrame) {}
00253     QT3_SUPPORT DummyFrame frameShape() const { return NoFrame; }
00254     QT3_SUPPORT void setFrameStyle(int) {}
00255     QT3_SUPPORT int frameStyle() const  { return 0; }
00256     QT3_SUPPORT int frameWidth() const { return 0; }
00257     QT3_SUPPORT void setLineWidth(int) {}
00258     QT3_SUPPORT int lineWidth() const { return 0; }
00259     QT3_SUPPORT void setMargin(int margin) { setContentsMargins(margin, margin, margin, margin); }
00260     QT3_SUPPORT int margin() const
00261     { int margin; int dummy; getContentsMargins(&margin, &dummy, &dummy, &dummy);  return margin; }
00262     QT3_SUPPORT void setMidLineWidth(int) {}
00263     QT3_SUPPORT int midLineWidth() const { return 0; }
00264 
00265 Q_SIGNALS:
00266     QT_MOC_COMPAT void lostFocus();
00267 #endif
00268 
00269 private:
00270     friend class QAbstractSpinBox;
00271 #ifdef QT_KEYPAD_NAVIGATION
00272     friend class QDateTimeEdit;
00273 #endif
00274     Q_DISABLE_COPY(QLineEdit)
00275     Q_DECLARE_PRIVATE(QLineEdit)
00276     Q_PRIVATE_SLOT(d_func(), void _q_handleWindowActivate())
00277     Q_PRIVATE_SLOT(d_func(), void _q_textEdited(const QString &))
00278     Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged(int, int))
00279 #ifndef QT_NO_COMPLETER
00280     Q_PRIVATE_SLOT(d_func(), void _q_completionHighlighted(QString))
00281 #endif
00282 #ifdef QT_KEYPAD_NAVIGATION
00283     Q_PRIVATE_SLOT(d_func(), void _q_editFocusChange(bool))
00284 #endif
00285     Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged())
00286 };
00287 
00288 #endif // QT_NO_LINEEDIT
00289 
00290 QT_END_NAMESPACE
00291 
00292 QT_END_HEADER
00293 
00294 #endif // QLINEEDIT_H