comparison src/gui/pages/now_playing.cpp @ 64:fe719c109dbc

*: update 1. add media tracking ability, and it displays info on the `now playing` page 2. the `now playing` page now actually shows something 3. renamed every page class to be more accurate to what it is 4. ...
author Paper <mrpapersonic@gmail.com>
date Sun, 01 Oct 2023 23:15:43 -0400
parents d0adc4aedfc8
children 6481c5aed3e1
comparison
equal deleted inserted replaced
63:3d2decf093bb 64:fe719c109dbc
1 #include "gui/pages/now_playing.h" 1 #include "gui/pages/now_playing.h"
2 #include "core/anime_db.h"
3 #include "gui/widgets/anime_info.h"
4 #include "gui/widgets/text.h"
5 #include <QLabel>
6 #include <QStackedWidget>
7 #include <QVBoxLayout>
8 #include <QWidget>
2 9
3 NowPlayingWidget::NowPlayingWidget(QWidget* parent) : QWidget(parent) { 10 namespace NowPlayingPages {
11
12 class Default : public QWidget {
13 Q_OBJECT
14
15 public:
16 Default(QWidget* parent = nullptr);
17 };
18
19 class Playing : public QWidget {
20 Q_OBJECT
21
22 public:
23 Playing(QWidget* parent = nullptr);
24
25 void SetPlayingAnime(int id) {
26 if (info.get())
27 layout()->removeWidget(info.get());
28 info.reset(new AnimeInfoWidget(Anime::db.items[id]));
29 layout()->addWidget(info.get());
30 }
31
32 private:
33 std::unique_ptr<AnimeInfoWidget> info = nullptr;
34 };
35
36 Default::Default(QWidget* parent) : QWidget(parent) {
37 QVBoxLayout* layout = new QVBoxLayout(this);
38 layout->setContentsMargins(0, 0, 0, 0);
39
40 layout->addStretch();
41 }
42
43 Playing::Playing(QWidget* parent) : QWidget(parent) {
44 QVBoxLayout* layout = new QVBoxLayout(this);
45 layout->setContentsMargins(0, 0, 0, 0);
46 }
47
48 } // namespace NowPlayingPages
49
50 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) {
51 QVBoxLayout* layout = new QVBoxLayout(this);
52
53 setFrameShape(QFrame::Box);
54 setFrameShadow(QFrame::Sunken);
55
56 QPalette pal = QPalette();
57 pal.setColor(QPalette::Window, pal.color(QPalette::Base));
58 setPalette(pal);
59 setAutoFillBackground(true);
60
61 TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this);
62 layout->addWidget(title);
63
64 stack = new QStackedWidget(this);
65 stack->addWidget(new NowPlayingPages::Default(stack));
66 stack->addWidget(new NowPlayingPages::Playing(stack));
67 layout->addWidget(stack);
68
69 layout->addStretch();
70 SetDefault();
71 }
72
73 void NowPlayingPage::SetDefault() {
74 stack->setCurrentIndex(0);
75 }
76
77 void NowPlayingPage::SetPlaying(int id) {
78 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id);
79 stack->setCurrentIndex(1);
4 } 80 }
5 81
6 #include "gui/pages/moc_now_playing.cpp" 82 #include "gui/pages/moc_now_playing.cpp"
83 #include "now_playing.moc"