[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/apps/plasma/applets/folderview
From:       Fredrik Höglund <fredrik () kde ! org>
Date:       2010-01-19 21:38:32
Message-ID: 1263937112.080155.15809.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1077284 by fredrik:

- Prevent icons from being placed at fractional grid positions when
  they're manually positioned near the edge of the icon view and align
  to grid is enabled.
- Take the direction of the flow into account when aligning icons to the grid.
- Fix an off-by-one error in nextGridPosition().

Fixed for: KDE 4.4 RC2
BUG: 195996


 M  +47 -7     iconview.cpp  
 M  +1 -0      iconview.h  


--- trunk/KDE/kdebase/apps/plasma/applets/folderview/iconview.cpp #1077283:1077284
@@ -567,7 +567,7 @@
     }
 
     const int xOrigin = (m_flow == LeftToRight || m_flow == TopToBottom) ?
-                    r.left() :  r.right() - grid.width();
+                    r.left() :  r.right() - grid.width() + 1;
 
     if (lastPos.isNull()) {
         return QPoint(xOrigin, r.top());
@@ -751,12 +751,50 @@
     updateScrollBar();
 }
 
+// Returns the contents rect with the width and height snapped to the grid 
+// and aligned according to the direction of the flow.
+QRect IconView::adjustedContentsRect(int *rowCount, int *colCount) const
+{
+    QRect r = contentsRect().toRect();
+
+    const QSize size = gridSize() + QSize(10, 10);
+    *colCount = qMax(1, (r.width() - 10) / size.width());
+    *rowCount = qMax(1, (r.height() - 10) / size.height());
+    int dx = r.width() - (*colCount * size.width() + 10);
+    int dy = r.height() - (*rowCount * size.height() + 10);
+    r.setWidth(r.width() - dx);
+    r.setHeight(r.height() - dy);
+
+    // Take the origin into account
+    if (m_flow == RightToLeft || m_flow == TopToBottomRightToLeft) {
+        r.translate(dx, 0);
+    }
+
+    return r;
+}
+
 void IconView::alignIconsToGrid()
 {
+    int rowCount, colCount;
+    const QRect cr = adjustedContentsRect(&rowCount, &colCount);
+
+    int lastRow = rowCount - 1;
+    int lastCol = colCount - 1;
+
+    const Plasma::Containment *containment = \
qobject_cast<Plasma::Containment*>(parentWidget()); +    if (!containment || \
!containment->isContainment()) { +        // Don't limit the max rows/columns in the \
scrolling direction +        if (m_flow == LeftToRight || m_flow == RightToLeft) {
+            lastRow = INT_MAX;
+        } else {
+            lastCol = INT_MAX;
+        }
+    }
+
     int margin = 10;
     int spacing = 10;
-    const QRect cr = contentsRect().toRect();
     const QSize size = gridSize() + QSize(spacing, spacing);
+
     int topMargin = margin + cr.top();
     int leftMargin = margin + cr.left();
     int vOffset = topMargin + size.height() / 2;
@@ -765,11 +803,10 @@
 
     for (int i = 0; i < m_items.size(); i++) {
         const QPoint center = m_items[i].rect.center();
-        const int col = qRound((center.x() - hOffset) / qreal(size.width()));
-        const int row = qRound((center.y() - vOffset) / qreal(size.height()));
+        const int col = qBound(0, qRound((center.x() - hOffset) / \
qreal(size.width())), lastCol); +        const int row = qBound(0, qRound((center.y() \
- vOffset) / qreal(size.height())), lastRow);  
-        const QPoint pos(leftMargin + col * size.width() + (size.width() - \
                m_items[i].rect.width() - spacing) / 2,
-                         topMargin + row * size.height());
+        const QPoint pos(leftMargin + col * size.width(), topMargin + row * \
size.height());  
         if (pos != m_items[i].rect.topLeft()) {
             m_items[i].rect.moveTo(pos);
@@ -2178,7 +2215,10 @@
         }
     }
 
-    const QRect cr = contentsRect().toRect();
+    int rowCount, colCount;
+    const QRect cr = m_alignToGrid ? adjustedContentsRect(&rowCount, &colCount)
+                            : contentsRect().toRect();
+
     boundingRect.adjust(-10, -10, 10, 10);
     boundingRect.translate(delta);
 
--- trunk/KDE/kdebase/apps/plasma/applets/folderview/iconview.h #1077283:1077284
@@ -202,6 +202,7 @@
     void layoutItems();
     void alignIconsToGrid();
     QRect itemsBoundingRect() const;
+    QRect adjustedContentsRect(int *rowCount, int *colCount) const;
     bool doLayoutSanityCheck();
     void saveIconPositions() const;
     void loadIconPositions();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic