Skip to content

Commit

Permalink
support more icon sizes, fix initial library render, fix style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ahigerd committed Jul 4, 2022
1 parent 2297bd0 commit 2daac44
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 53 deletions.
2 changes: 0 additions & 2 deletions src/platform/qt/CMakeLists.txt
Expand Up @@ -505,8 +505,6 @@ if(BUILD_SUITE)
list(FILTER ALL_TESTS INCLUDE REGEX "^TEST_QT_.*_SRC$")
foreach(TEST_SRC ${ALL_TESTS})
string(REGEX REPLACE "^TEST_QT_(.*)_SRC$" "\\1" TEST_NAME ${TEST_SRC})
message("TEST_NAME=${TEST_NAME}")
message("TEST_SRC=${${TEST_SRC}}")
add_executable(test-qt-${TEST_NAME} WIN32 ${${TEST_SRC}})
target_link_libraries(test-qt-${TEST_NAME} ${PLATFORM_LIBRARY} ${BINARY_NAME} ${QT_LIBRARIES} ${QT}::Test)
set_target_properties(test-qt-${TEST_NAME} PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES};${FUNCTION_DEFINES};${OS_DEFINES};${QT_DEFINES}" COMPILE_OPTIONS "${FEATURE_FLAGS}")
Expand Down
4 changes: 4 additions & 0 deletions src/platform/qt/library/LibraryController.cpp
Expand Up @@ -258,6 +258,10 @@ void LibraryController::setShowFilename(bool showFilename) {
refresh();
}

void LibraryController::showEvent(QShowEvent*) {
resizeTreeView(false);
}

void LibraryController::resizeEvent(QResizeEvent*) {
resizeTreeView(false);
}
Expand Down
3 changes: 2 additions & 1 deletion src/platform/qt/library/LibraryController.h
Expand Up @@ -70,7 +70,8 @@ private slots:
void resizeTreeView(bool expand);

protected:
void resizeEvent(QResizeEvent*);
void showEvent(QShowEvent*) override;
void resizeEvent(QResizeEvent*) override;

private:
void loadDirectory(const QString&, bool recursive = true); // Called on separate thread
Expand Down
91 changes: 42 additions & 49 deletions src/platform/qt/library/LibraryModel.cpp
Expand Up @@ -17,37 +17,30 @@

using namespace QGBA;

static const QStringList iconSets{
"GBA",
"GBC",
"GB",
// "DS",
};

LibraryModel::LibraryModel(QObject* parent)
: QAbstractItemModel(parent)
, m_treeMode(false)
, m_showFilename(false)
{
QIcon iconGBA;
iconGBA.addFile(":/res/gba-icon-256.png", QSize(256, 256));
iconGBA.addFile(":/res/gba-icon-128.png");

QIcon iconGBC;
iconGBC.addFile(":/res/gbc-icon-128.png", QSize(128, 128));
iconGBC.addFile(":/res/gbc-icon-256.png", QSize(256, 256));

QIcon iconGB;
iconGB.addFile(":/res/gb-icon-128.png", QSize(128, 128));
iconGB.addFile(":/res/gb-icon-256.png", QSize(256, 256));

// QIcon iconNDS;
// iconNDS.addFile(":/res/gb-icon-128.png", QSize(128, 128));
// iconNDS.addFile(":/res/gb-icon-256.png", QSize(256, 256));

// These will silently and harmlessly fail if QSvgIconEngine isn't compiled in.
iconGBA.addFile(":/res/gba-icon.svg");
iconGBA.addFile(":/res/gbc-icon.svg");
iconGB.addFile(":/res/gb-icon.svg");
// iconNDS.addFile(":/res/nds-icon.svg");

m_icons[mPLATFORM_GBA] = iconGBA;
// m_icons[mPLATFORM_GBC] = iconGBC;
m_icons[mPLATFORM_GB] = iconGB;
// m_icons["NDS"] = iconNDS;
for (const QString& platform : iconSets) {
QString pathTemplate = QStringLiteral(":/res/%1-icon%2").arg(platform);
QIcon icon;
icon.addFile(pathTemplate.arg("-256.png"), QSize(256, 256));
icon.addFile(pathTemplate.arg("-128.png"), QSize(128, 128));
icon.addFile(pathTemplate.arg("-32.png"), QSize(32, 32));
icon.addFile(pathTemplate.arg("-24.png"), QSize(24, 24));
icon.addFile(pathTemplate.arg("-16.png"), QSize(16, 16));
// This will silently and harmlessly fail if QSvgIconEngine isn't compiled in.
icon.addFile(pathTemplate.arg(".svg"));
m_icons[platform.toLower()] = icon;
}
}

