changeset 295:b82841e76e79

*: better support on Windows things now look much better in dark mode
author Paper <paper@paper.us.eu.org>
date Sun, 12 May 2024 20:24:09 -0400
parents 99cbc51433e4
children b2a4358da16c
files Makefile.am include/gui/pages/seasons.h include/gui/widgets/poster.h include/gui/widgets/text.h src/gui/locale.cc src/gui/pages/now_playing.cc src/gui/pages/seasons.cc src/gui/pages/statistics.cc src/gui/widgets/anime_button.cc src/gui/widgets/poster.cc src/gui/widgets/text.cc
diffstat 11 files changed, 73 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.am	Sun May 12 18:16:08 2024 -0400
+++ b/Makefile.am	Sun May 12 20:24:09 2024 -0400
@@ -18,6 +18,8 @@
 
 # Qt resources
 
+
+
 minori_qtrc = \
 	$(top_srcdir)/rc/icons/icons.qrc	\
 	$(top_srcdir)/rc/animone.qrc	\
@@ -101,6 +103,7 @@
 
 # Add dark stylesheet to resources
 minori_qtrc_win = $(top_srcdir)/rc/sys/win32/dark/dark.qrc
+minori_qtrc_win_dep = $(top_srcdir)/rc/sys/win32/dark/dark.qss
 
 if BUILD_WINDRES
 
@@ -261,7 +264,7 @@
 
 # Build only one qrc, otherwise we get a ton of
 # weird linking errors
-rc/final_qrc.cc: $(minori_qtrc) $(minori_qtrc_win)
+rc/final_qrc.cc: $(minori_qtrc) $(minori_qtrc_win) $(minori_icons_png) $(minori_qtrc_win_dep)
 	$(QT_RCC) -o $@ $(minori_qtrc) $(minori_qtrc_win)
 
 .h_moc.cc:
--- a/include/gui/pages/seasons.h	Sun May 12 18:16:08 2024 -0400
+++ b/include/gui/pages/seasons.h	Sun May 12 20:24:09 2024 -0400
@@ -1,7 +1,7 @@
 #ifndef MINORI_GUI_PAGES_SEASONS_H_
 #define MINORI_GUI_PAGES_SEASONS_H_
 
-#include <QWidget>
+#include <QFrame>
 
 #include "core/anime.h"
 #include "core/date.h"
@@ -9,7 +9,7 @@
 class QListWidget;
 class QToolButton;
 
