annotate src/gui/pages/now_playing.cc @ 83:d02fdf1d6708

*: huuuge update 1. make the now playing page function correctly 2. de-constructorfy many of our custom widgets, allowing them to be changed on-the-fly from the Now Playing page 3. ... :)
author Paper <mrpapersonic@gmail.com>
date Tue, 24 Oct 2023 22:01:02 -0400
parents 8b65c417c225
children 2c27582a177c
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"
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
6 #include "gui/widgets/poster.h"
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
7 #include <QLabel>
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
8 #include <QStackedWidget>
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
9 #include <QHBoxLayout>
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
10 #include <QVBoxLayout>
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
11 #include <QWidget>
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
12
82
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
13 /* WARNING: HACKY STUFF HERE
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
14
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
15 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
16 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
17 feels very very stupid and I really don't like it */
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
18 namespace NowPlayingPages {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
19
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
20 class Default : public QWidget {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
21 Q_OBJECT
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
22
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
23 public:
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
24 Default(QWidget* parent = nullptr);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
25 };
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
26
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
27 class Playing : public QWidget {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
28 Q_OBJECT
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
29
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
30 public:
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
31 Playing(QWidget* parent = nullptr);
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
32 void SetPlayingAnime(const Anime::Anime& anime, const std::unordered_map<std::string, std::string>& info);
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
33 int GetPlayingAnime();
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
34
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
35 private:
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
36 int _id = 0;
79
c489dd4434af *: what did I do again?
Paper <mrpapersonic@gmail.com>
parents: 69
diff changeset
37 int _episode = 0;
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
38 std::unique_ptr<QWidget> _main = nullptr;
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
39 std::unique_ptr<TextWidgets::Title> _title = nullptr;
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
40 std::unique_ptr<AnimeInfoWidget> _info = nullptr;
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
41 std::unique_ptr<QWidget> _sidebar = nullptr;
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
42 std::unique_ptr<Poster> _poster = nullptr;
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
43 };
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
44
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
45 Default::Default(QWidget* parent) : QWidget(parent) {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
46 QVBoxLayout* layout = new QVBoxLayout(this);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
47 layout->setContentsMargins(0, 0, 0, 0);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
48
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
49 TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this);
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
50 layout->addWidget(title);
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
51
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
52 layout->addStretch();
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
53 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
54
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
55 Playing::Playing(QWidget* parent) : QWidget(parent) {
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents: 64
diff changeset
56 QHBoxLayout* layout = new QHBoxLayout(this);
68
2417121d894e *: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents: 66
diff changeset
57
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
58 _main.reset(new QWidget(this));
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
59 _main->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
60
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
61 QVBoxLayout* main_layout = new QVBoxLayout(_main.get());
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
62 main_layout->setContentsMargins(0, 0, 0, 0);
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
63
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
64 _title.reset(new TextWidgets::Title("", _main.get()));
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
65 main_layout->addWidget(_title.get());
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
66
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
67 _info.reset(new AnimeInfoWidget(_main.get()));
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
68 _info->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
69 main_layout->addWidget(_info.get());
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
70
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
71 /* "sidebar", includes... just the anime image :) */
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
72 _sidebar.reset(new QWidget(this));
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
73 QVBoxLayout* sidebar_layout = new QVBoxLayout(_sidebar.get());
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
74 sidebar_layout->setContentsMargins(0, 0, 0, 0);
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 79
diff changeset
75
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
76 _poster.reset(new Poster(_sidebar.get()));
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
77 sidebar_layout->addWidget(_poster.get());
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
78
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
79 sidebar_layout->addStretch();
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
80
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
81 layout->addWidget(_sidebar.get());
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
82 layout->addWidget(_main.get());
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
83 layout->setSpacing(10);
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
84 layout->setContentsMargins(0, 0, 0, 0);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
85 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
86
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
87 int Playing::GetPlayingAnime() {
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
88 return _id;
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
89 }
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
90
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
91 void Playing::SetPlayingAnime(const Anime::Anime& anime, const std::unordered_map<std::string, std::string>& info) {
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
92 if (_id == anime.GetId() && std::to_string(_episode) == info.at("episode"))
79
c489dd4434af *: what did I do again?
Paper <mrpapersonic@gmail.com>
parents: 69
diff changeset
93 return;
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
94 _id = anime.GetId();
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
95 try {
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
96 _episode = std::stoi(info.at("episode"));
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
97 } catch (std::invalid_argument) {
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
98 _episode = 0;
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
99 }
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
100 _title->SetText(Strings::ToQString(anime.GetUserPreferredTitle()));
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
101 _info->SetAnime(anime);
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
102 _poster->SetAnime(anime);
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
103
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
104 updateGeometry();
66
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents: 64
diff changeset
105 }
6481c5aed3e1 posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents: 64
diff changeset
106
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
107 } // namespace NowPlayingPages
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
108
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
109 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
110 QVBoxLayout* layout = new QVBoxLayout(this);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
111
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
112 setFrameShape(QFrame::Box);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
113 setFrameShadow(QFrame::Sunken);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
114
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
115 QPalette pal = QPalette();
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
116 pal.setColor(QPalette::Window, pal.color(QPalette::Base));
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
117 setPalette(pal);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
118 setAutoFillBackground(true);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
119
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
120 stack = new QStackedWidget(this);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
121 stack->addWidget(new NowPlayingPages::Default(stack));
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
122 stack->addWidget(new NowPlayingPages::Playing(stack));
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
123 layout->addWidget(stack);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
124
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
125 SetDefault();
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
126 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
127
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
128 void NowPlayingPage::SetDefault() {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
129 stack->setCurrentIndex(0);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
130 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
131
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
132 int NowPlayingPage::GetPlayingId() {
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
133 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime();
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
134 }
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 68
diff changeset
135
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
136 void NowPlayingPage::SetPlaying(const Anime::Anime& anime, const std::unordered_map<std::string, std::string>& info) {
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
137 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(anime, info);
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
138 stack->setCurrentIndex(1);
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
139 updateGeometry();
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
140 }
7
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
141
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
142 #include "gui/pages/moc_now_playing.cpp"
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
143 #include "now_playing.moc"