bool LibraryModel::treeMode() const {
Expand Down Expand Up @@ -353,19 +346,19 @@ QVariant LibraryModel::data(const QModelIndex& index, int role) const {
return entry->fullpath;
}
switch (index.column()) {
case COL_NAME:
if (role == Qt::DecorationRole) {
return m_icons.value(entry->platform, qApp->style()->standardIcon(QStyle::SP_FileIcon));
}
return entry->displayTitle(m_showFilename);
case COL_LOCATION:
return QDir::toNativeSeparators(entry->base);
case COL_PLATFORM:
return nicePlatformFormat(entry->platform);
case COL_SIZE:
return (role == Qt::DisplayRole) ? QVariant(niceSizeFormat(entry->filesize)) : QVariant(int(entry->filesize));
case COL_CRC32:
return (role == Qt::DisplayRole) ? QVariant(QStringLiteral("%0").arg(entry->crc32, 8, 16, QChar('0'))) : QVariant(entry->crc32);
case COL_NAME:
if (role == Qt::DecorationRole) {
return m_icons.value(nicePlatformFormat(entry->platform), qApp->style()->standardIcon(QStyle::SP_FileIcon));
}
return entry->displayTitle(m_showFilename);
case COL_LOCATION:
return QDir::toNativeSeparators(entry->base);
case COL_PLATFORM:
return nicePlatformFormat(entry->platform);
case COL_SIZE:
return (role == Qt::DisplayRole) ? QVariant(niceSizeFormat(entry->filesize)) : QVariant(int(entry->filesize));
case COL_CRC32:
return (role == Qt::DisplayRole) ? QVariant(QStringLiteral("%0").arg(entry->crc32, 8, 16, QChar('0'))) : QVariant(entry->crc32);
}
}
return QVariant();
Expand All @@ -374,16 +367,16 @@ QVariant LibraryModel::data(const QModelIndex& index, int role) const {
QVariant LibraryModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch (section) {
case COL_NAME:
return QApplication::translate("LibraryTree", "Name", nullptr);
case COL_LOCATION:
return QApplication::translate("LibraryTree", "Location", nullptr);
case COL_PLATFORM:
return QApplication::translate("LibraryTree", "Platform", nullptr);
case COL_SIZE:
return QApplication::translate("LibraryTree", "Size", nullptr);
case COL_CRC32:
return QApplication::translate("LibraryTree", "CRC32", nullptr);
case COL_NAME:
return QApplication::translate("LibraryTree", "Name", nullptr);
case COL_LOCATION:
return QApplication::translate("LibraryTree", "Location", nullptr);
case COL_PLATFORM:
return QApplication::translate("LibraryTree", "Platform", nullptr);
case COL_SIZE:
return QApplication::translate("LibraryTree", "Size", nullptr);
case COL_CRC32:
return QApplication::translate("LibraryTree", "CRC32", nullptr);
};
}
return QVariant();
Expand Down
2 changes: 1 addition & 1 deletion src/platform/qt/library/LibraryModel.h
Expand Up @@ -75,7 +75,7 @@ Q_OBJECT
QStringList m_pathOrder;
QHash<QString, QList<const LibraryEntry*>> m_pathIndex;
QHash<QString, int> m_gameIndex;
QHash<int, QIcon> m_icons;
QHash<QString, QIcon> m_icons;
};

}

0 comments on commit 2daac44

Please sign in to comment.