diff src/gui/pages/now_playing.cc @ 83:d02fdf1d6708

*: huuuge update 1. make the now playing page function correctly 2. de-constructorfy many of our custom widgets, allowing them to be changed on-the-fly from the Now Playing page 3. ... :)
author Paper <mrpapersonic@gmail.com>
date Tue, 24 Oct 2023 22:01:02 -0400
parents 8b65c417c225
children 2c27582a177c
line wrap: on
line diff
--- a/src/gui/pages/now_playing.cc	Mon Oct 23 13:37:42 2023 -0400
+++ b/src/gui/pages/now_playing.cc	Tue Oct 24 22:01:02 2023 -0400
@@ -3,8 +3,10 @@
 #include "core/strings.h"
 #include "gui/widgets/anime_info.h"
 #include "gui/widgets/text.h"
+#include "gui/widgets/poster.h"
 #include <QLabel>
 #include <QStackedWidget>
+#include <QHBoxLayout>
 #include <QVBoxLayout>
 #include <QWidget>
 
@@ -27,14 +29,17 @@
 
 	public:
 		Playing(QWidget* parent = nullptr);
-		void SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info);
+		void SetPlayingAnime(const Anime::Anime& anime, const std::unordered_map<std::string, std::string>& info);
 		int GetPlayingAnime();
 
 	private:
 		int _id = 0;
 		int _episode = 0;
+		std::unique_ptr<QWidget> _main = nullptr;
 		std::unique_ptr<TextWidgets::Title> _title = nullptr;
 		std::unique_ptr<AnimeInfoWidget> _info = nullptr;
+		std::unique_ptr<QWidget> _sidebar = nullptr;
+		std::unique_ptr<Poster> _poster = nullptr;
 };
 
 Default::Default(QWidget* parent) : QWidget(parent) {
@@ -50,12 +55,32 @@
 Playing::Playing(QWidget* parent) : QWidget(parent) {
 	QHBoxLayout* layout = new QHBoxLayout(this);
 
-	_title.reset(new TextWidgets::Title("\n", this));
-	layout->addWidget(_title.get());
+	_main.reset(new QWidget(this));
+	_main->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
+
+	QVBoxLayout* main_layout = new QVBoxLayout(_main.get());
+	main_layout->setContentsMargins(0, 0, 0, 0);
+
+	_title.reset(new TextWidgets::Title("", _main.get()));
+	main_layout->addWidget(_title.get());
+
+	_info.reset(new AnimeInfoWidget(_main.get()));
+	_info->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
+	main_layout->addWidget(_info.get());
 
-	_info.reset(new AnimeInfoWidget(this));
-	layout->addWidget(_info.get());
+	/* "sidebar", includes... just the anime image :) */
+	_sidebar.reset(new QWidget(this));
+	QVBoxLayout* sidebar_layout = new QVBoxLayout(_sidebar.get());
+	sidebar_layout->setContentsMargins(0, 0, 0, 0);
 
+	_poster.reset(new Poster(_sidebar.get()));
+	sidebar_layout->addWidget(_poster.get());
+
+	sidebar_layout->addStretch();
+
+	layout->addWidget(_sidebar.get());
+	layout->addWidget(_main.get());
+	layout->setSpacing(10);
 	layout->setContentsMargins(0, 0, 0, 0);
 }
 
@@ -63,14 +88,20 @@
 	return _id;
 }
 
-void Playing::SetPlayingAnime(int id, const std::unordered_map<std::string, std::string>& info) {
-	if (id == _id || id <= 0)
+void Playing::SetPlayingAnime(const Anime::Anime& anime, const std::unordered_map<std::string, std::string>& info) {
+	if (_id == anime.GetId() && std::to_string(_episode) == info.at("episode"))
 		return;
-	if (Anime::db.items.find(id) != Anime::db.items.end()) {
-		const Anime::Anime& anime = Anime::db.items[_id = id];
-		_title->setText(Strings::ToQString(anime.GetUserPreferredTitle()));
-		_info->SetAnime(anime);
+	_id = anime.GetId();
+	try {
+		_episode = std::stoi(info.at("episode"));
+	} catch (std::invalid_argument) {
+		_episode = 0;
 	}
+	_title->SetText(Strings::ToQString(anime.GetUserPreferredTitle()));
+	_info->SetAnime(anime);
+	_poster->SetAnime(anime);
+
+	updateGeometry();
 }
 
 } // namespace NowPlayingPages
@@ -102,9 +133,10 @@
 	return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime();
 }
 
-void NowPlayingPage::SetPlaying(int id, const std::unordered_map<std::string, std::string>& info) {
-	reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id, info);
+void NowPlayingPage::SetPlaying(const Anime::Anime& anime, const std::unordered_map<std::string, std::string>& info) {
+	reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(anime, info);
 	stack->setCurrentIndex(1);
+	updateGeometry();
 }
 
 #include "gui/pages/moc_now_playing.cpp"