| 11 | namespace QodeAssist { |
| 12 | |
| 13 | ErrorWidget::ErrorWidget(const QString &errorMessage, QWidget *parent, int autoHideMs) |
| 14 | : QWidget(parent) |
| 15 | , m_errorMessage(errorMessage) |
| 16 | , m_autoHideTimer(nullptr) |
| 17 | , m_isHovered(false) |
| 18 | { |
| 19 | setupColors(); |
| 20 | setupIcon(); |
| 21 | |
| 22 | QFont errorFont = font(); |
| 23 | errorFont.setPointSize(qMax(8, errorFont.pointSize() - 2)); |
| 24 | setFont(errorFont); |
| 25 | |
| 26 | setFixedSize(calculateSize()); |
| 27 | setAttribute(Qt::WA_TranslucentBackground); |
| 28 | setMouseTracking(true); |
| 29 | |
| 30 | if (autoHideMs > 0) { |
| 31 | m_autoHideTimer = new QTimer(this); |
| 32 | m_autoHideTimer->setSingleShot(true); |
| 33 | connect(m_autoHideTimer, &QTimer::timeout, this, [this]() { |
| 34 | if (!m_isHovered) { |
| 35 | emit dismissed(); |
| 36 | deleteLater(); |
| 37 | } |
| 38 | }); |
| 39 | m_autoHideTimer->start(autoHideMs); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | ErrorWidget::~ErrorWidget() |
| 44 | { |