view src/gui/pages/now_playing.cpp @ 75:d3e9310598b1

*: refactor some stuff text: "TextParagraph"s are now called sections, because that's the actual word for it :P text: new classes: Line and OneLineSection, solves many problems with paragraphs that are only one line long (ex. going out of bounds) http: reworked http stuff to allow threaded get requests, also moved it to its own file to (hopefully) remove clutter eventually I'll make a threaded post request method and use that in the "basic" function
author Paper <mrpapersonic@gmail.com>
date Wed, 04 Oct 2023 01:42:30 -0400
parents 27a19dd6cba1
children c489dd4434af
line wrap: on
line source

#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);
		int GetPlayingAnime();

	private:
		int _id = 0;
		std::unique_ptr<AnimeInfoWidget> info = nullptr;
};

Default::Default(QWidget* parent) : QWidget(parent) {
	QVBoxLayout* layout = new QVBoxLayout(this);
	layout->setContentsMargins(0, 0, 0, 0);

	layout->addStretch();
}

Playing::Playing(QWidget* parent) : QWidget(parent) {
	QHBoxLayout* layout = new QHBoxLayout(this);

	layout->setContentsMargins(0, 0, 0, 0);
}

int Playing::GetPlayingAnime() {
	return _id;
}

void Playing::SetPlayingAnime(int id) {
	if (info.get())
		layout()->removeWidget(info.get());
	if (Anime::db.items.find(id) != Anime::db.items.end()) {
		info.reset(new AnimeInfoWidget(Anime::db.items[_id = id]));
		layout()->addWidget(info.get());
	}
}

} // 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);

	SetDefault();
}

void NowPlayingPage::SetDefault() {
	stack->setCurrentIndex(0);
}

int NowPlayingPage::GetPlayingId() {
	return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime();
}

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"