]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Make group headers mirror rtl
authorJan Blackquill <uhhadd@gmail.com>
Fri, 21 Jan 2022 23:42:20 +0000 (18:42 -0500)
committerJanet Blackquill <uhhadd@gmail.com>
Tue, 25 Jan 2022 23:49:03 +0000 (23:49 +0000)
src/kitemviews/kitemlistgroupheader.cpp
src/kitemviews/kitemlistgroupheader.h
src/kitemviews/kstandarditemlistgroupheader.cpp
src/kitemviews/kstandarditemlistgroupheader.h
src/kitemviews/private/kitemlistheaderwidget.cpp

index 80dd94149b6bea2b62cc15ce8f11e314ee0806f6..f0ff52503de4313ef8b372cc346fbd9b3c109733 100644 (file)
@@ -161,6 +161,7 @@ void KItemListGroupHeader::resizeEvent(QGraphicsSceneResizeEvent* event)
     if (event->oldSize().height() != event->newSize().height()) {
         m_dirtyCache = true;
     }
+    updateSize();
 }
 
 void KItemListGroupHeader::updateCache()
@@ -174,6 +175,13 @@ void KItemListGroupHeader::updateCache()
     m_separatorColor = mixedColor(c1, c2, 10);
     m_roleColor = mixedColor(c1, c2, 60);
 
+    updateSize();
+
+    m_dirtyCache = false;
+}
+
+void KItemListGroupHeader::updateSize()
+{
     const int padding = qMax(1, m_styleOption.padding);
     const int horizontalMargin = qMax(2, m_styleOption.horizontalMargin);
 
@@ -187,7 +195,7 @@ void KItemListGroupHeader::updateCache()
                           size().width() - 2 * padding - horizontalMargin,
                           roleHeight);
 
-    m_dirtyCache = false;
+    update();
 }
 
 QColor KItemListGroupHeader::mixedColor(const QColor& c1, const QColor& c2, int c1Percent)
index 4ba4690561196bd1043afb37eddee02fea785983..48af1e9e0d12267c4806833fd34c52f6e0bd9cc9 100644 (file)
@@ -94,6 +94,7 @@ protected:
 
 private:
     void updateCache();
+    void updateSize();
 
     static QColor mixedColor(const QColor& c1, const QColor& c2, int c1Percent = 50);
 
index 22eefe5eac7e2202e0159e8117e885a7b41df30f..28497ddfc2dbff5011097425d5d420ae14e7c622 100644 (file)
@@ -17,8 +17,7 @@ KStandardItemListGroupHeader::KStandardItemListGroupHeader(QGraphicsWidget* pare
     m_text(),
     m_pixmap()
 {
-    m_text.setTextFormat(Qt::PlainText);
-    m_text.setPerformanceHint(QStaticText::AggressiveCaching);
+
 }
 
 KStandardItemListGroupHeader::~KStandardItemListGroupHeader()
@@ -37,7 +36,7 @@ void KStandardItemListGroupHeader::paintRole(QPainter* painter, const QRectF& ro
 {
     if (m_pixmap.isNull()) {
         painter->setPen(color);
-        painter->drawStaticText(roleBounds.topLeft(), m_text);
+        painter->drawText(roleBounds, 0, m_text);
     } else {
         painter->drawPixmap(roleBounds.topLeft(), m_pixmap);
     }
@@ -55,7 +54,11 @@ void KStandardItemListGroupHeader::paintSeparator(QPainter* painter, const QColo
     if (scrollOrientation() == Qt::Horizontal) {
         painter->drawLine(0, 0, 0, size().height() - 1);
     } else {
-        painter->drawLine(0, 0, size().width() - 1, 0);
+        if (layoutDirection() == Qt::LeftToRight) {
+            painter->drawLine(0, 0, size().width() - 1, 0);
+        } else {
+            painter->drawLine(1, 0, size().width(), 0);
+        }
     }
 }
 
@@ -75,7 +78,7 @@ void KStandardItemListGroupHeader::dataChanged(const QVariant& current, const QV
 
 void KStandardItemListGroupHeader::resizeEvent(QGraphicsSceneResizeEvent* event)
 {
-    QGraphicsWidget::resizeEvent(event);
+    KItemListGroupHeader::resizeEvent(event);
     m_dirtyCache = true;
 }
 
@@ -87,7 +90,7 @@ void KStandardItemListGroupHeader::updateCache()
     const qreal maxWidth = size().width() - 4 * styleOption().padding;
 
     if (role() == "rating") {
-        m_text.setText(QString());
+        m_text = QString();
 
         const qreal height = styleOption().fontMetrics.ascent();
         const QSizeF pixmapSize(qMin(height * 5, maxWidth), height);
@@ -104,7 +107,7 @@ void KStandardItemListGroupHeader::updateCache()
 
         QFontMetricsF fontMetrics(font());
         const QString text = fontMetrics.elidedText(data().toString(), Qt::ElideRight, maxWidth);
-        m_text.setText(text);
+        m_text = text;
     }
 }
 
index ff428c4eae801a88fbde162e0ae6071f978a7b8a..965bf995cf7bd48b28da2fc968885c69b05a7468 100644 (file)
@@ -35,7 +35,7 @@ private:
 
 private:
     bool m_dirtyCache;
-    QStaticText m_text;
+    QString m_text;
     QPixmap m_pixmap;
 };
 #endif
index 8b39c25fe208289a7bd3e083c07d535fb024d463..5fb929e5209b50bf48b696e68df93b08dd46978a 100644 (file)
@@ -420,6 +420,12 @@ void KItemListHeaderWidget::paintRole(QPainter* painter,
     // The following code is based on the code from QHeaderView::paintSection().
     // SPDX-FileCopyrightText: 2011 Nokia Corporation and/or its subsidiary(-ies).
     QStyleOptionHeader option;
+    option.direction = widget->layoutDirection();
+    option.textAlignment =
+        widget->layoutDirection() == Qt::LeftToRight
+            ? Qt::AlignLeft
+            : Qt::AlignRight;
+
     option.section = orderIndex;
     option.state = QStyle::State_None | QStyle::State_Raised | QStyle::State_Horizontal;
     if (isEnabled()) {