keditlistbox.h
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2000 David Faure <faure@kde.org>, Alexander Neundorf <neundorf@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef KEDITLISTBOX_H 00021 #define KEDITLISTBOX_H 00022 00023 #include <tqgroupbox.h> 00024 #include <tqlistbox.h> 00025 00026 #include <tdelibs_export.h> 00027 00028 class KLineEdit; 00029 class KComboBox; 00030 class TQPushButton; 00031 00032 class KEditListBoxPrivate; 00044 class TDEUI_EXPORT KEditListBox : public TQGroupBox 00045 { 00046 Q_OBJECT 00047 00048 00049 TQ_SETS( Button ) 00050 TQ_PROPERTY( Button buttons READ buttonsProp WRITE setButtonsProp ) 00051 TQ_PROPERTY( TQStringList items READ items WRITE setItems ) 00052 00053 public: 00054 class CustomEditor; 00055 00056 public: 00057 00062 enum Button { Add = 1, Remove = 2, UpDown = 4 }; 00063 enum { All = Add|Remove|UpDown }; // separated so that it doesn't appear in Qt designer 00064 00077 KEditListBox(TQWidget *parent = 0, const char *name = 0, 00078 bool checkAtEntering=false, int buttons = All ); 00085 KEditListBox(const TQString& title, TQWidget *parent = 0, 00086 const char *name = 0, bool checkAtEntering=false, 00087 int buttons = All ); 00088 00101 KEditListBox( const TQString& title, 00102 const CustomEditor &customEditor, 00103 TQWidget *parent = 0, const char *name = 0, 00104 bool checkAtEntering = false, int buttons = All ); 00105 00106 virtual ~KEditListBox(); 00107 00111 TQListBox* listBox() const { return m_listBox; } 00115 KLineEdit* lineEdit() const { return m_lineEdit; } 00119 TQPushButton* addButton() const { return servNewButton; } 00123 TQPushButton* removeButton() const { return servRemoveButton; } 00127 TQPushButton* upButton() const { return servUpButton; } 00131 TQPushButton* downButton() const { return servDownButton; } 00132 00136 int count() const { return int(m_listBox->count()); } 00140 void insertStringList(const TQStringList& list, int index=-1); 00144 void insertStrList(const TQStrList* list, int index=-1); 00148 void insertStrList(const TQStrList& list, int index=-1); 00152 void insertStrList(const char ** list, int numStrings=-1, int index=-1); 00156 void insertItem(const TQString& text, int index=-1) {m_listBox->insertItem(text,index);} 00160 void clear(); 00164 TQString text(int index) const { return m_listBox->text(index); } 00168 int currentItem() const; 00172 TQString currentText() const { return m_listBox->currentText(); } 00173 00177 TQStringList items() const; 00178 00184 void setItems(const TQStringList& items); 00185 00189 int buttons() const; 00190 inline Button buttonsProp() const { return (Button)buttons(); } 00191 00195 void setButtons( uint buttons ); 00196 inline void setButtonsProp( Button buttons ) { setButtons((uint)buttons); } 00197 00198 signals: 00199 void changed(); 00200 00206 void added( const TQString & text ); 00207 00213 void removed( const TQString & text ); 00214 00215 protected slots: 00216 //the names should be self-explaining 00217 void moveItemUp(); 00218 void moveItemDown(); 00219 void addItem(); 00220 void removeItem(); 00221 void enableMoveButtons(int index); 00222 void typedSomething(const TQString& text); 00223 00224 private: 00225 TQListBox *m_listBox; 00226 TQPushButton *servUpButton, *servDownButton; 00227 TQPushButton *servNewButton, *servRemoveButton; 00228 KLineEdit *m_lineEdit; 00229 00230 //this is called in both ctors, to avoid code duplication 00231 void init( bool checkAtEntering, int buttons, 00232 TQWidget *representationWidget = 0L ); 00233 00234 protected: 00235 virtual void virtual_hook( int id, void* data ); 00236 private: 00237 //our lovely private d-pointer 00238 KEditListBoxPrivate* const d; 00239 00245 // ### KDE4: add virtual destructor 00246 public: 00247 class CustomEditor 00248 { 00249 public: 00250 TDEUI_EXPORT CustomEditor() 00251 : m_representationWidget( 0L ), 00252 m_lineEdit( 0L ) {} 00253 TDEUI_EXPORT CustomEditor( TQWidget *repWidget, KLineEdit *edit ) 00254 : m_representationWidget( repWidget ), 00255 m_lineEdit( edit ) {} 00256 TDEUI_EXPORT CustomEditor( KComboBox *combo ); 00257 00258 TDEUI_EXPORT void setRepresentationWidget( TQWidget *repWidget ) { 00259 m_representationWidget = repWidget; 00260 } 00261 TDEUI_EXPORT void setLineEdit( KLineEdit *edit ) { 00262 m_lineEdit = edit; 00263 } 00264 00265 TDEUI_EXPORT virtual TQWidget *representationWidget() const { 00266 return m_representationWidget; 00267 } 00268 TDEUI_EXPORT virtual KLineEdit *lineEdit() const { 00269 return m_lineEdit; 00270 } 00271 00272 protected: 00273 TQWidget *m_representationWidget; 00274 KLineEdit *m_lineEdit; 00275 }; 00276 }; 00277 00278 #endif 00279