kdeui Library API Documentation

kcombobox.h

00001 /* This file is part of the KDE libraries
00002 
00003    Copyright (c) 2000,2001 Dawit Alemayehu <adawit@kde.org>
00004    Copyright (c) 2000,2001 Carsten Pfeiffer <pfeiffer@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License (LGPL) as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.
00020 */
00021 
00022 #ifndef _KCOMBOBOX_H
00023 #define _KCOMBOBOX_H
00024 
00025 #include <qlineedit.h>
00026 #include <qcombobox.h>
00027 
00028 #include <kcompletion.h>
00029 
00030 class QListBoxItem;
00031 class QPopupMenu;
00032 class QLineEdit;
00033 
00034 class KCompletionBox;
00035 class KURL;
00036 
00139 class KComboBox : public QComboBox, public KCompletionBase
00140 {
00141   Q_OBJECT
00142   Q_PROPERTY( bool autoCompletion READ autoCompletion WRITE setAutoCompletion )
00143   Q_PROPERTY( bool contextMenuEnabled READ isContextMenuEnabled WRITE setContextMenuEnabled )
00144   Q_PROPERTY( bool urlDropsEnabled READ isURLDropsEnabled WRITE setURLDropsEnabled )
00145 
00146 public:
00147 
00155     KComboBox( QWidget *parent=0, const char *name=0 );
00156 
00166     KComboBox( bool rw, QWidget *parent=0, const char *name=0 );
00167 
00171     virtual ~KComboBox();
00172 
00178     void setEditURL( const KURL& url );
00179 
00185     void insertURL( const KURL& url, int index = -1 );
00186 
00193     void insertURL( const QPixmap& pixmap, const KURL& url, int index = -1 );
00194 
00200     void changeURL( const KURL& url, int index );
00201 
00207     void changeURL( const QPixmap& pixmap, const KURL& url, int index );
00208 
00217     int cursorPosition() const { return ( lineEdit() ) ? lineEdit()->cursorPosition() : -1; }
00218 
00229     virtual void setAutoCompletion( bool autocomplete );
00230 
00240     bool autoCompletion() const {
00241         return completionMode() == KGlobalSettings::CompletionAuto;
00242     }
00243 
00259     virtual void setContextMenuEnabled( bool showMenu );
00260 
00264     bool isContextMenuEnabled() const { return m_bEnableMenu; }
00265 
00273     void setURLDropsEnabled( bool enable );
00274 
00278     bool isURLDropsEnabled() const;
00279 
00289     bool contains( const QString& text ) const;
00290 
00304     void setTrapReturnKey( bool trap );
00305 
00312     bool trapReturnKey() const;
00313 
00317     virtual bool eventFilter( QObject *, QEvent * );
00318 
00328     KCompletionBox * completionBox( bool create = true );
00329 
00336     virtual void setLineEdit( QLineEdit * );
00337 
00338 signals:
00344     void returnPressed();
00345 
00355     void returnPressed( const QString& );
00356 
00365     void completion( const QString& );
00366 
00370     void substringCompletion( const QString& );
00371 
00383     void textRotation( KCompletionBase::KeyBindingType );
00384 
00389     void completionModeChanged( KGlobalSettings::Completion );
00390 
00400     void aboutToShowContextMenu( QPopupMenu * p );
00401 
00402 public slots:
00403 
00421     void rotateText( KCompletionBase::KeyBindingType type );
00422 
00429     virtual void setCompletedText( const QString& );
00430 
00435     void setCompletedItems( const QStringList& items );
00436 
00442     void setCurrentItem( const QString& item, bool insert = false, int index = -1 );
00447     void setCurrentItem(int index) { QComboBox::setCurrentItem(index); }
00448 
00449 protected slots:
00450 
00454     virtual void itemSelected( QListBoxItem* ) {};
00455 
00467     virtual void makeCompletion( const QString& );
00468 
00469 protected:
00470     /*
00471     * This function simply sets the lineedit text and
00472     * highlights the text appropriately if the boolean
00473     * value is set to true.
00474     *
00475     * @param
00476     * @param
00477     */
00478     virtual void setCompletedText( const QString& /* */, bool /*marked*/ );
00479 
00483     virtual void create( WId = 0, bool initializeWindow = true,
00484                          bool destroyOldWindow = true );
00485 
00486     virtual void wheelEvent( QWheelEvent *ev );
00487 
00488 private slots:
00489     void lineEditDeleted();
00490 
00491 private:
00495     void init();
00496     bool m_bEnableMenu; // ### BCI: unused, remove in KDE4
00497     bool m_trapReturnKey; // ### BCI: unused, remove in KDE4
00498 
00499 protected:
00500     virtual void virtual_hook( int id, void* data );
00501 
00502 private:
00503     class KComboBoxPrivate;
00504     KComboBoxPrivate *d;
00505 };
00506 
00507 
00508 class KPixmapProvider;
00509 
00526 class KHistoryCombo : public KComboBox
00527 {
00528     Q_OBJECT
00529     Q_PROPERTY( QStringList historyItems READ historyItems WRITE setHistoryItems )
00530 
00531 public:
00551     KHistoryCombo( QWidget *parent = 0L, const char *name = 0L );
00552 
00553     // ### merge these two constructors
00560     KHistoryCombo( bool useCompletion,
00561            QWidget *parent = 0L, const char *name = 0L );
00562 
00566     ~KHistoryCombo();
00567 
00574     inline void setHistoryItems( QStringList items ) {
00575         setHistoryItems(items, false);
00576     }
00577 
00619     void setHistoryItems( QStringList items, bool setCompletionList );
00620 
00627     QStringList historyItems() const;
00628 
00636     bool removeFromHistory( const QString& item );
00637 
00650     void setPixmapProvider( KPixmapProvider *prov );
00651 
00657     KPixmapProvider * pixmapProvider() const { return myPixProvider; }
00658 
00663     void reset() { slotReset(); }
00664 
00665 public slots:
00685     void addToHistory( const QString& item );
00686 
00690     void clearHistory();
00691 
00692 signals:
00696     void cleared();
00697 
00698 protected:
00702     virtual void keyPressEvent( QKeyEvent * );
00703 
00707     virtual void wheelEvent( QWheelEvent *ev );
00708 
00717     void insertItems( const QStringList& items );
00718 
00722     bool useCompletion() const { return compObj() != 0L; }
00723 
00724 private slots:
00728     void slotReset();
00729 
00734     void slotClear();
00735 
00739     void addContextMenuItems( QPopupMenu* );
00740 
00741 private:
00742     void init( bool useCompletion );
00743     void rotateUp();
00744     void rotateDown();
00745 
00749     int myIterateIndex;
00750 
00754     QString myText;
00755 
00760     bool myRotated;
00761     KPixmapProvider *myPixProvider;
00762 
00763 protected:
00764     virtual void virtual_hook( int id, void* data );
00765 private:
00766     class KHistoryComboPrivate;
00767     KHistoryComboPrivate *d;
00768 };
00769 
00770 
00771 #endif
00772 
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 Fri Feb 18 15:10:17 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003