kdeui Library API Documentation

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., 59 Temple Place - Suite 330,
00027     Boston, MA 02111-1307, USA.
00028 */
00029 
00030 #ifndef _KLINEEDIT_H
00031 #define _KLINEEDIT_H
00032 
00033 #include <qlineedit.h>
00034 #include <kcompletion.h>
00035 #include <kdemacros.h>
00036 
00037 class QPopupMenu;
00038 
00039 class KCompletionBox;
00040 class KURL;
00041 
00146 class KLineEdit : public QLineEdit, public KCompletionBase
00147 {
00148     friend class KComboBox;
00149 
00150     Q_OBJECT
00151     Q_PROPERTY( bool contextMenuEnabled READ isContextMenuEnabled WRITE setContextMenuEnabled )
00152     Q_PROPERTY( bool urlDropsEnabled READ isURLDropsEnabled WRITE setURLDropsEnabled )
00153     Q_PROPERTY( bool trapEnterKeyEvent READ trapReturnKey WRITE setTrapReturnKey )
00154     Q_PROPERTY( bool enableSqueezedText READ isSqueezedTextEnabled WRITE setEnableSqueezedText )
00155 
00156 public:
00157 
00166     KLineEdit( const QString &string, QWidget *parent, const char *name = 0 );
00167 
00174     KLineEdit ( QWidget *parent=0, const char *name=0 );
00175 
00179     virtual ~KLineEdit ();
00180 
00185     void setURL( const KURL& url );
00186 
00196     void cursorAtEnd() { end( false ); }
00197 
00206     virtual void setCompletionMode( KGlobalSettings::Completion mode );
00207 
00222     virtual void setContextMenuEnabled( bool showMenu ) {  m_bEnableMenu = showMenu; }
00223 
00227     bool isContextMenuEnabled() const { return m_bEnableMenu; }
00228 
00236     void setURLDropsEnabled( bool enable );
00237 
00241     bool isURLDropsEnabled() const;
00242 
00253     void setTrapReturnKey( bool trap );
00254 
00261     bool trapReturnKey() const;
00262 
00267     virtual bool eventFilter( QObject *, QEvent * );
00268 
00277     KCompletionBox * completionBox( bool create = true );
00278 
00282     virtual void setCompletionObject( KCompletion *, bool hsig = true );
00283 
00287     virtual void copy() const;
00288 
00299     void setEnableSqueezedText( bool enable );
00300     
00307     bool isSqueezedTextEnabled() const;
00308     
00316     QString originalText() const;
00317 
00318 signals:
00319 
00324     void completionBoxActivated (const QString &);
00325 
00333     void returnPressed( const QString& );
00334 
00342     void completion( const QString& );
00343 
00347     void substringCompletion( const QString& );
00348 
00360     void textRotation( KCompletionBase::KeyBindingType );
00361 
00366     void completionModeChanged( KGlobalSettings::Completion );
00367 
00380     void aboutToShowContextMenu( QPopupMenu * p );
00381 
00382 public slots:
00383 
00387     virtual void setReadOnly(bool);
00388 
00399     void rotateText( KCompletionBase::KeyBindingType type );
00400 
00404     virtual void setCompletedText( const QString& );
00405 
00412     void setCompletedItems( const QStringList& items );
00413     
00424     void setCompletedItems( const QStringList& items, bool autoSuggest );
00425 
00430     virtual void clear();
00431 
00437     void setSqueezedText( const QString &text);
00438 
00442     virtual void setText ( const QString& );
00443     
00444     
00445 protected slots:
00446 
00451     virtual void makeCompletion( const QString& );
00452 
00456     void slotAboutToShow() {}
00457 
00461     void slotCancelled() {}
00462     
00468     void userCancelled(const QString & cancelText);
00469 
00470 protected:
00471 
00477     virtual void resizeEvent( QResizeEvent * );
00478 
00484     virtual void keyPressEvent( QKeyEvent * );
00485 
00491     virtual void mousePressEvent( QMouseEvent * );
00492 
00498     virtual void mouseDoubleClickEvent( QMouseEvent * );
00499 
00505     virtual void contextMenuEvent( QContextMenuEvent * );
00506 
00512     virtual QPopupMenu *createPopupMenu();
00513 
00519     virtual void dropEvent( QDropEvent * );
00520 
00521     /*
00522     * This function simply sets the lineedit text and
00523     * highlights the text appropriately if the boolean
00524     * value is set to true.
00525     *
00526     * @param text
00527     * @param marked
00528     */
00529     virtual void setCompletedText( const QString& /*text*/, bool /*marked*/ );
00530 
00531 
00536     void setUserSelection( bool userSelection );
00537 
00541     virtual void create( WId = 0, bool initializeWindow = true,
00542                          bool destroyOldWindow = true );
00543 
00544 private slots:
00545     void completionMenuActivated( int id );
00546     void tripleClickTimeout();  // resets possibleTripleClick
00547     void slotRestoreSelectionColors();
00548     void setTextWorkaround( const QString& text );
00549 
00550 private:
00551 
00552     // Constants that represent the ID's of the popup menu.
00553     enum MenuID
00554     {
00555         Default = 42,
00556         NoCompletion,
00557         AutoCompletion,
00558         ShellCompletion,
00559         PopupCompletion,
00560         ShortAutoCompletion,
00561         PopupAutoCompletion
00562     };
00563 
00567     void init();
00568 
00572     void makeCompletionBox();
00573 
00578     bool overrideAccel (const QKeyEvent* e);
00579 
00584     void setSqueezedText ();
00585 
00586     bool m_bEnableMenu;
00587 
00588     bool possibleTripleClick;  // set in mousePressEvent, deleted in tripleClickTimeout
00589 
00590 protected:
00591     virtual void virtual_hook( int id, void* data );
00592 private:
00593     class KLineEditPrivate;
00594     KLineEditPrivate *d;
00595 };
00596 
00597 #endif
KDE Logo
This file is part of the documentation for kdeui Library Version 3.3.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jan 22 16:45:12 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003