src/gui/itemviews/qlistview.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
child 37 758a864f9613
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
  1385     d->selectionModel->select(selection, command);
  1385     d->selectionModel->select(selection, command);
  1386 }
  1386 }
  1387 
  1387 
  1388 /*!
  1388 /*!
  1389   \reimp
  1389   \reimp
       
  1390 
       
  1391   Since 4.7, the returned region only contains rectangles intersecting
       
  1392   (or included in) the viewport.
  1390 */
  1393 */
  1391 QRegion QListView::visualRegionForSelection(const QItemSelection &selection) const
  1394 QRegion QListView::visualRegionForSelection(const QItemSelection &selection) const
  1392 {
  1395 {
  1393     Q_D(const QListView);
  1396     Q_D(const QListView);
  1394     // ### NOTE: this is a potential bottleneck in non-static mode
  1397     // ### NOTE: this is a potential bottleneck in non-static mode
  1395     int c = d->column;
  1398     int c = d->column;
  1396     QRegion selectionRegion;
  1399     QRegion selectionRegion;
       
  1400     const QRect &viewportRect = d->viewport->rect();
  1397     for (int i = 0; i < selection.count(); ++i) {
  1401     for (int i = 0; i < selection.count(); ++i) {
  1398         if (!selection.at(i).isValid())
  1402         if (!selection.at(i).isValid())
  1399             continue;
  1403             continue;
  1400         QModelIndex parent = selection.at(i).topLeft().parent();
  1404         QModelIndex parent = selection.at(i).topLeft().parent();
  1401         //we only display the children of the root in a listview
  1405         //we only display the children of the root in a listview
  1403         if (parent != d->root)
  1407         if (parent != d->root)
  1404             continue;
  1408             continue;
  1405         int t = selection.at(i).topLeft().row();
  1409         int t = selection.at(i).topLeft().row();
  1406         int b = selection.at(i).bottomRight().row();
  1410         int b = selection.at(i).bottomRight().row();
  1407         if (d->viewMode == IconMode || d->isWrapping()) { // in non-static mode, we have to go through all selected items
  1411         if (d->viewMode == IconMode || d->isWrapping()) { // in non-static mode, we have to go through all selected items
  1408             for (int r = t; r <= b; ++r)
  1412             for (int r = t; r <= b; ++r) {
  1409                 selectionRegion += QRegion(visualRect(d->model->index(r, c, parent)));
  1413                 const QRect &rect = visualRect(d->model->index(r, c, parent));
       
  1414                 if (viewportRect.intersects(rect))
       
  1415                     selectionRegion += rect;
       
  1416             }
  1410         } else { // in static mode, we can optimize a bit
  1417         } else { // in static mode, we can optimize a bit
  1411             while (t <= b && d->isHidden(t)) ++t;
  1418             while (t <= b && d->isHidden(t)) ++t;
  1412             while (b >= t && d->isHidden(b)) --b;
  1419             while (b >= t && d->isHidden(b)) --b;
  1413             const QModelIndex top = d->model->index(t, c, parent);
  1420             const QModelIndex top = d->model->index(t, c, parent);
  1414             const QModelIndex bottom = d->model->index(b, c, parent);
  1421             const QModelIndex bottom = d->model->index(b, c, parent);
  1415             QRect rect(visualRect(top).topLeft(),
  1422             QRect rect(visualRect(top).topLeft(),
  1416                        visualRect(bottom).bottomRight());
  1423                        visualRect(bottom).bottomRight());
  1417             selectionRegion += QRegion(rect);
  1424             if (viewportRect.intersects(rect))
       
  1425                 selectionRegion += rect;
  1418         }
  1426         }
  1419     }
  1427     }
  1420 
  1428 
  1421     return selectionRegion;
  1429     return selectionRegion;
  1422 }
  1430 }
  1843 
  1851 
  1844 void QCommonListViewBase::updateHorizontalScrollBar(const QSize &step)
  1852 void QCommonListViewBase::updateHorizontalScrollBar(const QSize &step)
  1845 {
  1853 {
  1846     horizontalScrollBar()->setSingleStep(step.width() + spacing());
  1854     horizontalScrollBar()->setSingleStep(step.width() + spacing());
  1847     horizontalScrollBar()->setPageStep(viewport()->width());
  1855     horizontalScrollBar()->setPageStep(viewport()->width());
  1848     horizontalScrollBar()->setRange(0, contentsSize.width() - viewport()->width() - 2 * spacing());
  1856     horizontalScrollBar()->setRange(0, contentsSize.width() - viewport()->width());
  1849 }
  1857 }
  1850 
  1858 
  1851 void QCommonListViewBase::updateVerticalScrollBar(const QSize &step)
  1859 void QCommonListViewBase::updateVerticalScrollBar(const QSize &step)
  1852 {
  1860 {
  1853     verticalScrollBar()->setSingleStep(step.height() + spacing());
  1861     verticalScrollBar()->setSingleStep(step.height() + spacing());
  1854     verticalScrollBar()->setPageStep(viewport()->height());
  1862     verticalScrollBar()->setPageStep(viewport()->height());
  1855     verticalScrollBar()->setRange(0, contentsSize.height() - viewport()->height() - 2 * spacing());
  1863     verticalScrollBar()->setRange(0, contentsSize.height() - viewport()->height());
  1856 }
  1864 }
  1857 
  1865 
  1858 void QCommonListViewBase::scrollContentsBy(int dx, int dy, bool /*scrollElasticBand*/)
  1866 void QCommonListViewBase::scrollContentsBy(int dx, int dy, bool /*scrollElasticBand*/)
  1859 {
  1867 {
  1860     dd->scrollContentsBy(isRightToLeft() ? -dx : dx, dy);
  1868     dd->scrollContentsBy(isRightToLeft() ? -dx : dx, dy);
  2266 {
  2274 {
  2267     const bool useItemSize = !info.grid.isValid();
  2275     const bool useItemSize = !info.grid.isValid();
  2268     const QPoint topLeft = initStaticLayout(info);
  2276     const QPoint topLeft = initStaticLayout(info);
  2269     QStyleOptionViewItemV4 option = viewOptions();
  2277     QStyleOptionViewItemV4 option = viewOptions();
  2270     option.rect = info.bounds;
  2278     option.rect = info.bounds;
       
  2279     option.rect.adjust(info.spacing, info.spacing, -info.spacing, -info.spacing);
  2271 
  2280 
  2272     // The static layout data structures are as follows:
  2281     // The static layout data structures are as follows:
  2273     // One vector contains the coordinate in the direction of layout flow.
  2282     // One vector contains the coordinate in the direction of layout flow.
  2274     // Another vector contains the coordinates of the segments.
  2283     // Another vector contains the coordinates of the segments.
  2275     // A third vector contains the index (model row) of the first item
  2284     // A third vector contains the index (model row) of the first item
  2895     }
  2904     }
  2896     batchSavedDeltaSeg = deltaSegPosition;
  2905     batchSavedDeltaSeg = deltaSegPosition;
  2897     batchStartRow = info.last + 1;
  2906     batchStartRow = info.last + 1;
  2898     bool done = (info.last >= rowCount() - 1);
  2907     bool done = (info.last >= rowCount() - 1);
  2899     // resize the content area
  2908     // resize the content area
  2900     if (done || !info.bounds.contains(item->rect()))
  2909     if (done || !info.bounds.contains(item->rect())) {
  2901         contentsSize = QSize(rect.width(), rect.height());
  2910         contentsSize = rect.size();
       
  2911         if (info.flow == QListView::LeftToRight)
       
  2912             contentsSize.rheight() += info.spacing;
       
  2913         else
       
  2914             contentsSize.rwidth() += info.spacing;
       
  2915     }
  2902     // resize tree
  2916     // resize tree
  2903     int insertFrom = info.first;
  2917     int insertFrom = info.first;
  2904     if (done || info.first == 0) {
  2918     if (done || info.first == 0) {
  2905         initBspTree(rect.size());
  2919         initBspTree(rect.size());
  2906         insertFrom = 0;
  2920         insertFrom = 0;