summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-08-27 18:50:49 (GMT)
committerMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-08-27 18:50:49 (GMT)
commit2fb122d6ebefc9f350f5fcf5ae39ef18b74fe1d5 (patch)
treee7b147ecf6dab411bba4edb537c360c121301089
parent63b31e2cd7566ada7dfd5472910d8d7829525734 (diff)
Replace tooltip with our own hack
It might not look much better, but at least it doesn't get in the way of tracking the cursor, and doesn't jump around a bit randomly, or go away randomly.
-rw-r--r--src/part/radialMap/widget.cpp2
-rw-r--r--src/part/radialMap/widget.h3
-rw-r--r--src/part/radialMap/widgetEvents.cpp28
3 files changed, 30 insertions, 3 deletions
diff --git a/src/part/radialMap/widget.cpp b/src/part/radialMap/widget.cpp
index cc259a1..450d08f 100644
--- a/src/part/radialMap/widget.cpp
+++ b/src/part/radialMap/widget.cpp
@@ -50,6 +50,8 @@ RadialMap::Widget::Widget(QWidget *parent, bool isSummary)
connect(this, &Widget::folderCreated, this, &Widget::sendFakeMouseEvent);
connect(&m_timer, &QTimer::timeout, this, &Widget::resizeTimeout);
+ m_tooltip.setFrameShape(QFrame::StyledPanel);
+ m_tooltip.setWindowFlags(Qt::ToolTip | Qt::WindowTransparentForInput);
}
RadialMap::Widget::~Widget()
diff --git a/src/part/radialMap/widget.h b/src/part/radialMap/widget.h
index 7fbeefa..c3fd780 100644
--- a/src/part/radialMap/widget.h
+++ b/src/part/radialMap/widget.h
@@ -25,6 +25,7 @@
#include <KJob>
#include <QUrl>
+#include <QLabel>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMouseEvent>
@@ -95,6 +96,7 @@ protected:
virtual void paintEvent(QPaintEvent*);
virtual void resizeEvent(QResizeEvent*);
virtual void enterEvent(QEvent*);
+ virtual void leaveEvent(QEvent*);
protected:
const Segment *segmentAt(QPoint&) const; //FIXME const reference for a library others can use
@@ -116,6 +118,7 @@ private:
Segment *m_rootSegment;
const bool m_isSummary;
const Segment *m_toBeDeleted;
+ QLabel m_tooltip;
};
}
diff --git a/src/part/radialMap/widgetEvents.cpp b/src/part/radialMap/widgetEvents.cpp
index f92184e..8161de5 100644
--- a/src/part/radialMap/widgetEvents.cpp
+++ b/src/part/radialMap/widgetEvents.cpp
@@ -144,18 +144,20 @@ void RadialMap::Widget::mouseMoveEvent(QMouseEvent *e)
if (m_focus)
{
+ m_tooltip.move(e->globalX() + 20, e->globalY() + 20);
if (m_focus != oldFocus) //if not same as last time
{
setCursor(Qt::PointingHandCursor);
+
QString string = m_focus->file()->fullPath(m_tree)
+ QLatin1Char('\n')
- + m_focus->file()->humanReadableSize()
- + QLatin1Char('\n');
+ + m_focus->file()->humanReadableSize();
if (m_focus->file()->isFolder()) {
int files = static_cast<const Folder*>(m_focus->file())->children();
const uint percent = uint((100 * files) / (double)m_tree->children());
+ string += QLatin1Char('\n');
string += i18np("File: %1", "Files: %1", files);
@@ -167,7 +169,21 @@ void RadialMap::Widget::mouseMoveEvent(QMouseEvent *e)
string += i18n("\nClick to go up to parent directory");
}
- QToolTip::showText(e->globalPos(), string, this);
+ // Calculate a semi-sane size for the tooltip
+ QFontMetrics fontMetrics(font());
+ int tooltipWidth = 0;
+ int tooltipHeight = 0;
+ for (const QString &part : string.split(QLatin1Char('\n'))) {
+ tooltipHeight += fontMetrics.height();
+ tooltipWidth = qMax(tooltipWidth, fontMetrics.width(part));
+ }
+ // Limit it to the window size, probably should find something better
+ tooltipWidth = qMin(tooltipWidth, window()->width());
+ tooltipWidth += 10;
+ tooltipHeight += 10;
+ m_tooltip.resize(tooltipWidth, tooltipHeight);
+ m_tooltip.setText(string);
+ m_tooltip.show();
emit mouseHover(m_focus->file()->fullPath());
update();
@@ -175,6 +191,7 @@ void RadialMap::Widget::mouseMoveEvent(QMouseEvent *e)
}
else if (oldFocus && oldFocus->file() != m_tree)
{
+ m_tooltip.hide();
unsetCursor();
update();
@@ -191,6 +208,11 @@ void RadialMap::Widget::enterEvent(QEvent *)
update();
}
+void RadialMap::Widget::leaveEvent(QEvent *)
+{
+ m_tooltip.hide();
+}
+
void RadialMap::Widget::mousePressEvent(QMouseEvent *e)
{
if (!isEnabled())