]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
Fix uninitialised value
[dolphin.git] / src / views / dolphinview.cpp
index 250fe4cc7a25b7f301f4e5039feebc489154e0ea..7ed141c9cb5f1f94606f1a01ac039116b40c37af 100644 (file)
@@ -78,6 +78,7 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent)
     , m_assureVisibleCurrentIndex(false)
     , m_isFolderWritable(true)
     , m_dragging(false)
+    , m_selectNextItem(false)
     , m_url(url)
     , m_viewPropertiesContext()
     , m_mode(DolphinView::IconsView)
@@ -87,7 +88,6 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent)
     , m_view(nullptr)
     , m_container(nullptr)
     , m_toolTipManager(nullptr)
-    , m_selectNextItem(false)
     , m_selectionChangedTimer(nullptr)
     , m_currentItemUrl()
     , m_scrollToCurrentItem(false)
@@ -210,6 +210,14 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent)
     connect(m_view, &DolphinItemListView::sortRoleChanged, this, &DolphinView::slotSortRoleChangedByHeader);
     connect(m_view, &DolphinItemListView::visibleRolesChanged, this, &DolphinView::slotVisibleRolesChangedByHeader);
     connect(m_view, &DolphinItemListView::roleEditingCanceled, this, &DolphinView::slotRoleEditingCanceled);
+
+    connect(m_view, &DolphinItemListView::columnHovered, this, [this](int roleIndex) {
+        m_hoveredColumnHearderRoleIndex = roleIndex;
+    });
+    connect(m_view, &DolphinItemListView::columnUnHovered, this, [this](int roleIndex) {
+        Q_UNUSED(roleIndex)
+        m_hoveredColumnHearderRoleIndex = std::nullopt;
+    });
     connect(m_view->header(), &KItemListHeader::columnWidthChangeFinished, this, &DolphinView::slotHeaderColumnWidthChangeFinished);
     connect(m_view->header(), &KItemListHeader::sidePaddingChanged, this, &DolphinView::slotSidePaddingWidthChanged);
 
@@ -931,6 +939,11 @@ bool DolphinView::eventFilter(QObject *watched, QEvent *event)
             }
         }
         break;
+    case QEvent::KeyRelease:
+        if (static_cast<QKeyEvent *>(event)->key() == Qt::Key_Control) {
+            m_controlWheelAccumulatedDelta = 0;
+        }
+        break;
     case QEvent::FocusIn:
         if (watched == m_container) {
             setActive(true);
@@ -956,9 +969,18 @@ bool DolphinView::eventFilter(QObject *watched, QEvent *event)
         }
         break;
 
-    case QEvent::ToolTip:
-        tryShowNameToolTip(static_cast<QHelpEvent *>(event));
+    case QEvent::ToolTip: {
+        const auto helpEvent = static_cast<QHelpEvent *>(event);
+        if (tryShowNameToolTip(helpEvent)) {
+            return true;
 
+        } else if (m_hoveredColumnHearderRoleIndex) {
+            const auto roleInfo = KFileItemModel::rolesInformation().at(*m_hoveredColumnHearderRoleIndex);
+            QToolTip::showText(helpEvent->globalPos(), roleInfo.tooltip, this);
+            return true;
+        }
+        break;
+    }
     default:
         break;
     }
@@ -969,10 +991,16 @@ bool DolphinView::eventFilter(QObject *watched, QEvent *event)
 void DolphinView::wheelEvent(QWheelEvent *event)
 {
     if (event->modifiers().testFlag(Qt::ControlModifier)) {
-        const QPoint numDegrees = event->angleDelta() / 8;
-        const QPoint numSteps = numDegrees / 15;
+        m_controlWheelAccumulatedDelta += event->angleDelta().y();
+
+        if (m_controlWheelAccumulatedDelta <= -QWheelEvent::DefaultDeltasPerStep) {
+            slotDecreaseZoom();
+            m_controlWheelAccumulatedDelta += QWheelEvent::DefaultDeltasPerStep;
+        } else if (m_controlWheelAccumulatedDelta >= QWheelEvent::DefaultDeltasPerStep) {
+            slotIncreaseZoom();
+            m_controlWheelAccumulatedDelta -= QWheelEvent::DefaultDeltasPerStep;
+        }
 
-        setZoomLevel(zoomLevel() + numSteps.y());
         event->accept();
     } else {
         event->ignore();
@@ -1156,6 +1184,7 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF &pos)
         action->setCheckable(true);
         action->setChecked(visibleRolesSet.contains(info.role));
         action->setData(info.role);
+        action->setToolTip(info.tooltip);
 
         const bool enable = (!info.requiresBaloo && !info.requiresIndexer) || (info.requiresBaloo) || (info.requiresIndexer && indexingEnabled);
         action->setEnabled(enable);
@@ -1765,7 +1794,7 @@ void DolphinView::slotDeleteFileFinished(KJob *job)
 void DolphinView::selectNextItem()
 {
     if (m_active && m_selectNextItem) {
-        KItemListSelectionManagerselectionManager = m_container->controller()->selectionManager();
+        KItemListSelectionManager *selectionManager = m_container->controller()->selectionManager();
         if (selectedItems().isEmpty()) {
             Q_ASSERT_X(false, "DolphinView", "Selecting the next item failed.");
             return;
@@ -1910,7 +1939,7 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray &role, con
             newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName));
 
 #ifndef Q_OS_WIN
-            //Confirm hiding file/directory by renaming inline
+            // Confirm hiding file/directory by renaming inline
             if (!hiddenFilesShown() && newName.startsWith(QLatin1Char('.')) && !oldItem.name().startsWith(QLatin1Char('.'))) {
                 KGuiItem yesGuiItem(i18nc("@action:button", "Rename and Hide"), QStringLiteral("view-hidden"));
 
@@ -2288,13 +2317,13 @@ void DolphinView::updatePlaceholderLabel()
     m_placeholderLabel->setVisible(true);
 }
 
-void DolphinView::tryShowNameToolTip(QHelpEvent *event)
+bool DolphinView::tryShowNameToolTip(QHelpEvent *event)
 {
     if (!GeneralSettings::showToolTips() && m_mode == DolphinView::IconsView) {
         const std::optional<int> index = m_view->itemAt(event->pos());
 
         if (!index.has_value()) {
-            return;
+            return false;
         }
 
         // Check whether the filename has been elided
@@ -2305,6 +2334,8 @@ void DolphinView::tryShowNameToolTip(QHelpEvent *event)
             const QString text = item.text();
             const QPoint pos = mapToGlobal(event->pos());
             QToolTip::showText(pos, text);
+            return true;
         }
     }
+    return false;
 }