diff src/gui/pages/now_playing.cpp @ 64:fe719c109dbc

*: update 1. add media tracking ability, and it displays info on the `now playing` page 2. the `now playing` page now actually shows something 3. renamed every page class to be more accurate to what it is 4. ...
author Paper <mrpapersonic@gmail.com>
date Sun, 01 Oct 2023 23:15:43 -0400
parents d0adc4aedfc8
children 6481c5aed3e1
line wrap: on
line diff
--- a/src/gui/pages/now_playing.cpp	Sun Oct 01 06:39:47 2023 -0400
+++ b/src/gui/pages/now_playing.cpp	Sun Oct 01 23:15:43 2023 -0400
@@ -1,6 +1,83 @@
 #include "gui/pages/now_playing.h"
+#include "core/anime_db.h"
+#include "gui/widgets/anime_info.h"
+#include "gui/widgets/text.h"
+#include <QLabel>
+#include <QStackedWidget>
+#include <QVBoxLayout>
+#include <QWidget>
+
+namespace NowPlayingPages {
+
+class Default : public QWidget {
+		Q_OBJECT
+
+	public:
+		Default(QWidget* parent = nullptr);
+};
+
+class Playing : public QWidget {
+		Q_OBJECT
+
+	public:
+		Playing(QWidget* parent = nullptr);
+
+		void SetPlayingAnime(int id) {
+			if (info.get())
+				layout()->removeWidget(info.get());
+			info.reset(new AnimeInfoWidget(Anime::db.items[id]));
+			layout()->addWidget(info.get());
+		}
+
+	private:
+		std::unique_ptr<AnimeInfoWidget> info = nullptr;
+};
+
+Default::Default(QWidget* parent) : QWidget(parent) {
+	QVBoxLayout* layout = new QVBoxLayout(this);
+	layout->setContentsMargins(0, 0, 0, 0);
 
-NowPlayingWidget::NowPlayingWidget(QWidget* parent) : QWidget(parent) {
+	layout->addStretch();
+}
+
+Playing::Playing(QWidget* parent) : QWidget(parent) {
+	QVBoxLayout* layout = new QVBoxLayout(this);
+	layout->setContentsMargins(0, 0, 0, 0);
+}
+
+} // namespace NowPlayingPages
+
+NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) {
+	QVBoxLayout* layout = new QVBoxLayout(this);
+
+	setFrameShape(QFrame::Box);
+	setFrameShadow(QFrame::Sunken);
+
+	QPalette pal = QPalette();
+	pal.setColor(QPalette::Window, pal.color(QPalette::Base));
+	setPalette(pal);
+	setAutoFillBackground(true);
+
+	TextWidgets::Title* title = new TextWidgets::Title(tr("Now Playing"), this);
+	layout->addWidget(title);
+
+	stack = new QStackedWidget(this);
+	stack->addWidget(new NowPlayingPages::Default(stack));
+	stack->addWidget(new NowPlayingPages::Playing(stack));
+	layout->addWidget(stack);
+
+	layout->addStretch();
+	SetDefault();
+}
+
+void NowPlayingPage::SetDefault() {
+	stack->setCurrentIndex(0);
+}
+
+void NowPlayingPage::SetPlaying(int id) {
+	reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id);
+	stack->setCurrentIndex(1);
 }
 
 #include "gui/pages/moc_now_playing.cpp"
+#include "now_playing.moc"