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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
1 #include "gui/pages/now_playing.h"
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
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
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
4 #include "gui/widgets/anime_info.h"
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
5 #include "gui/widgets/text.h"
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
6 #include <QLabel>
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
7 #include <QStackedWidget>
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
8 #include <QVBoxLayout>
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
9 #include <QWidget>
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
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
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
16 namespace NowPlayingPages {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
17
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
18 class Default : public QWidget {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
19 Q_OBJECT
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
20
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
21 public:
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
22 Default(QWidget* parent = nullptr);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
23 };
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
24
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
25 class Playing : public QWidget {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
26 Q_OBJECT
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
27
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
28 public:
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
29 Playing(QWidget* parent = nullptr);
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
30 void SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info);
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
31 int GetPlayingAnime();
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
32
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
33 private:
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
34 int _id = 0;
79
c489dd4434af *: what did I do again?
Paper <mrpapersonic@gmail.com>
parents: 69
diff changeset
35 int _episode = 0;
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
36 std::unique_ptr<TextWidgets::Title> _title = nullptr;
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
37 std::unique_ptr<AnimeInfoWidget> _info = nullptr;
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
38 };
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
39
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
40 Default::Default(QWidget* parent) : QWidget(parent) {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
41 QVBoxLayout* layout = new QVBoxLayout(this);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
42 layout->setContentsMargins(0, 0, 0, 0);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
43
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
44 TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this);
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
45 layout->addWidget(title);
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
46
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
47 layout->addStretch();
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
48 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
49
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
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
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
53 _title.reset(new TextWidgets::Title("\n", this));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
54 layout->addWidget(_title.get());
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
55
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
56 _info.reset(new AnimeInfoWidget(this));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
57 layout->addWidget(_info.get());
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
58
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
59 layout->setContentsMargins(0, 0, 0, 0);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
60 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
61
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
62 int Playing::GetPlayingAnime() {
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
63 return _id;
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
64 }
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
65
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
66 void Playing::SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info) {
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
67 if (id == _id || id <= 0)
79
c489dd4434af *: what did I do again?
Paper <mrpapersonic@gmail.com>
parents: 69
diff changeset
68 return;
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
69 if (Anime::db.items.find(id) != Anime::db.items.end()) {
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
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
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
72 _info->SetAnime(anime);
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
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
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
76 } // namespace NowPlayingPages
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
77
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
78 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
79 QVBoxLayout* layout = new QVBoxLayout(this);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
80
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
81 setFrameShape(QFrame::Box);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
82 setFrameShadow(QFrame::Sunken);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
83
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
84 QPalette pal = QPalette();
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
85 pal.setColor(QPalette::Window, pal.color(QPalette::Base));
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
86 setPalette(pal);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
87 setAutoFillBackground(true);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
88
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
89 stack = new QStackedWidget(this);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
90 stack->addWidget(new NowPlayingPages::Default(stack));
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
91 stack->addWidget(new NowPlayingPages::Playing(stack));
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
92 layout->addWidget(stack);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
93
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
94 SetDefault();
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
95 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
96
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
97 void NowPlayingPage::SetDefault() {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
98 stack->setCurrentIndex(0);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
99 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
100
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
101 int NowPlayingPage::GetPlayingId() {
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
102 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime();
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
103 }
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
104
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
105 void NowPlayingPage::SetPlaying(int id, const std::unordered_map<std::string, std::string>& info) {
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
106 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id, info);
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
107 stack->setCurrentIndex(1);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
108 }
7
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
109
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
110 #include "gui/pages/moc_now_playing.cpp"
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
111 #include "now_playing.moc"