mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-22 01:40:02 +00:00
[ToolTipManager] Create DolphinFileMetaDataWidget on-demand again
This reverts b7fbd19a76
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.
This commit is contained in:
parent
447c35868c
commit
64ffcdad4f
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue