|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt3Support module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef Q3ICONVIEW_H |
|
43 #define Q3ICONVIEW_H |
|
44 |
|
45 #include <Qt3Support/q3scrollview.h> |
|
46 #include <QtCore/qstring.h> |
|
47 #include <QtCore/qrect.h> |
|
48 #include <QtCore/qpoint.h> |
|
49 #include <QtCore/qsize.h> |
|
50 #include <QtGui/qfont.h> // QString->QFont conversion |
|
51 #include <Qt3Support/q3dragobject.h> |
|
52 #include <QtGui/qbitmap.h> |
|
53 #include <QtGui/qpicture.h> |
|
54 #include <Qt3Support/q3valuelist.h> |
|
55 |
|
56 QT_BEGIN_HEADER |
|
57 |
|
58 QT_BEGIN_NAMESPACE |
|
59 |
|
60 QT_MODULE(Qt3SupportLight) |
|
61 |
|
62 #ifndef QT_NO_ICONVIEW |
|
63 |
|
64 class Q3IconView; |
|
65 class QPainter; |
|
66 class QMimeSource; |
|
67 class QMouseEvent; |
|
68 class QDragEnterEvent; |
|
69 class QDragMoveEvent; |
|
70 class QDragLeaveEvent; |
|
71 class QKeyEvent; |
|
72 class QFocusEvent; |
|
73 class QShowEvent; |
|
74 class Q3IconViewItem; |
|
75 class Q3IconViewItemLineEdit; |
|
76 class QStringList; |
|
77 class Q3IconDragPrivate; |
|
78 class QColorGroup; |
|
79 |
|
80 #ifndef QT_NO_DRAGANDDROP |
|
81 |
|
82 class Q_COMPAT_EXPORT Q3IconDragItem |
|
83 { |
|
84 public: |
|
85 Q3IconDragItem(); |
|
86 virtual ~Q3IconDragItem(); |
|
87 virtual QByteArray data() const; |
|
88 virtual void setData(const QByteArray &d); |
|
89 bool operator== (const Q3IconDragItem&) const; |
|
90 |
|
91 private: |
|
92 QByteArray ba; |
|
93 |
|
94 }; |
|
95 |
|
96 class Q_COMPAT_EXPORT Q3IconDrag : public Q3DragObject |
|
97 { |
|
98 Q_OBJECT |
|
99 public: |
|
100 Q3IconDrag(QWidget * dragSource, const char* name = 0); |
|
101 virtual ~Q3IconDrag(); |
|
102 |
|
103 void append(const Q3IconDragItem &item, const QRect &pr, const QRect &tr); |
|
104 |
|
105 virtual const char* format(int i) const; |
|
106 static bool canDecode(QMimeSource* e); |
|
107 virtual QByteArray encodedData(const char* mime) const; |
|
108 |
|
109 private: |
|
110 Q_DISABLE_COPY(Q3IconDrag) |
|
111 |
|
112 Q3IconDragPrivate *d; |
|
113 QChar endMark; |
|
114 |
|
115 friend class Q3IconView; |
|
116 friend class Q3IconViewPrivate; |
|
117 }; |
|
118 |
|
119 #endif |
|
120 |
|
121 class Q3IconViewToolTip; |
|
122 class Q3IconViewItemPrivate; |
|
123 |
|
124 class Q_COMPAT_EXPORT Q3IconViewItem |
|
125 { |
|
126 friend class Q3IconView; |
|
127 friend class Q3IconViewToolTip; |
|
128 friend class Q3IconViewItemLineEdit; |
|
129 |
|
130 public: |
|
131 Q3IconViewItem(Q3IconView *parent); |
|
132 Q3IconViewItem(Q3IconView *parent, Q3IconViewItem *after); |
|
133 Q3IconViewItem(Q3IconView *parent, const QString &text); |
|
134 Q3IconViewItem(Q3IconView *parent, Q3IconViewItem *after, const QString &text); |
|
135 Q3IconViewItem(Q3IconView *parent, const QString &text, const QPixmap &icon); |
|
136 Q3IconViewItem(Q3IconView *parent, Q3IconViewItem *after, const QString &text, const QPixmap &icon); |
|
137 #ifndef QT_NO_PICTURE |
|
138 Q3IconViewItem(Q3IconView *parent, const QString &text, const QPicture &picture); |
|
139 Q3IconViewItem(Q3IconView *parent, Q3IconViewItem *after, const QString &text, const QPicture &picture); |
|
140 #endif |
|
141 virtual ~Q3IconViewItem(); |
|
142 |
|
143 virtual void setRenameEnabled(bool allow); |
|
144 virtual void setDragEnabled(bool allow); |
|
145 virtual void setDropEnabled(bool allow); |
|
146 |
|
147 virtual QString text() const; |
|
148 virtual QPixmap *pixmap() const; |
|
149 #ifndef QT_NO_PICTURE |
|
150 virtual QPicture *picture() const; |
|
151 #endif |
|
152 virtual QString key() const; |
|
153 |
|
154 bool renameEnabled() const; |
|
155 bool dragEnabled() const; |
|
156 bool dropEnabled() const; |
|
157 |
|
158 Q3IconView *iconView() const; |
|
159 Q3IconViewItem *prevItem() const; |
|
160 Q3IconViewItem *nextItem() const; |
|
161 |
|
162 int index() const; |
|
163 |
|
164 virtual void setSelected(bool s, bool cb); |
|
165 virtual void setSelected(bool s); |
|
166 virtual void setSelectable(bool s); |
|
167 |
|
168 bool isSelected() const; |
|
169 bool isSelectable() const; |
|
170 |
|
171 virtual void repaint(); |
|
172 |
|
173 virtual bool move(int x, int y); |
|
174 virtual void moveBy(int dx, int dy); |
|
175 virtual bool move(const QPoint &pnt); |
|
176 virtual void moveBy(const QPoint &pnt); |
|
177 |
|
178 QRect rect() const; |
|
179 int x() const; |
|
180 int y() const; |
|
181 int width() const; |
|
182 int height() const; |
|
183 QSize size() const; |
|
184 QPoint pos() const; |
|
185 QRect textRect(bool relative = true) const; |
|
186 QRect pixmapRect(bool relative = true) const; |
|
187 bool contains(const QPoint& pnt) const; |
|
188 bool intersects(const QRect& r) const; |
|
189 |
|
190 virtual bool acceptDrop(const QMimeSource *mime) const; |
|
191 |
|
192 #ifndef QT_NO_TEXTEDIT |
|
193 void rename(); |
|
194 #endif |
|
195 |
|
196 virtual int compare(Q3IconViewItem *i) const; |
|
197 |
|
198 virtual void setText(const QString &text); |
|
199 virtual void setPixmap(const QPixmap &icon); |
|
200 #ifndef QT_NO_PICTURE |
|
201 virtual void setPicture(const QPicture &icon); |
|
202 #endif |
|
203 virtual void setText(const QString &text, bool recalc, bool redraw = true); |
|
204 virtual void setPixmap(const QPixmap &icon, bool recalc, bool redraw = true); |
|
205 virtual void setKey(const QString &k); |
|
206 |
|
207 virtual int rtti() const; |
|
208 static int RTTI; |
|
209 |
|
210 protected: |
|
211 #ifndef QT_NO_TEXTEDIT |
|
212 virtual void removeRenameBox(); |
|
213 #endif |
|
214 virtual void calcRect(const QString &text_ = QString()); |
|
215 virtual void paintItem(QPainter *p, const QColorGroup &cg); |
|
216 virtual void paintFocus(QPainter *p, const QColorGroup &cg); |
|
217 #ifndef QT_NO_DRAGANDDROP |
|
218 virtual void dropped(QDropEvent *e, const Q3ValueList<Q3IconDragItem> &lst); |
|
219 #endif |
|
220 virtual void dragEntered(); |
|
221 virtual void dragLeft(); |
|
222 void setItemRect(const QRect &r); |
|
223 void setTextRect(const QRect &r); |
|
224 void setPixmapRect(const QRect &r); |
|
225 void calcTmpText(); |
|
226 QString tempText() const; |
|
227 |
|
228 private: |
|
229 void init(Q3IconViewItem *after = 0 |
|
230 #ifndef QT_NO_PICTURE |
|
231 , QPicture *pic = 0 |
|
232 #endif |
|
233 ); |
|
234 #ifndef QT_NO_TEXTEDIT |
|
235 void renameItem(); |
|
236 void cancelRenameItem(); |
|
237 #endif |
|
238 void checkRect(); |
|
239 |
|
240 Q3IconView *view; |
|
241 QString itemText, itemKey; |
|
242 QString tmpText; |
|
243 QPixmap *itemIcon; |
|
244 #ifndef QT_NO_PICTURE |
|
245 QPicture *itemPic; |
|
246 #endif |
|
247 Q3IconViewItem *prev, *next; |
|
248 uint allow_rename : 1; |
|
249 uint allow_drag : 1; |
|
250 uint allow_drop : 1; |
|
251 uint selected : 1; |
|
252 uint selectable : 1; |
|
253 uint dirty : 1; |
|
254 uint wordWrapDirty : 1; |
|
255 QRect itemRect, itemTextRect, itemIconRect; |
|
256 #ifndef QT_NO_TEXTEDIT |
|
257 Q3IconViewItemLineEdit *renameBox; |
|
258 #endif |
|
259 QRect oldRect; |
|
260 |
|
261 Q3IconViewItemPrivate *d; |
|
262 |
|
263 }; |
|
264 |
|
265 class Q3IconViewPrivate; |
|
266 |
|
267 class Q_COMPAT_EXPORT Q3IconView : public Q3ScrollView |
|
268 { |
|
269 friend class Q3IconViewItem; |
|
270 friend class Q3IconViewPrivate; |
|
271 friend class Q3IconViewToolTip; |
|
272 |
|
273 Q_OBJECT |
|
274 // #### sorting and sort direction do not work |
|
275 Q_ENUMS(SelectionMode ItemTextPos Arrangement ResizeMode) |
|
276 Q_PROPERTY(bool sorting READ sorting) |
|
277 Q_PROPERTY(bool sortDirection READ sortDirection) |
|
278 Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) |
|
279 Q_PROPERTY(int gridX READ gridX WRITE setGridX) |
|
280 Q_PROPERTY(int gridY READ gridY WRITE setGridY) |
|
281 Q_PROPERTY(int spacing READ spacing WRITE setSpacing) |
|
282 Q_PROPERTY(ItemTextPos itemTextPos READ itemTextPos WRITE setItemTextPos) |
|
283 Q_PROPERTY(QBrush itemTextBackground READ itemTextBackground WRITE setItemTextBackground) |
|
284 Q_PROPERTY(Arrangement arrangement READ arrangement WRITE setArrangement) |
|
285 Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) |
|
286 Q_PROPERTY(int maxItemWidth READ maxItemWidth WRITE setMaxItemWidth) |
|
287 Q_PROPERTY(int maxItemTextLength READ maxItemTextLength WRITE setMaxItemTextLength) |
|
288 Q_PROPERTY(bool autoArrange READ autoArrange WRITE setAutoArrange) |
|
289 Q_PROPERTY(bool itemsMovable READ itemsMovable WRITE setItemsMovable) |
|
290 Q_PROPERTY(bool wordWrapIconText READ wordWrapIconText WRITE setWordWrapIconText) |
|
291 Q_PROPERTY(bool showToolTips READ showToolTips WRITE setShowToolTips) |
|
292 Q_PROPERTY(uint count READ count) |
|
293 |
|
294 public: |
|
295 enum SelectionMode { |
|
296 Single = 0, |
|
297 Multi, |
|
298 Extended, |
|
299 NoSelection |
|
300 }; |
|
301 enum Arrangement { |
|
302 LeftToRight = 0, |
|
303 TopToBottom |
|
304 }; |
|
305 enum ResizeMode { |
|
306 Fixed = 0, |
|
307 Adjust |
|
308 }; |
|
309 enum ItemTextPos { |
|
310 Bottom = 0, |
|
311 Right |
|
312 }; |
|
313 |
|
314 Q3IconView(QWidget* parent=0, const char* name=0, Qt::WindowFlags f = 0); |
|
315 virtual ~Q3IconView(); |
|
316 |
|
317 virtual void insertItem(Q3IconViewItem *item, Q3IconViewItem *after = 0L); |
|
318 virtual void takeItem(Q3IconViewItem *item); |
|
319 |
|
320 int index(const Q3IconViewItem *item) const; |
|
321 |
|
322 Q3IconViewItem *firstItem() const; |
|
323 Q3IconViewItem *lastItem() const; |
|
324 Q3IconViewItem *currentItem() const; |
|
325 virtual void setCurrentItem(Q3IconViewItem *item); |
|
326 virtual void setSelected(Q3IconViewItem *item, bool s, bool cb = false); |
|
327 |
|
328 uint count() const; |
|
329 |
|
330 public: |
|
331 virtual void showEvent(QShowEvent *); |
|
332 |
|
333 virtual void setSelectionMode(SelectionMode m); |
|
334 SelectionMode selectionMode() const; |
|
335 |
|
336 Q3IconViewItem *findItem(const QPoint &pos) const; |
|
337 |
|
338 enum StringComparisonMode { |
|
339 CaseSensitive = 0x00001, // 0 0001 |
|
340 BeginsWith = 0x00002, // 0 0010 |
|
341 EndsWith = 0x00004, // 0 0100 |
|
342 Contains = 0x00008, // 0 1000 |
|
343 ExactMatch = 0x00010 // 1 0000 |
|
344 }; |
|
345 typedef uint ComparisonFlags; |
|
346 Q3IconViewItem *findItem(const QString &text, ComparisonFlags = BeginsWith | Qt::CaseSensitive) const; |
|
347 virtual void selectAll(bool select); |
|
348 virtual void clearSelection(); |
|
349 virtual void invertSelection(); |
|
350 |
|
351 virtual void repaintItem(Q3IconViewItem *item); |
|
352 void repaintSelectedItems(); |
|
353 |
|
354 void ensureItemVisible(Q3IconViewItem *item); |
|
355 Q3IconViewItem* findFirstVisibleItem(const QRect &r) const; |
|
356 Q3IconViewItem* findLastVisibleItem(const QRect &r) const; |
|
357 |
|
358 virtual void clear(); |
|
359 |
|
360 virtual void setGridX(int rx); |
|
361 virtual void setGridY(int ry); |
|
362 int gridX() const; |
|
363 int gridY() const; |
|
364 virtual void setSpacing(int sp); |
|
365 int spacing() const; |
|
366 virtual void setItemTextPos(ItemTextPos pos); |
|
367 ItemTextPos itemTextPos() const; |
|
368 virtual void setItemTextBackground(const QBrush &b); |
|
369 QBrush itemTextBackground() const; |
|
370 virtual void setArrangement(Arrangement am); |
|
371 Arrangement arrangement() const; |
|
372 virtual void setResizeMode(ResizeMode am); |
|
373 ResizeMode resizeMode() const; |
|
374 virtual void setMaxItemWidth(int w); |
|
375 int maxItemWidth() const; |
|
376 virtual void setMaxItemTextLength(int w); |
|
377 int maxItemTextLength() const; |
|
378 virtual void setAutoArrange(bool b); |
|
379 bool autoArrange() const; |
|
380 virtual void setShowToolTips(bool b); |
|
381 bool showToolTips() const; |
|
382 |
|
383 void setSorting(bool sort, bool ascending = true); |
|
384 bool sorting() const; |
|
385 bool sortDirection() const; |
|
386 |
|
387 virtual void setItemsMovable(bool b); |
|
388 bool itemsMovable() const; |
|
389 virtual void setWordWrapIconText(bool b); |
|
390 bool wordWrapIconText() const; |
|
391 |
|
392 bool eventFilter(QObject * o, QEvent *); |
|
393 |
|
394 QSize minimumSizeHint() const; |
|
395 QSize sizeHint() const; |
|
396 |
|
397 virtual void sort(bool ascending = true); |
|
398 |
|
399 bool isRenaming() const; |
|
400 |
|
401 QVariant inputMethodQuery(Qt::InputMethodQuery query) const; |
|
402 |
|
403 public Q_SLOTS: |
|
404 virtual void arrangeItemsInGrid(const QSize &grid, bool update = true); |
|
405 virtual void arrangeItemsInGrid(bool update = true); |
|
406 virtual void setContentsPos(int x, int y); |
|
407 virtual void updateContents(); |
|
408 |
|
409 Q_SIGNALS: |
|
410 void selectionChanged(); |
|
411 void selectionChanged(Q3IconViewItem *item); |
|
412 void currentChanged(Q3IconViewItem *item); |
|
413 void clicked(Q3IconViewItem *); |
|
414 void clicked(Q3IconViewItem *, const QPoint &); |
|
415 void pressed(Q3IconViewItem *); |
|
416 void pressed(Q3IconViewItem *, const QPoint &); |
|
417 |
|
418 void doubleClicked(Q3IconViewItem *item); |
|
419 void returnPressed(Q3IconViewItem *item); |
|
420 void rightButtonClicked(Q3IconViewItem* item, const QPoint& pos); |
|
421 void rightButtonPressed(Q3IconViewItem* item, const QPoint& pos); |
|
422 void mouseButtonPressed(int button, Q3IconViewItem* item, const QPoint& pos); |
|
423 void mouseButtonClicked(int button, Q3IconViewItem* item, const QPoint& pos); |
|
424 void contextMenuRequested(Q3IconViewItem* item, const QPoint &pos); |
|
425 |
|
426 #ifndef QT_NO_DRAGANDDROP |
|
427 void dropped(QDropEvent *e, const Q3ValueList<Q3IconDragItem> &lst); |
|
428 #endif |
|
429 void moved(); |
|
430 void onItem(Q3IconViewItem *item); |
|
431 void onViewport(); |
|
432 void itemRenamed(Q3IconViewItem *item, const QString &); |
|
433 void itemRenamed(Q3IconViewItem *item); |
|
434 |
|
435 protected Q_SLOTS: |
|
436 virtual void doAutoScroll(); |
|
437 virtual void adjustItems(); |
|
438 virtual void slotUpdate(); |
|
439 |
|
440 private Q_SLOTS: |
|
441 void movedContents(int dx, int dy); |
|
442 |
|
443 protected: |
|
444 void drawContents(QPainter *p, int cx, int cy, int cw, int ch); |
|
445 void contentsMousePressEvent(QMouseEvent *e); |
|
446 void contentsMouseReleaseEvent(QMouseEvent *e); |
|
447 void contentsMouseMoveEvent(QMouseEvent *e); |
|
448 void contentsMouseDoubleClickEvent(QMouseEvent *e); |
|
449 void contentsContextMenuEvent(QContextMenuEvent *e); |
|
450 |
|
451 #ifndef QT_NO_DRAGANDDROP |
|
452 void contentsDragEnterEvent(QDragEnterEvent *e); |
|
453 void contentsDragMoveEvent(QDragMoveEvent *e); |
|
454 void contentsDragLeaveEvent(QDragLeaveEvent *e); |
|
455 void contentsDropEvent(QDropEvent *e); |
|
456 #endif |
|
457 |
|
458 void resizeEvent(QResizeEvent* e); |
|
459 void keyPressEvent(QKeyEvent *e); |
|
460 void focusInEvent(QFocusEvent *e); |
|
461 void focusOutEvent(QFocusEvent *e); |
|
462 void enterEvent(QEvent *e); |
|
463 |
|
464 virtual void drawRubber(QPainter *p); |
|
465 #ifndef QT_NO_DRAGANDDROP |
|
466 virtual Q3DragObject *dragObject(); |
|
467 virtual void startDrag(); |
|
468 #endif |
|
469 virtual void insertInGrid(Q3IconViewItem *item); |
|
470 virtual void drawBackground(QPainter *p, const QRect &r); |
|
471 |
|
472 void emitSelectionChanged(Q3IconViewItem * i = 0); |
|
473 void emitRenamed(Q3IconViewItem *item); |
|
474 |
|
475 Q3IconViewItem *makeRowLayout(Q3IconViewItem *begin, int &y, bool &changed); |
|
476 |
|
477 void changeEvent(QEvent *); |
|
478 |
|
479 private: |
|
480 Q_DISABLE_COPY(Q3IconView) |
|
481 |
|
482 void contentsMousePressEventEx(QMouseEvent *e); |
|
483 virtual void drawDragShapes(const QPoint &pnt); |
|
484 #ifndef QT_NO_DRAGANDDROP |
|
485 virtual void initDragEnter(QDropEvent *e); |
|
486 #endif |
|
487 Q3IconViewItem* findItemByName(Q3IconViewItem *start); |
|
488 void handleItemChange(Q3IconViewItem *old, bool shift, |
|
489 bool control, bool homeend = false); |
|
490 |
|
491 int calcGridNum(int w, int x) const; |
|
492 Q3IconViewItem *rowBegin(Q3IconViewItem *item) const; |
|
493 void updateItemContainer(Q3IconViewItem *item); |
|
494 void appendItemContainer(); |
|
495 void rebuildContainers(); |
|
496 enum Direction { |
|
497 DirUp = 0, |
|
498 DirDown, |
|
499 DirLeft, |
|
500 DirRight |
|
501 }; |
|
502 Q3IconViewItem* findItem(Direction dir, |
|
503 const QPoint &relativeTo, |
|
504 const QRect &searchRect) const; |
|
505 bool neighbourItem(Direction dir, |
|
506 const QPoint &relativeTo, |
|
507 const Q3IconViewItem *item) const; |
|
508 QBitmap mask(QPixmap *pix) const; |
|
509 |
|
510 Q3IconViewPrivate *d; |
|
511 }; |
|
512 |
|
513 #endif // QT_NO_ICONVIEW |
|
514 |
|
515 QT_END_NAMESPACE |
|
516 |
|
517 QT_END_HEADER |
|
518 |
|
519 #endif // QICONVIEW_H |