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., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #ifndef _KCOMBOBOX_H 00023 #define _KCOMBOBOX_H 00024 00025 #include <tqlineedit.h> 00026 #include <tqcombobox.h> 00027 #include <tqvbox.h> 00028 #include <tqlabel.h> 00029 #include <tqlayout.h> 00030 #include <tqtoolbutton.h> 00031 #include <tqheader.h> 00032 00033 #include <kcompletion.h> 00034 #include <kdialogbase.h> 00035 #include <tdelistview.h> 00036 00037 class TQListBoxItem; 00038 class TQPopupMenu; 00039 class TQLineEdit; 00040 00041 class TDECompletionBox; 00042 class KURL; 00043 00151 class TDEUI_EXPORT KComboBox : public TQComboBox, public TDECompletionBase 00152 { 00153 Q_OBJECT 00154 TQ_PROPERTY( bool autoCompletion READ autoCompletion WRITE setAutoCompletion ) 00155 TQ_PROPERTY( bool contextMenuEnabled READ isContextMenuEnabled WRITE setContextMenuEnabled ) 00156 TQ_PROPERTY( bool urlDropsEnabled READ isURLDropsEnabled WRITE setURLDropsEnabled ) 00157 TQ_PROPERTY( bool trapReturnKey READ trapReturnKey WRITE setTrapReturnKey ) 00158 00159 public: 00160 00168 KComboBox( TQWidget *parent=0, const char *name=0 ); 00169 00179 KComboBox( bool rw, TQWidget *parent=0, const char *name=0 ); 00180 00184 virtual ~KComboBox(); 00185 00191 void setEditURL( const KURL& url ); 00192 00198 void insertURL( const KURL& url, int index = -1 ); 00199 00206 void insertURL( const TQPixmap& pixmap, const KURL& url, int index = -1 ); 00207 00213 void changeURL( const KURL& url, int index ); 00214 00220 void changeURL( const TQPixmap& pixmap, const KURL& url, int index ); 00221 00230 int cursorPosition() const { return ( lineEdit() ) ? lineEdit()->cursorPosition() : -1; } 00231 00242 virtual void setAutoCompletion( bool autocomplete ); 00243 00253 bool autoCompletion() const { 00254 return completionMode() == TDEGlobalSettings::CompletionAuto; 00255 } 00256 00272 virtual void setContextMenuEnabled( bool showMenu ); 00273 00277 bool isContextMenuEnabled() const { return m_bEnableMenu; } 00278 00286 void setURLDropsEnabled( bool enable ); 00287 00291 bool isURLDropsEnabled() const; 00292 00302 bool contains( const TQString& text ) const; 00303 00317 void setTrapReturnKey( bool trap ); 00318 00325 bool trapReturnKey() const; 00326 00330 virtual bool eventFilter( TQObject *, TQEvent * ); 00331 00341 TDECompletionBox * completionBox( bool create = true ); 00342 00349 virtual void setLineEdit( TQLineEdit * ); 00350 00351 signals: 00357 void returnPressed(); 00358 00368 void returnPressed( const TQString& ); 00369 00378 void completion( const TQString& ); 00379 00383 void substringCompletion( const TQString& ); 00384 00396 void textRotation( TDECompletionBase::KeyBindingType ); 00397 00402 void completionModeChanged( TDEGlobalSettings::Completion ); 00403 00413 void aboutToShowContextMenu( TQPopupMenu * p ); 00414 00415 public slots: 00416 00434 void rotateText( TDECompletionBase::KeyBindingType type ); 00435 00441 virtual void setCompletedText( const TQString& ); 00442 00447 void setCompletedItems( const TQStringList& items ); 00448 00454 void setCurrentItem( const TQString& item, bool insert = false, int index = -1 ); 00455 00460 void setCurrentItem(int index) { TQComboBox::setCurrentItem(index); } 00461 00462 protected slots: 00463 00467 virtual void itemSelected( TQListBoxItem* ) {} 00468 00480 virtual void makeCompletion( const TQString& ); 00481 00482 protected: 00483 /* 00484 * This function simply sets the lineedit text and 00485 * highlights the text appropriately if the boolean 00486 * value is set to true. 00487 * 00488 * @param 00489 * @param 00490 */ 00491 virtual void setCompletedText( const TQString& /* */, bool /*marked*/ ); 00492 00496 virtual void create( WId = 0, bool initializeWindow = true, 00497 bool destroyOldWindow = true ); 00498 00499 virtual void wheelEvent( TQWheelEvent *ev ); 00500 00501 private slots: 00502 void lineEditDeleted(); 00503 00504 private: 00508 void init(); 00509 bool m_bEnableMenu; // ### BCI: unused, remove in KDE4 00510 bool m_trapReturnKey; // ### BCI: unused, remove in KDE4 00511 00512 protected: 00513 virtual void virtual_hook( int id, void* data ); 00514 00515 private: 00516 class KComboBoxPrivate; 00517 KComboBoxPrivate* const d; 00518 }; 00519 00520 00521 class KPixmapProvider; 00522 00540 class TDEUI_EXPORT KHistoryCombo : public KComboBox 00541 { 00542 Q_OBJECT 00543 TQ_PROPERTY( TQStringList historyItems READ historyItems WRITE setHistoryItems ) 00544 00545 public: 00565 KHistoryCombo( TQWidget *parent = 0L, const char *name = 0L ); 00566 00567 // ### merge these two constructors 00574 KHistoryCombo( bool useCompletion, 00575 TQWidget *parent = 0L, const char *name = 0L ); 00576 00580 ~KHistoryCombo(); 00581 00588 inline void setHistoryItems( TQStringList items ) { 00589 setHistoryItems(items, false); 00590 } 00591 00633 void setHistoryItems( TQStringList items, bool setCompletionList ); 00634 00641 TQStringList historyItems() const; 00642 00650 bool removeFromHistory( const TQString& item ); 00651 00664 void setPixmapProvider( KPixmapProvider *prov ); 00665 00671 KPixmapProvider * pixmapProvider() const { return myPixProvider; } 00672 00677 void reset() { slotReset(); } 00678 00682 void setHistoryEditorEnabled( bool enable ); 00683 bool isHistoryEditorEnabled() const; 00684 00685 public slots: 00705 void addToHistory( const TQString& item ); 00706 00710 void clearHistory(); 00711 00712 signals: 00716 void cleared(); 00717 00718 void removed( const TQString& item ); 00719 00720 protected: 00724 virtual void keyPressEvent( TQKeyEvent * ); 00725 00729 virtual void wheelEvent( TQWheelEvent *ev ); 00730 00739 void insertItems( const TQStringList& items ); 00740 00744 bool useCompletion() const { return compObj(); } 00745 00746 private slots: 00750 void slotReset(); 00751 00756 void slotClear(); 00757 00761 void slotEdit(); 00762 00766 void addContextMenuItems( TQPopupMenu* ); 00767 00768 void slotRemoveFromHistory( const TQString & ); 00769 00770 private: 00771 void init( bool useCompletion ); 00772 void rotateUp(); 00773 void rotateDown(); 00774 00778 int myIterateIndex; 00779 00783 TQString myText; 00784 00789 bool myRotated; 00790 KPixmapProvider *myPixProvider; 00791 00792 protected: 00793 virtual void virtual_hook( int id, void* data ); 00794 private: 00795 class KHistoryComboPrivate; 00796 KHistoryComboPrivate* const d; 00797 }; 00798 00799 class TDEUI_EXPORT KHistoryComboEditor : public KDialogBase 00800 { 00801 Q_OBJECT 00802 00803 public: 00804 KHistoryComboEditor( const TQStringList& entries, TQWidget *parent = 0L ); 00805 ~KHistoryComboEditor(); 00806 00807 signals: 00808 void removeFromHistory( const TQString& ); 00809 00810 protected slots: 00811 virtual void slotUser1(); // User1 is "Delete Entry" button 00812 void slotSelectionChanged( TQListViewItem * item ); 00813 00814 protected: 00815 virtual void virtual_hook( int id, void* data ); 00816 00817 private: 00818 TDEListView *m_pListView; 00819 00820 class KHistoryComboEditorPrivate; 00821 KHistoryComboEditorPrivate* const d; 00822 }; 00823 00824 #endif 00825