kio
kurlcombobox.h
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 #ifndef KURLCOMBOBOX_H
00020 #define KURLCOMBOBOX_H
00021 
00022 #include <qevent.h>
00023 #include <qptrlist.h>
00024 #include <qmap.h>
00025 #include <qpixmap.h>
00026 #include <qstringlist.h>
00027 
00028 #include <kcombobox.h>
00029 #include <kurl.h>
00030 
00041 class KIO_EXPORT KURLComboBox : public KComboBox
00042 {
00043     Q_OBJECT
00044     Q_PROPERTY(QStringList urls READ urls WRITE setURLs DESIGNABLE true)
00045     Q_PROPERTY(int maxItems READ maxItems WRITE setMaxItems DESIGNABLE true)
00046 
00047 public:
00051     enum Mode { Files = -1, Directories = 1, Both = 0 };
00059     enum OverLoadResolving { RemoveTop, RemoveBottom };
00060 
00076     KURLComboBox( Mode mode, QWidget *parent=0, const char *name=0 );
00077     KURLComboBox( Mode mode, bool rw, QWidget *parent=0, const char *name=0 );
00081     ~KURLComboBox();
00082 
00095     void setURL( const KURL& url );
00096 
00104     void setURLs( QStringList urls );
00105 
00113     void setURLs( QStringList urls, OverLoadResolving remove );
00114 
00125     QStringList urls() const;
00126 
00131     void setMaxItems( int );
00132 
00137     int maxItems() const { return myMaximum; }
00138 
00147     void addDefaultURL( const KURL& url, const QString& text = QString::null );
00148 
00157     void addDefaultURL( const KURL& url, const QPixmap& pix,
00158             const QString& text = QString::null );
00159 
00165     void setDefaults();
00166 
00171     void removeURL( const KURL& url, bool checkDefaultURLs = true );
00172 
00173 signals:
00179     void urlActivated( const KURL& url );
00180 
00181 
00182 protected slots:
00183     void slotActivated( int );
00184 
00185 
00186 protected:
00187     struct _KURLComboItem {
00188     QString text;
00189     KURL url;
00190     QPixmap pixmap;
00191     };
00192     typedef _KURLComboItem KURLComboItem;
00193     QPtrList<KURLComboItem> itemList;
00194     QPtrList<KURLComboItem> defaultList;
00195     QMap<int,const KURLComboItem*> itemMapper;
00196 
00197     void init( Mode mode );
00198     void insertURLItem( const KURLComboItem * );
00199 
00204     QPixmap getPixmap( const KURL& url ) const;
00205 
00211     void updateItem( const KURLComboItem *item, int index, const QPixmap& pix);
00212 
00213     QPixmap opendirPix;
00214     int firstItemIndex;
00215 
00216 
00217 private:
00218     bool urlAdded;
00219     int myMaximum;
00220     Mode myMode; 
00221                  
00222 
00223 private:
00224     class KURLComboBoxPrivate;
00225     KURLComboBoxPrivate *d;
00226 };
00227 
00228 
00229 #endif // KURLCOMBOBOX_H