Mercurial > minori
annotate src/gui/pages/now_playing.cpp @ 79:c489dd4434af
*: what did I do again?
I really forgot what I did here :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 12 Oct 2023 11:31:39 -0400 |
parents | 27a19dd6cba1 |
children | 825506f0e221 |
rev | line source |
---|---|
9 | 1 #include "gui/pages/now_playing.h" |
64 | 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> | |
9 | |
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); | |
79 | 24 void SetPlayingAnime(int id, int episode); |
69 | 25 int GetPlayingAnime(); |
64 | 26 |
27 private: | |
69 | 28 int _id = 0; |
79 | 29 int _episode = 0; |
64 | 30 std::unique_ptr<AnimeInfoWidget> info = nullptr; |
31 }; | |
32 | |
33 Default::Default(QWidget* parent) : QWidget(parent) { | |
34 QVBoxLayout* layout = new QVBoxLayout(this); | |
35 layout->setContentsMargins(0, 0, 0, 0); | |
2 | 36 |
64 | 37 layout->addStretch(); |
38 } | |
39 | |
40 Playing::Playing(QWidget* parent) : QWidget(parent) { | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
41 QHBoxLayout* layout = new QHBoxLayout(this); |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
42 |
64 | 43 layout->setContentsMargins(0, 0, 0, 0); |
44 } | |
45 | |
69 | 46 int Playing::GetPlayingAnime() { |
47 return _id; | |
48 } | |
49 | |
79 | 50 void Playing::SetPlayingAnime(int id, int episodes) { |
51 if (id == _id) | |
52 return; | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
53 if (info.get()) |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
54 layout()->removeWidget(info.get()); |
69 | 55 if (Anime::db.items.find(id) != Anime::db.items.end()) { |
56 info.reset(new AnimeInfoWidget(Anime::db.items[_id = id])); | |
57 layout()->addWidget(info.get()); | |
58 } | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
59 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
60 |
64 | 61 } // namespace NowPlayingPages |
62 | |
63 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) { | |
64 QVBoxLayout* layout = new QVBoxLayout(this); | |
65 | |
66 setFrameShape(QFrame::Box); | |
67 setFrameShadow(QFrame::Sunken); | |
68 | |
69 QPalette pal = QPalette(); | |
70 pal.setColor(QPalette::Window, pal.color(QPalette::Base)); | |
71 setPalette(pal); | |
72 setAutoFillBackground(true); | |
73 | |
74 TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this); | |
75 layout->addWidget(title); | |
76 | |
77 stack = new QStackedWidget(this); | |
78 stack->addWidget(new NowPlayingPages::Default(stack)); | |
79 stack->addWidget(new NowPlayingPages::Playing(stack)); | |
80 layout->addWidget(stack); | |
81 | |
82 SetDefault(); | |
83 } | |
84 | |
85 void NowPlayingPage::SetDefault() { | |
86 stack->setCurrentIndex(0); | |
87 } | |
88 | |
69 | 89 int NowPlayingPage::GetPlayingId() { |
90 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime(); | |
91 } | |
92 | |
79 | 93 void NowPlayingPage::SetPlaying(int id, int episodes) { |
94 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id, episodes); | |
64 | 95 stack->setCurrentIndex(1); |
2 | 96 } |
7 | 97 |
46 | 98 #include "gui/pages/moc_now_playing.cpp" |
64 | 99 #include "now_playing.moc" |