Mercurial > minori
annotate src/gui/pages/now_playing.cpp @ 68:2417121d894e
*: normalize usage of layouts
before, I used them two ways, once was by setting the layout later
by using setLayout(QWidget), and the other was just using the constructor.
I find the constructor to be easier to read, so I chose that one.
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 02 Oct 2023 21:33:25 -0400 |
parents | 6481c5aed3e1 |
children | 27a19dd6cba1 |
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); |
64 | 25 |
26 private: | |
27 std::unique_ptr<AnimeInfoWidget> info = nullptr; | |
28 }; | |
29 | |
30 Default::Default(QWidget* parent) : QWidget(parent) { | |
31 QVBoxLayout* layout = new QVBoxLayout(this); | |
32 layout->setContentsMargins(0, 0, 0, 0); | |
2 | 33 |
64 | 34 layout->addStretch(); |
35 } | |
36 | |
37 Playing::Playing(QWidget* parent) : QWidget(parent) { | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
38 QHBoxLayout* layout = new QHBoxLayout(this); |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
39 |
64 | 40 layout->setContentsMargins(0, 0, 0, 0); |
41 } | |
42 | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
43 void Playing::SetPlayingAnime(int id) { |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
44 if (info.get()) |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
45 layout()->removeWidget(info.get()); |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
46 info.reset(new AnimeInfoWidget(Anime::db.items[id])); |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
47 layout()->addWidget(info.get()); |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
48 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
49 |
64 | 50 } // namespace NowPlayingPages |
51 | |
52 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) { | |
53 QVBoxLayout* layout = new QVBoxLayout(this); | |
54 | |
55 setFrameShape(QFrame::Box); | |
56 setFrameShadow(QFrame::Sunken); | |
57 | |
58 QPalette pal = QPalette(); | |
59 pal.setColor(QPalette::Window, pal.color(QPalette::Base)); | |
60 setPalette(pal); | |
61 setAutoFillBackground(true); | |
62 | |
63 TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this); | |
64 layout->addWidget(title); | |
65 | |
66 stack = new QStackedWidget(this); | |
67 stack->addWidget(new NowPlayingPages::Default(stack)); | |
68 stack->addWidget(new NowPlayingPages::Playing(stack)); | |
69 layout->addWidget(stack); | |
70 | |
71 SetDefault(); | |
72 } | |
73 | |
74 void NowPlayingPage::SetDefault() { | |
75 stack->setCurrentIndex(0); | |
76 } | |
77 | |
78 void NowPlayingPage::SetPlaying(int id) { | |
79 reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id); | |
80 stack->setCurrentIndex(1); | |
2 | 81 } |
7 | 82 |
46 | 83 #include "gui/pages/moc_now_playing.cpp" |
64 | 84 #include "now_playing.moc" |