Mercurial > minori
annotate src/gui/pages/now_playing.cc @ 82:8b65c417c225
*: fix old stuff, make video players and extensions constants
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 23 Oct 2023 13:37:42 -0400 |
parents | 9b2b41f83a5e |
children | d02fdf1d6708 |
rev | line source |
---|---|
9 | 1 #include "gui/pages/now_playing.h" |
64 | 2 #include "core/anime_db.h" |
82
8b65c417c225
*: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
3 #include "core/strings.h" |
64 | 4 #include "gui/widgets/anime_info.h" |
5 #include "gui/widgets/text.h" | |
6 #include <QLabel> | |
7 #include <QStackedWidget> | |
8 #include <QVBoxLayout> | |
9 #include <QWidget> | |
10 | |
82
8b65c417c225
*: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
11 /* WARNING: HACKY STUFF HERE |
8b65c417c225
*: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
12 |
8b65c417c225
*: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
13 The Now Playing page is designed to "switch" between these two sub-pages, |
8b65c417c225
*: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
14 using a QStackedWidget. This *could* be the best way to do this, but this |
8b65c417c225
*: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
15 feels very very stupid and I really don't like it */ |
64 | 16 namespace NowPlayingPages { |
17 | |
18 class Default : public QWidget { | |
19 Q_OBJECT | |
20 | |
21 public: | |
22 Default(QWidget* parent = nullptr); | |
23 }; | |
24 | |
25 class Playing : public QWidget { | |
26 Q_OBJECT | |
27 | |
28 public: | |
29 Playing(QWidget* parent = nullptr); | |
80 | 30 void SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info); |
69 | 31 int GetPlayingAnime(); |
64 | 32 |
33 private: | |
69 | 34 int _id = 0; |
79 | 35 int _episode = 0; |
80 | 36 std::unique_ptr<TextWidgets::Title> _title = nullptr; |
37 std::unique_ptr<AnimeInfoWidget> _info = nullptr; | |
64 | 38 }; |
39 | |
40 Default::Default(QWidget* parent) : QWidget(parent) { | |
41 QVBoxLayout* layout = new QVBoxLayout(this); | |
42 layout->setContentsMargins(0, 0, 0, 0); | |
2 | 43 |
80 | 44 TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this); |
45 layout->addWidget(title); | |
46 | |
64 | 47 layout->addStretch(); |
48 } | |
49 | |
50 Playing::Playing(QWidget* parent) : QWidget(parent) { | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
51 QHBoxLayout* layout = new QHBoxLayout(this); |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
52 |
80 | 53 _title.reset(new TextWidgets::Title("\n", this)); |
54 layout->addWidget(_title.get()); | |
55 | |
56 _info.reset(new AnimeInfoWidget(this)); | |
57 layout->addWidget(_info.get()); | |
58 | |
64 | 59 layout->setContentsMargins(0, 0, 0, 0); |
60 } | |
61 | |
69 | 62 int Playing::GetPlayingAnime() { |
63 return _id; | |
64 } | |
65 | |
80 | 66 void Playing::SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info) { |
67 if (id == _id || id <= 0) | |
79 | 68 return; |
69 | 69 if (Anime::db.items.find(id) != Anime::db.items.end()) { |
80 | 70 const Anime::Anime& anime = Anime::db.items[_id = id]; |
82
8b65c417c225
*: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
71 _title->setText(Strings::ToQString(anime.GetUserPreferredTitle())); |
80 | 72 _info->SetAnime(anime); |
69 | 73 } |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
74 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
75 |
64 | 76 } // namespace NowPlayingPages |
77 | |
78 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) { | |
79 QVBoxLayout* layout = new QVBoxLayout(this); | |
80 | |
81 setFrameShape(QFrame::Box); | |
82 setFrameShadow(QFrame::Sunken); | |
83 | |
84 QPalette pal = QPalette(); | |
85 pal.setColor(QPalette::Window, pal.color(QPalette::Base)); | |
86 setPalette(pal); | |
87 setAutoFillBackground(true); | |
88 | |
89 stack = new QStackedWidget(this); | |
90 stack->addWidget(new NowPlayingPages::Default(stack)); | |
91 stack->addWidget(new NowPlayingPages::Playing(stack)); | |
92 layout->addWidget(stack); | |
93 | |
94 SetDefault(); | |
95 } | |
96 | |
97 void NowPlayingPage::SetDefault() { | |
98 stack->setCurrentIndex(0); | |
99 } | |
100 | |
69 | 101 int NowPlayingPage::GetPlayingId() { |
102 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime(); | |
103 } | |
104 | |
80 | 105 void NowPlayingPage::SetPlaying(int id, const std::unordered_map<std::string, std::string>& info) { |
106 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id, info); | |
64 | 107 stack->setCurrentIndex(1); |
2 | 108 } |
7 | 109 |
46 | 110 #include "gui/pages/moc_now_playing.cpp" |
64 | 111 #include "now_playing.moc" |