Mercurial > minori
annotate src/gui/pages/now_playing.cc @ 109:79714c95a145
*: add translation files and locale files
I forgot to add these in the last commit :p
also now you have to ask cmake to update the translations
because before the ts files were not tracked (obviously)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 06 Nov 2023 01:51:44 -0500 |
parents | 6d8da6e64d61 |
children | d43d68408d3c |
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(); |
102 | 96 _episode = Strings::ToInt(info.at("episode")); |
83 | 97 _title->SetText(Strings::ToQString(anime.GetUserPreferredTitle())); |
98 _info->SetAnime(anime); | |
99 _poster->SetAnime(anime); | |
100 | |
101 updateGeometry(); | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
102 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
103 |
64 | 104 } // namespace NowPlayingPages |
105 | |
106 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) { | |
107 QVBoxLayout* layout = new QVBoxLayout(this); | |
108 | |
109 setFrameShape(QFrame::Box); | |
110 setFrameShadow(QFrame::Sunken); | |
111 setAutoFillBackground(true); | |
112 | |
113 stack = new QStackedWidget(this); | |
114 stack->addWidget(new NowPlayingPages::Default(stack)); | |
115 stack->addWidget(new NowPlayingPages::Playing(stack)); | |
116 layout->addWidget(stack); | |
117 | |
118 SetDefault(); | |
119 } | |
120 | |
121 void NowPlayingPage::SetDefault() { | |
122 stack->setCurrentIndex(0); | |
123 } | |
124 | |
69 | 125 int NowPlayingPage::GetPlayingId() { |
126 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime(); | |
127 } | |
128 | |
83 | 129 void NowPlayingPage::SetPlaying(const Anime::Anime& anime, const std::unordered_map<std::string, std::string>& info) { |
130 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(anime, info); | |
64 | 131 stack->setCurrentIndex(1); |
83 | 132 updateGeometry(); |
2 | 133 } |
7 | 134 |
46 | 135 #include "gui/pages/moc_now_playing.cpp" |
64 | 136 #include "now_playing.moc" |