]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
Use cmakedefine01
[dolphin.git] / src / views / dolphinview.cpp
index bb537b982af6b3a35d575a2c9f2d64e2b5285600..168e282b535f874aab36cc4cea2e2eb032ecc9be 100644 (file)
@@ -8,6 +8,7 @@
 #include "dolphinview.h"
 
 #include "dolphin_generalsettings.h"
+#include "dolphin_detailsmodesettings.h"
 #include "dolphinitemlistview.h"
 #include "dolphinnewfilemenuobserver.h"
 #include "draganddrophelper.h"
@@ -24,7 +25,7 @@
 #include "views/tooltips/tooltipmanager.h"
 #include "zoomlevelinfo.h"
 
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
 #include <Baloo/IndexerConfig>
 #endif
 #include <KColorScheme>
@@ -59,6 +60,7 @@
 #include <QScrollBar>
 #include <QSize>
 #include <QTimer>
+#include <QToolTip>
 #include <QVBoxLayout>
 
 DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
@@ -200,12 +202,14 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
             this, &DolphinView::slotRoleEditingCanceled);
     connect(m_view->header(), &KItemListHeader::columnWidthChangeFinished,
             this, &DolphinView::slotHeaderColumnWidthChangeFinished);
+    connect(m_view->header(), &KItemListHeader::sidePaddingChanged,
+            this, &DolphinView::slotSidePaddingWidthChanged);
 
     KItemListSelectionManager* selectionManager = controller->selectionManager();
     connect(selectionManager, &KItemListSelectionManager::selectionChanged,
             this, &DolphinView::slotSelectionChanged);
 
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
     m_toolTipManager = new ToolTipManager(this);
     connect(m_toolTipManager, &ToolTipManager::urlActivated, this, &DolphinView::urlActivated);
 #endif
@@ -918,6 +922,11 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event)
         if (watched == m_view) {
             m_dragging = false;
         }
+        break;
+
+    case QEvent::ToolTip:
+        tryShowNameToolTip(event);
+
     default:
         break;
     }
@@ -1049,12 +1058,12 @@ void DolphinView::slotItemContextMenuRequested(int index, const QPointF& pos)
     }
 
     const KFileItem item = m_model->fileItem(index);
-    Q_EMIT requestContextMenu(pos.toPoint(), item, url(), QList<QAction*>());
+    Q_EMIT requestContextMenu(pos.toPoint(), item, selectedItems(), url());
 }
 
 void DolphinView::slotViewContextMenuRequested(const QPointF& pos)
 {
-    Q_EMIT requestContextMenu(pos.toPoint(), KFileItem(), url(), QList<QAction*>());
+    Q_EMIT requestContextMenu(pos.toPoint(), KFileItem(), selectedItems(), url());
 }
 
 void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
@@ -1067,7 +1076,7 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
     const QList<QByteArray> visibleRolesSet = view->visibleRoles();
 
     bool indexingEnabled = false;
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
     Baloo::IndexerConfig config;
     indexingEnabled = config.fileIndexingEnabled();
 #endif
@@ -1111,6 +1120,10 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
     QActionGroup* widthsGroup = new QActionGroup(menu);
     const bool autoColumnWidths = props.headerColumnWidths().isEmpty();
 
+    QAction* toggleSidePaddingAction = menu->addAction(i18nc("@action:inmenu", "Side Padding"));
+    toggleSidePaddingAction->setCheckable(true);
+    toggleSidePaddingAction->setChecked(view->header()->sidePadding() > 0);
+
     QAction* autoAdjustWidthsAction = menu->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
     autoAdjustWidthsAction->setCheckable(true);
     autoAdjustWidthsAction->setChecked(autoColumnWidths);
@@ -1141,6 +1154,8 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
             }
             props.setHeaderColumnWidths(columnWidths);
             header->setAutomaticColumnResizing(false);
