lib

koIconChooser.h
1/* This file is part of the KDE project
2 Copyright (c) 1999 Carsten Pfeiffer (pfeiffer@kde.org)
3 Copyright (c) 2002 Igor Jansen (rm@kde.org)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef __ko_iconchooser_h__
22#define __ko_iconchooser_h__
23
24#include <tqgridview.h>
25#include <tqptrlist.h>
26#include <tqpixmap.h>
27#include <koffice_export.h>
28
29class KoIconItem
30{
31public:
32 KoIconItem() {}
33 virtual ~KoIconItem() {}
34
35 bool hasValidPixmap() {return validPixmap; }
36 bool validPixmap;
37 bool hasValidThumb() {return validThumb; }
38 bool validThumb;
39
40 virtual int spacing() const {return 0; }
41 virtual void setSpacing(int) {}
42 virtual TQPixmap &pixmap() const = 0;
43 virtual TQPixmap &thumbPixmap() const = 0;
44 // Return -1 if this is less than other, 0 if equal, 1 if greater than.
45 virtual int compare(const KoIconItem */*other*/) const { return 0; }
46};
47
48class KoPixmapWidget : public TQFrame
49{
50public:
51 KoPixmapWidget(const TQPixmap &aPixmap, TQWidget *parent = 0L, const char *name = 0L);
52 ~KoPixmapWidget();
53
54protected:
55 void paintEvent(TQPaintEvent *e);
56 void mouseReleaseEvent( TQMouseEvent *e);
57
58private:
59 TQPixmap mPixmap;
60};
61
62class KOPAINTER_EXPORT KoIconChooser: public TQGridView
63{
64 TQ_OBJECT
65
66public:
67 // To make the items sorted, set 'sort' to true and override KoIconItem::compare().
68 KoIconChooser(TQSize iconSize, TQWidget *parent = 0L, const char *name = 0L, bool sort = false);
69 virtual ~KoIconChooser();
70
71 bool autoDelete() const {return mIconList.autoDelete(); }
72 void setAutoDelete(bool b) {mIconList.setAutoDelete(b); }
73
74 void addItem(KoIconItem *item);
75 bool removeItem(KoIconItem *item);
76 void clear();
77
78 KoIconItem *currentItem();
79 void setCurrentItem(KoIconItem *item);
80
81 void setDragEnabled(bool allow) { mDragEnabled = allow; }
82 bool dragEnabled() const { return mDragEnabled; }
83
84 KoIconItem *itemAt(int row, int col);
85 KoIconItem *itemAt(int index);
86
87signals:
88 void selected(KoIconItem *item);
89
90protected:
91 void keyPressEvent(TQKeyEvent *e);
92 void mousePressEvent( TQMouseEvent *e);
93 void mouseReleaseEvent( TQMouseEvent *e);
94 void mouseMoveEvent( TQMouseEvent *e);
95 void resizeEvent(TQResizeEvent *e);
96 void paintCell(TQPainter *p, int row, int col);
97 virtual void startDrag();
98
99private:
100 int cellIndex(int row, int col);
101 void calculateCells();
102 void showFullPixmap(const TQPixmap &pix, const TQPoint &p);
103 int sortInsertionIndex(const KoIconItem *item);
104
105private:
106 TQPtrList<KoIconItem> mIconList;
107 KoPixmapWidget *mPixmapWidget;
108 int mItemWidth;
109 int mItemHeight;
110 int mItemCount;
111 int mNCols;
112 int mCurRow;
113 int mCurCol;
114 int mMargin;
115 TQPoint mDragStartPos;
116 bool mMouseButtonDown;
117 bool mDragEnabled;
118 bool mSort;
119};
120
121// This is a first attempt at a pattern chooser widget abstraction which is at least
122// useful for two applications(karbon and chalk). It is really a light version of
123// kis_patternchooser. (Rob)
124class KOPAINTER_EXPORT KoPatternChooser : public TQWidget
125{
126 TQ_OBJECT
127
128public:
129 KoPatternChooser( const TQPtrList<KoIconItem> &list, TQWidget *parent, const char *name = 0 );
130 ~KoPatternChooser();
131
132 KoIconItem *currentPattern();
133 void setCurrentPattern( KoIconItem * );
134
135public slots:
136 void addPattern( KoIconItem * );
137 void removePattern( KoIconItem * );
138
139private:
140 KoIconChooser *chooser;
141
142signals:
143 void selected( KoIconItem * );
144};
145
146
147#endif
TDEAction * clear(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)