11#include <QLinearGradient>
14#include <QPainterPath>
24 : QWidget(parent), themeManager_(themeManager ? themeManager : &
ThemeManager::instance())
26 setFixedSize(width, height);
29 const auto& c = themeManager_->colors();
30 baseColor_ = c.inputBackground;
31 highlightColor_ = c.hoverBackground;
38 :
SkeletonWidget(size.width(), size.height(), parent, themeManager)
42void SkeletonWidget::initAnimation()
44 animation_ =
new QPropertyAnimation(
this,
"shimmerOffset",
this);
45 animation_->setDuration(1500);
46 animation_->setStartValue(0.0);
47 animation_->setEndValue(1.0);
48 animation_->setEasingCurve(QEasingCurve::InOutSine);
49 animation_->setLoopCount(-1);
54 if (animation_ && animation_->state() != QAbstractAnimation::Running)
70 QWidget::showEvent(event);
76 QWidget::hideEvent(event);
82 QPainter painter(
this);
83 painter.setRenderHint(QPainter::Antialiasing);
87 path.addRoundedRect(rect(), cornerRadius_, cornerRadius_);
88 painter.setClipPath(path);
91 painter.fillRect(rect(), baseColor_);
94 QLinearGradient gradient(0, 0, width(), 0);
97 qreal shimmerWidth = 0.3;
98 qreal shimmerStart = shimmerOffset_ - shimmerWidth;
99 qreal shimmerEnd = shimmerOffset_ + shimmerWidth;
101 gradient.setColorAt(qMax(0.0, shimmerStart), baseColor_);
102 gradient.setColorAt(qMax(0.0, shimmerOffset_ - shimmerWidth / 2), highlightColor_);
103 gradient.setColorAt(qMin(1.0, shimmerOffset_ + shimmerWidth / 2), highlightColor_);
104 gradient.setColorAt(qMin(1.0, shimmerEnd), baseColor_);
106 painter.fillRect(rect(), gradient);
114 : QWidget(parent), style_(style),
115 themeManager_(themeManager ? themeManager : &
ThemeManager::instance())
123 setupListItemStyle();
127void GameCardSkeleton::setupCardStyle()
129 auto* layout =
new QVBoxLayout(
this);
130 layout->setContentsMargins(0, 0, 0, 0);
131 layout->setSpacing(8);
134 auto* imageSkeleton =
new SkeletonWidget(150, 225,
this, themeManager_);
135 imageSkeleton->setCornerRadius(8);
136 layout->addWidget(imageSkeleton);
137 skeletons_.append(imageSkeleton);
140 auto* titleSkeleton =
new SkeletonWidget(130, 16,
this, themeManager_);
141 layout->addWidget(titleSkeleton);
142 skeletons_.append(titleSkeleton);
145 auto* subtitleSkeleton =
new SkeletonWidget(80, 12,
this, themeManager_);
146 layout->addWidget(subtitleSkeleton);
147 skeletons_.append(subtitleSkeleton);
149 setFixedSize(150, 280);
152void GameCardSkeleton::setupListItemStyle()
154 auto* layout =
new QHBoxLayout(
this);
155 layout->setContentsMargins(8, 8, 8, 8);
156 layout->setSpacing(12);
159 auto* imageSkeleton =
new SkeletonWidget(48, 48,
this, themeManager_);
160 imageSkeleton->setCornerRadius(4);
161 layout->addWidget(imageSkeleton);
162 skeletons_.append(imageSkeleton);
165 auto* textLayout =
new QVBoxLayout();
166 textLayout->setSpacing(4);
168 auto* titleSkeleton =
new SkeletonWidget(200, 16,
this, themeManager_);
169 textLayout->addWidget(titleSkeleton);
170 skeletons_.append(titleSkeleton);
172 auto* subtitleSkeleton =
new SkeletonWidget(120, 12,
this, themeManager_);
173 textLayout->addWidget(subtitleSkeleton);
174 skeletons_.append(subtitleSkeleton);
176 layout->addLayout(textLayout, 1);
183 for (
auto* skeleton : skeletons_)
185 skeleton->startAnimation();
191 for (
auto* skeleton : skeletons_)
193 skeleton->stopAnimation();
202 : QWidget(parent), themeManager_(themeManager ? themeManager : &
ThemeManager::instance())
204 setAttribute(Qt::WA_TransparentForMouseEvents,
false);
205 setAutoFillBackground(
false);
208 cancelButton_ =
new QPushButton(
"Cancel",
this);
209 cancelButton_->setVisible(
false);
210 cancelButton_->setCursor(Qt::PointingHandCursor);
214 spinnerAnimation_ =
new QPropertyAnimation(
this,
"spinnerAngle",
this);
215 spinnerAnimation_->setDuration(1000);
216 spinnerAnimation_->setStartValue(0);
217 spinnerAnimation_->setEndValue(360);
218 spinnerAnimation_->setLoopCount(-1);
221 const auto& c = themeManager_->colors();
222 cancelButton_->setStyleSheet(QString(
"QPushButton {"
223 " background-color: %1;"
225 " border: 1px solid %3;"
226 " border-radius: 4px;"
227 " padding: 8px 16px;"
228 " font-weight: bold;"
230 "QPushButton:hover {"
231 " background-color: %4;"
233 .arg(c.cardBackground.name(), c.textPrimary.name(),
234 c.border.name(), c.hoverBackground.name()));
247 cancellable_ = cancellable;
248 cancelButton_->setVisible(cancellable && isVisible());
254 progressCurrent_ = current;
255 progressTotal_ = total;
261 progressCurrent_ = -1;
266void LoadingOverlay::startSpinner()
268 if (spinnerAnimation_->state() != QAbstractAnimation::Running)
270 spinnerAnimation_->start();
274void LoadingOverlay::stopSpinner()
276 spinnerAnimation_->stop();
279void LoadingOverlay::updateGeometry()
283 resize(parentWidget()->size());
287 if (cancelButton_->isVisible())
289 int x = (width() - cancelButton_->width()) / 2;
290 int y = height() / 2 + 60;
291 cancelButton_->move(x, y);
297 QWidget::showEvent(event);
299 cancelButton_->setVisible(cancellable_);
306 QWidget::hideEvent(event);
312 QWidget::resizeEvent(event);
318 QPainter painter(
this);
319 painter.setRenderHint(QPainter::Antialiasing);
321 const auto& c = themeManager_->colors();
324 QColor overlayColor = c.windowBackground;
325 overlayColor.setAlpha(200);
326 painter.fillRect(rect(), overlayColor);
329 int spinnerSize = 48;
330 int centerX = width() / 2;
331 int centerY = height() / 2;
334 painter.translate(centerX, centerY);
335 painter.rotate(spinnerAngle_);
337 QPen spinnerPen(c.accent, 4, Qt::SolidLine, Qt::RoundCap);
338 painter.setPen(spinnerPen);
341 QRectF spinnerRect(-spinnerSize / 2.0, -spinnerSize / 2.0, spinnerSize, spinnerSize);
342 painter.drawArc(spinnerRect, 0, 270 * 16);
347 if (!message_.isEmpty())
349 QFont font = painter.font();
350 font.setPointSize(12);
351 painter.setFont(font);
352 painter.setPen(c.textPrimary);
354 QRect textRect(0, centerY + spinnerSize / 2 + 16, width(), 30);
355 painter.drawText(textRect, Qt::AlignHCenter | Qt::AlignTop, message_);
359 if (progressCurrent_ >= 0 && progressTotal_ > 0)
361 QString progressText = QString(
"%1 / %2").arg(progressCurrent_).arg(progressTotal_);
362 QFont font = painter.font();
363 font.setPointSize(10);
364 painter.setFont(font);
365 painter.setPen(c.textSecondary);
367 QRect progressRect(0, centerY + spinnerSize / 2 + 44, width(), 20);
368 painter.drawText(progressRect, Qt::AlignHCenter | Qt::AlignTop, progressText);
377 : QWidget(parent), themeManager_(themeManager ? themeManager : &
ThemeManager::instance())
379 auto* layout =
new QVBoxLayout(
this);
380 layout->setAlignment(Qt::AlignCenter);
381 layout->setSpacing(16);
384 iconLabel_ =
new QLabel(
this);
385 iconLabel_->setAlignment(Qt::AlignCenter);
386 QFont iconFont = iconLabel_->font();
387 iconFont.setPointSize(48);
388 iconLabel_->setFont(iconFont);
389 layout->addWidget(iconLabel_);
392 titleLabel_ =
new QLabel(
this);
393 titleLabel_->setAlignment(Qt::AlignCenter);
394 titleLabel_->setWordWrap(
true);
395 QFont titleFont = titleLabel_->font();
396 titleFont.setPointSize(16);
397 titleFont.setBold(
true);
398 titleLabel_->setFont(titleFont);
399 layout->addWidget(titleLabel_);
402 descriptionLabel_ =
new QLabel(
this);
403 descriptionLabel_->setAlignment(Qt::AlignCenter);
404 descriptionLabel_->setWordWrap(
true);
405 QFont descFont = descriptionLabel_->font();
406 descFont.setPointSize(11);
407 descriptionLabel_->setFont(descFont);
408 layout->addWidget(descriptionLabel_);
411 actionsContainer_ =
new QWidget(
this);
412 actionsLayout_ =
new QHBoxLayout(actionsContainer_);
413 actionsLayout_->setAlignment(Qt::AlignCenter);
414 actionsLayout_->setSpacing(12);
415 layout->addWidget(actionsContainer_);
417 layout->addStretch();
424 iconLabel_->setText(iconText);
429 titleLabel_->setText(title);
434 descriptionLabel_->setText(description);
439 auto* button =
new QPushButton(label, actionsContainer_);
440 button->setCursor(Qt::PointingHandCursor);
442 const auto& c = themeManager_->colors();
443 button->setStyleSheet(QString(
"QPushButton {"
444 " background-color: %1;"
447 " border-radius: 6px;"
448 " padding: 10px 20px;"
449 " font-weight: bold;"
451 "QPushButton:hover {"
452 " background-color: %3;"
454 .arg(c.accent.name(), c.textOnAccent.name(), c.accentHover.name()));
456 connect(button, &QPushButton::clicked,
this,
463 actionsLayout_->addWidget(button);
468 while (QLayoutItem* item = actionsLayout_->takeAt(0))
470 if (QWidget* widget = item->widget())
480 const auto& c = themeManager_->colors();
485 auto setLabelColor = [](QLabel* label,
const QColor& color)
487 QPalette p = label->palette();
488 p.setColor(QPalette::WindowText, color);
489 label->setPalette(p);
491 setLabelColor(titleLabel_, c.textPrimary);
492 setLabelColor(descriptionLabel_, c.textSecondary);
497 QWidget::showEvent(event);
506 : QWidget(parent), themeManager_(themeManager ? themeManager : &
ThemeManager::instance())
508 setFixedSize(size, size);
510 const auto& c = themeManager_->colors();
514 animation_ =
new QSequentialAnimationGroup(
this);
516 auto* fadeOut =
new QPropertyAnimation(
this,
"opacity",
this);
517 fadeOut->setDuration(600);
518 fadeOut->setStartValue(1.0);
519 fadeOut->setEndValue(0.3);
520 fadeOut->setEasingCurve(QEasingCurve::InOutSine);
522 auto* fadeIn =
new QPropertyAnimation(
this,
"opacity",
this);
523 fadeIn->setDuration(600);
524 fadeIn->setStartValue(0.3);
525 fadeIn->setEndValue(1.0);
526 fadeIn->setEasingCurve(QEasingCurve::InOutSine);
528 animation_->addAnimation(fadeOut);
529 animation_->addAnimation(fadeIn);
530 animation_->setLoopCount(-1);
535 if (animation_->state() != QAbstractAnimation::Running)
548 QWidget::showEvent(event);
554 QWidget::hideEvent(event);
560 QPainter painter(
this);
561 painter.setRenderHint(QPainter::Antialiasing);
563 QColor dotColor = color_;
564 dotColor.setAlphaF(
static_cast<float>(opacity_));
566 painter.setBrush(dotColor);
567 painter.setPen(Qt::NoPen);
568 painter.drawEllipse(rect());
GameCardSkeleton(Style style=Style::Card, QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
void hideEvent(QHideEvent *event) override
void setProgress(int current, int total)
void setCancellable(bool cancellable)
void resizeEvent(QResizeEvent *event) override
void paintEvent(QPaintEvent *event) override
void setMessage(const QString &message)
LoadingOverlay(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
void showEvent(QShowEvent *event) override
PulsingDot(int size=8, QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
void hideEvent(QHideEvent *event) override
void showEvent(QShowEvent *event) override
void paintEvent(QPaintEvent *event) override