Files
dota_factory/src/ui/Tooltip.h
Malte Langkabel 099d614395 show a tooltip on click, and keep it up until the pointer leaves
One tooltip mechanism for the whole UI: a Tooltip popup plus a
TooltipTrigger event filter, replacing every setToolTip call. Qt's own
tooltip cannot do what REQ-UI-TOOLTIP-TRIGGER and REQ-UI-TOOLTIP-DISMISS
ask for -- it times out, hides on the first mouse move, cannot be hovered
and cannot be brought up by a click.

A tooltip now appears the moment an element with no click action of its
own is clicked, and it is placed with its top-left corner on the pointer,
so the pointer can move onto the tooltip and hold it open. The pointer is
polled while a tooltip is up rather than tracked through enter and leave
events, whose order depends on which widget the pointer crosses first.

The item chip's children become transparent to the mouse. They were
taking the chip's enter and leave events, so its tooltip only ever
appeared when the pointer rested on the chip's padding.

The modal header's close button loses its "Close" tooltip: a close button
in a header says that by being one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ne3mejABZoLWKLh8fgpM3x
2026-08-18 14:52:02 +02:00

52 lines
1.7 KiB
C++

#pragma once
#include <QFrame>
#include <QPoint>
#include <QString>
class QHideEvent;
class QVBoxLayout;
// The popup every tooltip in the UI is drawn in (REQ-UI-TOOLTIP-TRIGGER,
// REQ-UI-TOOLTIP-DISMISS). Shown and hidden by a TooltipTrigger attached to the element
// it describes; it carries no trigger logic of its own.
//
// A window of its own rather than Qt's own tooltip, because ours must not time out, must
// stay up while the pointer is on it, and -- for the item production tooltip
// (REQ-UI-ITEM-TOOLTIP) -- must hold drawn content rather than text. A Qt::ToolTip window
// so it floats above the game window instead of being clipped by it.
class Tooltip : public QFrame
{
Q_OBJECT
public:
// The tooltip currently on screen, if any: only ever one, since the pointer can only
// be on one element.
static Tooltip* getVisibleTooltip();
static void hideVisibleTooltip();
explicit Tooltip(QWidget* parent = nullptr);
~Tooltip() override;
// Plain text content, wrapped at a readable measure. Newlines are kept.
void setText(const QString& text);
// Refreshes the content and shows the tooltip with its top-left corner on the given
// screen position, kept inside the screen (REQ-UI-TOOLTIP-DISMISS).
void showAt(const QPoint& globalPos);
bool getContainsGlobalPos(const QPoint& globalPos) const;
protected:
// Called before every show, for content that goes stale between them. The base
// tooltip's text does not, so this does nothing here.
virtual void refreshContent();
QVBoxLayout* getContentLayout();
void clearContent();
void hideEvent(QHideEvent* event) override;
private:
static Tooltip* s_visibleTooltip;
QVBoxLayout* m_layout;
};