Make Themable pass the current Theme through applyTheme

This reduces boilerplate code and remove the ThemeManager dependency at Thamable subclasses level.
This commit is contained in:
luisangelsm
2026-01-20 15:57:22 +01:00
parent b662e4975b
commit edd5bbc69c
33 changed files with 55 additions and 77 deletions

View File

@ -18,7 +18,6 @@
#include "yacreader_global.h"
#include "edit_shortcuts_dialog.h"
#include "shortcuts_manager.h"
#include "theme_manager.h"
#include "whats_new_controller.h"
@ -1556,9 +1555,9 @@ void MainWindowViewer::setLoadedComicActionsEnabled(bool enabled)
a->setEnabled(enabled);
}
void MainWindowViewer::applyTheme()
void MainWindowViewer::applyTheme(const Theme &theme)
{
const auto toolbarTheme = ThemeManager::instance().getCurrentTheme().toolbar;
const auto toolbarTheme = theme.toolbar;
if (comicToolBar) {
comicToolBar->setStyleSheet(toolbarTheme.toolbarQSS);

View File

@ -174,7 +174,7 @@ private:
void setMglassActionsEnabled(bool enabled);
void setLoadedComicActionsEnabled(bool enabled);
void applyTheme() override;
void applyTheme(const Theme &theme) override;
//! Manejadores de evento:
// void resizeEvent(QResizeEvent * event);

View File

@ -2,8 +2,6 @@
#include <QtWidgets>
#include "theme_manager.h"
PageLabelWidget::PageLabelWidget(QWidget *parent)
: QWidget(parent)
{
@ -111,9 +109,9 @@ void PageLabelWidget::updatePosition()
move(QPoint((parent->geometry().size().width() - this->width()), -this->height()));
}
void PageLabelWidget::applyTheme()
void PageLabelWidget::applyTheme(const Theme &theme)
{
const auto viewerTheme = ThemeManager::instance().getCurrentTheme().viewer;
const auto viewerTheme = theme.viewer;
infoBackgroundColor = viewerTheme.infoBackgroundColor;

View File

@ -19,7 +19,7 @@ private:
protected:
void paintEvent(QPaintEvent *) override;
void applyTheme() override;
void applyTheme(const Theme &theme) override;
public:
PageLabelWidget(QWidget *parent);

View File

@ -1019,11 +1019,11 @@ void Viewer::updateBackgroundColor(const QColor &color)
setPalette(palette);
}
void Viewer::applyTheme()
void Viewer::applyTheme(const Theme &theme)
{
const auto viewerTheme = ThemeManager::instance().getCurrentTheme().viewer;
const auto viewerTheme = theme.viewer;
updateBackgroundColor(Configuration::getConfiguration().getBackgroundColor(ThemeManager::instance().getCurrentTheme().viewer.defaultBackgroundColor));
updateBackgroundColor(Configuration::getConfiguration().getBackgroundColor(theme.viewer.defaultBackgroundColor));
const QString textColor = viewerTheme.defaultTextColor.name(QColor::HexArgb);
content->setStyleSheet(QStringLiteral("QLabel { color : %1; background: transparent; }").arg(textColor));

View File

@ -188,7 +188,7 @@ private:
std::unique_ptr<YACReader::MouseHandler> mouseHandler;
protected:
void applyTheme() override;
void applyTheme(const Theme &theme) override;
public:
Viewer(QWidget *parent = nullptr);

View File

@ -27,8 +27,6 @@
#include "db_helper.h"
#include "response_parser.h"
#include "theme_manager.h"
#include "QsLog.h"
ComicVineDialog::ComicVineDialog(QWidget *parent)
@ -657,9 +655,9 @@ void ComicVineDialog::launchSearchComic()
searchVolume({ volumeInfo, 1, exactMatch });
}
void ComicVineDialog::applyTheme()
void ComicVineDialog::applyTheme(const Theme &theme)
{
auto comicVineTheme = ThemeManager::instance().getCurrentTheme().comicVine;
auto comicVineTheme = theme.comicVine;
setStyleSheet(comicVineTheme.dialogQSS);

View File

@ -129,7 +129,7 @@ private:
QString currentVolumeId;
protected:
void applyTheme() override;
void applyTheme(const Theme &theme) override;
};
#endif // COMIC_VINE_DIALOG_H

View File

@ -1,16 +1,14 @@
#include "scraper_checkbox.h"
#include "theme_manager.h"
ScraperCheckBox::ScraperCheckBox(const QString &text, QWidget *parent)
: QCheckBox(text, parent)
{
initTheme(this);
}
void ScraperCheckBox::applyTheme()
void ScraperCheckBox::applyTheme(const Theme &theme)
{
auto comicVineTheme = ThemeManager::instance().getCurrentTheme().comicVine;
auto comicVineTheme = theme.comicVine;
setStyleSheet(comicVineTheme.checkBoxQSS);
}

View File

@ -11,7 +11,7 @@ public:
ScraperCheckBox(const QString &text, QWidget *parent = nullptr);
protected:
void applyTheme() override;
void applyTheme(const Theme &theme) override;
};
#endif // SCRAPER_CHECKBOX_H

View File

@ -1,7 +1,5 @@
#include "scraper_lineedit.h"
#include "theme_manager.h"
#include <QLabel>
ScraperLineEdit::ScraperLineEdit(const QString &title, QWidget *widget)
@ -20,9 +18,9 @@ void ScraperLineEdit::resizeEvent(QResizeEvent *)
titleLabel->move(6, (rect().bottom() + 1 - szl.height()) / 2);
}
void ScraperLineEdit::applyTheme()
void ScraperLineEdit::applyTheme(const Theme &theme)
{
auto comicVineTheme = ThemeManager::instance().getCurrentTheme().comicVine;
auto comicVineTheme = theme.comicVine;
titleLabel->setStyleSheet(comicVineTheme.scraperLineEditTitleLabelQSS);
setStyleSheet(comicVineTheme.scraperLineEditQSS.arg(titleLabel->sizeHint().width() + 6));

View File

@ -15,7 +15,7 @@ public:
protected:
void resizeEvent(QResizeEvent *) override;
void applyTheme() override;
void applyTheme(const Theme &theme) override;
private:
QLabel *titleLabel;

View File

@ -1,6 +1,5 @@
#include "scraper_results_paginator.h"
#include "response_parser.h"
#include "theme_manager.h"
#include <QHBoxLayout>
#include <QLabel>
@ -62,9 +61,9 @@ void ScraperResultsPaginator::setCustomLabel(const QString &label)
customLabel = label;
}
void ScraperResultsPaginator::applyTheme()
void ScraperResultsPaginator::applyTheme(const Theme &theme)
{
auto comicVineTheme = ThemeManager::instance().getCurrentTheme().comicVine;
auto comicVineTheme = theme.comicVine;
numElements->setStyleSheet(comicVineTheme.defaultLabelQSS);
numPages->setStyleSheet(comicVineTheme.defaultLabelQSS);

View File

@ -31,7 +31,7 @@ private:
QString customLabel;
protected:
void applyTheme() override;
void applyTheme(const Theme &theme) override;
};
#endif // SCRAPER_RESULTS_PAGINATOR_H

