Mercurial > minori
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 |
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" | |
83 | 6 #include "gui/widgets/poster.h" |
64 | 7 #include <QLabel> |
8 #include <QStackedWidget> | |
83 | 9 #include <QHBoxLayout> |
64 | 10 #include <QVBoxLayout> |
11 #include <QWidget> | |
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 | 18 namespace NowPlayingPages { |
19 | |
20 class Default : public QWidget { | |
21 Q_OBJECT | |
22 | |
23 public: | |
24 Default(QWidget* parent = nullptr); | |
25 }; | |
26 | |
27 class Playing : public QWidget { | |
28 Q_OBJECT | |
29 | |
30 public: | |
31 Playing(QWidget* parent = nullptr); | |
83 | 32 void SetPlayingAnime(const Anime::Anime& anime, const std::unordered_map<std::string, std::string>& info); |
69 | 33 int GetPlayingAnime(); |
64 | 34 |
35 private: | |
69 | 36 int _id = 0; |
79 | 37 int _episode = 0; |
83 | 38 std::unique_ptr<QWidget> _main = nullptr; |
80 | 39 std::unique_ptr<TextWidgets::Title> _title = nullptr; |
40 std::unique_ptr<AnimeInfoWidget> _info = nullptr; | |
83 | 41 std::unique_ptr<QWidget> _sidebar = nullptr; |
42 std::unique_ptr<Poster> _poster = nullptr; | |
64 | 43 }; |
44 | |
45 Default::Default(QWidget* parent) : QWidget(parent) { | |
46 QVBoxLayout* layout = new QVBoxLayout(this); | |
47 layout->setContentsMargins(0, 0, 0, 0); | |
2 | 48 |
80 | 49 TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this); |
50 layout->addWidget(title); | |
51 | |
64 | 52 layout->addStretch(); |
53 } | |
54 | |
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 | 58 _main.reset(new QWidget(this)); |
59 _main->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | |
60 | |
61 QVBoxLayout* main_layout = new QVBoxLayout(_main.get()); | |
62 main_layout->setContentsMargins(0, 0, 0, 0); | |
63 | |
64 _title.reset(new TextWidgets::Title("", _main.get())); | |
65 main_layout->addWidget(_title.get()); | |
66 | |
67 _info.reset(new AnimeInfoWidget(_main.get())); | |
68 _info->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | |
69 main_layout->addWidget(_info.get()); | |
80 | 70 |
83 | 71 /* "sidebar", includes... just the anime image :) */ |
72 _sidebar.reset(new QWidget(this)); | |
73 QVBoxLayout* sidebar_layout = new QVBoxLayout(_sidebar.get()); | |
74 sidebar_layout->setContentsMargins(0, 0, 0, 0); | |
80 | 75 |
83 | 76 _poster.reset(new Poster(_sidebar.get())); |
77 sidebar_layout->addWidget(_poster.get()); | |
78 | |
79 sidebar_layout->addStretch(); | |
80 | |
81 layout->addWidget(_sidebar.get()); | |
82 layout->addWidget(_main.get()); | |
83 layout->setSpacing(10); | |
64 | 84 layout->setContentsMargins(0, 0, 0, 0); |
85 } | |
86 | |
69 | 87 int Playing::GetPlayingAnime() { |
88 return _id; | |
89 } | |
90 | |
83 | 91 void Playing::SetPlayingAnime(const Anime::Anime& anime, const std::unordered_map<std::string, std::string>& info) { |
92 if (_id == anime.GetId() && std::to_string(_episode) == info.at("episode")) | |
79 | 93 return; |
83 | 94 _id = anime.GetId(); |
95 try { | |
96 _episode = std::stoi(info.at("episode")); | |
97 } catch (std::invalid_argument) { | |
98 _episode = 0; | |
69 | 99 } |
83 | 100 _title->SetText(Strings::ToQString(anime.GetUserPreferredTitle())); |
101 _info->SetAnime(anime); | |
102 _poster->SetAnime(anime); | |
103 | |
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 | 107 } // namespace NowPlayingPages |
108 | |
109 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) { | |
110 QVBoxLayout* layout = new QVBoxLayout(this); | |
111 | |
112 setFrameShape(QFrame::Box); | |
113 setFrameShadow(QFrame::Sunken); | |
114 | |
115 QPalette pal = QPalette(); | |
116 pal.setColor(QPalette::Window, pal.color(QPalette::Base)); | |
117 setPalette(pal); | |
118 setAutoFillBackground(true); | |
119 | |
120 stack = new QStackedWidget(this); | |
121 stack->addWidget(new NowPlayingPages::Default(stack)); | |
122 stack->addWidget(new NowPlayingPages::Playing(stack)); | |
123 layout->addWidget(stack); | |
124 | |
125 SetDefault(); | |
126 } | |
127 | |
128 void NowPlayingPage::SetDefault() { | |
129 stack->setCurrentIndex(0); | |
130 } | |
131 | |
69 | 132 int NowPlayingPage::GetPlayingId() { |
133 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime(); | |
134 } | |
135 | |
83 | 136 void NowPlayingPage::SetPlaying(const Anime::Anime& anime, const std::unordered_map<std::string, std::string>& info) { |
137 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(anime, info); | |
64 | 138 stack->setCurrentIndex(1); |
83 | 139 updateGeometry(); |
2 | 140 } |
7 | 141 |
46 | 142 #include "gui/pages/moc_now_playing.cpp" |
64 | 143 #include "now_playing.moc" |