]> cloud.milkyroute.net Git - dolphin.git/commitdiff
[Dolphin] Hide tooltip instantly on key press
authorPiotr Henryk Dabrowski <phd@phd.re>
Sat, 3 Aug 2019 13:28:35 +0000 (15:28 +0200)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Sat, 3 Aug 2019 13:29:26 +0000 (15:29 +0200)
Summary:
Instantly hide tooltip shown over an element when a key is pressed.

Currently, when pressing an alphanum key to select a different file,
the tooltip continues to cover much of the window - often hiding that newly selected file from view.

Reviewers: #dolphin, ngraham, elvisangelaccio

Reviewed By: #dolphin, elvisangelaccio

Subscribers: broulik, elvisangelaccio, kfm-devel, pdabrowski

Tags: #dolphin

Differential Revision: https://phabricator.kde.org/D22512

src/views/dolphinview.cpp
src/views/dolphinview.h
src/views/tooltips/tooltipmanager.cpp
src/views/tooltips/tooltipmanager.h

index 5b00fa36dcceefb6ca1b35f350e16512d1281f77..e6b232dcc14ed1d0f7a153f2bffa9d369b485a98 100644 (file)
@@ -128,8 +128,8 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
     m_container = new KItemListContainer(controller, this);
     m_container->installEventFilter(this);
     setFocusProxy(m_container);
-    connect(m_container->horizontalScrollBar(), &QScrollBar::valueChanged, this, &DolphinView::hideToolTip);
-    connect(m_container->verticalScrollBar(), &QScrollBar::valueChanged, this, &DolphinView::hideToolTip);
+    connect(m_container->horizontalScrollBar(), &QScrollBar::valueChanged, this, [=] { hideToolTip(); });
+    connect(m_container->verticalScrollBar(), &QScrollBar::valueChanged, this, [=] { hideToolTip(); });
 
     controller->setSelectionBehavior(KItemListController::MultiSelection);
     connect(controller, &KItemListController::itemActivated, this, &DolphinView::slotItemActivated);
@@ -744,6 +744,7 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event)
         break;
 
     case QEvent::KeyPress:
+        hideToolTip(ToolTipManager::HideBehavior::Instantly);
         if (GeneralSettings::useTabForSwitchingSplitView()) {
             QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
             if (keyEvent->key() == Qt::Key_Tab && keyEvent->modifiers() == Qt::NoModifier) {
@@ -1414,11 +1415,11 @@ void DolphinView::updateViewState()
     }
 }
 
-void DolphinView::hideToolTip()
+void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior)
 {
 #ifdef HAVE_BALOO
     if (GeneralSettings::showToolTips()) {
-        m_toolTipManager->hideToolTip();
+        m_toolTipManager->hideToolTip(behavior);
     }
 #endif
 }
index 7be2eed2d41ca36bb454b2d0602df0ec060d13b4..a4da92f2db317250dbe81b368781a2d78a3a6999 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "dolphintabwidget.h"
 #include "dolphin_export.h"
+#include "tooltips/tooltipmanager.h"
 
 #include <KFileItem>
 #include <KIO/Job>
@@ -697,8 +698,6 @@ private slots:
      */
     void updateViewState();
 
-    void hideToolTip();
-
     /**
      * Calculates the number of currently shown files into
      * \a fileCount and the number of folders into \a folderCount.
@@ -733,6 +732,11 @@ private:
      */
     void applyModeToView();
 
+    /**
+     * Hides tooltip displayed over element.
+     */
+    void hideToolTip(const ToolTipManager::HideBehavior behavior = ToolTipManager::HideBehavior::Later);
+
     /**
      * Helper method for DolphinView::paste() and DolphinView::pasteIntoFolder().
      * Pastes the clipboard data into the URL \a url.
index aae97458cfd6bbadfb606840366fec6b7765da7e..eaa78598732c12ba966181146535ad8e8e6939d4 100644 (file)
@@ -104,7 +104,7 @@ void ToolTipManager::showToolTip(const KFileItem& item, const QRectF& itemRect,
     Q_ASSERT(!m_metaDataRequested);
 }
 
-void ToolTipManager::hideToolTip()
+void ToolTipManager::hideToolTip(const HideBehavior behavior)
 {
     if (m_appliedWaitCursor) {
         QApplication::restoreOverrideCursor();
@@ -116,7 +116,14 @@ void ToolTipManager::hideToolTip()
     m_showToolTipTimer->stop();
     m_contentRetrievalTimer->stop();
     if (m_tooltipWidget) {
-        m_tooltipWidget->hideLater();
+        switch (behavior) {
+        case HideBehavior::Instantly:
+            m_tooltipWidget->hide();
+            break;
+        case HideBehavior::Later:
+            m_tooltipWidget->hideLater();
+            break;
+        }
     }
 }
 
index 10f88ad76e6cad0dc9a2ad96118bb925d6780bff..c09a40d31c9a84df777758aacce68cba4a72cf29 100644 (file)
@@ -42,6 +42,11 @@ class ToolTipManager : public QObject
     Q_OBJECT
 
 public:
+    enum class HideBehavior {
+        Instantly,
+        Later
+    };
+
     explicit ToolTipManager(QWidget* parent);
     ~ToolTipManager() override;
 
@@ -56,7 +61,7 @@ public:
     /**
      * Hides the currently shown tooltip.
      */
-    void hideToolTip();
+    void hideToolTip(const HideBehavior behavior = HideBehavior::Later);
 
 signals:
     /**