show recipes visually instead of describing them in text
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
#include "ItemChip.h"
|
||||
|
||||
#include <QCursor>
|
||||
#include <QFont>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QPalette>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "ItemTooltip.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -13,11 +17,18 @@ namespace
|
||||
const int kCountSizeRisePt = 2;
|
||||
const int kSubLineSizeDropPt = 1;
|
||||
|
||||
// How long the cursor rests on a chip before its tooltip appears, in milliseconds.
|
||||
// Matches the feel of an ordinary tooltip, which this one replaces (REQ-UI-ITEM-TOOLTIP).
|
||||
const int kHoverDelayMs = 500;
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
ItemChip::ItemChip(const QPixmap& icon, QWidget* parent)
|
||||
ItemChip::ItemChip(const SelectionContext& context, const std::string& itemId,
|
||||
const QPixmap& icon, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_context(context)
|
||||
, m_itemId(itemId)
|
||||
{
|
||||
// Its own boxed chrome, drawn with palette colors like the rest of the panel's
|
||||
// furniture rather than from visuals.toml, which is for world rendering.
|
||||
@@ -58,6 +69,11 @@ ItemChip::ItemChip(const QPixmap& icon, QWidget* parent)
|
||||
|
||||
layout->addWidget(m_iconLabel);
|
||||
layout->addWidget(text);
|
||||
|
||||
m_hoverTimer = new QTimer(this);
|
||||
m_hoverTimer->setSingleShot(true);
|
||||
m_hoverTimer->setInterval(kHoverDelayMs);
|
||||
connect(m_hoverTimer, &QTimer::timeout, this, &ItemChip::showTooltip);
|
||||
}
|
||||
|
||||
void ItemChip::setCount(const QString& count)
|
||||
@@ -70,3 +86,28 @@ void ItemChip::setSubLine(const QString& subLine)
|
||||
m_subLineLabel->setText(subLine);
|
||||
m_subLineLabel->setVisible(!subLine.isEmpty());
|
||||
}
|
||||
|
||||
void ItemChip::enterEvent(QEvent* event)
|
||||
{
|
||||
m_hoverTimer->start();
|
||||
QWidget::enterEvent(event);
|
||||
}
|
||||
|
||||
void ItemChip::leaveEvent(QEvent* event)
|
||||
{
|
||||
m_hoverTimer->stop();
|
||||
if (m_tooltip != nullptr)
|
||||
{
|
||||
m_tooltip->hide();
|
||||
}
|
||||
QWidget::leaveEvent(event);
|
||||
}
|
||||
|
||||
void ItemChip::showTooltip()
|
||||
{
|
||||
if (m_tooltip == nullptr)
|
||||
{
|
||||
m_tooltip = new ItemTooltip(m_context, m_itemId, this);
|
||||
}
|
||||
m_tooltip->showAt(QCursor::pos());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user