]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/statusbar/dolphinstatusbar.cpp
flatpak: Switch to non-preview runtime
[dolphin.git] / src / statusbar / dolphinstatusbar.cpp
index 42ce58f64478d444a157bcb352608c58d54dc26c..9ea0ae5aa76daa594ce5e3cc2a3d3ed55e379f20 100644 (file)
 #include <QHelpEvent>
 #include <QIcon>
 #include <QMenu>
+#include <QPainter>
 #include <QProgressBar>
 #include <QSlider>
+#include <QStyleOption>
 #include <QTimer>
 #include <QToolButton>
 
@@ -44,13 +46,14 @@ DolphinStatusBar::DolphinStatusBar(QWidget *parent)
     , m_delayUpdateTimer(nullptr)
     , m_textTimestamp()
 {
+    setProperty("_breeze_statusbar_separator", true);
     // Initialize text label
     m_label = new KSqueezedTextLabel(m_text, this);
     m_label->setWordWrap(true);
     m_label->setTextFormat(Qt::PlainText);
 
     // Initialize zoom slider's explanatory label
-    m_zoomLabel = new QLabel(i18nc("Used as a noun, i.e. 'Here is the zoom level:'", "Zoom:"), this);
+    m_zoomLabel = new KSqueezedTextLabel(i18nc("Used as a noun, i.e. 'Here is the zoom level:'", "Zoom:"), this);
 
     // Initialize zoom widget
     m_zoomSlider = new QSlider(Qt::Horizontal, this);
@@ -113,7 +116,7 @@ DolphinStatusBar::DolphinStatusBar(QWidget *parent)
     m_progressBar->setMaximumWidth(fontMetrics.averageCharWidth() * 20);
 
     QHBoxLayout *topLayout = new QHBoxLayout(this);
-    topLayout->setContentsMargins(2, 0, 2, 0);
+    updateContentsMargins();
     topLayout->setSpacing(4);
     topLayout->addWidget(m_label, 1);
     topLayout->addWidget(m_zoomLabel);
@@ -269,7 +272,7 @@ void DolphinStatusBar::contextMenuEvent(QContextMenuEvent *event)
     showSpaceInfoAction->setCheckable(true);
     showSpaceInfoAction->setChecked(GeneralSettings::showSpaceInfo());
 
-    const QAction *action = menu.exec(QCursor::pos());
+    const QAction *action = menu.exec(event->reason() == QContextMenuEvent::Reason::Mouse ? QCursor::pos() : mapToGlobal(QPoint(width() / 2, height() / 2)));
     if (action == showZoomSliderAction) {
         const bool visible = showZoomSliderAction->isChecked();
         GeneralSettings::setShowZoomSlider(visible);
@@ -280,6 +283,7 @@ void DolphinStatusBar::contextMenuEvent(QContextMenuEvent *event)
         GeneralSettings::setShowSpaceInfo(visible);
         m_spaceInfo->setVisible(visible);
     }
+    updateContentsMargins();
 }
 
 void DolphinStatusBar::showZoomSliderToolTip(int zoomLevel)
@@ -334,4 +338,26 @@ void DolphinStatusBar::setExtensionsVisible(bool visible)
     m_spaceInfo->setVisible(showSpaceInfo);
     m_zoomSlider->setVisible(showZoomSlider);
     m_zoomLabel->setVisible(showZoomSlider);
+    updateContentsMargins();
 }
+
+void DolphinStatusBar::updateContentsMargins()
+{
+    if (GeneralSettings::showSpaceInfo()) {
+        // We reduce the outside margin for the flat button so it visually has the same margin as the status bar text label on the other end of the bar.
+        layout()->setContentsMargins(6, 0, 2, 0);
+    } else {
+        layout()->setContentsMargins(6, 0, 6, 0);
+    }
+}
+
+void DolphinStatusBar::paintEvent(QPaintEvent *paintEvent)
+{
+    Q_UNUSED(paintEvent)
+    QPainter p(this);
+    QStyleOption opt;
+    opt.initFrom(this);
+    style()->drawPrimitive(QStyle::PE_PanelStatusBar, &opt, &p, this);
+}
+
+#include "moc_dolphinstatusbar.cpp"