]> cloud.milkyroute.net Git - dolphin.git/commitdiff
[ToolTipManager] Create DolphinFileMetaDataWidget on-demand again
authorKai Uwe Broulik <kde@privat.broulik.de>
Tue, 29 Mar 2022 07:36:30 +0000 (09:36 +0200)
committerKai Uwe Broulik <kde@privat.broulik.de>
Thu, 31 Mar 2022 12:22:24 +0000 (14:22 +0200)
This reverts b7fbd19a7660424e6839df37f12b33111408b1fc but creates the
widget only once and then reuses it.

However, ownership of a parent-less widget is transferred to the
`KToolTipWidget` but since we first request metadata, then show the
tooltip (or won't if the mouse moved on since), we cannot rely on
the `KToolTipWidget` exclusively.

Instead, when we still delete the widget ourself until we have
shown the `KToolTipWidget` once at which point it will handle the
life time for us.

This fixes parenting the widget to `DolphinView` which would make
it appear as a broken line in the top left of the window.

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

index e80d45e614c1c9125d821672ddc64befdb0f293c..6372617027da3e892d6f640d088e79410cac7f0f 100644 (file)
@@ -38,7 +38,6 @@ ToolTipManager::ToolTipManager(QWidget* parent) :
     m_showToolTipTimer(nullptr),
     m_contentRetrievalTimer(nullptr),
     m_transientParent(nullptr),
-    m_fileMetaDataWidget(nullptr),
     m_toolTipRequested(false),
     m_metaDataRequested(false),
     m_appliedWaitCursor(false),
@@ -61,17 +60,13 @@ ToolTipManager::ToolTipManager(QWidget* parent) :
     connect(m_contentRetrievalTimer, &QTimer::timeout, this, &ToolTipManager::startContentRetrieval);
 
     Q_ASSERT(m_contentRetrievalTimer->interval() < m_showToolTipTimer->interval());
-
-    // Only start the retrieving of the content, when the mouse has been over this
-    // item for 200 milliseconds. This prevents a lot of useless preview jobs and
-    // meta data retrieval, when passing rapidly over a lot of items.
-    m_fileMetaDataWidget = new DolphinFileMetaDataWidget(parent);
-    connect(m_fileMetaDataWidget, &DolphinFileMetaDataWidget::metaDataRequestFinished, this, &ToolTipManager::slotMetaDataRequestFinished);
-    connect(m_fileMetaDataWidget, &DolphinFileMetaDataWidget::urlActivated, this, &ToolTipManager::urlActivated);
 }
 
 ToolTipManager::~ToolTipManager()
 {
+    if (!m_fileMetaDatWidgetOwnershipTransferred) {
+        delete m_fileMetaDataWidget;
+    }
 }
 
 void ToolTipManager::showToolTip(const KFileItem& item, const QRectF& itemRect, QWindow *transientParent)
@@ -85,6 +80,15 @@ void ToolTipManager::showToolTip(const KFileItem& item, const QRectF& itemRect,
 
     m_transientParent = transientParent;
 
+    // Only start the retrieving of the content, when the mouse has been over this
+    // item for 200 milliseconds. This prevents a lot of useless preview jobs and
+    // meta data retrieval, when passing rapidly over a lot of items.
+    if (!m_fileMetaDataWidget) {
+        m_fileMetaDataWidget = new DolphinFileMetaDataWidget();
+        connect(m_fileMetaDataWidget, &DolphinFileMetaDataWidget::metaDataRequestFinished, this, &ToolTipManager::slotMetaDataRequestFinished);
+        connect(m_fileMetaDataWidget, &DolphinFileMetaDataWidget::urlActivated, this, &ToolTipManager::urlActivated);
+    }
+
     m_contentRetrievalTimer->start();
     m_showToolTipTimer->start();
     m_toolTipRequested = true;
@@ -219,6 +223,9 @@ void ToolTipManager::showToolTip()
         m_tooltipWidget.reset(new KToolTipWidget());
     }
     m_tooltipWidget->showBelow(m_itemRect, m_fileMetaDataWidget, m_transientParent);
+    // At this point KToolTipWidget adopted our parent-less metadata widget.
+    m_fileMetaDatWidgetOwnershipTransferred = true;
+
     m_toolTipRequested = false;
 }
 
index 06639334471e948e0848f465d6b197cef8d46c13..c86c97f6bc821db8eb0c681c4896b1750565c3cb 100644 (file)
@@ -77,7 +77,12 @@ private:
     QWindow* m_transientParent;
 
     QScopedPointer<KToolTipWidget> m_tooltipWidget;
-    DolphinFileMetaDataWidget *m_fileMetaDataWidget;
+    DolphinFileMetaDataWidget *m_fileMetaDataWidget = nullptr;
+
+    /// Whether ownership of the metadata widget was transferred
+    /// over to the KToolTipWidget (i.e. we should not delete it
+    /// anymore)
+    bool m_fileMetaDatWidgetOwnershipTransferred = false;
 
     bool m_toolTipRequested;
     bool m_metaDataRequested;