Mercurial > minori
annotate src/gui/pages/now_playing.cpp @ 69:27a19dd6cba1
*: fix up some stuff
settings: due to my own incompetence OnOK caused the entire program to crash,
now that's fixed :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 03 Oct 2023 03:38:25 -0400 |
parents | 2417121d894e |
children | c489dd4434af |
rev | line source |
---|---|
9 | 1 #include "gui/pages/now_playing.h" |
64 | 2 #include "core/anime_db.h" |
3 #include "gui/widgets/anime_info.h" | |
4 #include "gui/widgets/text.h" | |
5 #include <QLabel> | |
6 #include <QStackedWidget> | |
7 #include <QVBoxLayout> | |
8 #include <QWidget> | |
9 | |
10 namespace NowPlayingPages { | |
11 | |
12 class Default : public QWidget { | |
13 Q_OBJECT | |
14 | |
15 public: | |
16 Default(QWidget* parent = nullptr); | |
17 }; | |
18 | |
19 class Playing : public QWidget { | |
20 Q_OBJECT | |
21 | |
22 public: | |
23 Playing(QWidget* parent = nullptr); | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
24 void SetPlayingAnime(int id); |
69 | 25 int GetPlayingAnime(); |
64 | 26 |
27 private: | |
69 | 28 int _id = 0; |
64 | 29 std::unique_ptr<AnimeInfoWidget> info = nullptr; |
30 }; | |
31 | |
32 Default::Default(QWidget* parent) : QWidget(parent) { | |
33 QVBoxLayout* layout = new QVBoxLayout(this); | |
34 layout->setContentsMargins(0, 0, 0, 0); | |
2 | 35 |
64 | 36 layout->addStretch(); |
37 } | |
38 | |
39 Playing::Playing(QWidget* parent) : QWidget(parent) { | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
40 QHBoxLayout* layout = new QHBoxLayout(this); |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
41 |
64 | 42 layout->setContentsMargins(0, 0, 0, 0); |
43 } | |
44 | |
69 | 45 int Playing::GetPlayingAnime() { |
46 return _id; | |
47 } | |
48 | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
49 void Playing::SetPlayingAnime(int id) { |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
50 if (info.get()) |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
51 layout()->removeWidget(info.get()); |
69 | 52 if (Anime::db.items.find(id) != Anime::db.items.end()) { |
53 info.reset(new AnimeInfoWidget(Anime::db.items[_id = id])); | |
54 layout()->addWidget(info.get()); | |
55 } | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
56 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
57 |
64 | 58 } // namespace NowPlayingPages |
59 | |
60 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) { | |
61 QVBoxLayout* layout = new QVBoxLayout(this); | |
62 | |
63 setFrameShape(QFrame::Box); | |
64 setFrameShadow(QFrame::Sunken); | |
65 | |
66 QPalette pal = QPalette(); | |
67 pal.setColor(QPalette::Window, pal.color(QPalette::Base)); | |
68 setPalette(pal); | |
69 setAutoFillBackground(true); | |
70 | |
71 TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this); | |
72 layout->addWidget(title); | |
73 | |
74 stack = new QStackedWidget(this); | |
75 stack->addWidget(new NowPlayingPages::Default(stack)); | |
76 stack->addWidget(new NowPlayingPages::Playing(stack)); | |
77 layout->addWidget(stack); | |
78 | |
79 SetDefault(); | |
80 } | |
81 | |
82 void NowPlayingPage::SetDefault() { | |
83 stack->setCurrentIndex(0); | |
84 } | |
85 | |
69 | 86 int NowPlayingPage::GetPlayingId() { |
87 return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime(); | |
88 } | |
89 | |
64 | 90 void NowPlayingPage::SetPlaying(int id) { |
91 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id); | |
92 stack->setCurrentIndex(1); | |
2 | 93 } |
7 | 94 |
46 | 95 #include "gui/pages/moc_now_playing.cpp" |
64 | 96 #include "now_playing.moc" |