-class SeasonsPage final : public QWidget {
+class SeasonsPage final : public QFrame {
 	Q_OBJECT
 
 public:
--- a/include/gui/widgets/poster.h	Sun May 12 18:16:08 2024 -0400
+++ b/include/gui/widgets/poster.h	Sun May 12 20:24:09 2024 -0400
@@ -6,7 +6,6 @@
 #include "gui/widgets/clickable_label.h"
 #include "core/http.h"
 
-class QWidget;
 namespace Anime {
 class Anime;
 }
@@ -17,21 +16,28 @@
 public:
 	Poster(QWidget* parent = nullptr);
 	Poster(const Anime::Anime& anime, QWidget* parent = nullptr);
+	~Poster();
 	void SetAnime(const Anime::Anime& anime);
 	void SetClickable(bool clickable);
 
 protected:
+	void showEvent(QShowEvent*) override;
 	void resizeEvent(QResizeEvent*) override;
 	void ImageDownloadFinished(const QByteArray& arr);
 	void RenderToLabel();
+	void DownloadPoster();
 
 private:
-	HTTP::RequestThread get_thread_;
+	/* stored as a pointer to prevent blocking */
+	HTTP::RequestThread* get_thread_;
 
 	QImage img_;
 	QString service_url_;
+	std::string poster_url_;
 	ClickableLabel label_;
+
 	bool clickable_ = true;
+	bool need_refresh_ = false;
 };
 
 #endif // MINORI_GUI_WIDGETS_POSTER_H_
--- a/include/gui/widgets/text.h	Sun May 12 18:16:08 2024 -0400
+++ b/include/gui/widgets/text.h	Sun May 12 20:24:09 2024 -0400
@@ -34,8 +34,8 @@
 	QPlainTextEdit* GetLabel();
 
 protected:
-	QSize minimumSizeHint() const;
-	QSize sizeHint() const;
+	bool hasHeightForWidth() const override;
+	int heightForWidth(int w) const override;
 
 private:
 	QPlainTextEdit text_edit;
--- a/src/gui/locale.cc	Sun May 12 18:16:08 2024 -0400
+++ b/src/gui/locale.cc	Sun May 12 20:24:09 2024 -0400
@@ -7,16 +7,20 @@
 #include <QString>
 #include <QTranslator>
 
-#include <QDebug>
-
-#include <iostream>
+#include <QtGlobal>
 
 namespace Locale {
 
 std::string GetLocaleFullName(const QLocale& locale) {
 	QString res = QLocale::languageToString(locale.language());
+#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
+	/* silence deprecation warning for locale.country() */
+	if (locale.territory() != QLocale::AnyTerritory)
+		res += " (" + QLocale::territoryToString(locale.territory()) + ")";
+#else
 	if (locale.country() != QLocale::AnyCountry)
 		res += " (" + QLocale::countryToString(locale.country()) + ")";
+#endif
 	return Strings::ToUtf8String(res);
 }
 
@@ -82,7 +86,7 @@
 	const QString path = qApp->applicationDirPath();
 	if (!SwitchTranslator(_translator_qt, path + QString("/translations/qt_%1.qm").arg(name))) {
 		/* Sometimes Qt will have proper translations for the language, but not the specific
-		   country. In that case, we still want to use that language. */
+		 * country. In that case, we still want to use that language. */
 		const int underscore_index = name.lastIndexOf("_");
 		if (!underscore_index)
 			return false;
--- a/src/gui/pages/now_playing.cc	Sun May 12 18:16:08 2024 -0400
+++ b/src/gui/pages/now_playing.cc	Sun May 12 20:24:09 2024 -0400
@@ -78,6 +78,7 @@
 } // namespace NowPlayingPages
 
 NowPlayingPage::NowPlayingPage(QWidget* parent) : QFrame(parent) {
+	setBackgroundRole(QPalette::Base);
 	QVBoxLayout* layout = new QVBoxLayout(this);
 
 	setFrameShape(QFrame::Box);
--- a/src/gui/pages/seasons.cc	Sun May 12 18:16:08 2024 -0400
+++ b/src/gui/pages/seasons.cc	Sun May 12 20:24:09 2024 -0400
@@ -37,7 +37,11 @@
 	season_button->setText(Strings::ToQString(Translate::ToLocalString(season)) + " " + QString::number(year));
 }
 
-SeasonsPage::SeasonsPage(QWidget* parent) : QWidget(parent) {
+SeasonsPage::SeasonsPage(QWidget* parent) : QFrame(parent) {
+	setBackgroundRole(QPalette::Base);
+	setFrameShape(QFrame::Box);
+	setFrameShadow(QFrame::Sunken);
+
 	QVBoxLayout* full_layout = new QVBoxLayout(this);
 
 	{
@@ -177,6 +181,9 @@
 		full_layout->addWidget(buttons);
 	}
 
+	full_layout->setContentsMargins(0, 0, 0, 0);
+	full_layout->setSpacing(0);
+
 	/* Do NOT move this up in this function, buttons HAS to be initialized */
 	SetSeason(Anime::SeriesSeason::Summer, 2011);
 }
--- a/src/gui/pages/statistics.cc	Sun May 12 18:16:08 2024 -0400
+++ b/src/gui/pages/statistics.cc	Sun May 12 20:24:09 2024 -0400
@@ -22,6 +22,8 @@
 };
 
 StatisticsPage::StatisticsPage(QWidget* parent) : QFrame(parent) {
+	setBackgroundRole(QPalette::Base);
+
 	QVBoxLayout* layout = new QVBoxLayout(this);
 
 	setFrameShape(QFrame::Box);
@@ -106,6 +108,8 @@
 			str << amount << ((amount == 1) ? singular : plural);
 	};
 
+	/* for now, this function is very en_US specific */
+
 	std::ostringstream string;
 	add_time_segment(string, years, " year ", " years ");
 	add_time_segment(string, months, " month ", " months ");
--- a/src/gui/widgets/anime_button.cc	Sun May 12 18:16:08 2024 -0400
+++ b/src/gui/widgets/anime_button.cc	Sun May 12 20:24:09 2024 -0400
@@ -34,6 +34,7 @@
 	setFrameShape(QFrame::Box);
 	QHBoxLayout* ly = new QHBoxLayout(this);
 
+	/* XXX does Qt have a "fixed ratio"? */
 	_poster.setFixedSize(120, 170);
 	_poster.SetClickable(false);
 	ly->addWidget(&_poster, 0, Qt::AlignTop);
--- a/src/gui/widgets/poster.cc	Sun May 12 18:16:08 2024 -0400
+++ b/src/gui/widgets/poster.cc	Sun May 12 20:24:09 2024 -0400
@@ -28,21 +28,36 @@
 	label_.setAlignment(Qt::AlignCenter);
 	layout->addWidget(&label_);
 
-	connect(&get_thread_, &HTTP::RequestThread::ReceivedData, this, &Poster::ImageDownloadFinished);
+	get_thread_ = new HTTP::RequestThread(HTTP::Type::Get);
+	connect(get_thread_, &HTTP::RequestThread::ReceivedData, this, &Poster::ImageDownloadFinished);
 }
 
 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) {
 	SetAnime(anime);
 }
 
