]> cloud.milkyroute.net Git - dolphin.git/commitdiff
DolphinStatusBar: Fix premature text squeezing
authorAkseli Lahtinen <akselmo@akselmo.dev>
Thu, 24 Apr 2025 12:03:42 +0000 (15:03 +0300)
committerAkseli Lahtinen <akselmo@akselmo.dev>
Thu, 24 Apr 2025 12:08:25 +0000 (15:08 +0300)
The text would get squeezed and elided prematurely due to some clipping
calculations and paddings created for the clipping.

This slightly modifies the clipping code, that we extend the painted
area and then clip off the excess, instead of moving the area to
specific place and then clipping off the excess.

This also makes sure the text width accounts for one extra character
plus the clippings we do, so that text will always fit the statusbar.

BUG: 503164

src/dolphinviewcontainer.cpp
src/statusbar/dolphinstatusbar.cpp

index 9bda4d8881dea731054399ee62d7ea6e2d533d10..ee4bb6e4c3bbdbbffac58ec15931a624401abd74 100644 (file)
@@ -1094,11 +1094,9 @@ bool DolphinViewContainer::eventFilter(QObject *object, QEvent *event)
 
 QRect DolphinViewContainer::preferredSmallStatusBarGeometry()
 {
-    // Adjust to clipping, we need to add 1 due to how QRects coordinates work.
-    int clipAdjustment = m_statusBar->clippingAmount() + 1;
-    // Add offset depending if horizontal scrollbar or filterbar is visible.
-    const int yPos = m_view->geometry().bottom() - m_view->horizontalScrollBarHeight() - m_statusBar->minimumHeight() + clipAdjustment;
-    QRect statusBarRect = rect().adjusted(-clipAdjustment, yPos, 0, 0);
+    // Add offset depending if horizontal scrollbar or filterbar is visible, we need to add 1 due to how QRect coordinates work.
+    const int yPos = m_view->geometry().bottom() - m_view->horizontalScrollBarHeight() - m_statusBar->minimumHeight() + 1;
+    QRect statusBarRect = rect().adjusted(0, yPos, 0, 0);
     return statusBarRect;
 }
 
index 17a29e84cdc296951c7a5fb2f45a5909a449ad9b..f81120a44ea1b342a2f65c53ea7e3fbf9d9be847 100644 (file)
@@ -50,6 +50,7 @@ DolphinStatusBar::DolphinStatusBar(QWidget *parent)
     setProperty("_breeze_statusbar_separator", true);
 
     QWidget *contentsContainer = prepareContentsContainer();
+    contentsContainer->setContentsMargins(0, 0, 0, 0);
 
     // Initialize text label
     m_label = new KSqueezedTextLabel(m_text, contentsContainer);
@@ -292,8 +293,8 @@ void DolphinStatusBar::updateWidthToContent()
             // from "jumping around" when user tries to interact with them.
             setFixedWidth(maximumViewWidth);
         } else {
-            const int contentWidth = style()->pixelMetric(QStyle::PM_LayoutLeftMargin, &opt, this) + labelSize.width()
-                + style()->pixelMetric(QStyle::PM_LayoutRightMargin, &opt, this);
+            // Make sure we have room for the text
+            const int contentWidth = labelSize.width() + QFontMetrics(font()).averageCharWidth() + (clippingAmount() * 2);
             setFixedWidth(qMin(contentWidth, maximumViewWidth));
         }
         Q_EMIT widthUpdated();
@@ -422,7 +423,7 @@ void DolphinStatusBar::updateContentsMargins()
         m_topLayout->setContentsMargins(6, 0, 2, 0);
     } else {
         // Add extra margins to toplayout to avoid clipping too early.
-        m_topLayout->setContentsMargins(clippingAmount() * 2, 0, clippingAmount(), clippingAmount());
+        m_topLayout->setContentsMargins(clippingAmount() * 2, 0, clippingAmount(), 0);
     }
     setContentsMargins(0, 0, 0, 0);
 }
@@ -438,11 +439,13 @@ void DolphinStatusBar::paintEvent(QPaintEvent *paintEvent)
         if (m_label && !m_label->fullText().isEmpty()) {
             opt.state = QStyle::State_Sunken;
             QPainterPath path;
-            // Clip the left and bottom border off.
+            // Adjust the rectangle to be a bit larger, then clip the left and bottom border off.
             QRect clipRect;
             if (layoutDirection() == Qt::RightToLeft) {
+                opt.rect = rect().adjusted(0, 0, clippingAmount(), clippingAmount());
                 clipRect = QRect(opt.rect.topLeft(), opt.rect.bottomRight()).adjusted(0, 0, -clippingAmount(), -clippingAmount());
             } else {
+                opt.rect = rect().adjusted(-clippingAmount(), 0, 0, clippingAmount());
                 clipRect = QRect(opt.rect.topLeft(), opt.rect.bottomRight()).adjusted(clippingAmount(), 0, 0, -clippingAmount());
             }
             path.addRect(clipRect);