View File

@ -1,7 +1,5 @@
#include "scraper_scroll_label.h"
#include "theme_manager.h"
#include <QLabel>
#include <QDesktopServices>
#include <QUrl>
@ -41,9 +39,9 @@ void ScraperScrollLabel::openLink(const QString &link)
QDesktopServices::openUrl(QUrl("http://www.comicvine.com" + link));
}
void ScraperScrollLabel::applyTheme()
void ScraperScrollLabel::applyTheme(const Theme &theme)
{
auto comicVineTheme = ThemeManager::instance().getCurrentTheme().comicVine;
auto comicVineTheme = theme.comicVine;
textLabel->setStyleSheet(comicVineTheme.scraperScrollLabelTextQSS);
setStyleSheet(comicVineTheme.scraperScrollLabelScrollAreaQSS);

View File

@ -23,7 +23,7 @@ private:
QLabel *textLabel;
protected:
void applyTheme() override;
void applyTheme(const Theme &theme) override;
};
#endif // SCRAPER_SCROLL_LABEL_H

View File

@ -1,7 +1,5 @@
#include "scraper_tableview.h"
#include "theme_manager.h"
#include <QHeaderView>
ScraperTableView::ScraperTableView(QWidget *parent)
@ -44,9 +42,9 @@ ScraperTableView::ScraperTableView(QWidget *parent)
initTheme(this);
}
void ScraperTableView::applyTheme()
void ScraperTableView::applyTheme(const Theme &theme)
{
auto comicVineTheme = ThemeManager::instance().getCurrentTheme().comicVine;
auto comicVineTheme = theme.comicVine;
setStyleSheet(comicVineTheme.scraperTableViewQSS);
}

