Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | | - |
41 | #include "qlistview.h" | - |
42 | | - |
43 | #ifndef QT_NO_LISTVIEW | - |
44 | #include <qabstractitemdelegate.h> | - |
45 | #include <qapplication.h> | - |
46 | #include <qpainter.h> | - |
47 | #include <qbitmap.h> | - |
48 | #include <qdrag.h> | - |
49 | #include <qvector.h> | - |
50 | #include <qstyle.h> | - |
51 | #include <qevent.h> | - |
52 | #include <qscrollbar.h> | - |
53 | #include <qrubberband.h> | - |
54 | #include <private/qlistview_p.h> | - |
55 | #include <private/qscrollbar_p.h> | - |
56 | #include <qdebug.h> | - |
57 | #ifndef QT_NO_ACCESSIBILITY | - |
58 | #include <qaccessible.h> | - |
59 | #endif | - |
60 | | - |
61 | #include <algorithm> | - |
62 | | - |
63 | QT_BEGIN_NAMESPACE | - |
64 | | - |
65 | extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); | - |
66 | | - |
67 | | - |
68 | | - |
69 | | - |
70 | | - |
71 | | - |
72 | | - |
73 | | - |
74 | | - |
75 | | - |
76 | | - |
77 | | - |
78 | | - |
79 | | - |
80 | | - |
81 | | - |
82 | | - |
83 | | - |
84 | | - |
85 | | - |
86 | | - |
87 | | - |
88 | | - |
89 | | - |
90 | | - |
91 | | - |
92 | | - |
93 | | - |
94 | | - |
95 | | - |
96 | | - |
97 | | - |
98 | | - |
99 | | - |
100 | | - |
101 | | - |
102 | | - |
103 | | - |
104 | | - |
105 | | - |
106 | | - |
107 | | - |
108 | | - |
109 | | - |
110 | | - |
111 | | - |
112 | | - |
113 | | - |
114 | | - |
115 | | - |
116 | | - |
117 | | - |
118 | | - |
119 | | - |
120 | | - |
121 | | - |
122 | | - |
123 | | - |
124 | | - |
125 | | - |
126 | | - |
127 | | - |
128 | | - |
129 | | - |
130 | | - |
131 | | - |
132 | | - |
133 | | - |
134 | | - |
135 | | - |
136 | | - |
137 | | - |
138 | | - |
139 | | - |
140 | | - |
141 | | - |
142 | | - |
143 | | - |
144 | | - |
145 | | - |
146 | | - |
147 | | - |
148 | | - |
149 | | - |
150 | | - |
151 | | - |
152 | | - |
153 | | - |
154 | | - |
155 | | - |
156 | | - |
157 | | - |
158 | | - |
159 | | - |
160 | | - |
161 | | - |
162 | | - |
163 | | - |
164 | | - |
165 | | - |
166 | | - |
167 | | - |
168 | | - |
169 | | - |
170 | | - |
171 | | - |
172 | | - |
173 | | - |
174 | | - |
175 | | - |
176 | | - |
177 | | - |
178 | | - |
179 | | - |
180 | | - |
181 | | - |
182 | | - |
183 | | - |
184 | QListView::QListView(QWidget *parent) | - |
185 | : QAbstractItemView(*new QListViewPrivate, parent) | - |
186 | { | - |
187 | setViewMode(ListMode); | - |
188 | setSelectionMode(SingleSelection); | - |
189 | setAttribute(Qt::WA_MacShowFocusRect); | - |
190 | Q_D(QListView); | - |
191 | d->updateStyledFrameWidths(); | - |
192 | } | - |
193 | | - |
194 | | - |
195 | | - |
196 | | - |
197 | QListView::QListView(QListViewPrivate &dd, QWidget *parent) | - |
198 | : QAbstractItemView(dd, parent) | - |
199 | { | - |
200 | setViewMode(ListMode); | - |
201 | setSelectionMode(SingleSelection); | - |
202 | setAttribute(Qt::WA_MacShowFocusRect); | - |
203 | Q_D(QListView); | - |
204 | d->updateStyledFrameWidths(); | - |
205 | } | - |
206 | | - |
207 | | - |
208 | | - |
209 | | - |
210 | QListView::~QListView() | - |
211 | { | - |
212 | } | - |
213 | | - |
214 | | - |
215 | | - |
216 | | - |
217 | | - |
218 | | - |
219 | | - |
220 | | - |
221 | | - |
222 | | - |
223 | | - |
224 | | - |
225 | | - |
226 | | - |
227 | | - |
228 | | - |
229 | | - |
230 | | - |
231 | | - |
232 | | - |
233 | void QListView::setMovement(Movement movement) | - |
234 | { | - |
235 | Q_D(QListView); | - |
236 | d->modeProperties |= uint(QListViewPrivate::Movement); | - |
237 | d->movement = movement; | - |
238 | | - |
239 | #ifndef QT_NO_DRAGANDDROP | - |
240 | bool movable = (movement != Static); | - |
241 | setDragEnabled(movable); | - |
242 | d->viewport->setAcceptDrops(movable); | - |
243 | #endif | - |
244 | d->doDelayedItemsLayout(); | - |
245 | } | - |
246 | | - |
247 | QListView::Movement QListView::movement() const | - |
248 | { | - |
249 | Q_D(const QListView); | - |
250 | return d->movement; | - |
251 | } | - |
252 | | - |
253 | | - |
254 | | - |
255 | | - |
256 | | - |
257 | | - |
258 | | - |
259 | | - |
260 | | - |
261 | | - |
262 | | - |
263 | | - |
264 | | - |
265 | | - |
266 | | - |
267 | | - |
268 | | - |
269 | | - |
270 | void QListView::setFlow(Flow flow) | - |
271 | { | - |
272 | Q_D(QListView); | - |
273 | d->modeProperties |= uint(QListViewPrivate::Flow); | - |
274 | d->flow = flow; | - |
275 | d->doDelayedItemsLayout(); | - |
276 | } | - |
277 | | - |
278 | QListView::Flow QListView::flow() const | - |
279 | { | - |
280 | Q_D(const QListView); | - |
281 | return d->flow; | - |
282 | } | - |
283 | | - |
284 | | - |
285 | | - |
286 | | - |
287 | | - |
288 | | - |
289 | | - |
290 | | - |
291 | | - |
292 | | - |
293 | | - |
294 | | - |
295 | | - |
296 | | - |
297 | | - |
298 | | - |
299 | void QListView::setWrapping(bool enable) | - |
300 | { | - |
301 | Q_D(QListView); | - |
302 | d->modeProperties |= uint(QListViewPrivate::Wrap); | - |
303 | d->setWrapping(enable); | - |
304 | d->doDelayedItemsLayout(); | - |
305 | } | - |
306 | | - |
307 | bool QListView::isWrapping() const | - |
308 | { | - |
309 | Q_D(const QListView); | - |
310 | return d->isWrapping(); | - |
311 | } | - |
312 | | - |
313 | | - |
314 | | - |
315 | | - |
316 | | - |
317 | | - |
318 | | - |
319 | | - |
320 | | - |
321 | | - |
322 | | - |
323 | | - |
324 | | - |
325 | void QListView::setResizeMode(ResizeMode mode) | - |
326 | { | - |
327 | Q_D(QListView); | - |
328 | d->modeProperties |= uint(QListViewPrivate::ResizeMode); | - |
329 | d->resizeMode = mode; | - |
330 | } | - |
331 | | - |
332 | QListView::ResizeMode QListView::resizeMode() const | - |
333 | { | - |
334 | Q_D(const QListView); | - |
335 | return d->resizeMode; | - |
336 | } | - |
337 | | - |
338 | | - |
339 | | - |
340 | | - |
341 | | - |
342 | | - |
343 | | - |
344 | | - |
345 | | - |
346 | | - |
347 | | - |
348 | | - |
349 | | - |
350 | | - |
351 | void QListView::setLayoutMode(LayoutMode mode) | - |
352 | { | - |
353 | Q_D(QListView); | - |
354 | d->layoutMode = mode; | - |
355 | } | - |
356 | | - |
357 | QListView::LayoutMode QListView::layoutMode() const | - |
358 | { | - |
359 | Q_D(const QListView); | - |
360 | return d->layoutMode; | - |
361 | } | - |
362 | | - |
363 | | - |
364 | | - |
365 | | - |
366 | | - |
367 | | - |
368 | | - |
369 | | - |
370 | | - |
371 | | - |
372 | | - |
373 | | - |
374 | | - |
375 | | - |
376 | | - |
377 | void QListView::setSpacing(int space) | - |
378 | { | - |
379 | Q_D(QListView); | - |
380 | d->modeProperties |= uint(QListViewPrivate::Spacing); | - |
381 | d->setSpacing(space); | - |
382 | d->doDelayedItemsLayout(); | - |
383 | } | - |
384 | | - |
385 | int QListView::spacing() const | - |
386 | { | - |
387 | Q_D(const QListView); | - |
388 | return d->spacing(); | - |
389 | } | - |
390 | | - |
391 | | - |
392 | | - |
393 | | - |
394 | | - |
395 | | - |
396 | | - |
397 | | - |
398 | | - |
399 | | - |
400 | | - |
401 | void QListView::setBatchSize(int batchSize) | - |
402 | { | - |
403 | Q_D(QListView); | - |
404 | if (Q_UNLIKELY(batchSize <= 0))) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
405 | qWarning("Invalid batchSize (%d)", batchSize); | - |
406 | return; never executed: return; | 0 |
407 | } | - |
408 | d->batchSize = batchSize; | - |
409 | } never executed: end of block | 0 |
410 | | - |
411 | int QListView::batchSize() const | - |
412 | { | - |
413 | Q_D(const QListView); | - |
414 | return d->batchSize; | - |
415 | } | - |
416 | | - |
417 | | - |
418 | | - |
419 | | - |
420 | | - |
421 | | - |
422 | | - |
423 | | - |
424 | | - |
425 | | - |
426 | | - |
427 | | - |
428 | | - |
429 | | - |
430 | | - |
431 | | - |
432 | void QListView::setGridSize(const QSize &size) | - |
433 | { | - |
434 | Q_D(QListView); | - |
435 | d->modeProperties |= uint(QListViewPrivate::GridSize); | - |
436 | d->setGridSize(size); | - |
437 | d->doDelayedItemsLayout(); | - |
438 | } | - |
439 | | - |
440 | QSize QListView::gridSize() const | - |
441 | { | - |
442 | Q_D(const QListView); | - |
443 | return d->gridSize(); | - |
444 | } | - |
445 | | - |
446 | | - |
447 | | - |
448 | | - |
449 | | - |
450 | | - |
451 | | - |
452 | | - |
453 | | - |
454 | | - |
455 | | - |
456 | | - |
457 | | - |
458 | | - |
459 | | - |
460 | | - |
461 | void QListView::setViewMode(ViewMode mode) | - |
462 | { | - |
463 | Q_D(QListView); | - |
464 | if (d->commonListView && d->viewMode == mode) | - |
465 | return; | - |
466 | d->viewMode = mode; | - |
467 | | - |
468 | delete d->commonListView; | - |
469 | if (mode == ListMode) { | - |
470 | d->commonListView = new QListModeViewBase(this, d); | - |
471 | if (!(d->modeProperties & QListViewPrivate::Wrap)) | - |
472 | d->setWrapping(false); | - |
473 | if (!(d->modeProperties & QListViewPrivate::Spacing)) | - |
474 | d->setSpacing(0); | - |
475 | if (!(d->modeProperties & QListViewPrivate::GridSize)) | - |
476 | d->setGridSize(QSize()); | - |
477 | if (!(d->modeProperties & QListViewPrivate::Flow)) | - |
478 | d->flow = TopToBottom; | - |
479 | if (!(d->modeProperties & QListViewPrivate::Movement)) | - |
480 | d->movement = Static; | - |
481 | if (!(d->modeProperties & QListViewPrivate::ResizeMode)) | - |
482 | d->resizeMode = Fixed; | - |
483 | if (!(d->modeProperties & QListViewPrivate::SelectionRectVisible)) | - |
484 | d->showElasticBand = false; | - |
485 | } else { | - |
486 | d->commonListView = new QIconModeViewBase(this, d); | - |
487 | if (!(d->modeProperties & QListViewPrivate::Wrap)) | - |
488 | d->setWrapping(true); | - |
489 | if (!(d->modeProperties & QListViewPrivate::Spacing)) | - |
490 | d->setSpacing(0); | - |
491 | if (!(d->modeProperties & QListViewPrivate::GridSize)) | - |
492 | d->setGridSize(QSize()); | - |
493 | if (!(d->modeProperties & QListViewPrivate::Flow)) | - |
494 | d->flow = LeftToRight; | - |
495 | if (!(d->modeProperties & QListViewPrivate::Movement)) | - |
496 | d->movement = Free; | - |
497 | if (!(d->modeProperties & QListViewPrivate::ResizeMode)) | - |
498 | d->resizeMode = Fixed; | - |
499 | if (!(d->modeProperties & QListViewPrivate::SelectionRectVisible)) | - |
500 | d->showElasticBand = true; | - |
501 | } | - |
502 | | - |
503 | #ifndef QT_NO_DRAGANDDROP | - |
504 | bool movable = (d->movement != Static); | - |
505 | setDragEnabled(movable); | - |
506 | setAcceptDrops(movable); | - |
507 | #endif | - |
508 | d->clear(); | - |
509 | d->doDelayedItemsLayout(); | - |
510 | } | - |
511 | | - |
512 | QListView::ViewMode QListView::viewMode() const | - |
513 | { | - |
514 | Q_D(const QListView); | - |
515 | return d->viewMode; | - |
516 | } | - |
517 | | - |
518 | | - |
519 | | - |
520 | | - |
521 | | - |
522 | | - |
523 | | - |
524 | | - |
525 | | - |
526 | | - |
527 | void QListView::clearPropertyFlags() | - |
528 | { | - |
529 | Q_D(QListView); | - |
530 | d->modeProperties = 0; | - |
531 | } | - |
532 | | - |
533 | | - |
534 | | - |
535 | | - |
536 | bool QListView::isRowHidden(int row) const | - |
537 | { | - |
538 | Q_D(const QListView); | - |
539 | return d->isHidden(row); | - |
540 | } | - |
541 | | - |
542 | | - |
543 | | - |
544 | | - |
545 | | - |
546 | void QListView::setRowHidden(int row, bool hide) | - |
547 | { | - |
548 | Q_D(QListView); | - |
549 | const bool hidden = d->isHidden(row); | - |
550 | if (hide && !hidden) | - |
551 | d->commonListView->appendHiddenRow(row); | - |
552 | else if (!hide && hidden) | - |
553 | d->commonListView->removeHiddenRow(row); | - |
554 | d->doDelayedItemsLayout(); | - |
555 | d->viewport->update(); | - |
556 | } | - |
557 | | - |
558 | | - |
559 | | - |
560 | | - |
561 | QRect QListView::visualRect(const QModelIndex &index) const | - |
562 | { | - |
563 | Q_D(const QListView); | - |
564 | return d->mapToViewport(rectForIndex(index)); | - |
565 | } | - |
566 | | - |
567 | | - |
568 | | - |
569 | | - |
570 | void QListView::scrollTo(const QModelIndex &index, ScrollHint hint) | - |
571 | { | - |
572 | Q_D(QListView); | - |
573 | | - |
574 | if (index.parent() != d->root || index.column() != d->column) | - |
575 | return; | - |
576 | | - |
577 | const QRect rect = visualRect(index); | - |
578 | if (hint == EnsureVisible && d->viewport->rect().contains(rect)) { | - |
579 | d->viewport->update(rect); | - |
580 | return; | - |
581 | } | - |
582 | | - |
583 | if (d->flow == QListView::TopToBottom || d->isWrapping()) | - |
584 | verticalScrollBar()->setValue(d->verticalScrollToValue(index, rect, hint)); | - |
585 | | - |
586 | if (d->flow == QListView::LeftToRight || d->isWrapping()) | - |
587 | horizontalScrollBar()->setValue(d->horizontalScrollToValue(index, rect, hint)); | - |
588 | } | - |
589 | | - |
590 | int QListViewPrivate::horizontalScrollToValue(const QModelIndex &index, const QRect &rect, | - |
591 | QListView::ScrollHint hint) const | - |
592 | { | - |
593 | Q_Q(const QListView); | - |
594 | const QRect area = viewport->rect(); | - |
595 | const bool leftOf = q->isRightToLeft() | - |
596 | ? (rect.left() < area.left()) && (rect.right() < area.right()) | - |
597 | : rect.left() < area.left(); | - |
598 | const bool rightOf = q->isRightToLeft() | - |
599 | ? rect.right() > area.right() | - |
600 | : (rect.right() > area.right()) && (rect.left() > area.left()); | - |
601 | return commonListView->horizontalScrollToValue(q->visualIndex(index), hint, leftOf, rightOf, area, rect); | - |
602 | } | - |
603 | | - |
604 | int QListViewPrivate::verticalScrollToValue(const QModelIndex &index, const QRect &rect, | - |
605 | QListView::ScrollHint hint) const | - |
606 | { | - |
607 | Q_Q(const QListView); | - |
608 | const QRect area = viewport->rect(); | - |
609 | const bool above = (hint == QListView::EnsureVisible && rect.top() < area.top()); | - |
610 | const bool below = (hint == QListView::EnsureVisible && rect.bottom() > area.bottom()); | - |
611 | return commonListView->verticalScrollToValue(q->visualIndex(index), hint, above, below, area, rect); | - |
612 | } | - |
613 | | - |
614 | void QListViewPrivate::selectAll(QItemSelectionModel::SelectionFlags command) | - |
615 | { | - |
616 | if (!selectionModel) | - |
617 | return; | - |
618 | | - |
619 | QItemSelection selection; | - |
620 | QModelIndex topLeft; | - |
621 | int row = 0; | - |
622 | const int colCount = model->columnCount(root); | - |
623 | for(; row < model->rowCount(root); ++row) { | - |
624 | if (isHidden(row)) { | - |
625 | | - |
626 | if (topLeft.isValid()) { | - |
627 | QModelIndex bottomRight = model->index(row - 1, colCount - 1, root); | - |
628 | selection.append(QItemSelectionRange(topLeft, bottomRight)); | - |
629 | topLeft = QModelIndex(); | - |
630 | } | - |
631 | continue; | - |
632 | } | - |
633 | | - |
634 | if (!topLeft.isValid()) | - |
635 | topLeft = model->index(row, 0, root); | - |
636 | } | - |
637 | | - |
638 | if (topLeft.isValid()) { | - |
639 | | - |
640 | QModelIndex bottomRight = model->index(row - 1, colCount - 1, root); | - |
641 | selection.append(QItemSelectionRange(topLeft, bottomRight)); | - |
642 | } | - |
643 | | - |
644 | if (!selection.isEmpty()) | - |
645 | selectionModel->select(selection, command); | - |
646 | } | - |
647 | | - |
648 | | - |
649 | | - |
650 | | - |
651 | | - |
652 | | - |
653 | | - |
654 | QItemViewPaintPairs QListViewPrivate::draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const | - |
655 | { | - |
656 | Q_ASSERT(r); | - |
657 | Q_Q(const QListView); | - |
658 | QRect &rect = *r; | - |
659 | const QRect viewportRect = viewport->rect(); | - |
660 | QItemViewPaintPairs ret; | - |
661 | const QSetQVector<QModelIndex> visibleIndexes = intersectingSet(viewportRect.translated(q->horizontalOffset(), q->verticalOffset())).toList().toSet(); | - |
| for())); | |
662 | std::sort(int i = 0; i < indexesvisibleIndexes.count(); ++i) {begin(), visibleIndexes.end()); | - |
663 | for (const QModelIndexauto &index =: indexes.at(i);) { | - |
664 | if (std::binary_search(visibleIndexes.contains(cbegin(), visibleIndexes.cend(), index)) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
665 | const QRect current = q->visualRect(index); | - |
666 | ret += qMakePair(QItemViewPaintPair p = { current, index );}; | - |
667 | ret += p; | - |
668 | rect |= current; | - |
669 | } never executed: end of block | 0 |
670 | } never executed: end of block | 0 |
671 | rect &= viewportRect; | - |
672 | return ret; never executed: return ret; | 0 |
673 | } | - |
674 | | - |
675 | | - |
676 | | - |
677 | | - |
678 | void QListView::reset() | - |
679 | { | - |
680 | Q_D(QListView); | - |
681 | d->clear(); | - |
682 | d->hiddenRows.clear(); | - |
683 | QAbstractItemView::reset(); | - |
684 | } | - |
685 | | - |
686 | | - |
687 | | - |
688 | | - |
689 | void QListView::setRootIndex(const QModelIndex &index) | - |
690 | { | - |
691 | Q_D(QListView); | - |
692 | d->column = qBound(0, d->column, d->model->columnCount(index) - 1); | - |
693 | QAbstractItemView::setRootIndex(index); | - |
694 | | - |
695 | d->clear(); | - |
696 | d->hiddenRows.clear(); | - |
697 | } | - |
698 | | - |
699 | | - |
700 | | - |
701 | | - |
702 | | - |
703 | | - |
704 | | - |
705 | void QListView::scrollContentsBy(int dx, int dy) | - |
706 | { | - |
707 | Q_D(QListView); | - |
708 | d->delayedAutoScroll.stop(); | - |
709 | d->commonListView->scrollContentsBy(dx, dy, d->state == QListView::DragSelectingState); | - |
710 | } | - |
711 | | - |
712 | | - |
713 | | - |
714 | | - |
715 | | - |
716 | | - |
717 | | - |
718 | void QListView::resizeContents(int width, int height) | - |
719 | { | - |
720 | Q_D(QListView); | - |
721 | d->setContentsSize(width, height); | - |
722 | } | - |
723 | | - |
724 | | - |
725 | | - |
726 | | - |
727 | QSize QListView::contentsSize() const | - |
728 | { | - |
729 | Q_D(const QListView); | - |
730 | return d->contentsSize(); | - |
731 | } | - |
732 | | - |
733 | | - |
734 | | - |
735 | | - |
736 | void QListView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) | - |
737 | { | - |
738 | d_func()->commonListView->dataChanged(topLeft, bottomRight); | - |
739 | QAbstractItemView::dataChanged(topLeft, bottomRight, roles); | - |
740 | } | - |
741 | | - |
742 | | - |
743 | | - |
744 | | - |
745 | void QListView::rowsInserted(const QModelIndex &parent, int start, int end) | - |
746 | { | - |
747 | Q_D(QListView); | - |
748 | | - |
749 | d->clear(); | - |
750 | d->doDelayedItemsLayout(); | - |
751 | QAbstractItemView::rowsInserted(parent, start, end); | - |
752 | } | - |
753 | | - |
754 | | - |
755 | | - |
756 | | - |
757 | void QListView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) | - |
758 | { | - |
759 | Q_D(QListView); | - |
760 | | - |
761 | QAbstractItemView::rowsAboutToBeRemoved(parent, start, end); | - |
762 | if (parent == d->root) { | - |
763 | QSet<QPersistentModelIndex>::iterator it = d->hiddenRows.begin(); | - |
764 | while (it != d->hiddenRows.end()) { | - |
765 | int hiddenRow = it->row(); | - |
766 | if (hiddenRow >= start && hiddenRow <= end) { | - |
767 | it = d->hiddenRows.erase(it); | - |
768 | } else { | - |
769 | ++it; | - |
770 | } | - |
771 | } | - |
772 | } | - |
773 | d->clear(); | - |
774 | d->doDelayedItemsLayout(); | - |
775 | } | - |
776 | | - |
777 | | - |
778 | | - |
779 | | - |
780 | void QListView::mouseMoveEvent(QMouseEvent *e) | - |
781 | { | - |
782 | if (!isVisible()) | - |
783 | return; | - |
784 | Q_D(QListView); | - |
785 | QAbstractItemView::mouseMoveEvent(e); | - |
786 | if (state() == DragSelectingState | - |
787 | && d->showElasticBand | - |
788 | && d->selectionMode != SingleSelection | - |
789 | && d->selectionMode != NoSelection) { | - |
790 | QRect rect(d->pressedPosition, e->pos() + QPoint(horizontalOffset(), verticalOffset())); | - |
791 | rect = rect.normalized(); | - |
792 | d->viewport->update(d->mapToViewport(rect.united(d->elasticBand))); | - |
793 | d->elasticBand = rect; | - |
794 | } | - |
795 | } | - |
796 | | - |
797 | | - |
798 | | - |
799 | | - |
800 | void QListView::mouseReleaseEvent(QMouseEvent *e) | - |
801 | { | - |
802 | Q_D(QListView); | - |
803 | QAbstractItemView::mouseReleaseEvent(e); | - |
804 | | - |
805 | if (d->showElasticBand && d->elasticBand.isValid()) { | - |
806 | d->viewport->update(d->mapToViewport(d->elasticBand)); | - |
807 | d->elasticBand = QRect(); | - |
808 | } | - |
809 | } | - |
810 | | - |
811 | #ifndef QT_NO_WHEELEVENT | - |
812 | | - |
813 | | - |
814 | | - |
815 | void QListView::wheelEvent(QWheelEvent *e) | - |
816 | { | - |
817 | Q_D(QListView); | - |
818 | if (e->orientation() == Qt::Vertical) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
819 | if (e->angleDelta().x() == 0TRUE | never evaluated | FALSE | never evaluated |
| 0 |
820 | && ((d->flow == TopToBottom && d->wrap) || (d->flow == LeftToRight && !d->wrap))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
821 | && d->vbar->minimum() == 0 && d->vbar->maximum() == 0) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
822 | QPoint pixelDelta(e->pixelDelta().y(), e->pixelDelta().x()); | - |
823 | QPoint angleDelta(e->angleDelta().y(), e->angleDelta().x()); | - |
824 | QWheelEvent hwe(e->pos(), e->globalPos(), pixelDelta, angleDelta, e->delta(), | - |
825 | Qt::Horizontal, e->buttons(), e->modifiers(), e->phase(), e->source(), e->inverted()); | - |
826 | if (e->spontaneous())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
827 | qt_sendSpontaneousEvent(d->hbar, &hwe); never executed: qt_sendSpontaneousEvent(d->hbar, &hwe); | 0 |
828 | else | - |
829 | QApplication::sendEvent(d->hbar, &hwe); never executed: QApplication::sendEvent(d->hbar, &hwe); | 0 |
830 | e->setAccepted(hwe.isAccepted()); | - |
831 | } else { never executed: end of block | 0 |
832 | QApplication::sendEvent(d->vbar, e); | - |
833 | } never executed: end of block | 0 |
834 | } else { | - |
835 | QApplication::sendEvent(d->hbar, e); | - |
836 | } never executed: end of block | 0 |
837 | } | - |
838 | #endif // QT_NO_WHEELEVENT | - |
839 | | - |
840 | | - |
841 | | - |
842 | | - |
843 | void QListView::timerEvent(QTimerEvent *e) | - |
844 | { | - |
845 | Q_D(QListView); | - |
846 | if (e->timerId() == d->batchLayoutTimer.timerId()) { | - |
847 | if (d->doItemsLayout(d->batchSize)) { | - |
848 | d->batchLayoutTimer.stop(); | - |
849 | updateGeometries(); | - |
850 | d->viewport->update(); | - |
851 | } | - |
852 | } | - |
853 | QAbstractItemView::timerEvent(e); | - |
854 | } | - |
855 | | - |
856 | | - |
857 | | - |
858 | | - |
859 | void QListView::resizeEvent(QResizeEvent *e) | - |
860 | { | - |
861 | Q_D(QListView); | - |
862 | if (d->delayedPendingLayout) | - |
863 | return; | - |
864 | | - |
865 | QSize delta = e->size() - e->oldSize(); | - |
866 | | - |
867 | if (delta.isNull()) | - |
868 | return; | - |
869 | | - |
870 | bool listWrap = (d->viewMode == ListMode) && d->wrapItemText; | - |
871 | bool flowDimensionChanged = (d->flow == LeftToRight && delta.width() != 0) | - |
872 | || (d->flow == TopToBottom && delta.height() != 0); | - |
873 | | - |
874 | | - |
875 | | - |
876 | | - |
877 | if (listWrap | - |
878 | || (state() == NoState && d->resizeMode == Adjust && flowDimensionChanged)) { | - |
879 | d->doDelayedItemsLayout(100); | - |
880 | } else { | - |
881 | QAbstractItemView::resizeEvent(e); | - |
882 | } | - |
883 | } | - |
884 | | - |
885 | #ifndef QT_NO_DRAGANDDROP | - |
886 | | - |
887 | | - |
888 | | - |
889 | | - |
890 | void QListView::dragMoveEvent(QDragMoveEvent *e) | - |
891 | { | - |
892 | Q_D(QListView); | - |
893 | if (!d->commonListView->filterDragMoveEvent(e)) { | - |
894 | if (viewMode() == QListView::ListMode && flow() == QListView::LeftToRight) | - |
895 | static_cast<QListModeViewBase *>(d->commonListView)->dragMoveEvent(e); | - |
896 | else | - |
897 | QAbstractItemView::dragMoveEvent(e); | - |
898 | } | - |
899 | } | - |
900 | | - |
901 | | - |
902 | | - |
903 | | - |
904 | | - |
905 | void QListView::dragLeaveEvent(QDragLeaveEvent *e) | - |
906 | { | - |
907 | if (!d_func()->commonListView->filterDragLeaveEvent(e)) | - |
908 | QAbstractItemView::dragLeaveEvent(e); | - |
909 | } | - |
910 | | - |
911 | | - |
912 | | - |
913 | | - |
914 | void QListView::dropEvent(QDropEvent *e) | - |
915 | { | - |
916 | if (!d_func()->commonListView->filterDropEvent(e)) | - |
917 | QAbstractItemView::dropEvent(e); | - |
918 | } | - |
919 | | - |
920 | | - |
921 | | - |
922 | | - |
923 | void QListView::startDrag(Qt::DropActions supportedActions) | - |
924 | { | - |
925 | if (!d_func()->commonListView->filterStartDrag(supportedActions)) | - |
926 | QAbstractItemView::startDrag(supportedActions); | - |
927 | } | - |
928 | | - |
929 | #endif // QT_NO_DRAGANDDROP | - |
930 | | - |
931 | | - |
932 | | - |
933 | | - |
934 | QStyleOptionViewItem QListView::viewOptions() const | - |
935 | { | - |
936 | Q_D(const QListView); | - |
937 | QStyleOptionViewItem option = QAbstractItemView::viewOptions(); | - |
938 | if (!d->iconSize.isValid()) { | - |
939 | int pm = (d->viewMode == QListView::ListMode | - |
940 | ? style()->pixelMetric(QStyle::PM_ListViewIconSize, 0, this) | - |
941 | : style()->pixelMetric(QStyle::PM_IconViewIconSize, 0, this)); | - |
942 | option.decorationSize = QSize(pm, pm); | - |
943 | } | - |
944 | if (d->viewMode == QListView::IconMode) { | - |
945 | option.showDecorationSelected = false; | - |
946 | option.decorationPosition = QStyleOptionViewItem::Top; | - |
947 | option.displayAlignment = Qt::AlignCenter; | - |
948 | } else { | - |
949 | option.decorationPosition = QStyleOptionViewItem::Left; | - |
950 | } | - |
951 | | - |
952 | if (d->gridSize().isValid()) { | - |
953 | option.rect.setSize(d->gridSize()); | - |
954 | } | - |
955 | | - |
956 | return option; | - |
957 | } | - |
958 | | - |
959 | | - |
960 | | - |
961 | | - |
962 | | - |
963 | void QListView::paintEvent(QPaintEvent *e) | - |
964 | { | - |
965 | Q_D(QListView); | - |
966 | if (!d->itemDelegate)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
967 | return; never executed: return; | 0 |
968 | QStyleOptionViewItem option = d->viewOptionsV1(); | - |
969 | QPainter painter(d->viewport); | - |
970 | | - |
971 | const QVector<QModelIndex> toBeRendered = d->intersectingSet(e->rect().translated(horizontalOffset(), verticalOffset()), false); | - |
972 | | - |
973 | const QModelIndex current = currentIndex(); | - |
974 | const QModelIndex hover = d->hover; | - |
975 | const QAbstractItemModel *itemModel = d->model; | - |
976 | const QItemSelectionModel *selections = d->selectionModel; | - |
977 | const bool focus = (hasFocus() || d->viewport->hasFocus()) && current.isValid();TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
978 | const bool alternate = d->alternatingColors; | - |
979 | const QStyle::State state = option.state; | - |
980 | const QAbstractItemView::State viewState = this->state(); | - |
981 | const bool enabled = (state & QStyle::State_Enabled) != 0; | - |
982 | | - |
983 | bool alternateBase = false; | - |
984 | int previousRow = -2; | - |
985 | | - |
986 | int maxSize = (flow() == TopToBottom)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
987 | ? qMax(viewport()->size().width(), d->contentsSize().width()) - 2 * d->spacing() | - |
988 | : qMax(viewport()->size().height(), d->contentsSize().height()) - 2 * d->spacing(); | - |
989 | | - |
990 | QVector<QModelIndex>::const_iterator end = toBeRendered.constEnd(); | - |
991 | for (QVector<QModelIndex>::const_iterator it = toBeRendered.constBegin(); it != end; ++it) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
992 | Q_ASSERT((*it).isValid()); | - |
993 | option.rect = visualRect(*it); | - |
994 | | - |
995 | if (flow() == TopToBottom)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
996 | option.rect.setWidth(qMin(maxSize, option.rect.width())); never executed: option.rect.setWidth(qMin(maxSize, option.rect.width())); | 0 |
997 | else | - |
998 | option.rect.setHeight(qMin(maxSize, option.rect.height())); never executed: option.rect.setHeight(qMin(maxSize, option.rect.height())); | 0 |
999 | | - |
1000 | option.state = state; | - |
1001 | if (selections && selections->isSelected(*it))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1002 | option.state |= QStyle::State_Selected; never executed: option.state |= QStyle::State_Selected; | 0 |
1003 | if (enabled) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1004 | QPalette::ColorGroup cg; | - |
1005 | if ((itemModel->flags(*it) & Qt::ItemIsEnabled) == 0) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1006 | option.state &= ~QStyle::State_Enabled; | - |
1007 | cg = QPalette::Disabled; | - |
1008 | } else { never executed: end of block | 0 |
1009 | cg = QPalette::Normal; | - |
1010 | } never executed: end of block | 0 |
1011 | option.palette.setCurrentColorGroup(cg); | - |
1012 | } never executed: end of block | 0 |
1013 | if (focus && current == *it) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1014 | option.state |= QStyle::State_HasFocus; | - |
1015 | if (viewState == EditingState)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1016 | option.state |= QStyle::State_Editing; never executed: option.state |= QStyle::State_Editing; | 0 |
1017 | } never executed: end of block | 0 |
1018 | if (*it == hover)option.state|= QStyle::State_MouseOver; | - |
| else | |
| option.state &= ~setFlag(QStyle::State_MouseOver;, *it == hover); | |
1019 | | - |
1020 | if (alternate) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1021 | int row = (*it).row(); | - |
1022 | if (row != previousRow + 1) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1023 | | - |
1024 | if (!d->hiddenRows.isEmpty()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1025 | for (int r = qMax(previousRow + 1, 0); r < row; ++r) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1026 | if (!d->isHidden(r))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1027 | alternateBase = !alternateBase; never executed: alternateBase = !alternateBase; | 0 |
1028 | } never executed: end of block | 0 |
1029 | } else { never executed: end of block | 0 |
1030 | alternateBase = (row & 1) != 0; | - |
1031 | } never executed: end of block | 0 |
1032 | } | - |
1033 | if (alternateBase) {option.features|= QStyleOptionViewItem::Alternate; | - |
| } else { | |
| option.features &= ~setFlag(QStyleOptionViewItem::Alternate; | |
| }, alternateBase); | |
1034 | | - |
1035 | | - |
1036 | | - |
1037 | QStyle::State oldState = option.state; | - |
1038 | option.state &= ~QStyle::State_Selected; | - |
1039 | style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &option, &painter, this); | - |
1040 | option.state = oldState; | - |
1041 | | - |
1042 | alternateBase = !alternateBase; | - |
1043 | previousRow = row; | - |
1044 | } never executed: end of block | 0 |
1045 | | - |
1046 | d->delegateForIndex(*it)->paint(&painter, option, *it); | - |
1047 | } never executed: end of block | 0 |
1048 | | - |
1049 | #ifndef QT_NO_DRAGANDDROP | - |
1050 | d->commonListView->paintDragDrop(&painter); | - |
1051 | #endif | - |
1052 | | - |
1053 | #ifndef QT_NO_RUBBERBAND | - |
1054 | | - |
1055 | if (d->showElasticBand && d->elasticBand.isValid()) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1056 | QStyleOptionRubberBand opt; | - |
1057 | opt.initFrom(this); | - |
1058 | opt.shape = QRubberBand::Rectangle; | - |
1059 | opt.opaque = false; | - |
1060 | opt.rect = d->mapToViewport(d->elasticBand, false).intersected( | - |
1061 | d->viewport->rect().adjusted(-16, -16, 16, 16)); | - |
1062 | painter.save(); | - |
1063 | style()->drawControl(QStyle::CE_RubberBand, &opt, &painter); | - |
1064 | painter.restore(); | - |
1065 | } never executed: end of block | 0 |
1066 | #endif | - |
1067 | } never executed: end of block | 0 |
1068 | | - |
1069 | | - |
1070 | | - |
1071 | | - |
1072 | QModelIndex QListView::indexAt(const QPoint &p) const | - |
1073 | { | - |
1074 | Q_D(const QListView); | - |
1075 | QRect rect(p.x() + horizontalOffset(), p.y() + verticalOffset(), 1, 1); | - |
1076 | const QVector<QModelIndex> intersectVector = d->intersectingSet(rect); | - |
1077 | QModelIndex index = intersectVector.count() > 0 | - |
1078 | ? intersectVector.last() : QModelIndex(); | - |
1079 | if (index.isValid() && visualRect(index).contains(p)) | - |
1080 | return index; | - |
1081 | return QModelIndex(); | - |
1082 | } | - |
1083 | | - |
1084 | | - |
1085 | | - |
1086 | | - |
1087 | int QListView::horizontalOffset() const | - |
1088 | { | - |
1089 | return d_func()->commonListView->horizontalOffset(); | - |
1090 | } | - |
1091 | | - |
1092 | | - |
1093 | | - |
1094 | | - |
1095 | int QListView::verticalOffset() const | - |
1096 | { | - |
1097 | return d_func()->commonListView->verticalOffset(); | - |
1098 | } | - |
1099 | | - |
1100 | | - |
1101 | | - |
1102 | | - |
1103 | QModelIndex QListView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) | - |
1104 | { | - |
1105 | Q_D(QListView); | - |
1106 | Q_UNUSED(modifiers); | - |
1107 | | - |
1108 | QModelIndex current = currentIndex(); | - |
1109 | if (!current.isValid()) { | - |
1110 | int rowCount = d->model->rowCount(d->root); | - |
1111 | if (!rowCount) | - |
1112 | return QModelIndex(); | - |
1113 | int row = 0; | - |
1114 | while (row < rowCount && d->isHiddenOrDisabled(row)) | - |
1115 | ++row; | - |
1116 | if (row >= rowCount) | - |
1117 | return QModelIndex(); | - |
1118 | return d->model->index(row, d->column, d->root); | - |
1119 | } | - |
1120 | | - |
1121 | const QRect initialRect = rectForIndex(current); | - |
1122 | QRect rect = initialRect; | - |
1123 | if (rect.isEmpty()) { | - |
1124 | return d->model->index(0, d->column, d->root); | - |
1125 | } | - |
1126 | if (d->gridSize().isValid()) rect.setSize(d->gridSize()); | - |
1127 | | - |
1128 | QSize contents = d->contentsSize(); | - |
1129 | QVector<QModelIndex> intersectVector; | - |
1130 | | - |
1131 | switch (cursorAction) { | - |
1132 | case MoveLeft: | - |
1133 | while (intersectVector.isEmpty()) { | - |
1134 | rect.translate(-rect.width(), 0); | - |
1135 | if (rect.right() <= 0) | - |
1136 | return current; | - |
1137 | if (rect.left() < 0) | - |
1138 | rect.setLeft(0); | - |
1139 | intersectVector = d->intersectingSet(rect); | - |
1140 | d->removeCurrentAndDisabled(&intersectVector, current); | - |
1141 | } | - |
1142 | return d->closestIndex(initialRect, intersectVector); | - |
1143 | case MoveRight: | - |
1144 | while (intersectVector.isEmpty()) { | - |
1145 | rect.translate(rect.width(), 0); | - |
1146 | if (rect.left() >= contents.width()) | - |
1147 | return current; | - |
1148 | if (rect.right() > contents.width()) | - |
1149 | rect.setRight(contents.width()); | - |
1150 | intersectVector = d->intersectingSet(rect); | - |
1151 | d->removeCurrentAndDisabled(&intersectVector, current); | - |
1152 | } | - |
1153 | return d->closestIndex(initialRect, intersectVector); | - |
1154 | case MovePageUp: | - |
1155 | | - |
1156 | | - |
1157 | rect.moveTop(rect.top() - d->viewport->height() + 2 * rect.height()); | - |
1158 | if (rect.top() < rect.height()) | - |
1159 | rect.moveTop(rect.height()); | - |
1160 | case MovePrevious: | - |
1161 | case MoveUp: | - |
1162 | while (intersectVector.isEmpty()) { | - |
1163 | rect.translate(0, -rect.height()); | - |
1164 | if (rect.bottom() <= 0) { | - |
1165 | #ifdef QT_KEYPAD_NAVIGATION | - |
1166 | if (QApplication::keypadNavigationEnabled()) { | - |
1167 | int row = d->batchStartRow() - 1; | - |
1168 | while (row >= 0 && d->isHiddenOrDisabled(row)) | - |
1169 | --row; | - |
1170 | if (row >= 0) | - |
1171 | return d->model->index(row, d->column, d->root); | - |
1172 | } | - |
1173 | #endif | - |
1174 | return current; | - |
1175 | } | - |
1176 | if (rect.top() < 0) | - |
1177 | rect.setTop(0); | - |
1178 | intersectVector = d->intersectingSet(rect); | - |
1179 | d->removeCurrentAndDisabled(&intersectVector, current); | - |
1180 | } | - |
1181 | return d->closestIndex(initialRect, intersectVector); | - |
1182 | case MovePageDown: | - |
1183 | | - |
1184 | | - |
1185 | rect.moveTop(rect.top() + d->viewport->height() - 2 * rect.height()); | - |
1186 | if (rect.bottom() > contents.height() - rect.height()) | - |
1187 | rect.moveBottom(contents.height() - rect.height()); | - |
1188 | case MoveNext: | - |
1189 | case MoveDown: | - |
1190 | while (intersectVector.isEmpty()) { | - |
1191 | rect.translate(0, rect.height()); | - |
1192 | if (rect.top() >= contents.height()) { | - |
1193 | #ifdef QT_KEYPAD_NAVIGATION | - |
1194 | if (QApplication::keypadNavigationEnabled()) { | - |
1195 | int rowCount = d->model->rowCount(d->root); | - |
1196 | int row = 0; | - |
1197 | while (row < rowCount && d->isHiddenOrDisabled(row)) | - |
1198 | ++row; | - |
1199 | if (row < rowCount) | - |
1200 | return d->model->index(row, d->column, d->root); | - |
1201 | } | - |
1202 | #endif | - |
1203 | return current; | - |
1204 | } | - |
1205 | if (rect.bottom() > contents.height()) | - |
1206 | rect.setBottom(contents.height()); | - |
1207 | intersectVector = d->intersectingSet(rect); | - |
1208 | d->removeCurrentAndDisabled(&intersectVector, current); | - |
1209 | } | - |
1210 | return d->closestIndex(initialRect, intersectVector); | - |
1211 | case MoveHome: | - |
1212 | return d->model->index(0, d->column, d->root); | - |
1213 | case MoveEnd: | - |
1214 | return d->model->index(d->batchStartRow() - 1, d->column, d->root);} | - |
1215 | | - |
1216 | return current; | - |
1217 | } | - |
1218 | | - |
1219 | | - |
1220 | | - |
1221 | | - |
1222 | | - |
1223 | | - |
1224 | | - |
1225 | QRect QListView::rectForIndex(const QModelIndex &index) const | - |
1226 | { | - |
1227 | return d_func()->rectForIndex(index); | - |
1228 | } | - |
1229 | | - |
1230 | | - |
1231 | | - |
1232 | | - |
1233 | | - |
1234 | | - |
1235 | | - |
1236 | | - |
1237 | | - |
1238 | void QListView::setPositionForIndex(const QPoint &position, const QModelIndex &index) | - |
1239 | { | - |
1240 | Q_D(QListView); | - |
1241 | if (d->movement == Static | - |
1242 | || !d->isIndexValid(index) | - |
1243 | || index.parent() != d->root | - |
1244 | || index.column() != d->column) | - |
1245 | return; | - |
1246 | | - |
1247 | d->executePostedLayout(); | - |
1248 | d->commonListView->setPositionForIndex(position, index); | - |
1249 | } | - |
1250 | | - |
1251 | | - |
1252 | | - |
1253 | | - |
1254 | void QListView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) | - |
1255 | { | - |
1256 | Q_D(QListView); | - |
1257 | if (!d->selectionModel) | - |
1258 | return; | - |
1259 | | - |
1260 | | - |
1261 | int w = qMax(d->contentsSize().width(), d->viewport->width()); | - |
1262 | int h = qMax(d->contentsSize().height(), d->viewport->height()); | - |
1263 | if (d->wrap && !QRect(0, 0, w, h).intersects(rect)) | - |
1264 | return; | - |
1265 | | - |
1266 | QItemSelection selection; | - |
1267 | | - |
1268 | if (rect.width() == 1 && rect.height() == 1) { | - |
1269 | const QVector<QModelIndex> intersectVector = d->intersectingSet(rect.translated(horizontalOffset(), verticalOffset())); | - |
1270 | QModelIndex tl; | - |
1271 | if (!intersectVector.isEmpty()) | - |
1272 | tl = intersectVector.last(); | - |
1273 | if (tl.isValid() && d->isIndexEnabled(tl)) | - |
1274 | selection.select(tl, tl); | - |
1275 | } else { | - |
1276 | if (state() == DragSelectingState) { | - |
1277 | selection = d->selection(rect.translated(horizontalOffset(), verticalOffset())); | - |
1278 | } else { | - |
1279 | QModelIndex tl, br; | - |
1280 | | - |
1281 | const QRect topLeft(rect.left() + horizontalOffset(), rect.top() + verticalOffset(), 1, 1); | - |
1282 | QVector<QModelIndex> intersectVector = d->intersectingSet(topLeft); | - |
1283 | if (!intersectVector.isEmpty()) | - |
1284 | tl = intersectVector.last(); | - |
1285 | | - |
1286 | const QRect bottomRight(rect.right() + horizontalOffset(), rect.bottom() + verticalOffset(), 1, 1); | - |
1287 | intersectVector = d->intersectingSet(bottomRight); | - |
1288 | if (!intersectVector.isEmpty()) | - |
1289 | br = intersectVector.last(); | - |
1290 | | - |
1291 | | - |
1292 | if (tl.isValid() && br.isValid() | - |
1293 | && d->isIndexEnabled(tl) | - |
1294 | && d->isIndexEnabled(br)) { | - |
1295 | QRect first = rectForIndex(tl); | - |
1296 | QRect last = rectForIndex(br); | - |
1297 | QRect middle; | - |
1298 | if (d->flow == LeftToRight) { | - |
1299 | QRect &top = first; | - |
1300 | QRect &bottom = last; | - |
1301 | | - |
1302 | if (top.center().y() > bottom.center().y()) { | - |
1303 | QRect tmp = top; | - |
1304 | top = bottom; | - |
1305 | bottom = tmp; | - |
1306 | } | - |
1307 | | - |
1308 | if (top.top() != bottom.top()) { | - |
1309 | | - |
1310 | if (isRightToLeft()) | - |
1311 | top.setLeft(0); | - |
1312 | else | - |
1313 | top.setRight(contentsSize().width()); | - |
1314 | | - |
1315 | if (isRightToLeft()) | - |
1316 | bottom.setRight(contentsSize().width()); | - |
1317 | else | - |
1318 | bottom.setLeft(0); | - |
1319 | } else if (top.left() > bottom.right()) { | - |
1320 | if (isRightToLeft()) | - |
1321 | bottom.setLeft(top.right()); | - |
1322 | else | - |
1323 | bottom.setRight(top.left()); | - |
1324 | } else { | - |
1325 | if (isRightToLeft()) | - |
1326 | top.setLeft(bottom.right()); | - |
1327 | else | - |
1328 | top.setRight(bottom.left()); | - |
1329 | } | - |
1330 | | - |
1331 | if (top.bottom() < bottom.top()) { | - |
1332 | if (gridSize().isValid() && !gridSize().isNull()) | - |
1333 | middle.setTop(top.top() + gridSize().height()); | - |
1334 | else | - |
1335 | middle.setTop(top.bottom() + 1); | - |
1336 | middle.setLeft(qMin(top.left(), bottom.left())); | - |
1337 | middle.setBottom(bottom.top() - 1); | - |
1338 | middle.setRight(qMax(top.right(), bottom.right())); | - |
1339 | } | - |
1340 | } else { | - |
1341 | QRect &left = first; | - |
1342 | QRect &right = last; | - |
1343 | if (left.center().x() > right.center().x()) | - |
1344 | qSwap(left, right); | - |
1345 | | - |
1346 | int ch = contentsSize().height(); | - |
1347 | if (left.left() != right.left()) { | - |
1348 | | - |
1349 | if (isRightToLeft()) | - |
1350 | left.setTop(0); | - |
1351 | else | - |
1352 | left.setBottom(ch); | - |
1353 | | - |
1354 | | - |
1355 | if (isRightToLeft()) | - |
1356 | right.setBottom(ch); | - |
1357 | else | - |
1358 | right.setTop(0); | - |
1359 | | - |
1360 | middle.setTop(0); | - |
1361 | middle.setBottom(ch); | - |
1362 | if (gridSize().isValid() && !gridSize().isNull()) | - |
1363 | middle.setLeft(left.left() + gridSize().width()); | - |
1364 | else | - |
1365 | middle.setLeft(left.right() + 1); | - |
1366 | middle.setRight(right.left() - 1); | - |
1367 | } else if (left.bottom() < right.top()) { | - |
1368 | left.setBottom(right.top() - 1); | - |
1369 | } else { | - |
1370 | right.setBottom(left.top() - 1); | - |
1371 | } | - |
1372 | } | - |
1373 | | - |
1374 | | - |
1375 | QItemSelection topSelection = d->selection(first); | - |
1376 | QItemSelection middleSelection = d->selection(middle); | - |
1377 | QItemSelection bottomSelection = d->selection(last); | - |
1378 | | - |
1379 | selection.merge(topSelection, QItemSelectionModel::Select); | - |
1380 | selection.merge(middleSelection, QItemSelectionModel::Select); | - |
1381 | selection.merge(bottomSelection, QItemSelectionModel::Select); | - |
1382 | } | - |
1383 | } | - |
1384 | } | - |
1385 | | - |
1386 | d->selectionModel->select(selection, command); | - |
1387 | } | - |
1388 | | - |
1389 | | - |
1390 | | - |
1391 | | - |
1392 | | - |
1393 | | - |
1394 | | - |
1395 | QRegion QListView::visualRegionForSelection(const QItemSelection &selection) const | - |
1396 | { | - |
1397 | Q_D(const QListView); | - |
1398 | | - |
1399 | int c = d->column; | - |
1400 | QRegion selectionRegion; | - |
1401 | const QRect &viewportRect = d->viewport->rect(); | - |
1402 | for (int i = 0; i <const auto &elem : selection.count(); ++i) { | - |
1403 | if (!selectionelem.at(i).isValid())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1404 | continue; never executed: continue; | 0 |
1405 | QModelIndex parent = selectionelem.at(i).topLeft().parent(); | - |
1406 | | - |
1407 | | - |
1408 | if (parent != d->root)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1409 | continue; never executed: continue; | 0 |
1410 | int t = selectionelem.at(i).topLeft().row(); | - |
1411 | int b = selectionelem.at(i).bottomRight().row(); | - |
1412 | if (d->viewMode == IconMode || d->isWrapping()) { TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1413 | for (int r = t; r <= b; ++r) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1414 | const QRect &rect = visualRect(d->model->index(r, c, parent)); | - |
1415 | if (viewportRect.intersects(rect))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1416 | selectionRegion += rect; never executed: selectionRegion += rect; | 0 |
1417 | } never executed: end of block | 0 |
1418 | } else { never executed: end of block | 0 |
1419 | while (t <= b && d->isHidden(t)) ++t; never executed: ++t; TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1420 | while (b >= t && d->isHidden(b)) --b; never executed: --b; TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1421 | const QModelIndex top = d->model->index(t, c, parent); | - |
1422 | const QModelIndex bottom = d->model->index(b, c, parent); | - |
1423 | QRect rect(visualRect(top).topLeft(), | - |
1424 | visualRect(bottom).bottomRight()); | - |
1425 | if (viewportRect.intersects(rect))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1426 | selectionRegion += rect; never executed: selectionRegion += rect; | 0 |
1427 | } never executed: end of block | 0 |
1428 | } | - |
1429 | | - |
1430 | return selectionRegion; never executed: return selectionRegion; | 0 |
1431 | } | - |
1432 | | - |
1433 | | - |
1434 | | - |
1435 | | - |
1436 | QModelIndexList QListView::selectedIndexes() const | - |
1437 | { | - |
1438 | Q_D(const QListView); | - |
1439 | if (!d->selectionModel)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1440 | return QModelIndexList(); never executed: return QModelIndexList(); | 0 |
1441 | | - |
1442 | QModelIndexList viewSelected = d->selectionModel->selectedIndexes(); | - |
1443 | for (int iauto ignorable = 0; i < viewSelected.count();) {[this, d](const QModelIndex &index= viewSelected.at(i); | - |
| if (!isIndexHidden(index) &&{ | |
1444 | return never executed: return index.column() != d->column || index.parent() != d->root || isIndexHidden(index); index.parentcolumn() ==!= d->root &&column || index.columnparent() ==!= d->column)never executed: return index.column() != d->column || index.parent() != d->root || isIndexHidden(index); | 0 |
| ++i; never executed: return index.column() != d->column || index.parent() != d->root || isIndexHidden(index); | |
| else never executed: return index.column() != d->column || index.parent() != d->root || isIndexHidden(index); root || isIndexHidden(index);never executed: return index.column() != d->column || index.parent() != d->root || isIndexHidden(index); | |
1445 | }; | - |
1446 | viewSelected.removeAterase(i); | - |
| }std::remove_if(viewSelected.begin(), viewSelected.end(), ignorable), | |
1447 | viewSelected.end()); | - |
1448 | return viewSelected; never executed: return viewSelected; | 0 |
1449 | } | - |
1450 | | - |
1451 | | - |
1452 | | - |
1453 | | - |
1454 | | - |
1455 | | - |
1456 | void QListView::doItemsLayout() | - |
1457 | { | - |
1458 | Q_D(QListView); | - |
1459 | | - |
1460 | | - |
1461 | | - |
1462 | QAbstractItemView::State oldState = state(); | - |
1463 | setState(ExpandingState); | - |
1464 | if (d->model->columnCount(d->root) > 0) { | - |
1465 | d->resetBatchStartRow(); | - |
1466 | if (layoutMode() == SinglePass) | - |
1467 | d->doItemsLayout(d->model->rowCount(d->root)); | - |
1468 | else if (!d->batchLayoutTimer.isActive()) { | - |
1469 | if (!d->doItemsLayout(d->batchSize)) | - |
1470 | d->batchLayoutTimer.start(0, this); | - |
1471 | } | - |
1472 | } | - |
1473 | QAbstractItemView::doItemsLayout(); | - |
1474 | setState(oldState); | - |
1475 | } | - |
1476 | | - |
1477 | | - |
1478 | | - |
1479 | | - |
1480 | void QListView::updateGeometries() | - |
1481 | { | - |
1482 | Q_D(QListView); | - |
1483 | if (geometry().isEmpty() || d->model->rowCount(d->root) <= 0 || d->model->columnCount(d->root) <= 0) { | - |
1484 | horizontalScrollBar()->setRange(0, 0); | - |
1485 | verticalScrollBar()->setRange(0, 0); | - |
1486 | } else { | - |
1487 | QModelIndex index = d->model->index(0, d->column, d->root); | - |
1488 | QStyleOptionViewItem option = d->viewOptionsV1(); | - |
1489 | QSize step = d->itemSize(option, index); | - |
1490 | d->commonListView->updateHorizontalScrollBar(step); | - |
1491 | d->commonListView->updateVerticalScrollBar(step); | - |
1492 | } | - |
1493 | | - |
1494 | QAbstractItemView::updateGeometries(); | - |
1495 | | - |
1496 | | - |
1497 | if (d->movement == Static && !d->isWrapping()) { | - |
1498 | d->layoutChildren(); | - |
1499 | if (d->flow == TopToBottom) { | - |
1500 | if (horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff) { | - |
1501 | d->setContentsSize(viewport()->width(), contentsSize().height()); | - |
1502 | horizontalScrollBar()->setRange(0, 0); | - |
1503 | } | - |
1504 | } else { | - |
1505 | if (verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff) { | - |
1506 | d->setContentsSize(contentsSize().width(), viewport()->height()); | - |
1507 | verticalScrollBar()->setRange(0, 0); | - |
1508 | } | - |
1509 | } | - |
1510 | } | - |
1511 | | - |
1512 | } | - |
1513 | | - |
1514 | | - |
1515 | | - |
1516 | | - |
1517 | bool QListView::isIndexHidden(const QModelIndex &index) const | - |
1518 | { | - |
1519 | Q_D(const QListView); | - |
1520 | return (d->isHidden(index.row()) | - |
1521 | && (index.parent() == d->root) | - |
1522 | && index.column() == d->column); | - |
1523 | } | - |
1524 | | - |
1525 | | - |
1526 | | - |
1527 | | - |
1528 | | - |
1529 | | - |
1530 | | - |
1531 | | - |
1532 | void QListView::setModelColumn(int column) | - |
1533 | { | - |
1534 | Q_D(QListView); | - |
1535 | if (column < 0 || column >= d->model->columnCount(d->root)) | - |
1536 | return; | - |
1537 | d->column = column; | - |
1538 | d->doDelayedItemsLayout(); | - |
1539 | } | - |
1540 | | - |
1541 | int QListView::modelColumn() const | - |
1542 | { | - |
1543 | Q_D(const QListView); | - |
1544 | return d->column; | - |
1545 | } | - |
1546 | | - |
1547 | | - |
1548 | | - |
1549 | | - |
1550 | | - |
1551 | | - |
1552 | | - |
1553 | | - |
1554 | | - |
1555 | | - |
1556 | | - |
1557 | | - |
1558 | void QListView::setUniformItemSizes(bool enable) | - |
1559 | { | - |
1560 | Q_D(QListView); | - |
1561 | d->uniformItemSizes = enable; | - |
1562 | } | - |
1563 | | - |
1564 | bool QListView::uniformItemSizes() const | - |
1565 | { | - |
1566 | Q_D(const QListView); | - |
1567 | return d->uniformItemSizes; | - |
1568 | } | - |
1569 | | - |
1570 | | - |
1571 | | - |
1572 | | - |
1573 | | - |
1574 | | - |
1575 | | - |
1576 | | - |
1577 | | - |
1578 | | - |
1579 | | - |
1580 | | - |
1581 | | - |
1582 | | - |
1583 | | - |
1584 | void QListView::setWordWrap(bool on) | - |
1585 | { | - |
1586 | Q_D(QListView); | - |
1587 | if (d->wrapItemText == on) | - |
1588 | return; | - |
1589 | d->wrapItemText = on; | - |
1590 | d->doDelayedItemsLayout(); | - |
1591 | } | - |
1592 | | - |
1593 | bool QListView::wordWrap() const | - |
1594 | { | - |
1595 | Q_D(const QListView); | - |
1596 | return d->wrapItemText; | - |
1597 | } | - |
1598 | | - |
1599 | | - |
1600 | | - |
1601 | | - |
1602 | | - |
1603 | | - |
1604 | | - |
1605 | | - |
1606 | | - |
1607 | | - |
1608 | | - |
1609 | | - |
1610 | | - |
1611 | | - |
1612 | | - |
1613 | | - |
1614 | void QListView::setSelectionRectVisible(bool show) | - |
1615 | { | - |
1616 | Q_D(QListView); | - |
1617 | d->modeProperties |= uint(QListViewPrivate::SelectionRectVisible); | - |
1618 | d->setSelectionRectVisible(show); | - |
1619 | } | - |
1620 | | - |
1621 | bool QListView::isSelectionRectVisible() const | - |
1622 | { | - |
1623 | Q_D(const QListView); | - |
1624 | return d->isSelectionRectVisible(); | - |
1625 | } | - |
1626 | | - |
1627 | | - |
1628 | | - |
1629 | | - |
1630 | bool QListView::event(QEvent *e) | - |
1631 | { | - |
1632 | return QAbstractItemView::event(e); | - |
1633 | } | - |
1634 | | - |
1635 | | - |
1636 | | - |
1637 | | - |
1638 | | - |
1639 | QListViewPrivate::QListViewPrivate() | - |
1640 | : QAbstractItemViewPrivate(), | - |
1641 | commonListView(0), | - |
1642 | wrap(false), | - |
1643 | space(0), | - |
1644 | flow(QListView::TopToBottom), | - |
1645 | movement(QListView::Static), | - |
1646 | resizeMode(QListView::Fixed), | - |
1647 | layoutMode(QListView::SinglePass), | - |
1648 | viewMode(QListView::ListMode), | - |
1649 | modeProperties(0), | - |
1650 | column(0), | - |
1651 | uniformItemSizes(false), | - |
1652 | batchSize(100), | - |
1653 | showElasticBand(false) | - |
1654 | { | - |
1655 | } | - |
1656 | | - |
1657 | QListViewPrivate::~QListViewPrivate() | - |
1658 | { | - |
1659 | delete commonListView; | - |
1660 | } | - |
1661 | | - |
1662 | void QListViewPrivate::clear() | - |
1663 | { | - |
1664 | | - |
1665 | cachedItemSize = QSize(); | - |
1666 | commonListView->clear(); | - |
1667 | } | - |
1668 | | - |
1669 | void QListViewPrivate::prepareItemsLayout() | - |
1670 | { | - |
1671 | Q_Q(QListView); | - |
1672 | clear(); | - |
1673 | | - |
1674 | | - |
1675 | layoutBounds = QRect(QPoint(), q->maximumViewportSize()); | - |
1676 | | - |
1677 | int frameAroundContents = 0; | - |
1678 | if (q->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents)) | - |
1679 | frameAroundContents = q->style()->pixelMetric(QStyle::PM_DefaultFrameWidth) * 2; | - |
1680 | | - |
1681 | | - |
1682 | | - |
1683 | | - |
1684 | int verticalMargin = vbarpolicy==Qt::ScrollBarAsNeeded | - |
1685 | ? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, vbar) + frameAroundContents | - |
1686 | : 0; | - |
1687 | int horizontalMargin = hbarpolicy==Qt::ScrollBarAsNeeded | - |
1688 | ? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, hbar) + frameAroundContents | - |
1689 | : 0; | - |
1690 | | - |
1691 | layoutBounds.adjust(0, 0, -verticalMargin, -horizontalMargin); | - |
1692 | | - |
1693 | int rowCount = model->columnCount(root) <= 0 ? 0 : model->rowCount(root); | - |
1694 | commonListView->setRowCount(rowCount); | - |
1695 | } | - |
1696 | | - |
1697 | | - |
1698 | | - |
1699 | | - |
1700 | bool QListViewPrivate::doItemsLayout(int delta) | - |
1701 | { | - |
1702 | int max = model->rowCount(root) - 1; | - |
1703 | int first = batchStartRow(); | - |
1704 | int last = qMin(first + delta - 1, max); | - |
1705 | | - |
1706 | if (first == 0) { | - |
1707 | layoutChildren(); | - |
1708 | prepareItemsLayout(); | - |
1709 | } | - |
1710 | | - |
1711 | if (max < 0 || last < first) { | - |
1712 | return true; | - |
1713 | } | - |
1714 | | - |
1715 | QListViewLayoutInfo info; | - |
1716 | info.bounds = layoutBounds; | - |
1717 | info.grid = gridSize(); | - |
1718 | info.spacing = (info.grid.isValid() ? 0 : spacing()); | - |
1719 | info.first = first; | - |
1720 | info.last = last; | - |
1721 | info.wrap = isWrapping(); | - |
1722 | info.flow = flow; | - |
1723 | info.max = max; | - |
1724 | | - |
1725 | return commonListView->doBatchedItemLayout(info, max); | - |
1726 | } | - |
1727 | | - |
1728 | QListViewItem QListViewPrivate::indexToListViewItem(const QModelIndex &index) const | - |
1729 | { | - |
1730 | if (!index.isValid() || isHidden(index.row())) | - |
1731 | return QListViewItem(); | - |
1732 | | - |
1733 | return commonListView->indexToListViewItem(index); | - |
1734 | } | - |
1735 | | - |
1736 | QRect QListViewPrivate::mapToViewport(const QRect &rect, bool extend) const | - |
1737 | { | - |
1738 | Q_Q(const QListView); | - |
1739 | if (!rect.isValid()) | - |
1740 | return rect; | - |
1741 | | - |
1742 | QRect result = extend ? commonListView->mapToViewport(rect) : rect; | - |
1743 | int dx = -q->horizontalOffset(); | - |
1744 | int dy = -q->verticalOffset(); | - |
1745 | return result.adjusted(dx, dy, dx, dy); | - |
1746 | } | - |
1747 | | - |
1748 | QModelIndex QListViewPrivate::closestIndex(const QRect &target, | - |
1749 | const QVector<QModelIndex> &candidates) const | - |
1750 | { | - |
1751 | int distance = 0; | - |
1752 | int shortest = INT_MAX; | - |
1753 | QModelIndex closest; | - |
1754 | QVector<QModelIndex>::const_iterator it = candidates.begin(); | - |
1755 | | - |
1756 | for (; it != candidates.end(); ++it) { | - |
1757 | if (!(*it).isValid()) | - |
1758 | continue; | - |
1759 | | - |
1760 | const QRect indexRect = indexToListViewItem(*it).rect(); | - |
1761 | | - |
1762 | | - |
1763 | | - |
1764 | | - |
1765 | if ((target.center().x() >= indexRect.x() && target.center().x() < indexRect.right()) | - |
1766 | || (indexRect.center().x() >= target.x() && indexRect.center().x() < target.right())) { | - |
1767 | | - |
1768 | distance = qAbs(indexRect.center().y() - target.center().y()); | - |
1769 | } else if ((target.center().y() >= indexRect.y() && target.center().y() < indexRect.bottom()) | - |
1770 | || (indexRect.center().y() >= target.y() && indexRect.center().y() < target.bottom())) { | - |
1771 | | - |
1772 | distance = qAbs(indexRect.center().x() - target.center().x()); | - |
1773 | } else { | - |
1774 | distance = (indexRect.center() - target.center()).manhattanLength(); | - |
1775 | } | - |
1776 | if (distance < shortest) { | - |
1777 | shortest = distance; | - |
1778 | closest = *it; | - |
1779 | } | - |
1780 | } | - |
1781 | return closest; | - |
1782 | } | - |
1783 | | - |
1784 | QSize QListViewPrivate::itemSize(const QStyleOptionViewItem &option, const QModelIndex &index) const | - |
1785 | { | - |
1786 | if (!uniformItemSizes) { | - |
1787 | const QAbstractItemDelegate *delegate = delegateForIndex(index); | - |
1788 | return delegate ? delegate->sizeHint(option, index) : QSize(); | - |
1789 | } | - |
1790 | if (!cachedItemSize.isValid()) { | - |
1791 | int row = model->rowCount(root) - 1; | - |
1792 | QModelIndex sample = model->index(row, column, root); | - |
1793 | const QAbstractItemDelegate *delegate = delegateForIndex(sample); | - |
1794 | cachedItemSize = delegate ? delegate->sizeHint(option, sample) : QSize(); | - |
1795 | } | - |
1796 | return cachedItemSize; | - |
1797 | } | - |
1798 | | - |
1799 | QItemSelection QListViewPrivate::selection(const QRect &rect) const | - |
1800 | { | - |
1801 | QItemSelection selection; | - |
1802 | QModelIndex tl, br; | - |
1803 | const QVector<QModelIndex> intersectVector = intersectingSet(rect); | - |
1804 | QVector<QModelIndex>::const_iterator it = intersectVector.begin(); | - |
1805 | for (; it != intersectVector.end(); ++it) { | - |
1806 | if (!tl.isValid() && !br.isValid()) { | - |
1807 | tl = br = *it; | - |
1808 | } else if ((*it).row() == (tl.row() - 1)) { | - |
1809 | tl = *it; | - |
1810 | } else if ((*it).row() == (br.row() + 1)) { | - |
1811 | br = (*it); | - |
1812 | } else { | - |
1813 | selection.select(tl, br); | - |
1814 | tl = br = *it; | - |
1815 | } | - |
1816 | } | - |
1817 | | - |
1818 | if (tl.isValid() && br.isValid()) | - |
1819 | selection.select(tl, br); | - |
1820 | else if (tl.isValid()) | - |
1821 | selection.select(tl, tl); | - |
1822 | else if (br.isValid()) | - |
1823 | selection.select(br, br); | - |
1824 | | - |
1825 | return selection; | - |
1826 | } | - |
1827 | | - |
1828 | #ifndef QT_NO_DRAGANDDROP | - |
1829 | QAbstractItemView::DropIndicatorPosition QListViewPrivate::position(const QPoint &pos, const QRect &rect, const QModelIndex &idx) const | - |
1830 | { | - |
1831 | if (viewMode == QListView::ListMode && flow == QListView::LeftToRight) | - |
1832 | return static_cast<QListModeViewBase *>(commonListView)->position(pos, rect, idx); | - |
1833 | else | - |
1834 | return QAbstractItemViewPrivate::position(pos, rect, idx); | - |
1835 | } | - |
1836 | | - |
1837 | bool QListViewPrivate::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QModelIndex *dropIndex) | - |
1838 | { | - |
1839 | if (viewMode == QListView::ListMode && flow == QListView::LeftToRight) | - |
1840 | return static_cast<QListModeViewBase *>(commonListView)->dropOn(event, dropRow, dropCol, dropIndex); | - |
1841 | else | - |
1842 | return QAbstractItemViewPrivate::dropOn(event, dropRow, dropCol, dropIndex); | - |
1843 | } | - |
1844 | #endif | - |
1845 | | - |
1846 | void QListViewPrivate::removeCurrentAndDisabled(QVector<QModelIndex> *indexes, const QModelIndex ¤t) const | - |
1847 | { | - |
1848 | auto isCurrentOrDisabled = [=](const QModelIndex &index) { | - |
1849 | return !isIndexEnabled(index) || index == current; never executed: return !isIndexEnabled(index) || index == current; | 0 |
1850 | }; | - |
1851 | indexes->erase(std::remove_if(indexes->begin(), indexes->end(), | - |
1852 | isCurrentOrDisabled), | - |
1853 | indexes->end()); | - |
1854 | } never executed: end of block | 0 |
1855 | | - |
1856 | | - |
1857 | | - |
1858 | | - |
1859 | | - |
1860 | void QCommonListViewBase::appendHiddenRow(int row) | - |
1861 | { | - |
1862 | dd->hiddenRows.insert(dd->model->index(row, 0, qq->rootIndex())); | - |
1863 | } | - |
1864 | | - |
1865 | void QCommonListViewBase::removeHiddenRow(int row) | - |
1866 | { | - |
1867 | dd->hiddenRows.remove(dd->model->index(row, 0, qq->rootIndex())); | - |
1868 | } | - |
1869 | | - |
1870 | #ifndef QT_NO_DRAGANDDROP | - |
1871 | void QCommonListViewBase::paintDragDrop(QPainter *painter) | - |
1872 | { | - |
1873 | | - |
1874 | | - |
1875 | dd->paintDropIndicator(painter); | - |
1876 | } | - |
1877 | #endif | - |
1878 | | - |
1879 | void QCommonListViewBase::updateHorizontalScrollBar(const QSize &step) | - |
1880 | { | - |
1881 | horizontalScrollBar()->setSingleStepd_func()->itemviewChangeSingleStep(step.width() + spacing()); | - |
1882 | horizontalScrollBar()->setPageStep(viewport()->width()); | - |
1883 | | - |
1884 | | - |
1885 | | - |
1886 | | - |
1887 | | - |
1888 | const bool bothScrollBarsAuto = qq->verticalScrollBarPolicy() == Qt::ScrollBarAsNeeded &&TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1889 | qq->horizontalScrollBarPolicy() == Qt::ScrollBarAsNeeded;TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1890 | | - |
1891 | const QSize viewportSize = qq->contentsRect().size(); | - |
1892 | | - |
1893 | bool verticalWantsToShow = contentsSize.height() > viewportSize.height(); | - |
1894 | bool horizontalWantsToShow; | - |
1895 | if (verticalWantsToShow)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1896 | horizontalWantsToShow = contentsSize.width() > viewportSize.width() - qq->verticalScrollBar()->width(); never executed: horizontalWantsToShow = contentsSize.width() > viewportSize.width() - qq->verticalScrollBar()->width(); | 0 |
1897 | else | - |
1898 | horizontalWantsToShow = contentsSize.width() > viewportSize.width(); never executed: horizontalWantsToShow = contentsSize.width() > viewportSize.width(); | 0 |
1899 | | - |
1900 | if (bothScrollBarsAuto && !horizontalWantsToShow) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1901 | | - |
1902 | | - |
1903 | horizontalScrollBar()->setRange(0, 0); | - |
1904 | } else { never executed: end of block | 0 |
1905 | horizontalScrollBar()->setRange(0, contentsSize.width() - viewport()->width()); | - |
1906 | } never executed: end of block | 0 |
1907 | } | - |
1908 | | - |
1909 | void QCommonListViewBase::updateVerticalScrollBar(const QSize &step) | - |
1910 | { | - |
1911 | verticalScrollBar()->setSingleStepd_func()->itemviewChangeSingleStep(step.height() + spacing()); | - |
1912 | verticalScrollBar()->setPageStep(viewport()->height()); | - |
1913 | | - |
1914 | | - |
1915 | | - |
1916 | | - |
1917 | | - |
1918 | const bool bothScrollBarsAuto = qq->verticalScrollBarPolicy() == Qt::ScrollBarAsNeeded &&TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1919 | qq->horizontalScrollBarPolicy() == Qt::ScrollBarAsNeeded;TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1920 | | - |
1921 | const QSize viewportSize = qq->contentsRect().size(); | - |
1922 | | - |
1923 | bool horizontalWantsToShow = contentsSize.width() > viewportSize.width(); | - |
1924 | bool verticalWantsToShow; | - |
1925 | if (horizontalWantsToShow)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1926 | verticalWantsToShow = contentsSize.height() > viewportSize.height() - qq->horizontalScrollBar()->height(); never executed: verticalWantsToShow = contentsSize.height() > viewportSize.height() - qq->horizontalScrollBar()->height(); | 0 |
1927 | else | - |
1928 | verticalWantsToShow = contentsSize.height() > viewportSize.height(); never executed: verticalWantsToShow = contentsSize.height() > viewportSize.height(); | 0 |
1929 | | - |
1930 | if (bothScrollBarsAuto && !verticalWantsToShow) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1931 | | - |
1932 | | - |
1933 | verticalScrollBar()->setRange(0, 0); | - |
1934 | } else { never executed: end of block | 0 |
1935 | verticalScrollBar()->setRange(0, contentsSize.height() - viewport()->height()); | - |
1936 | } never executed: end of block | 0 |
1937 | } | - |
1938 | | - |
1939 | void QCommonListViewBase::scrollContentsBy(int dx, int dy, bool ) | - |
1940 | { | - |
1941 | dd->scrollContentsBy(isRightToLeft() ? -dx : dx, dy); | - |
1942 | } | - |
1943 | | - |
1944 | int QCommonListViewBase::verticalScrollToValue(int , QListView::ScrollHint hint, | - |
1945 | bool above, bool below, const QRect &area, const QRect &rect) const | - |
1946 | { | - |
1947 | int verticalValue = verticalScrollBar()->value(); | - |
1948 | QRect adjusted = rect.adjusted(-spacing(), -spacing(), spacing(), spacing()); | - |
1949 | if (hint == QListView::PositionAtTop || above) | - |
1950 | verticalValue += adjusted.top(); | - |
1951 | else if (hint == QListView::PositionAtBottom || below) | - |
1952 | verticalValue += qMin(adjusted.top(), adjusted.bottom() - area.height() + 1); | - |
1953 | else if (hint == QListView::PositionAtCenter) | - |
1954 | verticalValue += adjusted.top() - ((area.height() - adjusted.height()) / 2); | - |
1955 | return verticalValue; | - |
1956 | } | - |
1957 | | - |
1958 | int QCommonListViewBase::horizontalOffset() const | - |
1959 | { | - |
1960 | return (isRightToLeft() ? horizontalScrollBar()->maximum() - horizontalScrollBar()->value() : horizontalScrollBar()->value()); | - |
1961 | } | - |
1962 | | - |
1963 | int QCommonListViewBase::horizontalScrollToValue(const int , QListView::ScrollHint hint, | - |
1964 | bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const | - |
1965 | { | - |
1966 | int horizontalValue = horizontalScrollBar()->value(); | - |
1967 | if (isRightToLeft()) { | - |
1968 | if (hint == QListView::PositionAtCenter) { | - |
1969 | horizontalValue += ((area.width() - rect.width()) / 2) - rect.left(); | - |
1970 | } else { | - |
1971 | if (leftOf) | - |
1972 | horizontalValue -= rect.left(); | - |
1973 | else if (rightOf) | - |
1974 | horizontalValue += qMin(rect.left(), area.width() - rect.right()); | - |
1975 | } | - |
1976 | } else { | - |
1977 | if (hint == QListView::PositionAtCenter) { | - |
1978 | horizontalValue += rect.left() - ((area.width()- rect.width()) / 2); | - |
1979 | } else { | - |
1980 | if (leftOf) | - |
1981 | horizontalValue += rect.left(); | - |
1982 | else if (rightOf) | - |
1983 | horizontalValue += qMin(rect.left(), rect.right() - area.width()); | - |
1984 | } | - |
1985 | } | - |
1986 | return horizontalValue; | - |
1987 | } | - |
1988 | | - |
1989 | | - |
1990 | | - |
1991 | | - |
1992 | QListModeViewBase::QListModeViewBase(QListView *q, QListViewPrivate *d) | - |
1993 | : QCommonListViewBase(q, d) | - |
1994 | { | - |
1995 | dd->defaultDropAction = Qt::CopyAction; | - |
1996 | } | - |
1997 | | - |
1998 | #ifndef QT_NO_DRAGANDDROP | - |
1999 | QAbstractItemView::DropIndicatorPosition QListModeViewBase::position(const QPoint &pos, const QRect &rect, const QModelIndex &index) const | - |
2000 | { | - |
2001 | QAbstractItemView::DropIndicatorPosition r = QAbstractItemView::OnViewport; | - |
2002 | if (!dd->overwrite) { | - |
2003 | const int margin = 2; | - |
2004 | if (pos.x() - rect.left() < margin) { | - |
2005 | r = QAbstractItemView::AboveItem; | - |
2006 | } else if (rect.right() - pos.x() < margin) { | - |
2007 | r = QAbstractItemView::BelowItem; | - |
2008 | } else if (rect.contains(pos, true)) { | - |
2009 | r = QAbstractItemView::OnItem; | - |
2010 | } | - |
2011 | } else { | - |
2012 | QRect touchingRect = rect; | - |
2013 | touchingRect.adjust(-1, -1, 1, 1); | - |
2014 | if (touchingRect.contains(pos, false)) { | - |
2015 | r = QAbstractItemView::OnItem; | - |
2016 | } | - |
2017 | } | - |
2018 | | - |
2019 | if (r == QAbstractItemView::OnItem && (!(dd->model->flags(index) & Qt::ItemIsDropEnabled))) | - |
2020 | r = pos.x() < rect.center().x() ? QAbstractItemView::AboveItem : QAbstractItemView::BelowItem; | - |
2021 | | - |
2022 | return r; | - |
2023 | } | - |
2024 | | - |
2025 | void QListModeViewBase::dragMoveEvent(QDragMoveEvent *event) | - |
2026 | { | - |
2027 | if (qq->dragDropMode() == QAbstractItemView::InternalMove | - |
2028 | && (event->source() != qq || !(event->possibleActions() & Qt::MoveAction))) | - |
2029 | return; | - |
2030 | | - |
2031 | | - |
2032 | event->ignore(); | - |
2033 | | - |
2034 | | - |
2035 | QPoint p = event->pos(); | - |
2036 | QRect rect(p.x() + horizontalOffset(), p.y() + verticalOffset(), 1, 1); | - |
2037 | rect.adjust(-dd->spacing(), -dd->spacing(), dd->spacing(), dd->spacing()); | - |
2038 | const QVector<QModelIndex> intersectVector = dd->intersectingSet(rect); | - |
2039 | QModelIndex index = intersectVector.count() > 0 | - |
2040 | ? intersectVector.last() : QModelIndex(); | - |
2041 | dd->hover = index; | - |
2042 | if (!dd->droppingOnItself(event, index) | - |
2043 | && dd->canDrop(event)) { | - |
2044 | | - |
2045 | if (index.isValid() && dd->showDropIndicator) { | - |
2046 | QRect rect = qq->visualRect(index); | - |
2047 | dd->dropIndicatorPosition = position(event->pos(), rect, index); | - |
2048 | | - |
2049 | switch (dd->dropIndicatorPosition) { | - |
2050 | case QAbstractItemView::AboveItem: | - |
2051 | if (dd->isIndexDropEnabled(index.parent())) { | - |
2052 | dd->dropIndicatorRect = QRect(rect.left()-dd->spacing(), rect.top(), 0, rect.height()); | - |
2053 | event->accept(); | - |
2054 | } else { | - |
2055 | dd->dropIndicatorRect = QRect(); | - |
2056 | } | - |
2057 | break; | - |
2058 | case QAbstractItemView::BelowItem: | - |
2059 | if (dd->isIndexDropEnabled(index.parent())) { | - |
2060 | dd->dropIndicatorRect = QRect(rect.right()+dd->spacing(), rect.top(), 0, rect.height()); | - |
2061 | event->accept(); | - |
2062 | } else { | - |
2063 | dd->dropIndicatorRect = QRect(); | - |
2064 | } | - |
2065 | break; | - |
2066 | case QAbstractItemView::OnItem: | - |
2067 | if (dd->isIndexDropEnabled(index)) { | - |
2068 | dd->dropIndicatorRect = rect; | - |
2069 | event->accept(); | - |
2070 | } else { | - |
2071 | dd->dropIndicatorRect = QRect(); | - |
2072 | } | - |
2073 | break; | - |
2074 | case QAbstractItemView::OnViewport: | - |
2075 | dd->dropIndicatorRect = QRect(); | - |
2076 | if (dd->isIndexDropEnabled(qq->rootIndex())) { | - |
2077 | event->accept(); | - |
2078 | } | - |
2079 | break; | - |
2080 | } | - |
2081 | } else { | - |
2082 | dd->dropIndicatorRect = QRect(); | - |
2083 | dd->dropIndicatorPosition = QAbstractItemView::OnViewport; | - |
2084 | if (dd->isIndexDropEnabled(qq->rootIndex())) { | - |
2085 | event->accept(); | - |
2086 | } | - |
2087 | } | - |
2088 | dd->viewport->update(); | - |
2089 | } | - |
2090 | | - |
2091 | if (dd->shouldAutoScroll(event->pos())) | - |
2092 | qq->startAutoScroll(); | - |
2093 | } | - |
2094 | | - |
2095 | | - |
2096 | | - |
2097 | | - |
2098 | | - |
2099 | | - |
2100 | | - |
2101 | | - |
2102 | | - |
2103 | | - |
2104 | | - |
2105 | | - |
2106 | bool QListModeViewBase::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QModelIndex *dropIndex) | - |
2107 | { | - |
2108 | if (event->isAccepted()) | - |
2109 | return false; | - |
2110 | | - |
2111 | QModelIndex index; | - |
2112 | if (dd->viewport->rect().contains(event->pos())) { | - |
2113 | | - |
2114 | QPoint p = event->pos(); | - |
2115 | QRect rect(p.x() + horizontalOffset(), p.y() + verticalOffset(), 1, 1); | - |
2116 | rect.adjust(-dd->spacing(), -dd->spacing(), dd->spacing(), dd->spacing()); | - |
2117 | const QVector<QModelIndex> intersectVector = dd->intersectingSet(rect); | - |
2118 | index = intersectVector.count() > 0 | - |
2119 | ? intersectVector.last() : QModelIndex(); | - |
2120 | if (!index.isValid()) | - |
2121 | index = dd->root; | - |
2122 | } | - |
2123 | | - |
2124 | | - |
2125 | if (dd->model->supportedDropActions() & event->dropAction()) { | - |
2126 | int row = -1; | - |
2127 | int col = -1; | - |
2128 | if (index != dd->root) { | - |
2129 | dd->dropIndicatorPosition = position(event->pos(), qq->visualRect(index), index); | - |
2130 | switch (dd->dropIndicatorPosition) { | - |
2131 | case QAbstractItemView::AboveItem: | - |
2132 | row = index.row(); | - |
2133 | col = index.column(); | - |
2134 | index = index.parent(); | - |
2135 | break; | - |
2136 | case QAbstractItemView::BelowItem: | - |
2137 | row = index.row() + 1; | - |
2138 | col = index.column(); | - |
2139 | index = index.parent(); | - |
2140 | break; | - |
2141 | case QAbstractItemView::OnItem: | - |
2142 | case QAbstractItemView::OnViewport: | - |
2143 | break; | - |
2144 | } | - |
2145 | } else { | - |
2146 | dd->dropIndicatorPosition = QAbstractItemView::OnViewport; | - |
2147 | } | - |
2148 | *dropIndex = index; | - |
2149 | *dropRow = row; | - |
2150 | *dropCol = col; | - |
2151 | if (!dd->droppingOnItself(event, index)) | - |
2152 | return true; | - |
2153 | } | - |
2154 | return false; | - |
2155 | } | - |
2156 | | - |
2157 | #endif //QT_NO_DRAGANDDROP | - |
2158 | | - |
2159 | void QListModeViewBase::updateVerticalScrollBar(const QSize &step) | - |
2160 | { | - |
2161 | if (verticalScrollMode() == QAbstractItemView::ScrollPerItem | - |
2162 | && ((flow() == QListView::TopToBottom && !isWrapping()) | - |
2163 | || (flow() == QListView::LeftToRight && isWrapping()))) { | - |
2164 | const int steps = (flow() == QListView::TopToBottom ? scrollValueMap : segmentPositions).count() - 1; | - |
2165 | if (steps > 0) { | - |
2166 | const int pageSteps = perItemScrollingPageSteps(viewport()->height(), contentsSize.height(), isWrapping()); | - |
2167 | verticalScrollBar()->setSingleStep(1); | - |
2168 | verticalScrollBar()->setPageStep(pageSteps); | - |
2169 | verticalScrollBar()->setRange(0, steps - pageSteps); | - |
2170 | } else { | - |
2171 | verticalScrollBar()->setRange(0, 0); | - |
2172 | } | - |
2173 | | - |
2174 | | - |
2175 | } else { | - |
2176 | QCommonListViewBase::updateVerticalScrollBar(step); | - |
2177 | } | - |
2178 | } | - |
2179 | | - |
2180 | void QListModeViewBase::updateHorizontalScrollBar(const QSize &step) | - |
2181 | { | - |
2182 | if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem | - |
2183 | && ((flow() == QListView::TopToBottom && isWrapping()) | - |
2184 | || (flow() == QListView::LeftToRight && !isWrapping()))) { | - |
2185 | int steps = (flow() == QListView::TopToBottom ? segmentPositions : scrollValueMap).count() - 1; | - |
2186 | if (steps > 0) { | - |
2187 | const int pageSteps = perItemScrollingPageSteps(viewport()->width(), contentsSize.width(), isWrapping()); | - |
2188 | horizontalScrollBar()->setSingleStep(1); | - |
2189 | horizontalScrollBar()->setPageStep(pageSteps); | - |
2190 | horizontalScrollBar()->setRange(0, steps - pageSteps); | - |
2191 | } else { | - |
2192 | horizontalScrollBar()->setRange(0, 0); | - |
2193 | } | - |
2194 | } else { | - |
2195 | QCommonListViewBase::updateHorizontalScrollBar(step); | - |
2196 | } | - |
2197 | } | - |
2198 | | - |
2199 | int QListModeViewBase::verticalScrollToValue(int index, QListView::ScrollHint hint, | - |
2200 | bool above, bool below, const QRect &area, const QRect &rect) const | - |
2201 | { | - |
2202 | if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) { | - |
2203 | int value; | - |
2204 | if (scrollValueMap.isEmpty()) { | - |
2205 | value = 0; | - |
2206 | } else { | - |
2207 | int scrollBarValue = verticalScrollBar()->value(); | - |
2208 | int numHidden = 0; | - |
2209 | for (int i = 0; i < flowPositions.count() - 1 && i <= scrollBarValue; ++i) | - |
2210 | if (isHidden(i)) | - |
2211 | ++numHidden; | - |
2212 | value = qBound(0, scrollValueMap.at(verticalScrollBar()->value()) - numHidden, flowPositions.count() - 1); | - |
2213 | } | - |
2214 | if (above) | - |
2215 | hint = QListView::PositionAtTop; | - |
2216 | else if (below) | - |
2217 | hint = QListView::PositionAtBottom; | - |
2218 | if (hint == QListView::EnsureVisible) | - |
2219 | return value; | - |
2220 | | - |
2221 | return perItemScrollToValue(index, value, area.height(), hint, Qt::Vertical, isWrapping(), rect.height()); | - |
2222 | } | - |
2223 | | - |
2224 | return QCommonListViewBase::verticalScrollToValue(index, hint, above, below, area, rect); | - |
2225 | } | - |
2226 | | - |
2227 | int QListModeViewBase::horizontalOffset() const | - |
2228 | { | - |
2229 | if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem) { | - |
2230 | if (isWrapping()) { | - |
2231 | if (flow() == QListView::TopToBottom && !segmentPositions.isEmpty()) { | - |
2232 | const int max = segmentPositions.count() - 1; | - |
2233 | int currentValue = qBound(0, horizontalScrollBar()->value(), max); | - |
2234 | int position = segmentPositions.at(currentValue); | - |
2235 | int maximumValue = qBound(0, horizontalScrollBar()->maximum(), max); | - |
2236 | int maximum = segmentPositions.at(maximumValue); | - |
2237 | return (isRightToLeft() ? maximum - position : position); | - |
2238 | } | - |
2239 | } else if (flow() == QListView::LeftToRight && !flowPositions.isEmpty()) { | - |
2240 | int position = flowPositions.at(scrollValueMap.at(horizontalScrollBar()->value())); | - |
2241 | int maximum = flowPositions.at(scrollValueMap.at(horizontalScrollBar()->maximum())); | - |
2242 | return (isRightToLeft() ? maximum - position : position); | - |
2243 | } | - |
2244 | } | - |
2245 | return QCommonListViewBase::horizontalOffset(); | - |
2246 | } | - |
2247 | | - |
2248 | int QListModeViewBase::verticalOffset() const | - |
2249 | { | - |
2250 | if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) { | - |
2251 | if (isWrapping()) { | - |
2252 | if (flow() == QListView::LeftToRight && !segmentPositions.isEmpty()) { | - |
2253 | int value = verticalScrollBar()->value(); | - |
2254 | if (value >= segmentPositions.count()) | - |
2255 | return 0; | - |
2256 | return segmentPositions.at(value) - spacing(); | - |
2257 | } | - |
2258 | } else if (flow() == QListView::TopToBottom && !flowPositions.isEmpty()) { | - |
2259 | int value = verticalScrollBar()->value(); | - |
2260 | if (value > scrollValueMap.count()) | - |
2261 | return 0; | - |
2262 | return flowPositions.at(scrollValueMap.at(value)) - spacing(); | - |
2263 | } | - |
2264 | } | - |
2265 | return QCommonListViewBase::verticalOffset(); | - |
2266 | } | - |
2267 | | - |
2268 | int QListModeViewBase::horizontalScrollToValue(int index, QListView::ScrollHint hint, | - |
2269 | bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const | - |
2270 | { | - |
2271 | if (horizontalScrollMode() != QAbstractItemView::ScrollPerItem) | - |
2272 | return QCommonListViewBase::horizontalScrollToValue(index, hint, leftOf, rightOf, area, rect); | - |
2273 | | - |
2274 | int value; | - |
2275 | if (scrollValueMap.isEmpty()) | - |
2276 | value = 0; | - |
2277 | else | - |
2278 | value = qBound(0, scrollValueMap.at(horizontalScrollBar()->value()), flowPositions.count() - 1); | - |
2279 | if (leftOf) | - |
2280 | hint = QListView::PositionAtTop; | - |
2281 | else if (rightOf) | - |
2282 | hint = QListView::PositionAtBottom; | - |
2283 | if (hint == QListView::EnsureVisible) | - |
2284 | return value; | - |
2285 | | - |
2286 | return perItemScrollToValue(index, value, area.width(), hint, Qt::Horizontal, isWrapping(), rect.width()); | - |
2287 | } | - |
2288 | | - |
2289 | void QListModeViewBase::scrollContentsBy(int dx, int dy, bool scrollElasticBand) | - |
2290 | { | - |
2291 | | - |
2292 | const int verticalValue = verticalScrollBar()->value(); | - |
2293 | const int horizontalValue = horizontalScrollBar()->value(); | - |
2294 | const bool vertical = (verticalScrollMode() == QAbstractItemView::ScrollPerItem); | - |
2295 | const bool horizontal = (horizontalScrollMode() == QAbstractItemView::ScrollPerItem); | - |
2296 | | - |
2297 | if (isWrapping()) { | - |
2298 | if (segmentPositions.isEmpty()) | - |
2299 | return; | - |
2300 | const int max = segmentPositions.count() - 1; | - |
2301 | if (horizontal && flow() == QListView::TopToBottom && dx != 0) { | - |
2302 | int currentValue = qBound(0, horizontalValue, max); | - |
2303 | int previousValue = qBound(0, currentValue + dx, max); | - |
2304 | int currentCoordinate = segmentPositions.at(currentValue) - spacing(); | - |
2305 | int previousCoordinate = segmentPositions.at(previousValue) - spacing(); | - |
2306 | dx = previousCoordinate - currentCoordinate; | - |
2307 | } else if (vertical && flow() == QListView::LeftToRight && dy != 0) { | - |
2308 | int currentValue = qBound(0, verticalValue, max); | - |
2309 | int previousValue = qBound(0, currentValue + dy, max); | - |
2310 | int currentCoordinate = segmentPositions.at(currentValue) - spacing(); | - |
2311 | int previousCoordinate = segmentPositions.at(previousValue) - spacing(); | - |
2312 | dy = previousCoordinate - currentCoordinate; | - |
2313 | } | - |
2314 | } else { | - |
2315 | if (flowPositions.isEmpty()) | - |
2316 | return; | - |
2317 | const int max = scrollValueMap.count() - 1; | - |
2318 | if (vertical && flow() == QListView::TopToBottom && dy != 0) { | - |
2319 | int currentValue = qBound(0, verticalValue, max); | - |
2320 | int previousValue = qBound(0, currentValue + dy, max); | - |
2321 | int currentCoordinate = flowPositions.at(scrollValueMap.at(currentValue)); | - |
2322 | int previousCoordinate = flowPositions.at(scrollValueMap.at(previousValue)); | - |
2323 | dy = previousCoordinate - currentCoordinate; | - |
2324 | } else if (horizontal && flow() == QListView::LeftToRight && dx != 0) { | - |
2325 | int currentValue = qBound(0, horizontalValue, max); | - |
2326 | int previousValue = qBound(0, currentValue + dx, max); | - |
2327 | int currentCoordinate = flowPositions.at(scrollValueMap.at(currentValue)); | - |
2328 | int previousCoordinate = flowPositions.at(scrollValueMap.at(previousValue)); | - |
2329 | dx = previousCoordinate - currentCoordinate; | - |
2330 | } | - |
2331 | } | - |
2332 | QCommonListViewBase::scrollContentsBy(dx, dy, scrollElasticBand); | - |
2333 | } | - |
2334 | | - |
2335 | bool QListModeViewBase::doBatchedItemLayout(const QListViewLayoutInfo &info, int max) | - |
2336 | { | - |
2337 | doStaticLayout(info); | - |
2338 | if (batchStartRow > max) { | - |
2339 | flowPositions.resize(flowPositions.count()); | - |
2340 | segmentPositions.resize(segmentPositions.count()); | - |
2341 | segmentStartRows.resize(segmentStartRows.count()); | - |
2342 | return true; | - |
2343 | } | - |
2344 | return false; | - |
2345 | } | - |
2346 | | - |
2347 | QListViewItem QListModeViewBase::indexToListViewItem(const QModelIndex &index) const | - |
2348 | { | - |
2349 | if (flowPositions.isEmpty() | - |
2350 | || segmentPositions.isEmpty() | - |
2351 | || index.row() >= flowPositions.count()) | - |
2352 | return QListViewItem(); | - |
2353 | | - |
2354 | const int segment = qBinarySearch<int>(segmentStartRows, index.row(), | - |
2355 | 0, segmentStartRows.count() - 1); | - |
2356 | | - |
2357 | | - |
2358 | QStyleOptionViewItem options = viewOptions(); | - |
2359 | options.rect.setSize(contentsSize); | - |
2360 | QSize size = (uniformItemSizes() && cachedItemSize().isValid()) | - |
2361 | ? cachedItemSize() : itemSize(options, index); | - |
2362 | | - |
2363 | QPoint pos; | - |
2364 | if (flow() == QListView::LeftToRight) { | - |
2365 | pos.setX(flowPositions.at(index.row())); | - |
2366 | pos.setY(segmentPositions.at(segment)); | - |
2367 | } else { | - |
2368 | pos.setY(flowPositions.at(index.row())); | - |
2369 | pos.setX(segmentPositions.at(segment)); | - |
2370 | if (isWrapping()) { | - |
2371 | int right = (segment + 1 >= segmentPositions.count() | - |
2372 | ? contentsSize.width() | - |
2373 | : segmentPositions.at(segment + 1)); | - |
2374 | size.setWidth(right - pos.x()); | - |
2375 | } else { | - |
2376 | size.setWidth(qMax(size.width(), viewport()->width() - 2 * spacing())); | - |
2377 | } | - |
2378 | } | - |
2379 | | - |
2380 | return QListViewItem(QRect(pos, size), index.row()); | - |
2381 | } | - |
2382 | | - |
2383 | QPoint QListModeViewBase::initStaticLayout(const QListViewLayoutInfo &info) | - |
2384 | { | - |
2385 | int x, y; | - |
2386 | if (info.first == 0) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2387 | flowPositions.clear(); | - |
2388 | segmentPositions.clear(); | - |
2389 | segmentStartRows.clear(); | - |
2390 | segmentExtents.clear(); | - |
2391 | scrollValueMap.clear(); | - |
2392 | x = info.bounds.left() + info.spacing; | - |
2393 | y = info.bounds.top() + info.spacing; | - |
2394 | segmentPositions.append(info.flow == QListView::LeftToRight ? y : x); | - |
2395 | segmentStartRows.append(0); | - |
2396 | } else if (info.wrap) { never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2397 | if (info.flow == QListView::LeftToRight) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2398 | x = batchSavedPosition; | - |
2399 | y = segmentPositions.lastconstLast(); | - |
2400 | } else { never executed: end of block | 0 |
2401 | x = segmentPositions.lastconstLast(); | - |
2402 | y = batchSavedPosition; | - |
2403 | } never executed: end of block | 0 |
2404 | } else { | - |
2405 | if (info.flow == QListView::LeftToRight) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2406 | x = batchSavedPosition; | - |
2407 | y = info.bounds.top() + info.spacing; | - |
2408 | } else { never executed: end of block | 0 |
2409 | x = info.bounds.left() + info.spacing; | - |
2410 | y = batchSavedPosition; | - |
2411 | } never executed: end of block | 0 |
2412 | } | - |
2413 | return QPoint(x, y); never executed: return QPoint(x, y); | 0 |
2414 | } | - |
2415 | | - |
2416 | | - |
2417 | | - |
2418 | | - |
2419 | void QListModeViewBase::doStaticLayout(const QListViewLayoutInfo &info) | - |
2420 | { | - |
2421 | const bool useItemSize = !info.grid.isValid(); | - |
2422 | const QPoint topLeft = initStaticLayout(info); | - |
2423 | QStyleOptionViewItem option = viewOptions(); | - |
2424 | option.rect = info.bounds; | - |
2425 | option.rect.adjust(info.spacing, info.spacing, -info.spacing, -info.spacing); | - |
2426 | | - |
2427 | | - |
2428 | | - |
2429 | | - |
2430 | | - |
2431 | | - |
2432 | | - |
2433 | int segStartPosition; | - |
2434 | int segEndPosition; | - |
2435 | int deltaFlowPosition; | - |
2436 | int deltaSegPosition; | - |
2437 | int deltaSegHint; | - |
2438 | int flowPosition; | - |
2439 | int segPosition; | - |
2440 | | - |
2441 | if (info.flow == QListView::LeftToRight) { | - |
2442 | segStartPosition = info.bounds.left(); | - |
2443 | segEndPosition = info.bounds.width(); | - |
2444 | flowPosition = topLeft.x(); | - |
2445 | segPosition = topLeft.y(); | - |
2446 | deltaFlowPosition = info.grid.width(); | - |
2447 | deltaSegPosition = useItemSize ? batchSavedDeltaSeg : info.grid.height(); | - |
2448 | deltaSegHint = info.grid.height(); | - |
2449 | } else { | - |
2450 | segStartPosition = info.bounds.top(); | - |
2451 | segEndPosition = info.bounds.height(); | - |
2452 | flowPosition = topLeft.y(); | - |
2453 | segPosition = topLeft.x(); | - |
2454 | deltaFlowPosition = info.grid.height(); | - |
2455 | deltaSegPosition = useItemSize ? batchSavedDeltaSeg : info.grid.width(); | - |
2456 | deltaSegHint = info.grid.width(); | - |
2457 | } | - |
2458 | | - |
2459 | for (int row = info.first; row <= info.last; ++row) { | - |
2460 | if (isHidden(row)) { | - |
2461 | flowPositions.append(flowPosition); | - |
2462 | } else { | - |
2463 | | - |
2464 | if (useItemSize) { | - |
2465 | QSize hint = itemSize(option, modelIndex(row)); | - |
2466 | if (info.flow == QListView::LeftToRight) { | - |
2467 | deltaFlowPosition = hint.width() + info.spacing; | - |
2468 | deltaSegHint = hint.height() + info.spacing; | - |
2469 | } else { | - |
2470 | deltaFlowPosition = hint.height() + info.spacing; | - |
2471 | deltaSegHint = hint.width() + info.spacing; | - |
2472 | } | - |
2473 | } | - |
2474 | | - |
2475 | if (info.wrap && (flowPosition + deltaFlowPosition >= segEndPosition)) { | - |
2476 | segmentExtents.append(flowPosition); | - |
2477 | flowPosition = info.spacing + segStartPosition; | - |
2478 | segPosition += deltaSegPosition; | - |
2479 | if (info.wrap) | - |
2480 | segPosition += info.spacing; | - |
2481 | segmentPositions.append(segPosition); | - |
2482 | segmentStartRows.append(row); | - |
2483 | deltaSegPosition = 0; | - |
2484 | } | - |
2485 | | - |
2486 | scrollValueMap.append(flowPositions.count()); | - |
2487 | flowPositions.append(flowPosition); | - |
2488 | | - |
2489 | deltaSegPosition = qMax(deltaSegHint, deltaSegPosition); | - |
2490 | flowPosition += info.spacing + deltaFlowPosition; | - |
2491 | } | - |
2492 | } | - |
2493 | | - |
2494 | batchSavedPosition = flowPosition; | - |
2495 | batchSavedDeltaSeg = deltaSegPosition; | - |
2496 | batchStartRow = info.last + 1; | - |
2497 | if (info.last == info.max) | - |
2498 | flowPosition -= info.spacing; | - |
2499 | | - |
2500 | QRect rect = info.bounds; | - |
2501 | if (info.flow == QListView::LeftToRight) { | - |
2502 | rect.setRight(segmentPositions.count() == 1 ? flowPosition : info.bounds.right()); | - |
2503 | rect.setBottom(segPosition + deltaSegPosition); | - |
2504 | } else { | - |
2505 | rect.setRight(segPosition + deltaSegPosition); | - |
2506 | rect.setBottom(segmentPositions.count() == 1 ? flowPosition : info.bounds.bottom()); | - |
2507 | } | - |
2508 | contentsSize = QSize(rect.right(), rect.bottom()); | - |
2509 | | - |
2510 | if (info.last == info.max) { | - |
2511 | segmentExtents.append(flowPosition); | - |
2512 | scrollValueMap.append(flowPositions.count()); | - |
2513 | flowPositions.append(flowPosition); | - |
2514 | segmentPositions.append(info.wrap ? segPosition + deltaSegPosition : INT_MAX); | - |
2515 | } | - |
2516 | | - |
2517 | QRect changedRect(topLeft, rect.bottomRight()); | - |
2518 | if (clipRect().intersects(changedRect)) | - |
2519 | viewport()->update(); | - |
2520 | } | - |
2521 | | - |
2522 | | - |
2523 | | - |
2524 | | - |
2525 | | - |
2526 | | - |
2527 | QVector<QModelIndex> QListModeViewBase::intersectingSet(const QRect &area) const | - |
2528 | { | - |
2529 | QVector<QModelIndex> ret; | - |
2530 | int segStartPosition; | - |
2531 | int segEndPosition; | - |
2532 | int flowStartPosition; | - |
2533 | int flowEndPosition; | - |
2534 | if (flow() == QListView::LeftToRight) { | - |
2535 | segStartPosition = area.top(); | - |
2536 | segEndPosition = area.bottom(); | - |
2537 | flowStartPosition = area.left(); | - |
2538 | flowEndPosition = area.right(); | - |
2539 | } else { | - |
2540 | segStartPosition = area.left(); | - |
2541 | segEndPosition = area.right(); | - |
2542 | flowStartPosition = area.top(); | - |
2543 | flowEndPosition = area.bottom(); | - |
2544 | } | - |
2545 | if (segmentPositions.count() < 2 || flowPositions.isEmpty()) | - |
2546 | return ret; | - |
2547 | | - |
2548 | const int segLast = segmentPositions.count() - 2; | - |
2549 | int seg = qBinarySearch<int>(segmentPositions, segStartPosition, 0, segLast + 1); | - |
2550 | for (; seg <= segLast && segmentPositions.at(seg) <= segEndPosition; ++seg) { | - |
2551 | int first = segmentStartRows.at(seg); | - |
2552 | int last = (seg < segLast ? segmentStartRows.at(seg + 1) : batchStartRow) - 1; | - |
2553 | if (segmentExtents.at(seg) < flowStartPosition) | - |
2554 | continue; | - |
2555 | int row = qBinarySearch<int>(flowPositions, flowStartPosition, first, last); | - |
2556 | for (; row <= last && flowPositions.at(row) <= flowEndPosition; ++row) { | - |
2557 | if (isHidden(row)) | - |
2558 | continue; | - |
2559 | QModelIndex index = modelIndex(row); | - |
2560 | if (index.isValid()) | - |
2561 | ret += index; | - |
2562 | #if 0 // for debugging | - |
2563 | else | - |
2564 | qWarning("intersectingSet: row %d was invalid", row); | - |
2565 | #endif | - |
2566 | } | - |
2567 | } | - |
2568 | return ret; | - |
2569 | } | - |
2570 | | - |
2571 | void QListModeViewBase::dataChanged(const QModelIndex &, const QModelIndex &) | - |
2572 | { | - |
2573 | dd->doDelayedItemsLayout(); | - |
2574 | } | - |
2575 | | - |
2576 | | - |
2577 | QRect QListModeViewBase::mapToViewport(const QRect &rect) const | - |
2578 | { | - |
2579 | if (isWrapping()) | - |
2580 | return rect; | - |
2581 | | - |
2582 | | - |
2583 | QRect result = rect; | - |
2584 | if (flow() == QListView::TopToBottom) { | - |
2585 | result.setLeft(spacing()); | - |
2586 | result.setWidth(qMax(rect.width(), qMax(contentsSize.width(), viewport()->width()) - 2 * spacing())); | - |
2587 | } else { | - |
2588 | result.setTop(spacing()); | - |
2589 | result.setHeight(qMax(rect.height(), qMax(contentsSize.height(), viewport()->height()) - 2 * spacing())); | - |
2590 | } | - |
2591 | return result; | - |
2592 | } | - |
2593 | | - |
2594 | int QListModeViewBase::perItemScrollingPageSteps(int length, int bounds, bool wrap) const | - |
2595 | { | - |
2596 | QVector<int> positions; | - |
2597 | if (wrap)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2598 | positions = segmentPositions; never executed: positions = segmentPositions; | 0 |
2599 | else if (!flowPositions.isEmpty()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2600 | positions.reserve(scrollValueMap.size()); | - |
2601 | foreach (int itemShown, scrollValueMap) | - |
2602 | positions.append(flowPositions.at(itemShown)); never executed: positions.append(flowPositions.at(itemShown)); | 0 |
2603 | } never executed: end of block | 0 |
2604 | if (positions.isEmpty() || bounds <= length)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2605 | return positions.count(); never executed: return positions.count(); | 0 |
2606 | if (uniformItemSizes()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2607 | for (int i = 1; i < positions.count(); ++i)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2608 | if (positions.at(i) > 0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2609 | return length / positions.at(i); never executed: return length / positions.at(i); | 0 |
2610 | return 0; never executed: return 0; | 0 |
2611 | } | - |
2612 | int pageSteps = 0; | - |
2613 | int steps = positions.count() - 1; | - |
2614 | int max = qMax(length, bounds); | - |
2615 | int min = qMin(length, bounds); | - |
2616 | int pos = min - (max - positions.lastconstLast()); | - |
2617 | | - |
2618 | while (pos >= 0 && steps > 0) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2619 | pos -= (positions.at(steps) - positions.at(steps - 1)); | - |
2620 | if (pos >= 0) TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2621 | ++pageSteps; never executed: ++pageSteps; | 0 |
2622 | --steps; | - |
2623 | } never executed: end of block | 0 |
2624 | | - |
2625 | | - |
2626 | return qMax(pageSteps, 1); never executed: return qMax(pageSteps, 1); | 0 |
2627 | } | - |
2628 | | - |
2629 | int QListModeViewBase::perItemScrollToValue(int index, int scrollValue, int viewportSize, | - |
2630 | QAbstractItemView::ScrollHint hint, | - |
2631 | Qt::Orientation orientation, bool wrap, int itemExtent) const | - |
2632 | { | - |
2633 | if (index < 0) | - |
2634 | return scrollValue; | - |
2635 | | - |
2636 | itemExtent += spacing(); | - |
2637 | QVector<int> visibleFlowPositions; | - |
2638 | visibleFlowPositions.reserve(flowPositions.count() - 1); | - |
2639 | for (int i = 0; i < flowPositions.count() - 1; i++) { | - |
2640 | if (!isHidden(i)) | - |
2641 | visibleFlowPositions.append(flowPositions.at(i)); | - |
2642 | } | - |
2643 | | - |
2644 | if (!wrap) { | - |
2645 | int topIndex = index; | - |
2646 | const int bottomIndex = topIndex; | - |
2647 | const int bottomCoordinate = visibleFlowPositions.at(index); | - |
2648 | | - |
2649 | while (topIndex > 0 && | - |
2650 | (bottomCoordinate - visibleFlowPositions.at(topIndex - 1) + itemExtent) <= (viewportSize)) { | - |
2651 | topIndex--; | - |
2652 | } | - |
2653 | | - |
2654 | const int itemCount = bottomIndex - topIndex + 1; | - |
2655 | switch (hint) { | - |
2656 | case QAbstractItemView::PositionAtTop: | - |
2657 | return index; | - |
2658 | case QAbstractItemView::PositionAtBottom: | - |
2659 | return index - itemCount + 1; | - |
2660 | case QAbstractItemView::PositionAtCenter: | - |
2661 | return index - (itemCount / 2); | - |
2662 | default: | - |
2663 | break; | - |
2664 | } | - |
2665 | } else { | - |
2666 | Qt::Orientation flowOrientation = (flow() == QListView::LeftToRight | - |
2667 | ? Qt::Horizontal : Qt::Vertical); | - |
2668 | if (flowOrientation == orientation) { | - |
2669 | | - |
2670 | return visibleFlowPositions.at(index); | - |
2671 | } else if (!segmentStartRows.isEmpty()) { | - |
2672 | int segment = qBinarySearch<int>(segmentStartRows, index, 0, segmentStartRows.count() - 1); | - |
2673 | int leftSegment = segment; | - |
2674 | const int rightSegment = leftSegment; | - |
2675 | const int bottomCoordinate = segmentPositions.at(segment); | - |
2676 | | - |
2677 | while (leftSegment > scrollValue && | - |
2678 | (bottomCoordinate - segmentPositions.at(leftSegment-1) + itemExtent) <= (viewportSize)) { | - |
2679 | leftSegment--; | - |
2680 | } | - |
2681 | | - |
2682 | const int segmentCount = rightSegment - leftSegment + 1; | - |
2683 | switch (hint) { | - |
2684 | case QAbstractItemView::PositionAtTop: | - |
2685 | return segment; | - |
2686 | case QAbstractItemView::PositionAtBottom: | - |
2687 | return segment - segmentCount + 1; | - |
2688 | case QAbstractItemView::PositionAtCenter: | - |
2689 | return segment - (segmentCount / 2); | - |
2690 | default: | - |
2691 | break; | - |
2692 | } | - |
2693 | } | - |
2694 | } | - |
2695 | return scrollValue; | - |
2696 | } | - |
2697 | | - |
2698 | void QListModeViewBase::clear() | - |
2699 | { | - |
2700 | flowPositions.clear(); | - |
2701 | segmentPositions.clear(); | - |
2702 | segmentStartRows.clear(); | - |
2703 | segmentExtents.clear(); | - |
2704 | batchSavedPosition = 0; | - |
2705 | batchStartRow = 0; | - |
2706 | batchSavedDeltaSeg = 0; | - |
2707 | } | - |
2708 | | - |
2709 | | - |
2710 | | - |
2711 | | - |
2712 | | - |
2713 | void QIconModeViewBase::setPositionForIndex(const QPoint &position, const QModelIndex &index) | - |
2714 | { | - |
2715 | if (index.row() >= items.count()) | - |
2716 | return; | - |
2717 | const QSize oldContents = contentsSize; | - |
2718 | qq->update(index); | - |
2719 | moveItem(index.row(), position); | - |
2720 | qq->update(index); | - |
2721 | | - |
2722 | if (contentsSize != oldContents) | - |
2723 | dd->viewUpdateGeometries(); | - |
2724 | } | - |
2725 | | - |
2726 | void QIconModeViewBase::appendHiddenRow(int row) | - |
2727 | { | - |
2728 | if (row >= 0 && row < items.count()) | - |
2729 | tree.removeLeaf(items.at(row).rect(), row); | - |
2730 | QCommonListViewBase::appendHiddenRow(row); | - |
2731 | } | - |
2732 | | - |
2733 | void QIconModeViewBase::removeHiddenRow(int row) | - |
2734 | { | - |
2735 | QCommonListViewBase::removeHiddenRow(row); | - |
2736 | if (row >= 0 && row < items.count()) | - |
2737 | tree.insertLeaf(items.at(row).rect(), row); | - |
2738 | } | - |
2739 | | - |
2740 | #ifndef QT_NO_DRAGANDDROP | - |
2741 | bool QIconModeViewBase::filterStartDrag(Qt::DropActions supportedActions) | - |
2742 | { | - |
2743 | | - |
2744 | | - |
2745 | | - |
2746 | QModelIndexList indexes = dd->selectionModel->selectedIndexes(); | - |
2747 | if (indexes.count() > 0 ) { | - |
2748 | if (viewport()->acceptDrops()) { | - |
2749 | QModelIndexList::ConstIterator it = indexes.constBegin(); | - |
2750 | for (; it != indexes.constEnd(); ++it) | - |
2751 | if (dd->model->flags(*it) & Qt::ItemIsDragEnabled | - |
2752 | && (*it).column() == dd->column) | - |
2753 | draggedItems.push_back(*it); | - |
2754 | } | - |
2755 | | - |
2756 | QRect rect; | - |
2757 | QPixmap pixmap = dd->renderToPixmap(indexes, &rect); | - |
2758 | rect.adjust(horizontalOffset(), verticalOffset(), 0, 0); | - |
2759 | QDrag *drag = new QDrag(qq); | - |
2760 | drag->setMimeData(dd->model->mimeData(indexes)); | - |
2761 | drag->setPixmap(pixmap); | - |
2762 | drag->setHotSpot(dd->pressedPosition - rect.topLeft()); | - |
2763 | Qt::DropAction action = drag->exec(supportedActions, dd->defaultDropAction); | - |
2764 | draggedItems.clear(); | - |
2765 | if (action == Qt::MoveAction) | - |
2766 | dd->clearOrRemove(); | - |
2767 | } | - |
2768 | return true; | - |
2769 | } | - |
2770 | | - |
2771 | bool QIconModeViewBase::filterDropEvent(QDropEvent *e) | - |
2772 | { | - |
2773 | if (e->source() != qq)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2774 | return false; never executed: return false; | 0 |
2775 | | - |
2776 | const QSize contents = contentsSize; | - |
2777 | QPoint offset(horizontalOffset(), verticalOffset()); | - |
2778 | QPoint end = e->pos() + offset; | - |
2779 | if (qq->acceptDrops()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2780 | const Qt::ItemFlags dropableFlags = Qt::ItemIsDropEnabled|Qt::ItemIsEnabled; | - |
2781 | const QVector<QModelIndex> &dropIndices = intersectingSet(QRect(end, QSize(1, 1))); | - |
2782 | foreach (const QModelIndex &index, dropIndices) | - |
2783 | if ((index.flags() & dropableFlags) == dropableFlags)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2784 | return false; never executed: return false; | 0 |
2785 | } never executed: end of block | 0 |
2786 | QPoint start = dd->pressedPosition; | - |
2787 | QPoint delta = (dd->movement == QListView::Snap ? snapToGrid(end) - snapToGrid(start) : end - start);TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2788 | const QList<QModelIndex> indexes = dd->selectionModel->selectedIndexes(); | - |
2789 | for (int i = 0; i <const auto &index : indexes.count(); ++i) {QModelIndex index = indexes.at(i); | - |
2790 | QRect rect = dd->rectForIndex(index); | - |
2791 | viewport()->update(dd->mapToViewport(rect, false)); | - |
2792 | QPoint dest = rect.topLeft() + delta; | - |
2793 | if (qq->isRightToLeft())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2794 | dest.setX(dd->flipX(dest.x()) - rect.width()); never executed: dest.setX(dd->flipX(dest.x()) - rect.width()); | 0 |
2795 | moveItem(index.row(), dest); | - |
2796 | qq->update(index); | - |
2797 | } never executed: end of block | 0 |
2798 | dd->stopAutoScroll(); | - |
2799 | draggedItems.clear(); | - |
2800 | dd->emitIndexesMoved(indexes); | - |
2801 | e->accept(); | - |
2802 | | - |
2803 | if (contentsSize != contents) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2804 | if ((contentsSize.width() <= contents.width()TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2805 | || contentsSize.height() <= contents.height())) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2806 | updateContentsSize(); | - |
2807 | } never executed: end of block | 0 |
2808 | dd->viewUpdateGeometries(); | - |
2809 | } never executed: end of block | 0 |
2810 | return true; never executed: return true; | 0 |
2811 | } | - |
2812 | | - |
2813 | bool QIconModeViewBase::filterDragLeaveEvent(QDragLeaveEvent *e) | - |
2814 | { | - |
2815 | viewport()->update(draggedItemsRect()); | - |
2816 | draggedItemsPos = QPoint(-1, -1); | - |
2817 | return QCommonListViewBase::filterDragLeaveEvent(e); | - |
2818 | } | - |
2819 | | - |
2820 | bool QIconModeViewBase::filterDragMoveEvent(QDragMoveEvent *e) | - |
2821 | { | - |
2822 | if (e->source() != qq || !dd->canDrop(e)) | - |
2823 | return false; | - |
2824 | | - |
2825 | | - |
2826 | e->ignore(); | - |
2827 | | - |
2828 | QRect itemsRect = this->itemsRect(draggedItems); | - |
2829 | viewport()->update(itemsRect.translated(draggedItemsDelta())); | - |
2830 | | - |
2831 | draggedItemsPos = e->pos(); | - |
2832 | | - |
2833 | viewport()->update(itemsRect.translated(draggedItemsDelta())); | - |
2834 | | - |
2835 | QModelIndex index; | - |
2836 | if (movement() == QListView::Snap) { | - |
2837 | QRect rect(snapToGrid(e->pos() + offset()), gridSize()); | - |
2838 | const QVector<QModelIndex> intersectVector = intersectingSet(rect); | - |
2839 | index = intersectVector.count() > 0 ? intersectVector.last() : QModelIndex(); | - |
2840 | } else { | - |
2841 | index = qq->indexAt(e->pos()); | - |
2842 | } | - |
2843 | | - |
2844 | if (draggedItems.contains(index)) | - |
2845 | e->accept(); | - |
2846 | else if (dd->model->flags(index) & Qt::ItemIsDropEnabled) | - |
2847 | e->accept(); | - |
2848 | else if (!index.isValid()) | - |
2849 | e->accept(); | - |
2850 | | - |
2851 | | - |
2852 | if (dd->shouldAutoScroll(e->pos())) | - |
2853 | dd->startAutoScroll(); | - |
2854 | return true; | - |
2855 | } | - |
2856 | #endif // QT_NO_DRAGANDDROP | - |
2857 | | - |
2858 | void QIconModeViewBase::setRowCount(int rowCount) | - |
2859 | { | - |
2860 | tree.create(qMax(rowCount - hiddenCount(), 0)); | - |
2861 | } | - |
2862 | | - |
2863 | void QIconModeViewBase::scrollContentsBy(int dx, int dy, bool scrollElasticBand) | - |
2864 | { | - |
2865 | if (scrollElasticBand) | - |
2866 | dd->scrollElasticBandBy(isRightToLeft() ? -dx : dx, dy); | - |
2867 | | - |
2868 | QCommonListViewBase::scrollContentsBy(dx, dy, scrollElasticBand); | - |
2869 | if (!draggedItems.isEmpty()) | - |
2870 | viewport()->update(draggedItemsRect().translated(dx, dy)); | - |
2871 | } | - |
2872 | | - |
2873 | void QIconModeViewBase::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) | - |
2874 | { | - |
2875 | if (column() >= topLeft.column() && column() <= bottomRight.column()) { | - |
2876 | QStyleOptionViewItem option = viewOptions(); | - |
2877 | int bottom = qMin(items.count(), bottomRight.row() + 1); | - |
2878 | for (int row = topLeft.row(); row < bottom; ++row) | - |
2879 | items[row].resize(itemSize(option, modelIndex(row))); | - |
2880 | } | - |
2881 | } | - |
2882 | | - |
2883 | bool QIconModeViewBase::doBatchedItemLayout(const QListViewLayoutInfo &info, int max) | - |
2884 | { | - |
2885 | if (info.last >= items.count()) { | - |
2886 | | - |
2887 | QStyleOptionViewItem option = viewOptions(); | - |
2888 | for (int row = items.count(); row <= info.last; ++row) { | - |
2889 | QSize size = itemSize(option, modelIndex(row)); | - |
2890 | QListViewItem item(QRect(0, 0, size.width(), size.height()), row); | - |
2891 | items.append(item); | - |
2892 | } | - |
2893 | doDynamicLayout(info); | - |
2894 | } | - |
2895 | return (batchStartRow > max); | - |
2896 | } | - |
2897 | | - |
2898 | QListViewItem QIconModeViewBase::indexToListViewItem(const QModelIndex &index) const | - |
2899 | { | - |
2900 | if (index.isValid() && index.row() < items.count()) | - |
2901 | return items.at(index.row()); | - |
2902 | return QListViewItem(); | - |
2903 | } | - |
2904 | | - |
2905 | void QIconModeViewBase::initBspTree(const QSize &contents) | - |
2906 | { | - |
2907 | | - |
2908 | int leafCount = tree.leafCount(); | - |
2909 | for (int l = 0; l < leafCount; ++l) | - |
2910 | tree.leaf(l).clear(); | - |
2911 | | - |
2912 | QBspTree::Node::Type type = QBspTree::Node::Both; | - |
2913 | | - |
2914 | if (contents.height() / contents.width() >= 3) | - |
2915 | type = QBspTree::Node::HorizontalPlane; | - |
2916 | else if (contents.width() / contents.height() >= 3) | - |
2917 | type = QBspTree::Node::VerticalPlane; | - |
2918 | | - |
2919 | tree.init(QRect(0, 0, contents.width(), contents.height()), type); | - |
2920 | } | - |
2921 | | - |
2922 | QPoint QIconModeViewBase::initDynamicLayout(const QListViewLayoutInfo &info) | - |
2923 | { | - |
2924 | int x, y; | - |
2925 | if (info.first == 0) { | - |
2926 | x = info.bounds.x() + info.spacing; | - |
2927 | y = info.bounds.y() + info.spacing; | - |
2928 | items.reserve(rowCount() - hiddenCount()); | - |
2929 | } else { | - |
2930 | int idx = info.first - 1; | - |
2931 | while (idx > 0 && !items.at(idx).isValid()) | - |
2932 | --idx; | - |
2933 | const QListViewItem &item = items.at(idx); | - |
2934 | x = item.x; | - |
2935 | y = item.y; | - |
2936 | if (info.flow == QListView::LeftToRight) | - |
2937 | x += (info.grid.isValid() ? info.grid.width() : item.w) + info.spacing; | - |
2938 | else | - |
2939 | y += (info.grid.isValid() ? info.grid.height() : item.h) + info.spacing; | - |
2940 | } | - |
2941 | return QPoint(x, y); | - |
2942 | } | - |
2943 | | - |
2944 | | - |
2945 | | - |
2946 | | - |
2947 | void QIconModeViewBase::doDynamicLayout(const QListViewLayoutInfo &info) | - |
2948 | { | - |
2949 | const bool useItemSize = !info.grid.isValid(); | - |
2950 | const QPoint topLeft = initDynamicLayout(info); | - |
2951 | | - |
2952 | int segStartPosition; | - |
2953 | int segEndPosition; | - |
2954 | int deltaFlowPosition; | - |
2955 | int deltaSegPosition; | - |
2956 | int deltaSegHint; | - |
2957 | int flowPosition; | - |
2958 | int segPosition; | - |
2959 | | - |
2960 | if (info.flow == QListView::LeftToRight) { | - |
2961 | segStartPosition = info.bounds.left() + info.spacing; | - |
2962 | segEndPosition = info.bounds.right(); | - |
2963 | deltaFlowPosition = info.grid.width(); | - |
2964 | deltaSegPosition = (useItemSize ? batchSavedDeltaSeg : info.grid.height()); | - |
2965 | deltaSegHint = info.grid.height(); | - |
2966 | flowPosition = topLeft.x(); | - |
2967 | segPosition = topLeft.y(); | - |
2968 | } else { | - |
2969 | segStartPosition = info.bounds.top() + info.spacing; | - |
2970 | segEndPosition = info.bounds.bottom(); | - |
2971 | deltaFlowPosition = info.grid.height(); | - |
2972 | deltaSegPosition = (useItemSize ? batchSavedDeltaSeg : info.grid.width()); | - |
2973 | deltaSegHint = info.grid.width(); | - |
2974 | flowPosition = topLeft.y(); | - |
2975 | segPosition = topLeft.x(); | - |
2976 | } | - |
2977 | | - |
2978 | if (moved.count() != items.count()) | - |
2979 | moved.resize(items.count()); | - |
2980 | | - |
2981 | QRect rect(QPoint(), topLeft); | - |
2982 | QListViewItem *item = 0; | - |
2983 | for (int row = info.first; row <= info.last; ++row) { | - |
2984 | item = &items[row]; | - |
2985 | if (isHidden(row)) { | - |
2986 | item->invalidate(); | - |
2987 | } else { | - |
2988 | | - |
2989 | if (useItemSize) { | - |
2990 | if (info.flow == QListView::LeftToRight) | - |
2991 | deltaFlowPosition = item->w + info.spacing; | - |
2992 | else | - |
2993 | deltaFlowPosition = item->h + info.spacing; | - |
2994 | } else { | - |
2995 | item->w = qMin<int>(info.grid.width(), item->w); | - |
2996 | item->h = qMin<int>(info.grid.height(), item->h); | - |
2997 | } | - |
2998 | | - |
2999 | | - |
3000 | if (info.wrap | - |
3001 | && flowPosition + deltaFlowPosition > segEndPosition | - |
3002 | && flowPosition > segStartPosition) { | - |
3003 | flowPosition = segStartPosition; | - |
3004 | segPosition += deltaSegPosition; | - |
3005 | if (useItemSize) | - |
3006 | deltaSegPosition = 0; | - |
3007 | } | - |
3008 | | - |
3009 | | - |
3010 | if (useItemSize) { | - |
3011 | if (info.flow == QListView::LeftToRight) | - |
3012 | deltaSegHint = item->h + info.spacing; | - |
3013 | else | - |
3014 | deltaSegHint = item->w + info.spacing; | - |
3015 | deltaSegPosition = qMax(deltaSegPosition, deltaSegHint); | - |
3016 | } | - |
3017 | | - |
3018 | | - |
3019 | | - |
3020 | | - |
3021 | if (!moved.testBit(row)) { | - |
3022 | if (info.flow == QListView::LeftToRight) { | - |
3023 | if (useItemSize) { | - |
3024 | item->x = flowPosition; | - |
3025 | item->y = segPosition; | - |
3026 | } else { | - |
3027 | item->x = flowPosition + ((deltaFlowPosition - item->w) / 2); | - |
3028 | item->y = segPosition; | - |
3029 | } | - |
3030 | } else { | - |
3031 | if (useItemSize) { | - |
3032 | item->y = flowPosition; | - |
3033 | item->x = segPosition; | - |
3034 | } else { | - |
3035 | item->y = flowPosition + ((deltaFlowPosition - item->h) / 2); | - |
3036 | item->x = segPosition; | - |
3037 | } | - |
3038 | } | - |
3039 | } | - |
3040 | | - |
3041 | | - |
3042 | if (useItemSize) | - |
3043 | rect |= item->rect(); | - |
3044 | else if (info.flow == QListView::LeftToRight) | - |
3045 | rect |= QRect(flowPosition, segPosition, deltaFlowPosition, deltaSegPosition); | - |
3046 | else | - |
3047 | rect |= QRect(segPosition, flowPosition, deltaSegPosition, deltaFlowPosition); | - |
3048 | | - |
3049 | | - |
3050 | flowPosition += deltaFlowPosition; | - |
3051 | } | - |
3052 | } | - |
3053 | batchSavedDeltaSeg = deltaSegPosition; | - |
3054 | batchStartRow = info.last + 1; | - |
3055 | bool done = (info.last >= rowCount() - 1); | - |
3056 | | - |
3057 | if (done || !info.bounds.contains(item->rect())) { | - |
3058 | contentsSize = rect.size(); | - |
3059 | if (info.flow == QListView::LeftToRight) | - |
3060 | contentsSize.rheight() += info.spacing; | - |
3061 | else | - |
3062 | contentsSize.rwidth() += info.spacing; | - |
3063 | } | - |
3064 | if (rect.size().isEmpty()) | - |
3065 | return; | - |
3066 | | - |
3067 | int insertFrom = info.first; | - |
3068 | if (done || info.first == 0) { | - |
3069 | initBspTree(rect.size()); | - |
3070 | insertFrom = 0; | - |
3071 | } | - |
3072 | | - |
3073 | for (int row = insertFrom; row <= info.last; ++row) | - |
3074 | tree.insertLeaf(items.at(row).rect(), row); | - |
3075 | | - |
3076 | QRect changedRect(topLeft, rect.bottomRight()); | - |
3077 | if (clipRect().intersects(changedRect)) | - |
3078 | viewport()->update(); | - |
3079 | } | - |
3080 | | - |
3081 | QVector<QModelIndex> QIconModeViewBase::intersectingSet(const QRect &area) const | - |
3082 | { | - |
3083 | QIconModeViewBase *that = const_cast<QIconModeViewBase*>(this); | - |
3084 | QBspTree::Data data(static_cast<void*>(that)); | - |
3085 | QVector<QModelIndex> res; | - |
3086 | that->interSectingVector = &res; | - |
3087 | that->tree.climbTree(area, &QIconModeViewBase::addLeaf, data); | - |
3088 | that->interSectingVector = 0; | - |
3089 | return res; | - |
3090 | } | - |
3091 | | - |
3092 | QRect QIconModeViewBase::itemsRect(const QVector<QModelIndex> &indexes) const | - |
3093 | { | - |
3094 | QVector<QModelIndex>::const_iterator it = indexes.begin(); | - |
3095 | QListViewItem item = indexToListViewItem(*it); | - |
3096 | QRect rect(item.x, item.y, item.w, item.h); | - |
3097 | for (; it != indexes.end(); ++it) { | - |
3098 | item = indexToListViewItem(*it); | - |
3099 | rect |= viewItemRect(item); | - |
3100 | } | - |
3101 | return rect; | - |
3102 | } | - |
3103 | | - |
3104 | int QIconModeViewBase::itemIndex(const QListViewItem &item) const | - |
3105 | { | - |
3106 | if (!item.isValid()) | - |
3107 | return -1; | - |
3108 | int i = item.indexHint; | - |
3109 | if (i < items.count()) { | - |
3110 | if (items.at(i) == item) | - |
3111 | return i; | - |
3112 | } else { | - |
3113 | i = items.count() - 1; | - |
3114 | } | - |
3115 | | - |
3116 | int j = i; | - |
3117 | int c = items.count(); | - |
3118 | bool a = true; | - |
3119 | bool b = true; | - |
3120 | | - |
3121 | while (a || b) { | - |
3122 | if (a) { | - |
3123 | if (items.at(i) == item) { | - |
3124 | items.at(i).indexHint = i; | - |
3125 | return i; | - |
3126 | } | - |
3127 | a = ++i < c; | - |
3128 | } | - |
3129 | if (b) { | - |
3130 | if (items.at(j) == item) { | - |
3131 | items.at(j).indexHint = j; | - |
3132 | return j; | - |
3133 | } | - |
3134 | b = --j > -1; | - |
3135 | } | - |
3136 | } | - |
3137 | return -1; | - |
3138 | } | - |
3139 | | - |
3140 | void QIconModeViewBase::addLeaf(QVector<int> &leaf, const QRect &area, | - |
3141 | uint visited, QBspTree::Data data) | - |
3142 | { | - |
3143 | QListViewItem *vi; | - |
3144 | QIconModeViewBase *_this = static_cast<QIconModeViewBase *>(data.ptr); | - |
3145 | for (int i = 0; i < leaf.count(); ++i) { | - |
3146 | int idx = leaf.at(i); | - |
3147 | if (idx < 0 || idx >= _this->items.count()) | - |
3148 | continue; | - |
3149 | vi = &_this->items[idx]; | - |
3150 | Q_ASSERT(vi); | - |
3151 | if (vi->isValid() && vi->rect().intersects(area) && vi->visited != visited) { | - |
3152 | QModelIndex index = _this->dd->listViewItemToIndex(*vi); | - |
3153 | Q_ASSERT(index.isValid()); | - |
3154 | _this->interSectingVector->append(index); | - |
3155 | vi->visited = visited; | - |
3156 | } | - |
3157 | } | - |
3158 | } | - |
3159 | | - |
3160 | void QIconModeViewBase::moveItem(int index, const QPoint &dest) | - |
3161 | { | - |
3162 | | - |
3163 | QListViewItem *item = &items[index]; | - |
3164 | QRect rect = item->rect(); | - |
3165 | | - |
3166 | | - |
3167 | tree.removeLeaf(rect, index); | - |
3168 | item->move(dest); | - |
3169 | tree.insertLeaf(QRect(dest, rect.size()), index); | - |
3170 | | - |
3171 | | - |
3172 | contentsSize = (QRect(QPoint(0, 0), contentsSize)|QRect(dest, rect.size())).size(); | - |
3173 | | - |
3174 | | - |
3175 | if (moved.count() != items.count()) | - |
3176 | moved.resize(items.count()); | - |
3177 | moved.setBit(index, true); | - |
3178 | } | - |
3179 | | - |
3180 | QPoint QIconModeViewBase::snapToGrid(const QPoint &pos) const | - |
3181 | { | - |
3182 | int x = pos.x() - (pos.x() % gridSize().width()); | - |
3183 | int y = pos.y() - (pos.y() % gridSize().height()); | - |
3184 | return QPoint(x, y); | - |
3185 | } | - |
3186 | | - |
3187 | QPoint QIconModeViewBase::draggedItemsDelta() const | - |
3188 | { | - |
3189 | if (movement() == QListView::Snap) { | - |
3190 | QPoint snapdelta = QPoint((offset().x() % gridSize().width()), | - |
3191 | (offset().y() % gridSize().height())); | - |
3192 | return snapToGrid(draggedItemsPos + snapdelta) - snapToGrid(pressedPosition()) - snapdelta; | - |
3193 | } | - |
3194 | return draggedItemsPos - pressedPosition(); | - |
3195 | } | - |
3196 | | - |
3197 | QRect QIconModeViewBase::draggedItemsRect() const | - |
3198 | { | - |
3199 | QRect rect = itemsRect(draggedItems); | - |
3200 | rect.translate(draggedItemsDelta()); | - |
3201 | return rect; | - |
3202 | } | - |
3203 | | - |
3204 | void QListViewPrivate::scrollElasticBandBy(int dx, int dy) | - |
3205 | { | - |
3206 | if (dx > 0) | - |
3207 | elasticBand.moveRight(elasticBand.right() + dx); | - |
3208 | else if (dx < 0) | - |
3209 | elasticBand.moveLeft(elasticBand.left() - dx); | - |
3210 | if (dy > 0) | - |
3211 | elasticBand.moveBottom(elasticBand.bottom() + dy); | - |
3212 | else if (dy < 0) | - |
3213 | elasticBand.moveTop(elasticBand.top() - dy); | - |
3214 | } | - |
3215 | | - |
3216 | void QIconModeViewBase::clear() | - |
3217 | { | - |
3218 | tree.destroy(); | - |
3219 | items.clear(); | - |
3220 | moved.clear(); | - |
3221 | batchStartRow = 0; | - |
3222 | batchSavedDeltaSeg = 0; | - |
3223 | } | - |
3224 | | - |
3225 | void QIconModeViewBase::updateContentsSize() | - |
3226 | { | - |
3227 | QRect bounding; | - |
3228 | for (int i = 0; i < items.count(); ++i) | - |
3229 | bounding |= items.at(i).rect(); | - |
3230 | contentsSize = bounding.size(); | - |
3231 | } | - |
3232 | | - |
3233 | | - |
3234 | | - |
3235 | | - |
3236 | void QListView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) | - |
3237 | { | - |
3238 | #ifndef QT_NO_ACCESSIBILITY | - |
3239 | if (QAccessible::isActive()) { | - |
3240 | if (current.isValid()) { | - |
3241 | int entry = visualIndex(current); | - |
3242 | QAccessibleEvent event(this, QAccessible::Focus); | - |
3243 | event.setChild(entry); | - |
3244 | QAccessible::updateAccessibility(&event); | - |
3245 | } | - |
3246 | } | - |
3247 | #endif | - |
3248 | QAbstractItemView::currentChanged(current, previous); | - |
3249 | } | - |
3250 | | - |
3251 | | - |
3252 | | - |
3253 | | - |
3254 | void QListView::selectionChanged(const QItemSelection &selected, | - |
3255 | const QItemSelection &deselected) | - |
3256 | { | - |
3257 | #ifndef QT_NO_ACCESSIBILITY | - |
3258 | if (QAccessible::isActive()) { | - |
3259 | | - |
3260 | QModelIndex sel = selected.indexes().value(0); | - |
3261 | if (sel.isValid()) { | - |
3262 | int entry = visualIndex(sel); | - |
3263 | QAccessibleEvent event(this, QAccessible::SelectionAdd); | - |
3264 | event.setChild(entry); | - |
3265 | QAccessible::updateAccessibility(&event); | - |
3266 | } | - |
3267 | QModelIndex desel = deselected.indexes().value(0); | - |
3268 | if (desel.isValid()) { | - |
3269 | int entry = visualIndex(desel); | - |
3270 | QAccessibleEvent event(this, QAccessible::SelectionRemove); | - |
3271 | event.setChild(entry); | - |
3272 | QAccessible::updateAccessibility(&event); | - |
3273 | } | - |
3274 | } | - |
3275 | #endif | - |
3276 | QAbstractItemView::selectionChanged(selected, deselected); | - |
3277 | } | - |
3278 | | - |
3279 | int QListView::visualIndex(const QModelIndex &index) const | - |
3280 | { | - |
3281 | Q_D(const QListView); | - |
3282 | d->executePostedLayout(); | - |
3283 | QListViewItem itm = d->indexToListViewItem(index); | - |
3284 | int visualIndex = d->commonListView->itemIndex(itm); | - |
3285 | for (int row = 0; row <= index.row() && visualIndex >= 0; row++) { | - |
3286 | if (d->isHidden(row)) | - |
3287 | visualIndex--; | - |
3288 | } | - |
3289 | return visualIndex; | - |
3290 | } | - |
3291 | | - |
3292 | | - |
3293 | | - |
3294 | | - |
3295 | | - |
3296 | | - |
3297 | QSize QListView::viewportSizeHint() const | - |
3298 | { | - |
3299 | return QAbstractItemView::viewportSizeHint(); | - |
3300 | } | - |
3301 | | - |
3302 | QT_END_NAMESPACE | - |
3303 | | - |
3304 | #include "moc_qlistview.cpp" | - |
3305 | | - |
3306 | #endif // QT_NO_LISTVIEW | - |
| | |