ScrollableLineEdit.h

Go to the documentation of this file.
00001 /*
00002  * The source code of this class comes from Qt (qt-x11/qt-2.3.2/src/widgets/qlineedit.h/cpp).
00003  * It's been slightly modified to allow scrollRight() and scrollLeft() features.
00004  * This was needed because the API doesn't allow to retrieve the offset.
00005  * If there is a better way to implement that, suggestions are welcome.
00006  *
00007  */
00008 
00009 
00010 /**********************************************************************
00011 ** $Id: qt/src/widgets/qlineedit.h   2.3.3   edited 2001-04-04 $
00012 **
00013 ** Definition of ScrollableLineEdit widget class
00014 **
00015 ** Created : 941011
00016 **
00017 ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
00018 **
00019 ** This file is part of the widgets module of the Qt GUI Toolkit.
00020 **
00021 ** This file may be distributed under the terms of the Q Public License
00022 ** as defined by Trolltech AS of Norway and appearing in the file
00023 ** LICENSE.QPL included in the packaging of this file.
00024 **
00025 ** This file may be distributed and/or modified under the terms of the
00026 ** GNU General Public License version 2 as published by the Free Software
00027 ** Foundation and appearing in the file LICENSE.GPL included in the
00028 ** packaging of this file.
00029 **
00030 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00031 ** licenses may use this file in accordance with the Qt Commercial License
00032 ** Agreement provided with the Software.
00033 **
00034 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00035 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00036 **
00037 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00038 **   information about Qt Commercial License Agreements.
00039 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00040 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00041 **
00042 ** Contact info@trolltech.com if any conditions of this licensing are
00043 ** not clear to you.
00044 **
00045 **********************************************************************/
00046 
00047 #ifndef SCROLLABLE_LINEEDIT_H
00048 #define SCROLLABLE_LINEEDIT_H
00049 
00050 struct ScrollableLineEditPrivate;
00051 
00052 class QComboBox;
00053 class QValidator;
00054 
00055 
00056 #ifndef QT_H
00057 #include "qwidget.h"
00058 #include "qstring.h"
00059 #include <iostream.h>
00060 #endif // QT_H
00061 
00062 #ifndef QT_NO_LINEEDIT
00063 
00064 class Q_EXPORT ScrollableLineEdit : public QWidget
00065 {
00066     Q_OBJECT
00067     Q_ENUMS( EchoMode )
00068     Q_PROPERTY( QString text READ text WRITE setText )
00069     Q_PROPERTY( int maxLength READ maxLength WRITE setMaxLength )
00070     Q_PROPERTY( bool frame READ frame WRITE setFrame )
00071     Q_PROPERTY( EchoMode echoMode READ echoMode WRITE setEchoMode )
00072     Q_PROPERTY( QString displayText READ displayText )
00073     Q_PROPERTY( int cursorPosition READ cursorPosition WRITE setCursorPosition )
00074     Q_PROPERTY( Alignment alignment READ alignment WRITE setAlignment )
00075     Q_PROPERTY( bool edited READ edited WRITE setEdited )
00076     Q_PROPERTY( bool hasMarkedText READ hasMarkedText )
00077     Q_PROPERTY( QString markedText READ markedText )
00078     
00079 public:
00080     ScrollableLineEdit( QWidget *parent, const char *name=0 );
00081     ScrollableLineEdit( const QString &, QWidget *parent, const char *name=0 );
00082    ~ScrollableLineEdit();
00083 
00084     QString text() const;
00085 
00086     QString displayText() const;
00087 
00088     int     maxLength() const;
00089     virtual void setMaxLength( int );
00090 
00091     virtual void setFrame( bool );
00092     bool    frame() const;
00093 
00094     enum    EchoMode { Normal, NoEcho, Password };
00095     virtual void setEchoMode( EchoMode );
00096     EchoMode    echoMode() const;
00097 #if QT_VERSION >= 300
00098 #error "Make setReadOnly virtual"
00099 #endif
00100     void setReadOnly( bool );
00101     bool isReadOnly() const;
00102 
00103     virtual void setValidator( const QValidator * );
00104     const QValidator * validator() const;
00105 
00106     QSize   sizeHint() const;
00107     QSize   minimumSizeHint() const;
00108     QSizePolicy sizePolicy() const;
00109 
00110     virtual void setEnabled( bool );
00111     virtual void setFont( const QFont & );
00112     virtual void setPalette( const QPalette & );
00113     virtual void setSelection( int, int );
00114 
00115     virtual void setCursorPosition( int );
00116     int     cursorPosition() const;
00117 
00118     bool    validateAndSet( const QString &, int, int, int );
00119 
00120 #ifndef QT_NO_CLIPBOARD
00121     void    cut();
00122     void    copy() const;
00123     void    paste();
00124 #endif
00125 
00126     void setAlignment( int flag );
00127     int alignment() const;
00128 
00129     void    cursorLeft( bool mark, int steps = 1 );
00130     void    cursorRight( bool mark, int steps = 1 );
00131     void    cursorWordForward( bool mark );
00132     void    cursorWordBackward( bool mark );
00133     void    backspace();
00134     void    del();
00135     void    home( bool mark );
00136     void    end( bool mark );
00137 
00138     void    setEdited( bool );
00139     bool    edited() const;
00140 
00141     bool    hasMarkedText() const;
00142     QString markedText() const;
00143 #if defined(Q_INCOMPATIBLE_3_0_ADDONS)
00144     bool    getSelection( int *start, int *end );
00145     void    setPasswordChar( QChar c );
00146     QChar   passwordChar() const;
00147 #endif    
00148 
00149 public slots:
00150     virtual void setText( const QString &);
00151 
00152     void    selectAll();
00153     void    deselect();
00154 
00155     void    clearValidator();
00156 
00157     void    insert( const QString &);
00158 
00159     void    clear();
00160 
00161     void    scrollLeft(); // For toMOTko.
00162     void    scrollRight(); // For toMOTko.
00163 
00164 signals:
00165     void    textChanged( const QString &);
00166     void    returnPressed();
00167 
00168 protected:
00169     bool    event( QEvent * );
00170     void    mousePressEvent( QMouseEvent * );
00171     void    mouseMoveEvent( QMouseEvent * );
00172     void    mouseReleaseEvent( QMouseEvent * );
00173     void    mouseDoubleClickEvent( QMouseEvent * );
00174     void    keyPressEvent( QKeyEvent * );
00175     void    focusInEvent( QFocusEvent * );
00176     void    focusOutEvent( QFocusEvent * );
00177     void    paintEvent( QPaintEvent * );
00178     void    resizeEvent( QResizeEvent * );
00179     void    leaveEvent( QEvent * );
00180 #ifndef QT_NO_DRAGANDDROP
00181     void    dragEnterEvent( QDragEnterEvent * );
00182     void    dropEvent( QDropEvent * );
00183 #endif
00184 
00185     void    repaintArea( int, int );
00186 
00187     void    keyReleaseEvent( QKeyEvent * ); // For toMOTko.
00188 
00189 private slots:
00190     void    clipboardChanged();
00191     void    blinkSlot();
00192     void    dragScrollSlot();
00193 
00194 //#ifndef QT_NO_DRAGANDDROP
00195 //    void    doDrag();
00196 //#endif
00197 
00198 private:
00199     // kept
00200     void    newMark( int pos, bool copy=TRUE );
00201     void    markWord( int pos );
00202     int     lastCharVisible() const;
00203     int     minMark() const;
00204     int     maxMark() const;
00205     int     frameW() const;
00206 
00207     void    init();
00208 
00209     QString tbuf;
00210     ScrollableLineEditPrivate * d;
00211     int     cursorPos;
00212     int     offset;
00213     int     maxLen;
00214     int     markAnchor;
00215     int     markDrag;
00216     bool    cursorOn;
00217     bool    dragScrolling;
00218     bool    scrollingLeft;
00219     int     alignmentFlag;
00220     bool    ed;
00221 
00222     void updateOffset();
00223     int xPosToCursorPos( int ) const;
00224     void blinkOn();
00225     void makePixmap() const;
00226     void undoInternal();
00227     void redoInternal();
00228 
00229 private:    // Disabled copy constructor and operator=
00230 #if defined(Q_DISABLE_COPY)
00231     ScrollableLineEdit( const ScrollableLineEdit & );
00232     ScrollableLineEdit &operator=( const ScrollableLineEdit & );
00233 #endif
00234 };
00235 
00236 #endif // QT_NO_LINEEDIT
00237 
00238 #endif // QLINEEDIT_H

Generated on Sun Mar 1 17:30:47 2009 for toMOTko by  doxygen 1.5.6