]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/private/kitemlistviewlayouter.cpp
Add smaller statusbar and set it as default
[dolphin.git] / src / kitemviews / private / kitemlistviewlayouter.cpp
index 5b0df0bd0200959c91019f2cb40772d1d1b2d51d..3ed2343a83c2ace6ae93af4b6acbf727a67fa677 100644 (file)
@@ -40,6 +40,7 @@ KItemListViewLayouter::KItemListViewLayouter(KItemListSizeHintResolver *sizeHint
     , m_groupHeaderHeight(0)
     , m_groupHeaderMargin(0)
     , m_itemInfos()
+    , m_statusBarOffset(0)
 {
     Q_ASSERT(m_sizeHintResolver);
 }
@@ -226,8 +227,12 @@ QRectF KItemListViewLayouter::itemRect(int index) const
         // Rotate the logical direction which is always vertical by 90°
         // to get the physical horizontal direction
         QPointF pos(y, x);
-        pos.rx() -= m_scrollOffset;
         sizeHint.transpose();
+        if (QGuiApplication::isRightToLeft()) {
+            pos.rx() = m_size.width() - 1 + m_scrollOffset - pos.x() - sizeHint.width();
+        } else {
+            pos.rx() -= m_scrollOffset;
+        }
         return QRectF(pos, sizeHint);
     }
 
@@ -256,7 +261,6 @@ QRectF KItemListViewLayouter::groupHeaderRect(int index) const
         pos.ry() -= m_groupHeaderHeight;
         size = QSizeF(m_size.width(), m_groupHeaderHeight);
     } else {
-        pos.rx() -= m_itemMargin.width();
         pos.ry() = 0;
 
         // Determine the maximum width used in the current column. As the
@@ -282,7 +286,14 @@ QRectF KItemListViewLayouter::groupHeaderRect(int index) const
         }
 
         size = QSizeF(headerWidth, m_size.height());
+
+        if (QGuiApplication::isRightToLeft()) {
+            pos.setX(firstItemRect.right() + m_itemMargin.width() - size.width());
+        } else {
+            pos.rx() -= m_itemMargin.width();
+        }
     }
+
     return QRectF(pos, size);
 }
 
@@ -331,6 +342,13 @@ void KItemListViewLayouter::markAsDirty()
     m_dirty = true;
 }
 
+void KItemListViewLayouter::setStatusBarOffset(int offset)
+{
+    if (m_statusBarOffset != offset) {
+        m_statusBarOffset = offset;
+    }
+}
+
 #ifndef QT_NO_DEBUG
 bool KItemListViewLayouter::isDirty()
 {
@@ -361,13 +379,14 @@ void KItemListViewLayouter::doLayout()
 
     const bool grouped = createGroupHeaders();
 
-    const bool horizontalScrolling = (m_scrollOrientation == Qt::Horizontal);
+    const bool horizontalScrolling = m_scrollOrientation == Qt::Horizontal;
     if (horizontalScrolling) {
         // Flip everything so that the layout logically can work like having
         // a vertical scrolling
         itemSize.transpose();
         itemMargin.transpose();
         size.transpose();
+        size.rwidth() -= m_statusBarOffset;
 
         if (grouped) {
             // In the horizontal scrolling case all groups are aligned
@@ -377,8 +396,9 @@ void KItemListViewLayouter::doLayout()
         }
     }
 
+    const bool isRightToLeft = QGuiApplication::isRightToLeft();
     m_columnWidth = itemSize.width() + itemMargin.width();
-    const qreal widthForColumns = size.width() - itemMargin.width();
+    const qreal widthForColumns = std::max(size.width() - itemMargin.width(), m_columnWidth);
     m_columnCount = qMax(1, int(widthForColumns / m_columnWidth));
     m_xPosInc = itemMargin.width();
 
@@ -397,7 +417,7 @@ void KItemListViewLayouter::doLayout()
 
     // Calculate the offset of each column, i.e., the x-coordinate where the column starts.
     m_columnOffsets.resize(m_columnCount);
-    qreal currentOffset = QGuiApplication::isRightToLeft() ? widthForColumns : m_xPosInc;
+    qreal currentOffset = isRightToLeft && !horizontalScrolling ? widthForColumns : m_xPosInc;
 
     if (grouped && horizontalScrolling) {
         // All group headers will always be aligned on the top and not
@@ -405,16 +425,21 @@ void KItemListViewLayouter::doLayout()
         currentOffset += m_groupHeaderHeight;
     }
 
-    if (QGuiApplication::isLeftToRight())
+    if (isRightToLeft) {
         for (int column = 0; column < m_columnCount; ++column) {
-            m_columnOffsets[column] = currentOffset;
-            currentOffset += m_columnWidth;
+            if (horizontalScrolling) {
+                m_columnOffsets[column] = currentOffset + column * m_columnWidth;
+            } else {
+                currentOffset -= m_columnWidth;
+                m_columnOffsets[column] = currentOffset;
+            }
         }
-    else
+    } else {
         for (int column = 0; column < m_columnCount; ++column) {
-            m_columnOffsets[column] = currentOffset - m_columnWidth;
-            currentOffset -= m_columnWidth;
+            m_columnOffsets[column] = currentOffset;
+            currentOffset += m_columnWidth;
         }
+    }
 
     // Prepare the QVector which stores the y-coordinate for each new row.
     int numberOfRows = (itemCount + m_columnCount - 1) / m_columnCount;