lib
koIconChooser.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00045 virtual int compare(const KoIconItem *) 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
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
00121
00122
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
|