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 00028 class KoIconItem 00029 { 00030 public: 00031 KoIconItem() {} 00032 virtual ~KoIconItem() {} 00033 00034 bool hasValidPixmap() {return validPixmap; } 00035 bool validPixmap; 00036 bool hasValidThumb() {return validThumb; } 00037 bool validThumb; 00038 00039 virtual int spacing() const {return 0; } 00040 virtual void setSpacing(int) {} 00041 virtual QPixmap &pixmap() const = 0; 00042 virtual QPixmap &thumbPixmap() const = 0; 00043 }; 00044 00045 class KoPixmapWidget : public QFrame 00046 { 00047 public: 00048 KoPixmapWidget(const QPixmap &aPixmap, QWidget *parent = 0L, const char *name = 0L); 00049 ~KoPixmapWidget(); 00050 00051 protected: 00052 void paintEvent(QPaintEvent *e); 00053 00054 private: 00055 QPixmap mPixmap; 00056 }; 00057 00058 class KoIconChooser: public QGridView 00059 { 00060 Q_OBJECT 00061 public: 00062 KoIconChooser(QSize iconSize, QWidget *parent = 0L, const char *name = 0L); 00063 virtual ~KoIconChooser(); 00064 00065 bool autoDelete() const {return mIconList.autoDelete(); } 00066 void setAutoDelete(bool b) {mIconList.setAutoDelete(b); } 00067 00068 void addItem(KoIconItem *item); 00069 bool removeItem(KoIconItem *item); 00070 void clear(); 00071 00072 KoIconItem *currentItem(); 00073 void setCurrentItem(KoIconItem *item); 00074 00075 void setDragEnabled(bool allow) { mDragEnabled = allow; } 00076 bool dragEnabled() const { return mDragEnabled; } 00077 00078 signals: 00079 void selected(KoIconItem *item); 00080 00081 protected: 00082 void keyPressEvent(QKeyEvent *e); 00083 void mousePressEvent( QMouseEvent *e); 00084 void mouseReleaseEvent( QMouseEvent *e); 00085 void mouseMoveEvent( QMouseEvent *e); 00086 void resizeEvent(QResizeEvent *e); 00087 void paintCell(QPainter *p, int row, int col); 00088 virtual void startDrag(); 00089 00090 private: 00091 KoIconItem *itemAt(int row, int col); 00092 KoIconItem *itemAt(int index); 00093 int cellIndex(int row, int col); 00094 void calculateCells(); 00095 void showFullPixmap(const QPixmap &pix, const QPoint &p); 00096 00097 private: 00098 QPtrList<KoIconItem> mIconList; 00099 KoPixmapWidget *mPixmapWidget; 00100 int mItemWidth; 00101 int mItemHeight; 00102 int mItemCount; 00103 int nCols; 00104 int mCurRow; 00105 int mCurCol; 00106 int mMargin; 00107 QPoint mDragStartPos; 00108 bool mMouseButtonDown; 00109 bool mDragEnabled; 00110 }; 00111 00112 // This is a first attempt at a pattern chooser widget abstraction which is at least 00113 // useful for two applications(karbon and krita). It is really a light version of 00114 // kis_patternchooser. (Rob) 00115 class KoPatternChooser : public QWidget 00116 { 00117 Q_OBJECT 00118 public: 00119 KoPatternChooser( const QPtrList<KoIconItem> &list, QWidget *parent, const char *name = 0 ); 00120 ~KoPatternChooser(); 00121 00122 KoIconItem *currentPattern(); 00123 void setCurrentPattern( KoIconItem * ); 00124 void addPattern( KoIconItem * ); 00125 00126 private: 00127 KoIconChooser *chooser; 00128 00129 signals: 00130 void selected( KoIconItem * ); 00131 }; 00132 00133 00134 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.3.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Sep 28 04:04:00 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003