Mercurial > minori
annotate src/gui/pages/now_playing.cc @ 97:18979b066284
animia/unix: fix a bunch of stuff that breaks OS X things
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 02 Nov 2023 13:14:15 -0400 |
parents | 2c27582a177c |
children | b315f3759c56 |
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); | |
97
18979b066284
animia/unix: fix a bunch of stuff that breaks OS X things
Paper <mrpapersonic@gmail.com>
parents:
92
diff
changeset
|
69 _info->layout()->setContentsMargins(0, 0, 0, 0); |
83 | 70 main_layout->addWidget(_info.get()); |
80 | 71 |
83 | 72 /* "sidebar", includes... just the anime image :) */ |
73 _sidebar.reset(new QWidget(this)); | |
74 QVBoxLayout* sidebar_layout = new QVBoxLayout(_sidebar.get()); | |
75 sidebar_layout->setContentsMargins(0, 0, 0, 0); | |
80 | 76 |
83 | 77 _poster.reset(new Poster(_sidebar.get())); |
78 sidebar_layout->addWidget(_poster.get()); | |
79 | |
80 sidebar_layout->addStretch(); | |
81 | |
82 layout->addWidget(_sidebar.get()); | |
83 layout->addWidget(_main.get()); | |
84 layout->setSpacing(10); | |
64 | 85 layout->setContentsMargins(0, 0, 0, 0); |
86 } | |
87 | |
69 | 88 int Playing::GetPlayingAnime() { |
89 return _id; | |
90 } | |
91 | |
83 | 92 void Playing::SetPlayingAnime(const Anime::Anime& anime, const std::unordered_map<std::string, std::string>& info) { |
93 if (_id == anime.GetId() && std::to_string(_episode) == info.at("episode")) | |
79 | 94 return; |
83 | 95 _id = anime.GetId(); |
96 try { | |
97 _episode = std::stoi(info.at("episode")); | |
92
2c27582a177c
pages/now_playing: fix invalid catch
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
98 } catch (std::invalid_argument const&) { |
83 | 99 _episode = 0; |
69 | 100 } |
83 | 101 _title->SetText(Strings::ToQString(anime.GetUserPreferredTitle())); |
102 _info->SetAnime(anime); | |
103 _poster->SetAnime(anime); | |
104 | |
105 updateGeometry(); | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
106 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
107 |
64 | 108 } // namespace NowPlayingPages |
109 | |
110 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) { | |
111 QVBoxLayout* layout = new QVBoxLayout(this); | |
112 | |
113 setFrameShape(QFrame::Box); | |
114 setFrameShadow(QFrame::Sunken); | |
115 | |
116 QPalette pal = QPalette(); | |
117 pal.setColor(QPalette::Window, pal.color(QPalette::Base)); | |
118 setPalette(pal); | |
119 setAutoFillBackground(true); | |
120 | |
121 stack = new QStackedWidget(this); | |
122 stack->addWidget(new NowPlayingPages::Default(stack)); | |
123 stack->addWidget(new NowPlayingPages::Playing(stack)); | |
124 layout->addWidget(stack); | |
125 | |
126 SetDefault(); | |
127 } | |
128 | |
129 void NowPlayingPage::SetDefault() { | |
130 stack->setCurrentIndex(0); | |
131 } | |
132 | |
69 | 133 int NowPlayingPage::GetPlayingId() { |
134 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime(); | |
135 } | |
136 | |
83 | 137 void NowPlayingPage::SetPlaying(const Anime::Anime& anime, const std::unordered_map<std::string, std::string>& info) { |
138 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(anime, info); | |
64 | 139 stack->setCurrentIndex(1); |
83 | 140 updateGeometry(); |
2 | 141 } |
7 | 142 |
46 | 143 #include "gui/pages/moc_now_playing.cpp" |
64 | 144 #include "now_playing.moc" |