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.
parent 63b31e2c
......@@ -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()
......
......@@ -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;
};
}
......
......@@ -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())
......
Markdown is supported
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