Mercurial > minori
annotate src/gui/pages/now_playing.cc @ 198:bc1ae1810855
dep/animia: switch from using classes to global functions
the old idea was ok, but sort of hackish; this method doesn't use classes
at all, and this way (especially important!) we can do wayland stuff AND x11
at the same time, which wasn't really possible without stupid workarounds in
the other method
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 24 Dec 2023 02:59:42 -0500 |
parents | bc8d2ccff09c |
children | 4d461ef7d424 |
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" |
178
bc8d2ccff09c
win32/dark: use existing STL classes for dwmapi
Paper <mrpapersonic@gmail.com>
parents:
154
diff
changeset
|
7 |
64 | 8 #include <QLabel> |
9 #include <QStackedWidget> | |
83 | 10 #include <QHBoxLayout> |
64 | 11 #include <QVBoxLayout> |
12 #include <QWidget> | |
13 | |
154 | 14 #include "anitomy/anitomy.h" |
15 | |
64 | 16 namespace NowPlayingPages { |
17 | |
18 class Default : public QWidget { | |
19 Q_OBJECT | |
20 | |
21 public: | |
22 Default(QWidget* parent = nullptr); | |
23 }; | |
24 | |
25 class Playing : public QWidget { | |
26 Q_OBJECT | |
27 | |
28 public: | |
29 Playing(QWidget* parent = nullptr); | |
154 | 30 void SetPlayingAnime(const Anime::Anime& anime, const anitomy::Elements& info); |
69 | 31 int GetPlayingAnime(); |
64 | 32 |
33 private: | |
69 | 34 int _id = 0; |
79 | 35 int _episode = 0; |
83 | 36 std::unique_ptr<QWidget> _main = nullptr; |
80 | 37 std::unique_ptr<TextWidgets::Title> _title = nullptr; |
38 std::unique_ptr<AnimeInfoWidget> _info = nullptr; | |
83 | 39 std::unique_ptr<QWidget> _sidebar = nullptr; |
40 std::unique_ptr<Poster> _poster = nullptr; | |
64 | 41 }; |
42 | |
43 Default::Default(QWidget* parent) : QWidget(parent) { | |
44 QVBoxLayout* layout = new QVBoxLayout(this); | |
45 layout->setContentsMargins(0, 0, 0, 0); | |
2 | 46 |
80 | 47 TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this); |
48 layout->addWidget(title); | |
49 | |
64 | 50 layout->addStretch(); |
51 } | |
52 | |
53 Playing::Playing(QWidget* parent) : QWidget(parent) { | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
54 QHBoxLayout* layout = new QHBoxLayout(this); |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
55 |
83 | 56 _main.reset(new QWidget(this)); |
57 _main->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | |
58 | |
59 QVBoxLayout* main_layout = new QVBoxLayout(_main.get()); | |
60 main_layout->setContentsMargins(0, 0, 0, 0); | |
61 | |
62 _title.reset(new TextWidgets::Title("", _main.get())); | |
63 main_layout->addWidget(_title.get()); | |
64 | |
65 _info.reset(new AnimeInfoWidget(_main.get())); | |
66 _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
|
67 _info->layout()->setContentsMargins(0, 0, 0, 0); |
83 | 68 main_layout->addWidget(_info.get()); |
80 | 69 |
83 | 70 /* "sidebar", includes... just the anime image :) */ |
71 _sidebar.reset(new QWidget(this)); | |
72 QVBoxLayout* sidebar_layout = new QVBoxLayout(_sidebar.get()); | |
73 sidebar_layout->setContentsMargins(0, 0, 0, 0); | |
80 | 74 |
83 | 75 _poster.reset(new Poster(_sidebar.get())); |
76 sidebar_layout->addWidget(_poster.get()); | |
77 | |
78 sidebar_layout->addStretch(); | |
79 | |
80 layout->addWidget(_sidebar.get()); | |
81 layout->addWidget(_main.get()); | |
82 layout->setSpacing(10); | |
64 | 83 layout->setContentsMargins(0, 0, 0, 0); |
84 } | |
85 | |
69 | 86 int Playing::GetPlayingAnime() { |
87 return _id; | |
88 } | |
89 | |
154 | 90 void Playing::SetPlayingAnime(const Anime::Anime& anime, const anitomy::Elements& info) { |
91 if (_id == anime.GetId() && _episode == Strings::ToInt(Strings::ToUtf8String(info.get(anitomy::kElementEpisodeNumber)))) | |
79 | 92 return; |
83 | 93 _id = anime.GetId(); |
154 | 94 _episode = Strings::ToInt(Strings::ToUtf8String(info.get(anitomy::kElementEpisodeNumber))); |
83 | 95 _title->SetText(Strings::ToQString(anime.GetUserPreferredTitle())); |
96 _info->SetAnime(anime); | |
97 _poster->SetAnime(anime); | |
98 | |
99 updateGeometry(); | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
100 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
101 |
64 | 102 } // namespace NowPlayingPages |
103 | |
104 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) { | |
105 QVBoxLayout* layout = new QVBoxLayout(this); | |
106 | |
107 setFrameShape(QFrame::Box); | |
108 setFrameShadow(QFrame::Sunken); | |
109 setAutoFillBackground(true); | |
110 | |
111 stack = new QStackedWidget(this); | |
112 stack->addWidget(new NowPlayingPages::Default(stack)); | |
113 stack->addWidget(new NowPlayingPages::Playing(stack)); | |
114 layout->addWidget(stack); | |
115 | |
116 SetDefault(); | |
117 } | |
118 | |
119 void NowPlayingPage::SetDefault() { | |
120 stack->setCurrentIndex(0); | |
121 } | |
122 | |
69 | 123 int NowPlayingPage::GetPlayingId() { |
124 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime(); | |
125 } | |
126 | |
154 | 127 void NowPlayingPage::SetPlaying(const Anime::Anime& anime, const anitomy::Elements& info) { |
83 | 128 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(anime, info); |
64 | 129 stack->setCurrentIndex(1); |
83 | 130 updateGeometry(); |
2 | 131 } |
7 | 132 |
46 | 133 #include "gui/pages/moc_now_playing.cpp" |
64 | 134 #include "now_playing.moc" |