mirror of
https://github.com/YACReader/yacreader
synced 2026-03-01 18:33:09 -05:00
Initial implementation of theming
This commit is contained in:
@ -10,48 +10,47 @@
|
||||
#include "yacreader_global_gui.h"
|
||||
|
||||
#include <QtGui>
|
||||
#include <QFileIconProvider>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace YACReader;
|
||||
|
||||
#ifdef Y_MAC_UI
|
||||
#include <QFileIconProvider>
|
||||
QIcon finishedFolderIcon;
|
||||
void drawMacOSXFinishedFolderIcon()
|
||||
QIcon drawFinishedFolderIcon(const QPixmap &overlay)
|
||||
{
|
||||
QIcon finishedIcon;
|
||||
QIcon ico = QFileIconProvider().icon(QFileIconProvider::Folder);
|
||||
QPixmap pixNormalOff = ico.pixmap(16, 16, QIcon::Normal, QIcon::Off);
|
||||
QPixmap pixNormalOn = ico.pixmap(16, 16, QIcon::Normal, QIcon::On);
|
||||
QPixmap pixSelectedOff = ico.pixmap(16, 16, QIcon::Selected, QIcon::Off);
|
||||
QPixmap pixSelectedOn = ico.pixmap(16, 16, QIcon::Selected, QIcon::On);
|
||||
QPixmap tick(":/images/folder_finished_macosx.png");
|
||||
|
||||
{
|
||||
QPainter p(&pixNormalOff);
|
||||
p.drawPixmap(4, 7, tick);
|
||||
p.drawPixmap(4, 7, overlay);
|
||||
}
|
||||
finishedFolderIcon.addPixmap(pixNormalOff, QIcon::Normal, QIcon::Off);
|
||||
finishedIcon.addPixmap(pixNormalOff, QIcon::Normal, QIcon::Off);
|
||||
|
||||
{
|
||||
QPainter p(&pixNormalOn);
|
||||
p.drawPixmap(4, 7, tick);
|
||||
p.drawPixmap(4, 7, overlay);
|
||||
}
|
||||
finishedFolderIcon.addPixmap(pixNormalOn, QIcon::Normal, QIcon::On);
|
||||
finishedIcon.addPixmap(pixNormalOn, QIcon::Normal, QIcon::On);
|
||||
|
||||
{
|
||||
QPainter p(&pixSelectedOff);
|
||||
p.drawPixmap(4, 7, tick);
|
||||
p.drawPixmap(4, 7, overlay);
|
||||
}
|
||||
finishedFolderIcon.addPixmap(pixSelectedOff, QIcon::Selected, QIcon::Off);
|
||||
finishedIcon.addPixmap(pixSelectedOff, QIcon::Selected, QIcon::Off);
|
||||
|
||||
{
|
||||
QPainter p(&pixSelectedOn);
|
||||
p.drawPixmap(4, 7, tick);
|
||||
p.drawPixmap(4, 7, overlay);
|
||||
}
|
||||
finishedFolderIcon.addPixmap(pixSelectedOn, QIcon::Selected, QIcon::On);
|
||||
finishedIcon.addPixmap(pixSelectedOn, QIcon::Selected, QIcon::On);
|
||||
|
||||
return finishedIcon;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define ROOT 1
|
||||
|
||||
@ -132,8 +131,22 @@ FolderItem *createRoot(QSqlDatabase &db)
|
||||
}
|
||||
|
||||
FolderModel::FolderModel(QObject *parent)
|
||||
: QAbstractItemModel(parent), isSubfolder(false), rootItem(nullptr), folderIcon(YACReader::noHighlightedIcon(":/images/sidebar/folder.svg")), folderFinishedIcon(YACReader::noHighlightedIcon(":/images/sidebar/folder_finished.svg")), showRecent(false), recentDays(1)
|
||||
: QAbstractItemModel(parent), isSubfolder(false), rootItem(nullptr), showRecent(false), recentDays(1)
|
||||
{
|
||||
initTheme(this);
|
||||
}
|
||||
|
||||
void FolderModel::applyTheme(const Theme &theme)
|
||||
{
|
||||
const auto &sidebarIcons = theme.sidebarIcons;
|
||||
|
||||
if (sidebarIcons.useSystemFolderIcons) {
|
||||
folderIcon = QFileIconProvider().icon(QFileIconProvider::Folder);
|
||||
folderFinishedIcon = drawFinishedFolderIcon(sidebarIcons.folderReadOverlay);
|
||||
} else {
|
||||
folderIcon = sidebarIcons.folderIcon;
|
||||
folderFinishedIcon = sidebarIcons.folderFinishedIcon;
|
||||
}
|
||||
}
|
||||
|
||||
FolderModel::~FolderModel()
|
||||
@ -368,22 +381,10 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
|
||||
if (role == Qt::DecorationRole) {
|
||||
#ifdef Y_MAC_UI
|
||||
if (item->data(FolderModel::Finished).toBool()) {
|
||||
if (finishedFolderIcon.isNull()) {
|
||||
drawMacOSXFinishedFolderIcon();
|
||||
}
|
||||
|
||||
return QVariant(finishedFolderIcon);
|
||||
} else {
|
||||
return QVariant(QFileIconProvider().icon(QFileIconProvider::Folder));
|
||||
}
|
||||
#else
|
||||
if (item->data(FolderModel::Finished).toBool())
|
||||
return QVariant(folderFinishedIcon);
|
||||
else
|
||||
return QVariant(folderIcon);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (role == FolderModel::FolderNameRole) {
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
#include "folder.h"
|
||||
#include "folder_query_result_processor.h"
|
||||
#include "yacreader_global.h"
|
||||
#include "themable.h"
|
||||
|
||||
class FolderItem;
|
||||
|
||||
@ -35,7 +36,7 @@ protected:
|
||||
bool filterEnabled;
|
||||
};
|
||||
|
||||
class FolderModel : public QAbstractItemModel
|
||||
class FolderModel : public QAbstractItemModel, protected Themable
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -146,6 +147,9 @@ private:
|
||||
|
||||
bool showRecent;
|
||||
qlonglong recentDays;
|
||||
|
||||
protected:
|
||||
void applyTheme(const Theme &theme) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include <QFileIconProvider>
|
||||
|
||||
#include "QsLog.h"
|
||||
#include "theme_manager.h"
|
||||
|
||||
ListItem::ListItem(const QList<QVariant> &data)
|
||||
: itemData(data)
|
||||
@ -35,8 +36,18 @@ SpecialListItem::SpecialListItem(const QList<QVariant> &data)
|
||||
QIcon SpecialListItem::getIcon() const
|
||||
{
|
||||
if (itemData.count() > Id) {
|
||||
QString id = itemData.at(Id).toString();
|
||||
return YACReader::noHighlightedIcon(QString(":/images/lists/default_%1.svg").arg(id));
|
||||
int id = itemData.at(Id).toInt();
|
||||
const auto &icons = ThemeManager::instance().getCurrentTheme().readingListIcons;
|
||||
switch (id) {
|
||||
case 0:
|
||||
return icons.readingListIcon;
|
||||
case 1:
|
||||
return icons.favoritesIcon;
|
||||
case 2:
|
||||
return icons.currentlyReadingIcon;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QLOG_WARN() << "Icon for SpecialListItem not available";
|
||||
@ -75,8 +86,11 @@ LabelItem::LabelItem(const QList<QVariant> &data)
|
||||
QIcon LabelItem::getIcon() const
|
||||
{
|
||||
if (itemData.count() > Color) {
|
||||
QString color = itemData.at(Color).toString();
|
||||
return YACReader::noHighlightedIcon(QString(":/images/lists/label_%1.svg").arg(color).toLower());
|
||||
QString color = itemData.at(Color).toString().toLower();
|
||||
const auto &icons = ThemeManager::instance().getCurrentTheme().readingListIcons;
|
||||
if (icons.labelIcons.contains(color)) {
|
||||
return icons.labelIcons[color];
|
||||
}
|
||||
}
|
||||
|
||||
QLOG_WARN() << "Icon for label item not available";
|
||||
@ -127,20 +141,19 @@ qulonglong LabelItem::getId() const
|
||||
//------------------------------------------------------
|
||||
|
||||
ReadingListItem::ReadingListItem(const QList<QVariant> &data, ReadingListItem *p)
|
||||
: ListItem(data), parent(p), list(YACReader::noHighlightedIcon(":/images/lists/list.svg")), folder(YACReader::noHighlightedIcon(":/images/sidebar/folder.svg"))
|
||||
: ListItem(data), parent(p)
|
||||
{
|
||||
}
|
||||
|
||||
QIcon ReadingListItem::getIcon() const
|
||||
{
|
||||
const auto &theme = ThemeManager::instance().getCurrentTheme();
|
||||
if (parent->getId() == 0)
|
||||
return list; // top level list
|
||||
else
|
||||
#ifdef Y_MAC_UI
|
||||
return theme.readingListIcons.listIcon; // top level list
|
||||
else if (theme.sidebarIcons.useSystemFolderIcons)
|
||||
return QFileIconProvider().icon(QFileIconProvider::Folder);
|
||||
#else
|
||||
return folder; // sublist
|
||||
#endif
|
||||
else
|
||||
return theme.sidebarIcons.folderIcon; // sublist
|
||||
}
|
||||
|
||||
int ReadingListItem::childCount() const
|
||||
|
||||
@ -82,9 +82,6 @@ public:
|
||||
private:
|
||||
QList<ReadingListItem *> childItems;
|
||||
|
||||
QIcon list;
|
||||
QIcon folder;
|
||||
|
||||
enum DataIndexes {
|
||||
Name,
|
||||
Id,
|
||||
|
||||
Reference in New Issue
Block a user