+        } else if (action == toggleSidePaddingAction) {
+            header->setSidePadding(toggleSidePaddingAction->isChecked() ? 20 : 0);
         } else {
             // Show or hide the selected role
             const QByteArray selectedRole = action->data().toByteArray();
@@ -1193,6 +1208,13 @@ void DolphinView::slotHeaderColumnWidthChangeFinished(const QByteArray& role, qr
     props.setHeaderColumnWidths(columnWidths);
 }
 
+void DolphinView::slotSidePaddingWidthChanged(qreal width)
+{
+    ViewProperties props(viewPropertiesUrl());
+    DetailsModeSettings::setSidePadding(int(width));
+    m_view->writeSettings();
+}
+
 void DolphinView::slotItemHovered(int index)
 {
     const KFileItem item = m_model->fileItem(index);
@@ -1202,8 +1224,11 @@ void DolphinView::slotItemHovered(int index)
         const QPoint pos = m_container->mapToGlobal(itemRect.topLeft().toPoint());
         itemRect.moveTo(pos);
 
-#ifdef HAVE_BALOO
-        m_toolTipManager->showToolTip(item, itemRect, nativeParentWidget()->windowHandle());
+#if HAVE_BALOO
+        auto nativeParent = nativeParentWidget();
+        if (nativeParent) {
+            m_toolTipManager->showToolTip(item, itemRect, nativeParent->windowHandle());
+        }
 #endif
     }
 
@@ -1589,12 +1614,13 @@ void DolphinView::updateViewState()
                     m_view->scrollToItem(currentIndex);
                     m_scrollToCurrentItem = false;
                 }
+                m_currentItemUrl = QUrl();
             } else {
                 selectionManager->setCurrentItem(0);
             }
+        } else {
+            m_currentItemUrl = QUrl();
         }
-
-        m_currentItemUrl = QUrl();
     }
 
     if (!m_restoredContentsPosition.isNull()) {
@@ -1629,21 +1655,25 @@ void DolphinView::updateViewState()
                 }
             }
 
-            selectionManager->beginAnchoredSelection(selectionManager->currentItem());
-            selectionManager->setSelectedItems(selectedItems);
+            if (!selectedItems.isEmpty()) {
+                selectionManager->beginAnchoredSelection(selectionManager->currentItem());
+                selectionManager->setSelectedItems(selectedItems);
+            }
         }
     }
 }
 
 void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior)
 {
-#ifdef HAVE_BALOO
     if (GeneralSettings::showToolTips()) {
+#if HAVE_BALOO
         m_toolTipManager->hideToolTip(behavior);
-    }
 #else
         Q_UNUSED(behavior)
 #endif
+    } else if (m_mode == DolphinView::IconsView) {
+       QToolTip::hideText();
+    }
 }
 
 void DolphinView::slotTwoClicksRenamingTimerTimeout()
@@ -1984,6 +2014,7 @@ void DolphinView::applyViewProperties(const ViewProperties& props)
         } else {
             header->setAutomaticColumnResizing(true);
         }
+        header->setSidePadding(DetailsModeSettings::sidePadding());
     }
 
     m_view->endTransaction();
@@ -2141,7 +2172,13 @@ void DolphinView::updatePlaceholderLabel()
     } else if (m_url.scheme() == QLatin1String("trash") && m_url.path() == QLatin1String("/")) {
         m_placeholderLabel->setText(i18n("Trash is empty"));
     } else if (m_url.scheme() == QLatin1String("tags")) {
-        m_placeholderLabel->setText(i18n("No tags"));
+        if (m_url.path() == QLatin1Char('/')) {
+            m_placeholderLabel->setText(i18n("No tags"));
+        } else {
+            const QString tagName = m_url.path().mid(1); // Remove leading /
+            m_placeholderLabel->setText(i18n("No files tagged with \"%1\"", tagName));
+        }
+
     } else if (m_url.scheme() == QLatin1String("recentlyused")) {
         m_placeholderLabel->setText(i18n("No recently used items"));
     } else if (m_url.scheme() == QLatin1String("smb")) {
@@ -2158,3 +2195,25 @@ void DolphinView::updatePlaceholderLabel()
 
     m_placeholderLabel->setVisible(true);
 }
+
+void DolphinView::tryShowNameToolTip(QEvent* event)
+{
+    if (!GeneralSettings::showToolTips() && m_mode == DolphinView::IconsView) {
+        QHelpEvent *hoverEvent = reinterpret_cast<QHelpEvent *>(event);
+        const std::optional<int> index = m_view->itemAt(hoverEvent->pos());
+
+        if (!index.has_value()) {
+            return;
+        }
+
+        // Check whether the filename has been elided
+        const bool isElided = m_view->isElided(index.value());
+
+        if(isElided) {
+            const KFileItem item = m_model->fileItem(index.value());
+            const QString text = item.text();
+            const QPoint pos = mapToGlobal(hoverEvent->pos());
+            QToolTip::showText(pos, text);
+        }
+    }
+}