Commit 64ffcdad authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[ToolTipManager] Create DolphinFileMetaDataWidget on-demand again

This reverts b7fbd19a 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.
parent 447c3586
Pipeline #157394 passed with stage
in 3 minutes and 50 seconds
......@@ -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;
}
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment