comparison src/progress.cpp @ 6:1d82f6e04d7d

Update: add first parts to the settings dialog
author Paper <mrpapersonic@gmail.com>
date Wed, 16 Aug 2023 00:49:17 -0400
parents
children
comparison
equal deleted inserted replaced
5:51ae25154b70 6:1d82f6e04d7d
1 #include "progress.h"
2
3 #include <QPainter>
4 #include <QPalette>
5 #include <QStyleOptionProgressBar>
6 #include <QStyleOptionViewItem>
7 #include <QProxyStyle>
8 #include <QMessageBox>
9
10 AnimeProgressBar::AnimeProgressBar() {
11 #if (defined(WIN32) || defined(MACOSX))
12 auto *fusionStyle = new QProxyStyle {"fusion"};
13 fusionStyle->setParent(&dummy_progress);
14 dummy_progress.setStyle(fusionStyle);
15 #endif
16 }
17
18 void AnimeProgressBar::paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, const int progress, const int episodes) const {
19 QStyleOptionProgressBar styleOption;
20 styleOption.initFrom(&dummy_progress);
21
22 styleOption.maximum = episodes;
23 styleOption.minimum = 0;
24 styleOption.progress = progress;
25 styleOption.text = text;
26 styleOption.textVisible = true;
27
28 styleOption.rect = option.rect;
29 styleOption.state = option.state;
30
31 const bool enabled = option.state.testFlag(QStyle::State_Enabled);
32 styleOption.palette.setCurrentColorGroup(enabled ? QPalette::Active : QPalette::Disabled);
33
34 painter->save();
35 const QStyle *style = dummy_progress.style();
36 style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, option.widget);
37 style->drawControl(QStyle::CE_ProgressBar, &styleOption, painter, &dummy_progress);
38 painter->restore();
39 }