lib

koIconChooser.h

00001 /* This file is part of the KDE project
00002   Copyright (c) 1999 Carsten Pfeiffer (pfeiffer@kde.org)
00003   Copyright (c) 2002 Igor Jansen (rm@kde.org)
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef __ko_iconchooser_h__
00022 #define __ko_iconchooser_h__
00023 
00024 #include <qgridview.h>
00025 #include <qptrlist.h>
00026 #include <qpixmap.h>
00027 #include <koffice_export.h>
00028 
00029 class KoIconItem
00030 {
00031 public:
00032   KoIconItem() {}
00033   virtual ~KoIconItem() {}
00034 
00035   bool hasValidPixmap() {return validPixmap; }
00036   bool validPixmap;
00037   bool hasValidThumb() {return validThumb; }
00038   bool validThumb;
00039 
00040   virtual int spacing() const {return 0; }
00041   virtual void setSpacing(int) {}
00042   virtual QPixmap &pixmap() const = 0;
00043   virtual QPixmap &thumbPixmap() const = 0;
00044   // Return -1 if this is less than other, 0 if equal, 1 if greater than.
00045   virtual int compare(const KoIconItem */*other*/) const { return 0; }
00046 };
00047 
00048 class KoPixmapWidget : public QFrame
00049 {
00050 public:
00051   KoPixmapWidget(const QPixmap &aPixmap, QWidget *parent = 0L, const char *name = 0L);
00052   ~KoPixmapWidget();
00053 
00054 protected:
00055   void paintEvent(QPaintEvent *e);
00056   void mouseReleaseEvent( QMouseEvent *e);
00057 
00058 private:
00059   QPixmap mPixmap;
00060 };
00061 
00062 class KOPAINTER_EXPORT KoIconChooser: public QGridView
00063 {
00064   Q_OBJECT
00065 public:
00066   // To make the items sorted, set 'sort' to true and override KoIconItem::compare().
00067   KoIconChooser(QSize iconSize, QWidget *parent = 0L, const char *name = 0L, bool sort = false);
00068   virtual ~KoIconChooser();
00069 
00070   bool autoDelete() const {return mIconList.autoDelete(); }
00071   void setAutoDelete(bool b) {mIconList.setAutoDelete(b); }
00072 
00073   void addItem(KoIconItem *item);
00074   bool removeItem(KoIconItem *item);
00075   void clear();
00076 
00077   KoIconItem *currentItem();
00078   void setCurrentItem(KoIconItem *item);
00079 
00080   void setDragEnabled(bool allow) { mDragEnabled = allow; }
00081   bool dragEnabled() const { return mDragEnabled; }
00082   
00083   KoIconItem *itemAt(int row, int col);
00084   KoIconItem *itemAt(int index);
00085 
00086 signals:
00087   void  selected(KoIconItem *item);
00088 
00089 protected:
00090   void keyPressEvent(QKeyEvent *e);
00091   void mousePressEvent( QMouseEvent *e);
00092   void mouseReleaseEvent( QMouseEvent *e);
00093   void mouseMoveEvent( QMouseEvent *e);
00094   void resizeEvent(QResizeEvent *e);
00095   void paintCell(QPainter *p, int row, int col);
00096   virtual void startDrag();
00097 
00098 private:
00099   int cellIndex(int row, int col);
00100   void calculateCells();
00101   void showFullPixmap(const QPixmap &pix, const QPoint &p);
00102   int sortInsertionIndex(const KoIconItem *item);
00103 
00104 private:
00105   QPtrList<KoIconItem>    mIconList;
00106   KoPixmapWidget         *mPixmapWidget;
00107   int                     mItemWidth;
00108   int                     mItemHeight;
00109   int                     mItemCount;
00110   int                     mNCols;
00111   int                     mCurRow;
00112   int                     mCurCol;
00113   int                     mMargin;
00114   QPoint                  mDragStartPos;
00115   bool                    mMouseButtonDown;
00116   bool                    mDragEnabled;
00117   bool                    mSort;
00118 };
00119 
00120 // This is a first attempt at a pattern chooser widget abstraction which is at least
00121 // useful for two applications(karbon and krita). It is really a light version of
00122 // kis_patternchooser. (Rob)
00123 class KOPAINTER_EXPORT KoPatternChooser : public QWidget
00124 {
00125   Q_OBJECT
00126 public:
00127   KoPatternChooser( const QPtrList<KoIconItem> &list, QWidget *parent, const char *name = 0 );
00128   ~KoPatternChooser();
00129 
00130   KoIconItem *currentPattern();
00131   void setCurrentPattern( KoIconItem * );
00132   void addPattern( KoIconItem * );
00133  
00134 private:
00135   KoIconChooser *chooser;
00136 
00137 signals:
00138   void selected( KoIconItem * );
00139 };
00140 
00141 
00142 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys