diff options
| author | Nate Graham <[email protected]> | 2020-11-10 10:39:15 -0700 |
|---|---|---|
| committer | Nate Graham <[email protected]> | 2020-11-10 10:39:15 -0700 |
| commit | 8276f1e46e3af9c3499ff121ac603cc6cb9032ff (patch) | |
| tree | ee96621ffb8c7aa669dffbd4f198c9de4a3d159a /src/panels/places/placespanel.cpp | |
| parent | 6719072837f30c1822768da65e6ea222e987e32f (diff) | |
| parent | 6b1524e4ff115f9cbee93c3c14c09fb347885d56 (diff) | |
Merge branch 'release/20.12'
Diffstat (limited to 'src/panels/places/placespanel.cpp')
| -rw-r--r-- | src/panels/places/placespanel.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp index 336b9deb8..66770ee86 100644 --- a/src/panels/places/placespanel.cpp +++ b/src/panels/places/placespanel.cpp @@ -39,6 +39,8 @@ #include <QMenu> #include <QMimeData> #include <QVBoxLayout> +#include <QToolTip> +#include <QTimer> PlacesPanel::PlacesPanel(QWidget* parent) : Panel(parent), @@ -49,8 +51,12 @@ PlacesPanel::PlacesPanel(QWidget* parent) : m_triggerStorageSetupButton(), m_itemDropEventIndex(-1), m_itemDropEventMimeData(nullptr), - m_itemDropEvent(nullptr) + m_itemDropEvent(nullptr), + m_tooltipTimer() { + m_tooltipTimer.setInterval(500); + m_tooltipTimer.setSingleShot(true); + connect(&m_tooltipTimer, &QTimer::timeout, this, &PlacesPanel::slotShowTooltip); } PlacesPanel::~PlacesPanel() @@ -111,6 +117,8 @@ void PlacesPanel::showEvent(QShowEvent* event) m_view->setWidgetCreator(new KItemListWidgetCreator<PlacesItemListWidget>()); m_view->setGroupHeaderCreator(new KItemListGroupHeaderCreator<PlacesItemListGroupHeader>()); + installEventFilter(this); + m_controller = new KItemListController(m_model, m_view, this); m_controller->setSelectionBehavior(KItemListController::SingleSelection); m_controller->setSingleClickActivationEnforced(true); @@ -137,6 +145,21 @@ void PlacesPanel::showEvent(QShowEvent* event) Panel::showEvent(event); } +bool PlacesPanel::eventFilter(QObject * /* obj */, QEvent *event) +{ + if (event->type() == QEvent::ToolTip) { + + QHelpEvent *hoverEvent = reinterpret_cast<QHelpEvent *>(event); + + m_hoveredIndex = m_view->itemAt(hoverEvent->pos()); + m_hoverPos = mapToGlobal(hoverEvent->pos()); + + m_tooltipTimer.start(); + return true; + } + return false; +} + void PlacesPanel::slotItemActivated(int index) { triggerItem(index, Qt::LeftButton); @@ -460,6 +483,13 @@ void PlacesPanel::slotStorageSetupDone(int index, bool success) } } +void PlacesPanel::slotShowTooltip() +{ + const QUrl url = m_model->data(m_hoveredIndex).value("url").value<QUrl>(); + const QString text = url.isLocalFile() ? url.path() : url.toString(); + QToolTip::showText(m_hoverPos, text); +} + void PlacesPanel::addEntry() { const int index = m_controller->selectionManager()->currentItem(); |
