klineedit.h

00001 /*  This file is part of the KDE libraries
00002 
00003     This class was originally inspired by Torben Weis'
00004     fileentry.cpp for KFM II.
00005 
00006     Copyright (C) 1997 Sven Radej <sven.radej@iname.com>
00007     Copyright (c) 1999 Patrick Ward <PAT_WARD@HP-USA-om5.om.hp.com>
00008     Copyright (c) 1999 Preston Brown <pbrown@kde.org>
00009 
00010     Completely re-designed:
00011     Copyright (c) 2000,2001 Dawit Alemayehu <adawit@kde.org>
00012 
00013     This library is free software; you can redistribute it and/or
00014     modify it under the terms of the GNU Lesser General Public
00015     License (LGPL) as published by the Free Software Foundation;
00016     either version 2 of the License, or (at your option) any later
00017     version.
00018 
00019     This library is distributed in the hope that it will be useful,
00020     but WITHOUT ANY WARRANTY; without even the implied warranty of
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022     Lesser General Public License for more details.
00023 
00024     You should have received a copy of the GNU Lesser General Public License
00025     along with this library; see the file COPYING.LIB.  If not, write to
00026     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00027     Boston, MA 02110-1301, USA.
00028 */
00029 
00030 #ifndef _KLINEEDIT_H
00031 #define _KLINEEDIT_H
00032 
00033 #include <qlineedit.h>
00034 #include <kcompletion.h>
00035 
00036 class QPopupMenu;
00037 
00038 class KCompletionBox;
00039 class KURL;
00040 
00145 class KDEUI_EXPORT KLineEdit : public QLineEdit, public KCompletionBase
00146 {
00147     friend class KComboBox;
00148 
00149     Q_OBJECT
00150     Q_PROPERTY( bool contextMenuEnabled READ isContextMenuEnabled WRITE setContextMenuEnabled )
00151     Q_PROPERTY( bool urlDropsEnabled READ isURLDropsEnabled WRITE setURLDropsEnabled )
00152     Q_PROPERTY( bool trapEnterKeyEvent READ trapReturnKey WRITE setTrapReturnKey )
00153     Q_PROPERTY( bool enableSqueezedText READ isSqueezedTextEnabled WRITE setEnableSqueezedText )
00154 
00155 public:
00156 
00165     KLineEdit( const QString &string, QWidget *parent, const char *name = 0 );
00166 
00173     KLineEdit ( QWidget *parent=0, const char *name=0 );
00174 
00178     virtual ~KLineEdit ();
00179 
00184     void setURL( const KURL& url );
00185 
00195     void cursorAtEnd() { end( false ); }
00196 
00205     virtual void setCompletionMode( KGlobalSettings::Completion mode );
00206 
00221     virtual void setContextMenuEnabled( bool showMenu ) {  m_bEnableMenu = showMenu; }
00222 
00226     bool isContextMenuEnabled() const { return m_bEnableMenu; }
00227 
00235     void setURLDropsEnabled( bool enable );
00236 
00240     bool isURLDropsEnabled() const;
00241 
00252     void setTrapReturnKey( bool trap );
00253 
00260     bool trapReturnKey() const;
00261 
00266     virtual bool eventFilter( QObject *, QEvent * );
00267 
00276     KCompletionBox * completionBox( bool create = true );
00277 
00281     virtual void setCompletionObject( KCompletion *, bool hsig = true );
00282 
00286     virtual void copy() const;
00287 
00299     void setEnableSqueezedText( bool enable );
00300 
00307     bool isSqueezedTextEnabled() const;
00308 
00317     QString originalText() const;
00318 
00327     void setCompletionBox( KCompletionBox *box );
00328 
00329 signals:
00330 
00335     void completionBoxActivated (const QString &);
00336 
00344     void returnPressed( const QString& );
00345 
00353     void completion( const QString& );
00354 
00358     void substringCompletion( const QString& );
00359 
00372     void textRotation( KCompletionBase::KeyBindingType );
00373 
00378     void completionModeChanged( KGlobalSettings::Completion );
00379 
00392     void aboutToShowContextMenu( QPopupMenu * p );
00393 
00394 public slots:
00395 
00399     virtual void setReadOnly(bool);
00400 
00411     void rotateText( KCompletionBase::KeyBindingType type );
00412 
00416     virtual void setCompletedText( const QString& );
00417 
00424     void setCompletedItems( const QStringList& items );
00425 
00436     void setCompletedItems( const QStringList& items, bool autoSuggest );
00437 
00442     virtual void clear();
00443 
00449     void setSqueezedText( const QString &text);
00450 
00454     virtual void setText ( const QString& );
00455 
00456 
00457 protected slots:
00458 
00463     virtual void makeCompletion( const QString& );
00464 
00468     void slotAboutToShow() {}
00469 
00473     void slotCancelled() {}
00474 
00480     void userCancelled(const QString & cancelText);
00481 
00482 protected:
00483 
00489     virtual void resizeEvent( QResizeEvent * );
00490 
00496     virtual void keyPressEvent( QKeyEvent * );
00497 
00503     virtual void mousePressEvent( QMouseEvent * );
00504 
00510     virtual void mouseDoubleClickEvent( QMouseEvent * );
00511 
00517     virtual void contextMenuEvent( QContextMenuEvent * );
00518 
00524     virtual QPopupMenu *createPopupMenu();
00525 
00531     virtual void dropEvent( QDropEvent * );
00532 
00533     /*
00534     * This function simply sets the lineedit text and
00535     * highlights the text appropriately if the boolean
00536     * value is set to true.
00537     *
00538     * @param text
00539     * @param marked
00540     */
00541     virtual void setCompletedText( const QString& /*text*/, bool /*marked*/ );
00542 
00543 
00548     void setUserSelection( bool userSelection );
00549 
00553     virtual void create( WId = 0, bool initializeWindow = true,
00554                          bool destroyOldWindow = true );
00555 
00561     virtual void focusInEvent( QFocusEvent* );
00562 
00567     bool autoSuggest() const;
00568 
00569 private slots:
00570     void completionMenuActivated( int id );
00571     void tripleClickTimeout();  // resets possibleTripleClick
00572     void slotRestoreSelectionColors();
00573     void setTextWorkaround( const QString& text );
00574 
00575 private:
00576 
00577     // Constants that represent the ID's of the popup menu.
00578     enum MenuID
00579     {
00580         Default = 42,
00581         NoCompletion,
00582         AutoCompletion,
00583         ShellCompletion,
00584         PopupCompletion,
00585         ShortAutoCompletion,
00586         PopupAutoCompletion
00587     };
00588 
00592     void init();
00593 
00598     bool overrideAccel (const QKeyEvent* e);
00599 
00604     void setSqueezedText ();
00605 
00606     bool m_bEnableMenu;
00607 
00608     bool possibleTripleClick;  // set in mousePressEvent, deleted in tripleClickTimeout
00609 
00610 protected:
00611     virtual void virtual_hook( int id, void* data );
00612 private:
00613     class KLineEditPrivate;
00614     KLineEditPrivate *d;
00615 };
00616 
00617 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys