From: Akseli Lahtinen Date: Fri, 8 Mar 2024 11:37:20 +0000 (+0000) Subject: Start autoActivationTimer only if hovering over a directory X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/803bbd1ae191a89ffdb3889acb6621431525f96d Start autoActivationTimer only if hovering over a directory Before starting autoActivationTimer, check that we're hovering the item on top of a directory. If we don't check for it, the the autoActivationTimer will try to open the hovered item in it's default application, which can be distracting and break the actual action the user was trying to do, like moving the file to a directory. BUG:479960 --- diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 9ef66d6b8..c694da9f2 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -352,6 +352,17 @@ bool KFileItemModel::supportsDropping(int index) const return !item.isNull() && DragAndDropHelper::supportsDropping(item); } +bool KFileItemModel::canEnterOnHover(int index) const +{ + KFileItem item; + if (index == -1) { + item = rootItem(); + } else { + item = fileItem(index); + } + return !item.isNull() && (item.isDir() || item.isDesktopFile()); +} + QString KFileItemModel::roleDescription(const QByteArray &role) const { static QHash description; diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h index ad1b0a138..ce58f89ac 100644 --- a/src/kitemviews/kfileitemmodel.h +++ b/src/kitemviews/kfileitemmodel.h @@ -109,6 +109,8 @@ public: bool supportsDropping(int index) const override; + bool canEnterOnHover(int index) const override; + QString roleDescription(const QByteArray &role) const override; QList> groups() const override; diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index aea59c711..2a0641aa1 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -827,11 +827,12 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent *event, cons Q_EMIT itemHovered(index); } - if (!m_autoActivationTimer->isActive() && m_autoActivationTimer->interval() >= 0) { + if (!m_autoActivationTimer->isActive() && m_autoActivationTimer->interval() >= 0 && m_model->canEnterOnHover(index)) { m_autoActivationTimer->setProperty("index", index); m_autoActivationTimer->start(); newHoveredWidget->startActivateSoonAnimation(m_autoActivationTimer->remainingTime()); } + } else { m_autoActivationTimer->stop(); if (newHoveredWidget && newHoveredWidget->isHovered()) { diff --git a/src/kitemviews/kitemmodelbase.cpp b/src/kitemviews/kitemmodelbase.cpp index b49d4ebb1..9fdecafb8 100644 --- a/src/kitemviews/kitemmodelbase.cpp +++ b/src/kitemviews/kitemmodelbase.cpp @@ -128,6 +128,12 @@ bool KItemModelBase::supportsDropping(int index) const return false; } +bool KItemModelBase::canEnterOnHover(int index) const +{ + Q_UNUSED(index) + return false; +} + QString KItemModelBase::blacklistItemDropEventMimeType() const { return QStringLiteral("application/x-dolphin-blacklist-drop"); diff --git a/src/kitemviews/kitemmodelbase.h b/src/kitemviews/kitemmodelbase.h index 4e1fd8a8f..42a9c54c9 100644 --- a/src/kitemviews/kitemmodelbase.h +++ b/src/kitemviews/kitemmodelbase.h @@ -159,6 +159,15 @@ public: // decision whether it accepts the drop? virtual bool supportsDropping(int index) const; + /** + * @return True, if the item with the index \a index can be entered in during hover actions. + * Per default false is returned. + * + * This is used to check that if the item + * we're hovering on is either directory or a desktop file. + */ + virtual bool canEnterOnHover(int index) const; + /** * @return An internal mimetype to signal that an itemDropEvent() should be rejected by * the receiving model.