Commit efaa5c52 authored by Martin Flöser's avatar Martin Flöser
Browse files

[tools] Simulate a panel tooltip

On entered on the panel window we show a tooltip at the entered
position and make it follow the mouse.
parent 239e702f
......@@ -58,6 +58,9 @@ public:
private:
void setupRegistry(Registry *registry);
void render();
void showTooltip(const QPointF &pos);
void hideTooltip();
void moveTooltip(const QPointF &pos);
QThread *m_connectionThread;
ConnectionThread *m_connectionThreadObject;
EventQueue *m_eventQueue = nullptr;
......@@ -70,6 +73,12 @@ private:
PlasmaShell *m_plasmaShell = nullptr;
PlasmaShellSurface *m_plasmaShellSurface = nullptr;
PlasmaWindowManagement *m_windowManagement = nullptr;
struct {
Surface *surface = nullptr;
ShellSurface *shellSurface = nullptr;
PlasmaShellSurface *plasmaSurface = nullptr;
bool visible = false;
} m_tooltip;
};
PanelTest::PanelTest(QObject *parent)
......@@ -104,6 +113,48 @@ void PanelTest::init()
m_connectionThreadObject->initConnection();
}
void PanelTest::showTooltip(const QPointF &pos)
{
if (!m_tooltip.surface) {
m_tooltip.surface = m_compositor->createSurface(this);
m_tooltip.shellSurface = m_shell->createSurface(m_tooltip.surface, this);
if (m_plasmaShell) {
m_tooltip.plasmaSurface = m_plasmaShell->createSurface(m_tooltip.surface, this);
}
}
m_tooltip.shellSurface->setTransient(m_surface, pos.toPoint());
if (!m_tooltip.visible) {
const QSize size(100, 50);
auto buffer = m_shm->getBuffer(size, size.width() * 4).toStrongRef();
buffer->setUsed(true);
QImage image(buffer->address(), size.width(), size.height(), QImage::Format_ARGB32_Premultiplied);
image.fill(Qt::red);
m_tooltip.surface->attachBuffer(*buffer);
m_tooltip.surface->damage(QRect(QPoint(0, 0), size));
m_tooltip.surface->commit(Surface::CommitFlag::None);
m_tooltip.visible = true;
}
}
void PanelTest::hideTooltip()
{
if (!m_tooltip.visible) {
return;
}
m_tooltip.surface->attachBuffer(Buffer::Ptr());
m_tooltip.surface->commit(Surface::CommitFlag::None);
m_tooltip.visible = false;
}
void PanelTest::moveTooltip(const QPointF &pos)
{
if (m_tooltip.plasmaSurface) {
m_tooltip.plasmaSurface->setPosition(QPoint(10, 0) + pos.toPoint());
}
}
void PanelTest::setupRegistry(Registry *registry)
{
connect(registry, &Registry::compositorAnnounced, this,
......@@ -147,6 +198,26 @@ void PanelTest::setupRegistry(Registry *registry)
}
}
);
connect(p, &Pointer::entered, this,
[this, p] (quint32 serial, const QPointF &relativeToSurface) {
Q_UNUSED(serial)
if (p->enteredSurface() == m_surface) {
showTooltip(relativeToSurface);
}
}
);
connect(p, &Pointer::motion, this,
[this, p] (const QPointF &relativeToSurface) {
if (p->enteredSurface() == m_surface) {
moveTooltip(relativeToSurface);
}
}
);
connect(p, &Pointer::left, this,
[this] {
hideTooltip();
}
);
}
);
}
......
Supports Markdown
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