mirror of
https://github.com/Dark98/threeSD.git
synced 2026-07-06 00:38:55 +00:00
Add Save Icon feature
This commit is contained in:
@@ -2,7 +2,10 @@
|
|||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <QAction>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QImageWriter>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
@@ -61,12 +64,7 @@ void TitleInfoDialog::LoadInfo() {
|
|||||||
|
|
||||||
// Icons
|
// Icons
|
||||||
if (has_smdh) {
|
if (has_smdh) {
|
||||||
ui->iconLargeLabel->setPixmap(
|
LoadIcons();
|
||||||
QPixmap::fromImage(QImage(reinterpret_cast<const uchar*>(smdh.GetIcon(true).data()), 48,
|
|
||||||
48, QImage::Format::Format_RGB16)));
|
|
||||||
ui->iconSmallLabel->setPixmap(
|
|
||||||
QPixmap::fromImage(QImage(reinterpret_cast<const uchar*>(smdh.GetIcon(false).data()),
|
|
||||||
24, 24, QImage::Format::Format_RGB16)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Names
|
// Names
|
||||||
@@ -103,6 +101,24 @@ void TitleInfoDialog::LoadEncryption(Core::NCCHContainer& ncch) {
|
|||||||
ui->encryptionLineEdit->setText(encryption_text);
|
ui->encryptionLineEdit->setText(encryption_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TitleInfoDialog::LoadIcons() {
|
||||||
|
ui->iconLargeLabel->setPixmap(
|
||||||
|
QPixmap::fromImage(QImage(reinterpret_cast<const uchar*>(smdh.GetIcon(true).data()), 48, 48,
|
||||||
|
QImage::Format::Format_RGB16)));
|
||||||
|
|
||||||
|
QAction* save_icon_large = new QAction(tr("Save Icon (Large)"), this);
|
||||||
|
ui->iconLargeLabel->addAction(save_icon_large);
|
||||||
|
connect(save_icon_large, &QAction::triggered, this, [this] { SaveIcon(true); });
|
||||||
|
|
||||||
|
ui->iconSmallLabel->setPixmap(
|
||||||
|
QPixmap::fromImage(QImage(reinterpret_cast<const uchar*>(smdh.GetIcon(false).data()), 24,
|
||||||
|
24, QImage::Format::Format_RGB16)));
|
||||||
|
|
||||||
|
QAction* save_icon_small = new QAction(tr("Save Icon (Small)"), this);
|
||||||
|
ui->iconSmallLabel->addAction(save_icon_small);
|
||||||
|
connect(save_icon_small, &QAction::triggered, this, [this] { SaveIcon(false); });
|
||||||
|
}
|
||||||
|
|
||||||
void TitleInfoDialog::InitializeLanguageComboBox() {
|
void TitleInfoDialog::InitializeLanguageComboBox() {
|
||||||
if (!ui->namesGroupBox->isEnabled()) { // SMDH not available
|
if (!ui->namesGroupBox->isEnabled()) { // SMDH not available
|
||||||
return;
|
return;
|
||||||
@@ -141,6 +157,29 @@ void TitleInfoDialog::InitializeLanguageComboBox() {
|
|||||||
UpdateNames();
|
UpdateNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TitleInfoDialog::SaveIcon(bool large) {
|
||||||
|
const auto types = QImageWriter::supportedImageFormats();
|
||||||
|
QStringList filters;
|
||||||
|
for (const auto& type : types) {
|
||||||
|
const QString extension = QString::fromUtf8(type);
|
||||||
|
filters << QStringLiteral("%1 Image (*.%2)").arg(extension.toUpper(), extension);
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString last_path;
|
||||||
|
const QString path = QFileDialog::getSaveFileName(this, tr("Save Icon"), last_path,
|
||||||
|
filters.join(QStringLiteral(";;")));
|
||||||
|
if (path.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
last_path = QFileInfo(path).path();
|
||||||
|
|
||||||
|
const auto pixmap = large ? ui->iconLargeLabel->pixmap(Qt::ReturnByValue)
|
||||||
|
: ui->iconSmallLabel->pixmap(Qt::ReturnByValue);
|
||||||
|
if (!pixmap.save(path)) {
|
||||||
|
QMessageBox::warning(this, tr("threeSD"), tr("Could not save icon."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TitleInfoDialog::UpdateNames() {
|
void TitleInfoDialog::UpdateNames() {
|
||||||
const auto& title = smdh.titles.at(ui->languageComboBox->currentData().toInt());
|
const auto& title = smdh.titles.at(ui->languageComboBox->currentData().toInt());
|
||||||
ui->shortTitleLineEdit->setText(
|
ui->shortTitleLineEdit->setText(
|
||||||
|
|||||||
@@ -30,9 +30,11 @@ private:
|
|||||||
void LoadInfo();
|
void LoadInfo();
|
||||||
|
|
||||||
void LoadEncryption(Core::NCCHContainer& ncch);
|
void LoadEncryption(Core::NCCHContainer& ncch);
|
||||||
|
void LoadIcons();
|
||||||
void InitializeLanguageComboBox();
|
void InitializeLanguageComboBox();
|
||||||
void InitializeChecks(Core::TitleMetadata& tmd);
|
void InitializeChecks(Core::TitleMetadata& tmd);
|
||||||
|
|
||||||
|
void SaveIcon(bool large);
|
||||||
void UpdateNames();
|
void UpdateNames();
|
||||||
void ExecuteContentsCheck();
|
void ExecuteContentsCheck();
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,9 @@
|
|||||||
<height>48</height>
|
<height>48</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="contextMenuPolicy">
|
||||||
|
<enum>Qt::ActionsContextMenu</enum>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="3" rowspan="2">
|
<item row="0" column="3" rowspan="2">
|
||||||
@@ -52,6 +55,9 @@
|
|||||||
<height>24</height>
|
<height>24</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="contextMenuPolicy">
|
||||||
|
<enum>Qt::ActionsContextMenu</enum>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
|
|||||||
Reference in New Issue
Block a user