diff --git a/src/platform/qt/CMakeLists.txt b/src/platform/qt/CMakeLists.txt index 4c732bc5a37..f4250367f51 100644 --- a/src/platform/qt/CMakeLists.txt +++ b/src/platform/qt/CMakeLists.txt @@ -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}") diff --git a/src/platform/qt/library/LibraryController.cpp b/src/platform/qt/library/LibraryController.cpp index aa22a20ee58..ed78ce410d2 100644 --- a/src/platform/qt/library/LibraryController.cpp +++ b/src/platform/qt/library/LibraryController.cpp @@ -258,6 +258,10 @@ void LibraryController::setShowFilename(bool showFilename) { refresh(); } +void LibraryController::showEvent(QShowEvent*) { + resizeTreeView(false); +} + void LibraryController::resizeEvent(QResizeEvent*) { resizeTreeView(false); } diff --git a/src/platform/qt/library/LibraryController.h b/src/platform/qt/library/LibraryController.h index c84acdcf3a8..8a14f3a4b01 100644 --- a/src/platform/qt/library/LibraryController.h +++ b/src/platform/qt/library/LibraryController.h @@ -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 diff --git a/src/platform/qt/library/LibraryModel.cpp b/src/platform/qt/library/LibraryModel.cpp index 42b1cb01060..bc08228c10a 100644 --- a/src/platform/qt/library/LibraryModel.cpp +++ b/src/platform/qt/library/LibraryModel.cpp @@ -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 { @@ -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(); @@ -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(); diff --git a/src/platform/qt/library/LibraryModel.h b/src/platform/qt/library/LibraryModel.h index 51083a4b8ad..db220392fb5 100644 --- a/src/platform/qt/library/LibraryModel.h +++ b/src/platform/qt/library/LibraryModel.h @@ -75,7 +75,7 @@ Q_OBJECT QStringList m_pathOrder; QHash> m_pathIndex; QHash m_gameIndex; - QHash m_icons; + QHash m_icons; }; }