#include "seektimebubble.h" #include #include #include #include "../utils/fadehelper.h" SeekTimeBubble::SeekTimeBubble(QWidget *parent) : QWidget(parent) { setAttribute(Qt::WA_TransparentForMouseEvents); setVisible(false); auto *layout = new QVBoxLayout(this); layout->setContentsMargins(10, 4, 10, 4); layout->setSpacing(4); m_thumbSlot = new QLabel(this); m_thumbSlot->setObjectName("seekBubbleThumb"); m_thumbSlot->setVisible(false); layout->addWidget(m_thumbSlot, 0, Qt::AlignHCenter); m_timeLabel = new QLabel(this); m_timeLabel->setObjectName("seekBubbleTime"); m_timeLabel->setAlignment(Qt::AlignCenter); layout->addWidget(m_timeLabel, 0, Qt::AlignHCenter); } void SeekTimeBubble::setTimeText(const QString &text) { if (m_timeLabel->text() == text) { return; } m_timeLabel->setText(text); adjustSize(); } void SeekTimeBubble::showAt(const QPoint &anchor) { adjustSize(); QPoint topLeft(anchor.x() - width() / 2, anchor.y() - height()); if (parentWidget()) { const int maxX = parentWidget()->width() - width(); topLeft.setX(qBound(0, topLeft.x(), qMax(0, maxX))); topLeft.setY(qMax(0, topLeft.y())); } move(topLeft); if (!m_shown) { m_shown = true; raise(); FadeHelper::fadeIn(this, AnimationTokens::DurationMs::kQuick); } } void SeekTimeBubble::hideBubble() { if (!m_shown) { return; } m_shown = false; FadeHelper::fadeOut(this, AnimationTokens::DurationMs::kMicro, AnimationTokens::Curve::exit(), [this]() { hide(); }); } void SeekTimeBubble::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.setPen(QPen(QColor(148, 163, 184, 60), 1)); painter.setBrush(QColor(15, 23, 42, 235)); painter.drawRoundedRect(QRectF(rect()).adjusted(0.5, 0.5, -0.5, -0.5), 6, 6); }