author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 12:15:23 +0300 | |
branch | RCL_3 |
changeset 12 | cc75c76972ee |
parent 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
#include <qplatformdefs.h> |
|
43 |
#include "q3listview.h" |
|
44 |
#ifndef QT_NO_LISTVIEW |
|
45 |
#include "q3tl.h" |
|
46 |
#include "qapplication.h" |
|
47 |
#include "qbitmap.h" |
|
48 |
#include "q3cleanuphandler.h" |
|
49 |
#include "qcursor.h" |
|
50 |
#include "qdatetime.h" |
|
51 |
#include "q3dragobject.h" |
|
52 |
#include "qevent.h" |
|
53 |
#include "qhash.h" |
|
54 |
#include "q3header.h" |
|
55 |
#include "qicon.h" |
|
56 |
#include "qlineedit.h" |
|
57 |
#include "qpainter.h" |
|
58 |
#include "qpixmapcache.h" |
|
59 |
#include "qstack.h" |
|
60 |
#include "qstyle.h" |
|
61 |
#include "qstyleoption.h" |
|
62 |
#include "qtimer.h" |
|
63 |
#include "qtooltip.h" |
|
64 |
#include "qdebug.h" |
|
65 |
#ifndef QT_NO_ACCESSIBILITY |
|
66 |
#include "qaccessible.h" |
|
67 |
#endif |
|
68 |
||
69 |
QT_BEGIN_NAMESPACE |
|
70 |
||
71 |
const int Unsorted = 16383; |
|
72 |
||
73 |
struct Q3ListViewPrivate |
|
74 |
{ |
|
75 |
// classes that are here to avoid polluting the global name space |
|
76 |
||
77 |
// the magical hidden mother of all items |
|
78 |
class Root: public Q3ListViewItem { |
|
79 |
public: |
|
80 |
Root(Q3ListView * parent); |
|
81 |
||
82 |
void setHeight(int); |
|
83 |
void invalidateHeight(); |
|
84 |
void setup(); |
|
85 |
Q3ListView * theListView() const; |
|
86 |
||
87 |
Q3ListView * lv; |
|
88 |
}; |
|
89 |
||
90 |
// to remember what's on screen |
|
91 |
class DrawableItem { |
|
92 |
public: |
|
93 |
DrawableItem() {} |
|
94 |
DrawableItem(int level, int ypos, Q3ListViewItem * item) |
|
95 |
: l(level), y(ypos), i(item) {}; |
|
96 |
int l; |
|
97 |
int y; |
|
98 |
Q3ListViewItem * i; |
|
99 |
}; |
|
100 |
||
101 |
// for sorting |
|
102 |
class SortableItem { |
|
103 |
public: |
|
104 |
/* |
|
105 |
We could be smarter and keep a pointer to the Q3ListView |
|
106 |
item instead of numCols, col and asc. This would then allow |
|
107 |
us to use the physical ordering of columns rather than the |
|
108 |
logical. Microsoft uses the logical ordering, so there is |
|
109 |
some virtue in doing so, although it prevents the user from |
|
110 |
choosing the secondary key. |
|
111 |
*/ |
|
112 |
Q3ListViewItem * item; |
|
113 |
int numCols; |
|
114 |
int col; |
|
115 |
bool asc; |
|
116 |
||
117 |
int cmp(const SortableItem& i) const { |
|
118 |
int diff = item->compare(i.item, col, asc); |
|
119 |
if (diff == 0 && numCols != 1) { |
|
120 |
for (int j = 0; j < numCols; j++) { |
|
121 |
if (j != col) { |
|
122 |
diff = item->compare(i.item, j, asc); |
|
123 |
if (diff != 0) |
|
124 |
break; |
|
125 |
} |
|
126 |
} |
|
127 |
} |
|
128 |
return diff; |
|
129 |
} |
|
130 |
bool operator<(const SortableItem& i) const { return cmp(i) < 0; } |
|
131 |
bool operator<=(const SortableItem& i) const { return cmp(i) <= 0; } |
|
132 |
bool operator>(const SortableItem& i) const { return cmp(i) > 0; } |
|
133 |
}; |
|
134 |
||
135 |
class ItemColumnInfo { |
|
136 |
public: |
|
137 |
ItemColumnInfo(): pm(0), next(0), truncated(false), dirty(false), allow_rename(false), width(0) {} |
|
138 |
~ItemColumnInfo() { delete pm; delete next; } |
|
139 |
QString text, tmpText; |
|
140 |
QPixmap * pm; |
|
141 |
ItemColumnInfo * next; |
|
142 |
uint truncated : 1; |
|
143 |
uint dirty : 1; |
|
144 |
uint allow_rename : 1; |
|
145 |
int width; |
|
146 |
}; |
|
147 |
||
148 |
class ViewColumnInfo { |
|
149 |
public: |
|
150 |
ViewColumnInfo(): align(Qt::AlignAuto), sortable(true), next(0) {} |
|
151 |
~ViewColumnInfo() { delete next; } |
|
152 |
int align; |
|
153 |
bool sortable; |
|
154 |
ViewColumnInfo * next; |
|
155 |
}; |
|
156 |
||
157 |
// private variables used in Q3ListView |
|
158 |
ViewColumnInfo * vci; |
|
159 |
Q3Header * h; |
|
160 |
Root * r; |
|
161 |
uint rootIsExpandable : 1; |
|
162 |
int margin; |
|
163 |
||
164 |
Q3ListViewItem * focusItem, *highlighted, *oldFocusItem; |
|
165 |
||
166 |
QTimer * timer; |
|
167 |
QTimer * dirtyItemTimer; |
|
168 |
QTimer * visibleTimer; |
|
169 |
int levelWidth; |
|
170 |
||
171 |
// the list of drawables, and the range drawables covers entirely |
|
172 |
// (it may also include a few items above topPixel) |
|
173 |
QList<DrawableItem> drawables; |
|
174 |
int topPixel; |
|
175 |
int bottomPixel; |
|
176 |
||
177 |
QList<const Q3ListViewItem *> dirtyItems; |
|
178 |
||
179 |
Q3ListView::SelectionMode selectionMode; |
|
180 |
||
181 |
// Per-column structure for information not in the Q3Header |
|
182 |
struct Column { |
|
183 |
Q3ListView::WidthMode wmode; |
|
184 |
}; |
|
185 |
QVector<Column> column; |
|
186 |
||
187 |
// suggested height for the items |
|
188 |
int fontMetricsHeight; |
|
189 |
int minLeftBearing, minRightBearing; |
|
190 |
int ellipsisWidth; |
|
191 |
||
192 |
// currently typed prefix for the keyboard interface, and the time |
|
193 |
// of the last key-press |
|
194 |
QString currentPrefix; |
|
195 |
QTime currentPrefixTime; |
|
196 |
||
197 |
// holds a list of iterators |
|
198 |
QList<Q3ListViewItemIterator *> iterators; |
|
199 |
Q3ListViewItem *pressedItem, *selectAnchor; |
|
200 |
||
201 |
QTimer *scrollTimer; |
|
202 |
QTimer *renameTimer; |
|
203 |
QTimer *autoopenTimer; |
|
204 |
||
205 |
// sort column and order #### may need to move to Q3Header [subclass] |
|
206 |
int sortcolumn; |
|
207 |
bool ascending :1; |
|
208 |
bool sortIndicator :1; |
|
209 |
// whether to select or deselect during this mouse press. |
|
210 |
bool allColumnsShowFocus :1; |
|
211 |
bool select :1; |
|
212 |
||
213 |
// true if the widget should take notice of mouseReleaseEvent |
|
214 |
bool buttonDown :1; |
|
215 |
// true if the widget should ignore a double-click |
|
216 |
bool ignoreDoubleClick :1; |
|
217 |
||
218 |
bool clearing :1; |
|
219 |
bool pressedSelected :1; |
|
220 |
bool pressedEmptyArea :1; |
|
221 |
||
222 |
bool toolTips :1; |
|
223 |
bool fullRepaintOnComlumnChange:1; |
|
224 |
bool updateHeader :1; |
|
225 |
||
226 |
bool startEdit : 1; |
|
227 |
bool ignoreEditAfterFocus : 1; |
|
228 |
bool inMenuMode :1; |
|
229 |
||
230 |
Q3ListView::RenameAction defRenameAction; |
|
231 |
||
232 |
Q3ListViewItem *startDragItem; |
|
233 |
QPoint dragStartPos; |
|
234 |
int pressedColumn; |
|
235 |
Q3ListView::ResizeMode resizeMode; |
|
236 |
}; |
|
237 |
||
238 |
Q_DECLARE_TYPEINFO(Q3ListViewPrivate::DrawableItem, Q_PRIMITIVE_TYPE); |
|
239 |
||
240 |
// these should probably be in Q3ListViewPrivate, for future thread safety |
|
241 |
static bool activatedByClick; |
|
242 |
static QPoint activatedP; |
|
243 |
||
244 |
#ifndef QT_NO_ACCESSIBILITY |
|
245 |
static int indexOfItem(Q3ListViewItem *item) |
|
246 |
{ |
|
247 |
if (!QAccessible::isActive()) |
|
248 |
return 0; |
|
249 |
||
250 |
static Q3ListViewItem *lastItem = 0; |
|
251 |
static int lastIndex = 0; |
|
252 |
||
253 |
if (!item || !item->listView()) |
|
254 |
return 0; |
|
255 |
||
256 |
if (item == lastItem) |
|
257 |
return lastIndex; |
|
258 |
||
259 |
lastItem = item; |
|
260 |
int index = 1; |
|
261 |
||
262 |
Q3ListViewItemIterator it(item->listView()); |
|
263 |
while (it.current()) { |
|
264 |
if (it.current() == item) { |
|
265 |
lastIndex = index; |
|
266 |
return index; |
|
267 |
} |
|
268 |
++it; |
|
269 |
++index; |
|
270 |
} |
|
271 |
lastIndex = 0; |
|
272 |
return 0; |
|
273 |
} |
|
274 |
#endif |
|
275 |
||
276 |
/*! |
|
277 |
Creates a string with ... like "Trollte..." or "...olltech", depending on the alignment. |
|
278 |
*/ |
|
279 |
static QString qEllipsisText(const QString &org, const QFontMetrics &fm, int width, int align) |
|
280 |
{ |
|
281 |
int ellWidth = fm.width(QLatin1String("...")); |
|
282 |
QString text = QString::fromLatin1(""); |
|
283 |
int i = 0; |
|
284 |
int len = org.length(); |
|
285 |
int offset = (align & Qt::AlignRight) ? (len-1) - i : i; |
|
286 |
while (i < len && fm.width(text + org[offset]) + ellWidth < width) { |
|
287 |
if (align & Qt::AlignRight) |
|
288 |
text.prepend(org[offset]); |
|
289 |
else |
|
290 |
text += org[offset]; |
|
291 |
offset = (align & Qt::AlignRight) ? (len-1) - ++i : ++i; |
|
292 |
} |
|
293 |
if (text.isEmpty()) |
|
294 |
text = (align & Qt::AlignRight) ? org.right(1) : text = org.left(1); |
|
295 |
if (align & Qt::AlignRight) |
|
296 |
text.prepend(QLatin1String("...")); |
|
297 |
else |
|
298 |
text += QLatin1String("..."); |
|
299 |
return text; |
|
300 |
} |
|
301 |
||
302 |
/*! |
|
303 |
\class Q3ListViewItem |
|
304 |
\brief The Q3ListViewItem class implements a list view item. |
|
305 |
||
306 |
\compat |
|
307 |
||
308 |
A list view item is a multi-column object capable of displaying |
|
309 |
itself in a Q3ListView. |
|
310 |
||
311 |
The easiest way to use Q3ListViewItem is to construct one with a |
|
312 |
few constant strings, and either a Q3ListView or another |
|
313 |
Q3ListViewItem as parent. |
|
314 |
\snippet doc/src/snippets/code/src_qt3support_itemviews_q3listview.cpp 0 |
|
315 |
We've discarded the pointers to the items since we can still access |
|
316 |
them via their parent \e listView. By default, Q3ListView sorts its |
|
317 |
items; this can be switched off with Q3ListView::setSorting(-1). |
|
318 |
||
319 |
The parent must be another Q3ListViewItem or a Q3ListView. If the |
|
320 |
parent is a Q3ListView, the item becomes a top-level item within |
|
321 |
that Q3ListView. If the parent is another Q3ListViewItem, the item |
|
322 |
becomes a child of that list view item. |
|
323 |
||
324 |
If you keep the pointer, you can set or change the texts using |
|
325 |
setText(), add pixmaps using setPixmap(), change its mode using |
|
326 |
setSelectable(), setSelected(), setOpen() and setExpandable(). |
|
327 |
You'll also be able to change its height using setHeight(), and |
|
328 |
traverse its sub-items. You don't have to keep the pointer since |
|
329 |
you can get a pointer to any Q3ListViewItem in a Q3ListView using |
|
330 |
Q3ListView::selectedItem(), Q3ListView::currentItem(), |
|
331 |
Q3ListView::firstChild(), Q3ListView::lastItem() and |
|
332 |
Q3ListView::findItem(). |
|
333 |
||
334 |
If you call \c delete on a list view item, it will be deleted as |
|
335 |
expected, and as usual for \l{QObject}s, if it has any child items |
|
336 |
(to any depth), all these will be deleted too. |
|
337 |
||
338 |
\l{Q3CheckListItem}s are list view items that have a checkbox or |
|
339 |
radio button and can be used in place of plain Q3ListViewItems. |
|
340 |
||
341 |
You can traverse the tree as if it were a doubly-linked list using |
|
342 |
itemAbove() and itemBelow(); they return pointers to the items |
|
343 |
directly above and below this item on the screen (even if none of |
|
344 |
them are actually visible at the moment). |
|
345 |
||
346 |
Here's how to traverse all of an item's children (but not its |
|
347 |
children's children, etc.): |
|
348 |
Example: |
|
349 |
\snippet doc/src/snippets/code/src_qt3support_itemviews_q3listview.cpp 1 |
|
350 |
||
351 |
If you want to iterate over every item, to any level of depth use |
|
352 |
an iterator. To iterate over the entire tree, initialize the |
|
353 |
iterator with the list view itself; to iterate over an item's |
|
354 |
children (and children's children to any depth), initialize the |
|
355 |
iterator with the item: |
|
356 |
\snippet doc/src/snippets/code/src_qt3support_itemviews_q3listview.cpp 2 |
|
357 |
||
358 |
Note that the order of the children will change when the sorting |
|
359 |
order changes and is undefined if the items are not visible. You |
|
360 |
can, however, call enforceSortOrder() at any time; Q3ListView will |
|
361 |
always call it before it needs to show an item. |
|
362 |
||
363 |
Many programs will need to reimplement Q3ListViewItem. The most |
|
364 |
commonly reimplemented functions are: |
|
365 |
\table |
|
366 |
\header \i Function \i Description |
|
367 |
\row \i \l text() |
|
368 |
\i Returns the text in a column. Many subclasses will compute |
|
369 |
this on the fly. |
|
370 |
\row \i \l key() |
|
371 |
\i Used for sorting. The default key() simply calls |
|
372 |
text(), but judicious use of key() can give you fine |
|
373 |
control over sorting; for example, QFileDialog |
|
374 |
reimplements key() to sort by date. |
|
375 |
\row \i \l setup() |
|
376 |
\i Called before showing the item and whenever the list |
|
377 |
view's font changes, for example. |
|
378 |
\row \i \l activate() |
|
379 |
\i Called whenever the user clicks on the item or presses |
|
380 |
Space when the item is the current item. |
|
381 |
\endtable |
|
382 |
||
383 |
Some subclasses call setExpandable(true) even when they have no |
|
384 |
children, and populate themselves when setup() or setOpen(true) is |
|
385 |
called. The \c dirview/dirview.cpp example program uses this |
|
386 |
technique to start up quickly: The files and subdirectories in a |
|
387 |
directory aren't inserted into the tree until they're actually |
|
388 |
needed. |
|
389 |
||
390 |
\img qlistviewitems.png List View Items |
|
391 |
||
392 |
\sa Q3CheckListItem Q3ListView |
|
393 |
*/ |
|
394 |
||
395 |
/*! |
|
396 |
\fn int Q3CheckListItem::rtti() const |
|
397 |
||
398 |
Returns 1. |
|
399 |
||
400 |
Make your derived classes return their own values for rtti(), and |
|
401 |
you can distinguish between list view items. You should use values |
|
402 |
greater than 1000, to allow for extensions to this class. |
|
403 |
*/ |
|
404 |
||
405 |
/*! |
|
406 |
Constructs a new top-level list view item in the Q3ListView \a |
|
407 |
parent. |
|
408 |
*/ |
|
409 |
||
410 |
Q3ListViewItem::Q3ListViewItem(Q3ListView * parent) |
|
411 |
{ |
|
412 |
init(); |
|
413 |
parent->insertItem(this); |
|
414 |
} |
|
415 |
||
416 |
||
417 |
/*! |
|
418 |
Constructs a new list view item that is a child of \a parent and |
|
419 |
first in the parent's list of children. |
|
420 |
*/ |
|
421 |
||
422 |
Q3ListViewItem::Q3ListViewItem(Q3ListViewItem * parent) |
|
423 |
{ |
|
424 |
init(); |
|
425 |
parent->insertItem(this); |
|
426 |
} |
|
427 |
||
428 |
||
429 |
||
430 |
||
431 |
/*! |
|
432 |
Constructs an empty list view item that is a child of \a parent |
|
433 |
and is after item \a after in the parent's list of children. Since |
|
434 |
\a parent is a Q3ListView the item will be a top-level item. |
|
435 |
*/ |
|
436 |
||
437 |
Q3ListViewItem::Q3ListViewItem(Q3ListView * parent, Q3ListViewItem * after) |
|
438 |
{ |
|
439 |
init(); |
|
440 |
parent->insertItem(this); |
|
441 |
moveToJustAfter(after); |
|
442 |
} |
|
443 |
||
444 |
||
445 |
/*! |
|
446 |
Constructs an empty list view item that is a child of \a parent |
|
447 |
and is after item \a after in the parent's list of children. |
|
448 |
*/ |
|
449 |
||
450 |
Q3ListViewItem::Q3ListViewItem(Q3ListViewItem * parent, Q3ListViewItem * after) |
|
451 |
{ |
|
452 |
init(); |
|
453 |
parent->insertItem(this); |
|
454 |
moveToJustAfter(after); |
|
455 |
} |
|
456 |
||
457 |
||
458 |
||
459 |
/*! |
|
460 |
Constructs a new top-level list view item in the Q3ListView \a |
|
461 |
parent, with up to eight constant strings, \a label1, \a label2, \a |
|
462 |
label3, \a label4, \a label5, \a label6, \a label7 and \a label8 |
|
463 |
defining its columns' contents. |
|
464 |
||
465 |
\sa setText() |
|
466 |
*/ |
|
467 |
||
468 |
Q3ListViewItem::Q3ListViewItem(Q3ListView * parent, |
|
469 |
const QString &label1, |
|
470 |
const QString &label2, |
|
471 |
const QString &label3, |
|
472 |
const QString &label4, |
|
473 |
const QString &label5, |
|
474 |
const QString &label6, |
|
475 |
const QString &label7, |
|
476 |
const QString &label8) |
|
477 |
{ |
|
478 |
init(); |
|
479 |
parent->insertItem(this); |
|
480 |
||
481 |
setText(0, label1); |
|
482 |
setText(1, label2); |
|
483 |
setText(2, label3); |
|
484 |
setText(3, label4); |
|
485 |
setText(4, label5); |
|
486 |
setText(5, label6); |
|
487 |
setText(6, label7); |
|
488 |
setText(7, label8); |
|
489 |
} |
|
490 |
||
491 |
||
492 |
/*! |
|
493 |
Constructs a new list view item as a child of the Q3ListViewItem \a |
|
494 |
parent with up to eight constant strings, \a label1, \a label2, \a |
|
495 |
label3, \a label4, \a label5, \a label6, \a label7 and \a label8 |
|
496 |
as columns' contents. |
|
497 |
||
498 |
\sa setText() |
|
499 |
*/ |
|
500 |
||
501 |
Q3ListViewItem::Q3ListViewItem(Q3ListViewItem * parent, |
|
502 |
const QString &label1, |
|
503 |
const QString &label2, |
|
504 |
const QString &label3, |
|
505 |
const QString &label4, |
|
506 |
const QString &label5, |
|
507 |
const QString &label6, |
|
508 |
const QString &label7, |
|
509 |
const QString &label8) |
|
510 |
{ |
|
511 |
init(); |
|
512 |
parent->insertItem(this); |
|
513 |
||
514 |
setText(0, label1); |
|
515 |
setText(1, label2); |
|
516 |
setText(2, label3); |
|
517 |
setText(3, label4); |
|
518 |
setText(4, label5); |
|
519 |
setText(5, label6); |
|
520 |
setText(6, label7); |
|
521 |
setText(7, label8); |
|
522 |
} |
|
523 |
||
524 |
/*! |
|
525 |
Constructs a new list view item in the Q3ListView \a parent that is |
|
526 |
included after item \a after and that has up to eight column |
|
527 |
texts, \a label1, \a label2, \a label3, \a label4, \a label5, \a |
|
528 |
label6, \a label7 and\a label8. |
|
529 |
||
530 |
Note that the order is changed according to Q3ListViewItem::key() |
|
531 |
unless the list view's sorting is disabled using |
|
532 |
Q3ListView::setSorting(-1). |
|
533 |
||
534 |
\sa setText() |
|
535 |
*/ |
|
536 |
||
537 |
Q3ListViewItem::Q3ListViewItem(Q3ListView * parent, Q3ListViewItem * after, |
|
538 |
const QString &label1, |
|
539 |
const QString &label2, |
|
540 |
const QString &label3, |
|
541 |
const QString &label4, |
|
542 |
const QString &label5, |
|
543 |
const QString &label6, |
|
544 |
const QString &label7, |
|
545 |
const QString &label8) |
|
546 |
{ |
|
547 |
init(); |
|
548 |
parent->insertItem(this); |
|
549 |
moveToJustAfter(after); |
|
550 |
||
551 |
setText(0, label1); |
|
552 |
setText(1, label2); |
|
553 |
setText(2, label3); |
|
554 |
setText(3, label4); |
|
555 |
setText(4, label5); |
|
556 |
setText(5, label6); |
|
557 |
setText(6, label7); |
|
558 |
setText(7, label8); |
|
559 |
} |
|
560 |
||
561 |
||
562 |
/*! |
|
563 |
Constructs a new list view item as a child of the Q3ListViewItem \a |
|
564 |
parent. It is inserted after item \a after and may contain up to |
|
565 |
eight strings, \a label1, \a label2, \a label3, \a label4, \a |
|
566 |
label5, \a label6, \a label7 and \a label8 as column entries. |
|
567 |
||
568 |
Note that the order is changed according to Q3ListViewItem::key() |
|
569 |
unless the list view's sorting is disabled using |
|
570 |
Q3ListView::setSorting(-1). |
|
571 |
||
572 |
\sa setText() |
|
573 |
*/ |
|
574 |
||
575 |
Q3ListViewItem::Q3ListViewItem(Q3ListViewItem * parent, Q3ListViewItem * after, |
|
576 |
const QString &label1, |
|
577 |
const QString &label2, |
|
578 |
const QString &label3, |
|
579 |
const QString &label4, |
|
580 |
const QString &label5, |
|
581 |
const QString &label6, |
|
582 |
const QString &label7, |
|
583 |
const QString &label8) |
|
584 |
{ |
|
585 |
init(); |
|
586 |
parent->insertItem(this); |
|
587 |
moveToJustAfter(after); |
|
588 |
||
589 |
setText(0, label1); |
|
590 |
setText(1, label2); |
|
591 |
setText(2, label3); |
|
592 |
setText(3, label4); |
|
593 |
setText(4, label5); |
|
594 |
setText(5, label6); |
|
595 |
setText(6, label7); |
|
596 |
setText(7, label8); |
|
597 |
} |
|
598 |
||
599 |
/*! |
|
600 |
Sorts all this item's child items using the current sorting |
|
601 |
configuration (sort column and direction). |
|
602 |
||
603 |
\sa enforceSortOrder() |
|
604 |
*/ |
|
605 |
||
606 |
void Q3ListViewItem::sort() |
|
607 |
{ |
|
608 |
if (!listView()) |
|
609 |
return; |
|
610 |
lsc = Unsorted; |
|
611 |
enforceSortOrder(); |
|
612 |
listView()->triggerUpdate(); |
|
613 |
} |
|
614 |
||
615 |
/*! |
|
616 |
Returns 0. |
|
617 |
||
618 |
Make your derived classes return their own values for rtti(), so |
|
619 |
that you can distinguish between different kinds of list view |
|
620 |
items. You should use values greater than 1000 to allow for |
|
621 |
extensions to this class. |
|
622 |
*/ |
|
623 |
||
624 |
int Q3ListViewItem::rtti() const |
|
625 |
{ |
|
626 |
return RTTI; |
|
627 |
} |
|
628 |
||
629 |
/* |
|
630 |
Performs the initializations that's common to the constructors. |
|
631 |
*/ |
|
632 |
||
633 |
void Q3ListViewItem::init() |
|
634 |
{ |
|
635 |
ownHeight = 0; |
|
636 |
maybeTotalHeight = -1; |
|
637 |
open = false; |
|
638 |
||
639 |
nChildren = 0; |
|
640 |
parentItem = 0; |
|
641 |
siblingItem = childItem = 0; |
|
642 |
||
643 |
columns = 0; |
|
644 |
||
645 |
selected = 0; |
|
646 |
selectable = true; |
|
647 |
||
648 |
lsc = Unsorted; |
|
649 |
lso = true; // unsorted in ascending order :) |
|
650 |
configured = false; |
|
651 |
expandable = false; |
|
652 |
selectable = true; |
|
653 |
is_root = false; |
|
654 |
allow_drag = false; |
|
655 |
allow_drop = false; |
|
656 |
visible = true; |
|
657 |
renameBox = 0; |
|
658 |
enabled = true; |
|
659 |
mlenabled = false; |
|
660 |
} |
|
661 |
||
662 |
/*! |
|
663 |
If \a b is true, the item is made visible; otherwise it is hidden. |
|
664 |
||
665 |
If the item is not visible, itemAbove() and itemBelow() will never |
|
666 |
return this item, although you still can reach it by using e.g. |
|
667 |
Q3ListViewItemIterator. |
|
668 |
*/ |
|
669 |
||
670 |
void Q3ListViewItem::setVisible(bool b) |
|
671 |
{ |
|
672 |
if (b == (bool)visible) |
|
673 |
return; |
|
674 |
Q3ListView *lv = listView(); |
|
675 |
if (!lv) |
|
676 |
return; |
|
677 |
if (b && parent() && !parent()->isVisible()) |
|
678 |
return; |
|
679 |
visible = b; |
|
680 |
configured = false; |
|
681 |
setHeight(0); |
|
682 |
invalidateHeight(); |
|
683 |
if (parent()) |
|
684 |
parent()->invalidateHeight(); |
|
685 |
else |
|
686 |
lv->d->r->invalidateHeight(); |
|
687 |
for (Q3ListViewItem *i = childItem; i; i = i->siblingItem) |
|
688 |
i->setVisible(b); |
|
689 |
if (lv) |
|
690 |
lv->triggerUpdate(); |
|
691 |
} |
|
692 |
||
693 |
/*! |
|
694 |
Returns true if the item is visible; otherwise returns false. |
|
695 |
||
696 |
\sa setVisible() |
|
697 |
*/ |
|
698 |
||
699 |
bool Q3ListViewItem::isVisible() const |
|
700 |
{ |
|
701 |
return (bool)visible; |
|
702 |
} |
|
703 |
||
704 |
/*! |
|
705 |
If \a b is true, this item can be in-place renamed in the column |
|
706 |
\a col by the user; otherwise it cannot be renamed in-place. |
|
707 |
*/ |
|
708 |
||
709 |
void Q3ListViewItem::setRenameEnabled(int col, bool b) |
|
710 |
{ |
|
711 |
Q3ListViewPrivate::ItemColumnInfo * l = (Q3ListViewPrivate::ItemColumnInfo*)columns; |
|
712 |
if (!l) { |
|
713 |
l = new Q3ListViewPrivate::ItemColumnInfo; |
|
714 |
columns = (void*)l; |
|
715 |
} |
|
716 |
for(int c = 0; c < col; c++) { |
|
717 |
if (!l->next) |
|
718 |
l->next = new Q3ListViewPrivate::ItemColumnInfo; |
|
719 |
l = l->next; |
|
720 |
} |
|
721 |
||
722 |
if (!l) |
|
723 |
return; |
|
724 |
l->allow_rename = b; |
|
725 |
} |
|
726 |
||
727 |
/*! |
|
728 |
Returns true if this item can be in-place renamed in column \a |
|
729 |
col; otherwise returns false. |
|
730 |
*/ |
|
731 |
||
732 |
bool Q3ListViewItem::renameEnabled(int col) const |
|
733 |
{ |
|
734 |
Q3ListViewPrivate::ItemColumnInfo * l = (Q3ListViewPrivate::ItemColumnInfo*)columns; |
|
735 |
if (!l) |
|
736 |
return false; |
|
737 |
||
738 |
while(col && l) { |
|
739 |
l = l->next; |
|
740 |
col--; |
|
741 |
} |
|
742 |
||
743 |
if (!l) |
|
744 |
return false; |
|
745 |
return (bool)l->allow_rename; |
|
746 |
} |
|
747 |
||
748 |
/*! |
|
749 |
If \a b is true the item is enabled; otherwise it is disabled. |
|
750 |
Disabled items are drawn differently (e.g. grayed-out) and are not |
|
751 |
accessible by the user. |
|
752 |
*/ |
|
753 |
||
754 |
void Q3ListViewItem::setEnabled(bool b) |
|
755 |
{ |
|
756 |
if ((bool)enabled == b) |
|
757 |
return; |
|
758 |
enabled = b; |
|
759 |
if (!enabled) |
|
760 |
selected = false; |
|
761 |
Q3ListView *lv = listView(); |
|
762 |
if (lv) { |
|
763 |
lv->triggerUpdate(); |
|
764 |
||
765 |
#ifndef QT_NO_ACCESSIBILITY |
|
766 |
QAccessible::updateAccessibility(lv->viewport(), indexOfItem(this), QAccessible::StateChanged); |
|
767 |
#endif |
|
768 |
} |
|
769 |
} |
|
770 |
||
771 |
/*! |
|
772 |
Returns true if this item is enabled; otherwise returns false. |
|
773 |
||
774 |
\sa setEnabled() |
|
775 |
*/ |
|
776 |
||
777 |
bool Q3ListViewItem::isEnabled() const |
|
778 |
{ |
|
779 |
return (bool)enabled; |
|
780 |
} |
|
781 |
||
782 |
/*! |
|
783 |
If in-place renaming of this item is enabled (see |
|
784 |
renameEnabled()), this function starts renaming the item in column |
|
785 |
\a col, by creating and initializing an edit box. |
|
786 |
*/ |
|
787 |
||
788 |
void Q3ListViewItem::startRename(int col) |
|
789 |
{ |
|
790 |
if (!renameEnabled(col)) |
|
791 |
return; |
|
792 |
if (renameBox) |
|
793 |
cancelRename(col); |
|
794 |
Q3ListView *lv = listView(); |
|
795 |
if (!lv) |
|
796 |
return; |
|
797 |
||
798 |
if (lv->d->renameTimer) |
|
799 |
lv->d->renameTimer->stop(); |
|
800 |
||
801 |
lv->ensureItemVisible(this); |
|
802 |
||
803 |
if (lv->d->timer->isActive()) { |
|
804 |
// make sure that pending calculations get finished |
|
805 |
lv->d->timer->stop(); |
|
806 |
lv->updateContents(); |
|
807 |
} |
|
808 |
||
809 |
if (lv->currentItem() && lv->currentItem()->renameBox) { |
|
810 |
if (lv->d->defRenameAction == Q3ListView::Reject) |
|
811 |
lv->currentItem()->cancelRename(lv->currentItem()->renameCol); |
|
812 |
else |
|
813 |
lv->currentItem()->okRename(lv->currentItem()->renameCol); |
|
814 |
} |
|
815 |
||
816 |
if (this != lv->currentItem()) |
|
817 |
lv->setCurrentItem(this); |
|
818 |
||
819 |
QRect r = lv->itemRect(this); |
|
820 |
r = QRect(lv->viewportToContents(r.topLeft()), r.size()); |
|
821 |
r.setLeft(lv->header()->sectionPos(col)); |
|
822 |
r.setWidth(qMin(lv->header()->sectionSize(col) - 1, |
|
823 |
lv->contentsX() + lv->visibleWidth() - r.left())); |
|
824 |
if (col == 0) |
|
825 |
r.setLeft(r.left() + lv->itemMargin() + (depth() + (lv->rootIsDecorated() ? 1 : 0)) * lv->treeStepSize() - 1); |
|
826 |
if (pixmap(col)) |
|
827 |
r.setLeft(r.left() + pixmap(col)->width()); |
|
828 |
if (r.x() - lv->contentsX() < 0) { |
|
829 |
lv->scrollBy(r.x() - lv->contentsX(), 0); |
|
830 |
r.setX(lv->contentsX()); |
|
831 |
} else if ((lv->contentsX() + lv->visibleWidth()) < (r.x() + r.width())) { |
|
832 |
lv->scrollBy((r.x() + r.width()) - (lv->contentsX() + lv->visibleWidth()), 0); |
|
833 |
} |
|
834 |
if (r.width() > lv->visibleWidth()) |
|
835 |
r.setWidth(lv->visibleWidth()); |
|
836 |
renameBox = new QLineEdit(lv->viewport(), "qt_renamebox"); |
|
837 |
renameBox->setFrame(false); |
|
838 |
renameBox->setText(text(col)); |
|
839 |
renameBox->selectAll(); |
|
840 |
renameBox->installEventFilter(lv); |
|
841 |
lv->addChild(renameBox, r.x(), r.y()); |
|
842 |
renameBox->resize(r.size()); |
|
843 |
lv->viewport()->setFocusProxy(renameBox); |
|
844 |
renameBox->setFocus(); |
|
845 |
renameBox->show(); |
|
846 |
renameCol = col; |
|
847 |
} |
|
848 |
||
849 |
/*! |
|
850 |
This function removes the rename box. |
|
851 |
*/ |
|
852 |
||
853 |
void Q3ListViewItem::removeRenameBox() |
|
854 |
{ |
|
855 |
// Sanity, it should be checked by the functions calling this first anyway |
|
856 |
Q3ListView *lv = listView(); |
|
857 |
if (!lv || !renameBox) |
|
858 |
return; |
|
859 |
const bool resetFocus = lv->viewport()->focusProxy() == renameBox; |
|
860 |
delete renameBox; |
|
861 |
renameBox = 0; |
|
862 |
if (resetFocus) { |
|
863 |
lv->viewport()->setFocusProxy(lv); |
|
864 |
lv->setFocus(); |
|
865 |
} |
|
866 |
} |
|
867 |
||
868 |
/*! |
|
869 |
This function is called if the user presses Enter during in-place |
|
870 |
renaming of the item in column \a col. |
|
871 |
||
872 |
\sa cancelRename() |
|
873 |
*/ |
|
874 |
||
875 |
void Q3ListViewItem::okRename(int col) |
|
876 |
{ |
|
877 |
Q3ListView *lv = listView(); |
|
878 |
if (!lv || !renameBox) |
|
879 |
return; |
|
880 |
setText(col, renameBox->text()); |
|
881 |
removeRenameBox(); |
|
882 |
||
883 |
// we set the parent lsc to Unsorted if that column is the sorted one |
|
884 |
if (parent() && (int)parent()->lsc == col) |
|
885 |
parent()->lsc = Unsorted; |
|
886 |
||
887 |
emit lv->itemRenamed(this, col); |
|
888 |
emit lv->itemRenamed(this, col, text(col)); |
|
889 |
} |
|
890 |
||
891 |
/*! |
|
892 |
This function is called if the user cancels in-place renaming of |
|
893 |
this item in column \a col (e.g. by pressing Esc). |
|
894 |
||
895 |
\sa okRename() |
|
896 |
*/ |
|
897 |
||
898 |
void Q3ListViewItem::cancelRename(int) |
|
899 |
{ |
|
900 |
Q3ListView *lv = listView(); |
|
901 |
if (!lv || !renameBox) |
|
902 |
return; |
|
903 |
removeRenameBox(); |
|
904 |
} |
|
905 |
||
906 |
/*! |
|
907 |
Destroys the item, deleting all its children and freeing up all |
|
908 |
allocated resources. |
|
909 |
*/ |
|
910 |
||
911 |
Q3ListViewItem::~Q3ListViewItem() |
|
912 |
{ |
|
913 |
if (renameBox) { |
|
914 |
delete renameBox; |
|
915 |
renameBox = 0; |
|
916 |
} |
|
917 |
||
918 |
Q3ListView *lv = listView(); |
|
919 |
||
920 |
if (lv) { |
|
921 |
if (lv->d->oldFocusItem == this) |
|
922 |
lv->d->oldFocusItem = 0; |
|
923 |
if (lv->d->focusItem == this) |
|
924 |
lv->d->focusItem = 0; |
|
925 |
if (lv->d->highlighted == this) |
|
926 |
lv->d->highlighted = 0; |
|
927 |
if (lv->d->pressedItem == this) |
|
928 |
lv->d->pressedItem = 0; |
|
929 |
if (lv->d->selectAnchor == this) |
|
930 |
lv->d->selectAnchor = 0; |
|
931 |
for (int j = 0; j < lv->d->iterators.size(); ++j) { |
|
932 |
Q3ListViewItemIterator *i = lv->d->iterators.at(j); |
|
933 |
if (i->current() == this) |
|
934 |
i->currentRemoved(); |
|
935 |
} |
|
936 |
} |
|
937 |
||
938 |
if (parentItem) |
|
939 |
parentItem->takeItem(this); |
|
940 |
Q3ListViewItem * i = childItem; |
|
941 |
childItem = 0; |
|
942 |
while (i) { |
|
943 |
i->parentItem = 0; |
|
944 |
Q3ListViewItem * n = i->siblingItem; |
|
945 |
delete i; |
|
946 |
i = n; |
|
947 |
} |
|
948 |
delete (Q3ListViewPrivate::ItemColumnInfo *)columns; |
|
949 |
} |
|
950 |
||
951 |
||
952 |
/*! |
|
953 |
If \a b is true each of the item's columns may contain multiple |
|
954 |
lines of text; otherwise each of them may only contain a single |
|
955 |
line. |
|
956 |
*/ |
|
957 |
||
958 |
void Q3ListViewItem::setMultiLinesEnabled(bool b) |
|
959 |
{ |
|
960 |
mlenabled = b; |
|
961 |
} |
|
962 |
||
963 |
/*! |
|
964 |
Returns true if the item can display multiple lines of text in its |
|
965 |
columns; otherwise returns false. |
|
966 |
*/ |
|
967 |
||
968 |
bool Q3ListViewItem::multiLinesEnabled() const |
|
969 |
{ |
|
970 |
return mlenabled; |
|
971 |
} |
|
972 |
||
973 |
/*! |
|
974 |
If \a allow is true, the list view starts a drag (see |
|
975 |
Q3ListView::dragObject()) when the user presses and moves the mouse |
|
976 |
on this item. |
|
977 |
*/ |
|
978 |
||
979 |
||
980 |
void Q3ListViewItem::setDragEnabled(bool allow) |
|
981 |
{ |
|
982 |
allow_drag = (uint)allow; |
|
983 |
} |
|
984 |
||
985 |
/*! |
|
986 |
If \a allow is true, the list view accepts drops onto the item; |
|
987 |
otherwise drops are not allowed. |
|
988 |
*/ |
|
989 |
||
990 |
void Q3ListViewItem::setDropEnabled(bool allow) |
|
991 |
{ |
|
992 |
allow_drop = (uint)allow; |
|
993 |
} |
|
994 |
||
995 |
/*! |
|
996 |
Returns true if this item can be dragged; otherwise returns false. |
|
997 |
||
998 |
\sa setDragEnabled() |
|
999 |
*/ |
|
1000 |
||
1001 |
bool Q3ListViewItem::dragEnabled() const |
|
1002 |
{ |
|
1003 |
return (bool)allow_drag; |
|
1004 |
} |
|
1005 |
||
1006 |
/*! |
|
1007 |
Returns true if this item accepts drops; otherwise returns false. |
|
1008 |
||
1009 |
\sa setDropEnabled(), acceptDrop() |
|
1010 |
*/ |
|
1011 |
||
1012 |
bool Q3ListViewItem::dropEnabled() const |
|
1013 |
{ |
|
1014 |
return (bool)allow_drop; |
|
1015 |
} |
|
1016 |
||
1017 |
/*! |
|
1018 |
Returns true if the item can accept drops of type QMimeSource \a |
|
1019 |
mime; otherwise returns false. |
|
1020 |
||
1021 |
The default implementation does nothing and returns false. A |
|
1022 |
subclass must reimplement this to accept drops. |
|
1023 |
*/ |
|
1024 |
||
1025 |
bool Q3ListViewItem::acceptDrop(const QMimeSource *) const |
|
1026 |
{ |
|
1027 |
return false; |
|
1028 |
} |
|
1029 |
||
1030 |
#ifndef QT_NO_DRAGANDDROP |
|
1031 |
||
1032 |
/*! |
|
1033 |
This function is called when something was dropped on the item. \a e |
|
1034 |
contains all the information about the drop. |
|
1035 |
||
1036 |
The default implementation does nothing, subclasses may need to |
|
1037 |
reimplement this function. |
|
1038 |
*/ |
|
1039 |
||
1040 |
void Q3ListViewItem::dropped(QDropEvent *e) |
|
1041 |
{ |
|
1042 |
Q_UNUSED(e); |
|
1043 |
} |
|
1044 |
||
1045 |
#endif |
|
1046 |
||
1047 |
/*! |
|
1048 |
This function is called when a drag enters the item's bounding |
|
1049 |
rectangle. |
|
1050 |
||
1051 |
The default implementation does nothing, subclasses may need to |
|
1052 |
reimplement this function. |
|
1053 |
*/ |
|
1054 |
||
1055 |
void Q3ListViewItem::dragEntered() |
|
1056 |
{ |
|
1057 |
} |
|
1058 |
||
1059 |
/*! |
|
1060 |
This function is called when a drag leaves the item's bounding |
|
1061 |
rectangle. |
|
1062 |
||
1063 |
The default implementation does nothing, subclasses may need to |
|
1064 |
reimplement this function. |
|
1065 |
*/ |
|
1066 |
||
1067 |
void Q3ListViewItem::dragLeft() |
|
1068 |
{ |
|
1069 |
} |
|
1070 |
||
1071 |
/*! |
|
1072 |
Inserts \a newChild into this list view item's list of children. |
|
1073 |
You should not need to call this function; it is called |
|
1074 |
automatically by the constructor of \a newChild. |
|
1075 |
||
1076 |
\warning If you are using \c Single selection mode, then you |
|
1077 |
should only insert unselected items. |
|
1078 |
*/ |
|
1079 |
||
1080 |
void Q3ListViewItem::insertItem(Q3ListViewItem * newChild) |
|
1081 |
{ |
|
1082 |
Q3ListView *lv = listView(); |
|
1083 |
if (lv && lv->currentItem() && lv->currentItem()->renameBox) { |
|
1084 |
if (lv->d->defRenameAction == Q3ListView::Reject) |
|
1085 |
lv->currentItem()->cancelRename(lv->currentItem()->renameCol); |
|
1086 |
else |
|
1087 |
lv->currentItem()->okRename(lv->currentItem()->renameCol); |
|
1088 |
} |
|
1089 |
||
1090 |
if (!newChild || newChild->parentItem == this) |
|
1091 |
return; |
|
1092 |
if (newChild->parentItem) |
|
1093 |
newChild->parentItem->takeItem(newChild); |
|
1094 |
if (open) |
|
1095 |
invalidateHeight(); |
|
1096 |
newChild->siblingItem = childItem; |
|
1097 |
childItem = newChild; |
|
1098 |
nChildren++; |
|
1099 |
newChild->parentItem = this; |
|
1100 |
lsc = Unsorted; |
|
1101 |
newChild->ownHeight = 0; |
|
1102 |
newChild->configured = false; |
|
1103 |
||
1104 |
if (lv && !lv->d->focusItem) { |
|
1105 |
lv->d->focusItem = lv->firstChild(); |
|
1106 |
lv->d->selectAnchor = lv->d->focusItem; |
|
1107 |
lv->repaintItem(lv->d->focusItem); |
|
1108 |
} |
|
1109 |
} |
|
1110 |
||
1111 |
||
1112 |
/*! |
|
1113 |
\fn void Q3ListViewItem::removeItem(Q3ListViewItem *item) |
|
1114 |
||
1115 |
Removes the given \a item. Use takeItem() instead. |
|
1116 |
*/ |
|
1117 |
||
1118 |
||
1119 |
/*! |
|
1120 |
Removes \a item from this object's list of children and causes an |
|
1121 |
update of the screen display. The item is not deleted. You should |
|
1122 |
not normally need to call this function because |
|
1123 |
Q3ListViewItem::~Q3ListViewItem() calls it. |
|
1124 |
||
1125 |
The normal way to delete an item is to use \c delete. |
|
1126 |
||
1127 |
If you need to move an item from one place in the hierarchy to |
|
1128 |
another you can use takeItem() to remove the item from the list |
|
1129 |
view and then insertItem() to put the item back in its new |
|
1130 |
position. |
|
1131 |
||
1132 |
If a taken item is part of a selection in \c Single selection |
|
1133 |
mode, it is unselected and selectionChanged() is emitted. If a |
|
1134 |
taken item is part of a selection in \c Multi or \c Extended |
|
1135 |
selection mode, it remains selected. |
|
1136 |
||
1137 |
\warning This function leaves \a item and its children in a state |
|
1138 |
where most member functions are unsafe. Only a few functions work |
|
1139 |
correctly on an item in this state, most notably insertItem(). The |
|
1140 |
functions that work on taken items are explicitly documented as |
|
1141 |
such. |
|
1142 |
||
1143 |
\sa Q3ListViewItem::insertItem() |
|
1144 |
*/ |
|
1145 |
||
1146 |
void Q3ListViewItem::takeItem(Q3ListViewItem * item) |
|
1147 |
{ |
|
1148 |
if (!item) |
|
1149 |
return; |
|
1150 |
||
1151 |
Q3ListView *lv = listView(); |
|
1152 |
if (lv && lv->currentItem() && lv->currentItem()->renameBox) { |
|
1153 |
if (lv->d->defRenameAction == Q3ListView::Reject) |
|
1154 |
lv->currentItem()->cancelRename(lv->currentItem()->renameCol); |
|
1155 |
else |
|
1156 |
lv->currentItem()->okRename(lv->currentItem()->renameCol); |
|
1157 |
} |
|
1158 |
bool emit_changed = false; |
|
1159 |
if (lv && !lv->d->clearing) { |
|
1160 |
if (lv->d->oldFocusItem == this) |
|
1161 |
lv->d->oldFocusItem = 0; |
|
1162 |
||
1163 |
for (int j = 0; j < lv->d->iterators.size(); ++j) { |
|
1164 |
Q3ListViewItemIterator *i = lv->d->iterators.at(j); |
|
1165 |
if (i->current() == item) |
|
1166 |
i->currentRemoved(); |
|
1167 |
} |
|
1168 |
||
1169 |
invalidateHeight(); |
|
1170 |
||
1171 |
if (lv->d && !lv->d->drawables.isEmpty()) |
|
1172 |
lv->d->drawables.clear(); |
|
1173 |
||
1174 |
if (!lv->d->dirtyItems.isEmpty()) { |
|
1175 |
if (item->childItem) { |
|
1176 |
lv->d->dirtyItems.clear(); |
|
1177 |
lv->d->dirtyItemTimer->stop(); |
|
1178 |
lv->triggerUpdate(); |
|
1179 |
} else { |
|
1180 |
lv->d->dirtyItems.removeAll(item); |
|
1181 |
} |
|
1182 |
} |
|
1183 |
||
1184 |
if (lv->d->focusItem) { |
|
1185 |
const Q3ListViewItem * c = lv->d->focusItem; |
|
1186 |
while(c && c != item) |
|
1187 |
c = c->parentItem; |
|
1188 |
if (c == item) { |
|
1189 |
if (lv->selectedItem()) { |
|
1190 |
// for Single, setSelected(false) when selectedItem() is taken |
|
1191 |
lv->selectedItem()->setSelected(false); |
|
1192 |
// we don't emit selectionChanged(0) |
|
1193 |
emit lv->selectionChanged(); |
|
1194 |
} |
|
1195 |
if (item->nextSibling()) |
|
1196 |
lv->d->focusItem = item->nextSibling(); |
|
1197 |
else if (item->itemAbove()) |
|
1198 |
lv->d->focusItem = item->itemAbove(); |
|
1199 |
else |
|
1200 |
lv->d->focusItem = 0; |
|
1201 |
emit_changed = true; |
|
1202 |
} |
|
1203 |
} |
|
1204 |
||
1205 |
// reset anchors etc. if they are set to this or any child |
|
1206 |
// items |
|
1207 |
const Q3ListViewItem *ptr = lv->d->selectAnchor; |
|
1208 |
while (ptr && ptr != item) |
|
1209 |
ptr = ptr->parentItem; |
|
1210 |
if (ptr == item) |
|
1211 |
lv->d->selectAnchor = lv->d->focusItem; |
|
1212 |
||
1213 |
ptr = lv->d->startDragItem; |
|
1214 |
while (ptr && ptr != item) |
|
1215 |
ptr = ptr->parentItem; |
|
1216 |
if (ptr == item) |
|
1217 |
lv->d->startDragItem = 0; |
|
1218 |
||
1219 |
ptr = lv->d->pressedItem; |
|
1220 |
while (ptr && ptr != item) |
|
1221 |
ptr = ptr->parentItem; |
|
1222 |
if (ptr == item) |
|
1223 |
lv->d->pressedItem = 0; |
|
1224 |
||
1225 |
ptr = lv->d->highlighted; |
|
1226 |
while (ptr && ptr != item) |
|
1227 |
ptr = ptr->parentItem; |
|
1228 |
if (ptr == item) |
|
1229 |
lv->d->highlighted = 0; |
|
1230 |
} |
|
1231 |
||
1232 |
nChildren--; |
|
1233 |
||
1234 |
Q3ListViewItem ** nextChild = &childItem; |
|
1235 |
while(nextChild && *nextChild && item != *nextChild) |
|
1236 |
nextChild = &((*nextChild)->siblingItem); |
|
1237 |
||
1238 |
if (nextChild && item == *nextChild) |
|
1239 |
*nextChild = (*nextChild)->siblingItem; |
|
1240 |
item->parentItem = 0; |
|
1241 |
item->siblingItem = 0; |
|
1242 |
item->ownHeight = 0; |
|
1243 |
item->maybeTotalHeight = -1; |
|
1244 |
item->configured = false; |
|
1245 |
||
1246 |
if (emit_changed) { |
|
1247 |
emit lv->currentChanged(lv->d->focusItem); |
|
1248 |
#ifndef QT_NO_ACCESSIBILITY |
|
1249 |
QAccessible::updateAccessibility(lv->viewport(), 0, QAccessible::Focus); |
|
1250 |
#endif |
|
1251 |
} |
|
1252 |
} |
|
1253 |
||
1254 |
||
1255 |
/*! |
|
1256 |
\fn QString Q3ListViewItem::key(int column, bool ascending) const |
|
1257 |
||
1258 |
Returns a key that can be used for sorting by column \a column. |
|
1259 |
The default implementation returns text(). Derived classes may |
|
1260 |
also incorporate the order indicated by \a ascending into this |
|
1261 |
key, although this is not recommended. |
|
1262 |
||
1263 |
If you want to sort on non-alphabetical data, e.g. dates, numbers, |
|
1264 |
etc., it is more efficient to reimplement compare(). |
|
1265 |
||
1266 |
\sa compare(), sortChildItems() |
|
1267 |
*/ |
|
1268 |
||
1269 |
QString Q3ListViewItem::key(int column, bool) const |
|
1270 |
{ |
|
1271 |
return text(column); |
|
1272 |
} |
|
1273 |
||
1274 |
||
1275 |
/*! |
|
1276 |
Compares this list view item to \a i using the column \a col in \a |
|
1277 |
ascending order. Returns \< 0 if this item is less than \a i, 0 if |
|
1278 |
they are equal and \> 0 if this item is greater than \a i. |
|
1279 |
||
1280 |
This function is used for sorting. |
|
1281 |
||
1282 |
The default implementation compares the item keys (key()) using |
|
1283 |
QString::localeAwareCompare(). A reimplementation can use |
|
1284 |
different values and a different comparison function. Here is a |
|
1285 |
reimplementation that uses plain Unicode comparison: |
|
1286 |
||
1287 |
\snippet doc/src/snippets/code/src_qt3support_itemviews_q3listview.cpp 3 |
|
1288 |
We don't recommend using \a ascending so your code can safely |
|
1289 |
ignore it. |
|
1290 |
||
1291 |
\sa key() QString::localeAwareCompare() QString::compare() |
|
1292 |
*/ |
|
1293 |
||
1294 |
int Q3ListViewItem::compare(Q3ListViewItem *i, int col, bool ascending) const |
|
1295 |
{ |
|
1296 |
return key(col, ascending).localeAwareCompare(i->key(col, ascending)); |
|
1297 |
} |
|
1298 |
||
1299 |
/*! |
|
1300 |
Sorts this item's children using column \a column. This is done in |
|
1301 |
ascending order if \a ascending is true and in descending order if |
|
1302 |
\a ascending is false. |
|
1303 |
||
1304 |
Asks some of the children to sort their children. (Q3ListView and |
|
1305 |
Q3ListViewItem ensure that all on-screen objects are properly |
|
1306 |
sorted but may avoid or defer sorting other objects in order to be |
|
1307 |
more responsive.) |
|
1308 |
||
1309 |
\sa key() compare() |
|
1310 |
*/ |
|
1311 |
||
1312 |
void Q3ListViewItem::sortChildItems(int column, bool ascending) |
|
1313 |
{ |
|
1314 |
// we try HARD not to sort. if we're already sorted, don't. |
|
1315 |
if (column == (int)lsc && ascending == (bool)lso) |
|
1316 |
return; |
|
1317 |
||
1318 |
if (column < 0) |
|
1319 |
return; |
|
1320 |
||
1321 |
lsc = column; |
|
1322 |
lso = ascending; |
|
1323 |
||
1324 |
const int nColumns = (listView() ? listView()->columns() : 0); |
|
1325 |
||
1326 |
// and don't sort if we already have the right sorting order |
|
1327 |
if (column > nColumns || childItem == 0 || childItem->siblingItem == 0) |
|
1328 |
return; |
|
1329 |
||
1330 |
// make an array for qHeapSort() |
|
1331 |
Q3ListViewPrivate::SortableItem * siblings |
|
1332 |
= new Q3ListViewPrivate::SortableItem[nChildren]; |
|
1333 |
Q3ListViewItem * s = childItem; |
|
1334 |
int i = 0; |
|
1335 |
while (s && i < nChildren) { |
|
1336 |
siblings[i].numCols = nColumns; |
|
1337 |
siblings[i].col = column; |
|
1338 |
siblings[i].asc = ascending; |
|
1339 |
siblings[i].item = s; |
|
1340 |
s = s->siblingItem; |
|
1341 |
i++; |
|
1342 |
} |
|
1343 |
||
1344 |
// and sort it. |
|
1345 |
qHeapSort(siblings, siblings + nChildren); |
|
1346 |
||
1347 |
// build the linked list of siblings, in the appropriate |
|
1348 |
// direction, and finally set this->childItem to the new top |
|
1349 |
// child. |
|
1350 |
if (ascending) { |
|
1351 |
for(i = 0; i < nChildren - 1; i++) |
|
1352 |
siblings[i].item->siblingItem = siblings[i+1].item; |
|
1353 |
siblings[nChildren-1].item->siblingItem = 0; |
|
1354 |
childItem = siblings[0].item; |
|
1355 |
} else { |
|
1356 |
for(i = nChildren - 1; i > 0; i--) |
|
1357 |
siblings[i].item->siblingItem = siblings[i-1].item; |
|
1358 |
siblings[0].item->siblingItem = 0; |
|
1359 |
childItem = siblings[nChildren-1].item; |
|
1360 |
} |
|
1361 |
for (i = 0; i < nChildren; i++) { |
|
1362 |
if (siblings[i].item->isOpen()) |
|
1363 |
siblings[i].item->sort(); |
|
1364 |
} |
|
1365 |
delete[] siblings; |
|
1366 |
} |
|
1367 |
||
1368 |
||
1369 |
/*! |
|
1370 |
Sets this item's height to \a height pixels. This implicitly |
|
1371 |
changes totalHeight(), too. |
|
1372 |
||
1373 |
Note that a font change causes this height to be overwritten |
|
1374 |
unless you reimplement setup(). |
|
1375 |
||
1376 |
For best results in Windows style we suggest using an even number |
|
1377 |
of pixels. |
|
1378 |
||
1379 |
\sa height() totalHeight() isOpen() |
|
1380 |
*/ |
|
1381 |
||
1382 |
void Q3ListViewItem::setHeight(int height) |
|
1383 |
{ |
|
1384 |
if (ownHeight != height) { |
|
1385 |
if (visible) |
|
1386 |
ownHeight = height; |
|
1387 |
else |
|
1388 |
ownHeight = 0; |
|
1389 |
invalidateHeight(); |
|
1390 |
} |
|
1391 |
} |
|
1392 |
||
1393 |
||
1394 |
/*! |
|
1395 |
Invalidates the cached total height of this item, including all |
|
1396 |
open children. |
|
1397 |
||
1398 |
\sa setHeight() height() totalHeight() |
|
1399 |
*/ |
|
1400 |
||
1401 |
void Q3ListViewItem::invalidateHeight() |
|
1402 |
{ |
|
1403 |
if (maybeTotalHeight < 0) |
|
1404 |
return; |
|
1405 |
maybeTotalHeight = -1; |
|
1406 |
if (parentItem && parentItem->isOpen()) |
|
1407 |
parentItem->invalidateHeight(); |
|
1408 |
} |
|
1409 |
||
1410 |
||
1411 |
/*! |
|
1412 |
Opens or closes an item, i.e. shows or hides an item's children. |
|
1413 |
||
1414 |
If \a o is true all child items are shown initially. The user can |
|
1415 |
hide them by clicking the \bold{-} icon to the left of the item. |
|
1416 |
If \a o is false, the children of this item are initially hidden. |
|
1417 |
The user can show them by clicking the \bold{+} icon to the left |
|
1418 |
of the item. |
|
1419 |
||
1420 |
\sa height() totalHeight() isOpen() |
|
1421 |
*/ |
|
1422 |
||
1423 |
void Q3ListViewItem::setOpen(bool o) |
|
1424 |
{ |
|
1425 |
if (o == (bool)open || !enabled) |
|
1426 |
return; |
|
1427 |
open = o; |
|
1428 |
||
1429 |
// If no children to show simply emit signals and return |
|
1430 |
if (!nChildren) { |
|
1431 |
Q3ListView *lv = listView(); |
|
1432 |
if (lv && this != lv->d->r) { |
|
1433 |
if (o) |
|
1434 |
emit lv->expanded(this); |
|
1435 |
else |
|
1436 |
emit lv->collapsed(this); |
|
1437 |
#ifndef QT_NO_ACCESSIBILITY |
|
1438 |
QAccessible::updateAccessibility(lv->viewport(), indexOfItem(this), QAccessible::StateChanged); |
|
1439 |
#endif |
|
1440 |
} |
|
1441 |
return; |
|
1442 |
} |
|
1443 |
invalidateHeight(); |
|
1444 |
||
1445 |
if (!configured) { |
|
1446 |
Q3ListViewItem * l = this; |
|
1447 |
QStack<Q3ListViewItem *> s; |
|
1448 |
while(l) { |
|
1449 |
if (l->open && l->childItem) { |
|
1450 |
s.push(l->childItem); |
|
1451 |
} else if (l->childItem) { |
|
1452 |
// first invisible child is unconfigured |
|
1453 |
Q3ListViewItem * c = l->childItem; |
|
1454 |
while(c) { |
|
1455 |
c->configured = false; |
|
1456 |
c = c->siblingItem; |
|
1457 |
} |
|
1458 |
} |
|
1459 |
l->configured = true; |
|
1460 |
l->setup(); |
|
1461 |
l = (l == this) ? 0 : l->siblingItem; |
|
1462 |
if (!l && !s.isEmpty()) |
|
1463 |
l = s.pop(); |
|
1464 |
} |
|
1465 |
} |
|
1466 |
||
1467 |
Q3ListView *lv = listView(); |
|
1468 |
||
1469 |
if (open && lv) |
|
1470 |
enforceSortOrder(); |
|
1471 |
||
1472 |
if (isVisible() && lv && lv->d && !lv->d->drawables.isEmpty()) |
|
1473 |
lv->buildDrawableList(); |
|
1474 |
||
1475 |
if (lv && this != lv->d->r) { |
|
1476 |
if (o) |
|
1477 |
emit lv->expanded(this); |
|
1478 |
else |
|
1479 |
emit lv->collapsed(this); |
|
1480 |
#ifndef QT_NO_ACCESSIBILITY |
|
1481 |
QAccessible::updateAccessibility(lv->viewport(), indexOfItem(this), QAccessible::StateChanged); |
|
1482 |
#endif |
|
1483 |
} |
|
1484 |
} |
|
1485 |
||
1486 |
||
1487 |
/*! |
|
1488 |
This virtual function is called before the first time Q3ListView |
|
1489 |
needs to know the height or any other graphical attribute of this |
|
1490 |
object, and whenever the font, GUI style, or colors of the list |
|
1491 |
view change. |
|
1492 |
||
1493 |
The default calls widthChanged() and sets the item's height to the |
|
1494 |
height of a single line of text in the list view's font. (If you |
|
1495 |
use icons, multi-line text, etc., you will probably need to call |
|
1496 |
setHeight() yourself or reimplement it.) |
|
1497 |
*/ |
|
1498 |
||
1499 |
void Q3ListViewItem::setup() |
|
1500 |
{ |
|
1501 |
widthChanged(); |
|
1502 |
Q3ListView *lv = listView(); |
|
1503 |
||
1504 |
int ph = 0; |
|
1505 |
int h = 0; |
|
1506 |
if (lv) { |
|
1507 |
for (int i = 0; i < lv->d->column.size(); ++i) { |
|
1508 |
if (pixmap(i)) |
|
1509 |
ph = qMax(ph, pixmap(i)->height()); |
|
1510 |
} |
|
1511 |
||
1512 |
if (mlenabled) { |
|
1513 |
h = ph; |
|
1514 |
for (int c = 0; c < lv->columns(); ++c) { |
|
1515 |
int lines = text(c).count(QLatin1Char('\n')) + 1; |
|
1516 |
int tmph = lv->d->fontMetricsHeight |
|
1517 |
+ lv->fontMetrics().lineSpacing() * (lines - 1); |
|
1518 |
h = qMax(h, tmph); |
|
1519 |
} |
|
1520 |
h += 2*lv->itemMargin(); |
|
1521 |
} else { |
|
1522 |
h = qMax(lv->d->fontMetricsHeight, ph) + 2*lv->itemMargin(); |
|
1523 |
} |
|
1524 |
} |
|
1525 |
||
1526 |
h = qMax(h, QApplication::globalStrut().height()); |
|
1527 |
||
1528 |
if (h % 2 > 0) |
|
1529 |
h++; |
|
1530 |
setHeight(h); |
|
1531 |
} |
|
1532 |
||
1533 |
||
1534 |
||
1535 |
||
1536 |
/*! |
|
1537 |
This virtual function is called whenever the user presses the mouse |
|
1538 |
on this item or presses Space on it. |
|
1539 |
||
1540 |
\sa activatedPos() |
|
1541 |
*/ |
|
1542 |
||
1543 |
void Q3ListViewItem::activate() |
|
1544 |
{ |
|
1545 |
} |
|
1546 |
||
1547 |
||
1548 |
/*! |
|
1549 |
When called from a reimplementation of activate(), this function |
|
1550 |
gives information on how the item was activated. Otherwise the |
|
1551 |
behavior is undefined. |
|
1552 |
||
1553 |
If activate() was caused by a mouse press, the function sets \a |
|
1554 |
pos to where the user clicked and returns true; otherwise it |
|
1555 |
returns false and does not change \a pos. |
|
1556 |
||
1557 |
\a pos is relative to the top-left corner of this item. |
|
1558 |
||
1559 |
\sa activate() |
|
1560 |
*/ |
|
1561 |
||
1562 |
bool Q3ListViewItem::activatedPos(QPoint &pos) |
|
1563 |
{ |
|
1564 |
if (activatedByClick) |
|
1565 |
pos = activatedP; |
|
1566 |
return activatedByClick; |
|
1567 |
} |
|
1568 |
||
1569 |
||
1570 |
/*! |
|
1571 |
\fn bool Q3ListViewItem::isSelectable() const |
|
1572 |
||
1573 |
Returns true if the item is selectable (as it is by default); |
|
1574 |
otherwise returns false |
|
1575 |
||
1576 |
\sa setSelectable() |
|
1577 |
*/ |
|
1578 |
||
1579 |
||
1580 |
/*! |
|
1581 |
Sets this items to be selectable if \a enable is true (the |
|
1582 |
default) or not to be selectable if \a enable is false. |
|
1583 |
||
1584 |
The user is not able to select a non-selectable item using either |
|
1585 |
the keyboard or the mouse. The application programmer still can |
|
1586 |
though, e.g. using setSelected(). |
|
1587 |
||
1588 |
\sa isSelectable() |
|
1589 |
*/ |
|
1590 |
||
1591 |
void Q3ListViewItem::setSelectable(bool enable) |
|
1592 |
{ |
|
1593 |
selectable = enable; |
|
1594 |
} |
|
1595 |
||
1596 |
||
1597 |
/*! |
|
1598 |
\fn bool Q3ListViewItem::isExpandable() const |
|
1599 |
||
1600 |
Returns true if this item is expandable even when it has no |
|
1601 |
children; otherwise returns false. |
|
1602 |
*/ |
|
1603 |
||
1604 |
/*! |
|
1605 |
Sets this item to be expandable even if it has no children if \a |
|
1606 |
enable is true, and to be expandable only if it has children if \a |
|
1607 |
enable is false (the default). |
|
1608 |
||
1609 |
The dirview example uses this in the canonical fashion. It checks |
|
1610 |
whether the directory is empty in setup() and calls |
|
1611 |
setExpandable(true) if not; in setOpen() it reads the contents of |
|
1612 |
the directory and inserts items accordingly. This strategy means |
|
1613 |
that dirview can display the entire file system without reading |
|
1614 |
very much at startup. |
|
1615 |
||
1616 |
Note that root items are not expandable by the user unless |
|
1617 |
Q3ListView::setRootIsDecorated() is set to true. |
|
1618 |
||
1619 |
\sa setSelectable() |
|
1620 |
*/ |
|
1621 |
||
1622 |
void Q3ListViewItem::setExpandable(bool enable) |
|
1623 |
{ |
|
1624 |
expandable = enable; |
|
1625 |
} |
|
1626 |
||
1627 |
||
1628 |
/*! |
|
1629 |
Makes sure that this object's children are sorted appropriately. |
|
1630 |
||
1631 |
This only works if every item from the root item down to this item |
|
1632 |
is already sorted. |
|
1633 |
||
1634 |
\sa sortChildItems() |
|
1635 |
*/ |
|
1636 |
||
1637 |
void Q3ListViewItem::enforceSortOrder() const |
|
1638 |
{ |
|
1639 |
Q3ListView *lv = listView(); |
|
1640 |
if (!lv || (lv && (lv->d->clearing || lv->d->sortcolumn == Unsorted))) |
|
1641 |
return; |
|
1642 |
if (parentItem && |
|
1643 |
(parentItem->lsc != lsc || parentItem->lso != lso)) |
|
1644 |
((Q3ListViewItem *)this)->sortChildItems((int)parentItem->lsc, |
|
1645 |
(bool)parentItem->lso); |
|
1646 |
else if (!parentItem && |
|
1647 |
((int)lsc != lv->d->sortcolumn || (bool)lso != lv->d->ascending)) |
|
1648 |
((Q3ListViewItem *)this)->sortChildItems(lv->d->sortcolumn, lv->d->ascending); |
|
1649 |
} |
|
1650 |
||
1651 |
||
1652 |
/*! |
|
1653 |
\fn bool Q3ListViewItem::isSelected() const |
|
1654 |
||
1655 |
Returns true if this item is selected; otherwise returns false. |
|
1656 |
||
1657 |
\sa setSelected() Q3ListView::setSelected() Q3ListView::selectionChanged() |
|
1658 |
*/ |
|
1659 |
||
1660 |
||
1661 |
/*! |
|
1662 |
If \a s is true this item is selected; otherwise it is deselected. |
|
1663 |
||
1664 |
This function does not maintain any invariants or repaint anything |
|
1665 |
-- Q3ListView::setSelected() does that. |
|
1666 |
||
1667 |
\sa height() totalHeight() |
|
1668 |
*/ |
|
1669 |
||
1670 |
void Q3ListViewItem::setSelected(bool s) |
|
1671 |
{ |
|
1672 |
bool old = selected; |
|
1673 |
||
1674 |
Q3ListView *lv = listView(); |
|
1675 |
if (lv && lv->selectionMode() != Q3ListView::NoSelection) { |
|
1676 |
if (s && isSelectable()) |
|
1677 |
selected = true; |
|
1678 |
else |
|
1679 |
selected = false; |
|
1680 |
||
1681 |
#ifndef QT_NO_ACCESSIBILITY |
|
1682 |
if (old != (bool)selected) { |
|
1683 |
int ind = indexOfItem(this); |
|
1684 |
QAccessible::updateAccessibility(lv->viewport(), ind, QAccessible::StateChanged); |
|
1685 |
QAccessible::updateAccessibility(lv->viewport(), ind, selected ? QAccessible::SelectionAdd : QAccessible::SelectionRemove); |
|
1686 |
} |
|
1687 |
#else |
|
1688 |
Q_UNUSED(old); |
|
1689 |
#endif |
|
1690 |
} |
|
1691 |
} |
|
1692 |
||
1693 |
/*! |
|
1694 |
Returns the total height of this object, including any visible |
|
1695 |
children. This height is recomputed lazily and cached for as long |
|
1696 |
as possible. |
|
1697 |
||
1698 |
Functions which can affect the total height are, setHeight() which |
|
1699 |
is used to set an item's height, setOpen() to show or hide an |
|
1700 |
item's children, and invalidateHeight() to invalidate the cached |
|
1701 |
height. |
|
1702 |
||
1703 |
\sa height() |
|
1704 |
*/ |
|
1705 |
||
1706 |
int Q3ListViewItem::totalHeight() const |
|
1707 |
{ |
|
1708 |
if (!visible) |
|
1709 |
return 0; |
|
1710 |
if (maybeTotalHeight >= 0) |
|
1711 |
return maybeTotalHeight; |
|
1712 |
Q3ListViewItem * that = (Q3ListViewItem *)this; |
|
1713 |
if (!that->configured) { |
|
1714 |
that->configured = true; |
|
1715 |
that->setup(); // ### virtual non-const function called in const |
|
1716 |
} |
|
1717 |
that->maybeTotalHeight = that->ownHeight; |
|
1718 |
||
1719 |
if (!that->isOpen() || !that->childCount()) |
|
1720 |
return that->ownHeight; |
|
1721 |
||
1722 |
Q3ListViewItem * child = that->childItem; |
|
1723 |
while (child != 0) { |
|
1724 |
that->maybeTotalHeight += child->totalHeight(); |
|
1725 |
child = child->siblingItem; |
|
1726 |
} |
|
1727 |
return that->maybeTotalHeight; |
|
1728 |
} |
|
1729 |
||
1730 |
||
1731 |
/*! |
|
1732 |
Returns the text in column \a column, or an empty string if there is |
|
1733 |
no text in that column. |
|
1734 |
||
1735 |
\sa key() paintCell() |
|
1736 |
*/ |
|
1737 |
||
1738 |
QString Q3ListViewItem::text(int column) const |
|
1739 |
{ |
|
1740 |
Q3ListViewPrivate::ItemColumnInfo * l |
|
1741 |
= (Q3ListViewPrivate::ItemColumnInfo*) columns; |
|
1742 |
||
1743 |
while(column && l) { |
|
1744 |
l = l->next; |
|
1745 |
column--; |
|
1746 |
} |
|
1747 |
||
1748 |
return l ? l->text : QString(); |
|
1749 |
} |
|
1750 |
||
1751 |
||
1752 |
/*! |
|
1753 |
Sets the text in column \a column to \a text, if \a column is a |
|
1754 |
valid column number and \a text is different from the existing |
|
1755 |
text. |
|
1756 |
||
1757 |
If the text() function has been reimplemented, this function may |
|
1758 |
be a no-op. |
|
1759 |
||
1760 |
\sa text() key() |
|
1761 |
*/ |
|
1762 |
||
1763 |
void Q3ListViewItem::setText(int column, const QString &text) |
|
1764 |
{ |
|
1765 |
if (column < 0) |
|
1766 |
return; |
|
1767 |
||
1768 |
Q3ListViewPrivate::ItemColumnInfo * l |
|
1769 |
= (Q3ListViewPrivate::ItemColumnInfo*) columns; |
|
1770 |
if (!l) { |
|
1771 |
l = new Q3ListViewPrivate::ItemColumnInfo; |
|
1772 |
columns = (void*)l; |
|
1773 |
} |
|
1774 |
for(int c = 0; c < column; c++) { |
|
1775 |
if (!l->next) |
|
1776 |
l->next = new Q3ListViewPrivate::ItemColumnInfo; |
|
1777 |
l = l->next; |
|
1778 |
} |
|
1779 |
if (l->text == text) |
|
1780 |
return; |
|
1781 |
||
1782 |
int oldLc = 0; |
|
1783 |
int newLc = 0; |
|
1784 |
if (mlenabled) { |
|
1785 |
if (!l->text.isEmpty()) |
|
1786 |
oldLc = l->text.count(QLatin1Char('\n')) + 1; |
|
1787 |
if (!text.isEmpty()) |
|
1788 |
newLc = text.count(QLatin1Char('\n')) + 1; |
|
1789 |
} |
|
1790 |
||
1791 |
l->dirty = true; |
|
1792 |
l->text = text; |
|
1793 |
if (column == (int)lsc) |
|
1794 |
lsc = Unsorted; |
|
1795 |
||
1796 |
if (mlenabled && oldLc != newLc) |
|
1797 |
setup(); |
|
1798 |
else |
|
1799 |
widthChanged(column); |
|
1800 |
||
1801 |
Q3ListView * lv = listView(); |
|
1802 |
if (lv) { |
|
1803 |
lv->triggerUpdate(); |
|
1804 |
#ifndef QT_NO_ACCESSIBILITY |
|
1805 |
if (lv->isVisible()) |
|
1806 |
QAccessible::updateAccessibility(lv->viewport(), indexOfItem(this), QAccessible::NameChanged); |
|
1807 |
#endif |
|
1808 |
} |
|
1809 |
} |
|
1810 |
||
1811 |
||
1812 |
/*! |
|
1813 |
Sets the pixmap in column \a column to \a pm, if \a pm is non-null |
|
1814 |
and different from the current pixmap, and if \a column is |
|
1815 |
non-negative. |
|
1816 |
||
1817 |
\sa pixmap() setText() |
|
1818 |
*/ |
|
1819 |
||
1820 |
void Q3ListViewItem::setPixmap(int column, const QPixmap & pm) |
|
1821 |
{ |
|
1822 |
if (column < 0) |
|
1823 |
return; |
|
1824 |
||
1825 |
int oldW = 0; |
|
1826 |
int oldH = 0; |
|
1827 |
if (pixmap(column)) { |
|
1828 |
oldW = pixmap(column)->width(); |
|
1829 |
oldH = pixmap(column)->height(); |
|
1830 |
} |
|
1831 |
||
1832 |
Q3ListViewPrivate::ItemColumnInfo * l |
|
1833 |
= (Q3ListViewPrivate::ItemColumnInfo*) columns; |
|
1834 |
if (!l) { |
|
1835 |
l = new Q3ListViewPrivate::ItemColumnInfo; |
|
1836 |
columns = (void*)l; |
|
1837 |
} |
|
1838 |
||
1839 |
for(int c = 0; c < column; c++) { |
|
1840 |
if (!l->next) |
|
1841 |
l->next = new Q3ListViewPrivate::ItemColumnInfo; |
|
1842 |
l = l->next; |
|
1843 |
} |
|
1844 |
||
1845 |
if ((pm.isNull() && (!l->pm || l->pm->isNull())) || |
|
1846 |
(l->pm && pm.serialNumber() == l->pm->serialNumber())) |
|
1847 |
return; |
|
1848 |
||
1849 |
if (pm.isNull()) { |
|
1850 |
delete l->pm; |
|
1851 |
l->pm = 0; |
|
1852 |
} else { |
|
1853 |
if (l->pm) |
|
1854 |
*(l->pm) = pm; |
|
1855 |
else |
|
1856 |
l->pm = new QPixmap(pm); |
|
1857 |
} |
|
1858 |
||
1859 |
int newW = 0; |
|
1860 |
int newH = 0; |
|
1861 |
if (pixmap(column)) { |
|
1862 |
newW = pixmap(column)->width(); |
|
1863 |
newH = pixmap(column)->height(); |
|
1864 |
} |
|
1865 |
||
1866 |
if (oldW != newW || oldH != newH) { |
|
1867 |
setup(); |
|
1868 |
widthChanged(column); |
|
1869 |
invalidateHeight(); |
|
1870 |
} |
|
1871 |
Q3ListView *lv = listView(); |
|
1872 |
if (lv) { |
|
1873 |
lv->triggerUpdate(); |
|
1874 |
} |
|
1875 |
} |
|
1876 |
||
1877 |
||
1878 |
/*! |
|
1879 |
Returns the pixmap for \a column, or 0 if there is no pixmap for |
|
1880 |
\a column. |
|
1881 |
||
1882 |
\sa setText() setPixmap() |
|
1883 |
*/ |
|
1884 |
||
1885 |
const QPixmap * Q3ListViewItem::pixmap(int column) const |
|
1886 |
{ |
|
1887 |
Q3ListViewPrivate::ItemColumnInfo * l |
|
1888 |
= (Q3ListViewPrivate::ItemColumnInfo*) columns; |
|
1889 |
||
1890 |
while(column && l) { |
|
1891 |
l = l->next; |
|
1892 |
column--; |
|
1893 |
} |
|
1894 |
||
1895 |
return (l && l->pm) ? l->pm : 0; |
|
1896 |
} |
|
1897 |
||
1898 |
||
1899 |
/* |
|
1900 |
This function paints the contents of one column of an item |
|
1901 |
and aligns it as described by \a align. |
|
1902 |
||
1903 |
\a p is a QPainter open on the relevant paint device. \a p is |
|
1904 |
translated so (0, 0) is the top-left pixel in the cell and \a |
|
1905 |
width-1, height()-1 is the bottom-right pixel \e in the cell. The |
|
1906 |
other properties of \a p (pen, brush, etc) are undefined. \a pal is |
|
1907 |
the color group to use. \a column is the logical column number |
|
1908 |
within the item that is to be painted; 0 is the column which may |
|
1909 |
contain a tree. |
|
1910 |
||
1911 |
This function may use Q3ListView::itemMargin() for readability |
|
1912 |
spacing on the left and right sides of data such as text, and |
|
1913 |
should honor isSelected() and Q3ListView::allColumnsShowFocus(). |
|
1914 |
||
1915 |
If you reimplement this function, you should also reimplement |
|
1916 |
width(). |
|
1917 |
||
1918 |
The rectangle to be painted is in an undefined state when this |
|
1919 |
function is called, so you \e must draw on all the pixels. The |
|
1920 |
painter \a p has the right font on entry. |
|
1921 |
||
1922 |
\sa paintBranches(), Q3ListView::drawContentsOffset() |
|
1923 |
*/ |
|
1924 |
||
1925 |
static QStyleOptionQ3ListView getStyleOption(const Q3ListView *lv, const Q3ListViewItem *item, |
|
1926 |
bool hierarchy = false) |
|
1927 |
{ |
|
1928 |
QStyleOptionQ3ListView opt; |
|
1929 |
opt.init(lv); |
|
1930 |
opt.subControls = QStyle::SC_None; |
|
1931 |
opt.activeSubControls = QStyle::SC_None; |
|
1932 |
QWidget *vp = lv->viewport(); |
|
1933 |
opt.viewportPalette = vp->palette(); |
|
1934 |
opt.viewportBGRole = vp->backgroundRole(); |
|
1935 |
opt.itemMargin = lv->itemMargin(); |
|
1936 |
opt.sortColumn = 0; |
|
1937 |
opt.treeStepSize = lv->treeStepSize(); |
|
1938 |
opt.rootIsDecorated = lv->rootIsDecorated(); |
|
1939 |
bool firstItem = true; |
|
1940 |
int y = item ? item->itemPos() : 0; |
|
1941 |
while (item) { |
|
1942 |
QStyleOptionQ3ListViewItem lvi; |
|
1943 |
lvi.height = item->height(); |
|
1944 |
lvi.totalHeight = item->totalHeight(); |
|
1945 |
lvi.itemY = y; |
|
1946 |
lvi.childCount = item->childCount(); |
|
1947 |
lvi.features = QStyleOptionQ3ListViewItem::None; |
|
1948 |
lvi.state = QStyle::State_None; |
|
1949 |
if (item->isEnabled()) |
|
1950 |
lvi.state |= QStyle::State_Enabled; |
|
1951 |
if (item->isOpen()) |
|
1952 |
lvi.state |= QStyle::State_Open; |
|
1953 |
if (item->isExpandable()) |
|
1954 |
lvi.features |= QStyleOptionQ3ListViewItem::Expandable; |
|
1955 |
if (item->multiLinesEnabled()) |
|
1956 |
lvi.features |= QStyleOptionQ3ListViewItem::MultiLine; |
|
1957 |
if (item->isVisible()) |
|
1958 |
lvi.features |= QStyleOptionQ3ListViewItem::Visible; |
|
1959 |
if (item->parent() && item->parent()->rtti() == 1 |
|
1960 |
&& static_cast<Q3CheckListItem *>(item->parent())->type() == Q3CheckListItem::Controller) |
|
1961 |
lvi.features |= QStyleOptionQ3ListViewItem::ParentControl; |
|
1962 |
opt.items.append(lvi); |
|
1963 |
// we only care about the children when we are painting the branches |
|
1964 |
// this is only enabled by Q3ListViewItem::paintBranches |
|
1965 |
if (hierarchy) { |
|
1966 |
if (!firstItem) { |
|
1967 |
item = item->nextSibling(); |
|
1968 |
} else { |
|
1969 |
firstItem = false; |
|
1970 |
item = item->firstChild(); |
|
1971 |
} |
|
1972 |
y += lvi.height; |
|
1973 |
} else { |
|
1974 |
break; |
|
1975 |
} |
|
1976 |
} |
|
1977 |
return opt; |
|
1978 |
} |
|
1979 |
||
1980 |
/*! |
|
1981 |
\fn void Q3ListViewItem::paintCell(QPainter *painter, const QColorGroup & cg, int column, int width, int align) |
|
1982 |
||
1983 |
This virtual function paints the contents of one column of an item |
|
1984 |
and aligns it as described by \a align. |
|
1985 |
||
1986 |
The \a painter is a Q3Painter open on the relevant paint |
|
1987 |
device. It is translated so (0, 0) is the top-left pixel in the |
|
1988 |
cell and \a width - 1, height() - 1 is the bottom-right pixel \e |
|
1989 |
in the cell. The other properties of the \a painter (pen, brush, etc) are |
|
1990 |
undefined. \a cg is the color group to use. \a column is the |
|
1991 |
logical column number within the item that is to be painted; 0 is |
|
1992 |
the column which may contain a tree. |
|
1993 |
||
1994 |
This function may use Q3ListView::itemMargin() for readability |
|
1995 |
spacing on the left and right sides of data such as text, and |
|
1996 |
should honor \l isSelected() and |
|
1997 |
Q3ListView::allColumnsShowFocus(). |
|
1998 |
||
1999 |
If you reimplement this function, you should also reimplement \l |
|
2000 |
width(). |
|
2001 |
||
2002 |
The rectangle to be painted is in an undefined state when this |
|
2003 |
function is called, so you \e must draw on all the pixels. The |
|
2004 |
\a painter has the right font on entry. |
|
2005 |
||
2006 |
\sa paintBranches(), Q3ListView::drawContentsOffset() |
|
2007 |
*/ |
|
2008 |
void Q3ListViewItem::paintCell(QPainter * p, const QColorGroup & cg, |
|
2009 |
int column, int width, int align) |
|
2010 |
{ |
|
2011 |
// Change width() if you change this. |
|
2012 |
||
2013 |
QPalette pal = cg; |
|
2014 |
if (!p) |
|
2015 |
return; |
|
2016 |
||
2017 |
Q3ListView *lv = listView(); |
|
2018 |
if (!lv) |
|
2019 |
return; |
|
2020 |
QFontMetrics fm(p->fontMetrics()); |
|
2021 |
||
2022 |
// had, but we _need_ the column info for the ellipsis thingy!!! |
|
2023 |
if (!columns) { |
|
2024 |
for (int i = 0; i < lv->d->column.size(); ++i) { |
|
2025 |
setText(i, text(i)); |
|
2026 |
} |
|
2027 |
} |
|
2028 |
||
2029 |
QString t = text(column); |
|
2030 |
||
2031 |
if (columns) { |
|
2032 |
Q3ListViewPrivate::ItemColumnInfo *ci = 0; |
|
2033 |
// try until we have a column info.... |
|
2034 |
while (!ci) { |
|
2035 |
ci = (Q3ListViewPrivate::ItemColumnInfo*)columns; |
|
2036 |
for (int i = 0; ci && (i < column); ++i) |
|
2037 |
ci = ci->next; |
|
2038 |
||
2039 |
if (!ci) { |
|
2040 |
setText(column, t); |
|
2041 |
ci = 0; |
|
2042 |
} |
|
2043 |
} |
|
2044 |
||
2045 |
// if the column width changed and this item was not painted since this change |
|
2046 |
if (ci && (ci->width != width || ci->text != t || ci->dirty)) { |
|
2047 |
ci->text = t; |
|
2048 |
ci->dirty = false; |
|
2049 |
ci->width = width; |
|
2050 |
ci->truncated = false; |
|
2051 |
// if we have to do the ellipsis thingy calc the truncated text |
|
2052 |
int pw = lv->itemMargin()*2 - lv->d->minLeftBearing - lv->d->minRightBearing; |
|
2053 |
pw += pixmap(column) ? pixmap(column)->width() + lv->itemMargin() : 0; |
|
2054 |
if (!mlenabled && fm.width(t) + pw > width) { |
|
2055 |
// take care of arabic shaping in width calculation (lars) |
|
2056 |
ci->truncated = true; |
|
2057 |
ci->tmpText = qEllipsisText(t, fm, width - pw, align); |
|
2058 |
} else if (mlenabled && fm.width(t) + pw > width) { |
|
2059 |
QStringList list = t.split(QLatin1Char('\n')); |
|
2060 |
for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) { |
|
2061 |
QString z = *it; |
|
2062 |
if (fm.width(z) + pw > width) { |
|
2063 |
ci->truncated = true; |
|
2064 |
*it = qEllipsisText(z, fm, width - pw, align); |
|
2065 |
} |
|
2066 |
} |
|
2067 |
||
2068 |
if (ci->truncated) |
|
2069 |
ci->tmpText = list.join(QString(QLatin1Char('\n'))); |
|
2070 |
} |
|
2071 |
} |
|
2072 |
||
2073 |
// if we have to draw the ellipsis thingy, use the truncated text |
|
2074 |
if (ci && ci->truncated) |
|
2075 |
t = ci->tmpText; |
|
2076 |
} |
|
2077 |
||
2078 |
int marg = lv->itemMargin(); |
|
2079 |
int r = marg; |
|
2080 |
const QPixmap * icon = pixmap(column); |
|
2081 |
||
2082 |
const QPalette::ColorRole crole = lv->viewport()->backgroundRole(); |
|
2083 |
if (pal.brush(crole) != lv->palette().brush(pal.currentColorGroup(), crole)) |
|
2084 |
p->fillRect(0, 0, width, height(), pal.brush(crole)); |
|
2085 |
else |
|
2086 |
lv->paintEmptyArea(p, QRect(0, 0, width, height())); |
|
2087 |
||
2088 |
// (lars) what does this do??? |
|
2089 |
#if 0 // RS: #### |
|
2090 |
if (align != Qt::AlignLeft) |
|
2091 |
marg -= lv->d->minRightBearing; |
|
2092 |
#endif |
|
2093 |
if (isSelected() && |
|
2094 |
(column == 0 || lv->allColumnsShowFocus())) { |
|
2095 |
p->fillRect(r - marg, 0, qMax(0, width - r + marg), height(), |
|
2096 |
pal.brush(QPalette::Highlight)); |
|
2097 |
if (enabled || !lv) |
|
2098 |
p->setPen(pal.highlightedText().color()); |
|
2099 |
else if (!enabled && lv) |
|
2100 |
p->setPen(lv->palette().color(QPalette::Disabled, QPalette::HighlightedText)); |
|
2101 |
} else { |
|
2102 |
if (enabled || !lv) |
|
2103 |
p->setPen(pal.text().color()); |
|
2104 |
else if (!enabled && lv) |
|
2105 |
p->setPen(lv->palette().color(QPalette::Disabled, QPalette::Text)); |
|
2106 |
} |
|
2107 |
||
2108 |
||
2109 |
#if 0 |
|
2110 |
bool reverse = QApplication::reverseLayout(); |
|
2111 |
#else |
|
2112 |
bool reverse = false; |
|
2113 |
#endif |
|
2114 |
int iconWidth = 0; |
|
2115 |
||
2116 |
if (icon) { |
|
2117 |
iconWidth = icon->width() + lv->itemMargin(); |
|
2118 |
int xo = r; |
|
2119 |
// we default to Qt::AlignVCenter. |
|
2120 |
int yo = (height() - icon->height()) / 2; |
|
2121 |
||
2122 |
// I guess we may as well always respect vertical alignment. |
|
2123 |
if (align & Qt::AlignBottom) |
|
2124 |
yo = height() - icon->height(); |
|
2125 |
else if (align & Qt::AlignTop) |
|
2126 |
yo = 0; |
|
2127 |
||
2128 |
// respect horizontal alignment when there is no text for an item. |
|
2129 |
if (text(column).isEmpty()) { |
|
2130 |
if (align & Qt::AlignRight) |
|
2131 |
xo = width - 2 * marg - iconWidth; |
|
2132 |
else if (align & Qt::AlignHCenter) |
|
2133 |
xo = (width - iconWidth) / 2; |
|
2134 |
} |
|
2135 |
if (reverse) |
|
2136 |
xo = width - 2 * marg - iconWidth; |
|
2137 |
p->drawPixmap(xo, yo, *icon); |
|
2138 |
} |
|
2139 |
||
2140 |
if (!t.isEmpty()) { |
|
2141 |
if (!mlenabled) { |
|
2142 |
if (!(align & Qt::AlignTop || align & Qt::AlignBottom)) |
|
2143 |
align |= Qt::AlignVCenter; |
|
2144 |
} else { |
|
2145 |
if (!(align & Qt::AlignVCenter || align & Qt::AlignBottom)) |
|
2146 |
align |= Qt::AlignTop; |
|
2147 |
} |
|
2148 |
if (!reverse) |
|
2149 |
r += iconWidth; |
|
2150 |
||
2151 |
if (!mlenabled) { |
|
2152 |
p->drawText(r, 0, width-marg-r, height(), align, t); |
|
2153 |
} else { |
|
2154 |
p->drawText(r, marg, width-marg-r, height(), align, t); |
|
2155 |
} |
|
2156 |
} |
|
2157 |
||
2158 |
if (mlenabled && column == 0 && isOpen() && childCount()) { |
|
2159 |
int textheight = fm.size(align, t).height() + 2 * lv->itemMargin(); |
|
2160 |
textheight = qMax(textheight, QApplication::globalStrut().height()); |
|
2161 |
if (textheight % 2 > 0) |
|
2162 |
textheight++; |
|
2163 |
if (textheight < height()) { |
|
2164 |
int w = lv->treeStepSize() / 2; |
|
2165 |
QStyleOptionQ3ListView opt = getStyleOption(lv, this); |
|
2166 |
opt.rect.setRect(0, textheight, w + 1, height() - textheight + 1); |
|
2167 |
opt.palette = pal; |
|
2168 |
opt.subControls = QStyle::SC_Q3ListViewExpand; |
|
2169 |
opt.activeSubControls = QStyle::SC_All; |
|
2170 |
lv->style()->drawComplexControl(QStyle::CC_Q3ListView, &opt, p, lv); |
|
2171 |
} |
|
2172 |
} |
|
2173 |
} |
|
2174 |
||
2175 |
/*! |
|
2176 |
Returns the number of pixels of width required to draw column \a c |
|
2177 |
of list view \a lv, using the metrics \a fm without cropping. The |
|
2178 |
list view containing this item may use this information depending |
|
2179 |
on the Q3ListView::WidthMode settings for the column. |
|
2180 |
||
2181 |
The default implementation returns the width of the bounding |
|
2182 |
rectangle of the text of column \a c. |
|
2183 |
||
2184 |
\sa listView() widthChanged() Q3ListView::setColumnWidthMode() |
|
2185 |
Q3ListView::itemMargin() |
|
2186 |
*/ |
|
2187 |
int Q3ListViewItem::width(const QFontMetrics& fm, |
|
2188 |
const Q3ListView* lv, int c) const |
|
2189 |
{ |
|
2190 |
int w; |
|
2191 |
if (mlenabled) |
|
2192 |
w = fm.size(Qt::AlignVCenter, text(c)).width() + lv->itemMargin() * 2 |
|
2193 |
- lv->d->minLeftBearing - lv->d->minRightBearing; |
|
2194 |
else |
|
2195 |
w = fm.width(text(c)) + lv->itemMargin() * 2 |
|
2196 |
- lv->d->minLeftBearing - lv->d->minRightBearing; |
|
2197 |
const QPixmap * pm = pixmap(c); |
|
2198 |
if (pm) |
|
2199 |
w += pm->width() + lv->itemMargin(); // ### correct margin stuff? |
|
2200 |
return qMax(w, QApplication::globalStrut().width()); |
|
2201 |
} |
|
2202 |
||
2203 |
||
2204 |
/*! |
|
2205 |
Paints a focus indicator on the rectangle \a r using painter \a p |
|
2206 |
and colors \a cg. |
|
2207 |
||
2208 |
\a p is already clipped. |
|
2209 |
||
2210 |
\sa paintCell() paintBranches() Q3ListView::setAllColumnsShowFocus() |
|
2211 |
*/ |
|
2212 |
||
2213 |
void Q3ListViewItem::paintFocus(QPainter *p, const QColorGroup &cg, const QRect &r) |
|
2214 |
{ |
|
2215 |
QPalette pal = cg; |
|
2216 |
Q3ListView *lv = listView(); |
|
2217 |
if (lv) { |
|
2218 |
QStyleOptionFocusRect opt; |
|
2219 |
opt.init(lv); |
|
2220 |
opt.rect = r; |
|
2221 |
opt.palette = pal; |
|
2222 |
opt.state |= QStyle::State_KeyboardFocusChange; |
|
2223 |
if (isSelected()) { |
|
2224 |
opt.state |= QStyle::State_FocusAtBorder; |
|
2225 |
opt.backgroundColor = pal.highlight().color(); |
|
2226 |
} else { |
|
2227 |
opt.state |= QStyle::State_None; |
|
2228 |
opt.backgroundColor = pal.base().color(); |
|
2229 |
} |
|
2230 |
lv->style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, p, lv); |
|
2231 |
} |
|
2232 |
} |
|
2233 |
||
2234 |
||
2235 |
/*! |
|
2236 |
Paints a set of branches from this item to (some of) its children. |
|
2237 |
||
2238 |
Painter \a p is set up with clipping and translation so that you |
|
2239 |
can only draw in the rectangle that needs redrawing; \a cg is the |
|
2240 |
color group to use; the update rectangle is at (0, 0) and has size |
|
2241 |
width \a w by height \a h. The top of the rectangle you own is at |
|
2242 |
\a y (which is never greater than 0 but can be outside the window |
|
2243 |
system's allowed coordinate range). |
|
2244 |
||
2245 |
The update rectangle is in an undefined state when this function |
|
2246 |
is called; this function must draw on \e all of the pixels. |
|
2247 |
||
2248 |
\sa paintCell(), Q3ListView::drawContentsOffset() |
|
2249 |
*/ |
|
2250 |
||
2251 |
void Q3ListViewItem::paintBranches(QPainter * p, const QColorGroup & cg, |
|
2252 |
int w, int y, int h) |
|
2253 |
{ |
|
2254 |
Q3ListView *lv = listView(); |
|
2255 |
if (lv) |
|
2256 |
lv->paintEmptyArea(p, QRect(0, 0, w, h)); |
|
2257 |
if (!visible || !lv) |
|
2258 |
return; |
|
2259 |
QStyleOptionQ3ListView opt = getStyleOption(lv, this, true); |
|
2260 |
opt.rect.setRect(0, y, w, h); |
|
2261 |
opt.palette = cg; |
|
2262 |
opt.subControls = QStyle::SC_Q3ListViewBranch | QStyle::SC_Q3ListViewExpand; |
|
2263 |
opt.activeSubControls = QStyle::SC_None; |
|
2264 |
lv->style()->drawComplexControl(QStyle::CC_Q3ListView, &opt, p, lv); |
|
2265 |
} |
|
2266 |
||
2267 |
||
2268 |
Q3ListViewPrivate::Root::Root(Q3ListView * parent) |
|
2269 |
: Q3ListViewItem(parent) |
|
2270 |
{ |
|
2271 |
lv = parent; |
|
2272 |
setHeight(0); |
|
2273 |
setOpen(true); |
|
2274 |
} |
|
2275 |
||
2276 |
||
2277 |
void Q3ListViewPrivate::Root::setHeight(int) |
|
2278 |
{ |
|
2279 |
Q3ListViewItem::setHeight(0); |
|
2280 |
} |
|
2281 |
||
2282 |
||
2283 |
void Q3ListViewPrivate::Root::invalidateHeight() |
|
2284 |
{ |
|
2285 |
Q3ListViewItem::invalidateHeight(); |
|
2286 |
lv->triggerUpdate(); |
|
2287 |
} |
|
2288 |
||
2289 |
||
2290 |
Q3ListView * Q3ListViewPrivate::Root::theListView() const |
|
2291 |
{ |
|
2292 |
return lv; |
|
2293 |
} |
|
2294 |
||
2295 |
||
2296 |
void Q3ListViewPrivate::Root::setup() |
|
2297 |
{ |
|
2298 |
// explicitly nothing |
|
2299 |
} |
|
2300 |
||
2301 |
||
2302 |
||
2303 |
/*! |
|
2304 |
\internal |
|
2305 |
If called after a mouse click, tells the list view to ignore a |
|
2306 |
following double click. This state is reset after the next mouse click. |
|
2307 |
*/ |
|
2308 |
||
2309 |
void Q3ListViewItem::ignoreDoubleClick() |
|
2310 |
{ |
|
2311 |
Q3ListView *lv = listView(); |
|
2312 |
if (lv) |
|
2313 |
lv->d->ignoreDoubleClick = true; |
|
2314 |
} |
|
2315 |
||
2316 |
||
2317 |
||
2318 |
/*! |
|
2319 |
\fn void Q3ListView::onItem(Q3ListViewItem *i) |
|
2320 |
||
2321 |
This signal is emitted when the user moves the mouse cursor onto |
|
2322 |
item \a i, similar to the QWidget::enterEvent() function. |
|
2323 |
*/ |
|
2324 |
||
2325 |
// ### bug here too? see qiconview.cppp onItem/onViewport |
|
2326 |
||
2327 |
/*! |
|
2328 |
\fn void Q3ListView::onViewport() |
|
2329 |
||
2330 |
This signal is emitted when the user moves the mouse cursor from |
|
2331 |
an item to an empty part of the list view. |
|
2332 |
*/ |
|
2333 |
||
2334 |
/*! |
|
2335 |
\enum Q3ListView::SelectionMode |
|
2336 |
||
2337 |
This enumerated type is used by Q3ListView to indicate how it |
|
2338 |
reacts to selection by the user. |
|
2339 |
||
2340 |
\value Single When the user selects an item, any already-selected |
|
2341 |
item becomes unselected, and the user cannot unselect the selected |
|
2342 |
item. |
|
2343 |
||
2344 |
\value Multi When the user selects an item in the usual way, the |
|
2345 |
selection status of that item is toggled and the other items are |
|
2346 |
left alone. |
|
2347 |
||
2348 |
\value Extended When the user selects an item in the usual way, |
|
2349 |
the selection is cleared and the new item selected. However, if |
|
2350 |
the user presses the Ctrl key when clicking on an item, the |
|
2351 |
clicked item gets toggled and all other items are left untouched. |
|
2352 |
And if the user presses the Shift key while clicking on an item, |
|
2353 |
all items between the current item and the clicked item get |
|
2354 |
selected or unselected, depending on the state of the clicked |
|
2355 |
item. Also, multiple items can be selected by dragging the mouse |
|
2356 |
over them. |
|
2357 |
||
2358 |
\value NoSelection Items cannot be selected. |
|
2359 |
||
2360 |
In other words, \c Single is a real single-selection list view, \c |
|
2361 |
Multi a real multi-selection list view, \c Extended is a list view |
|
2362 |
where users can select multiple items but usually want to select |
|
2363 |
either just one or a range of contiguous items, and \c NoSelection |
|
2364 |
is a list view where the user can look but not touch. |
|
2365 |
*/ |
|
2366 |
||
2367 |
/*! |
|
2368 |
\enum Q3ListView::ResizeMode |
|
2369 |
||
2370 |
This enum describes how the list view's header adjusts to resize |
|
2371 |
events which affect the width of the list view. |
|
2372 |
||
2373 |
\value NoColumn The columns do not get resized in resize events. |
|
2374 |
||
2375 |
\value AllColumns All columns are resized equally to fit the width |
|
2376 |
of the list view. |
|
2377 |
||
2378 |
\value LastColumn The last column is resized to fit the width of |
|
2379 |
the list view. |
|
2380 |
*/ |
|
2381 |
||
2382 |
/*! |
|
2383 |
\enum Q3ListView::RenameAction |
|
2384 |
||
2385 |
This enum describes whether a rename operation is accepted if the |
|
2386 |
rename editor loses focus without the user pressing Enter. |
|
2387 |
||
2388 |
\value Accept Rename if Enter is pressed or focus is lost. |
|
2389 |
||
2390 |
\value Reject Discard the rename operation if focus is lost (and |
|
2391 |
Enter has not been pressed). |
|
2392 |
*/ |
|
2393 |
||
2394 |
/*! |
|
2395 |
\class Q3ListView |
|
2396 |
\brief The Q3ListView class implements a list/tree view. |
|
2397 |
||
2398 |
\compat |
|
2399 |
||
2400 |
It can display and control a hierarchy of multi-column items, and |
|
2401 |
provides the ability to add new items at any time. The user may |
|
2402 |
select one or many items (depending on the \c SelectionMode) and |
|
2403 |
sort the list in increasing or decreasing order by any column. |
|
2404 |
||
2405 |
The simplest pattern of use is to create a Q3ListView, add some |
|
2406 |
column headers using addColumn() and create one or more |
|
2407 |
Q3ListViewItem or Q3CheckListItem objects with the Q3ListView as |
|
2408 |
parent. |
|
2409 |
||
2410 |
Further nodes can be added to the list view object (the root of the |
|
2411 |
tree) or as child nodes to Q3ListViewItems. |
|
2412 |
||
2413 |
The main setup functions are: |
|
2414 |
\table |
|
2415 |
\header \i Function \i Action |
|
2416 |
\row \i \l addColumn() |
|
2417 |
\i Adds a column with a text label and perhaps width. Columns |
|
2418 |
are counted from the left starting with column 0. |
|
2419 |
\row \i \l setColumnWidthMode() |
|
2420 |
\i Sets the column to be resized automatically or not. |
|
2421 |
\row \i \l setAllColumnsShowFocus() |
|
2422 |
\i Sets whether items should show keyboard focus using all |
|
2423 |
columns or just column 0. The default is to show focus |
|
2424 |
just using column 0. |
|
2425 |
\row \i \l setRootIsDecorated() |
|
2426 |
\i Sets whether root items can be opened and closed by the |
|
2427 |
user and have open/close decoration to their left. The |
|
2428 |
default is false. |
|
2429 |
\row \i \l setTreeStepSize() |
|
2430 |
\i Sets how many pixels an item's children are indented |
|
2431 |
relative to their parent. The default is 20. This is |
|
2432 |
mostly a matter of taste. |
|
2433 |
\row \i \l setSorting() |
|
2434 |
\i Sets whether the items should be sorted, whether it should |
|
2435 |
be in ascending or descending order, and by what column |
|
2436 |
they should be sorted. By default the list view is sorted |
|
2437 |
by the first column; to switch this off call setSorting(-1). |
|
2438 |
\endtable |
|
2439 |
||
2440 |
There are several functions for mapping between items and |
|
2441 |
coordinates. itemAt() returns the item at a position on-screen, |
|
2442 |
itemRect() returns the rectangle an item occupies on the screen, |
|
2443 |
and itemPos() returns the position of any item (whether it is |
|
2444 |
on-screen or not). firstChild() returns the list view's first item |
|
2445 |
(not necessarily visible on-screen). |
|
2446 |
||
2447 |
You can iterate over visible items using |
|
2448 |
Q3ListViewItem::itemBelow(); over a list view's top-level items |
|
2449 |
using Q3ListViewItem::firstChild() and |
|
2450 |
Q3ListViewItem::nextSibling(); or every item using a |
|
2451 |
Q3ListViewItemIterator. See |
|
2452 |
the Q3ListViewItem documentation for examples of traversal. |
|
2453 |
||
2454 |
An item can be moved amongst its siblings using |
|
2455 |
Q3ListViewItem::moveItem(). To move an item in the hierarchy use |
|
2456 |
takeItem() and insertItem(). Item's (and all their child items) |
|
2457 |
are deleted with \c delete; to delete all the list view's items |
|
2458 |
use clear(). |
|
2459 |
||
2460 |
There are a variety of selection modes described in the |
|
2461 |
Q3ListView::SelectionMode documentation. The default is \c Single |
|
2462 |
selection, which you can change using setSelectionMode(). |
|
2463 |
||
2464 |
Because Q3ListView offers multiple selection it must display |
|
2465 |
keyboard focus and selection state separately. Therefore there are |
|
2466 |
functions both to set the selection state of an item |
|
2467 |
(setSelected()) and to set which item displays keyboard focus |
|
2468 |
(setCurrentItem()). |
|
2469 |
||
2470 |
Q3ListView emits two groups of signals; one group signals changes |
|
2471 |
in selection/focus state and one indicates selection. The first |
|
2472 |
group consists of selectionChanged() (applicable to all list |
|
2473 |
views), selectionChanged(Q3ListViewItem*) (applicable only to a |
|
2474 |
\c Single selection list view), and currentChanged(Q3ListViewItem*). |
|
2475 |
The second group consists of doubleClicked(Q3ListViewItem*), |
|
2476 |
returnPressed(Q3ListViewItem*), |
|
2477 |
rightButtonClicked(Q3ListViewItem*, const QPoint&, int), etc. |
|
2478 |
||
2479 |
Note that changing the state of the list view in a slot connected |
|
2480 |
to a list view signal may cause unexpected side effects. If you |
|
2481 |
need to change the list view's state in response to a signal, use |
|
2482 |
a \link QTimer::singleShot() single shot timer\endlink with a |
|
2483 |
time out of 0, and connect this timer to a slot that modifies the |
|
2484 |
list view's state. |
|
2485 |
||
2486 |
In Motif style, Q3ListView deviates fairly strongly from the look |
|
2487 |
and feel of the Motif hierarchical tree view. This is done mostly |
|
2488 |
to provide a usable keyboard interface and to make the list view |
|
2489 |
look better with a white background. |
|
2490 |
||
2491 |
If selectionMode() is \c Single (the default) the user can select |
|
2492 |
one item at a time, e.g. by clicking an item with the mouse, see |
|
2493 |
\l Q3ListView::SelectionMode for details. |
|
2494 |
||
2495 |
The list view can be navigated either using the mouse or the |
|
2496 |
keyboard. Clicking a \bold{-} icon closes an item (hides its |
|
2497 |
children) and clicking a \bold{+} icon opens an item (shows its |
|
2498 |
children). The keyboard controls are these: |
|
2499 |
\table |
|
2500 |
\header \i Keypress \i Action |
|
2501 |
\row \i Home |
|
2502 |
\i Make the first item current and visible. |
|
2503 |
\row \i End |
|
2504 |
\i Make the last item current and visible. |
|
2505 |
\row \i Page Up |
|
2506 |
\i Make the item above the top visible item current and visible. |
|
2507 |
\row \i Page Down |
|
2508 |
\i Make the item below the bottom visible item current and visible. |
|
2509 |
\row \i Up Arrow |
|
2510 |
\i Make the item above the current item current and visible. |
|
2511 |
\row \i Down Arrow |
|
2512 |
\i Make the item below the current item current and visible. |
|
2513 |
\row \i Left Arrow |
|
2514 |
\i If the current item is closed (\bold{+} icon) or has no |
|
2515 |
children, make its parent item current and visible. If the |
|
2516 |
current item is open (\bold{-} icon) close it, i.e. hide its |
|
2517 |
children. Exception: if the current item is the first item |
|
2518 |
and is closed and the horizontal scroll bar is offset to |
|
2519 |
the right the list view will be scrolled left. |
|
2520 |
\row \i Right Arrow |
|
2521 |
\i If the current item is closed (\bold{+} icon) and has |
|
2522 |
children, the item is opened. If the current item is |
|
2523 |
opened (\bold{-} icon) and has children the item's first |
|
2524 |
child is made current and visible. If the current item has |
|
2525 |
no children the list view is scrolled right. |
|
2526 |
\endtable |
|
2527 |
||
2528 |
If the user starts typing letters with the focus in the list view |
|
2529 |
an incremental search will occur. For example if the user types |
|
2530 |
'd' the current item will change to the first item that begins |
|
2531 |
with the letter 'd'; if they then type 'a', the current item will |
|
2532 |
change to the first item that begins with 'da', and so on. If no |
|
2533 |
item begins with the letters they type the current item doesn't |
|
2534 |
change. |
|
2535 |
||
2536 |
Note that the list view's size hint is calculated taking into |
|
2537 |
account the height \e and width to produce a nice aspect ratio. |
|
2538 |
This may mean that you need to reimplement sizeHint() in some |
|
2539 |
cases. |
|
2540 |
||
2541 |
\warning The list view assumes ownership of all list view items |
|
2542 |
and will delete them when it does not need them any more. |
|
2543 |
||
2544 |
\sa Q3ListViewItem Q3CheckListItem |
|
2545 |
*/ |
|
2546 |
||
2547 |
/*! |
|
2548 |
\fn void Q3ListView::itemRenamed(Q3ListViewItem * item, int col) |
|
2549 |
||
2550 |
\overload |
|
2551 |
||
2552 |
This signal is emitted when \a item has been renamed, e.g. by |
|
2553 |
in-place renaming, in column \a col. |
|
2554 |
||
2555 |
\sa Q3ListViewItem::setRenameEnabled() |
|
2556 |
*/ |
|
2557 |
||
2558 |
/*! |
|
2559 |
\fn void Q3ListView::itemRenamed(Q3ListViewItem * item, int col, const QString &text) |
|
2560 |
||
2561 |
This signal is emitted when \a item has been renamed to \a text, |
|
2562 |
e.g. by in in-place renaming, in column \a col. |
|
2563 |
||
2564 |
\sa Q3ListViewItem::setRenameEnabled() |
|
2565 |
*/ |
|
2566 |
||
2567 |
/*! |
|
2568 |
Constructs a new empty list view called \a name with parent \a |
|
2569 |
parent and widget attributes \a f. |
|
2570 |
||
2571 |
This constructor sets the \c WA_StaticContent and the \c |
|
2572 |
Qt::WA_NoBackground attributes to boost performance when drawing |
|
2573 |
Q3ListViewItems. This may be unsuitable for custom Q3ListViewItem |
|
2574 |
classes, in which case Qt::WA_StaticContents and Qt::WA_NoBackground |
|
2575 |
should be cleared on the viewport() after construction. |
|
2576 |
||
2577 |
\sa QWidget::setAttribute() |
|
2578 |
*/ |
|
2579 |
Q3ListView::Q3ListView(QWidget * parent, const char *name, Qt::WindowFlags f) |
|
2580 |
: Q3ScrollView(parent, name, f | Qt::WStaticContents | Qt::WNoAutoErase) |
|
2581 |
{ |
|
2582 |
init(); |
|
2583 |
} |
|
2584 |
||
2585 |
void Q3ListView::init() |
|
2586 |
{ |
|
2587 |
d = new Q3ListViewPrivate; |
|
2588 |
d->vci = 0; |
|
2589 |
d->timer = new QTimer(this); |
|
2590 |
d->levelWidth = 20; |
|
2591 |
d->r = 0; |
|
2592 |
d->rootIsExpandable = 0; |
|
2593 |
d->h = new Q3Header(this, "list view header"); |
|
2594 |
d->h->installEventFilter(this); |
|
2595 |
d->focusItem = 0; |
|
2596 |
d->oldFocusItem = 0; |
|
2597 |
d->dirtyItemTimer = new QTimer(this); |
|
2598 |
d->visibleTimer = new QTimer(this); |
|
2599 |
d->renameTimer = new QTimer(this); |
|
2600 |
d->autoopenTimer = new QTimer(this); |
|
2601 |
d->margin = 1; |
|
2602 |
d->selectionMode = Q3ListView::Single; |
|
2603 |
d->sortcolumn = 0; |
|
2604 |
d->ascending = true; |
|
2605 |
d->allColumnsShowFocus = false; |
|
2606 |
d->fontMetricsHeight = fontMetrics().height(); |
|
2607 |
d->h->setTracking(true); |
|
2608 |
d->buttonDown = false; |
|
2609 |
d->ignoreDoubleClick = false; |
|
2610 |
d->scrollTimer = 0; |
|
2611 |
d->sortIndicator = false; |
|
2612 |
d->clearing = false; |
|
2613 |
d->minLeftBearing = fontMetrics().minLeftBearing(); |
|
2614 |
d->minRightBearing = fontMetrics().minRightBearing(); |
|
2615 |
d->ellipsisWidth = fontMetrics().width(QLatin1String("...")) * 2; |
|
2616 |
d->highlighted = 0; |
|
2617 |
d->pressedItem = 0; |
|
2618 |
d->selectAnchor = 0; |
|
2619 |
d->select = true; |
|
2620 |
d->startDragItem = 0; |
|
2621 |
d->toolTips = true; |
|
2622 |
d->updateHeader = false; |
|
2623 |
d->fullRepaintOnComlumnChange = false; |
|
2624 |
d->resizeMode = NoColumn; |
|
2625 |
d->defRenameAction = Reject; |
|
2626 |
d->pressedEmptyArea = false; |
|
2627 |
d->startEdit = true; |
|
2628 |
d->ignoreEditAfterFocus = false; |
|
2629 |
d->inMenuMode = false; |
|
2630 |
d->pressedSelected = false; |
|
2631 |
||
2632 |
setMouseTracking(true); |
|
2633 |
viewport()->setMouseTracking(true); |
|
2634 |
||
2635 |
connect(d->timer, SIGNAL(timeout()), |
|
2636 |
this, SLOT(updateContents())); |
|
2637 |
connect(d->dirtyItemTimer, SIGNAL(timeout()), |
|
2638 |
this, SLOT(updateDirtyItems())); |
|
2639 |
connect(d->visibleTimer, SIGNAL(timeout()), |
|
2640 |
this, SLOT(makeVisible())); |
|
2641 |
connect(d->renameTimer, SIGNAL(timeout()), |
|
2642 |
this, SLOT(startRename())); |
|
2643 |
connect(d->autoopenTimer, SIGNAL(timeout()), |
|
2644 |
this, SLOT(openFocusItem())); |
|
2645 |
||
2646 |
connect(d->h, SIGNAL(sizeChange(int,int,int)), |
|
2647 |
this, SLOT(handleSizeChange(int,int,int))); |
|
2648 |
connect(d->h, SIGNAL(indexChange(int,int,int)), |
|
2649 |
this, SLOT(handleIndexChange())); |
|
2650 |
connect(d->h, SIGNAL(sectionClicked(int)), |
|
2651 |
this, SLOT(changeSortColumn(int))); |
|
2652 |
connect(d->h, SIGNAL(sectionHandleDoubleClicked(int)), |
|
2653 |
this, SLOT(adjustColumn(int))); |
|
2654 |
connect(horizontalScrollBar(), SIGNAL(sliderMoved(int)), |
|
2655 |
d->h, SLOT(setOffset(int))); |
|
2656 |
connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), |
|
2657 |
d->h, SLOT(setOffset(int))); |
|
2658 |
||
2659 |
// will access d->r |
|
2660 |
Q3ListViewPrivate::Root * r = new Q3ListViewPrivate::Root(this); |
|
2661 |
r->is_root = true; |
|
2662 |
d->r = r; |
|
2663 |
d->r->setSelectable(false); |
|
2664 |
||
2665 |
viewport()->setFocusProxy(this); |
|
2666 |
viewport()->setFocusPolicy(Qt::WheelFocus); |
|
2667 |
setFocusPolicy(Qt::WheelFocus); |
|
2668 |
viewport()->setBackgroundRole(QPalette::Base); |
|
2669 |
setAttribute(Qt::WA_MacShowFocusRect); |
|
2670 |
} |
|
2671 |
||
2672 |
/*! |
|
2673 |
\property Q3ListView::showSortIndicator |
|
2674 |
\brief whether the list view header should display a sort indicator. |
|
2675 |
||
2676 |
If this property is true, an arrow is drawn in the header of the |
|
2677 |
list view to indicate the sort order of the list view contents. |
|
2678 |
The arrow will be drawn in the correct column and will point up or |
|
2679 |
down, depending on the current sort direction. The default is |
|
2680 |
false (don't show an indicator). |
|
2681 |
||
2682 |
\sa Q3Header::setSortIndicator() |
|
2683 |
*/ |
|
2684 |
||
2685 |
void Q3ListView::setShowSortIndicator(bool show) |
|
2686 |
{ |
|
2687 |
if (show == d->sortIndicator) |
|
2688 |
return; |
|
2689 |
||
2690 |
d->sortIndicator = show; |
|
2691 |
if (d->sortcolumn != Unsorted && d->sortIndicator) |
|
2692 |
d->h->setSortIndicator(d->sortcolumn, d->ascending); |
|
2693 |
else |
|
2694 |
d->h->setSortIndicator(-1); |
|
2695 |
} |
|
2696 |
||
2697 |
bool Q3ListView::showSortIndicator() const |
|
2698 |
{ |
|
2699 |
return d->sortIndicator; |
|
2700 |
} |
|
2701 |
||
2702 |
/*! |
|
2703 |
\property Q3ListView::showToolTips |
|
2704 |
\brief whether this list view should show tooltips for truncated column texts |
|
2705 |
||
2706 |
The default is true. |
|
2707 |
*/ |
|
2708 |
||
2709 |
void Q3ListView::setShowToolTips(bool b) |
|
2710 |
{ |
|
2711 |
d->toolTips = b; |
|
2712 |
} |
|
2713 |
||
2714 |
bool Q3ListView::showToolTips() const |
|
2715 |
{ |
|
2716 |
return d->toolTips; |
|
2717 |
} |
|
2718 |
||
2719 |
/*! |
|
2720 |
\property Q3ListView::resizeMode |
|
2721 |
\brief whether all, none or the only the last column should be resized |
|
2722 |
||
2723 |
Specifies whether all, none or only the last column should be |
|
2724 |
resized to fit the full width of the list view. The values for this |
|
2725 |
property can be one of: \c NoColumn (the default), \c AllColumns |
|
2726 |
or \c LastColumn. |
|
2727 |
||
2728 |
\warning Setting the resize mode should be done after all necessary |
|
2729 |
columns have been added to the list view, otherwise the behavior is |
|
2730 |
undefined. |
|
2731 |
||
2732 |
\sa Q3Header, header() |
|
2733 |
*/ |
|
2734 |
||
2735 |
void Q3ListView::setResizeMode(ResizeMode m) |
|
2736 |
{ |
|
2737 |
d->resizeMode = m; |
|
2738 |
if (m == NoColumn) |
|
2739 |
header()->setStretchEnabled(false); |
|
2740 |
else if (m == AllColumns) |
|
2741 |
header()->setStretchEnabled(true); |
|
2742 |
else |
|
2743 |
header()->setStretchEnabled(true, header()->count() - 1); |
|
2744 |
} |
|
2745 |
||
2746 |
Q3ListView::ResizeMode Q3ListView::resizeMode() const |
|
2747 |
{ |
|
2748 |
return d->resizeMode; |
|
2749 |
} |
|
2750 |
||
2751 |
/*! |
|
2752 |
Destroys the list view, deleting all its items, and frees up all |
|
2753 |
allocated resources. |
|
2754 |
*/ |
|
2755 |
||
2756 |
Q3ListView::~Q3ListView() |
|
2757 |
{ |
|
2758 |
for (int j = 0; j < d->iterators.size(); ++j) { |
|
2759 |
Q3ListViewItemIterator *i = d->iterators.at(j); |
|
2760 |
i->listView = 0; |
|
2761 |
} |
|
2762 |
||
2763 |
d->focusItem = 0; |
|
2764 |
delete d->r; |
|
2765 |
d->r = 0; |
|
2766 |
delete d->vci; |
|
2767 |
d->vci = 0; |
|
2768 |
#if 0 |
|
2769 |
delete d->toolTip; |
|
2770 |
d->toolTip = 0; |
|
2771 |
#endif |
|
2772 |
delete d; |
|
2773 |
d = 0; |
|
2774 |
} |
|
2775 |
||
2776 |
||
2777 |
/*! |
|
2778 |
Calls Q3ListViewItem::paintCell() and |
|
2779 |
Q3ListViewItem::paintBranches() as necessary for all list view |
|
2780 |
items that require repainting in the \a cw pixels wide and \a ch |
|
2781 |
pixels high bounding rectangle starting at position \a cx, \a cy |
|
2782 |
with offset \a ox, \a oy. Uses the painter \a p. |
|
2783 |
*/ |
|
2784 |
||
2785 |
void Q3ListView::drawContentsOffset(QPainter * p, int ox, int oy, |
|
2786 |
int cx, int cy, int cw, int ch) |
|
2787 |
{ |
|
2788 |
if (columns() == 0) { |
|
2789 |
paintEmptyArea(p, QRect(cx, cy, cw, ch)); |
|
2790 |
return; |
|
2791 |
} |
|
2792 |
||
2793 |
if (d->drawables.isEmpty() || |
|
2794 |
d->topPixel > cy || |
|
2795 |
d->bottomPixel < cy + ch - 1 || |
|
2796 |
d->r->maybeTotalHeight < 0) |
|
2797 |
buildDrawableList(); |
|
2798 |
||
2799 |
if (!d->dirtyItems.isEmpty()) { |
|
2800 |
QRect br(cx - ox, cy - oy, cw, ch); |
|
2801 |
for (int i = 0; i < d->dirtyItems.size(); ++i) { |
|
2802 |
const Q3ListViewItem * item = d->dirtyItems.at(i); |
|
2803 |
QRect ir = itemRect(item).intersected(viewport()->visibleRect()); |
|
2804 |
if (ir.isEmpty() || br.contains(ir)) |
|
2805 |
// we're painting this one, or it needs no painting: forget it |
|
2806 |
d->dirtyItems.removeAt(i); |
|
2807 |
} |
|
2808 |
if (d->dirtyItems.count()) { |
|
2809 |
// there are still items left that need repainting |
|
2810 |
d->dirtyItemTimer->start(0, true); |
|
2811 |
} else { |
|
2812 |
// we're painting all items that need to be painted |
|
2813 |
d->dirtyItems.clear(); |
|
2814 |
d->dirtyItemTimer->stop(); |
|
2815 |
} |
|
2816 |
} |
|
2817 |
||
2818 |
p->setFont(font()); |
|
2819 |
||
2820 |
QRect r; |
|
2821 |
int fx = -1, x, fc = 0, lc = 0; |
|
2822 |
int tx = -1; |
|
2823 |
||
2824 |
for (int i = 0; i < d->drawables.size(); ++i) { |
|
2825 |
Q3ListViewPrivate::DrawableItem current = d->drawables.at(i); |
|
2826 |
if (!current.i->isVisible()) |
|
2827 |
continue; |
|
2828 |
int ih = current.i->height(); |
|
2829 |
int ith = current.i->totalHeight(); |
|
2830 |
int c; |
|
2831 |
int cs; |
|
2832 |
||
2833 |
// need to paint current? |
|
2834 |
if (ih > 0 && current.y < cy+ch && current.y+ih > cy) { |
|
2835 |
if (fx < 0) { |
|
2836 |
// find first interesting column, once |
|
2837 |
x = 0; |
|
2838 |
c = 0; |
|
2839 |
cs = d->h->cellSize(0); |
|
2840 |
while (x + cs <= cx && c < d->h->count()) { |
|
2841 |
x += cs; |
|
2842 |
c++; |
|
2843 |
if (c < d->h->count()) |
|
2844 |
cs = d->h->cellSize(c); |
|
2845 |
} |
|
2846 |
fx = x; |
|
2847 |
fc = c; |
|
2848 |
while(x < cx + cw && c < d->h->count()) { |
|
2849 |
x += cs; |
|
2850 |
c++; |
|
2851 |
if (c < d->h->count()) |
|
2852 |
cs = d->h->cellSize(c); |
|
2853 |
} |
|
2854 |
lc = c; |
|
2855 |
} |
|
2856 |
||
2857 |
x = fx; |
|
2858 |
c = fc; |
|
2859 |
// draw to last interesting column |
|
2860 |
||
2861 |
bool drawActiveSelection = hasFocus() || d->inMenuMode || |
|
2862 |
!style()->styleHint(QStyle::SH_ItemView_ChangeHighlightOnFocus, 0, this) |
|
2863 |
|| (currentItem() && currentItem()->renameBox |
|
2864 |
&& currentItem()->renameBox->hasFocus()); |
|
2865 |
QPalette pal = palette(); |
|
2866 |
if(!drawActiveSelection) |
|
2867 |
pal.setCurrentColorGroup(QPalette::Inactive); |
|
2868 |
||
2869 |
while (c < lc) { |
|
2870 |
int i = d->h->mapToLogical(c); |
|
2871 |
cs = d->h->cellSize(c); |
|
2872 |
r.setRect(x - ox, current.y - oy, cs, ih); |
|
2873 |
if (i == 0 && current.i->parentItem) |
|
2874 |
r.setLeft(r.left() + current.l * treeStepSize()); |
|
2875 |
||
2876 |
p->save(); |
|
2877 |
// No need to paint if the cell isn't technically visible |
|
2878 |
if (!(r.width() == 0 || r.height() == 0)) { |
|
2879 |
p->translate(r.left(), r.top()); |
|
2880 |
int ac = d->h->mapToLogical(c); |
|
2881 |
// map to Left currently. This should change once we |
|
2882 |
// can really reverse the listview. |
|
2883 |
int align = columnAlignment(ac); |
|
2884 |
if (align == Qt::AlignAuto) align = Qt::AlignLeft; |
|
2885 |
current.i->paintCell(p, pal, ac, r.width(), align); |
|
2886 |
} |
|
2887 |
p->restore(); |
|
2888 |
x += cs; |
|
2889 |
c++; |
|
2890 |
} |
|
2891 |
||
2892 |
if (current.i == d->focusItem && hasFocus() && |
|
2893 |
!d->allColumnsShowFocus) { |
|
2894 |
p->save(); |
|
2895 |
int cell = d->h->mapToActual(0); |
|
2896 |
QRect r(d->h->cellPos(cell) - ox, current.y - oy, d->h->cellSize(cell), ih); |
|
2897 |
if (current.i->parentItem) |
|
2898 |
r.setLeft(r.left() + current.l * treeStepSize()); |
|
2899 |
if (r.left() < r.right()) |
|
2900 |
current.i->paintFocus(p, palette(), r); |
|
2901 |
p->restore(); |
|
2902 |
} |
|
2903 |
} |
|
2904 |
||
2905 |
const int cell = d->h->mapToActual(0); |
|
2906 |
||
2907 |
// does current need focus indication? |
|
2908 |
if (current.i == d->focusItem && hasFocus() && |
|
2909 |
d->allColumnsShowFocus) { |
|
2910 |
p->save(); |
|
2911 |
int x = -contentsX(); |
|
2912 |
int w = header()->cellPos(header()->count() - 1) + |
|
2913 |
header()->cellSize(header()->count() - 1); |
|
2914 |
||
2915 |
r.setRect(x, current.y - oy, w, ih); |
|
2916 |
if (d->h->mapToActual(0) == 0 || (current.l == 0 && !rootIsDecorated())) { |
|
2917 |
int offsetx = qMin(current.l * treeStepSize(), d->h->cellSize(cell)); |
|
2918 |
r.setLeft(r.left() + offsetx); |
|
2919 |
current.i->paintFocus(p, palette(), r); |
|
2920 |
} else { |
|
2921 |
int xdepth = qMin(treeStepSize() * (current.i->depth() + (rootIsDecorated() ? 1 : 0)) |
|
2922 |
+ itemMargin(), d->h->cellSize(cell)); |
|
2923 |
xdepth += d->h->cellPos(cell); |
|
2924 |
QRect r1(r); |
|
2925 |
r1.setRight(d->h->cellPos(cell) - 1); |
|
2926 |
QRect r2(r); |
|
2927 |
r2.setLeft(xdepth - 1); |
|
2928 |
current.i->paintFocus(p, palette(), r1); |
|
2929 |
current.i->paintFocus(p, palette(), r2); |
|
2930 |
} |
|
2931 |
p->restore(); |
|
2932 |
} |
|
2933 |
||
2934 |
if (tx < 0) |
|
2935 |
tx = d->h->cellPos(cell); |
|
2936 |
||
2937 |
// do any children of current need to be painted? |
|
2938 |
if (ih != ith && |
|
2939 |
(current.i != d->r || d->rootIsExpandable) && |
|
2940 |
current.y + ith > cy && |
|
2941 |
current.y + ih < cy + ch && |
|
2942 |
tx + current.l * treeStepSize() < cx + cw && |
|
2943 |
tx + (current.l+1) * treeStepSize() > cx) { |
|
2944 |
// compute the clip rectangle the safe way |
|
2945 |
||
2946 |
int rtop = current.y + ih; |
|
2947 |
int rbottom = current.y + ith; |
|
2948 |
int rleft = tx + current.l*treeStepSize(); |
|
2949 |
int rright = rleft + treeStepSize(); |
|
2950 |
||
2951 |
int crtop = qMax(rtop, cy); |
|
2952 |
int crbottom = qMin(rbottom, cy+ch); |
|
2953 |
int crleft = qMax(rleft, cx); |
|
2954 |
int crright = qMin(rright, cx+cw); |
|
2955 |
||
2956 |
r.setRect(crleft-ox, crtop-oy, |
|
2957 |
crright-crleft, crbottom-crtop); |
|
2958 |
||
2959 |
if (r.isValid()) { |
|
2960 |
p->save(); |
|
2961 |
p->setClipRect(QRect(d->h->cellPos(cell), 0, d->h->cellSize(cell), height())); |
|
2962 |
p->translate(rleft-ox, crtop-oy); |
|
2963 |
||
2964 |
current.i->paintBranches(p, palette(), treeStepSize(), |
|
2965 |
rtop - crtop, r.height()); |
|
2966 |
p->restore(); |
|
2967 |
} |
|
2968 |
} |
|
2969 |
} |
|
2970 |
||
2971 |
if (d->r->totalHeight() < cy + ch) |
|
2972 |
paintEmptyArea(p, QRect(cx - ox, d->r->totalHeight() - oy, |
|
2973 |
cw, cy + ch - d->r->totalHeight())); |
|
2974 |
||
2975 |
int c = d->h->count()-1; |
|
2976 |
if (c >= 0 && |
|
2977 |
d->h->cellPos(c) + d->h->cellSize(c) < cx + cw) { |
|
2978 |
c = d->h->cellPos(c) + d->h->cellSize(c); |
|
2979 |
paintEmptyArea(p, QRect(c - ox, cy - oy, cx + cw - c, ch)); |
|
2980 |
} |
|
2981 |
} |
|
2982 |
||
2983 |
||
2984 |
||
2985 |
/*! |
|
2986 |
Paints \a rect so that it looks like empty background using |
|
2987 |
painter \a p. \a rect is in widget coordinates, ready to be fed to |
|
2988 |
\a p. |
|
2989 |
||
2990 |
The default function fills \a rect with the |
|
2991 |
viewport()->backgroundBrush(). |
|
2992 |
*/ |
|
2993 |
||
2994 |
void Q3ListView::paintEmptyArea(QPainter * p, const QRect & rect) |
|
2995 |
{ |
|
2996 |
QStyleOptionQ3ListView opt = getStyleOption(this, 0); |
|
2997 |
opt.rect = rect; |
|
2998 |
opt.sortColumn = d->sortcolumn; |
|
2999 |
opt.subControls = QStyle::SC_Q3ListView; |
|
3000 |
style()->drawComplexControl(QStyle::CC_Q3ListView, &opt, p, this); |
|
3001 |
} |
|
3002 |
||
3003 |
||
3004 |
/* |
|
3005 |
Rebuilds the list of drawable Q3ListViewItems. This function is |
|
3006 |
const so that const functions can call it without requiring |
|
3007 |
d->drawables to be mutable. |
|
3008 |
*/ |
|
3009 |
||
3010 |
void Q3ListView::buildDrawableList() const |
|
3011 |
{ |
|
3012 |
d->r->enforceSortOrder(); |
|
3013 |
||
3014 |
QStack<Q3ListViewPrivate::DrawableItem> stack; |
|
3015 |
Q3ListViewPrivate::DrawableItem di(((int)d->rootIsExpandable)-1, 0, d->r); |
|
3016 |
stack.push(di); |
|
3017 |
||
3018 |
Q3ListView *that = const_cast<Q3ListView *>(this); |
|
3019 |
||
3020 |
// could mess with cy and ch in order to speed up vertical |
|
3021 |
// scrolling |
|
3022 |
int cy = contentsY(); |
|
3023 |
int ch = that->visibleHeight(); |
|
3024 |
d->topPixel = cy + ch; // one below bottom |
|
3025 |
d->bottomPixel = cy - 1; // one above top |
|
3026 |
||
3027 |
that->d->drawables.clear(); |
|
3028 |
||
3029 |
while (!stack.isEmpty()) { |
|
3030 |
Q3ListViewPrivate::DrawableItem cur = stack.pop(); |
|
3031 |
||
3032 |
int ih = cur.i->height(); |
|
3033 |
int ith = cur.i->totalHeight(); |
|
3034 |
||
3035 |
// is this item, or its branch symbol, inside the viewport? |
|
3036 |
if (cur.y + ith >= cy && cur.y < cy + ch) { |
|
3037 |
that->d->drawables.append(cur); |
|
3038 |
// perhaps adjust topPixel up to this item? may be adjusted |
|
3039 |
// down again if any children are not to be painted |
|
3040 |
if (cur.y < d->topPixel) |
|
3041 |
d->topPixel = cur.y; |
|
3042 |
// bottompixel is easy: the bottom item drawn contains it |
|
3043 |
d->bottomPixel = cur.y + ih - 1; |
|
3044 |
} |
|
3045 |
||
3046 |
// push younger sibling of cur on the stack? |
|
3047 |
if (cur.y + ith < cy+ch && cur.i->siblingItem) |
|
3048 |
stack.push(Q3ListViewPrivate::DrawableItem(cur.l, cur.y + ith, cur.i->siblingItem)); |
|
3049 |
||
3050 |
// do any children of cur need to be painted? |
|
3051 |
if (cur.i->isOpen() && cur.i->childCount() && |
|
3052 |
cur.y + ith > cy && |
|
3053 |
cur.y + ih < cy + ch) { |
|
3054 |
cur.i->enforceSortOrder(); |
|
3055 |
||
3056 |
Q3ListViewItem * c = cur.i->childItem; |
|
3057 |
int y = cur.y + ih; |
|
3058 |
||
3059 |
// if any of the children are not to be painted, skip them |
|
3060 |
// and invalidate topPixel |
|
3061 |
while (c && y + c->totalHeight() <= cy) { |
|
3062 |
y += c->totalHeight(); |
|
3063 |
c = c->siblingItem; |
|
3064 |
d->topPixel = cy + ch; |
|
3065 |
} |
|
3066 |
||
3067 |
// push one child on the stack, if there is at least one |
|
3068 |
// needing to be painted |
|
3069 |
if (c && y < cy+ch) |
|
3070 |
stack.push(Q3ListViewPrivate::DrawableItem(cur.l + 1, y, c)); |
|
3071 |
} |
|
3072 |
} |
|
3073 |
} |
|
3074 |
||
3075 |
/*! |
|
3076 |
\property Q3ListView::treeStepSize |
|
3077 |
\brief the number of pixels a child is offset from its parent |
|
3078 |
||
3079 |
The default is 20 pixels. |
|
3080 |
||
3081 |
Of course, this property is only meaningful for hierarchical list |
|
3082 |
views. |
|
3083 |
*/ |
|
3084 |
||
3085 |
int Q3ListView::treeStepSize() const |
|
3086 |
{ |
|
3087 |
return d->levelWidth; |
|
3088 |
} |
|
3089 |
||
3090 |
void Q3ListView::setTreeStepSize(int size) |
|
3091 |
{ |
|
3092 |
if (size != d->levelWidth) { |
|
3093 |
d->levelWidth = size; |
|
3094 |
viewport()->repaint(); |
|
3095 |
} |
|
3096 |
} |
|
3097 |
||
3098 |
/*! |
|
3099 |
Inserts item \a i into the list view as a top-level item. You do |
|
3100 |
not need to call this unless you've called takeItem(\a i) or |
|
3101 |
Q3ListViewItem::takeItem(\a i) and need to reinsert \a i elsewhere. |
|
3102 |
||
3103 |
\sa Q3ListViewItem::takeItem() takeItem() |
|
3104 |
*/ |
|
3105 |
||
3106 |
void Q3ListView::insertItem(Q3ListViewItem * i) |
|
3107 |
{ |
|
3108 |
if (d->r) // not for d->r itself |
|
3109 |
d->r->insertItem(i); |
|
3110 |
} |
|
3111 |
||
3112 |
||
3113 |
/*! |
|
3114 |
Removes and deletes all the items in this list view and triggers |
|
3115 |
an update. |
|
3116 |
||
3117 |
\sa triggerUpdate() |
|
3118 |
*/ |
|
3119 |
||
3120 |
void Q3ListView::clear() |
|
3121 |
{ |
|
3122 |
bool wasUpdatesEnabled = viewport()->updatesEnabled(); |
|
3123 |
if (wasUpdatesEnabled) |
|
3124 |
viewport()->setUpdatesEnabled(false); |
|
3125 |
setContentsPos(0, 0); |
|
3126 |
if (wasUpdatesEnabled) |
|
3127 |
viewport()->setUpdatesEnabled(true); |
|
3128 |
||
3129 |
bool block = signalsBlocked(); |
|
3130 |
blockSignals(true); |
|
3131 |
d->clearing = true; |
|
3132 |
clearSelection(); |
|
3133 |
for (int j = 0; j < d->iterators.size(); ++j) { |
|
3134 |
Q3ListViewItemIterator *i = d->iterators.at(j); |
|
3135 |
i->curr = 0; |
|
3136 |
} |
|
3137 |
||
3138 |
d->drawables.clear(); |
|
3139 |
d->dirtyItems.clear(); |
|
3140 |
d->dirtyItemTimer->stop(); |
|
3141 |
||
3142 |
d->highlighted = 0; |
|
3143 |
d->focusItem = 0; |
|
3144 |
d->selectAnchor = 0; |
|
3145 |
d->pressedItem = 0; |
|
3146 |
d->startDragItem = 0; |
|
3147 |
||
3148 |
// if it's down its downness makes no sense, so undown it |
|
3149 |
d->buttonDown = false; |
|
3150 |
||
3151 |
Q3ListViewItem *c = (Q3ListViewItem *)d->r->firstChild(); |
|
3152 |
Q3ListViewItem *n; |
|
3153 |
while(c) { |
|
3154 |
n = (Q3ListViewItem *)c->nextSibling(); |
|
3155 |
delete c; |
|
3156 |
c = n; |
|
3157 |
} |
|
3158 |
resizeContents(d->h->sizeHint().width(), contentsHeight()); |
|
3159 |
delete d->r; |
|
3160 |
d->r = 0; |
|
3161 |
Q3ListViewPrivate::Root * r = new Q3ListViewPrivate::Root(this); |
|
3162 |
r->is_root = true; |
|
3163 |
d->r = r; |
|
3164 |
d->r->setSelectable(false); |
|
3165 |
blockSignals(block); |
|
3166 |
triggerUpdate(); |
|
3167 |
d->clearing = false; |
|
3168 |
} |
|
3169 |
||
3170 |
/*! |
|
3171 |
\reimp |
|
3172 |
*/ |
|
3173 |
||
3174 |
void Q3ListView::setContentsPos(int x, int y) |
|
3175 |
{ |
|
3176 |
updateGeometries(); |
|
3177 |
Q3ScrollView::setContentsPos(x, y); |
|
3178 |
} |
|
3179 |
||
3180 |
/*! |
|
3181 |
Adds a \a width pixels wide column with the column header \a label |
|
3182 |
to the list view, and returns the index of the new column. |
|
3183 |
||
3184 |
All columns apart from the first one are inserted to the right of |
|
3185 |
the existing ones. |
|
3186 |
||
3187 |
If \a width is negative, the new column's \l WidthMode is set to |
|
3188 |
\c Maximum instead of \c Manual. |
|
3189 |
||
3190 |
\sa setColumnText() setColumnWidth() setColumnWidthMode() |
|
3191 |
*/ |
|
3192 |
int Q3ListView::addColumn(const QString &label, int width) |
|
3193 |
{ |
|
3194 |
int c = d->h->addLabel(label, width); |
|
3195 |
d->column.resize(c+1); |
|
3196 |
d->column[c].wmode = (width >= 0 ? Manual : Maximum); |
|
3197 |
updateGeometries(); |
|
3198 |
updateGeometry(); |
|
3199 |
return c; |
|
3200 |
} |
|
3201 |
||
3202 |
/*! |
|
3203 |
\overload |
|
3204 |
||
3205 |
Adds a \a width pixels wide new column with the header \a label |
|
3206 |
and the \a icon to the list view, and returns the index of the |
|
3207 |
column. |
|
3208 |
||
3209 |
If \a width is negative, the new column's \l WidthMode is set to |
|
3210 |
\c Maximum, and to \c Manual otherwise. |
|
3211 |
||
3212 |
\sa setColumnText() setColumnWidth() setColumnWidthMode() |
|
3213 |
*/ |
|
3214 |
int Q3ListView::addColumn(const QIcon& icon, const QString &label, int width) |
|
3215 |
{ |
|
3216 |
int c = d->h->addLabel(icon, label, width); |
|
3217 |
d->column.resize(c+1); |
|
3218 |
d->column[c].wmode = (width >= 0 ? Manual : Maximum); |
|
3219 |
updateGeometries(); |
|
3220 |
updateGeometry(); |
|
3221 |
return c; |
|
3222 |
} |
|
3223 |
||
3224 |
/*! |
|
3225 |
\property Q3ListView::columns |
|
3226 |
\brief the number of columns in this list view |
|
3227 |
||
3228 |
\sa addColumn(), removeColumn() |
|
3229 |
*/ |
|
3230 |
||
3231 |
int Q3ListView::columns() const |
|
3232 |
{ |
|
3233 |
return d->column.count(); |
|
3234 |
} |
|
3235 |
||
3236 |
/*! |
|
3237 |
Removes the column at position \a index. |
|
3238 |
*/ |
|
3239 |
||
3240 |
void Q3ListView::removeColumn(int index) |
|
3241 |
{ |
|
3242 |
if (index < 0 || index > (int)d->column.count() - 1) |
|
3243 |
return; |
|
3244 |
||
3245 |
if (d->vci) { |
|
3246 |
Q3ListViewPrivate::ViewColumnInfo *vi = d->vci, *prev = 0, *next = 0; |
|
3247 |
for (int i = 0; i < index; ++i) { |
|
3248 |
if (vi) { |
|
3249 |
prev = vi; |
|
3250 |
vi = vi->next; |
|
3251 |
} |
|
3252 |
} |
|
3253 |
if (vi) { |
|
3254 |
next = vi->next; |
|
3255 |
if (prev) |
|
3256 |
prev->next = next; |
|
3257 |
vi->next = 0; |
|
3258 |
delete vi; |
|
3259 |
if (index == 0) |
|
3260 |
d->vci = next; |
|
3261 |
} |
|
3262 |
} |
|
3263 |
||
3264 |
Q3ListViewItemIterator it(this); |
|
3265 |
for (; it.current(); ++it) { |
|
3266 |
Q3ListViewPrivate::ItemColumnInfo *ci = (Q3ListViewPrivate::ItemColumnInfo*)it.current()->columns; |
|
3267 |
if (ci) { |
|
3268 |
Q3ListViewPrivate::ItemColumnInfo *prev = 0, *next = 0; |
|
3269 |
for (int i = 0; i < index; ++i) { |
|
3270 |
if (ci) { |
|
3271 |
prev = ci; |
|
3272 |
ci = ci->next; |
|
3273 |
} |
|
3274 |
} |
|
3275 |
if (ci) { |
|
3276 |
next = ci->next; |
|
3277 |
if (prev) |
|
3278 |
prev->next = next; |
|
3279 |
ci->next = 0; |
|
3280 |
delete ci; |
|
3281 |
if (index == 0) |
|
3282 |
it.current()->columns = next; |
|
3283 |
} |
|
3284 |
} |
|
3285 |
} |
|
3286 |
||
3287 |
for (int i = index; i < (int)d->column.size() - 1; ++i) |
|
3288 |
d->column[i] = d->column[i + 1]; |
|
3289 |
d->column.resize(d->column.size() - 1); |
|
3290 |
||
3291 |
d->h->removeLabel(index); |
|
3292 |
if (d->resizeMode == LastColumn) |
|
3293 |
d->h->setStretchEnabled(true, d->h->count() - 1); |
|
3294 |
||
3295 |
updateGeometries(); |
|
3296 |
if (d->column.count() == 0) |
|
3297 |
clear(); |
|
3298 |
updateGeometry(); |
|
3299 |
viewport()->update(); |
|
3300 |
} |
|
3301 |
||
3302 |
/*! |
|
3303 |
Sets the heading of column \a column to \a label. |
|
3304 |
||
3305 |
\sa columnText() |
|
3306 |
*/ |
|
3307 |
void Q3ListView::setColumnText(int column, const QString &label) |
|
3308 |
{ |
|
3309 |
if (column < d->h->count()) { |
|
3310 |
d->h->setLabel(column, label); |
|
3311 |
updateGeometries(); |
|
3312 |
updateGeometry(); |
|
3313 |
} |
|
3314 |
} |
|
3315 |
||
3316 |
/*! |
|
3317 |
\overload |
|
3318 |
||
3319 |
Sets the heading of column \a column to \a icon and \a label. |
|
3320 |
||
3321 |
\sa columnText() |
|
3322 |
*/ |
|
3323 |
void Q3ListView::setColumnText(int column, const QIcon& icon, const QString &label) |
|
3324 |
{ |
|
3325 |
if (column < d->h->count()) { |
|
3326 |
d->h->setLabel(column, icon, label); |
|
3327 |
updateGeometries(); |
|
3328 |
} |
|
3329 |
} |
|
3330 |
||
3331 |
/*! |
|
3332 |
Sets the width of column \a column to \a w pixels. Note that if |
|
3333 |
the column has a \c WidthMode other than \c Manual, this width |
|
3334 |
setting may be subsequently overridden. |
|
3335 |
||
3336 |
\sa columnWidth() |
|
3337 |
*/ |
|
3338 |
void Q3ListView::setColumnWidth(int column, int w) |
|
3339 |
{ |
|
3340 |
int oldw = d->h->sectionSize(column); |
|
3341 |
if (column < d->h->count() && oldw != w) { |
|
3342 |
d->h->resizeSection(column, w); |
|
3343 |
disconnect(d->h, SIGNAL(sizeChange(int,int,int)), |
|
3344 |
this, SLOT(handleSizeChange(int,int,int))); |
|
3345 |
emit d->h->sizeChange(column, oldw, w); |
|
3346 |
connect(d->h, SIGNAL(sizeChange(int,int,int)), |
|
3347 |
this, SLOT(handleSizeChange(int,int,int))); |
|
3348 |
viewport()->update(); |
|
3349 |
} |
|
3350 |
} |
|
3351 |
||
3352 |
||
3353 |
/*! |
|
3354 |
Returns the text of column \a c. |
|
3355 |
||
3356 |
\sa setColumnText() |
|
3357 |
*/ |
|
3358 |
||
3359 |
QString Q3ListView::columnText(int c) const |
|
3360 |
{ |
|
3361 |
return d->h->label(c); |
|
3362 |
} |
|
3363 |
||
3364 |
/*! |
|
3365 |
Returns the width of column \a c. |
|
3366 |
||
3367 |
\sa setColumnWidth() |
|
3368 |
*/ |
|
3369 |
||
3370 |
int Q3ListView::columnWidth(int c) const |
|
3371 |
{ |
|
3372 |
int actual = d->h->mapToActual(c); |
|
3373 |
return d->h->cellSize(actual); |
|
3374 |
} |
|
3375 |
||
3376 |
||
3377 |
/*! |
|
3378 |
\enum Q3ListView::WidthMode |
|
3379 |
||
3380 |
This enum type describes how the width of a column in the view |
|
3381 |
changes. |
|
3382 |
||
3383 |
\value Manual the column width does not change automatically. |
|
3384 |
||
3385 |
\value Maximum the column is automatically sized according to the |
|
3386 |
widths of all items in the column. (Note: The column never shrinks |
|
3387 |
in this case.) This means that the column is always resized to the |
|
3388 |
width of the item with the largest width in the column. |
|
3389 |
||
3390 |
\sa setColumnWidth() setColumnWidthMode() columnWidth() |
|
3391 |
*/ |
|
3392 |
||
3393 |
||
3394 |
/*! |
|
3395 |
Sets column \a{c}'s width mode to \a mode. The default depends on |
|
3396 |
the original width argument to addColumn(). |
|
3397 |
||
3398 |
\sa Q3ListViewItem::width() |
|
3399 |
*/ |
|
3400 |
||
3401 |
void Q3ListView::setColumnWidthMode(int c, WidthMode mode) |
|
3402 |
{ |
|
3403 |
if (c >= 0 && c < d->h->count()) |
|
3404 |
d->column[c].wmode = mode; |
|
3405 |
} |
|
3406 |
||
3407 |
||
3408 |
/*! |
|
3409 |
Returns the \c WidthMode for column \a c. |
|
3410 |
||
3411 |
\sa setColumnWidthMode() |
|
3412 |
*/ |
|
3413 |
||
3414 |
Q3ListView::WidthMode Q3ListView::columnWidthMode(int c) const |
|
3415 |
{ |
|
3416 |
if (c >= 0 && c < d->h->count()) |
|
3417 |
return d->column[c].wmode; |
|
3418 |
else |
|
3419 |
return Manual; |
|
3420 |
} |
|
3421 |
||
3422 |
||
3423 |
/*! |
|
3424 |
Sets column \a{column}'s alignment to \a align. The alignment is |
|
3425 |
ultimately passed to Q3ListViewItem::paintCell() for each item in |
|
3426 |
the list view. For horizontally aligned text with Qt::AlignLeft or |
|
3427 |
Qt::AlignHCenter the ellipsis (...) will be to the right, for |
|
3428 |
Qt::AlignRight the ellipsis will be to the left. |
|
3429 |
||
3430 |
\sa Qt::Alignment |
|
3431 |
*/ |
|
3432 |
||
3433 |
void Q3ListView::setColumnAlignment(int column, int align) |
|
3434 |
{ |
|
3435 |
if (column < 0) |
|
3436 |
return; |
|
3437 |
if (!d->vci) |
|
3438 |
d->vci = new Q3ListViewPrivate::ViewColumnInfo; |
|
3439 |
Q3ListViewPrivate::ViewColumnInfo * l = d->vci; |
|
3440 |
while(column) { |
|
3441 |
if (!l->next) |
|
3442 |
l->next = new Q3ListViewPrivate::ViewColumnInfo; |
|
3443 |
l = l->next; |
|
3444 |
column--; |
|
3445 |
} |
|
3446 |
if (l->align == align) |
|
3447 |
return; |
|
3448 |
l->align = align; |
|
3449 |
triggerUpdate(); |
|
3450 |
} |
|
3451 |
||
3452 |
||
3453 |
/*! |
|
3454 |
Returns the alignment of column \a column. The default is \c |
|
3455 |
Qt::AlignAuto. |
|
3456 |
||
3457 |
\sa Qt::Alignment |
|
3458 |
*/ |
|
3459 |
||
3460 |
int Q3ListView::columnAlignment(int column) const |
|
3461 |
{ |
|
3462 |
if (column < 0 || !d->vci) |
|
3463 |
return Qt::AlignAuto; |
|
3464 |
Q3ListViewPrivate::ViewColumnInfo * l = d->vci; |
|
3465 |
while(column) { |
|
3466 |
if (!l->next) |
|
3467 |
l->next = new Q3ListViewPrivate::ViewColumnInfo; |
|
3468 |
l = l->next; |
|
3469 |
column--; |
|
3470 |
} |
|
3471 |
return l ? l->align : Qt::AlignAuto; |
|
3472 |
} |
|
3473 |
||
3474 |
||
3475 |
||
3476 |
/*! |
|
3477 |
\internal |
|
3478 |
*/ |
|
3479 |
void Q3ListView::show() |
|
3480 |
{ |
|
3481 |
// Reimplemented to setx the correct background mode and viewed |
|
3482 |
// area size. |
|
3483 |
if (!isVisible()) { |
|
3484 |
reconfigureItems(); |
|
3485 |
updateGeometries(); |
|
3486 |
} |
|
3487 |
Q3ScrollView::show(); |
|
3488 |
} |
|
3489 |
||
3490 |
||
3491 |
/*! |
|
3492 |
Updates the sizes of the viewport, header, scroll bars and so on. |
|
3493 |
||
3494 |
\warning Don't call this directly; call triggerUpdate() instead. |
|
3495 |
*/ |
|
3496 |
||
3497 |
void Q3ListView::updateContents() |
|
3498 |
{ |
|
3499 |
if (d->updateHeader) |
|
3500 |
header()->adjustHeaderSize(); |
|
3501 |
d->updateHeader = false; |
|
3502 |
if (!isVisible()) { |
|
3503 |
// Not in response to a setText/setPixmap any more. |
|
3504 |
return; |
|
3505 |
} |
|
3506 |
d->drawables.clear(); |
|
3507 |
viewport()->setUpdatesEnabled(false); |
|
3508 |
updateGeometries(); |
|
3509 |
viewport()->setUpdatesEnabled(true); |
|
3510 |
viewport()->repaint(); |
|
3511 |
} |
|
3512 |
||
3513 |
||
3514 |
void Q3ListView::updateGeometries() |
|
3515 |
{ |
|
3516 |
int th = d->r->totalHeight(); |
|
3517 |
int tw = d->h->headerWidth(); |
|
3518 |
if (d->h->offset() && |
|
3519 |
tw < d->h->offset() + d->h->width()) |
|
3520 |
horizontalScrollBar()->setValue(tw - Q3ListView::d->h->width()); |
|
3521 |
#if 0 |
|
3522 |
if (QApplication::reverseLayout() && d->h->offset() != horizontalScrollBar()->value()) |
|
3523 |
horizontalScrollBar()->setValue(d->h->offset()); |
|
3524 |
#endif |
|
3525 |
verticalScrollBar()->raise(); |
|
3526 |
resizeContents(tw, th); |
|
3527 |
d->drawables.clear(); |
|
3528 |
if (d->h->isHidden()) { |
|
3529 |
setMargins(0, 0, 0, 0); |
|
3530 |
} else { |
|
3531 |
QSize hs(d->h->sizeHint()); |
|
3532 |
setMargins(0, hs.height(), 0, 0); |
|
3533 |
d->h->setGeometry(viewport()->x(), viewport()->y()-hs.height(), |
|
3534 |
visibleWidth(), hs.height()); |
|
3535 |
} |
|
3536 |
} |
|
3537 |
||
3538 |
||
3539 |
/*! |
|
3540 |
Updates the display when the section \a section has changed size |
|
3541 |
from the old size, \a os, to the new size, \a ns. |
|
3542 |
*/ |
|
3543 |
||
3544 |
void Q3ListView::handleSizeChange(int section, int os, int ns) |
|
3545 |
{ |
|
3546 |
bool upe = viewport()->updatesEnabled(); |
|
3547 |
if (upe) |
|
3548 |
viewport()->setUpdatesEnabled(false); |
|
3549 |
viewport()->setAttribute(Qt::WA_UpdatesDisabled, true); |
|
3550 |
int sx = horizontalScrollBar()->value(); |
|
3551 |
bool sv = horizontalScrollBar()->isVisible(); |
|
3552 |
updateGeometries(); |
|
3553 |
bool fullRepaint = d->fullRepaintOnComlumnChange || sx != horizontalScrollBar()->value() |
|
3554 |
|| sv != horizontalScrollBar()->isVisible(); |
|
3555 |
d->fullRepaintOnComlumnChange = false; |
|
3556 |
if (upe) |
|
3557 |
viewport()->setUpdatesEnabled(true); |
|
3558 |
||
3559 |
if (fullRepaint) { |
|
3560 |
viewport()->repaint(); |
|
3561 |
return; |
|
3562 |
} |
|
3563 |
||
3564 |
int actual = d->h->mapToActual(section); |
|
3565 |
int dx = ns - os; |
|
3566 |
int left = d->h->cellPos(actual) - contentsX() + d->h->cellSize(actual); |
|
3567 |
if (dx > 0) |
|
3568 |
left -= dx; |
|
3569 |
if (left < visibleWidth()) |
|
3570 |
viewport()->scroll(dx, 0, QRect(left, 0, visibleWidth() - left, visibleHeight())); |
|
3571 |
viewport()->repaint(left - 4 - d->ellipsisWidth, 0, 4 + d->ellipsisWidth, |
|
3572 |
visibleHeight()); // border between the items and ellipses width |
|
3573 |
||
3574 |
// map auto to left for now. Need to fix this once we support |
|
3575 |
// reverse layout on the listview. |
|
3576 |
int align = columnAlignment(section); |
|
3577 |
if (align == Qt::AlignAuto) align = Qt::AlignLeft; |
|
3578 |
if (align != Qt::AlignAuto && align != Qt::AlignLeft) |
|
3579 |
viewport()->repaint(d->h->cellPos(actual) - contentsX(), 0, |
|
3580 |
d->h->cellSize(actual), visibleHeight()); |
|
3581 |
||
3582 |
if (currentItem() && currentItem()->renameBox) { |
|
3583 |
QRect r = itemRect(currentItem()); |
|
3584 |
r = QRect(viewportToContents(r.topLeft()), r.size()); |
|
3585 |
r.setLeft(header()->sectionPos(currentItem()->renameCol)); |
|
3586 |
r.setWidth(header()->sectionSize(currentItem()->renameCol) - 1); |
|
3587 |
if (currentItem()->renameCol == 0) |
|
3588 |
r.setLeft(r.left() + itemMargin() + (currentItem()->depth() + |
|
3589 |
(rootIsDecorated() ? 1 : 0)) * treeStepSize() - 1); |
|
3590 |
if (currentItem()->pixmap(currentItem()->renameCol)) |
|
3591 |
r.setLeft(r.left() + currentItem()->pixmap(currentItem()->renameCol)->width()); |
|
3592 |
if (r.x() - contentsX() < 0) |
|
3593 |
r.setX(contentsX()); |
|
3594 |
if (r.width() > visibleWidth()) |
|
3595 |
r.setWidth(visibleWidth()); |
|
3596 |
addChild(currentItem()->renameBox, r.x(), r.y()); |
|
3597 |
currentItem()->renameBox->resize(r.size()); |
|
3598 |
} |
|
3599 |
} |
|
3600 |
||
3601 |
||
3602 |
/* |
|
3603 |
Very smart internal slot that repaints \e only the items that need |
|
3604 |
to be repainted. Don't use this directly; call repaintItem() |
|
3605 |
instead. |
|
3606 |
*/ |
|
3607 |
||
3608 |
void Q3ListView::updateDirtyItems() |
|
3609 |
{ |
|
3610 |
if (d->timer->isActive() || d->dirtyItems.isEmpty()) |
|
3611 |
return; |
|
3612 |
QRect ir; |
|
3613 |
for (int i = 0; i < d->dirtyItems.size(); ++i) { |
|
3614 |
const Q3ListViewItem *item = d->dirtyItems.at(i); |
|
3615 |
ir = ir.united(itemRect(item)); |
|
3616 |
} |
|
3617 |
d->dirtyItems.clear(); |
|
3618 |
if (!ir.isEmpty()) { // rectangle to be repainted |
|
3619 |
if (ir.x() < 0) |
|
3620 |
ir.moveBy(-ir.x(), 0); |
|
3621 |
viewport()->repaint(ir); |
|
3622 |
} |
|
3623 |
} |
|
3624 |
||
3625 |
||
3626 |
void Q3ListView::makeVisible() |
|
3627 |
{ |
|
3628 |
if (d->focusItem) |
|
3629 |
ensureItemVisible(d->focusItem); |
|
3630 |
} |
|
3631 |
||
3632 |
||
3633 |
/*! |
|
3634 |
Ensures that the header is correctly sized and positioned when the |
|
3635 |
resize event \a e occurs. |
|
3636 |
*/ |
|
3637 |
||
3638 |
void Q3ListView::resizeEvent(QResizeEvent *e) |
|
3639 |
{ |
|
3640 |
Q3ScrollView::resizeEvent(e); |
|
3641 |
d->fullRepaintOnComlumnChange = true; |
|
3642 |
d->h->resize(visibleWidth(), d->h->height()); |
|
3643 |
d->h->adjustHeaderSize(); |
|
3644 |
} |
|
3645 |
||
3646 |
/*! \reimp */ |
|
3647 |
||
3648 |
void Q3ListView::viewportResizeEvent(QResizeEvent *e) |
|
3649 |
{ |
|
3650 |
Q3ScrollView::viewportResizeEvent(e); |
|
3651 |
d->h->resize(visibleWidth(), d->h->height()); |
|
3652 |
if (resizeMode() != NoColumn && currentItem() && currentItem()->renameBox) { |
|
3653 |
QRect r = itemRect(currentItem()); |
|
3654 |
r = QRect(viewportToContents(r.topLeft()), r.size()); |
|
3655 |
r.setLeft(header()->sectionPos(currentItem()->renameCol)); |
|
3656 |
r.setWidth(header()->sectionSize(currentItem()->renameCol) - 1); |
|
3657 |
if (currentItem()->renameCol == 0) |
|
3658 |
r.setLeft(r.left() + itemMargin() + (currentItem()->depth() + |
|
3659 |
(rootIsDecorated() ? 1 : 0)) * treeStepSize() - 1); |
|
3660 |
if (currentItem()->pixmap(currentItem()->renameCol)) |
|
3661 |
r.setLeft(r.left() + currentItem()->pixmap(currentItem()->renameCol)->width()); |
|
3662 |
if (r.x() - contentsX() < 0) |
|
3663 |
r.setX(contentsX()); |
|
3664 |
if (r.width() > visibleWidth()) |
|
3665 |
r.setWidth(visibleWidth()); |
|
3666 |
addChild(currentItem()->renameBox, r.x(), r.y()); |
|
3667 |
currentItem()->renameBox->resize(r.size()); |
|
3668 |
} |
|
3669 |
} |
|
3670 |
||
3671 |
/*! |
|
3672 |
Triggers a size, geometry and content update during the next |
|
3673 |
iteration of the event loop. Ensures that there'll be just one |
|
3674 |
update to avoid flicker. |
|
3675 |
*/ |
|
3676 |
||
3677 |
void Q3ListView::triggerUpdate() |
|
3678 |
{ |
|
3679 |
if (!isVisible() || !updatesEnabled()) { |
|
3680 |
// Not in response to a setText/setPixmap any more. |
|
3681 |
return; // it will update when shown, or something. |
|
3682 |
} |
|
3683 |
||
3684 |
d->timer->start(0, true); |
|
3685 |
} |
|
3686 |
||
3687 |
||
3688 |
/*! |
|
3689 |
Redirects the event \a e relating to object \a o, for the viewport |
|
3690 |
to mousePressEvent(), keyPressEvent() and friends. |
|
3691 |
*/ |
|
3692 |
||
3693 |
bool Q3ListView::eventFilter(QObject * o, QEvent * e) |
|
3694 |
{ |
|
3695 |
if (o == d->h && |
|
3696 |
e->type() >= QEvent::MouseButtonPress && |
|
3697 |
e->type() <= QEvent::MouseMove) { |
|
3698 |
QMouseEvent * me = (QMouseEvent *)e; |
|
3699 |
QMouseEvent me2(me->type(), |
|
3700 |
QPoint(me->pos().x(), |
|
3701 |
me->pos().y() - d->h->height()), |
|
3702 |
me->button(), me->state()); |
|
3703 |
switch(me2.type()) { |
|
3704 |
case QEvent::MouseButtonDblClick: |
|
3705 |
if (me2.button() == Qt::RightButton) |
|
3706 |
return true; |
|
3707 |
break; |
|
3708 |
case QEvent::MouseMove: |
|
3709 |
if (me2.state() & Qt::RightButton) { |
|
3710 |
viewportMouseMoveEvent(&me2); |
|
3711 |
return true; |
|
3712 |
} |
|
3713 |
break; |
|
3714 |
default: |
|
3715 |
break; |
|
3716 |
} |
|
3717 |
} else if (o == viewport()) { |
|
3718 |
QFocusEvent * fe = (QFocusEvent *)e; |
|
3719 |
||
3720 |
switch(e->type()) { |
|
3721 |
case QEvent::FocusIn: |
|
3722 |
focusInEvent(fe); |
|
3723 |
return true; |
|
3724 |
case QEvent::FocusOut: |
|
3725 |
focusOutEvent(fe); |
|
3726 |
return true; |
|
3727 |
#ifndef QT_NO_TOOLTIP |
|
3728 |
case QEvent::ToolTip: |
|
3729 |
{ |
|
3730 |
if (!showToolTips()) |
|
3731 |
return false; |
|
3732 |
||
3733 |
QHelpEvent *he = static_cast<QHelpEvent *>(e); |
|
3734 |
Q3ListViewItem *item = itemAt(he->pos()); |
|
3735 |
QPoint contentsPos = viewportToContents(he->pos()); |
|
3736 |
if (!item || !item->columns) { |
|
3737 |
QToolTip::showText(he->globalPos(), QString(), viewport()); |
|
3738 |
return true; |
|
3739 |
} |
|
3740 |
int col = header()->sectionAt(contentsPos.x()); |
|
3741 |
Q3ListViewPrivate::ItemColumnInfo *ci = (Q3ListViewPrivate::ItemColumnInfo*)item->columns; |
|
3742 |
for (int i = 0; ci && (i < col); ++i) |
|
3743 |
ci = ci->next; |
|
3744 |
||
3745 |
if (!ci || !ci->truncated) |
|
3746 |
QToolTip::showText(he->globalPos(), QString(), viewport()); |
|
3747 |
else |
|
3748 |
QToolTip::showText(he->globalPos(), item->text(col), viewport()); |
|
3749 |
return true; |
|
3750 |
} |
|
3751 |
#endif |
|
3752 |
default: |
|
3753 |
// nothing |
|
3754 |
break; |
|
3755 |
} |
|
3756 |
} else if (qobject_cast<QLineEdit*>(o)) { |
|
3757 |
if (currentItem() && currentItem()->renameBox) { |
|
3758 |
if (e->type() == QEvent::KeyPress) { |
|
3759 |
QKeyEvent *ke = (QKeyEvent*)e; |
|
3760 |
if (ke->key() == Qt::Key_Return || |
|
3761 |
ke->key() == Qt::Key_Enter) { |
|
3762 |
currentItem()->okRename(currentItem()->renameCol); |
|
3763 |
return true; |
|
3764 |
} else if (ke->key() == Qt::Key_Escape) { |
|
3765 |
currentItem()->cancelRename(currentItem()->renameCol); |
|
3766 |
return true; |
|
3767 |
} |
|
3768 |
} else if (e->type() == QEvent::FocusOut) { |
|
3769 |
if (((QFocusEvent*)e)->reason() != Qt::PopupFocusReason) { |
|
3770 |
QCustomEvent *e = new QCustomEvent(9999); |
|
3771 |
QApplication::postEvent(o, e); |
|
3772 |
return true; |
|
3773 |
} |
|
3774 |
} else if (e->type() == 9999) { |
|
3775 |
if (d->defRenameAction == Reject) |
|
3776 |
currentItem()->cancelRename(currentItem()->renameCol); |
|
3777 |
else |
|
3778 |
currentItem()->okRename(currentItem()->renameCol); |
|
3779 |
return true; |
|
3780 |
} |
|
3781 |
} |
|
3782 |
} |
|
3783 |
||
3784 |
return Q3ScrollView::eventFilter(o, e); |
|
3785 |
} |
|
3786 |
||
3787 |
||
3788 |
/*! |
|
3789 |
Returns a pointer to the list view containing this item. |
|
3790 |
||
3791 |
Note that this function traverses the items to the root to find the |
|
3792 |
listview. This function will return 0 for taken items - see |
|
3793 |
Q3ListViewItem::takeItem() |
|
3794 |
*/ |
|
3795 |
||
3796 |
Q3ListView * Q3ListViewItem::listView() const |
|
3797 |
{ |
|
3798 |
const Q3ListViewItem* c = this; |
|
3799 |
while (c && !c->is_root) |
|
3800 |
c = c->parentItem; |
|
3801 |
if (!c) |
|
3802 |
return 0; |
|
3803 |
return ((Q3ListViewPrivate::Root*)c)->theListView(); |
|
3804 |
} |
|
3805 |
||
3806 |
||
3807 |
/*! |
|
3808 |
Returns the depth of this item. |
|
3809 |
*/ |
|
3810 |
int Q3ListViewItem::depth() const |
|
3811 |
{ |
|
3812 |
return parentItem ? parentItem->depth()+1 : -1; // -1 == the hidden root |
|
3813 |
} |
|
3814 |
||
3815 |
||
3816 |
/*! |
|
3817 |
Returns a pointer to the item immediately above this item on the |
|
3818 |
screen. This is usually the item's closest older sibling, but it |
|
3819 |
may also be its parent or its next older sibling's youngest child, |
|
3820 |
or something else if anyoftheabove->height() returns 0. Returns 0 |
|
3821 |
if there is no item immediately above this item. |
|
3822 |
||
3823 |
This function assumes that all parents of this item are open (i.e. |
|
3824 |
that this item is visible, or can be made visible by scrolling). |
|
3825 |
||
3826 |
This function might be relatively slow because of the tree |
|
3827 |
traversions needed to find the correct item. |
|
3828 |
||
3829 |
\sa itemBelow() Q3ListView::itemRect() |
|
3830 |
*/ |
|
3831 |
||
3832 |
Q3ListViewItem * Q3ListViewItem::itemAbove() const |
|
3833 |
{ |
|
3834 |
if (!parentItem) |
|
3835 |
return 0; |
|
3836 |
||
3837 |
Q3ListViewItem * c = parentItem; |
|
3838 |
if (c->childItem != this) { |
|
3839 |
c = c->childItem; |
|
3840 |
while(c && c->siblingItem != this) |
|
3841 |
c = c->siblingItem; |
|
3842 |
if (!c) |
|
3843 |
return 0; |
|
3844 |
while(c->isOpen() && c->childItem) { |
|
3845 |
c = c->childItem; |
|
3846 |
while(c->siblingItem) |
|
3847 |
c = c->siblingItem; // assign c's sibling to c |
|
3848 |
} |
|
3849 |
} |
|
3850 |
if (c && (!c->height() || !c->isEnabled())) |
|
3851 |
return c->itemAbove(); |
|
3852 |
return c; |
|
3853 |
} |
|
3854 |
||
3855 |
||
3856 |
/*! |
|
3857 |
Returns a pointer to the item immediately below this item on the |
|
3858 |
screen. This is usually the item's eldest child, but it may also |
|
3859 |
be its next younger sibling, its parent's next younger sibling, |
|
3860 |
grandparent's, etc., or something else if anyoftheabove->height() |
|
3861 |
returns 0. Returns 0 if there is no item immediately below this |
|
3862 |
item. |
|
3863 |
||
3864 |
This function assumes that all parents of this item are open (i.e. |
|
3865 |
that this item is visible or can be made visible by scrolling). |
|
3866 |
||
3867 |
\sa itemAbove() Q3ListView::itemRect() |
|
3868 |
*/ |
|
3869 |
||
3870 |
Q3ListViewItem * Q3ListViewItem::itemBelow() const |
|
3871 |
{ |
|
3872 |
Q3ListViewItem * c = 0; |
|
3873 |
if (isOpen() && childItem) { |
|
3874 |
c = childItem; |
|
3875 |
} else if (siblingItem) { |
|
3876 |
c = siblingItem; |
|
3877 |
} else if (parentItem) { |
|
3878 |
c = const_cast<Q3ListViewItem*>(this); |
|
3879 |
do { |
|
3880 |
c = c->parentItem; |
|
3881 |
} while(c->parentItem && !c->siblingItem); |
|
3882 |
if (c) |
|
3883 |
c = c->siblingItem; |
|
3884 |
} |
|
3885 |
if (c && (!c->height() || !c->isEnabled())) |
|
3886 |
return c->itemBelow(); |
|
3887 |
return c; |
|
3888 |
} |
|
3889 |
||
3890 |
||
3891 |
/*! |
|
3892 |
\fn bool Q3ListViewItem::isOpen() const |
|
3893 |
||
3894 |
Returns true if this list view item has children \e and they are |
|
3895 |
not explicitly hidden; otherwise returns false. |
|
3896 |
||
3897 |
\sa setOpen() |
|
3898 |
*/ |
|
3899 |
||
3900 |
/*! |
|
3901 |
Returns the first (top) child of this item, or 0 if this item has |
|
3902 |
no children. |
|
3903 |
||
3904 |
Note that the children are not guaranteed to be sorted properly. |
|
3905 |
Q3ListView and Q3ListViewItem try to postpone or avoid sorting to |
|
3906 |
the greatest degree possible, in order to keep the user interface |
|
3907 |
snappy. |
|
3908 |
||
3909 |
\sa nextSibling() sortChildItems() |
|
3910 |
*/ |
|
3911 |
||
3912 |
Q3ListViewItem* Q3ListViewItem::firstChild() const |
|
3913 |
{ |
|
3914 |
enforceSortOrder(); |
|
3915 |
return childItem; |
|
3916 |
} |
|
3917 |
||
3918 |
||
3919 |
/*! |
|
3920 |
Returns the parent of this item, or 0 if this item has no parent. |
|
3921 |
||
3922 |
\sa firstChild(), nextSibling() |
|
3923 |
*/ |
|
3924 |
||
3925 |
Q3ListViewItem* Q3ListViewItem::parent() const |
|
3926 |
{ |
|
3927 |
if (!parentItem || parentItem->is_root) return 0; |
|
3928 |
return parentItem; |
|
3929 |
} |
|
3930 |
||
3931 |
||
3932 |
/*! |
|
3933 |
\fn Q3ListViewItem* Q3ListViewItem::nextSibling() const |
|
3934 |
||
3935 |
Returns the sibling item below this item, or 0 if there is no |
|
3936 |
sibling item after this item. |
|
3937 |
||
3938 |
Note that the siblings are not guaranteed to be sorted properly. |
|
3939 |
Q3ListView and Q3ListViewItem try to postpone or avoid sorting to |
|
3940 |
the greatest degree possible, in order to keep the user interface |
|
3941 |
snappy. |
|
3942 |
||
3943 |
\sa firstChild() sortChildItems() |
|
3944 |
*/ |
|
3945 |
||
3946 |
/*! |
|
3947 |
\fn int Q3ListViewItem::childCount () const |
|
3948 |
||
3949 |
Returns how many children this item has. The count only includes |
|
3950 |
the item's immediate children. |
|
3951 |
*/ |
|
3952 |
||
3953 |
||
3954 |
/*! |
|
3955 |
Returns the height of this item in pixels. This does not include |
|
3956 |
the height of any children; totalHeight() returns that. |
|
3957 |
*/ |
|
3958 |
int Q3ListViewItem::height() const |
|
3959 |
{ |
|
3960 |
Q3ListViewItem * that = (Q3ListViewItem *)this; |
|
3961 |
if (!that->configured) { |
|
3962 |
that->configured = true; |
|
3963 |
that->setup(); // ### virtual non-const function called in const |
|
3964 |
} |
|
3965 |
||
3966 |
return visible ? ownHeight : 0; |
|
3967 |
} |
|
3968 |
||
3969 |
/*! |
|
3970 |
Call this function when the value of width() may have changed for |
|
3971 |
column \a c. Normally, you should call this if text(c) changes. |
|
3972 |
Passing -1 for \a c indicates that all columns may have changed. |
|
3973 |
It is more efficient to pass -1 if two or more columns have |
|
3974 |
changed than to call widthChanged() separately for each one. |
|
3975 |
||
3976 |
\sa width() |
|
3977 |
*/ |
|
3978 |
void Q3ListViewItem::widthChanged(int c) const |
|
3979 |
{ |
|
3980 |
Q3ListView *lv = listView(); |
|
3981 |
if (lv) |
|
3982 |
lv->widthChanged(this, c); |
|
3983 |
} |
|
3984 |
||
3985 |
/*! |
|
3986 |
\fn void Q3ListView::dropped (QDropEvent * e) |
|
3987 |
||
3988 |
This signal is emitted, when a drop event occurred on the |
|
3989 |
viewport (not onto an item). |
|
3990 |
||
3991 |
\a e provides all the information about the drop. |
|
3992 |
*/ |
|
3993 |
||
3994 |
/*! |
|
3995 |
\fn void Q3ListView::selectionChanged() |
|
3996 |
||
3997 |
This signal is emitted whenever the set of selected items has |
|
3998 |
changed (normally before the screen update). It is available both |
|
3999 |
in \c Single selection and \c Multi selection mode but is most |
|
4000 |
useful in \c Multi selection mode. |
|
4001 |
||
4002 |
\warning Do not delete any Q3ListViewItem objects in slots |
|
4003 |
connected to this signal. |
|
4004 |
||
4005 |
\sa setSelected() Q3ListViewItem::setSelected() |
|
4006 |
*/ |
|
4007 |
||
4008 |
||
4009 |
/*! |
|
4010 |
\fn void Q3ListView::pressed(Q3ListViewItem *item) |
|
4011 |
||
4012 |
This signal is emitted whenever the user presses the mouse button |
|
4013 |
in a list view. \a item is the list view item on which the user |
|
4014 |
pressed the mouse button, or 0 if the user didn't press the mouse |
|
4015 |
on an item. |
|
4016 |
||
4017 |
\warning Do not delete any Q3ListViewItem objects in slots |
|
4018 |
connected to this signal. |
|
4019 |
*/ |
|
4020 |
||
4021 |
/*! |
|
4022 |
\fn void Q3ListView::pressed(Q3ListViewItem *item, const QPoint &pnt, int c) |
|
4023 |
||
4024 |
\overload |
|
4025 |
||
4026 |
This signal is emitted whenever the user presses the mouse button |
|
4027 |
in a list view. \a item is the list view item on which the user |
|
4028 |
pressed the mouse button, or 0 if the user didn't press the mouse |
|
4029 |
on an item. \a pnt is the position of the mouse cursor in global |
|
4030 |
coordinates, and \a c is the column where the mouse cursor was |
|
4031 |
when the user pressed the mouse button. |
|
4032 |
||
4033 |
\warning Do not delete any Q3ListViewItem objects in slots |
|
4034 |
connected to this signal. |
|
4035 |
*/ |
|
4036 |
||
4037 |
/*! |
|
4038 |
\fn void Q3ListView::clicked(Q3ListViewItem *item) |
|
4039 |
||
4040 |
This signal is emitted whenever the user clicks (mouse pressed \e |
|
4041 |
and mouse released) in the list view. \a item is the clicked list |
|
4042 |
view item, or 0 if the user didn't click on an item. |
|
4043 |
||
4044 |
\warning Do not delete any Q3ListViewItem objects in slots |
|
4045 |
connected to this signal. |
|
4046 |
*/ |
|
4047 |
||
4048 |
/*! |
|
4049 |
\fn void Q3ListView::mouseButtonClicked(int button, Q3ListViewItem * item, const QPoint & pos, int c) |
|
4050 |
||
4051 |
This signal is emitted whenever the user clicks (mouse pressed \e |
|
4052 |
and mouse released) in the list view at position \a pos. \a button |
|
4053 |
is the mouse button that the user pressed, \a item is the clicked |
|
4054 |
list view item or 0 if the user didn't click on an item. If \a |
|
4055 |
item is not 0, \a c is the list view column into which the user |
|
4056 |
pressed; if \a item is 0 \a{c}'s value is undefined. |
|
4057 |
||
4058 |
\warning Do not delete any Q3ListViewItem objects in slots |
|
4059 |
connected to this signal. |
|
4060 |
*/ |
|
4061 |
||
4062 |
/*! |
|
4063 |
\fn void Q3ListView::mouseButtonPressed(int button, Q3ListViewItem * item, const QPoint & pos, int c) |
|
4064 |
||
4065 |
This signal is emitted whenever the user pressed the mouse button |
|
4066 |
in the list view at position \a pos. \a button is the mouse button |
|
4067 |
which the user pressed, \a item is the pressed list view item or 0 |
|
4068 |
if the user didn't press on an item. If \a item is not 0, \a c is |
|
4069 |
the list view column into which the user pressed; if \a item is 0 |
|
4070 |
\a{c}'s value is undefined. |
|
4071 |
||
4072 |
\warning Do not delete any Q3ListViewItem objects in slots |
|
4073 |
connected to this signal. |
|
4074 |
*/ |
|
4075 |
||
4076 |
/*! |
|
4077 |
\fn void Q3ListView::clicked(Q3ListViewItem *item, const QPoint &pnt, int c) |
|
4078 |
||
4079 |
\overload |
|
4080 |
||
4081 |
This signal is emitted whenever the user clicks (mouse pressed \e |
|
4082 |
and mouse released) in the list view. \a item is the clicked list |
|
4083 |
view item, or 0 if the user didn't click on an item. \a pnt is the |
|
4084 |
position where the user has clicked in global coordinates. If \a |
|
4085 |
item is not 0, \a c is the list view column into which the user |
|
4086 |
pressed; if \a item is 0 \a{c}'s value is undefined. |
|
4087 |
||
4088 |
\warning Do not delete any Q3ListViewItem objects in slots |
|
4089 |
connected to this signal. |
|
4090 |
*/ |
|
4091 |
||
4092 |
/*! |
|
4093 |
\fn void Q3ListView::selectionChanged(Q3ListViewItem *item) |
|
4094 |
||
4095 |
\overload |
|
4096 |
||
4097 |
This signal is emitted whenever the selected item has changed in |
|
4098 |
\c Single selection mode (normally after the screen update). The |
|
4099 |
argument is the newly selected \a item. |
|
4100 |
||
4101 |
In \c Multi selection mode, use the no argument overload of this |
|
4102 |
signal. |
|
4103 |
||
4104 |
\warning Do not delete any Q3ListViewItem objects in slots |
|
4105 |
connected to this signal. |
|
4106 |
||
4107 |
\sa setSelected() Q3ListViewItem::setSelected() currentChanged() |
|
4108 |
*/ |
|
4109 |
||
4110 |
||
4111 |
/*! |
|
4112 |
\fn void Q3ListView::currentChanged(Q3ListViewItem *item) |
|
4113 |
||
4114 |
This signal is emitted whenever the current item has changed |
|
4115 |
(normally after the screen update). The current item is the item |
|
4116 |
responsible for indicating keyboard focus. |
|
4117 |
||
4118 |
The argument is the newly current \a item, or 0 if the change made |
|
4119 |
no item current. This can happen, for example, if all the items in |
|
4120 |
the list view are deleted. |
|
4121 |
||
4122 |
\warning Do not delete any Q3ListViewItem objects in slots |
|
4123 |
connected to this signal. |
|
4124 |
||
4125 |
\sa setCurrentItem() currentItem() |
|
4126 |
*/ |
|
4127 |
||
4128 |
||
4129 |
/*! |
|
4130 |
\fn void Q3ListView::expanded(Q3ListViewItem *item) |
|
4131 |
||
4132 |
This signal is emitted when \a item has been expanded, i.e. when |
|
4133 |
the children of \a item are shown. |
|
4134 |
||
4135 |
\sa setOpen() collapsed() |
|
4136 |
*/ |
|
4137 |
||
4138 |
/*! |
|
4139 |
\fn void Q3ListView::collapsed(Q3ListViewItem *item) |
|
4140 |
||
4141 |
This signal is emitted when the \a item has been collapsed, i.e. |
|
4142 |
when the children of \a item are hidden. |
|
4143 |
||
4144 |
\sa setOpen() expanded() |
|
4145 |
*/ |
|
4146 |
||
4147 |
/*! |
|
4148 |
Processes the mouse press event \a e on behalf of the viewed widget. |
|
4149 |
*/ |
|
4150 |
void Q3ListView::contentsMousePressEvent(QMouseEvent * e) |
|
4151 |
{ |
|
4152 |
contentsMousePressEventEx(e); |
|
4153 |
} |
|
4154 |
||
4155 |
void Q3ListView::contentsMousePressEventEx(QMouseEvent * e) |
|
4156 |
{ |
|
4157 |
if (!e) |
|
4158 |
return; |
|
4159 |
||
4160 |
if (!d->ignoreEditAfterFocus) |
|
4161 |
d->startEdit = true; |
|
4162 |
d->ignoreEditAfterFocus = false; |
|
4163 |
||
4164 |
if (currentItem() && currentItem()->renameBox && |
|
4165 |
!itemRect(currentItem()).contains(e->pos())) { |
|
4166 |
d->startEdit = false; |
|
4167 |
if (d->defRenameAction == Reject) |
|
4168 |
currentItem()->cancelRename(currentItem()->renameCol); |
|
4169 |
else |
|
4170 |
currentItem()->okRename(currentItem()->renameCol); |
|
4171 |
} |
|
4172 |
||
4173 |
d->startDragItem = 0; |
|
4174 |
d->dragStartPos = e->pos(); |
|
4175 |
QPoint vp = contentsToViewport(e->pos()); |
|
4176 |
||
4177 |
d->ignoreDoubleClick = false; |
|
4178 |
d->buttonDown = true; |
|
4179 |
||
4180 |
Q3ListViewItem * i = itemAt(vp); |
|
4181 |
d->pressedEmptyArea = e->y() > contentsHeight(); |
|
4182 |
if (i && !i->isEnabled()) |
|
4183 |
return; |
|
4184 |
if (d->startEdit && (i != currentItem() || (i && !i->isSelected()))) |
|
4185 |
d->startEdit = false; |
|
4186 |
Q3ListViewItem *oldCurrent = currentItem(); |
|
4187 |
||
4188 |
if (e->button() == Qt::RightButton && (e->state() & Qt::ControlButton)) |
|
4189 |
goto emit_signals; |
|
4190 |
||
4191 |
if (!i) { |
|
4192 |
if (!(e->state() & Qt::ControlButton)) |
|
4193 |
clearSelection(); |
|
4194 |
goto emit_signals; |
|
4195 |
} else { |
|
4196 |
// No new anchor when using shift |
|
4197 |
if (!(e->state() & Qt::ShiftButton)) |
|
4198 |
d->selectAnchor = i; |
|
4199 |
} |
|
4200 |
||
4201 |
if ((i->isExpandable() || i->childCount()) && |
|
4202 |
d->h->mapToLogical(d->h->cellAt(vp.x())) == 0) { |
|
4203 |
int x1 = vp.x() + |
|
4204 |
d->h->offset() - |
|
4205 |
d->h->cellPos(d->h->mapToActual(0)); |
|
4206 |
int draw = 0; |
|
4207 |
for (; draw < d->drawables.size(); ++draw) |
|
4208 |
if (d->drawables.at(draw).i == i) |
|
4209 |
break; |
|
4210 |
||
4211 |
if (draw < d->drawables.size()) { |
|
4212 |
Q3ListViewPrivate::DrawableItem it = d->drawables.at(draw); |
|
4213 |
QStyleOptionQ3ListView opt = getStyleOption(this, i); |
|
4214 |
x1 -= treeStepSize() * (it.l - 1); |
|
4215 |
QStyle::SubControl ctrl = style()->hitTestComplexControl(QStyle::CC_Q3ListView, &opt, |
|
4216 |
QPoint(x1, e->pos().y()), this); |
|
4217 |
if (ctrl == QStyle::SC_Q3ListViewExpand && |
|
4218 |
e->type() == style()->styleHint(QStyle::SH_Q3ListViewExpand_SelectMouseType, 0, |
|
4219 |
this)) { |
|
4220 |
d->buttonDown = false; |
|
4221 |
if (e->button() == Qt::LeftButton) { |
|
4222 |
bool close = i->isOpen(); |
|
4223 |
setOpen(i, !close); |
|
4224 |
// ### Looks dangerous, removed because of reentrance problems |
|
4225 |
// qApp->processEvents(); |
|
4226 |
if (!d->focusItem) { |
|
4227 |
d->focusItem = i; |
|
4228 |
repaintItem(d->focusItem); |
|
4229 |
emit currentChanged(d->focusItem); |
|
4230 |
} |
|
4231 |
if (close) { |
|
4232 |
bool newCurrent = false; |
|
4233 |
Q3ListViewItem *ci = d->focusItem; |
|
4234 |
while (ci) { |
|
4235 |
if (ci->parent() && ci->parent() == i) { |
|
4236 |
newCurrent = true; |
|
4237 |
break; |
|
4238 |
} |
|
4239 |
ci = ci->parent(); |
|
4240 |
} |
|
4241 |
if (newCurrent) { |
|
4242 |
setCurrentItem(i); |
|
4243 |
} |
|
4244 |
} |
|
4245 |
} |
|
4246 |
d->ignoreDoubleClick = true; |
|
4247 |
d->buttonDown = false; |
|
4248 |
goto emit_signals; |
|
4249 |
} |
|
4250 |
} |
|
4251 |
} |
|
4252 |
||
4253 |
d->select = d->selectionMode == Multi ? !i->isSelected() : true; |
|
4254 |
||
4255 |
{// calculate activatedP |
|
4256 |
activatedByClick = true; |
|
4257 |
QPoint topLeft = itemRect(i).topLeft(); //### inefficient? |
|
4258 |
activatedP = vp - topLeft; |
|
4259 |
int xdepth = treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) |
|
4260 |
+ itemMargin(); |
|
4261 |
xdepth += d->h->sectionPos(d->h->mapToSection(0)); |
|
4262 |
activatedP.rx() -= xdepth; |
|
4263 |
} |
|
4264 |
i->activate(); |
|
4265 |
activatedByClick = false; |
|
4266 |
||
4267 |
if (i != d->focusItem) |
|
4268 |
setCurrentItem(i); |
|
4269 |
else |
|
4270 |
repaintItem(i); |
|
4271 |
||
4272 |
d->pressedSelected = i && i->isSelected(); |
|
4273 |
||
4274 |
if (i->isSelectable() && selectionMode() != NoSelection) { |
|
4275 |
if (selectionMode() == Single) |
|
4276 |
setSelected(i, true); |
|
4277 |
else if (selectionMode() == Multi) |
|
4278 |
setSelected(i, d->select); |
|
4279 |
else if (selectionMode() == Extended) { |
|
4280 |
bool changed = false; |
|
4281 |
if (!(e->state() & (Qt::ControlButton | Qt::ShiftButton))) { |
|
4282 |
if (!i->isSelected()) { |
|
4283 |
bool blocked = signalsBlocked(); |
|
4284 |
blockSignals(true); |
|
4285 |
clearSelection(); |
|
4286 |
blockSignals(blocked); |
|
4287 |
i->setSelected(true); |
|
4288 |
changed = true; |
|
4289 |
} |
|
4290 |
} else { |
|
4291 |
if (e->state() & Qt::ShiftButton) |
|
4292 |
d->pressedSelected = false; |
|
4293 |
if ((e->state() & Qt::ControlButton) && !(e->state() & Qt::ShiftButton) && i) { |
|
4294 |
i->setSelected(!i->isSelected()); |
|
4295 |
changed = true; |
|
4296 |
d->pressedSelected = false; |
|
4297 |
} else if (!oldCurrent || !i || oldCurrent == i) { |
|
4298 |
if ((bool)i->selected != d->select) { |
|
4299 |
changed = true; |
|
4300 |
i->setSelected(d->select); |
|
4301 |
} |
|
4302 |
// Shift pressed in Extended mode --- |
|
4303 |
} else { |
|
4304 |
changed = selectRange(i, oldCurrent, d->selectAnchor); |
|
4305 |
} |
|
4306 |
} |
|
4307 |
if (changed) { |
|
4308 |
triggerUpdate(); |
|
4309 |
emit selectionChanged(); |
|
4310 |
||
4311 |
#ifndef QT_NO_ACCESSIBILITY |
|
4312 |
QAccessible::updateAccessibility(viewport(), 0, QAccessible::Selection); |
|
4313 |
#endif |
|
4314 |
} |
|
4315 |
} |
|
4316 |
} |
|
4317 |
||
4318 |
emit_signals: |
|
4319 |
||
4320 |
if (i && !d->buttonDown && |
|
4321 |
vp.x() + contentsX() < itemMargin() + (i->depth() + (rootIsDecorated() ? 1 : 0)) * treeStepSize()) |
|
4322 |
i = 0; |
|
4323 |
d->pressedItem = i; |
|
4324 |
||
4325 |
int c = i ? d->h->mapToLogical(d->h->cellAt(vp.x())) : -1; |
|
4326 |
if (!i || (i && i->isEnabled())) { |
|
4327 |
emit pressed(i); |
|
4328 |
emit pressed(i, viewport()->mapToGlobal(vp), c); |
|
4329 |
} |
|
4330 |
emit mouseButtonPressed(e->button(), i, viewport()->mapToGlobal(vp), c); |
|
4331 |
||
4332 |
if (e->button() == Qt::RightButton && i == d->pressedItem) { |
|
4333 |
if (!i && !(e->state() & Qt::ControlButton)) |
|
4334 |
clearSelection(); |
|
4335 |
||
4336 |
emit rightButtonPressed(i, viewport()->mapToGlobal(vp), c); |
|
4337 |
} |
|
4338 |
} |
|
4339 |
||
4340 |
/*! |
|
4341 |
\reimp |
|
4342 |
*/ |
|
4343 |
||
4344 |
void Q3ListView::contentsContextMenuEvent(QContextMenuEvent *e) |
|
4345 |
{ |
|
4346 |
if (!receivers(SIGNAL(contextMenuRequested(Q3ListViewItem*,QPoint,int)))) { |
|
4347 |
e->ignore(); |
|
4348 |
return; |
|
4349 |
} |
|
4350 |
if (e->reason() == QContextMenuEvent::Keyboard) { |
|
4351 |
Q3ListViewItem *item = currentItem(); |
|
4352 |
if (item) { |
|
4353 |
QRect r = itemRect(item); |
|
4354 |
QPoint p = r.topLeft(); |
|
4355 |
if (allColumnsShowFocus()) |
|
4356 |
p += QPoint(width() / 2, (r.height() / 2)); |
|
4357 |
else |
|
4358 |
p += QPoint(columnWidth(0) / 2, (r.height() / 2)); |
|
4359 |
p.rx() = qMax(0, p.x()); |
|
4360 |
p.rx() = qMin(visibleWidth(), p.x()); |
|
4361 |
emit contextMenuRequested(item, viewport()->mapToGlobal(p), -1); |
|
4362 |
} |
|
4363 |
} else { |
|
4364 |
QPoint vp = contentsToViewport(e->pos()); |
|
4365 |
Q3ListViewItem * i = itemAt(vp); |
|
4366 |
int c = i ? d->h->mapToLogical(d->h->cellAt(vp.x())) : -1; |
|
4367 |
emit contextMenuRequested(i, viewport()->mapToGlobal(vp), c); |
|
4368 |
} |
|
4369 |
} |
|
4370 |
||
4371 |
/*! |
|
4372 |
Processes the mouse release event \a e on behalf of the viewed widget. |
|
4373 |
*/ |
|
4374 |
void Q3ListView::contentsMouseReleaseEvent(QMouseEvent * e) |
|
4375 |
{ |
|
4376 |
contentsMouseReleaseEventEx(e); |
|
4377 |
} |
|
4378 |
||
4379 |
void Q3ListView::contentsMouseReleaseEventEx(QMouseEvent * e) |
|
4380 |
{ |
|
4381 |
d->startDragItem = 0; |
|
4382 |
bool emitClicked = !d->pressedItem || d->buttonDown; |
|
4383 |
d->buttonDown = false; |
|
4384 |
// delete and disconnect autoscroll timer, if we have one |
|
4385 |
if (d->scrollTimer) { |
|
4386 |
disconnect(d->scrollTimer, SIGNAL(timeout()), |
|
4387 |
this, SLOT(doAutoScroll())); |
|
4388 |
d->scrollTimer->stop(); |
|
4389 |
delete d->scrollTimer; |
|
4390 |
d->scrollTimer = 0; |
|
4391 |
} |
|
4392 |
||
4393 |
if (!e) |
|
4394 |
return; |
|
4395 |
||
4396 |
if (d->selectionMode == Extended && |
|
4397 |
d->focusItem == d->pressedItem && |
|
4398 |
d->pressedSelected && d->focusItem && |
|
4399 |
e->button() == Qt::LeftButton) { |
|
4400 |
bool block = signalsBlocked(); |
|
4401 |
blockSignals(true); |
|
4402 |
clearSelection(); |
|
4403 |
blockSignals(block); |
|
4404 |
d->focusItem->setSelected(true); |
|
4405 |
emit selectionChanged(); |
|
4406 |
#ifndef QT_NO_ACCESSIBILITY |
|
4407 |
QAccessible::updateAccessibility(viewport(), 0, QAccessible::Selection); |
|
4408 |
#endif |
|
4409 |
} |
|
4410 |
||
4411 |
QPoint vp = contentsToViewport(e->pos()); |
|
4412 |
Q3ListViewItem *i = itemAt(vp); |
|
4413 |
if (i && !i->isEnabled()) |
|
4414 |
return; |
|
4415 |
||
4416 |
if (i && i == d->pressedItem && (i->isExpandable() || i->childCount()) && |
|
4417 |
!d->h->mapToLogical(d->h->cellAt(vp.x())) && e->button() == Qt::LeftButton && |
|
4418 |
e->type() == style()->styleHint(QStyle::SH_Q3ListViewExpand_SelectMouseType, 0, this)) { |
|
4419 |
int draw = 0; |
|
4420 |
for (; draw < d->drawables.size(); ++draw) |
|
4421 |
if (d->drawables.at(draw).i == i) |
|
4422 |
break; |
|
4423 |
if (draw < d->drawables.size()) { |
|
4424 |
int x1 = vp.x() + d->h->offset() - d->h->cellPos(d->h->mapToActual(0)) - |
|
4425 |
(treeStepSize() * (d->drawables.at(draw).l - 1)); |
|
4426 |
QStyleOptionQ3ListView opt = getStyleOption(this, i); |
|
4427 |
QStyle::SubControl ctrl = style()->hitTestComplexControl(QStyle::CC_Q3ListView, &opt, |
|
4428 |
QPoint(x1, e->pos().y()), this); |
|
4429 |
if (ctrl == QStyle::SC_Q3ListViewExpand) { |
|
4430 |
bool close = i->isOpen(); |
|
4431 |
setOpen(i, !close); |
|
4432 |
// ### Looks dangerous, removed because of reentrance problems |
|
4433 |
// qApp->processEvents(); |
|
4434 |
if (!d->focusItem) { |
|
4435 |
d->focusItem = i; |
|
4436 |
repaintItem(d->focusItem); |
|
4437 |
emit currentChanged(d->focusItem); |
|
4438 |
} |
|
4439 |
if (close) { |
|
4440 |
bool newCurrent = false; |
|
4441 |
Q3ListViewItem *ci = d->focusItem; |
|
4442 |
while (ci) { |
|
4443 |
if (ci->parent() && ci->parent() == i) { |
|
4444 |
newCurrent = true; |
|
4445 |
break; |
|
4446 |
} |
|
4447 |
ci = ci->parent(); |
|
4448 |
} |
|
4449 |
if (newCurrent) |
|
4450 |
setCurrentItem(i); |
|
4451 |
d->ignoreDoubleClick = true; |
|
4452 |
} |
|
4453 |
} |
|
4454 |
} |
|
4455 |
} |
|
4456 |
||
4457 |
if (i == d->pressedItem && i && i->isSelected() && e->button() == Qt::LeftButton && d->startEdit) { |
|
4458 |
QRect r = itemRect(currentItem()); |
|
4459 |
r = QRect(viewportToContents(r.topLeft()), r.size()); |
|
4460 |
d->pressedColumn = header()->sectionAt( e->pos().x()); |
|
4461 |
r.setLeft(header()->sectionPos(d->pressedColumn)); |
|
4462 |
r.setWidth(header()->sectionSize(d->pressedColumn) - 1); |
|
4463 |
if (d->pressedColumn == 0) |
|
4464 |
r.setLeft(r.left() + itemMargin() + (currentItem()->depth() + |
|
4465 |
(rootIsDecorated() ? 1 : 0)) * treeStepSize() - 1); |
|
4466 |
if (r.contains(e->pos()) && |
|
4467 |
!(e->state() & (Qt::ShiftButton | Qt::ControlButton))) |
|
4468 |
d->renameTimer->start(QApplication::doubleClickInterval(), true); |
|
4469 |
} |
|
4470 |
if (i && vp.x() + contentsX() < itemMargin() + (i->depth() + (rootIsDecorated() ? 1 : 0)) * treeStepSize()) |
|
4471 |
i = 0; |
|
4472 |
emitClicked = emitClicked && d->pressedItem == i; |
|
4473 |
d->pressedItem = 0; |
|
4474 |
||
4475 |
if (emitClicked) { |
|
4476 |
if (!i || (i && i->isEnabled())) { |
|
4477 |
emit clicked(i); |
|
4478 |
emit clicked(i, viewport()->mapToGlobal(vp), d->h->mapToLogical(d->h->cellAt(vp.x()))); |
|
4479 |
} |
|
4480 |
emit mouseButtonClicked(e->button(), i, viewport()->mapToGlobal(vp), |
|
4481 |
i ? d->h->mapToLogical(d->h->cellAt(vp.x())) : -1); |
|
4482 |
||
4483 |
if (e->button() == Qt::RightButton) { |
|
4484 |
if (!i) { |
|
4485 |
if (!(e->state() & Qt::ControlButton)) |
|
4486 |
clearSelection(); |
|
4487 |
emit rightButtonClicked(0, viewport()->mapToGlobal(vp), -1); |
|
4488 |
return; |
|
4489 |
} |
|
4490 |
||
4491 |
int c = d->h->mapToLogical(d->h->cellAt(vp.x())); |
|
4492 |
emit rightButtonClicked(i, viewport()->mapToGlobal(vp), c); |
|
4493 |
} |
|
4494 |
} |
|
4495 |
} |
|
4496 |
||
4497 |
||
4498 |
/*! |
|
4499 |
Processes the mouse double-click event \a e on behalf of the viewed widget. |
|
4500 |
*/ |
|
4501 |
void Q3ListView::contentsMouseDoubleClickEvent(QMouseEvent * e) |
|
4502 |
{ |
|
4503 |
d->renameTimer->stop(); |
|
4504 |
d->startEdit = false; |
|
4505 |
if (!e || e->button() != Qt::LeftButton) |
|
4506 |
return; |
|
4507 |
||
4508 |
// ensure that the following mouse moves and eventual release is |
|
4509 |
// ignored. |
|
4510 |
d->buttonDown = false; |
|
4511 |
||
4512 |
if (d->ignoreDoubleClick) { |
|
4513 |
d->ignoreDoubleClick = false; |
|
4514 |
return; |
|
4515 |
} |
|
4516 |
||
4517 |
QPoint vp = contentsToViewport(e->pos()); |
|
4518 |
||
4519 |
Q3ListViewItem * i = itemAt(vp); |
|
4520 |
||
4521 |
// we emit doubleClicked when the item is null (or enabled) to be consistent with |
|
4522 |
// rightButtonClicked etc. |
|
4523 |
if (!i || i->isEnabled()) { |
|
4524 |
int c = d->h->mapToLogical(d->h->cellAt(vp.x())); |
|
4525 |
emit doubleClicked(i, viewport()->mapToGlobal(vp), c); |
|
4526 |
} |
|
4527 |
||
4528 |
if (!i || !i->isEnabled()) |
|
4529 |
return; |
|
4530 |
||
4531 |
if (!i->isOpen()) { |
|
4532 |
if (i->isExpandable() || i->childCount()) |
|
4533 |
setOpen(i, true); |
|
4534 |
} else { |
|
4535 |
setOpen(i, false); |
|
4536 |
} |
|
4537 |
||
4538 |
// we emit the 'old' obsolete doubleClicked only if the item is not null and enabled |
|
4539 |
emit doubleClicked(i); |
|
4540 |
} |
|
4541 |
||
4542 |
||
4543 |
/*! |
|
4544 |
Processes the mouse move event \a e on behalf of the viewed widget. |
|
4545 |
*/ |
|
4546 |
void Q3ListView::contentsMouseMoveEvent(QMouseEvent * e) |
|
4547 |
{ |
|
4548 |
if (!e) |
|
4549 |
return; |
|
4550 |
||
4551 |
bool needAutoScroll = false; |
|
4552 |
||
4553 |
QPoint vp = contentsToViewport(e->pos()); |
|
4554 |
||
4555 |
Q3ListViewItem * i = itemAt(vp); |
|
4556 |
if (i && !i->isEnabled()) |
|
4557 |
return; |
|
4558 |
if (i != d->highlighted && |
|
4559 |
!(d->pressedItem && |
|
4560 |
(d->pressedItem->isSelected() || d->selectionMode == NoSelection) && |
|
4561 |
d->pressedItem->dragEnabled())) { |
|
4562 |
||
4563 |
if (i) { |
|
4564 |
emit onItem(i); |
|
4565 |
} else { |
|
4566 |
emit onViewport(); |
|
4567 |
} |
|
4568 |
d->highlighted = i; |
|
4569 |
} |
|
4570 |
||
4571 |
if (d->startDragItem) |
|
4572 |
i = d->startDragItem; |
|
4573 |
||
4574 |
if (!d->buttonDown || |
|
4575 |
((e->state() & Qt::LeftButton) != Qt::LeftButton && |
|
4576 |
(e->state() & Qt::MidButton) != Qt::MidButton && |
|
4577 |
(e->state() & Qt::RightButton) != Qt::RightButton)) |
|
4578 |
return; |
|
4579 |
||
4580 |
if (d->pressedItem && |
|
4581 |
(d->pressedItem->isSelected() || d->selectionMode == NoSelection) && |
|
4582 |
d->pressedItem->dragEnabled()) { |
|
4583 |
||
4584 |
if (!d->startDragItem) { |
|
4585 |
setSelected(d->pressedItem, true); |
|
4586 |
d->startDragItem = d->pressedItem; |
|
4587 |
} |
|
4588 |
if ((d->dragStartPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) { |
|
4589 |
d->buttonDown = false; |
|
4590 |
#ifndef QT_NO_DRAGANDDROP |
|
4591 |
startDrag(); |
|
4592 |
#endif |
|
4593 |
} |
|
4594 |
return; |
|
4595 |
} |
|
4596 |
||
4597 |
// check, if we need to scroll |
|
4598 |
if (vp.y() > visibleHeight() || vp.y() < 0) |
|
4599 |
needAutoScroll = true; |
|
4600 |
||
4601 |
// if we need to scroll and no autoscroll timer is started, |
|
4602 |
// connect the timer |
|
4603 |
if (needAutoScroll && !d->scrollTimer) { |
|
4604 |
d->scrollTimer = new QTimer(this); |
|
4605 |
connect(d->scrollTimer, SIGNAL(timeout()), |
|
4606 |
this, SLOT(doAutoScroll())); |
|
4607 |
d->scrollTimer->start(100, false); |
|
4608 |
// call it once manually |
|
4609 |
doAutoScroll(vp); |
|
4610 |
} |
|
4611 |
||
4612 |
// if we don't need to autoscroll |
|
4613 |
if (!needAutoScroll) { |
|
4614 |
// if there is a autoscroll timer, delete it |
|
4615 |
if (d->scrollTimer) { |
|
4616 |
disconnect(d->scrollTimer, SIGNAL(timeout()), |
|
4617 |
this, SLOT(doAutoScroll())); |
|
4618 |
d->scrollTimer->stop(); |
|
4619 |
delete d->scrollTimer; |
|
4620 |
d->scrollTimer = 0; |
|
4621 |
} |
|
4622 |
// call this to select an item (using the pos from the event) |
|
4623 |
doAutoScroll(vp); |
|
4624 |
} |
|
4625 |
} |
|
4626 |
||
4627 |
||
4628 |
/*! |
|
4629 |
This slot handles auto-scrolling when the mouse button is pressed |
|
4630 |
and the mouse is outside the widget. |
|
4631 |
*/ |
|
4632 |
void Q3ListView::doAutoScroll() |
|
4633 |
{ |
|
4634 |
doAutoScroll(QPoint()); |
|
4635 |
} |
|
4636 |
||
4637 |
/* |
|
4638 |
Handles auto-scrolling when the mouse button is pressed |
|
4639 |
and the mouse is outside the widget. |
|
4640 |
||
4641 |
If cursorPos is (0,0) (isNull == true) it uses the current QCursor::pos, otherwise it uses cursorPos |
|
4642 |
*/ |
|
4643 |
void Q3ListView::doAutoScroll(const QPoint &cursorPos) |
|
4644 |
{ |
|
4645 |
QPoint pos = cursorPos.isNull() ? viewport()->mapFromGlobal(QCursor::pos()) : cursorPos; |
|
4646 |
if (!d->focusItem || (d->pressedEmptyArea && pos.y() > contentsHeight())) |
|
4647 |
return; |
|
4648 |
||
4649 |
bool down = pos.y() > itemRect(d->focusItem).y(); |
|
4650 |
||
4651 |
int g = pos.y() + contentsY(); |
|
4652 |
||
4653 |
if (down && pos.y() > height() ) |
|
4654 |
g = height() + contentsY(); |
|
4655 |
else if (pos.y() < 0) |
|
4656 |
g = contentsY(); |
|
4657 |
||
4658 |
Q3ListViewItem *c = d->focusItem, *old = 0; |
|
4659 |
Q3ListViewItem *oldCurrent = c; |
|
4660 |
if (down) { |
|
4661 |
int y = itemRect(d->focusItem).y() + contentsY(); |
|
4662 |
while(c && y + c->height() <= g) { |
|
4663 |
y += c->height(); |
|
4664 |
old = c; |
|
4665 |
c = c->itemBelow(); |
|
4666 |
} |
|
4667 |
if (!c && old) |
|
4668 |
c = old; |
|
4669 |
} else { |
|
4670 |
int y = itemRect(d->focusItem).y() + contentsY(); |
|
4671 |
while(c && y >= g) { |
|
4672 |
old = c; |
|
4673 |
c = c->itemAbove(); |
|
4674 |
if (c) |
|
4675 |
y -= c->height(); |
|
4676 |
} |
|
4677 |
if (!c && old) |
|
4678 |
c = old; |
|
4679 |
} |
|
4680 |
||
4681 |
if (!c || c == d->focusItem) |
|
4682 |
return; |
|
4683 |
||
4684 |
if (d->focusItem) { |
|
4685 |
if (d->selectionMode == Multi) { |
|
4686 |
// also (de)select the ones in between |
|
4687 |
Q3ListViewItem * b = d->focusItem; |
|
4688 |
bool down = (itemPos(c) > itemPos(b)); |
|
4689 |
while(b && b != c) { |
|
4690 |
if (b->isSelectable()) |
|
4691 |
setSelected(b, d->select); |
|
4692 |
b = down ? b->itemBelow() : b->itemAbove(); |
|
4693 |
} |
|
4694 |
if (c->isSelectable()) |
|
4695 |
setSelected(c, d->select); |
|
4696 |
} else if (d->selectionMode == Extended) { |
|
4697 |
if (selectRange(c, oldCurrent, d->selectAnchor)) { |
|
4698 |
triggerUpdate(); |
|
4699 |
emit selectionChanged(); |
|
4700 |
} |
|
4701 |
} |
|
4702 |
} |
|
4703 |
||
4704 |
setCurrentItem(c); |
|
4705 |
d->visibleTimer->start(1, true); |
|
4706 |
} |
|
4707 |
||
4708 |
/*! |
|
4709 |
\reimp |
|
4710 |
*/ |
|
4711 |
||
4712 |
void Q3ListView::focusInEvent(QFocusEvent *e) |
|
4713 |
{ |
|
4714 |
d->inMenuMode = false; |
|
4715 |
if (d->focusItem) { |
|
4716 |
repaintItem(d->focusItem); |
|
4717 |
} else if (firstChild() && e->reason() != Qt::MouseFocusReason) { |
|
4718 |
d->focusItem = firstChild(); |
|
4719 |
emit currentChanged(d->focusItem); |
|
4720 |
repaintItem(d->focusItem); |
|
4721 |
} |
|
4722 |
if (e->reason() == Qt::MouseFocusReason) { |
|
4723 |
d->ignoreEditAfterFocus = true; |
|
4724 |
d->startEdit = false; |
|
4725 |
} |
|
4726 |
if (style()->styleHint(QStyle::SH_ItemView_ChangeHighlightOnFocus, 0, this)) { |
|
4727 |
viewport()->repaint(); |
|
4728 |
} |
|
4729 |
} |
|
4730 |
||
4731 |
/*! |
|
4732 |
\reimp |
|
4733 |
*/ |
|
4734 |
QVariant Q3ListView::inputMethodQuery(Qt::InputMethodQuery query) const |
|
4735 |
{ |
|
4736 |
if (query == Qt::ImMicroFocus) { |
|
4737 |
QRect mfrect = itemRect(d->focusItem); |
|
4738 |
if (mfrect.isValid() && header() && header()->isVisible()) |
|
4739 |
mfrect.moveBy(0, header()->height()); |
|
4740 |
return mfrect; |
|
4741 |
} |
|
4742 |
return QWidget::inputMethodQuery(query); |
|
4743 |
} |
|
4744 |
||
4745 |
/*! |
|
4746 |
\reimp |
|
4747 |
*/ |
|
4748 |
||
4749 |
void Q3ListView::focusOutEvent(QFocusEvent *e) |
|
4750 |
{ |
|
4751 |
if (e->reason() == Qt::PopupFocusReason && d->buttonDown) |
|
4752 |
d->buttonDown = false; |
|
4753 |
if (style()->styleHint(QStyle::SH_ItemView_ChangeHighlightOnFocus, 0, this)) { |
|
4754 |
d->inMenuMode = |
|
4755 |
e->reason() == Qt::PopupFocusReason |
|
4756 |
|| (qApp->focusWidget() && qApp->focusWidget()->inherits("QMenuBar")); |
|
4757 |
if (!d->inMenuMode) { |
|
4758 |
viewport()->repaint(); |
|
4759 |
} |
|
4760 |
} |
|
4761 |
||
4762 |
if (d->focusItem) |
|
4763 |
repaintItem(d->focusItem); |
|
4764 |
} |
|
4765 |
||
4766 |
||
4767 |
/*! |
|
4768 |
\reimp |
|
4769 |
*/ |
|
4770 |
||
4771 |
void Q3ListView::keyPressEvent(QKeyEvent * e) |
|
4772 |
{ |
|
4773 |
if (currentItem() && currentItem()->renameBox) |
|
4774 |
return; |
|
4775 |
if (!firstChild()) { |
|
4776 |
e->ignore(); |
|
4777 |
return; // subclass bug |
|
4778 |
} |
|
4779 |
||
4780 |
Q3ListViewItem* oldCurrent = currentItem(); |
|
4781 |
if (!oldCurrent) { |
|
4782 |
setCurrentItem(firstChild()); |
|
4783 |
if (d->selectionMode == Single) |
|
4784 |
setSelected(firstChild(), true); |
|
4785 |
return; |
|
4786 |
} |
|
4787 |
||
4788 |
Q3ListViewItem * i = currentItem(); |
|
4789 |
Q3ListViewItem *old = i; |
|
4790 |
||
4791 |
QRect r(itemRect(i)); |
|
4792 |
Q3ListViewItem * i2; |
|
4793 |
||
4794 |
bool singleStep = false; |
|
4795 |
bool selectCurrent = true; |
|
4796 |
bool wasNavigation = true; |
|
4797 |
||
4798 |
switch(e->key()) { |
|
4799 |
case Qt::Key_Backspace: |
|
4800 |
case Qt::Key_Delete: |
|
4801 |
d->currentPrefix.truncate(0); |
|
4802 |
break; |
|
4803 |
case Qt::Key_Enter: |
|
4804 |
case Qt::Key_Return: |
|
4805 |
d->currentPrefix.truncate(0); |
|
4806 |
if (i && !i->isSelectable() && i->isEnabled() && |
|
4807 |
(i->childCount() || i->isExpandable() || i->isOpen())) { |
|
4808 |
i->setOpen(!i->isOpen()); |
|
4809 |
return; |
|
4810 |
} |
|
4811 |
e->ignore(); |
|
4812 |
if (currentItem() && !currentItem()->isEnabled()) |
|
4813 |
break; |
|
4814 |
emit returnPressed(currentItem()); |
|
4815 |
// do NOT accept. QDialog. |
|
4816 |
return; |
|
4817 |
case Qt::Key_Down: |
|
4818 |
selectCurrent = false; |
|
4819 |
i = i->itemBelow(); |
|
4820 |
d->currentPrefix.truncate(0); |
|
4821 |
singleStep = true; |
|
4822 |
break; |
|
4823 |
case Qt::Key_Up: |
|
4824 |
selectCurrent = false; |
|
4825 |
i = i->itemAbove(); |
|
4826 |
d->currentPrefix.truncate(0); |
|
4827 |
singleStep = true; |
|
4828 |
break; |
|
4829 |
case Qt::Key_Home: |
|
4830 |
selectCurrent = false; |
|
4831 |
i = firstChild(); |
|
4832 |
if (!i->height() || !i->isEnabled()) |
|
4833 |
i = i->itemBelow(); |
|
4834 |
d->currentPrefix.truncate(0); |
|
4835 |
break; |
|
4836 |
case Qt::Key_End: |
|
4837 |
selectCurrent = false; |
|
4838 |
i = firstChild(); |
|
4839 |
while (i->nextSibling() && i->nextSibling()->height() && i->nextSibling()->isEnabled()) |
|
4840 |
i = i->nextSibling(); |
|
4841 |
while (i->itemBelow()) |
|
4842 |
i = i->itemBelow(); |
|
4843 |
d->currentPrefix.truncate(0); |
|
4844 |
break; |
|
4845 |
case Qt::Key_Next: |
|
4846 |
selectCurrent = false; |
|
4847 |
i2 = itemAt(QPoint(0, visibleHeight()-1)); |
|
4848 |
if (i2 == i || !r.isValid() || |
|
4849 |
visibleHeight() <= itemRect(i).bottom()) { |
|
4850 |
if (i2) |
|
4851 |
i = i2; |
|
4852 |
int left = visibleHeight(); |
|
4853 |
while((i2 = i->itemBelow()) != 0 && left > i2->height()) { |
|
4854 |
left -= i2->height(); |
|
4855 |
i = i2; |
|
4856 |
} |
|
4857 |
} else { |
|
4858 |
if (!i2) { |
|
4859 |
// list is shorter than the view, goto last item |
|
4860 |
while((i2 = i->itemBelow()) != 0) |
|
4861 |
i = i2; |
|
4862 |
} else { |
|
4863 |
i = i2; |
|
4864 |
} |
|
4865 |
} |
|
4866 |
d->currentPrefix.truncate(0); |
|
4867 |
break; |
|
4868 |
case Qt::Key_Prior: |
|
4869 |
selectCurrent = false; |
|
4870 |
i2 = itemAt(QPoint(0, 0)); |
|
4871 |
if (i == i2 || !r.isValid() || r.top() <= 0) { |
|
4872 |
if (i2) |
|
4873 |
i = i2; |
|
4874 |
int left = visibleHeight(); |
|
4875 |
while((i2 = i->itemAbove()) != 0 && left > i2->height()) { |
|
4876 |
left -= i2->height(); |
|
4877 |
i = i2; |
|
4878 |
} |
|
4879 |
} else { |
|
4880 |
i = i2; |
|
4881 |
} |
|
4882 |
d->currentPrefix.truncate(0); |
|
4883 |
break; |
|
4884 |
case Qt::Key_Plus: |
|
4885 |
d->currentPrefix.truncate(0); |
|
4886 |
if ( !i->isOpen() && (i->isExpandable() || i->childCount())) |
|
4887 |
setOpen(i, true); |
|
4888 |
else |
|
4889 |
return; |
|
4890 |
break; |
|
4891 |
case Qt::Key_Right: |
|
4892 |
d->currentPrefix.truncate(0); |
|
4893 |
if (i->isOpen() && i->childItem) { |
|
4894 |
i = i->childItem; |
|
4895 |
} else if (!i->isOpen() && (i->isExpandable() || i->childCount())) { |
|
4896 |
setOpen(i, true); |
|
4897 |
} else if (contentsX() + visibleWidth() < contentsWidth()) { |
|
4898 |
horizontalScrollBar()->triggerAction(QScrollBar::SliderSingleStepAdd); |
|
4899 |
return; |
|
4900 |
} else { |
|
4901 |
return; |
|
4902 |
} |
|
4903 |
break; |
|
4904 |
case Qt::Key_Minus: |
|
4905 |
d->currentPrefix.truncate(0); |
|
4906 |
if (i->isOpen()) |
|
4907 |
setOpen(i, false); |
|
4908 |
else |
|
4909 |
return; |
|
4910 |
break; |
|
4911 |
case Qt::Key_Left: |
|
4912 |
d->currentPrefix.truncate(0); |
|
4913 |
if (i->isOpen()) { |
|
4914 |
setOpen(i, false); |
|
4915 |
} else if (i->parentItem && i->parentItem != d->r) { |
|
4916 |
i = i->parentItem; |
|
4917 |
} else if (contentsX()) { |
|
4918 |
horizontalScrollBar()->triggerAction(QScrollBar::SliderSingleStepSub); |
|
4919 |
return; |
|
4920 |
} else { |
|
4921 |
return; |
|
4922 |
} |
|
4923 |
break; |
|
4924 |
case Qt::Key_Space: |
|
4925 |
activatedByClick = false; |
|
4926 |
d->currentPrefix.truncate(0); |
|
4927 |
if (currentItem() && !currentItem()->isEnabled()) |
|
4928 |
break; |
|
4929 |
i->activate(); |
|
4930 |
if (i->isSelectable() && (d->selectionMode == Multi || d->selectionMode == Extended)) { |
|
4931 |
setSelected(i, !i->isSelected()); |
|
4932 |
d->currentPrefix.truncate(0); |
|
4933 |
} |
|
4934 |
emit spacePressed(currentItem()); |
|
4935 |
break; |
|
4936 |
case Qt::Key_Escape: |
|
4937 |
e->ignore(); // For QDialog |
|
4938 |
return; |
|
4939 |
case Qt::Key_F2: |
|
4940 |
if (currentItem() && currentItem()->renameEnabled(0)) |
|
4941 |
currentItem()->startRename(0); |
|
4942 |
default: |
|
4943 |
if (e->text().length() > 0 && e->text()[0].isPrint()) { |
|
4944 |
selectCurrent = false; |
|
4945 |
wasNavigation = false; |
|
4946 |
QString input(d->currentPrefix); |
|
4947 |
Q3ListViewItem * keyItem = i; |
|
4948 |
QTime now(QTime::currentTime()); |
|
4949 |
bool tryFirst = true; |
|
4950 |
while(keyItem) { |
|
4951 |
// try twice, first with the previous string and this char |
|
4952 |
if (d->currentPrefixTime.msecsTo(now) <= 400) |
|
4953 |
input = input + e->text().toLower(); |
|
4954 |
else |
|
4955 |
input = e->text().toLower(); |
|
4956 |
if (input.length() == e->text().length()) { |
|
4957 |
if (keyItem->itemBelow()) { |
|
4958 |
keyItem = keyItem->itemBelow(); |
|
4959 |
tryFirst = true; |
|
4960 |
} else { |
|
4961 |
keyItem = firstChild(); |
|
4962 |
tryFirst = false; |
|
4963 |
} |
|
4964 |
} |
|
4965 |
QString keyItemKey; |
|
4966 |
QString prefix; |
|
4967 |
while(keyItem) { |
|
4968 |
keyItemKey = QString::null; |
|
4969 |
// Look first in the sort column, then left to right |
|
4970 |
if (d->sortcolumn != Unsorted) |
|
4971 |
keyItemKey = keyItem->text(d->sortcolumn); |
|
4972 |
for (int col = 0; col < d->h->count() && keyItemKey.isNull(); ++col) |
|
4973 |
keyItemKey = keyItem->text(d->h->mapToSection(col)); |
|
4974 |
if (!keyItemKey.isEmpty()) { |
|
4975 |
prefix = keyItemKey; |
|
4976 |
prefix.truncate(input.length()); |
|
4977 |
prefix = prefix.toLower(); |
|
4978 |
if (prefix == input) { |
|
4979 |
d->currentPrefix = input; |
|
4980 |
d->currentPrefixTime = now; |
|
4981 |
i = keyItem; |
|
4982 |
// nonoptimal double-break... |
|
4983 |
keyItem = 0; |
|
4984 |
input.truncate(0); |
|
4985 |
tryFirst = false; |
|
4986 |
} |
|
4987 |
} |
|
4988 |
if (keyItem) |
|
4989 |
keyItem = keyItem->itemBelow(); |
|
4990 |
if (!keyItem && tryFirst) { |
|
4991 |
keyItem = firstChild(); |
|
4992 |
tryFirst = false; |
|
4993 |
} |
|
4994 |
} |
|
4995 |
// then, if appropriate, with just this character |
|
4996 |
if (input.length() > e->text().length()) { |
|
4997 |
input.truncate(0); |
|
4998 |
keyItem = i; |
|
4999 |
} |
|
5000 |
} |
|
5001 |
} else { |
|
5002 |
d->currentPrefix.truncate(0); |
|
5003 |
if (e->state() & Qt::ControlButton) { |
|
5004 |
d->currentPrefix.clear(); |
|
5005 |
switch (e->key()) { |
|
5006 |
case Qt::Key_A: |
|
5007 |
selectAll(true); |
|
5008 |
break; |
|
5009 |
} |
|
5010 |
} |
|
5011 |
e->ignore(); |
|
5012 |
return; |
|
5013 |
} |
|
5014 |
} |
|
5015 |
||
5016 |
if (!i) |
|
5017 |
return; |
|
5018 |
||
5019 |
if (!(e->state() & Qt::ShiftButton) || !d->selectAnchor) |
|
5020 |
d->selectAnchor = i; |
|
5021 |
||
5022 |
setCurrentItem(i); |
|
5023 |
if (i->isSelectable()) |
|
5024 |
handleItemChange(old, wasNavigation && (e->state() & Qt::ShiftButton), |
|
5025 |
wasNavigation && (e->state() & Qt::ControlButton)); |
|
5026 |
||
5027 |
if (d->focusItem && !d->focusItem->isSelected() && d->selectionMode == Single && selectCurrent) |
|
5028 |
setSelected(d->focusItem, true); |
|
5029 |
||
5030 |
if (singleStep) |
|
5031 |
d->visibleTimer->start(1, true); |
|
5032 |
else |
|
5033 |
ensureItemVisible(i); |
|
5034 |
} |
|
5035 |
||
5036 |
||
5037 |
/*! |
|
5038 |
Returns the list view item at \a viewPos. Note that \a viewPos is |
|
5039 |
in the viewport()'s coordinate system, not in the list view's own, |
|
5040 |
much larger, coordinate system. |
|
5041 |
||
5042 |
itemAt() returns 0 if there is no such item. |
|
5043 |
||
5044 |
Note that you also get the pointer to the item if \a viewPos |
|
5045 |
points to the root decoration (see setRootIsDecorated()) of the |
|
5046 |
item. To check whether or not \a viewPos is on the root decoration |
|
5047 |
of the item, you can do something like this: |
|
5048 |
||
5049 |
\snippet doc/src/snippets/code/src_qt3support_itemviews_q3listview.cpp 4 |
|
5050 |
||
5051 |
This might be interesting if you use this function to find out |
|
5052 |
where the user clicked and if you want to start a drag (which you |
|
5053 |
do not want to do if the user clicked onto the root decoration of |
|
5054 |
an item). |
|
5055 |
||
5056 |
\sa itemPos() itemRect() viewportToContents() |
|
5057 |
*/ |
|
5058 |
||
5059 |
Q3ListViewItem * Q3ListView::itemAt(const QPoint & viewPos) const |
|
5060 |
{ |
|
5061 |
if (viewPos.x() > contentsWidth() - contentsX()) |
|
5062 |
return 0; |
|
5063 |
||
5064 |
if (d->drawables.isEmpty()) |
|
5065 |
buildDrawableList(); |
|
5066 |
||
5067 |
int g = viewPos.y() + contentsY(); |
|
5068 |
||
5069 |
for (int i = 0; i < d->drawables.size(); ++i) { |
|
5070 |
Q3ListViewPrivate::DrawableItem c = d->drawables.at(i); |
|
5071 |
if (c.y + c.i->height() > g |
|
5072 |
&& c.i->isVisible() && (!c.i->parent() || c.i->parent()->isVisible())) |
|
5073 |
return c.y <= g ? c.i : 0; |
|
5074 |
} |
|
5075 |
return 0; |
|
5076 |
} |
|
5077 |
||
5078 |
||
5079 |
/*! |
|
5080 |
Returns the y-coordinate of \a item in the list view's coordinate |
|
5081 |
system. This function is normally much slower than itemAt() but it |
|
5082 |
works for all items, whereas itemAt() normally works only for |
|
5083 |
items on the screen. |
|
5084 |
||
5085 |
This is a thin wrapper around Q3ListViewItem::itemPos(). |
|
5086 |
||
5087 |
\sa itemAt() itemRect() |
|
5088 |
*/ |
|
5089 |
||
5090 |
int Q3ListView::itemPos(const Q3ListViewItem * item) |
|
5091 |
{ |
|
5092 |
return item ? item->itemPos() : 0; |
|
5093 |
} |
|
5094 |
||
5095 |
||
5096 |
/*! |
|
5097 |
\property Q3ListView::multiSelection |
|
5098 |
\brief whether the list view is in multi-selection or extended-selection mode |
|
5099 |
||
5100 |
If you enable multi-selection, \c Multi, mode, it is possible to |
|
5101 |
specify whether or not this mode should be extended. \c Extended |
|
5102 |
means that the user can select multiple items only when pressing |
|
5103 |
the Shift or Ctrl key at the same time. |
|
5104 |
||
5105 |
The default selection mode is \c Single. |
|
5106 |
||
5107 |
\sa selectionMode() |
|
5108 |
*/ |
|
5109 |
||
5110 |
void Q3ListView::setMultiSelection(bool enable) |
|
5111 |
{ |
|
5112 |
if (!enable) |
|
5113 |
d->selectionMode = Q3ListView::Single; |
|
5114 |
else if ( d->selectionMode != Multi && d->selectionMode != Extended) |
|
5115 |
d->selectionMode = Q3ListView::Multi; |
|
5116 |
} |
|
5117 |
||
5118 |
bool Q3ListView::isMultiSelection() const |
|
5119 |
{ |
|
5120 |
return d->selectionMode == Q3ListView::Extended || d->selectionMode == Q3ListView::Multi; |
|
5121 |
} |
|
5122 |
||
5123 |
/*! |
|
5124 |
\property Q3ListView::selectionMode |
|
5125 |
\brief the list view's selection mode |
|
5126 |
||
5127 |
The mode can be \c Single (the default), \c Extended, \c Multi or |
|
5128 |
\c NoSelection. |
|
5129 |
||
5130 |
\sa multiSelection |
|
5131 |
*/ |
|
5132 |
||
5133 |
void Q3ListView::setSelectionMode(SelectionMode mode) |
|
5134 |
{ |
|
5135 |
if (d->selectionMode == mode) |
|
5136 |
return; |
|
5137 |
||
5138 |
if ((d->selectionMode == Multi || d->selectionMode == Extended) && |
|
5139 |
(mode == Q3ListView::Single || mode == Q3ListView::NoSelection)){ |
|
5140 |
clearSelection(); |
|
5141 |
if ((mode == Q3ListView::Single) && currentItem()) |
|
5142 |
currentItem()->selected = true; |
|
5143 |
} |
|
5144 |
||
5145 |
d->selectionMode = mode; |
|
5146 |
} |
|
5147 |
||
5148 |
Q3ListView::SelectionMode Q3ListView::selectionMode() const |
|
5149 |
{ |
|
5150 |
return d->selectionMode; |
|
5151 |
} |
|
5152 |
||
5153 |
||
5154 |
/*! |
|
5155 |
If \a selected is true the \a item is selected; otherwise it is |
|
5156 |
unselected. |
|
5157 |
||
5158 |
If the list view is in \c Single selection mode and \a selected is |
|
5159 |
true, the currently selected item is unselected and \a item is |
|
5160 |
made current. Unlike Q3ListViewItem::setSelected(), this function |
|
5161 |
updates the list view as necessary and emits the |
|
5162 |
selectionChanged() signals. |
|
5163 |
||
5164 |
\sa isSelected() setMultiSelection() isMultiSelection() |
|
5165 |
setCurrentItem(), setSelectionAnchor() |
|
5166 |
*/ |
|
5167 |
||
5168 |
void Q3ListView::setSelected(Q3ListViewItem * item, bool selected) |
|
5169 |
{ |
|
5170 |
if (!item || item->isSelected() == selected || |
|
5171 |
!item->isSelectable() || selectionMode() == NoSelection) |
|
5172 |
return; |
|
5173 |
||
5174 |
bool emitHighlighted = false; |
|
5175 |
if (selectionMode() == Single && d->focusItem != item) { |
|
5176 |
Q3ListViewItem *o = d->focusItem; |
|
5177 |
if (d->focusItem && d->focusItem->selected) |
|
5178 |
d->focusItem->setSelected(false); |
|
5179 |
d->focusItem = item; |
|
5180 |
if (o) |
|
5181 |
repaintItem(o); |
|
5182 |
emitHighlighted = true; |
|
5183 |
} |
|
5184 |
||
5185 |
item->setSelected(selected); |
|
5186 |
||
5187 |
repaintItem(item); |
|
5188 |
||
5189 |
if (d->selectionMode == Single && selected) |
|
5190 |
emit selectionChanged(item); |
|
5191 |
emit selectionChanged(); |
|
5192 |
||
5193 |
if (emitHighlighted) |
|
5194 |
emit currentChanged(d->focusItem); |
|
5195 |
} |
|
5196 |
||
5197 |
/*! |
|
5198 |
Sets the selection anchor to \a item, if \a item is selectable. |
|
5199 |
||
5200 |
The selection anchor is the item that remains selected when |
|
5201 |
Shift-selecting with either mouse or keyboard in \c Extended |
|
5202 |
selection mode. |
|
5203 |
||
5204 |
\sa setSelected() |
|
5205 |
*/ |
|
5206 |
||
5207 |
void Q3ListView::setSelectionAnchor(Q3ListViewItem *item) |
|
5208 |
{ |
|
5209 |
if (item && item->isSelectable()) |
|
5210 |
d->selectAnchor = item; |
|
5211 |
} |
|
5212 |
||
5213 |
/*! |
|
5214 |
Sets all the items to be not selected, updates the list view as |
|
5215 |
necessary, and emits the selectionChanged() signals. Note that for |
|
5216 |
\c Multi selection list views this function needs to iterate over |
|
5217 |
\e all items. |
|
5218 |
||
5219 |
\sa setSelected(), setMultiSelection() |
|
5220 |
*/ |
|
5221 |
||
5222 |
void Q3ListView::clearSelection() |
|
5223 |
{ |
|
5224 |
selectAll(false); |
|
5225 |
} |
|
5226 |
||
5227 |
/*! |
|
5228 |
If \a select is true, all the items get selected; otherwise all |
|
5229 |
the items get unselected. This only works in the selection modes \c |
|
5230 |
Multi and \c Extended. In \c Single and \c NoSelection mode the |
|
5231 |
selection of the current item is just set to \a select. |
|
5232 |
*/ |
|
5233 |
||
5234 |
void Q3ListView::selectAll(bool select) |
|
5235 |
{ |
|
5236 |
if (d->selectionMode == Multi || d->selectionMode == Extended) { |
|
5237 |
bool b = signalsBlocked(); |
|
5238 |
blockSignals(true); |
|
5239 |
bool anything = false; |
|
5240 |
Q3ListViewItemIterator it(this); |
|
5241 |
while (it.current()) { |
|
5242 |
Q3ListViewItem *i = it.current(); |
|
5243 |
if ((bool)i->selected != select) { |
|
5244 |
i->setSelected(select); |
|
5245 |
anything = true; |
|
5246 |
} |
|
5247 |
++it; |
|
5248 |
} |
|
5249 |
blockSignals(b); |
|
5250 |
if (anything) { |
|
5251 |
emit selectionChanged(); |
|
5252 |
triggerUpdate(); |
|
5253 |
} |
|
5254 |
} else if (d->focusItem) { |
|
5255 |
Q3ListViewItem * i = d->focusItem; |
|
5256 |
setSelected(i, select); |
|
5257 |
} |
|
5258 |
} |
|
5259 |
||
5260 |
/*! |
|
5261 |
Inverts the selection. Only works in \c Multi and \c Extended |
|
5262 |
selection modes. |
|
5263 |
*/ |
|
5264 |
||
5265 |
void Q3ListView::invertSelection() |
|
5266 |
{ |
|
5267 |
if (d->selectionMode == Single || |
|
5268 |
d->selectionMode == NoSelection) |
|
5269 |
return; |
|
5270 |
||
5271 |
bool b = signalsBlocked(); |
|
5272 |
blockSignals(true); |
|
5273 |
Q3ListViewItemIterator it(this); |
|
5274 |
for (; it.current(); ++it) |
|
5275 |
it.current()->setSelected(!it.current()->isSelected()); |
|
5276 |
blockSignals(b); |
|
5277 |
emit selectionChanged(); |
|
5278 |
triggerUpdate(); |
|
5279 |
} |
|
5280 |
||
5281 |
||
5282 |
/*! |
|
5283 |
Returns true if the list view item \a i is selected; otherwise |
|
5284 |
returns false. |
|
5285 |
||
5286 |
\sa Q3ListViewItem::isSelected() |
|
5287 |
*/ |
|
5288 |
||
5289 |
bool Q3ListView::isSelected(const Q3ListViewItem * i) const |
|
5290 |
{ |
|
5291 |
return i ? i->isSelected() : false; |
|
5292 |
} |
|
5293 |
||
5294 |
||
5295 |
/*! |
|
5296 |
Returns the selected item if the list view is in \c Single |
|
5297 |
selection mode and an item is selected. |
|
5298 |
||
5299 |
If no items are selected or the list view is not in \c Single |
|
5300 |
selection mode this function returns 0. |
|
5301 |
||
5302 |
\sa setSelected() setMultiSelection() |
|
5303 |
*/ |
|
5304 |
||
5305 |
Q3ListViewItem * Q3ListView::selectedItem() const |
|
5306 |
{ |
|
5307 |
if (d->selectionMode != Single) |
|
5308 |
return 0; |
|
5309 |
if (d->focusItem && d->focusItem->isSelected()) |
|
5310 |
return d->focusItem; |
|
5311 |
return 0; |
|
5312 |
} |
|
5313 |
||
5314 |
||
5315 |
/*! |
|
5316 |
Sets item \a i to be the current item and repaints appropriately |
|
5317 |
(i.e. highlights the item). The current item is used for keyboard |
|
5318 |
navigation and focus indication; it is independent of any selected |
|
5319 |
items, although a selected item can also be the current item. |
|
5320 |
||
5321 |
\sa currentItem() setSelected() |
|
5322 |
*/ |
|
5323 |
||
5324 |
void Q3ListView::setCurrentItem(Q3ListViewItem * i) |
|
5325 |
{ |
|
5326 |
if (!i || d->focusItem == i || !i->isEnabled()) |
|
5327 |
return; |
|
5328 |
||
5329 |
if (currentItem() && currentItem()->renameBox) { |
|
5330 |
if (d->defRenameAction == Reject) |
|
5331 |
currentItem()->cancelRename(currentItem()->renameCol); |
|
5332 |
else |
|
5333 |
currentItem()->okRename(currentItem()->renameCol); |
|
5334 |
} |
|
5335 |
||
5336 |
Q3ListViewItem * prev = d->focusItem; |
|
5337 |
d->focusItem = i; |
|
5338 |
||
5339 |
if (i != prev) { |
|
5340 |
if (i && d->selectionMode == Single) { |
|
5341 |
bool changed = false; |
|
5342 |
if (prev && prev->selected) { |
|
5343 |
changed = true; |
|
5344 |
prev->setSelected(false); |
|
5345 |
} |
|
5346 |
if (i && !i->selected && d->selectionMode != NoSelection && i->isSelectable()) { |
|
5347 |
i->setSelected(true); |
|
5348 |
changed = true; |
|
5349 |
emit selectionChanged(i); |
|
5350 |
} |
|
5351 |
if (changed) |
|
5352 |
emit selectionChanged(); |
|
5353 |
} |
|
5354 |
||
5355 |
if (i) |
|
5356 |
repaintItem(i); |
|
5357 |
if (prev) |
|
5358 |
repaintItem(prev); |
|
5359 |
emit currentChanged(i); |
|
5360 |
||
5361 |
#ifndef QT_NO_ACCESSIBILITY |
|
5362 |
QAccessible::updateAccessibility(viewport(), indexOfItem(i), QAccessible::Focus); |
|
5363 |
#endif |
|
5364 |
} |
|
5365 |
} |
|
5366 |
||
5367 |
||
5368 |
/*! |
|
5369 |
Returns the current item, or 0 if there isn't one. |
|
5370 |
||
5371 |
\sa setCurrentItem() |
|
5372 |
*/ |
|
5373 |
||
5374 |
Q3ListViewItem * Q3ListView::currentItem() const |
|
5375 |
{ |
|
5376 |
return d->focusItem; |
|
5377 |
} |
|
5378 |
||
5379 |
||
5380 |
/*! |
|
5381 |
Returns the rectangle on the screen that item \a item occupies in |
|
5382 |
viewport()'s coordinates, or an invalid rectangle if \a item is 0 or |
|
5383 |
is not currently visible. |
|
5384 |
||
5385 |
The rectangle returned does not include any children of the |
|
5386 |
rectangle (i.e. it uses Q3ListViewItem::height(), rather than |
|
5387 |
Q3ListViewItem::totalHeight()). If you want the rectangle to |
|
5388 |
include children you can use something like this: |
|
5389 |
||
5390 |
\snippet doc/src/snippets/code/src_qt3support_itemviews_q3listview.cpp 5 |
|
5391 |
||
5392 |
Note the way it avoids too-high rectangles. totalHeight() can be |
|
5393 |
much larger than the window system's coordinate system allows. |
|
5394 |
||
5395 |
itemRect() is comparatively slow. It's best to call it only for |
|
5396 |
items that are probably on-screen. |
|
5397 |
*/ |
|
5398 |
||
5399 |
QRect Q3ListView::itemRect(const Q3ListViewItem * item) const |
|
5400 |
{ |
|
5401 |
if (d->drawables.isEmpty()) |
|
5402 |
buildDrawableList(); |
|
5403 |
||
5404 |
for (int i = 0; i < d->drawables.size(); ++i) { |
|
5405 |
const Q3ListViewPrivate::DrawableItem &c = d->drawables.at(i); |
|
5406 |
if (c.i == item) { |
|
5407 |
int y = c.y - contentsY(); |
|
5408 |
if (y + c.i->height() >= 0 && y < ((Q3ListView *)this)->visibleHeight()) { |
|
5409 |
return QRect(-contentsX(), y, d->h->width(), c.i->height());; |
|
5410 |
} |
|
5411 |
} |
|
5412 |
} |
|
5413 |
||
5414 |
return QRect(0, 0, -1, -1); |
|
5415 |
} |
|
5416 |
||
5417 |
||
5418 |
/*! |
|
5419 |
\fn void Q3ListView::doubleClicked(Q3ListViewItem *item) |
|
5420 |
||
5421 |
This signal is emitted whenever an item is double-clicked. It's |
|
5422 |
emitted on the second button press, not the second button release. |
|
5423 |
\a item is the list view item on which the user did the |
|
5424 |
double-click. |
|
5425 |
*/ |
|
5426 |
||
5427 |
/*! |
|
5428 |
\fn void Q3ListView::doubleClicked(Q3ListViewItem *item, const |
|
5429 |
QPoint& point, int column) |
|
5430 |
||
5431 |
This signal is emitted when a double-click occurs. It's emitted on |
|
5432 |
the second button press, not the second button release. The \a |
|
5433 |
item is the Q3ListViewItem the button was double-clicked on (which |
|
5434 |
could be 0 if it wasn't double-clicked on an item). The \a point |
|
5435 |
where the double-click occurred is given in global coordinates. If |
|
5436 |
an item was double-clicked on, \a column is the column within the |
|
5437 |
item that was double-clicked; otherwise \a column is -1. |
|
5438 |
||
5439 |
\warning Do not delete any Q3ListViewItem objects in slots |
|
5440 |
connected to this signal. |
|
5441 |
*/ |
|
5442 |
||
5443 |
||
5444 |
/*! |
|
5445 |
\fn void Q3ListView::returnPressed(Q3ListViewItem *item) |
|
5446 |
||
5447 |
This signal is emitted when Enter or Return is pressed. The |
|
5448 |
\a item parameter is the currentItem(). |
|
5449 |
*/ |
|
5450 |
||
5451 |
/*! |
|
5452 |
\fn void Q3ListView::spacePressed(Q3ListViewItem *item) |
|
5453 |
||
5454 |
This signal is emitted when Space is pressed. The \a item |
|
5455 |
parameter is the currentItem(). |
|
5456 |
*/ |
|
5457 |
||
5458 |
||
5459 |
/*! |
|
5460 |
Sets the list view to be sorted by column \a column in ascending |
|
5461 |
order if \a ascending is true or descending order if it is false. |
|
5462 |
||
5463 |
If \a column is -1, sorting is disabled and the user cannot sort |
|
5464 |
columns by clicking on the column headers. If \a column is larger |
|
5465 |
than the number of columns the user must click on a column |
|
5466 |
header to sort the list view. |
|
5467 |
*/ |
|
5468 |
||
5469 |
void Q3ListView::setSorting(int column, bool ascending) |
|
5470 |
{ |
|
5471 |
if (column == -1) |
|
5472 |
column = Unsorted; |
|
5473 |
||
5474 |
if (d->sortcolumn == column && d->ascending == ascending) |
|
5475 |
return; |
|
5476 |
||
5477 |
d->ascending = ascending; |
|
5478 |
d->sortcolumn = column; |
|
5479 |
if (d->sortcolumn != Unsorted && d->sortIndicator) |
|
5480 |
d->h->setSortIndicator(d->sortcolumn, d->ascending); |
|
5481 |
else |
|
5482 |
d->h->setSortIndicator(-1); |
|
5483 |
||
5484 |
triggerUpdate(); |
|
5485 |
||
5486 |
#ifndef QT_NO_ACCESSIBILITY |
|
5487 |
QAccessible::updateAccessibility(viewport(), 0, QAccessible::ObjectReorder); |
|
5488 |
#endif |
|
5489 |
} |
|
5490 |
||
5491 |
/*! |
|
5492 |
Sets the \a column the list view is sorted by. |
|
5493 |
||
5494 |
Sorting is triggered by choosing a header section. |
|
5495 |
*/ |
|
5496 |
||
5497 |
void Q3ListView::changeSortColumn(int column) |
|
5498 |
{ |
|
5499 |
if (isRenaming()) { |
|
5500 |
if (d->defRenameAction == Q3ListView::Reject) { |
|
5501 |
currentItem()->cancelRename(currentItem()->renameCol); |
|
5502 |
} else { |
|
5503 |
currentItem()->okRename(currentItem()->renameCol); |
|
5504 |
} |
|
5505 |
} |
|
5506 |
if (d->sortcolumn != Unsorted) { |
|
5507 |
int lcol = d->h->mapToLogical(column); |
|
5508 |
setSorting(lcol, d->sortcolumn == lcol ? !d->ascending : true); |
|
5509 |
} |
|
5510 |
} |
|
5511 |
||
5512 |
/*! |
|
5513 |
\internal |
|
5514 |
Handles renaming when sections are being swapped by the user. |
|
5515 |
*/ |
|
5516 |
||
5517 |
void Q3ListView::handleIndexChange() |
|
5518 |
{ |
|
5519 |
if (isRenaming()) { |
|
5520 |
if (d->defRenameAction == Q3ListView::Reject) { |
|
5521 |
currentItem()->cancelRename(currentItem()->renameCol); |
|
5522 |
} else { |
|
5523 |
currentItem()->okRename(currentItem()->renameCol); |
|
5524 |
} |
|
5525 |
} |
|
5526 |
triggerUpdate(); |
|
5527 |
} |
|
5528 |
||
5529 |
/*! |
|
5530 |
Returns the column by which the list view is sorted, or -1 if |
|
5531 |
sorting is disabled. |
|
5532 |
||
5533 |
\sa sortOrder() |
|
5534 |
*/ |
|
5535 |
||
5536 |
int Q3ListView::sortColumn() const |
|
5537 |
{ |
|
5538 |
return d->sortcolumn; |
|
5539 |
} |
|
5540 |
||
5541 |
/*! |
|
5542 |
Sets the sorting column for the list view. |
|
5543 |
||
5544 |
If \a column is -1, sorting is disabled and the user cannot sort |
|
5545 |
columns by clicking on the column headers. If \a column is larger |
|
5546 |
than the number of columns the user must click on a column header |
|
5547 |
to sort the list view. |
|
5548 |
||
5549 |
\sa setSorting() |
|
5550 |
*/ |
|
5551 |
void Q3ListView::setSortColumn(int column) |
|
5552 |
{ |
|
5553 |
setSorting(column, d->ascending); |
|
5554 |
} |
|
5555 |
||
5556 |
/*! |
|
5557 |
Returns the sorting order of the list view items. |
|
5558 |
||
5559 |
\sa sortColumn() |
|
5560 |
*/ |
|
5561 |
Qt::SortOrder Q3ListView::sortOrder() const |
|
5562 |
{ |
|
5563 |
if (d->ascending) |
|
5564 |
return Qt::AscendingOrder; |
|
5565 |
return Qt::DescendingOrder; |
|
5566 |
} |
|
5567 |
||
5568 |
/*! |
|
5569 |
Sets the sort order for the items in the list view to \a order. |
|
5570 |
||
5571 |
\sa setSorting() |
|
5572 |
*/ |
|
5573 |
void Q3ListView::setSortOrder(Qt::SortOrder order) |
|
5574 |
{ |
|
5575 |
setSorting(d->sortcolumn, order == Qt::AscendingOrder ? true : false); |
|
5576 |
} |
|
5577 |
||
5578 |
/*! |
|
5579 |
Sorts the list view using the last sorting configuration (sort |
|
5580 |
column and ascending/descending). |
|
5581 |
*/ |
|
5582 |
||
5583 |
void Q3ListView::sort() |
|
5584 |
{ |
|
5585 |
if (d->r) |
|
5586 |
d->r->sort(); |
|
5587 |
} |
|
5588 |
||
5589 |
/*! |
|
5590 |
\property Q3ListView::itemMargin |
|
5591 |
\brief the advisory item margin that list items may use |
|
5592 |
||
5593 |
The item margin defaults to one pixel and is the margin between |
|
5594 |
the item's edges and the area where it draws its contents. |
|
5595 |
Q3ListViewItem::paintFocus() draws in the margin. |
|
5596 |
||
5597 |
\sa Q3ListViewItem::paintCell() |
|
5598 |
*/ |
|
5599 |
||
5600 |
void Q3ListView::setItemMargin(int m) |
|
5601 |
{ |
|
5602 |
if (d->margin == m) |
|
5603 |
return; |
|
5604 |
d->margin = m; |
|
5605 |
if (isVisible()) { |
|
5606 |
d->drawables.clear(); |
|
5607 |
triggerUpdate(); |
|
5608 |
} |
|
5609 |
} |
|
5610 |
||
5611 |
int Q3ListView::itemMargin() const |
|
5612 |
{ |
|
5613 |
return d->margin; |
|
5614 |
} |
|
5615 |
||
5616 |
||
5617 |
/*! |
|
5618 |
\fn void Q3ListView::rightButtonClicked(Q3ListViewItem *item, |
|
5619 |
const QPoint& point, int column) |
|
5620 |
||
5621 |
This signal is emitted when the right button is clicked. The \a |
|
5622 |
item is the Q3ListViewItem the button was clicked on (which could |
|
5623 |
be 0 if it wasn't clicked on an item). The \a point where the |
|
5624 |
click occurred is given in global coordinates. If an item was |
|
5625 |
clicked on, \a column is the column within the item that was |
|
5626 |
clicked; otherwise \a column is -1. |
|
5627 |
*/ |
|
5628 |
||
5629 |
||
5630 |
/*! |
|
5631 |
\fn void Q3ListView::rightButtonPressed (Q3ListViewItem *item, |
|
5632 |
const QPoint &point, int column) |
|
5633 |
||
5634 |
This signal is emitted when the right button is pressed. The \a |
|
5635 |
item is the Q3ListViewItem the button was pressed on (which could |
|
5636 |
be 0 if it wasn't pressed on an item). The \a point where the |
|
5637 |
press occurred is given in global coordinates. If an item was |
|
5638 |
pressed on, \a column is the column within the item that was |
|
5639 |
pressed; otherwise \a column is -1. |
|
5640 |
*/ |
|
5641 |
||
5642 |
/*! |
|
5643 |
\fn void Q3ListView::contextMenuRequested(Q3ListViewItem *item, const QPoint & pos, int col) |
|
5644 |
||
5645 |
This signal is emitted when the user invokes a context menu with |
|
5646 |
the right mouse button or with special system keys. If the |
|
5647 |
keyboard was used \a item is the current item; if the mouse was |
|
5648 |
used, \a item is the item under the mouse pointer or 0 if there is |
|
5649 |
no item under the mouse pointer. If no item is clicked, the column |
|
5650 |
index emitted is -1. |
|
5651 |
||
5652 |
\a pos is the position for the context menu in the global |
|
5653 |
coordinate system. |
|
5654 |
||
5655 |
\a col is the column on which the user pressed, or -1 if the |
|
5656 |
signal was triggered by a key event. |
|
5657 |
*/ |
|
5658 |
||
5659 |
/*! |
|
5660 |
\reimp |
|
5661 |
*/ |
|
5662 |
void Q3ListView::changeEvent(QEvent *ev) |
|
5663 |
{ |
|
5664 |
if(ev->type() == QEvent::StyleChange) { |
|
5665 |
reconfigureItems(); |
|
5666 |
} else if(ev->type() == QEvent::ActivationChange) { |
|
5667 |
if (!isActiveWindow() && d->scrollTimer) |
|
5668 |
d->scrollTimer->stop(); |
|
5669 |
if (!palette().isEqual(QPalette::Active, QPalette::Inactive)) |
|
5670 |
viewport()->update(); |
|
5671 |
} |
|
5672 |
Q3ScrollView::changeEvent(ev); |
|
5673 |
||
5674 |
if (ev->type() == QEvent::ApplicationFontChange || ev->type() == QEvent::FontChange |
|
5675 |
|| ev->type() == QEvent::ApplicationPaletteChange || ev->type() == QEvent::PaletteChange) |
|
5676 |
reconfigureItems(); |
|
5677 |
} |
|
5678 |
||
5679 |
/*! |
|
5680 |
Ensures that setup() is called for all currently visible items, |
|
5681 |
and that it will be called for currently invisible items as soon |
|
5682 |
as their parents are opened. |
|
5683 |
||
5684 |
(A visible item, here, is an item whose parents are all open. The |
|
5685 |
item may happen to be off-screen.) |
|
5686 |
||
5687 |
\sa Q3ListViewItem::setup() |
|
5688 |
*/ |
|
5689 |
||
5690 |
void Q3ListView::reconfigureItems() |
|
5691 |
{ |
|
5692 |
d->fontMetricsHeight = fontMetrics().height(); |
|
5693 |
d->minLeftBearing = fontMetrics().minLeftBearing(); |
|
5694 |
d->minRightBearing = fontMetrics().minRightBearing(); |
|
5695 |
d->ellipsisWidth = fontMetrics().width(QLatin1String("...")) * 2; |
|
5696 |
d->r->setOpen(false); |
|
5697 |
d->r->configured = false; |
|
5698 |
d->r->setOpen(true); |
|
5699 |
} |
|
5700 |
||
5701 |
/*! |
|
5702 |
Ensures that the width mode of column \a c is updated according to |
|
5703 |
the width of \a item. |
|
5704 |
*/ |
|
5705 |
||
5706 |
void Q3ListView::widthChanged(const Q3ListViewItem* item, int c) |
|
5707 |
{ |
|
5708 |
if (c >= d->h->count()) |
|
5709 |
return; |
|
5710 |
||
5711 |
||
5712 |
QFontMetrics fm = fontMetrics(); |
|
5713 |
int col = c < 0 ? 0 : c; |
|
5714 |
while (col == c || (c < 0 && col < d->h->count())) { |
|
5715 |
if (d->column[col].wmode == Maximum) { |
|
5716 |
int w = item->width(fm, this, col); |
|
5717 |
if (showSortIndicator()) { |
|
5718 |
int tw = d->h->sectionSizeHint( col, fm ).width(); |
|
5719 |
tw += 40; //add space for the sort indicator |
|
5720 |
w = qMax(w, tw); |
|
5721 |
} |
|
5722 |
if (col == 0) { |
|
5723 |
int indent = treeStepSize() * item->depth(); |
|
5724 |
if (rootIsDecorated()) |
|
5725 |
indent += treeStepSize(); |
|
5726 |
w += indent; |
|
5727 |
} |
|
5728 |
if (w > columnWidth(col) && !d->h->isStretchEnabled() && !d->h->isStretchEnabled(col)) { |
|
5729 |
d->updateHeader = true; |
|
5730 |
setColumnWidth(col, w); |
|
5731 |
} |
|
5732 |
} |
|
5733 |
col++; |
|
5734 |
} |
|
5735 |
} |
|
5736 |
||
5737 |
/*! |
|
5738 |
\property Q3ListView::allColumnsShowFocus |
|
5739 |
\brief whether items should show keyboard focus using all columns |
|
5740 |
||
5741 |
If this property is true all columns will show focus and selection |
|
5742 |
states, otherwise only column 0 will show focus. |
|
5743 |
||
5744 |
The default is false. |
|
5745 |
||
5746 |
Setting this to true if it's not necessary may cause noticeable |
|
5747 |
flicker. |
|
5748 |
*/ |
|
5749 |
||
5750 |
void Q3ListView::setAllColumnsShowFocus(bool enable) |
|
5751 |
{ |
|
5752 |
d->allColumnsShowFocus = enable; |
|
5753 |
} |
|
5754 |
||
5755 |
bool Q3ListView::allColumnsShowFocus() const |
|
5756 |
{ |
|
5757 |
return d->allColumnsShowFocus; |
|
5758 |
} |
|
5759 |
||
5760 |
||
5761 |
/*! |
|
5762 |
Returns the first item in this Q3ListView. Returns 0 if there is no |
|
5763 |
first item. |
|
5764 |
||
5765 |
A list view's items can be traversed using firstChild() |
|
5766 |
and nextSibling() or using a Q3ListViewItemIterator. |
|
5767 |
||
5768 |
\sa itemAt() Q3ListViewItem::itemBelow() Q3ListViewItem::itemAbove() |
|
5769 |
*/ |
|
5770 |
||
5771 |
Q3ListViewItem * Q3ListView::firstChild() const |
|
5772 |
{ |
|
5773 |
if (!d->r) |
|
5774 |
return 0; |
|
5775 |
||
5776 |
d->r->enforceSortOrder(); |
|
5777 |
return d->r->childItem; |
|
5778 |
} |
|
5779 |
||
5780 |
/*! |
|
5781 |
Returns the last item in the list view tree. Returns 0 if there |
|
5782 |
are no items in the Q3ListView. |
|
5783 |
||
5784 |
This function is slow because it traverses the entire tree to find |
|
5785 |
the last item. |
|
5786 |
*/ |
|
5787 |
||
5788 |
Q3ListViewItem* Q3ListView::lastItem() const |
|
5789 |
{ |
|
5790 |
Q3ListViewItem* item = firstChild(); |
|
5791 |
if (item) { |
|
5792 |
while (item->nextSibling() || item->firstChild()) { |
|
5793 |
if (item->nextSibling()) |
|
5794 |
item = item->nextSibling(); |
|
5795 |
else |
|
5796 |
item = item->firstChild(); |
|
5797 |
} |
|
5798 |
} |
|
5799 |
return item; |
|
5800 |
} |
|
5801 |
||
5802 |
/*! |
|
5803 |
Repaints this item on the screen if it is currently visible. |
|
5804 |
*/ |
|
5805 |
||
5806 |
void Q3ListViewItem::repaint() const |
|
5807 |
{ |
|
5808 |
Q3ListView *lv = listView(); |
|
5809 |
if (lv) |
|
5810 |
lv->repaintItem(this); |
|
5811 |
} |
|
5812 |
||
5813 |
||
5814 |
/*! |
|
5815 |
Repaints \a item on the screen if \a item is currently visible. |
|
5816 |
Takes care to avoid multiple repaints. |
|
5817 |
*/ |
|
5818 |
||
5819 |
void Q3ListView::repaintItem(const Q3ListViewItem * item) const |
|
5820 |
{ |
|
5821 |
if (!item) |
|
5822 |
return; |
|
5823 |
d->dirtyItemTimer->start(0, true); |
|
5824 |
d->dirtyItems.append(item); |
|
5825 |
} |
|
5826 |
||
5827 |
||
5828 |
struct Q3CheckListItemPrivate |
|
5829 |
{ |
|
5830 |
Q3CheckListItemPrivate(): |
|
5831 |
exclusive(0), |
|
5832 |
currentState(Q3CheckListItem::Off), |
|
5833 |
tristate(false) {} |
|
5834 |
||
5835 |
Q3CheckListItem *exclusive; |
|
5836 |
Q3CheckListItem::ToggleState currentState; |
|
5837 |
QHash<Q3CheckListItem *, Q3CheckListItem::ToggleState> statesDict; |
|
5838 |
bool tristate; |
|
5839 |
}; |
|
5840 |
||
5841 |
||
5842 |
/*! |
|
5843 |
\class Q3CheckListItem |
|
5844 |
\brief The Q3CheckListItem class provides checkable list view items. |
|
5845 |
||
5846 |
\compat |
|
5847 |
||
5848 |
Q3CheckListItems are used in \l{Q3ListView}s to provide |
|
5849 |
\l{Q3ListViewItem}s that are checkboxes, radio buttons or |
|
5850 |
controllers. |
|
5851 |
||
5852 |
Checkbox and controller check list items may be inserted at any |
|
5853 |
level in a list view. Radio button check list items must be |
|
5854 |
children of a controller check list item. |
|
5855 |
||
5856 |
The item can be checked or unchecked with setOn(). Its type can be |
|
5857 |
retrieved with type() and its text retrieved with text(). |
|
5858 |
||
5859 |
\img qlistviewitems.png List View Items |
|
5860 |
||
5861 |
\sa Q3ListViewItem Q3ListView |
|
5862 |
*/ |
|
5863 |
||
5864 |
/*! |
|
5865 |
\enum Q3CheckListItem::Type |
|
5866 |
||
5867 |
This enum type specifies a Q3CheckListItem's type: |
|
5868 |
||
5869 |
\value RadioButton |
|
5870 |
\value CheckBox |
|
5871 |
\value RadioButtonController |
|
5872 |
\value CheckBoxController |
|
5873 |
\omitvalue Controller |
|
5874 |
*/ |
|
5875 |
||
5876 |
/*! |
|
5877 |
\enum Q3CheckListItem::ToggleState |
|
5878 |
||
5879 |
This enum specifies a Q3CheckListItem's toggle state. |
|
5880 |
||
5881 |
\value Off |
|
5882 |
\value NoChange |
|
5883 |
\value On |
|
5884 |
*/ |
|
5885 |
||
5886 |
||
5887 |
/*! |
|
5888 |
Constructs a checkable item with parent \a parent, text \a text |
|
5889 |
and of type \a tt. Note that a \c RadioButton must be the child of a |
|
5890 |
\c RadioButtonController, otherwise it will not toggle. |
|
5891 |
*/ |
|
5892 |
Q3CheckListItem::Q3CheckListItem(Q3CheckListItem *parent, const QString &text, |
|
5893 |
Type tt) |
|
5894 |
: Q3ListViewItem(parent, text, QString()) |
|
5895 |
{ |
|
5896 |
myType = tt; |
|
5897 |
init(); |
|
5898 |
if (myType == RadioButton) { |
|
5899 |
if (parent->type() != RadioButtonController) |
|
5900 |
qWarning("Q3CheckListItem::Q3CheckListItem(), radio button must be " |
|
5901 |
"child of a controller"); |
|
5902 |
else |
|
5903 |
d->exclusive = parent; |
|
5904 |
} |
|
5905 |
} |
|
5906 |
||
5907 |
/*! |
|
5908 |
Constructs a checkable item with parent \a parent, which is after |
|
5909 |
\a after in the parent's list of children, and with text \a text |
|
5910 |
and of type \a tt. Note that a \c RadioButton must be the child of |
|
5911 |
a \c RadioButtonController, otherwise it will not toggle. |
|
5912 |
*/ |
|
5913 |
Q3CheckListItem::Q3CheckListItem(Q3CheckListItem *parent, Q3ListViewItem *after, |
|
5914 |
const QString &text, Type tt) |
|
5915 |
: Q3ListViewItem(parent, after, text) |
|
5916 |
{ |
|
5917 |
myType = tt; |
|
5918 |
init(); |
|
5919 |
if (myType == RadioButton) { |
|
5920 |
if (parent->type() != RadioButtonController) |
|
5921 |
qWarning("Q3CheckListItem::Q3CheckListItem(), radio button must be " |
|
5922 |
"child of a controller"); |
|
5923 |
else |
|
5924 |
d->exclusive = parent; |
|
5925 |
} |
|
5926 |
} |
|
5927 |
||
5928 |
/*! |
|
5929 |
Constructs a checkable item with parent \a parent, text \a text |
|
5930 |
and of type \a tt. Note that this item must \e not be a \c |
|
5931 |
RadioButton. Radio buttons must be children of a \c |
|
5932 |
RadioButtonController. |
|
5933 |
*/ |
|
5934 |
Q3CheckListItem::Q3CheckListItem(Q3ListViewItem *parent, const QString &text, |
|
5935 |
Type tt) |
|
5936 |
: Q3ListViewItem(parent, text, QString()) |
|
5937 |
{ |
|
5938 |
myType = tt; |
|
5939 |
if (myType == RadioButton) { |
|
5940 |
qWarning("Q3CheckListItem::Q3CheckListItem(), radio button must be " |
|
5941 |
"child of a Q3CheckListItem"); |
|
5942 |
} |
|
5943 |
init(); |
|
5944 |
} |
|
5945 |
||
5946 |
/*! |
|
5947 |
Constructs a checkable item with parent \a parent, which is after |
|
5948 |
\a after in the parent's list of children, with text \a text and |
|
5949 |
of type \a tt. Note that this item must \e not be a \c |
|
5950 |
RadioButton. Radio buttons must be children of a \c |
|
5951 |
RadioButtonController. |
|
5952 |
*/ |
|
5953 |
Q3CheckListItem::Q3CheckListItem(Q3ListViewItem *parent, Q3ListViewItem *after, |
|
5954 |
const QString &text, Type tt) |
|
5955 |
: Q3ListViewItem(parent, after, text) |
|
5956 |
{ |
|
5957 |
myType = tt; |
|
5958 |
if (myType == RadioButton) { |
|
5959 |
qWarning("Q3CheckListItem::Q3CheckListItem(), radio button must be " |
|
5960 |
"child of a Q3CheckListItem"); |
|
5961 |
} |
|
5962 |
init(); |
|
5963 |
} |
|
5964 |
||
5965 |
||
5966 |
/*! |
|
5967 |
Constructs a checkable item with parent \a parent, text \a text |
|
5968 |
and of type \a tt. Note that \a tt must \e not be \c RadioButton. |
|
5969 |
Radio buttons must be children of a \c RadioButtonController. |
|
5970 |
*/ |
|
5971 |
Q3CheckListItem::Q3CheckListItem(Q3ListView *parent, const QString &text, |
|
5972 |
Type tt) |
|
5973 |
: Q3ListViewItem(parent, text) |
|
5974 |
{ |
|
5975 |
myType = tt; |
|
5976 |
if (tt == RadioButton) |
|
5977 |
qWarning("Q3CheckListItem::Q3CheckListItem(), radio button must be " |
|
5978 |
"child of a Q3CheckListItem"); |
|
5979 |
init(); |
|
5980 |
} |
|
5981 |
||
5982 |
/*! |
|
5983 |
Constructs a checkable item with parent \a parent, which is after |
|
5984 |
\a after in the parent's list of children, with text \a text and |
|
5985 |
of type \a tt. Note that \a tt must \e not be \c RadioButton. |
|
5986 |
Radio buttons must be children of a \c RadioButtonController. |
|
5987 |
*/ |
|
5988 |
Q3CheckListItem::Q3CheckListItem(Q3ListView *parent, Q3ListViewItem *after, |
|
5989 |
const QString &text, Type tt) |
|
5990 |
: Q3ListViewItem(parent, after, text) |
|
5991 |
{ |
|
5992 |
myType = tt; |
|
5993 |
if (tt == RadioButton) |
|
5994 |
qWarning("Q3CheckListItem::Q3CheckListItem(), radio button must be " |
|
5995 |
"child of a Q3CheckListItem"); |
|
5996 |
init(); |
|
5997 |
} |
|
5998 |
||
5999 |
||
6000 |
/* \reimp */ |
|
6001 |
||
6002 |
int Q3CheckListItem::rtti() const |
|
6003 |
{ |
|
6004 |
return RTTI; |
|
6005 |
} |
|
6006 |
||
6007 |
/*! |
|
6008 |
Constructs a \c RadioButtonController item with parent \a parent, |
|
6009 |
text \a text and pixmap \a p. |
|
6010 |
*/ |
|
6011 |
Q3CheckListItem::Q3CheckListItem(Q3ListView *parent, const QString &text, |
|
6012 |
const QPixmap & p) |
|
6013 |
: Q3ListViewItem(parent, text) |
|
6014 |
{ |
|
6015 |
myType = RadioButtonController; |
|
6016 |
setPixmap(0, p); |
|
6017 |
init(); |
|
6018 |
} |
|
6019 |
||
6020 |
/*! |
|
6021 |
Constructs a \c RadioButtonController item with parent \a parent, |
|
6022 |
text \a text and pixmap \a p. |
|
6023 |
*/ |
|
6024 |
Q3CheckListItem::Q3CheckListItem(Q3ListViewItem *parent, const QString &text, |
|
6025 |
const QPixmap & p) |
|
6026 |
: Q3ListViewItem(parent, text) |
|
6027 |
{ |
|
6028 |
myType = RadioButtonController; |
|
6029 |
setPixmap(0, p); |
|
6030 |
init(); |
|
6031 |
} |
|
6032 |
||
6033 |
void Q3CheckListItem::init() |
|
6034 |
{ |
|
6035 |
d = new Q3CheckListItemPrivate(); |
|
6036 |
on = false; |
|
6037 |
// CheckBoxControllers by default have tristate set to true |
|
6038 |
if (myType == CheckBoxController) |
|
6039 |
setTristate(true); |
|
6040 |
} |
|
6041 |
||
6042 |
/*! |
|
6043 |
Destroys the item, and all its children to any depth, freeing up |
|
6044 |
all allocated resources. |
|
6045 |
*/ |
|
6046 |
Q3CheckListItem::~Q3CheckListItem() |
|
6047 |
{ |
|
6048 |
if (myType == RadioButton |
|
6049 |
&& d->exclusive && d->exclusive->d |
|
6050 |
&& d->exclusive->d->exclusive == this) |
|
6051 |
d->exclusive->turnOffChild(); |
|
6052 |
d->exclusive = 0; // so the children won't try to access us. |
|
6053 |
delete d; |
|
6054 |
d = 0; |
|
6055 |
} |
|
6056 |
||
6057 |
/*! |
|
6058 |
\fn Q3CheckListItem::Type Q3CheckListItem::type() const |
|
6059 |
||
6060 |
Returns the type of this item. |
|
6061 |
*/ |
|
6062 |
||
6063 |
/*! |
|
6064 |
\fn bool Q3CheckListItem::isOn() const |
|
6065 |
||
6066 |
Returns true if the item is toggled on; otherwise returns false. |
|
6067 |
*/ |
|
6068 |
||
6069 |
/*! |
|
6070 |
Sets tristate to \a b if the \c Type is either a \c CheckBoxController or |
|
6071 |
a \c CheckBox. |
|
6072 |
||
6073 |
\c CheckBoxControllers are tristate by default. |
|
6074 |
||
6075 |
\sa state() isTristate() |
|
6076 |
*/ |
|
6077 |
void Q3CheckListItem::setTristate(bool b) |
|
6078 |
{ |
|
6079 |
if ((myType != CheckBoxController) && (myType != CheckBox)) { |
|
6080 |
qWarning("Q3CheckListItem::setTristate(), has no effect on RadioButton " |
|
6081 |
"or RadioButtonController."); |
|
6082 |
return; |
|
6083 |
} |
|
6084 |
d->tristate = b; |
|
6085 |
} |
|
6086 |
||
6087 |
/*! |
|
6088 |
Returns true if the item is tristate; otherwise returns false. |
|
6089 |
||
6090 |
\sa setTristate() |
|
6091 |
*/ |
|
6092 |
bool Q3CheckListItem::isTristate() const |
|
6093 |
{ |
|
6094 |
return d->tristate; |
|
6095 |
} |
|
6096 |
||
6097 |
/*! |
|
6098 |
Returns the state of the item. |
|
6099 |
||
6100 |
\sa Q3CheckListItem::ToggleState |
|
6101 |
*/ |
|
6102 |
Q3CheckListItem::ToggleState Q3CheckListItem::state() const |
|
6103 |
{ |
|
6104 |
if (!isTristate() && internalState() == NoChange) |
|
6105 |
return Off; |
|
6106 |
else |
|
6107 |
return d->currentState; |
|
6108 |
} |
|
6109 |
||
6110 |
/* |
|
6111 |
Same as the public state() except this one does not mask NoChange into Off |
|
6112 |
when tristate is disabled. |
|
6113 |
*/ |
|
6114 |
Q3CheckListItem::ToggleState Q3CheckListItem::internalState() const |
|
6115 |
{ |
|
6116 |
return d->currentState; |
|
6117 |
} |
|
6118 |
||
6119 |
||
6120 |
||
6121 |
||
6122 |
/*! |
|
6123 |
Sets the toggle state of the checklistitem to \a s. \a s can be |
|
6124 |
\c Off, \c NoChange or \c On. |
|
6125 |
||
6126 |
Tristate can only be enabled for \c CheckBox or \c CheckBoxController, |
|
6127 |
therefore the \c NoChange only applies to them. |
|
6128 |
||
6129 |
Setting the state to \c On or \c Off on a \c CheckBoxController |
|
6130 |
will recursivly set the states of its children to the same state. |
|
6131 |
||
6132 |
Setting the state to \c NoChange on a \c CheckBoxController will |
|
6133 |
make it recursivly recall the previous stored state of its |
|
6134 |
children. If there was no previous stored state the children are |
|
6135 |
all set to \c On. |
|
6136 |
*/ |
|
6137 |
void Q3CheckListItem::setState(ToggleState s) |
|
6138 |
{ |
|
6139 |
if (myType == CheckBoxController && state() == NoChange) |
|
6140 |
updateStoredState(this); |
|
6141 |
setState(s, true, true); |
|
6142 |
} |
|
6143 |
||
6144 |
/* |
|
6145 |
Sets the toggle state of the checklistitems. \a update tells if the |
|
6146 |
controller / parent controller should be aware of these changes, \a store |
|
6147 |
tells if the parent should store its children if certain conditions arise |
|
6148 |
*/ |
|
6149 |
void Q3CheckListItem::setState(ToggleState s, bool update, bool store) |
|
6150 |
{ |
|
6151 |
||
6152 |
if (s == internalState()) |
|
6153 |
return; |
|
6154 |
||
6155 |
if (myType == CheckBox) { |
|
6156 |
setCurrentState(s); |
|
6157 |
stateChange(state()); |
|
6158 |
if (update && parent() && parent()->rtti() == 1 |
|
6159 |
&& ((Q3CheckListItem*)parent())->type() == CheckBoxController) |
|
6160 |
((Q3CheckListItem*)parent())->updateController(update, store); |
|
6161 |
} else if (myType == CheckBoxController) { |
|
6162 |
if (s == NoChange && childCount()) { |
|
6163 |
restoreState(this); |
|
6164 |
} else { |
|
6165 |
Q3ListViewItem *item = firstChild(); |
|
6166 |
int childCount = 0; |
|
6167 |
while(item) { |
|
6168 |
if (item->rtti() == 1 && |
|
6169 |
(((Q3CheckListItem*)item)->type() == CheckBox || |
|
6170 |
((Q3CheckListItem*)item)->type() == CheckBoxController)) { |
|
6171 |
Q3CheckListItem *checkItem = (Q3CheckListItem*)item; |
|
6172 |
checkItem->setState(s, false, false); |
|
6173 |
childCount++; |
|
6174 |
} |
|
6175 |
item = item->nextSibling(); |
|
6176 |
} |
|
6177 |
if (update) { |
|
6178 |
if (childCount > 0) { |
|
6179 |
ToggleState oldState = internalState(); |
|
6180 |
updateController(false, false); |
|
6181 |
if (oldState != internalState() && |
|
6182 |
parent() && parent()->rtti() == 1 && |
|
6183 |
((Q3CheckListItem*)parent())->type() == CheckBoxController) |
|
6184 |
((Q3CheckListItem*)parent())->updateController(update, store); |
|
6185 |
||
6186 |
updateController(update, store); |
|
6187 |
} else { |
|
6188 |
// if there are no children we simply set the CheckBoxController and update its parent |
|
6189 |
setCurrentState(s); |
|
6190 |
stateChange(state()); |
|
6191 |
if (parent() && parent()->rtti() == 1 |
|
6192 |
&& ((Q3CheckListItem*)parent())->type() == CheckBoxController) |
|
6193 |
((Q3CheckListItem*)parent())->updateController(update, store); |
|
6194 |
} |
|
6195 |
} else { |
|
6196 |
setCurrentState(s); |
|
6197 |
stateChange(state()); |
|
6198 |
} |
|
6199 |
||
6200 |
} |
|
6201 |
} else if (myType == RadioButton) { |
|
6202 |
if (s == On) { |
|
6203 |
if (d->exclusive && d->exclusive->d->exclusive != this) |
|
6204 |
d->exclusive->turnOffChild(); |
|
6205 |
setCurrentState(s); |
|
6206 |
if (d->exclusive) |
|
6207 |
d->exclusive->d->exclusive = this; |
|
6208 |
} else { |
|
6209 |
if (d->exclusive && d->exclusive->d->exclusive == this) |
|
6210 |
d->exclusive->d->exclusive = 0; |
|
6211 |
setCurrentState(Off); |
|
6212 |
} |
|
6213 |
stateChange(state()); |
|
6214 |
} |
|
6215 |
repaint(); |
|
6216 |
} |
|
6217 |
||
6218 |
/* |
|
6219 |
this function is needed because we need to update "on" every time we |
|
6220 |
update d->currentState. In order to retain binary compatibility the |
|
6221 |
inline function isOn() needs the "on" bool ### should be changed in |
|
6222 |
ver 4 |
|
6223 |
*/ |
|
6224 |
void Q3CheckListItem::setCurrentState(ToggleState s) |
|
6225 |
{ |
|
6226 |
ToggleState old = d->currentState; |
|
6227 |
d->currentState = s; |
|
6228 |
if (d->currentState == On) |
|
6229 |
on = true; |
|
6230 |
else |
|
6231 |
on = false; |
|
6232 |
||
6233 |
#ifndef QT_NO_ACCESSIBILITY |
|
6234 |
if (old != d->currentState && listView()) |
|
6235 |
QAccessible::updateAccessibility(listView()->viewport(), indexOfItem(this), QAccessible::StateChanged); |
|
6236 |
#else |
|
6237 |
Q_UNUSED(old); |
|
6238 |
#endif |
|
6239 |
} |
|
6240 |
||
6241 |
||
6242 |
||
6243 |
/* |
|
6244 |
updates the internally stored state of this item for the parent (key) |
|
6245 |
*/ |
|
6246 |
void Q3CheckListItem::setStoredState(ToggleState newState, Q3CheckListItem *key) |
|
6247 |
{ |
|
6248 |
if (myType == CheckBox || myType == CheckBoxController) |
|
6249 |
d->statesDict[key] = newState; |
|
6250 |
} |
|
6251 |
||
6252 |
/* |
|
6253 |
Returns the stored state for this item for the given key. |
|
6254 |
If the key is not found it returns Off. |
|
6255 |
*/ |
|
6256 |
Q3CheckListItem::ToggleState Q3CheckListItem::storedState(Q3CheckListItem *key) const |
|
6257 |
{ |
|
6258 |
QHash<Q3CheckListItem *, Q3CheckListItem::ToggleState>::Iterator it = d->statesDict.find(key); |
|
6259 |
if (it != d->statesDict.end()) |
|
6260 |
return it.value(); |
|
6261 |
else |
|
6262 |
return Off; |
|
6263 |
} |
|
6264 |
||
6265 |
||
6266 |
/*! |
|
6267 |
\fn QString Q3CheckListItem::text() const |
|
6268 |
||
6269 |
Returns the item's text. |
|
6270 |
*/ |
|
6271 |
||
6272 |
||
6273 |
/*! |
|
6274 |
If this is a \c RadioButtonController that has \c RadioButton |
|
6275 |
children, turn off the child that is on. |
|
6276 |
*/ |
|
6277 |
void Q3CheckListItem::turnOffChild() |
|
6278 |
{ |
|
6279 |
if (myType == RadioButtonController && d->exclusive) |
|
6280 |
d->exclusive->setOn(false); |
|
6281 |
} |
|
6282 |
||
6283 |
/*! |
|
6284 |
Toggle check box or set radio button to on. |
|
6285 |
*/ |
|
6286 |
void Q3CheckListItem::activate() |
|
6287 |
{ |
|
6288 |
Q3ListView * lv = listView(); |
|
6289 |
||
6290 |
if ((lv && !lv->isEnabled()) || !isEnabled()) |
|
6291 |
return; |
|
6292 |
||
6293 |
QPoint pos; |
|
6294 |
int boxsize = lv->style()->pixelMetric(QStyle::PM_CheckListButtonSize, 0, lv); |
|
6295 |
if (activatedPos(pos)) { |
|
6296 |
bool parentControl = false; |
|
6297 |
if (parent() && parent()->rtti() == 1 && |
|
6298 |
((Q3CheckListItem*) parent())->type() == RadioButtonController) |
|
6299 |
parentControl = true; |
|
6300 |
||
6301 |
int x = parentControl ? 0 : 3; |
|
6302 |
int align = lv->columnAlignment(0); |
|
6303 |
int marg = lv->itemMargin(); |
|
6304 |
int y = 0; |
|
6305 |
||
6306 |
if (align & Qt::AlignVCenter) |
|
6307 |
y = ((height() - boxsize) / 2) + marg; |
|
6308 |
else |
|
6309 |
y = (lv->fontMetrics().height() + 2 + marg - boxsize) / 2; |
|
6310 |
||
6311 |
QRect r(x, y, boxsize-3, boxsize-3); |
|
6312 |
// columns might have been swapped |
|
6313 |
r.moveBy(lv->header()->sectionPos(0), 0); |
|
6314 |
if (!r.contains(pos)) |
|
6315 |
return; |
|
6316 |
} |
|
6317 |
if ((myType == CheckBox) || (myType == CheckBoxController)) { |
|
6318 |
lv->d->startEdit = FALSE; |
|
6319 |
switch (internalState()) { |
|
6320 |
case On: |
|
6321 |
setState(Off); |
|
6322 |
break; |
|
6323 |
case Off: |
|
6324 |
if ( (!isTristate() && myType == CheckBox) || |
|
6325 |
(myType == CheckBoxController && !childCount()) ) { |
|
6326 |
setState(On); |
|
6327 |
} else { |
|
6328 |
setState(NoChange); |
|
6329 |
if (myType == CheckBoxController && internalState() != NoChange) |
|
6330 |
setState(On); |
|
6331 |
} |
|
6332 |
break; |
|
6333 |
case NoChange: |
|
6334 |
setState(On); |
|
6335 |
break; |
|
6336 |
} |
|
6337 |
ignoreDoubleClick(); |
|
6338 |
} else if (myType == RadioButton) { |
|
6339 |
setOn(true); |
|
6340 |
ignoreDoubleClick(); |
|
6341 |
} |
|
6342 |
} |
|
6343 |
||
6344 |
/*! |
|
6345 |
Sets the button on if \a b is true, otherwise sets it off. |
|
6346 |
Maintains radio button exclusivity. |
|
6347 |
*/ |
|
6348 |
void Q3CheckListItem::setOn(bool b ) |
|
6349 |
{ |
|
6350 |
if (b) |
|
6351 |
setState(On , true, true); |
|
6352 |
else |
|
6353 |
setState(Off , true, true); |
|
6354 |
} |
|
6355 |
||
6356 |
||
6357 |
/*! |
|
6358 |
\fn void Q3CheckListItem::stateChange(bool b) |
|
6359 |
||
6360 |
This virtual function is called when the item changes its state. |
|
6361 |
\a b is true if the state is \c On; otherwise the state is \c Off. |
|
6362 |
\c NoChange (if tristate is enabled and the type is either \c |
|
6363 |
CheckBox or \c CheckBoxController) reports the same as \c Off, so |
|
6364 |
use state() to determine if the state is actually \c Off or \c |
|
6365 |
NoChange. |
|
6366 |
*/ |
|
6367 |
void Q3CheckListItem::stateChange(bool) |
|
6368 |
{ |
|
6369 |
} |
|
6370 |
||
6371 |
/* |
|
6372 |
Calls the public virtual function if the state is changed to either On, NoChange or Off. |
|
6373 |
NoChange reports the same as Off - ### should be fixed in ver4 |
|
6374 |
*/ |
|
6375 |
void Q3CheckListItem::stateChange(ToggleState s) |
|
6376 |
{ |
|
6377 |
stateChange(s == On); |
|
6378 |
} |
|
6379 |
||
6380 |
/* |
|
6381 |
sets the state of the CheckBox and CheckBoxController back to |
|
6382 |
previous stored state |
|
6383 |
*/ |
|
6384 |
void Q3CheckListItem::restoreState(Q3CheckListItem *key, int depth) |
|
6385 |
{ |
|
6386 |
switch (type()) { |
|
6387 |
case CheckBox: |
|
6388 |
setCurrentState(storedState(key)); |
|
6389 |
stateChange(state()); |
|
6390 |
repaint(); |
|
6391 |
break; |
|
6392 |
case CheckBoxController: { |
|
6393 |
Q3ListViewItem *item = firstChild(); |
|
6394 |
int childCount = 0; |
|
6395 |
while (item) { |
|
6396 |
// recursively calling restoreState for children of type CheckBox and CheckBoxController |
|
6397 |
if (item->rtti() == 1 && |
|
6398 |
(((Q3CheckListItem*)item)->type() == CheckBox || |
|
6399 |
((Q3CheckListItem*)item)->type() == CheckBoxController)) { |
|
6400 |
((Q3CheckListItem*)item)->restoreState(key , depth+1); |
|
6401 |
childCount++; |
|
6402 |
} |
|
6403 |
item = item->nextSibling(); |
|
6404 |
} |
|
6405 |
if (childCount > 0) { |
|
6406 |
if (depth == 0) |
|
6407 |
updateController(true); |
|
6408 |
else |
|
6409 |
updateController(false); |
|
6410 |
} else { |
|
6411 |
// if there are no children we retrieve the CheckBoxController state directly. |
|
6412 |
setState(storedState(key), true, false); |
|
6413 |
} |
|
6414 |
} |
|
6415 |
break; |
|
6416 |
default: |
|
6417 |
break; |
|
6418 |
} |
|
6419 |
} |
|
6420 |
||
6421 |
||
6422 |
/* |
|
6423 |
Checks the childrens state and updates the controllers state |
|
6424 |
if necessary. If the controllers state change, then his parent again is |
|
6425 |
called to update itself. |
|
6426 |
*/ |
|
6427 |
void Q3CheckListItem::updateController(bool update , bool store) |
|
6428 |
{ |
|
6429 |
if (myType != CheckBoxController) |
|
6430 |
return; |
|
6431 |
||
6432 |
Q3CheckListItem *controller = 0; |
|
6433 |
// checks if this CheckBoxController has another CheckBoxController as parent |
|
6434 |
if (parent() && parent()->rtti() == 1 |
|
6435 |
&& ((Q3CheckListItem*)parent())->type() == CheckBoxController) |
|
6436 |
controller = (Q3CheckListItem*)parent(); |
|
6437 |
||
6438 |
ToggleState theState = Off; |
|
6439 |
bool first = true; |
|
6440 |
Q3ListViewItem *item = firstChild(); |
|
6441 |
while(item && theState != NoChange) { |
|
6442 |
if (item->rtti() == 1 && |
|
6443 |
(((Q3CheckListItem*)item)->type() == CheckBox || |
|
6444 |
((Q3CheckListItem*)item)->type() == CheckBoxController)) { |
|
6445 |
Q3CheckListItem *checkItem = (Q3CheckListItem*)item; |
|
6446 |
if (first) { |
|
6447 |
theState = checkItem->internalState(); |
|
6448 |
first = false; |
|
6449 |
} else { |
|
6450 |
if (checkItem->internalState() == NoChange || |
|
6451 |
theState != checkItem->internalState()) |
|
6452 |
theState = NoChange; |
|
6453 |
else |
|
6454 |
theState = checkItem->internalState(); |
|
6455 |
} |
|
6456 |
} |
|
6457 |
item = item->nextSibling(); |
|
6458 |
} |
|
6459 |
if (internalState() != theState) { |
|
6460 |
setCurrentState(theState); |
|
6461 |
if (store && (internalState() == On || internalState() == Off)) |
|
6462 |
updateStoredState(this); |
|
6463 |
stateChange(state()); |
|
6464 |
if (update && controller) { |
|
6465 |
controller->updateController(update, store); |
|
6466 |
} |
|
6467 |
repaint(); |
|
6468 |
} |
|
6469 |
} |
|
6470 |
||
6471 |
||
6472 |
/* |
|
6473 |
Makes all the children CheckBoxes update their storedState |
|
6474 |
*/ |
|
6475 |
void Q3CheckListItem::updateStoredState(Q3CheckListItem *key) |
|
6476 |
{ |
|
6477 |
if (myType != CheckBoxController) |
|
6478 |
return; |
|
6479 |
||
6480 |
Q3ListViewItem *item = firstChild(); |
|
6481 |
while(item) { |
|
6482 |
if (item->rtti() == 1) { |
|
6483 |
Q3CheckListItem *checkItem = (Q3CheckListItem*)item; |
|
6484 |
if (checkItem->type() == CheckBox) |
|
6485 |
checkItem->setStoredState(checkItem->internalState(), key); |
|
6486 |
else if (checkItem->type() == CheckBoxController) |
|
6487 |
checkItem->updateStoredState(key); |
|
6488 |
} |
|
6489 |
item = item->nextSibling(); |
|
6490 |
} |
|
6491 |
// this state is only needed if the CheckBoxController has no CheckBox / CheckBoxController children. |
|
6492 |
setStoredState(internalState() , key); |
|
6493 |
} |
|
6494 |
||
6495 |
||
6496 |
/*! |
|
6497 |
\reimp |
|
6498 |
*/ |
|
6499 |
void Q3CheckListItem::setup() |
|
6500 |
{ |
|
6501 |
Q3ListViewItem::setup(); |
|
6502 |
int h = height(); |
|
6503 |
Q3ListView *lv = listView(); |
|
6504 |
if (lv) |
|
6505 |
h = qMax(lv->style()->pixelMetric(QStyle::PM_CheckListButtonSize, 0, lv), |
|
6506 |
h); |
|
6507 |
h = qMax(h, QApplication::globalStrut().height()); |
|
6508 |
setHeight(h); |
|
6509 |
} |
|
6510 |
||
6511 |
/*! |
|
6512 |
\reimp |
|
6513 |
*/ |
|
6514 |
||
6515 |
int Q3CheckListItem::width(const QFontMetrics& fm, const Q3ListView* lv, int column) const |
|
6516 |
{ |
|
6517 |
int r = Q3ListViewItem::width(fm, lv, column); |
|
6518 |
if (column == 0) { |
|
6519 |
r += lv->itemMargin(); |
|
6520 |
if (myType == RadioButtonController && pixmap(0)) { |
|
6521 |
// r += 0; |
|
6522 |
} else { |
|
6523 |
r += lv->style()->pixelMetric(QStyle::PM_CheckListButtonSize, 0, lv) + 4; |
|
6524 |
} |
|
6525 |
} |
|
6526 |
return qMax(r, QApplication::globalStrut().width()); |
|
6527 |
} |
|
6528 |
||
6529 |
/*! |
|
6530 |
Paints the item using the painter \a p and the color group \a cg. |
|
6531 |
The item is in column \a column, has width \a width and has |
|
6532 |
alignment \a align. (See \l Qt::Alignment for valid alignments.) |
|
6533 |
*/ |
|
6534 |
void Q3CheckListItem::paintCell(QPainter * p, const QColorGroup & cg, |
|
6535 |
int column, int width, int align) |
|
6536 |
{ |
|
6537 |
if (!p) |
|
6538 |
return; |
|
6539 |
||
6540 |
Q3ListView *lv = listView(); |
|
6541 |
if (!lv) |
|
6542 |
return; |
|
6543 |
||
6544 |
const QPalette::ColorRole crole = lv->backgroundRole(); |
|
6545 |
if (cg.brush(crole) != lv->palette().brush(cg.currentColorGroup(), crole)) |
|
6546 |
p->fillRect(0, 0, width, height(), cg.brush(crole)); |
|
6547 |
else |
|
6548 |
lv->paintEmptyArea(p, QRect(0, 0, width, height())); |
|
6549 |
||
6550 |
if (column != 0) { |
|
6551 |
// The rest is text, or for subclasses to change. |
|
6552 |
Q3ListViewItem::paintCell(p, cg, column, width, align); |
|
6553 |
return; |
|
6554 |
} |
|
6555 |
||
6556 |
bool parentControl = false; |
|
6557 |
if (parent() && parent()->rtti() == 1 && |
|
6558 |
((Q3CheckListItem*) parent())->type() == RadioButtonController) |
|
6559 |
parentControl = true; |
|
6560 |
||
6561 |
QFontMetrics fm(lv->fontMetrics()); |
|
6562 |
int boxsize = lv->style()->pixelMetric(myType == RadioButtonController ? QStyle::PM_CheckListControllerSize : |
|
6563 |
QStyle::PM_CheckListButtonSize, 0, lv); |
|
6564 |
int marg = lv->itemMargin(); |
|
6565 |
int r = marg; |
|
6566 |
||
6567 |
// Draw controller / check box / radio button --------------------- |
|
6568 |
QStyle::State styleflags = QStyle::State_None; |
|
6569 |
if (internalState() == On) { |
|
6570 |
styleflags |= QStyle::State_On; |
|
6571 |
} else if (internalState() == NoChange) { |
|
6572 |
if (myType == CheckBoxController && !isTristate()) |
|
6573 |
styleflags |= QStyle::State_Off; |
|
6574 |
else |
|
6575 |
styleflags |= QStyle::State_NoChange; |
|
6576 |
} else { |
|
6577 |
styleflags |= QStyle::State_Off; |
|
6578 |
} |
|
6579 |
if (isSelected()) |
|
6580 |
styleflags |= QStyle::State_Selected; |
|
6581 |
if (isEnabled() && lv->isEnabled()) |
|
6582 |
styleflags |= QStyle::State_Enabled; |
|
6583 |
if (lv->window()->isActiveWindow()) |
|
6584 |
styleflags |= QStyle::State_Active; |
|
6585 |
||
6586 |
if (myType == RadioButtonController) { |
|
6587 |
int x = 0; |
|
6588 |
if(!parentControl) |
|
6589 |
x += 3; |
|
6590 |
if (!pixmap(0)) { |
|
6591 |
QStyleOptionQ3ListView opt = getStyleOption(lv, this); |
|
6592 |
opt.rect.setRect(x, 0, boxsize, fm.height() + 2 + marg); |
|
6593 |
opt.palette = cg; |
|
6594 |
opt.state = styleflags; |
|
6595 |
lv->style()->drawPrimitive(QStyle::PE_Q3CheckListController, &opt, p, lv); |
|
6596 |
r += boxsize + 4; |
|
6597 |
} |
|
6598 |
} else { |
|
6599 |
Q_ASSERT(lv); //### |
|
6600 |
int x = 0; |
|
6601 |
int y = 0; |
|
6602 |
if (!parentControl) |
|
6603 |
x += 3; |
|
6604 |
if (align & Qt::AlignVCenter) |
|
6605 |
y = ((height() - boxsize) / 2) + marg; |
|
6606 |
else |
|
6607 |
y = (fm.height() + 2 + marg - boxsize) / 2; |
|
6608 |
||
6609 |
QStyleOptionQ3ListView opt = getStyleOption(lv, this); |
|
6610 |
opt.rect.setRect(x, y, boxsize, fm.height() + 2 + marg); |
|
6611 |
opt.palette = cg; |
|
6612 |
opt.state = styleflags; |
|
6613 |
lv->style()->drawPrimitive((myType == CheckBox || myType == CheckBoxController) |
|
6614 |
? QStyle::PE_Q3CheckListIndicator |
|
6615 |
: QStyle::PE_Q3CheckListExclusiveIndicator, &opt, p, lv); |
|
6616 |
r += boxsize + 4; |
|
6617 |
} |
|
6618 |
||
6619 |
// Draw text ---------------------------------------------------- |
|
6620 |
p->translate(r, 0); |
|
6621 |
p->setPen(QPen(cg.text())); |
|
6622 |
Q3ListViewItem::paintCell(p, cg, column, width - r, align); |
|
6623 |
} |
|
6624 |
||
6625 |
/*! |
|
6626 |
Draws the focus rectangle \a r using the color group \a cg on the |
|
6627 |
painter \a p. |
|
6628 |
*/ |
|
6629 |
void Q3CheckListItem::paintFocus(QPainter *p, const QColorGroup & cg, |
|
6630 |
const QRect & r) |
|
6631 |
{ |
|
6632 |
bool intersect = true; |
|
6633 |
Q3ListView *lv = listView(); |
|
6634 |
if (lv && lv->header()->mapToActual(0) != 0) { |
|
6635 |
int xdepth = lv->treeStepSize() * (depth() + (lv->rootIsDecorated() ? 1 : 0)) + lv->itemMargin(); |
|
6636 |
int p = lv->header()->cellPos(lv->header()->mapToActual(0)); |
|
6637 |
xdepth += p; |
|
6638 |
intersect = r.intersects(QRect(p, r.y(), xdepth - p + 1, r.height())); |
|
6639 |
} |
|
6640 |
bool parentControl = false; |
|
6641 |
if (parent() && parent()->rtti() == 1 && |
|
6642 |
((Q3CheckListItem*) parent())->type() == RadioButtonController) |
|
6643 |
parentControl = true; |
|
6644 |
if (myType != RadioButtonController && intersect && |
|
6645 |
(lv->rootIsDecorated() || myType == RadioButton || |
|
6646 |
(myType == CheckBox && parentControl))) { |
|
6647 |
QRect rect; |
|
6648 |
int boxsize = lv->style()->pixelMetric(QStyle::PM_CheckListButtonSize, 0, lv); |
|
6649 |
if (lv->columnAlignment(0) == Qt::AlignCenter) { |
|
6650 |
QFontMetrics fm(lv->font()); |
|
6651 |
int bx = (lv->columnWidth(0) - (boxsize + fm.width(text())))/2 + boxsize; |
|
6652 |
if (bx < 0) bx = 0; |
|
6653 |
rect.setRect(r.x() + bx + 5, r.y(), r.width() - bx - 5, |
|
6654 |
r.height()); |
|
6655 |
} else |
|
6656 |
rect.setRect(r.x() + boxsize + 5, r.y(), r.width() - boxsize - 5, |
|
6657 |
r.height()); |
|
6658 |
Q3ListViewItem::paintFocus(p, cg, rect); |
|
6659 |
} else { |
|
6660 |
Q3ListViewItem::paintFocus(p, cg, r); |
|
6661 |
} |
|
6662 |
} |
|
6663 |
||
6664 |
/*! |
|
6665 |
\reimp |
|
6666 |
*/ |
|
6667 |
QSize Q3ListView::sizeHint() const |
|
6668 |
{ |
|
6669 |
if (cachedSizeHint().isValid()) |
|
6670 |
return cachedSizeHint(); |
|
6671 |
||
6672 |
ensurePolished(); |
|
6673 |
||
6674 |
if (!isVisible() && d->drawables.isEmpty()) |
|
6675 |
// force the column widths to sanity, if possible |
|
6676 |
buildDrawableList(); |
|
6677 |
||
6678 |
QSize s(d->h->sizeHint()); |
|
6679 |
if (verticalScrollBar()->isVisible()) |
|
6680 |
s.setWidth(s.width() + style()->pixelMetric(QStyle::PM_ScrollBarExtent)); |
|
6681 |
s += QSize(frameWidth()*2,frameWidth()*2); |
|
6682 |
Q3ListViewItem * l = d->r; |
|
6683 |
while(l && !l->height()) |
|
6684 |
l = l->childItem ? l->childItem : l->siblingItem; |
|
6685 |
||
6686 |
if (l && l->height()) |
|
6687 |
s.setHeight(s.height() + 10 * l->height()); |
|
6688 |
else |
|
6689 |
s.setHeight(s.height() + 140); |
|
6690 |
||
6691 |
if (s.width() > s.height() * 3) |
|
6692 |
s.setHeight(s.width() / 3); |
|
6693 |
else if (s.width() *3 < s.height()) |
|
6694 |
s.setHeight(s.width() * 3); |
|
6695 |
||
6696 |
setCachedSizeHint(s); |
|
6697 |
||
6698 |
return s; |
|
6699 |
} |
|
6700 |
||
6701 |
||
6702 |
/*! |
|
6703 |
\reimp |
|
6704 |
*/ |
|
6705 |
||
6706 |
QSize Q3ListView::minimumSizeHint() const |
|
6707 |
{ |
|
6708 |
return Q3ScrollView::minimumSizeHint(); |
|
6709 |
} |
|
6710 |
||
6711 |
||
6712 |
/*! |
|
6713 |
Sets \a item to be open if \a open is true and \a item is |
|
6714 |
expandable, and to be closed if \a open is false. Repaints |
|
6715 |
accordingly. |
|
6716 |
||
6717 |
\sa Q3ListViewItem::setOpen() Q3ListViewItem::setExpandable() |
|
6718 |
*/ |
|
6719 |
||
6720 |
void Q3ListView::setOpen(Q3ListViewItem * item, bool open) |
|
6721 |
{ |
|
6722 |
if (!item || |
|
6723 |
item->isOpen() == open || |
|
6724 |
(open && !item->childCount() && !item->isExpandable())) |
|
6725 |
return; |
|
6726 |
||
6727 |
Q3ListViewItem* nextParent = 0; |
|
6728 |
if (open) |
|
6729 |
nextParent = item->itemBelow(); |
|
6730 |
||
6731 |
item->setOpen(open); |
|
6732 |
||
6733 |
if (open) { |
|
6734 |
Q3ListViewItem* lastChild = item; |
|
6735 |
Q3ListViewItem* tmp; |
|
6736 |
while (true) { |
|
6737 |
tmp = lastChild->itemBelow(); |
|
6738 |
if (!tmp || tmp == nextParent) |
|
6739 |
break; |
|
6740 |
lastChild = tmp; |
|
6741 |
} |
|
6742 |
ensureItemVisible(lastChild); |
|
6743 |
ensureItemVisible(item); |
|
6744 |
} |
|
6745 |
buildDrawableList(); |
|
6746 |
||
6747 |
int i = 0; |
|
6748 |
for (; i < d->drawables.size(); ++i) { |
|
6749 |
const Q3ListViewPrivate::DrawableItem &c = d->drawables.at(i); |
|
6750 |
if(c.i == item) |
|
6751 |
break; |
|
6752 |
} |
|
6753 |
||
6754 |
if (i < d->drawables.size()) { |
|
6755 |
d->dirtyItemTimer->start(0, true); |
|
6756 |
for (; i < d->drawables.size(); ++i) { |
|
6757 |
const Q3ListViewPrivate::DrawableItem &c = d->drawables.at(i); |
|
6758 |
d->dirtyItems.append(c.i); |
|
6759 |
} |
|
6760 |
} |
|
6761 |
} |
|
6762 |
||
6763 |
||
6764 |
/*! |
|
6765 |
Returns true if this list view item has children \e and they are |
|
6766 |
not explicitly hidden; otherwise returns false. |
|
6767 |
||
6768 |
Identical to \a{item}->isOpen(). Provided for completeness. |
|
6769 |
||
6770 |
\sa setOpen() |
|
6771 |
*/ |
|
6772 |
||
6773 |
bool Q3ListView::isOpen(const Q3ListViewItem * item) const |
|
6774 |
{ |
|
6775 |
return item->isOpen(); |
|
6776 |
} |
|
6777 |
||
6778 |
||
6779 |
/*! |
|
6780 |
\property Q3ListView::rootIsDecorated |
|
6781 |
\brief whether the list view shows open/close signs on root items |
|
6782 |
||
6783 |
Open/close signs are small \bold{+} or \bold{-} symbols in windows |
|
6784 |
style, or arrows in Motif style. The default is false. |
|
6785 |
*/ |
|
6786 |
||
6787 |
void Q3ListView::setRootIsDecorated(bool enable) |
|
6788 |
{ |
|
6789 |
if (enable != (bool)d->rootIsExpandable) { |
|
6790 |
d->rootIsExpandable = enable; |
|
6791 |
if (isVisible()) |
|
6792 |
triggerUpdate(); |
|
6793 |
} |
|
6794 |
} |
|
6795 |
||
6796 |
bool Q3ListView::rootIsDecorated() const |
|
6797 |
{ |
|
6798 |
return d->rootIsExpandable; |
|
6799 |
} |
|
6800 |
||
6801 |
||
6802 |
/*! |
|
6803 |
Ensures that item \a i is visible, scrolling the list view |
|
6804 |
vertically if necessary and opening (expanding) any parent items |
|
6805 |
if this is required to show the item. |
|
6806 |
||
6807 |
\sa itemRect() Q3ScrollView::ensureVisible() |
|
6808 |
*/ |
|
6809 |
||
6810 |
void Q3ListView::ensureItemVisible(const Q3ListViewItem * i) |
|
6811 |
{ |
|
6812 |
if (!i || !i->isVisible()) |
|
6813 |
return; |
|
6814 |
||
6815 |
Q3ListViewItem *parent = i->parent(); |
|
6816 |
while (parent) { |
|
6817 |
if (!parent->isOpen()) |
|
6818 |
parent->setOpen(true); |
|
6819 |
parent = parent->parent(); |
|
6820 |
} |
|
6821 |
||
6822 |
if (d->r->maybeTotalHeight < 0) |
|
6823 |
updateGeometries(); |
|
6824 |
int y = itemPos(i); |
|
6825 |
int h = i->height(); |
|
6826 |
if (isVisible() && y + h > contentsY() + visibleHeight()) |
|
6827 |
setContentsPos(contentsX(), y - visibleHeight() + h); |
|
6828 |
else if (!isVisible() || y < contentsY()) |
|
6829 |
setContentsPos(contentsX(), y); |
|
6830 |
} |
|
6831 |
||
6832 |
||
6833 |
/*! |
|
6834 |
\fn QString Q3CheckListItem::text(int n) const |
|
6835 |
||
6836 |
\reimp |
|
6837 |
*/ |
|
6838 |
||
6839 |
/*! |
|
6840 |
Returns the Q3Header object that manages this list view's columns. |
|
6841 |
Please don't modify the header behind the list view's back. |
|
6842 |
||
6843 |
You may safely call Q3Header::setClickEnabled(), |
|
6844 |
Q3Header::setResizeEnabled(), Q3Header::setMovingEnabled(), |
|
6845 |
Q3Header::hide() and all the const Q3Header functions. |
|
6846 |
*/ |
|
6847 |
||
6848 |
Q3Header * Q3ListView::header() const |
|
6849 |
{ |
|
6850 |
return d->h; |
|
6851 |
} |
|
6852 |
||
6853 |
||
6854 |
/*! |
|
6855 |
\property Q3ListView::childCount |
|
6856 |
\brief the number of parentless (top-level) Q3ListViewItem objects in this Q3ListView |
|
6857 |
||
6858 |
Holds the current number of parentless (top-level) Q3ListViewItem |
|
6859 |
objects in this Q3ListView. |
|
6860 |
||
6861 |
\sa Q3ListViewItem::childCount() |
|
6862 |
*/ |
|
6863 |
||
6864 |
int Q3ListView::childCount() const |
|
6865 |
{ |
|
6866 |
if (d->r) |
|
6867 |
return d->r->childCount(); |
|
6868 |
return 0; |
|
6869 |
} |
|
6870 |
||
6871 |
||
6872 |
/* |
|
6873 |
Moves this item to just after \a olderSibling. \a olderSibling and |
|
6874 |
this object must have the same parent. |
|
6875 |
||
6876 |
If you need to move an item in the hierarchy use takeItem() and |
|
6877 |
insertItem(). |
|
6878 |
*/ |
|
6879 |
||
6880 |
void Q3ListViewItem::moveToJustAfter(Q3ListViewItem * olderSibling) |
|
6881 |
{ |
|
6882 |
if (parentItem && olderSibling && |
|
6883 |
olderSibling->parentItem == parentItem && olderSibling != this) { |
|
6884 |
if (parentItem->childItem == this) { |
|
6885 |
parentItem->childItem = siblingItem; |
|
6886 |
} else { |
|
6887 |
Q3ListViewItem * i = parentItem->childItem; |
|
6888 |
while(i && i->siblingItem != this) |
|
6889 |
i = i->siblingItem; |
|
6890 |
if (i) |
|
6891 |
i->siblingItem = siblingItem; |
|
6892 |
} |
|
6893 |
siblingItem = olderSibling->siblingItem; |
|
6894 |
olderSibling->siblingItem = this; |
|
6895 |
parentItem->lsc = Unsorted; |
|
6896 |
} |
|
6897 |
} |
|
6898 |
||
6899 |
/*! |
|
6900 |
Move the item to be after item \a after, which must be one of the |
|
6901 |
item's siblings. To move an item in the hierarchy, use takeItem() |
|
6902 |
and insertItem(). |
|
6903 |
||
6904 |
Note that this function will have no effect if sorting is enabled |
|
6905 |
in the list view. |
|
6906 |
*/ |
|
6907 |
||
6908 |
void Q3ListViewItem::moveItem(Q3ListViewItem *after) |
|
6909 |
{ |
|
6910 |
if (!after || after == this) |
|
6911 |
return; |
|
6912 |
if (parent() != after->parent()) { |
|
6913 |
if (parentItem) |
|
6914 |
parentItem->takeItem(this); |
|
6915 |
if (after->parentItem) { |
|
6916 |
int tmpLsc = after->parentItem->lsc; |
|
6917 |
after->parentItem->insertItem(this); |
|
6918 |
after->parentItem->lsc = tmpLsc; |
|
6919 |
} |
|
6920 |
} |
|
6921 |
moveToJustAfter(after); |
|
6922 |
Q3ListView *lv = listView(); |
|
6923 |
if (lv) |
|
6924 |
lv->triggerUpdate(); |
|
6925 |
} |
|
6926 |
||
6927 |
/* |
|
6928 |
Recursively sorts items, from the root to this item. |
|
6929 |
(enforceSortOrder() won't work the other way around, as |
|
6930 |
documented.) |
|
6931 |
*/ |
|
6932 |
void Q3ListViewItem::enforceSortOrderBackToRoot() |
|
6933 |
{ |
|
6934 |
if (parentItem) { |
|
6935 |
parentItem->enforceSortOrderBackToRoot(); |
|
6936 |
parentItem->enforceSortOrder(); |
|
6937 |
} |
|
6938 |
} |
|
6939 |
||
6940 |
/*! |
|
6941 |
\reimp |
|
6942 |
*/ |
|
6943 |
void Q3ListView::showEvent(QShowEvent *) |
|
6944 |
{ |
|
6945 |
d->drawables.clear(); |
|
6946 |
d->dirtyItems.clear(); |
|
6947 |
d->dirtyItemTimer->stop(); |
|
6948 |
d->fullRepaintOnComlumnChange = true; |
|
6949 |
||
6950 |
updateGeometries(); |
|
6951 |
} |
|
6952 |
||
6953 |
||
6954 |
/*! |
|
6955 |
Returns the y coordinate of this item in the list view's |
|
6956 |
coordinate system. This function is normally much slower than |
|
6957 |
Q3ListView::itemAt(), but it works for all items whereas |
|
6958 |
Q3ListView::itemAt() normally only works for items on the screen. |
|
6959 |
||
6960 |
\sa Q3ListView::itemAt() Q3ListView::itemRect() Q3ListView::itemPos() |
|
6961 |
*/ |
|
6962 |
||
6963 |
int Q3ListViewItem::itemPos() const |
|
6964 |
{ |
|
6965 |
QStack<Q3ListViewItem *> s; |
|
6966 |
Q3ListViewItem * i = (Q3ListViewItem *)this; |
|
6967 |
while(i) { |
|
6968 |
s.push(i); |
|
6969 |
i = i->parentItem; |
|
6970 |
} |
|
6971 |
||
6972 |
int a = 0; |
|
6973 |
Q3ListViewItem * p = 0; |
|
6974 |
while(s.count()) { |
|
6975 |
i = s.pop(); |
|
6976 |
if (p) { |
|
6977 |
if (!p->configured) { |
|
6978 |
p->configured = true; |
|
6979 |
p->setup(); // ### virtual non-const function called in const |
|
6980 |
} |
|
6981 |
a += p->height(); |
|
6982 |
Q3ListViewItem * s = p->firstChild(); |
|
6983 |
while(s && s != i) { |
|
6984 |
a += s->totalHeight(); |
|
6985 |
s = s->nextSibling(); |
|
6986 |
} |
|
6987 |
} |
|
6988 |
p = i; |
|
6989 |
} |
|
6990 |
return a; |
|
6991 |
} |
|
6992 |
||
6993 |
||
6994 |
/*! |
|
6995 |
\fn void Q3ListView::removeItem(Q3ListViewItem *item) |
|
6996 |
||
6997 |
Removes the given \a item. Use takeItem() instead. |
|
6998 |
*/ |
|
6999 |
||
7000 |
/*! |
|
7001 |
Removes item \a i from the list view; \a i must be a top-level |
|
7002 |
item. The warnings regarding Q3ListViewItem::takeItem() apply to |
|
7003 |
this function, too. |
|
7004 |
||
7005 |
\sa insertItem() |
|
7006 |
*/ |
|
7007 |
void Q3ListView::takeItem(Q3ListViewItem * i) |
|
7008 |
{ |
|
7009 |
if (d->r) |
|
7010 |
d->r->takeItem(i); |
|
7011 |
} |
|
7012 |
||
7013 |
||
7014 |
void Q3ListView::openFocusItem() |
|
7015 |
{ |
|
7016 |
d->autoopenTimer->stop(); |
|
7017 |
if (d->focusItem && !d->focusItem->isOpen()) { |
|
7018 |
d->focusItem->setOpen(true); |
|
7019 |
d->focusItem->repaint(); |
|
7020 |
} |
|
7021 |
} |
|
7022 |
||
7023 |
static const int autoopenTime = 750; |
|
7024 |
||
7025 |
#ifndef QT_NO_DRAGANDDROP |
|
7026 |
||
7027 |
/*! \reimp */ |
|
7028 |
||
7029 |
void Q3ListView::contentsDragEnterEvent(QDragEnterEvent *e) |
|
7030 |
{ |
|
7031 |
d->oldFocusItem = d->focusItem; |
|
7032 |
Q3ListViewItem *i = d->focusItem; |
|
7033 |
d->focusItem = itemAt(contentsToViewport(e->pos())); |
|
7034 |
if (i) |
|
7035 |
i->repaint(); |
|
7036 |
if (d->focusItem) { |
|
7037 |
d->autoopenTimer->start(autoopenTime); |
|
7038 |
d->focusItem->dragEntered(); |
|
7039 |
d->focusItem->repaint(); |
|
7040 |
} |
|
7041 |
e->accept(); |
|
7042 |
} |
|
7043 |
||
7044 |
/*! \reimp */ |
|
7045 |
||
7046 |
void Q3ListView::contentsDragMoveEvent(QDragMoveEvent *e) |
|
7047 |
{ |
|
7048 |
Q3ListViewItem *i = d->focusItem; |
|
7049 |
d->focusItem = itemAt(contentsToViewport(e->pos())); |
|
7050 |
if (i) { |
|
7051 |
if (i != d->focusItem) |
|
7052 |
i->dragLeft(); |
|
7053 |
i->repaint(); |
|
7054 |
} |
|
7055 |
if (d->focusItem) { |
|
7056 |
if (i != d->focusItem) { |
|
7057 |
d->focusItem->dragEntered(); |
|
7058 |
d->autoopenTimer->stop(); |
|
7059 |
d->autoopenTimer->start(autoopenTime); |
|
7060 |
} |
|
7061 |
d->focusItem->repaint(); |
|
7062 |
} else { |
|
7063 |
d->autoopenTimer->stop(); |
|
7064 |
} |
|
7065 |
if ((i && i->dropEnabled() && i->acceptDrop(e)) || acceptDrops()) |
|
7066 |
e->accept(); |
|
7067 |
else |
|
7068 |
e->ignore(); |
|
7069 |
} |
|
7070 |
||
7071 |
/*! \reimp */ |
|
7072 |
||
7073 |
void Q3ListView::contentsDragLeaveEvent(QDragLeaveEvent *) |
|
7074 |
{ |
|
7075 |
d->autoopenTimer->stop(); |
|
7076 |
||
7077 |
if (d->focusItem) |
|
7078 |
d->focusItem->dragLeft(); |
|
7079 |
||
7080 |
setCurrentItem(d->oldFocusItem); |
|
7081 |
d->oldFocusItem = 0; |
|
7082 |
} |
|
7083 |
||
7084 |
/*! \reimp */ |
|
7085 |
||
7086 |
void Q3ListView::contentsDropEvent(QDropEvent *e) |
|
7087 |
{ |
|
7088 |
d->autoopenTimer->stop(); |
|
7089 |
||
7090 |
setCurrentItem(d->oldFocusItem); |
|
7091 |
Q3ListViewItem *i = itemAt(contentsToViewport(e->pos())); |
|
7092 |
if (i && i->dropEnabled() && i->acceptDrop(e)) { |
|
7093 |
i->dropped(e); |
|
7094 |
e->accept(); |
|
7095 |
} else if (acceptDrops()) { |
|
7096 |
emit dropped(e); |
|
7097 |
e->accept(); |
|
7098 |
} |
|
7099 |
} |
|
7100 |
||
7101 |
/*! |
|
7102 |
If the user presses the mouse on an item and starts moving the |
|
7103 |
mouse, and the item allow dragging (see |
|
7104 |
Q3ListViewItem::setDragEnabled()), this function is called to get a |
|
7105 |
drag object and a drag is started unless dragObject() returns 0. |
|
7106 |
||
7107 |
By default this function returns 0. You should reimplement it and |
|
7108 |
create a Q3DragObject depending on the selected items. |
|
7109 |
*/ |
|
7110 |
||
7111 |
Q3DragObject *Q3ListView::dragObject() |
|
7112 |
{ |
|
7113 |
return 0; |
|
7114 |
} |
|
7115 |
||
7116 |
/*! |
|
7117 |
Starts a drag. |
|
7118 |
*/ |
|
7119 |
||
7120 |
void Q3ListView::startDrag() |
|
7121 |
{ |
|
7122 |
if (!d->startDragItem) |
|
7123 |
return; |
|
7124 |
||
7125 |
d->startDragItem = 0; |
|
7126 |
d->buttonDown = false; |
|
7127 |
||
7128 |
Q3DragObject *drag = dragObject(); |
|
7129 |
if (!drag) |
|
7130 |
return; |
|
7131 |
||
7132 |
drag->drag(); |
|
7133 |
} |
|
7134 |
||
7135 |
#endif // QT_NO_DRAGANDDROP |
|
7136 |
||
7137 |
/*! |
|
7138 |
\property Q3ListView::defaultRenameAction |
|
7139 |
\brief What action to perform when the editor loses focus during renaming |
|
7140 |
||
7141 |
If this property is \c Accept, and the user renames an item and |
|
7142 |
the editor loses focus (without the user pressing Enter), the |
|
7143 |
item will still be renamed. If the property's value is \c Reject, |
|
7144 |
the item will not be renamed unless the user presses Enter. The |
|
7145 |
default is \c Reject. |
|
7146 |
*/ |
|
7147 |
||
7148 |
void Q3ListView::setDefaultRenameAction(RenameAction a) |
|
7149 |
{ |
|
7150 |
d->defRenameAction = a; |
|
7151 |
} |
|
7152 |
||
7153 |
Q3ListView::RenameAction Q3ListView::defaultRenameAction() const |
|
7154 |
{ |
|
7155 |
return d->defRenameAction; |
|
7156 |
} |
|
7157 |
||
7158 |
/*! |
|
7159 |
Returns true if an item is being renamed; otherwise returns false. |
|
7160 |
*/ |
|
7161 |
||
7162 |
bool Q3ListView::isRenaming() const |
|
7163 |
{ |
|
7164 |
return currentItem() && currentItem()->renameBox; |
|
7165 |
} |
|
7166 |
||
7167 |
/********************************************************************** |
|
7168 |
* |
|
7169 |
* Class Q3ListViewItemIterator |
|
7170 |
* |
|
7171 |
**********************************************************************/ |
|
7172 |
||
7173 |
||
7174 |
/*! |
|
7175 |
\class Q3ListViewItemIterator |
|
7176 |
\brief The Q3ListViewItemIterator class provides an iterator for collections of Q3ListViewItems. |
|
7177 |
||
7178 |
\compat |
|
7179 |
||
7180 |
Construct an instance of a Q3ListViewItemIterator, with either a |
|
7181 |
Q3ListView* or a Q3ListViewItem* as argument, to operate on the tree |
|
7182 |
of Q3ListViewItems, starting from the argument. |
|
7183 |
||
7184 |
A Q3ListViewItemIterator iterates over all the items from its |
|
7185 |
starting point. This means that it always makes the first child of |
|
7186 |
the current item the new current item. If there is no child, the |
|
7187 |
next sibling becomes the new current item; and if there is no next |
|
7188 |
sibling, the next sibling of the parent becomes current. |
|
7189 |
||
7190 |
The following example creates a list of all the items that have |
|
7191 |
been selected by the user, storing pointers to the items in a |
|
7192 |
QList: |
|
7193 |
\snippet doc/src/snippets/code/src_qt3support_itemviews_q3listview.cpp 6 |
|
7194 |
||
7195 |
An alternative approach is to use an \c IteratorFlag: |
|
7196 |
\snippet doc/src/snippets/code/src_qt3support_itemviews_q3listview.cpp 7 |
|
7197 |
||
7198 |
A Q3ListViewItemIterator provides a convenient and easy way to |
|
7199 |
traverse a hierarchical Q3ListView. |
|
7200 |
||
7201 |
Multiple Q3ListViewItemIterators can operate on the tree of |
|
7202 |
Q3ListViewItems. A Q3ListView knows about all iterators operating on |
|
7203 |
its Q3ListViewItems. So when a Q3ListViewItem gets removed all |
|
7204 |
iterators that point to this item are updated and point to the |
|
7205 |
following item if possible, otherwise to a valid item before the |
|
7206 |
current one or to 0. Note however that deleting the parent item of |
|
7207 |
an item that an iterator points to is not safe. |
|
7208 |
||
7209 |
\sa Q3ListView, Q3ListViewItem |
|
7210 |
*/ |
|
7211 |
||
7212 |
/*! |
|
7213 |
\enum Q3ListViewItemIterator::IteratorFlag |
|
7214 |
||
7215 |
These flags can be passed to a Q3ListViewItemIterator constructor |
|
7216 |
(OR-ed together if more than one is used), so that the iterator |
|
7217 |
will only iterate over items that match the given flags. |
|
7218 |
||
7219 |
\value Visible |
|
7220 |
\value Invisible |
|
7221 |
\value Selected |
|
7222 |
\value Unselected |
|
7223 |
\value Selectable |
|
7224 |
\value NotSelectable |
|
7225 |
\value DragEnabled |
|
7226 |
\value DragDisabled |
|
7227 |
\value DropEnabled |
|
7228 |
\value DropDisabled |
|
7229 |
\value Expandable |
|
7230 |
\value NotExpandable |
|
7231 |
\value Checked |
|
7232 |
\value NotChecked |
|
7233 |
*/ |
|
7234 |
||
7235 |
/*! |
|
7236 |
Constructs an empty iterator. |
|
7237 |
*/ |
|
7238 |
||
7239 |
Q3ListViewItemIterator::Q3ListViewItemIterator() |
|
7240 |
: curr(0), listView(0), flags(0) |
|
7241 |
{ |
|
7242 |
} |
|
7243 |
||
7244 |
/*! |
|
7245 |
Constructs an iterator for the Q3ListView that contains the \a |
|
7246 |
item. The current iterator item is set to point to the \a item. |
|
7247 |
*/ |
|
7248 |
||
7249 |
Q3ListViewItemIterator::Q3ListViewItemIterator(Q3ListViewItem *item) |
|
7250 |
: curr(item), listView(0), flags(0) |
|
7251 |
{ |
|
7252 |
if (item) { |
|
7253 |
item->enforceSortOrderBackToRoot(); |
|
7254 |
listView = item->listView(); |
|
7255 |
} |
|
7256 |
if (listView) |
|
7257 |
listView->d->iterators.append(this); |
|
7258 |
} |
|
7259 |
||
7260 |
/*! |
|
7261 |
Constructs an iterator for the Q3ListView that contains the \a item |
|
7262 |
using the flags \a iteratorFlags. The current iterator item is set |
|
7263 |
to point to \a item or the next matching item if \a item doesn't |
|
7264 |
match the flags. |
|
7265 |
||
7266 |
\sa Q3ListViewItemIterator::IteratorFlag |
|
7267 |
*/ |
|
7268 |
||
7269 |
Q3ListViewItemIterator::Q3ListViewItemIterator(Q3ListViewItem *item, int iteratorFlags) |
|
7270 |
: curr(item), listView(0), flags(iteratorFlags) |
|
7271 |
{ |
|
7272 |
// go to next matching item if the current don't match |
|
7273 |
if (curr && !matchesFlags(curr)) |
|
7274 |
++(*this); |
|
7275 |
||
7276 |
if (curr) { |
|
7277 |
curr->enforceSortOrderBackToRoot(); |
|
7278 |
listView = curr->listView(); |
|
7279 |
} |
|
7280 |
if (listView) |
|
7281 |
listView->d->iterators.append(this); |
|
7282 |
} |
|
7283 |
||
7284 |
||
7285 |
/*! |
|
7286 |
Constructs an iterator for the same Q3ListView as \a it. The |
|
7287 |
current iterator item is set to point on the current item of \a |
|
7288 |
it. |
|
7289 |
*/ |
|
7290 |
||
7291 |
Q3ListViewItemIterator::Q3ListViewItemIterator(const Q3ListViewItemIterator& it) |
|
7292 |
: curr(it.curr), listView(it.listView), flags(it.flags) |
|
7293 |
{ |
|
7294 |
if (listView) |
|
7295 |
listView->d->iterators.append(this); |
|
7296 |
} |
|
7297 |
||
7298 |
/*! |
|
7299 |
Constructs an iterator for the Q3ListView \a lv. The current |
|
7300 |
iterator item is set to point on the first child (Q3ListViewItem) |
|
7301 |
of \a lv. |
|
7302 |
*/ |
|
7303 |
||
7304 |
Q3ListViewItemIterator::Q3ListViewItemIterator(Q3ListView *lv) |
|
7305 |
: curr(lv->firstChild()), listView(lv), flags(0) |
|
7306 |
{ |
|
7307 |
if (listView) |
|
7308 |
listView->d->iterators.append(this); |
|
7309 |
} |
|
7310 |
||
7311 |
/*! |
|
7312 |
Constructs an iterator for the Q3ListView \a lv with the flags \a |
|
7313 |
iteratorFlags. The current iterator item is set to point on the |
|
7314 |
first child (Q3ListViewItem) of \a lv that matches the flags. |
|
7315 |
||
7316 |
\sa Q3ListViewItemIterator::IteratorFlag |
|
7317 |
*/ |
|
7318 |
||
7319 |
Q3ListViewItemIterator::Q3ListViewItemIterator(Q3ListView *lv, int iteratorFlags) |
|
7320 |
: curr (lv->firstChild()), listView(lv), flags(iteratorFlags) |
|
7321 |
{ |
|
7322 |
if (listView) |
|
7323 |
listView->d->iterators.append(this); |
|
7324 |
if (!matchesFlags(curr)) |
|
7325 |
++(*this); |
|
7326 |
} |
|
7327 |
||
7328 |
||
7329 |
||
7330 |
/*! |
|
7331 |
Assignment. Makes a copy of \a it and returns a reference to its |
|
7332 |
iterator. |
|
7333 |
*/ |
|
7334 |
||
7335 |
Q3ListViewItemIterator &Q3ListViewItemIterator::operator=(const Q3ListViewItemIterator &it) |
|
7336 |
{ |
|
7337 |
if (listView) |
|
7338 |
listView->d->iterators.removeAll(this); |
|
7339 |
||
7340 |
listView = it.listView; |
|
7341 |
curr = it.curr; |
|
7342 |
flags = it.flags; |
|
7343 |
if (listView) |
|
7344 |
listView->d->iterators.append(this); |
|
7345 |
||
7346 |
// go to next matching item if the current don't match |
|
7347 |
if (curr && !matchesFlags(curr)) |
|
7348 |
++(*this); |
|
7349 |
||
7350 |
return *this; |
|
7351 |
} |
|
7352 |
||
7353 |
/*! |
|
7354 |
Destroys the iterator. |
|
7355 |
*/ |
|
7356 |
||
7357 |
Q3ListViewItemIterator::~Q3ListViewItemIterator() |
|
7358 |
{ |
|
7359 |
if (listView) |
|
7360 |
listView->d->iterators.removeAll(this); |
|
7361 |
} |
|
7362 |
||
7363 |
/*! |
|
7364 |
Prefix ++. Makes the next item the new current item and returns |
|
7365 |
it. Returns 0 if the current item is the last item or the |
|
7366 |
Q3ListView is 0. |
|
7367 |
*/ |
|
7368 |
||
7369 |
Q3ListViewItemIterator &Q3ListViewItemIterator::operator++() |
|
7370 |
{ |
|
7371 |
if (!curr) |
|
7372 |
return *this; |
|
7373 |
||
7374 |
Q3ListViewItem *item = curr->firstChild(); |
|
7375 |
if (!item) { |
|
7376 |
while ((item = curr->nextSibling()) == 0 ) { |
|
7377 |
curr = curr->parent(); |
|
7378 |
if (curr == 0) |
|
7379 |
break; |
|
7380 |
} |
|
7381 |
} |
|
7382 |
curr = item; |
|
7383 |
// if the next one doesn't match the flags we try one more ahead |
|
7384 |
if (curr && !matchesFlags(curr)) |
|
7385 |
++(*this); |
|
7386 |
return *this; |
|
7387 |
} |
|
7388 |
||
7389 |
/*! |
|
7390 |
\overload |
|
7391 |
||
7392 |
Postfix ++. Makes the next item the new current item and returns |
|
7393 |
the item that \e was the current item. |
|
7394 |
*/ |
|
7395 |
||
7396 |
const Q3ListViewItemIterator Q3ListViewItemIterator::operator++(int) |
|
7397 |
{ |
|
7398 |
Q3ListViewItemIterator oldValue = *this; |
|
7399 |
++(*this); |
|
7400 |
return oldValue; |
|
7401 |
} |
|
7402 |
||
7403 |
/*! |
|
7404 |
Sets the current item to the item \a j positions after the current |
|
7405 |
item. If that item is beyond the last item, the current item is |
|
7406 |
set to 0. Returns the current item. |
|
7407 |
*/ |
|
7408 |
||
7409 |
Q3ListViewItemIterator &Q3ListViewItemIterator::operator+=(int j) |
|
7410 |
{ |
|
7411 |
while (curr && j--) |
|
7412 |
++(*this); |
|
7413 |
||
7414 |
return *this; |
|
7415 |
} |
|
7416 |
||
7417 |
/*! |
|
7418 |
Prefix --. Makes the previous item the new current item and |
|
7419 |
returns it. Returns 0 if the current item is the first item or the |
|
7420 |
Q3ListView is 0. |
|
7421 |
*/ |
|
7422 |
||
7423 |
Q3ListViewItemIterator &Q3ListViewItemIterator::operator--() |
|
7424 |
{ |
|
7425 |
if (!curr) |
|
7426 |
return *this; |
|
7427 |
||
7428 |
if (!curr->parent()) { |
|
7429 |
// we are in the first depth |
|
7430 |
if (curr->listView()) { |
|
7431 |
if (curr->listView()->firstChild() != curr) { |
|
7432 |
// go the previous sibling |
|
7433 |
Q3ListViewItem *i = curr->listView()->firstChild(); |
|
7434 |
while (i && i->siblingItem != curr) |
|
7435 |
i = i->siblingItem; |
|
7436 |
||
7437 |
curr = i; |
|
7438 |
||
7439 |
if (i && i->firstChild()) { |
|
7440 |
// go to the last child of this item |
|
7441 |
Q3ListViewItemIterator it(curr->firstChild()); |
|
7442 |
for (; it.current() && it.current()->parent(); ++it) |
|
7443 |
curr = it.current(); |
|
7444 |
} |
|
7445 |
||
7446 |
if (curr && !matchesFlags(curr)) |
|
7447 |
--(*this); |
|
7448 |
||
7449 |
return *this; |
|
7450 |
} else { |
|
7451 |
//we are already the first child of the list view, so it's over |
|
7452 |
curr = 0; |
|
7453 |
return *this; |
|
7454 |
} |
|
7455 |
} else |
|
7456 |
return *this; |
|
7457 |
} else { |
|
7458 |
Q3ListViewItem *parent = curr->parent(); |
|
7459 |
||
7460 |
if (curr != parent->firstChild()) { |
|
7461 |
// go to the previous sibling |
|
7462 |
Q3ListViewItem *i = parent->firstChild(); |
|
7463 |
while (i && i->siblingItem != curr) |
|
7464 |
i = i->siblingItem; |
|
7465 |
||
7466 |
curr = i; |
|
7467 |
||
7468 |
if (i && i->firstChild()) { |
|
7469 |
// go to the last child of this item |
|
7470 |
Q3ListViewItemIterator it(curr->firstChild()); |
|
7471 |
for (; it.current() && it.current()->parent() != parent; ++it) |
|
7472 |
curr = it.current(); |
|
7473 |
} |
|
7474 |
||
7475 |
if (curr && !matchesFlags(curr)) |
|
7476 |
--(*this); |
|
7477 |
||
7478 |
return *this; |
|
7479 |
} else { |
|
7480 |
// make our parent the current item |
|
7481 |
curr = parent; |
|
7482 |
||
7483 |
if (curr && !matchesFlags(curr)) |
|
7484 |
--(*this); |
|
7485 |
||
7486 |
return *this; |
|
7487 |
} |
|
7488 |
} |
|
7489 |
} |
|
7490 |
||
7491 |
/*! |
|
7492 |
\overload |
|
7493 |
||
7494 |
Postfix --. Makes the previous item the new current item and |
|
7495 |
returns the item that \e was the current item. |
|
7496 |
*/ |
|
7497 |
||
7498 |
const Q3ListViewItemIterator Q3ListViewItemIterator::operator--(int) |
|
7499 |
{ |
|
7500 |
Q3ListViewItemIterator oldValue = *this; |
|
7501 |
--(*this); |
|
7502 |
return oldValue; |
|
7503 |
} |
|
7504 |
||
7505 |
/*! |
|
7506 |
Sets the current item to the item \a j positions before the |
|
7507 |
current item. If that item is before the first item, the current |
|
7508 |
item is set to 0. Returns the current item. |
|
7509 |
*/ |
|
7510 |
||
7511 |
Q3ListViewItemIterator &Q3ListViewItemIterator::operator-=(int j) |
|
7512 |
{ |
|
7513 |
while (curr && j--) |
|
7514 |
--(*this); |
|
7515 |
||
7516 |
return *this; |
|
7517 |
} |
|
7518 |
||
7519 |
/*! |
|
7520 |
Dereference operator. Returns a reference to the current item. The |
|
7521 |
same as current(). |
|
7522 |
*/ |
|
7523 |
||
7524 |
Q3ListViewItem* Q3ListViewItemIterator::operator*() |
|
7525 |
{ |
|
7526 |
if (curr != 0 && !matchesFlags(curr)) |
|
7527 |
qWarning("Q3ListViewItemIterator::operator*() curr out of sync"); |
|
7528 |
return curr; |
|
7529 |
} |
|
7530 |
||
7531 |
/*! |
|
7532 |
Returns iterator's current item. |
|
7533 |
*/ |
|
7534 |
||
7535 |
Q3ListViewItem *Q3ListViewItemIterator::current() const |
|
7536 |
{ |
|
7537 |
if (curr != 0 && !matchesFlags(curr)) |
|
7538 |
qWarning("Q3ListViewItemIterator::current() curr out of sync"); |
|
7539 |
return curr; |
|
7540 |
} |
|
7541 |
||
7542 |
/* |
|
7543 |
This function is called to notify the iterator that the current |
|
7544 |
item has been deleted, and sets the current item point to another |
|
7545 |
(valid) item or 0. |
|
7546 |
*/ |
|
7547 |
||
7548 |
void Q3ListViewItemIterator::currentRemoved() |
|
7549 |
{ |
|
7550 |
if (!curr) return; |
|
7551 |
||
7552 |
if (curr->parent()) |
|
7553 |
curr = curr->parent(); |
|
7554 |
else if (curr->nextSibling()) |
|
7555 |
curr = curr->nextSibling(); |
|
7556 |
else if (listView && listView->firstChild() && |
|
7557 |
listView->firstChild() != curr) |
|
7558 |
curr = listView->firstChild(); |
|
7559 |
else |
|
7560 |
curr = 0; |
|
7561 |
} |
|
7562 |
||
7563 |
/* |
|
7564 |
returns true if the item \a item matches all of the flags set for the iterator |
|
7565 |
*/ |
|
7566 |
bool Q3ListViewItemIterator::matchesFlags(const Q3ListViewItem *item) const |
|
7567 |
{ |
|
7568 |
if (!item) |
|
7569 |
return false; |
|
7570 |
||
7571 |
if (flags == 0) |
|
7572 |
return true; |
|
7573 |
||
7574 |
if (flags & Visible && !item->isVisible()) |
|
7575 |
return false; |
|
7576 |
if (flags & Invisible && item->isVisible()) |
|
7577 |
return false; |
|
7578 |
if (flags & Selected && !item->isSelected()) |
|
7579 |
return false; |
|
7580 |
if (flags & Unselected && item->isSelected()) |
|
7581 |
return false; |
|
7582 |
if (flags & Selectable && !item->isSelectable()) |
|
7583 |
return false; |
|
7584 |
if (flags & NotSelectable && item->isSelectable()) |
|
7585 |
return false; |
|
7586 |
if (flags & DragEnabled && !item->dragEnabled()) |
|
7587 |
return false; |
|
7588 |
if (flags & DragDisabled && item->dragEnabled()) |
|
7589 |
return false; |
|
7590 |
if (flags & DropEnabled && !item->dropEnabled()) |
|
7591 |
return false; |
|
7592 |
if (flags & DropDisabled && item->dropEnabled()) |
|
7593 |
return false; |
|
7594 |
if (flags & Expandable && !item->isExpandable()) |
|
7595 |
return false; |
|
7596 |
if (flags & NotExpandable && item->isExpandable()) |
|
7597 |
return false; |
|
7598 |
if (flags & Checked && !isChecked(item)) |
|
7599 |
return false; |
|
7600 |
if (flags & NotChecked && isChecked(item)) |
|
7601 |
return false; |
|
7602 |
||
7603 |
return true; |
|
7604 |
} |
|
7605 |
||
7606 |
/* |
|
7607 |
we want the iterator to check Q3CheckListItems as well, so we provide this convenience function |
|
7608 |
that checks if the rtti() is 1 which means Q3CheckListItem and if isOn is true, returns false otherwise. |
|
7609 |
*/ |
|
7610 |
bool Q3ListViewItemIterator::isChecked(const Q3ListViewItem *item) const |
|
7611 |
{ |
|
7612 |
if (item->rtti() == 1) |
|
7613 |
return ((const Q3CheckListItem*)item)->isOn(); |
|
7614 |
else return false; |
|
7615 |
} |
|
7616 |
||
7617 |
void Q3ListView::handleItemChange(Q3ListViewItem *old, bool shift, bool control) |
|
7618 |
{ |
|
7619 |
if (d->selectionMode == Single) { |
|
7620 |
// nothing |
|
7621 |
} else if (d->selectionMode == Extended) { |
|
7622 |
if (shift) { |
|
7623 |
selectRange(d->selectAnchor ? d->selectAnchor : old, |
|
7624 |
d->focusItem, false, true, (d->selectAnchor && !control) ? true : false); |
|
7625 |
} else if (!control) { |
|
7626 |
bool block = signalsBlocked(); |
|
7627 |
blockSignals(true); |
|
7628 |
selectAll(false); |
|
7629 |
blockSignals(block); |
|
7630 |
setSelected(d->focusItem, true); |
|
7631 |
} |
|
7632 |
} else if (d->selectionMode == Multi) { |
|
7633 |
if (shift) |
|
7634 |
selectRange(old, d->focusItem, true, false); |
|
7635 |
} |
|
7636 |
} |
|
7637 |
||
7638 |
void Q3ListView::startRename() |
|
7639 |
{ |
|
7640 |
if (!currentItem()) |
|
7641 |
return; |
|
7642 |
currentItem()->startRename(d->pressedColumn); |
|
7643 |
d->buttonDown = false; |
|
7644 |
} |
|
7645 |
||
7646 |
/* unselects items from to, including children, returns true if any items were unselected */ |
|
7647 |
bool Q3ListView::clearRange(Q3ListViewItem *from, Q3ListViewItem *to, bool includeFirst) |
|
7648 |
{ |
|
7649 |
if (!from || !to) |
|
7650 |
return false; |
|
7651 |
||
7652 |
// Swap |
|
7653 |
if (from->itemPos() > to->itemPos()) { |
|
7654 |
Q3ListViewItem *temp = from; |
|
7655 |
from = to; |
|
7656 |
to = temp; |
|
7657 |
} |
|
7658 |
||
7659 |
// Start on second? |
|
7660 |
if (!includeFirst) { |
|
7661 |
Q3ListViewItem *below = (from == to) ? from : from->itemBelow(); |
|
7662 |
if (below) |
|
7663 |
from = below; |
|
7664 |
} |
|
7665 |
||
7666 |
// Clear items <from, to> |
|
7667 |
bool changed = false; |
|
7668 |
||
7669 |
Q3ListViewItemIterator it(from); |
|
7670 |
while (it.current()) { |
|
7671 |
if (it.current()->isSelected()) { |
|
7672 |
it.current()->setSelected(false); |
|
7673 |
changed = true; |
|
7674 |
} |
|
7675 |
if (it.current() == to) |
|
7676 |
break; |
|
7677 |
++it; |
|
7678 |
} |
|
7679 |
||
7680 |
// NOTE! This function does _not_ emit |
|
7681 |
// any signals about selection changed |
|
7682 |
return changed; |
|
7683 |
} |
|
7684 |
||
7685 |
void Q3ListView::selectRange(Q3ListViewItem *from, Q3ListViewItem *to, bool invert, bool includeFirst, bool clearSel) |
|
7686 |
{ |
|
7687 |
if (!from || !to) |
|
7688 |
return; |
|
7689 |
if (from == to && !includeFirst) |
|
7690 |
return; |
|
7691 |
bool swap = false; |
|
7692 |
if (to == from->itemAbove()) |
|
7693 |
swap = true; |
|
7694 |
if (!swap && from != to && from != to->itemAbove()) { |
|
7695 |
Q3ListViewItemIterator it(from); |
|
7696 |
bool found = false; |
|
7697 |
for (; it.current(); ++it) { |
|
7698 |
if (it.current() == to) { |
|
7699 |
found = true; |
|
7700 |
break; |
|
7701 |
} |
|
7702 |
} |
|
7703 |
if (!found) |
|
7704 |
swap = true; |
|
7705 |
} |
|
7706 |
if (swap) { |
|
7707 |
Q3ListViewItem *i = from; |
|
7708 |
from = to; |
|
7709 |
to = i; |
|
7710 |
if (!includeFirst) |
|
7711 |
to = to->itemAbove(); |
|
7712 |
} else { |
|
7713 |
if (!includeFirst) |
|
7714 |
from = from->itemBelow(); |
|
7715 |
} |
|
7716 |
||
7717 |
bool changed = false; |
|
7718 |
if (clearSel) { |
|
7719 |
Q3ListViewItemIterator it(firstChild()); |
|
7720 |
for (; it.current(); ++it) { |
|
7721 |
if (it.current()->selected) { |
|
7722 |
it.current()->setSelected(false); |
|
7723 |
changed = true; |
|
7724 |
} |
|
7725 |
} |
|
7726 |
it = Q3ListViewItemIterator(to); |
|
7727 |
for (; it.current(); ++it) { |
|
7728 |
if (it.current()->selected) { |
|
7729 |
it.current()->setSelected(false); |
|
7730 |
changed = true; |
|
7731 |
} |
|
7732 |
} |
|
7733 |
} |
|
7734 |
||
7735 |
for (Q3ListViewItem *i = from; i; i = i->itemBelow()) { |
|
7736 |
if (!invert) { |
|
7737 |
if (!i->selected && i->isSelectable()) { |
|
7738 |
i->setSelected(true); |
|
7739 |
changed = true; |
|
7740 |
} |
|
7741 |
} else { |
|
7742 |
bool sel = !i->selected; |
|
7743 |
if (((bool)i->selected != sel && sel && i->isSelectable()) || !sel) { |
|
7744 |
i->setSelected(sel); |
|
7745 |
changed = true; |
|
7746 |
} |
|
7747 |
} |
|
7748 |
if (i == to) |
|
7749 |
break; |
|
7750 |
} |
|
7751 |
if (changed) { |
|
7752 |
triggerUpdate(); |
|
7753 |
emit selectionChanged(); |
|
7754 |
} |
|
7755 |
} |
|
7756 |
||
7757 |
/* clears selection from anchor to old, selects from anchor to new, does not emit selectionChanged on change */ |
|
7758 |
bool Q3ListView::selectRange(Q3ListViewItem *newItem, Q3ListViewItem *oldItem, Q3ListViewItem *anchorItem) |
|
7759 |
{ |
|
7760 |
if (!newItem || !oldItem || !anchorItem) |
|
7761 |
return false; |
|
7762 |
||
7763 |
int anchorPos = anchorItem ? anchorItem->itemPos() : 0, |
|
7764 |
oldPos = oldItem ? oldItem->itemPos() : 0, |
|
7765 |
newPos = newItem->itemPos(); |
|
7766 |
Q3ListViewItem *top=0, *bottom=0; |
|
7767 |
if (anchorPos > newPos) { |
|
7768 |
top = newItem; |
|
7769 |
bottom = anchorItem; |
|
7770 |
} else { |
|
7771 |
top = anchorItem; |
|
7772 |
bottom = newItem; |
|
7773 |
} |
|
7774 |
||
7775 |
// removes the subControls of the old selection that will no longer be selected |
|
7776 |
bool changed = false; |
|
7777 |
int topPos = top ? top->itemPos() : 0, |
|
7778 |
bottomPos = bottom ? bottom->itemPos() : 0; |
|
7779 |
if (!(oldPos > topPos && oldPos < bottomPos)) { |
|
7780 |
if (oldPos < topPos) |
|
7781 |
changed = clearRange(oldItem, top); |
|
7782 |
else |
|
7783 |
changed = clearRange(bottom, oldItem); |
|
7784 |
} |
|
7785 |
||
7786 |
// selects the new (not already selected) items |
|
7787 |
Q3ListViewItemIterator lit(top); |
|
7788 |
for (; lit.current(); ++lit) { |
|
7789 |
if ((bool)lit.current()->selected != d->select) { |
|
7790 |
lit.current()->setSelected(d->select); |
|
7791 |
changed = true; |
|
7792 |
} |
|
7793 |
// Include bottom, then break |
|
7794 |
if (lit.current() == bottom) |
|
7795 |
break; |
|
7796 |
} |
|
7797 |
||
7798 |
return changed; |
|
7799 |
} |
|
7800 |
||
7801 |
||
7802 |
/*! |
|
7803 |
Finds the first list view item in column \a column, that matches |
|
7804 |
\a text and returns the item, or returns 0 of no such item could |
|
7805 |
be found. Pass OR-ed together \l ComparisonFlags values |
|
7806 |
in the \a compare flag, to control how the matching is performed. |
|
7807 |
The default comparison mode is case-sensitive, exact match. |
|
7808 |
*/ |
|
7809 |
||
7810 |
Q3ListViewItem *Q3ListView::findItem(const QString& text, int column, |
|
7811 |
ComparisonFlags compare) const |
|
7812 |
{ |
|
7813 |
if (text.isEmpty() && !(compare & ExactMatch)) |
|
7814 |
return 0; |
|
7815 |
||
7816 |
if (compare == Qt::CaseSensitive || compare == 0) |
|
7817 |
compare |= ExactMatch; |
|
7818 |
||
7819 |
QString itmtxt; |
|
7820 |
QString comtxt = text; |
|
7821 |
if (!(compare & Qt::CaseSensitive)) |
|
7822 |
comtxt = comtxt.toLower(); |
|
7823 |
||
7824 |
Q3ListViewItemIterator it(d->focusItem ? d->focusItem : firstChild()); |
|
7825 |
Q3ListViewItem *sentinel = 0; |
|
7826 |
Q3ListViewItem *item; |
|
7827 |
Q3ListViewItem *beginsWithItem = 0; |
|
7828 |
Q3ListViewItem *endsWithItem = 0; |
|
7829 |
Q3ListViewItem *containsItem = 0; |
|
7830 |
||
7831 |
for (int pass = 0; pass < 2; pass++) { |
|
7832 |
while ((item = it.current()) != sentinel) { |
|
7833 |
itmtxt = item->text(column); |
|
7834 |
if (!(compare & CaseSensitive)) |
|
7835 |
itmtxt = itmtxt.toLower(); |
|
7836 |
||
7837 |
if ((compare & ExactMatch)==ExactMatch && itmtxt == comtxt) |
|
7838 |
return item; |
|
7839 |
if (compare & BeginsWith && !beginsWithItem && itmtxt.startsWith(comtxt)) |
|
7840 |
beginsWithItem = containsItem = item; |
|
7841 |
if (compare & EndsWith && !endsWithItem && itmtxt.endsWith(comtxt)) |
|
7842 |
endsWithItem = containsItem = item; |
|
7843 |
if ((compare & ExactMatch)==0 && !containsItem && itmtxt.contains(comtxt)) |
|
7844 |
containsItem = item; |
|
7845 |
++it; |
|
7846 |
} |
|
7847 |
||
7848 |
it = Q3ListViewItemIterator(firstChild()); |
|
7849 |
sentinel = d->focusItem ? d->focusItem : firstChild(); |
|
7850 |
} |
|
7851 |
||
7852 |
// Obey the priorities |
|
7853 |
if (beginsWithItem) |
|
7854 |
return beginsWithItem; |
|
7855 |
else if (endsWithItem) |
|
7856 |
return endsWithItem; |
|
7857 |
else if (containsItem) |
|
7858 |
return containsItem; |
|
7859 |
return 0; |
|
7860 |
} |
|
7861 |
||
7862 |
/*! |
|
7863 |
Hides the column specified at \a column. This is a convenience |
|
7864 |
function that calls setColumnWidth(column, 0). |
|
7865 |
||
7866 |
Note: The user may still be able to resize the hidden column using |
|
7867 |
the header handles. To prevent this, call setResizeEnabled(false, |
|
7868 |
\a column) on the list views header. |
|
7869 |
||
7870 |
\sa setColumnWidth() |
|
7871 |
*/ |
|
7872 |
||
7873 |
void Q3ListView::hideColumn(int column) |
|
7874 |
{ |
|
7875 |
setColumnWidth(column, 0); |
|
7876 |
} |
|
7877 |
||
7878 |
/*! Adjusts the column \a col to its preferred width */ |
|
7879 |
||
7880 |
void Q3ListView::adjustColumn(int col) |
|
7881 |
{ |
|
7882 |
if (col < 0 || col > (int)d->column.count() - 1 || d->h->isStretchEnabled(col)) |
|
7883 |
return; |
|
7884 |
||
7885 |
int oldw = d->h->sectionSize(col); |
|
7886 |
||
7887 |
int w = d->h->sectionSizeHint(col, fontMetrics()).width(); |
|
7888 |
if (d->h->iconSet(col)) |
|
7889 |
w += d->h->iconSet(col)->pixmap().width(); |
|
7890 |
w = qMax(w, 20); |
|
7891 |
QFontMetrics fm(fontMetrics()); |
|
7892 |
Q3ListViewItem* item = firstChild(); |
|
7893 |
int rootDepth = rootIsDecorated() ? treeStepSize() : 0; |
|
7894 |
while (item) { |
|
7895 |
int iw = item->width(fm, this, col); |
|
7896 |
if (0 == col) |
|
7897 |
iw += itemMargin() + rootDepth + item->depth()*treeStepSize() - 1; |
|
7898 |
w = qMax(w, iw); |
|
7899 |
item = item->itemBelow(); |
|
7900 |
} |
|
7901 |
w = qMax(w, QApplication::globalStrut().width()); |
|
7902 |
||
7903 |
d->h->adjustHeaderSize(oldw - w); |
|
7904 |
if (oldw != w) { |
|
7905 |
d->fullRepaintOnComlumnChange = true; |
|
7906 |
d->h->resizeSection(col, w); |
|
7907 |
emit d->h->sizeChange(col, oldw, w); |
|
7908 |
} |
|
7909 |
} |
|
7910 |
||
7911 |
/*! |
|
7912 |
\enum Q3ListView::StringComparisonMode |
|
7913 |
||
7914 |
This enum type is used to set the string comparison mode when |
|
7915 |
searching for an item. We'll refer to the string being searched |
|
7916 |
as the 'target' string. |
|
7917 |
||
7918 |
\value CaseSensitive The strings must match case sensitively. |
|
7919 |
\value ExactMatch The target and search strings must match exactly. |
|
7920 |
\value BeginsWith The target string begins with the search string. |
|
7921 |
\value EndsWith The target string ends with the search string. |
|
7922 |
\value Contains The target string contains the search string. |
|
7923 |
||
7924 |
If you OR these flags together (excluding \c CaseSensitive), the |
|
7925 |
search criteria be applied in the following order: \c ExactMatch, |
|
7926 |
\c BeginsWith, \c EndsWith, \c Contains. |
|
7927 |
||
7928 |
Matching is case-insensitive unless \c CaseSensitive is set. \c |
|
7929 |
CaseSensitive can be OR-ed with any combination of the other |
|
7930 |
flags. |
|
7931 |
||
7932 |
\sa ComparisonFlags |
|
7933 |
*/ |
|
7934 |
||
7935 |
/*! |
|
7936 |
\typedef Q3ListView::ComparisonFlags |
|
7937 |
||
7938 |
This typedef is used in Q3ListView's API for values that are OR'd |
|
7939 |
combinations of \l StringComparisonMode values. |
|
7940 |
||
7941 |
\sa StringComparisonMode |
|
7942 |
*/ |
|
7943 |
||
7944 |
QT_END_NAMESPACE |
|
7945 |
||
7946 |
#endif // QT_NO_LISTVIEW |