+Poster::~Poster() {
+	/* schedule deletion of the thread */
+	get_thread_->deleteLater();
+}
+
+void Poster::DownloadPoster() {
+	if (get_thread_->isRunning())
+		get_thread_->Stop();
+	get_thread_->wait();
+
+	get_thread_->SetUrl(poster_url_);
+	get_thread_->start();
+}
+
 void Poster::SetAnime(const Anime::Anime& anime) {
-	/* todo: only download on showEvent() */
-	if (get_thread_.isRunning())
-		get_thread_.Stop();
-	get_thread_.wait();
+	label_.clear();
 
-	get_thread_.SetUrl(anime.GetPosterUrl());
-	get_thread_.start();
+	poster_url_ = anime.GetPosterUrl();
+	if (isVisible())
+		DownloadPoster();
+	else
+		need_refresh_ = true;
 
 	std::optional<std::string> url = anime.GetServiceUrl(session.config.service);
 	if (url)
@@ -54,6 +69,13 @@
 	}
 }
 
+void Poster::showEvent(QShowEvent* event) {
+	if (need_refresh_) {
+		DownloadPoster();
+		need_refresh_ = false;
+	}
+}
+
 void Poster::SetClickable(bool enabled) {
 	clickable_ = enabled;
 
--- a/src/gui/widgets/text.cc	Sun May 12 18:16:08 2024 -0400
+++ b/src/gui/widgets/text.cc	Sun May 12 20:24:09 2024 -0400
@@ -62,6 +62,7 @@
 	text_edit.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 	text_edit.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 	text_edit.setStyleSheet("background: transparent;");
+	text_edit.setFrameStyle(QFrame::NoFrame);
 
 	text_edit.document()->setDocumentMargin(0);
 
@@ -79,20 +80,15 @@
 	text_edit.setTextCursor(cursor);
 }
 
-QSize Paragraph::minimumSizeHint() const {
-	return QSize(0, 0);
+bool Paragraph::hasHeightForWidth() const {
+	return true;
 }
 
-/* highly based upon... some stackoverflow answer for PyQt */
-QSize Paragraph::sizeHint() const {
+int Paragraph::heightForWidth(int w) const {
 	QTextDocument* doc = text_edit.document();
-	doc->adjustSize();
+	doc->setTextWidth(w);
 
-	long h = 0;
-	for (QTextBlock line = doc->begin(); line != doc->end(); line = line.next())
-		h += doc->documentLayout()->blockBoundingRect(line).height();
-
-	return QSize(doc->size().width(), h);
+	return doc->size().toSize().height();
 }
 
 QPlainTextEdit* Paragraph::GetLabel() {