Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

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    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library 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 
00127 class KComboBox : public QComboBox, public KCompletionBase
00128 {
00129   Q_OBJECT
00130   Q_PROPERTY( bool autoCompletion READ autoCompletion WRITE setAutoCompletion )
00131   Q_PROPERTY( bool contextMenuEnabled READ isContextMenuEnabled WRITE setContextMenuEnabled )
00132   Q_PROPERTY( bool urlDropsEnabled READ isURLDropsEnabled WRITE setURLDropsEnabled )
00133 
00134 public:
00135 
00143     KComboBox( QWidget *parent=0, const char *name=0 );
00144 
00154     KComboBox( bool rw, QWidget *parent=0, const char *name=0 );
00155 
00159     virtual ~KComboBox();
00160 
00166     void setEditURL( const KURL& url );
00167 
00173     void insertURL( const KURL& url, int index = -1 );
00174 
00181     void insertURL( const QPixmap& pixmap, const KURL& url, int index = -1 );
00182 
00188     void changeURL( const KURL& url, int index );
00189 
00195     void changeURL( const QPixmap& pixmap, const KURL& url, int index );
00196 
00205     int cursorPosition() const { return ( lineEdit() ) ? lineEdit()->cursorPosition() : -1; }
00206 
00217     virtual void setAutoCompletion( bool autocomplete );
00218 
00228     bool autoCompletion() const {
00229         return completionMode() == KGlobalSettings::CompletionAuto;
00230     }
00231 
00248     virtual void setContextMenuEnabled( bool showMenu );
00249 
00253     bool isContextMenuEnabled() const { return m_bEnableMenu; }
00254 
00262     void setURLDropsEnabled( bool enable );
00263 
00267     bool isURLDropsEnabled() const;
00268 
00278     bool contains( const QString& text ) const;
00279 
00294     void setTrapReturnKey( bool trap );
00295 
00302     bool trapReturnKey() const;
00303 
00309     virtual bool eventFilter( QObject *, QEvent * );
00310 
00320     KCompletionBox * completionBox( bool create = true );
00321 
00322     virtual void setLineEdit( QLineEdit * );
00323 
00324 signals:
00331     void returnPressed();
00332 
00345     void returnPressed( const QString& );
00346 
00358     void completion( const QString& );
00359 
00363     void substringCompletion( const QString& );
00364 
00377     void textRotation( KCompletionBase::KeyBindingType );
00378 
00383     void completionModeChanged( KGlobalSettings::Completion );
00384 
00397     void aboutToShowContextMenu( QPopupMenu * );
00398 
00399 public slots:
00400 
00418     void rotateText( KCompletionBase::KeyBindingType /* type */ );
00419 
00426     virtual void setCompletedText( const QString& );
00427 
00432     void setCompletedItems( const QStringList& items );
00433 
00439     void setCurrentItem( const QString& item, bool insert = false, int index = -1 );
00440     void setCurrentItem(int index) { QComboBox::setCurrentItem(index); }
00441 
00442 protected slots:
00443 
00447     virtual void itemSelected( QListBoxItem* ) {};
00448 
00460     virtual void makeCompletion( const QString& );
00461 
00462 protected:
00463     /*
00464     * This function simply sets the lineedit text and
00465     * highlights the text appropriately if the boolean
00466     * value is set to true.
00467     *
00468     * @param
00469     * @param
00470     */
00471     virtual void setCompletedText( const QString& /* */, bool /*marked*/ );
00472 
00476     virtual void create( WId = 0, bool initializeWindow = true,
00477                          bool destroyOldWindow = true );
00478 
00479 private:
00480     // Constants that represent the ID's of the popup menu.
00481     // TODO: See if we can replace this mess with KActionMenu
00482     // in the future though this is working lovely.
00483     enum MenuID {
00484         Default=0,
00485         Cut,
00486         Copy,
00487         Paste,
00488         Clear,
00489         Unselect,
00490         SelectAll,
00491         NoCompletion,
00492         AutoCompletion,
00493         ShellCompletion,
00494         PopupCompletion,
00495         SemiAutoCompletion
00496     };
00497 
00501     void init();
00506     void deleteWordBack();
00507     void deleteWordForward();
00508 
00509     bool m_bEnableMenu;
00510 
00511     // indicating if we should stop return-key events from propagating
00512     bool m_trapReturnKey;
00513 
00514 protected:
00515     virtual void virtual_hook( int id, void* data );
00516 private:
00517     class KComboBoxPrivate;
00518     KComboBoxPrivate *d;
00519 };
00520 
00521 
00522 class KPixmapProvider;
00523 
00534 class KHistoryCombo : public KComboBox
00535 {
00536     Q_OBJECT
00537     Q_PROPERTY( QStringList historyItems READ historyItems WRITE setHistoryItems )
00538 
00539 public:
00559     KHistoryCombo( QWidget *parent = 0L, const char *name = 0L );
00560 
00561     // ### merge these two constructors
00568     KHistoryCombo( bool useCompletion,
00569            QWidget *parent = 0L, const char *name = 0L );
00570 
00574     ~KHistoryCombo();
00575 
00582     inline void setHistoryItems( QStringList items ) {
00583         setHistoryItems(items, false);
00584     }
00585 
00627     void setHistoryItems( QStringList items, bool setCompletionList );
00628 
00635     QStringList historyItems() const;
00636 
00644     bool removeFromHistory( const QString& item );
00645 
00658     void setPixmapProvider( KPixmapProvider *prov );
00659 
00665     KPixmapProvider * pixmapProvider() const { return myPixProvider; }
00666 
00671     void reset() { slotReset(); }
00672 
00673 public slots:
00693     void addToHistory( const QString& item );
00694 
00698     void clearHistory();
00699 
00700 signals:
00704     void cleared();
00705 
00706 protected:
00710     virtual void keyPressEvent( QKeyEvent * );
00711 
00712 
00721     void insertItems( const QStringList& items );
00722 
00726     bool useCompletion() const { return compObj() != 0L; }
00727 
00728 private slots:
00732     void slotReset();
00733 
00738     void slotClear();
00739 
00743     void addContextMenuItems( QPopupMenu* );
00744 
00745 private:
00746     void init( bool useCompletion );
00747 
00751     int myIterateIndex;
00752 
00756     QString myText;
00757 
00762     bool myRotated;
00763     KPixmapProvider *myPixProvider;
00764 
00765 protected:
00766     virtual void virtual_hook( int id, void* data );
00767 private:
00768     class KHistoryComboPrivate;
00769     KHistoryComboPrivate *d;
00770 };
00771 
00772 
00773 #endif
00774 

Generated on Sat Mar 29 01:17:16 2003 by doxygen1.2.17