View File

@ -12,7 +12,7 @@ public:
explicit ScraperTableView(QWidget *parent = nullptr);
protected:
void applyTheme() override;
void applyTheme(const Theme &theme) override;
};
#endif // SCRAPPER_TABLEVIEW_H

View File

@ -1,7 +1,6 @@
#include "search_single_comic.h"
#include "scraper_lineedit.h"
#include "theme_manager.h"
#include <QLabel>
#include <QVBoxLayout>
@ -73,9 +72,9 @@ void SearchSingleComic::clean()
volumeEdit->clear();
}
void SearchSingleComic::applyTheme()
void SearchSingleComic::applyTheme(const Theme &theme)
{
auto comicVineTheme = ThemeManager::instance().getCurrentTheme().comicVine;
auto comicVineTheme = theme.comicVine;
label->setStyleSheet(comicVineTheme.defaultLabelQSS);
}

View File

@ -29,6 +29,6 @@ private:
QLabel *label;
protected:
void applyTheme() override;
void applyTheme(const Theme &theme) override;
};
#endif // SEARCH_SINGLE_COMIC_H

View File

@ -2,7 +2,6 @@
#include "scraper_lineedit.h"
#include "scraper_checkbox.h"
#include "theme_manager.h"
#include <QLabel>
#include <QVBoxLayout>
@ -48,9 +47,9 @@ QString SearchVolume::getVolumeInfo() const
return volumeEdit->text();
}
void SearchVolume::applyTheme()
void SearchVolume::applyTheme(const Theme &theme)
{
auto comicVineTheme = ThemeManager::instance().getCurrentTheme().comicVine;
auto comicVineTheme = theme.comicVine;
label->setStyleSheet(comicVineTheme.defaultLabelQSS);
}

View File

@ -24,7 +24,7 @@ private:
QLabel *label;
protected:
void applyTheme() override;
void applyTheme(const Theme &theme) override;
};
#endif // SEARCH_VOLUME_H

View File

@ -4,7 +4,6 @@
#include "scraper_scroll_label.h"
#include "scraper_tableview.h"
#include "volume_comics_model.h"
#include "theme_manager.h"
#include <QJsonDocument>
#include <QJsonParseError>
@ -164,9 +163,9 @@ QString SelectComic::getSelectedComicId()
return model->getComicId(tableComics->currentIndex());
}
void SelectComic::applyTheme()
void SelectComic::applyTheme(const Theme &theme)
{
auto comicVineTheme = ThemeManager::instance().getCurrentTheme().comicVine;
auto comicVineTheme = theme.comicVine;
label->setStyleSheet(comicVineTheme.defaultLabelQSS);
cover->setStyleSheet(comicVineTheme.coverLabelQSS);

View File

@ -44,7 +44,7 @@ private:
ScraperResultsPaginator *paginator;
protected:
void applyTheme() override;
void applyTheme(const Theme &theme) override;
};
#endif // SELECT_COMIC_H

View File

@ -25,7 +25,6 @@
#include "scraper_results_paginator.h"
#include "selected_volume_info.h"
#include "theme_manager.h"
SelectVolume::SelectVolume(QWidget *parent)
: QWidget(parent), model(0)
@ -218,9 +217,9 @@ SelectedVolumeInfo SelectVolume::getSelectedVolumeInfo()
return { volumeId, numIssues, publisher, selectedVolumeDescription };
}
void SelectVolume::applyTheme()
void SelectVolume::applyTheme(const Theme &theme)
{
auto comicVineTheme = ThemeManager::instance().getCurrentTheme().comicVine;
auto comicVineTheme = theme.comicVine;
label->setStyleSheet(comicVineTheme.defaultLabelQSS);
cover->setStyleSheet(comicVineTheme.coverLabelQSS);

View File

@ -53,7 +53,7 @@ private:
ScraperResultsPaginator *paginator;
protected:
void applyTheme() override;
void applyTheme(const Theme &theme) override;
};
#endif // SELECT_VOLUME_H

View File

@ -1,7 +1,5 @@
#include "series_question.h"
#include "theme_manager.h"
#include <QRadioButton>
#include <QVBoxLayout>
#include <QLabel>
@ -40,9 +38,9 @@ void SeriesQuestion::setYes(bool y)
yes->setChecked(y);
}
void SeriesQuestion::applyTheme()
void SeriesQuestion::applyTheme(const Theme &theme)
{
auto comicVineTheme = ThemeManager::instance().getCurrentTheme().comicVine;
auto comicVineTheme = theme.comicVine;
questionLabel->setStyleSheet(comicVineTheme.defaultLabelQSS);
yes->setStyleSheet(comicVineTheme.radioButtonQSS);

View File

@ -23,7 +23,7 @@ private:
QRadioButton *no;
protected:
void applyTheme() override;
void applyTheme(const Theme &theme) override;
};
#endif // SERIES_QUESTION_H

View File

@ -45,9 +45,9 @@ void ScrapperToolButton::paintEvent(QPaintEvent *e)
QPushButton::paintEvent(e);
}
void ScrapperToolButton::applyTheme()
void ScrapperToolButton::applyTheme(const Theme &theme)
{
auto comicVineTheme = ThemeManager::instance().getCurrentTheme().comicVine;
auto comicVineTheme = theme.comicVine;
setStyleSheet(comicVineTheme.scraperToolButtonQSS);
fillColor = comicVineTheme.scraperToolButtonFillColor;
update();
@ -265,9 +265,9 @@ QList<QPair<ComicDB, QString>> SortVolumeComics::getMatchingInfo()
return l;
}
void SortVolumeComics::applyTheme()
void SortVolumeComics::applyTheme(const Theme &theme)
{
auto comicVineTheme = ThemeManager::instance().getCurrentTheme().comicVine;
auto comicVineTheme = theme.comicVine;
label->setStyleSheet(comicVineTheme.defaultLabelQSS);
sortLabel->setStyleSheet(comicVineTheme.defaultLabelQSS);

View File

@ -32,7 +32,7 @@ public:
protected:
void paintEvent(QPaintEvent *e) override;
void applyTheme() override;
void applyTheme(const Theme &theme) override;
private:
Appearance appearance;
@ -85,7 +85,7 @@ private:
ScraperResultsPaginator *paginator;
protected:
void applyTheme() override;
void applyTheme(const Theme &theme) override;
};
#endif // SORT_VOLUME_COMICS_H

View File

@ -1,7 +1,5 @@
#include "title_header.h"
#include "theme_manager.h"
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
@ -49,9 +47,9 @@ void TitleHeader::showButtons(bool show)
}
}
void TitleHeader::applyTheme()
void TitleHeader::applyTheme(const Theme &theme)
{
auto comicVineTheme = ThemeManager::instance().getCurrentTheme().comicVine;
auto comicVineTheme = theme.comicVine;
mainTitleLabel->setStyleSheet(comicVineTheme.titleLabelQSS);
subTitleLabel->setStyleSheet(comicVineTheme.defaultLabelQSS);

View File

@ -22,7 +22,7 @@ private:
QLabel *subTitleLabel;
protected:
void applyTheme() override;
void applyTheme(const Theme &theme) override;
};
#endif // TITLE_HEADER_H

View File

@ -12,13 +12,13 @@ protected:
&ThemeManager::themeChanged,
owner,
[this]() {
applyTheme();
applyTheme(ThemeManager::instance().getCurrentTheme());
});
applyTheme();
applyTheme(ThemeManager::instance().getCurrentTheme());
}
virtual void applyTheme() = 0;
virtual void applyTheme(const Theme &theme) = 0;
};
#endif // THEMABLE_H