Merge branch 'release/20.12'

This commit is contained in:
Nate Graham 2020-11-10 10:39:15 -07:00
commit 8276f1e46e
2 changed files with 38 additions and 1 deletions

View file

@ -39,6 +39,8 @@
#include <QMenu> #include <QMenu>
#include <QMimeData> #include <QMimeData>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QToolTip>
#include <QTimer>
PlacesPanel::PlacesPanel(QWidget* parent) : PlacesPanel::PlacesPanel(QWidget* parent) :
Panel(parent), Panel(parent),
@ -49,8 +51,12 @@ PlacesPanel::PlacesPanel(QWidget* parent) :
m_triggerStorageSetupButton(), m_triggerStorageSetupButton(),
m_itemDropEventIndex(-1), m_itemDropEventIndex(-1),
m_itemDropEventMimeData(nullptr), 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() PlacesPanel::~PlacesPanel()
@ -111,6 +117,8 @@ void PlacesPanel::showEvent(QShowEvent* event)
m_view->setWidgetCreator(new KItemListWidgetCreator<PlacesItemListWidget>()); m_view->setWidgetCreator(new KItemListWidgetCreator<PlacesItemListWidget>());
m_view->setGroupHeaderCreator(new KItemListGroupHeaderCreator<PlacesItemListGroupHeader>()); m_view->setGroupHeaderCreator(new KItemListGroupHeaderCreator<PlacesItemListGroupHeader>());
installEventFilter(this);
m_controller = new KItemListController(m_model, m_view, this); m_controller = new KItemListController(m_model, m_view, this);
m_controller->setSelectionBehavior(KItemListController::SingleSelection); m_controller->setSelectionBehavior(KItemListController::SingleSelection);
m_controller->setSingleClickActivationEnforced(true); m_controller->setSingleClickActivationEnforced(true);
@ -137,6 +145,21 @@ void PlacesPanel::showEvent(QShowEvent* event)
Panel::showEvent(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) void PlacesPanel::slotItemActivated(int index)
{ {
triggerItem(index, Qt::LeftButton); 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() void PlacesPanel::addEntry()
{ {
const int index = m_controller->selectionManager()->currentItem(); const int index = m_controller->selectionManager()->currentItem();

View file

@ -11,6 +11,7 @@
#include "panels/panel.h" #include "panels/panel.h"
#include <QUrl> #include <QUrl>
#include <QTimer>
class KItemListController; class KItemListController;
class PlacesItemModel; class PlacesItemModel;
@ -30,6 +31,8 @@ public:
~PlacesPanel() override; ~PlacesPanel() override;
void proceedWithTearDown(); void proceedWithTearDown();
bool eventFilter(QObject *obj, QEvent *event) override;
signals: signals:
void placeActivated(const QUrl& url); void placeActivated(const QUrl& url);
void placeMiddleClicked(const QUrl& url); void placeMiddleClicked(const QUrl& url);
@ -58,6 +61,7 @@ private slots:
void slotAboveItemDropEvent(int index, QGraphicsSceneDragDropEvent* event); void slotAboveItemDropEvent(int index, QGraphicsSceneDragDropEvent* event);
void slotUrlsDropped(const QUrl& dest, QDropEvent* event, QWidget* parent); void slotUrlsDropped(const QUrl& dest, QDropEvent* event, QWidget* parent);
void slotStorageSetupDone(int index, bool success); void slotStorageSetupDone(int index, bool success);
void slotShowTooltip();
private: private:
void addEntry(); void addEntry();
@ -84,6 +88,9 @@ private:
int m_itemDropEventIndex; int m_itemDropEventIndex;
QMimeData* m_itemDropEventMimeData; QMimeData* m_itemDropEventMimeData;
QDropEvent* m_itemDropEvent; QDropEvent* m_itemDropEvent;
QTimer m_tooltipTimer;
int m_hoveredIndex;
QPoint m_hoverPos;
}; };
#endif // PLACESPANEL_H #endif // PLACESPANEL_H