From eee82fcd5c5648a822cbd0704e527c24fe884ba1 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Mon, 20 Jan 2020 00:22:31 +0800 Subject: [PATCH] frontend: Added icons for everything except titlebar --- dist/themes/default/default.qrc | 19 ++++++ dist/themes/default/icons/24x24/app.png | Bin 0 -> 179 bytes dist/themes/default/icons/24x24/dlc.png | Bin 0 -> 210 bytes dist/themes/default/icons/24x24/save_data.png | Bin 0 -> 152 bytes .../default/icons/24x24/system_archive.png | Bin 0 -> 97 bytes .../default/icons/24x24/system_data.png | Bin 0 -> 193 bytes dist/themes/default/icons/24x24/unknown.png | Bin 0 -> 289 bytes dist/themes/default/icons/24x24/update.png | Bin 0 -> 232 bytes dist/themes/default/icons/index.theme | 7 ++ license.txt | 5 ++ src/frontend/CMakeLists.txt | 3 + src/frontend/import_dialog.cpp | 62 +++++++++++++----- src/frontend/main.cpp | 3 + 13 files changed, 81 insertions(+), 18 deletions(-) create mode 100644 dist/themes/default/default.qrc create mode 100644 dist/themes/default/icons/24x24/app.png create mode 100644 dist/themes/default/icons/24x24/dlc.png create mode 100644 dist/themes/default/icons/24x24/save_data.png create mode 100644 dist/themes/default/icons/24x24/system_archive.png create mode 100644 dist/themes/default/icons/24x24/system_data.png create mode 100644 dist/themes/default/icons/24x24/unknown.png create mode 100644 dist/themes/default/icons/24x24/update.png create mode 100644 dist/themes/default/icons/index.theme diff --git a/dist/themes/default/default.qrc b/dist/themes/default/default.qrc new file mode 100644 index 0000000..6c5952d --- /dev/null +++ b/dist/themes/default/default.qrc @@ -0,0 +1,19 @@ + + + icons/index.theme + + icons/24x24/app.png + + icons/24x24/dlc.png + + icons/24x24/save_data.png + + icons/24x24/system_archive.png + + icons/24x24/system_data.png + + icons/24x24/unknown.png + + icons/24x24/update.png + + diff --git a/dist/themes/default/icons/24x24/app.png b/dist/themes/default/icons/24x24/app.png new file mode 100644 index 0000000000000000000000000000000000000000..01767915408ab3d711eec110ad034be8df896297 GIT binary patch literal 179 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_+iDo+>3kP61+1$F`ozB?HYTer#N z2>rjPz%s+AhUK#tM^=N@f1c;l1+FEqhV?a^{b6chP;*$|^|9rN%mRxKhw}*SFfA~6 zb2MOG<8^)q-S&w;-bjwiT;_#}5-bUVDF c?I0I}VD-OAu@iZw0$su2>FVdQ&MBb@0FK^1{r~^~ literal 0 HcmV?d00001 diff --git a/dist/themes/default/icons/24x24/dlc.png b/dist/themes/default/icons/24x24/dlc.png new file mode 100644 index 0000000000000000000000000000000000000000..61c6fa352691710fb83bbcae9e922d9d0cbae452 GIT binary patch literal 210 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_+inVv3=Ar*{!CpNMjHV|mrFRl^b zFh8^MvJ+zmV{`6;D4rMJ7!C_8-ECNCaoclhoqfS`?@89%E?@Y#WbwiY9W}z5Dd!IP zC@w0rFi@yB7BH|8FfZrHKXU$`(-Rjhktto*LWRnHU(xB9-SMzZe~;On4WIarZw=m* z9_#tk$vai<1sC_%^MVp;xnDHCM9no|Id;ctaly&06A$#&FvJ&&+kKYUumI>t22WQ% Jmvv4FO#n5sQSkr( literal 0 HcmV?d00001 diff --git a/dist/themes/default/icons/24x24/save_data.png b/dist/themes/default/icons/24x24/save_data.png new file mode 100644 index 0000000000000000000000000000000000000000..d35c8b13b0e0bd683c2ef0f56c33047a16944049 GIT binary patch literal 152 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`Gj@t!V@Ar*{o&u$cSU|?Wzocp39 z?a8VZo)w38bJ;NLnAxjekt$ep!eiqqIioBNPBC)_w~l*0W;`c+w(*}y`JHguMaxvA+;% uzQ?qS?P7+Ol&|aJl^G_Yy~`E_GBCJiJeJ)s*N1?y>qJ2N*85vjpTc8}d^HiQ+nt*Y^#JzVt zn5w=Nt(@D?`e*IV`7*aB-deJ88uP)$wmke*8-Wgea=7D t&Sz{pcl1YC7xSd2*``_@%`^Jc{~n&*wY`7RJD{5wJYD@<);T3K0RZ;XQ0o8y literal 0 HcmV?d00001 diff --git a/dist/themes/default/icons/24x24/unknown.png b/dist/themes/default/icons/24x24/unknown.png new file mode 100644 index 0000000000000000000000000000000000000000..1991c1e3043368a473f4f60f3a88f7a83e26447b GIT binary patch literal 289 zcmV++0p9+JP)3mS`cz~4T$JTnI((C(J2juUnb$H4&tP!E}ZUSI}5<HDQNu+3y4VwGz!z$cTf^4ID&Kp0L~zeE_vXh=ZM>Cq5VZ^IM^^TP37 nP(atYK;3^<^bxz$ik8X`0#6e>q-9BM00000NkvXXu0mjfvC?-G literal 0 HcmV?d00001 diff --git a/dist/themes/default/icons/24x24/update.png b/dist/themes/default/icons/24x24/update.png new file mode 100644 index 0000000000000000000000000000000000000000..90da7a26b90e060fea768c9fc5d70d0b9acb71cc GIT binary patch literal 232 zcmVP), 7> ContentTypeMap{{ - {Core::ContentType::Application, QT_TR_NOOP("Application")}, - {Core::ContentType::Update, QT_TR_NOOP("Update")}, - {Core::ContentType::DLC, QT_TR_NOOP("DLC")}, - {Core::ContentType::Savegame, QT_TR_NOOP("Save Data")}, - {Core::ContentType::Extdata, QT_TR_NOOP("Extra Data")}, - {Core::ContentType::SystemArchive, QT_TR_NOOP("System Archive")}, - {Core::ContentType::Sysdata, QT_TR_NOOP("System Data")}, -}}; +// content type, name, icon name +static constexpr std::array, 7> + ContentTypeMap{{ + {Core::ContentType::Application, QT_TR_NOOP("Application"), "app"}, + {Core::ContentType::Update, QT_TR_NOOP("Update"), "update"}, + {Core::ContentType::DLC, QT_TR_NOOP("DLC"), "dlc"}, + {Core::ContentType::Savegame, QT_TR_NOOP("Save Data"), "save_data"}, + {Core::ContentType::Extdata, QT_TR_NOOP("Extra Data"), "save_data"}, + {Core::ContentType::SystemArchive, QT_TR_NOOP("System Archive"), "system_archive"}, + {Core::ContentType::Sysdata, QT_TR_NOOP("System Data"), "system_data"}, + }}; static const std::unordered_map EncryptionTypeMap{{ {Core::EncryptionType::None, QT_TR_NOOP("None")}, @@ -57,10 +59,22 @@ QString GetContentName(const Core::ContentSpecifier& specifier) { } QString GetContentTypeName(Core::ContentType type) { - return QObject::tr(ContentTypeMap.at(static_cast(type)).second, "ImportDialog"); + return QObject::tr(std::get<1>(ContentTypeMap.at(static_cast(type))), + "ImportDialog"); } -QPixmap GetContentIcon(const Core::ContentSpecifier& specifier) { +QPixmap GetContentTypeIcon(Core::ContentType type) { + return QIcon::fromTheme( + QString::fromUtf8(std::get<2>(ContentTypeMap.at(static_cast(type))))) + .pixmap(24); +} + +QPixmap GetContentIcon(const Core::ContentSpecifier& specifier, bool use_category_icon = false) { + if (specifier.icon.empty()) { + // Return a category icon, or a null icon + return use_category_icon ? GetContentTypeIcon(specifier.type) + : QIcon::fromTheme(QStringLiteral("unknown")).pixmap(24); + } return QPixmap::fromImage(QImage(reinterpret_cast(specifier.icon.data()), 24, 24, QImage::Format::Format_RGB16)); } @@ -179,8 +193,10 @@ void ImportDialog::InsertSecondLevelItem(std::size_t row, const Core::ContentSpe // HACK: The checkbox is used to record ID. Is there a better way? checkBox->setProperty("id", id); + const bool use_title_view = ui->title_view_button->isChecked(); + QString name; - if (ui->title_view_button->isChecked()) { + if (use_title_view) { if (row == 0) { name = QStringLiteral("%1 (%2)") .arg(GetContentName(content)) @@ -214,11 +230,17 @@ void ImportDialog::InsertSecondLevelItem(std::size_t row, const Core::ContentSpe {QString{}, name, ReadableByteSize(content.maximum_size), encryption, content.already_exists ? QStringLiteral("Yes") : QStringLiteral("No")}}; - if (!ui->title_view_button->isChecked()) { - // Display icon when present - item->setData(1, Qt::DecorationRole, - replace_icon.isNull() ? GetContentIcon(content) : replace_icon); + QPixmap icon; + if (replace_icon.isNull()) { + // When not in title view, only System Data and System Archive groups use category icons. + const bool use_category_icon = content.type == Core::ContentType::Sysdata || + content.type == Core::ContentType::SystemArchive; + icon = use_title_view ? GetContentTypeIcon(content.type) + : GetContentIcon(content, use_category_icon); + } else { + icon = replace_icon; } + item->setData(1, Qt::DecorationRole, icon); ui->main->invisibleRootItem()->child(row)->addChild(item); ui->main->setItemWidget(item, 0, checkBox); @@ -276,6 +298,10 @@ void ImportDialog::RepopulateContent() { title_name_map.insert_or_assign(1, tr("System Archive")); title_name_map.insert_or_assign(2, tr("System Data")); + title_icon_map.insert_or_assign(0, QIcon::fromTheme(QStringLiteral("unknown")).pixmap(24)); + title_icon_map.insert_or_assign(1, GetContentTypeIcon(Core::ContentType::SystemArchive)); + title_icon_map.insert_or_assign(2, GetContentTypeIcon(Core::ContentType::Sysdata)); + std::unordered_map title_row_map; for (const auto& [id, name] : title_name_map) { InsertTopLevelItem(name, title_icon_map.count(id) ? title_icon_map.at(id) : QPixmap{}); @@ -316,8 +342,8 @@ void ImportDialog::RepopulateContent() { InsertSecondLevelItem(row, content, i); } } else { - for (const auto& [type, name] : ContentTypeMap) { - InsertTopLevelItem(tr(name)); + for (const auto& [type, name, _] : ContentTypeMap) { + InsertTopLevelItem(tr(name), GetContentTypeIcon(type)); } for (std::size_t i = 0; i < contents.size(); ++i) { diff --git a/src/frontend/main.cpp b/src/frontend/main.cpp index a76fe1a..55849dd 100644 --- a/src/frontend/main.cpp +++ b/src/frontend/main.cpp @@ -219,6 +219,9 @@ int main(int argc, char* argv[]) { QApplication app(argc, argv); + QIcon::setThemeSearchPaths(QStringList(QStringLiteral(":/icons/default"))); + QIcon::setThemeName(QStringLiteral(":/icons/default")); + MainDialog main_dialog; main_dialog.show();