lib Library API Documentation

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., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, 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 
00057 private:
00058   QPixmap mPixmap;
00059 };
00060 
00061 class KOPAINTER_EXPORT KoIconChooser: public QGridView
00062 {
00063   Q_OBJECT
00064 public:
00065   // To make the items sorted, set 'sort' to true and override KoIconItem::compare().
00066   KoIconChooser(QSize iconSize, QWidget *parent = 0L, const char *name = 0L, bool sort = false);
00067   virtual ~KoIconChooser();
00068 
00069   bool autoDelete() const {return mIconList.autoDelete(); }
00070   void setAutoDelete(bool b) {mIconList.setAutoDelete(b); }
00071 
00072   void addItem(KoIconItem *item);
00073   bool removeItem(KoIconItem *item);
00074   void clear();
00075 
00076   KoIconItem *currentItem();
00077   void setCurrentItem(KoIconItem *item);
00078 
00079   void setDragEnabled(bool allow) { mDragEnabled = allow; }
00080   bool dragEnabled() const { return mDragEnabled; }
00081 
00082 signals:
00083   void  selected(KoIconItem *item);
00084 
00085 protected:
00086   void keyPressEvent(QKeyEvent *e);
00087   void mousePressEvent( QMouseEvent *e);
00088   void mouseReleaseEvent( QMouseEvent *e);
00089   void mouseMoveEvent( QMouseEvent *e);
00090   void resizeEvent(QResizeEvent *e);
00091   void paintCell(QPainter *p, int row, int col);
00092   virtual void startDrag();
00093 
00094 private:
00095   KoIconItem *itemAt(int row, int col);
00096   KoIconItem *itemAt(int index);
00097   int cellIndex(int row, int col);
00098   void calculateCells();
00099   void showFullPixmap(const QPixmap &pix, const QPoint &p);
00100   int sortInsertionIndex(const KoIconItem *item);
00101 
00102 private:
00103   QPtrList<KoIconItem>    mIconList;
00104   KoPixmapWidget         *mPixmapWidget;
00105   int                     mItemWidth;
00106   int                     mItemHeight;
00107   int                     mItemCount;
00108   int                     mNCols;
00109   int                     mCurRow;
00110   int                     mCurCol;
00111   int                     mMargin;
00112   QPoint                  mDragStartPos;
00113   bool                    mMouseButtonDown;
00114   bool                    mDragEnabled;
00115   bool                    mSort;
00116 };
00117 
00118 // This is a first attempt at a pattern chooser widget abstraction which is at least
00119 // useful for two applications(karbon and krita). It is really a light version of
00120 // kis_patternchooser. (Rob)
00121 class KOPAINTER_EXPORT KoPatternChooser : public QWidget
00122 {
00123   Q_OBJECT
00124 public:
00125   KoPatternChooser( const QPtrList<KoIconItem> &list, QWidget *parent, const char *name = 0 );
00126   ~KoPatternChooser();
00127 
00128   KoIconItem *currentPattern();
00129   void setCurrentPattern( KoIconItem * );
00130   void addPattern( KoIconItem * );
00131  
00132 private:
00133   KoIconChooser *chooser;
00134 
00135 signals:
00136   void selected( KoIconItem * );
00137 };
00138 
00139 
00140 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:40:01 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003