#pragma once #include #include #include 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; };