diff --git a/src/platform/qt/library/LibraryEntry.cpp b/src/platform/qt/library/LibraryEntry.cpp index 920489d8607..27feb64e89d 100644 --- a/src/platform/qt/library/LibraryEntry.cpp +++ b/src/platform/qt/library/LibraryEntry.cpp @@ -31,8 +31,8 @@ bool LibraryEntry::isNull() const { return fullpath.isNull(); } -QString LibraryEntry::displayTitle() const { - if (title.isNull()) { +QString LibraryEntry::displayTitle(bool showFilename) const { + if (showFilename || title.isNull()) { return filename; } return title; diff --git a/src/platform/qt/library/LibraryEntry.h b/src/platform/qt/library/LibraryEntry.h index 024c79d8caa..2a733db4ab0 100644 --- a/src/platform/qt/library/LibraryEntry.h +++ b/src/platform/qt/library/LibraryEntry.h @@ -24,7 +24,7 @@ struct LibraryEntry { bool isNull() const; - QString displayTitle() const; + QString displayTitle(bool showFilename = false) const; QString base; QString filename; diff --git a/src/platform/qt/library/LibraryModel.cpp b/src/platform/qt/library/LibraryModel.cpp index 20e1dbcbcab..42b1cb01060 100644 --- a/src/platform/qt/library/LibraryModel.cpp +++ b/src/platform/qt/library/LibraryModel.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -21,6 +22,32 @@ LibraryModel::LibraryModel(QObject* 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; } bool LibraryModel::treeMode() const { @@ -274,27 +301,51 @@ int LibraryModel::rowCount(const QModelIndex& parent) const { return m_games.size(); } +QVariant LibraryModel::folderData(const QModelIndex& index, int role) const +{ + // Precondition: index and role must have already been validated + if (role == Qt::DecorationRole) { + return qApp->style()->standardIcon(QStyle::SP_DirOpenIcon); + } + if (role == FullPathRole || (index.column() == COL_LOCATION && role != Qt::DisplayRole)) { + return m_pathOrder[index.row()]; + } + if (index.column() == COL_NAME) { + QString path = m_pathOrder[index.row()]; + return path.section('/', -1); + } + return QVariant(); +} + QVariant LibraryModel::data(const QModelIndex& index, int role) const { + if (role != Qt::DisplayRole && + role != Qt::EditRole && + role != Qt::ToolTipRole && + role != Qt::DecorationRole && + role != Qt::TextAlignmentRole && + role != FullPathRole) { + return QVariant(); + } if (!checkIndex(index)) { return QVariant(); } - // TODO: Qt::DecorationRole - if (role == Qt::DisplayRole || role == Qt::EditRole || (role == Qt::ToolTipRole && index.column() <= COL_LOCATION) || role == FullPathRole) { - const LibraryEntry* entry = nullptr; - if (m_treeMode) { - if (!index.parent().isValid()) { - if (role == FullPathRole || (index.column() == COL_LOCATION && role != Qt::DisplayRole)) { - return m_pathOrder[index.row()]; - } - if (index.column() == COL_NAME) { - QString path = m_pathOrder[index.row()]; - return path.section('/', -1); - } - return QVariant(); - } - QString path = m_pathOrder[index.parent().row()]; - entry = m_pathIndex[path][index.row()]; - } else if (!index.parent().isValid() && index.row() < m_games.size()) { + if (role == Qt::ToolTipRole && index.column() > COL_LOCATION) { + return QVariant(); + } + if (role == Qt::DecorationRole && index.column() != COL_NAME) { + return QVariant(); + } + if (role == Qt::TextAlignmentRole) { + return index.column() == COL_SIZE ? (int)(Qt::AlignTrailing | Qt::AlignVCenter) : (int)(Qt::AlignLeading | Qt::AlignVCenter); + } + const LibraryEntry* entry = nullptr; + if (m_treeMode) { + if (!index.parent().isValid()) { + return folderData(index, role); + } + QString path = m_pathOrder[index.parent().row()]; + entry = m_pathIndex[path][index.row()]; + } else if (!index.parent().isValid() && index.row() < m_games.size()) { entry = &m_games[index.row()]; } if (entry) { @@ -303,7 +354,10 @@ QVariant LibraryModel::data(const QModelIndex& index, int role) const { } switch (index.column()) { case COL_NAME: - return m_showFilename ? entry->filename : entry->displayTitle(); + 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: @@ -314,9 +368,6 @@ QVariant LibraryModel::data(const QModelIndex& index, int role) const { return (role == Qt::DisplayRole) ? QVariant(QStringLiteral("%0").arg(entry->crc32, 8, 16, QChar('0'))) : QVariant(entry->crc32); } } - } else if (role == Qt::TextAlignmentRole) { - return index.column() == COL_SIZE ? (int)(Qt::AlignTrailing | Qt::AlignVCenter) : (int)(Qt::AlignLeading | Qt::AlignVCenter); - } return QVariant(); } diff --git a/src/platform/qt/library/LibraryModel.h b/src/platform/qt/library/LibraryModel.h index fb94fb99b88..51083a4b8ad 100644 --- a/src/platform/qt/library/LibraryModel.h +++ b/src/platform/qt/library/LibraryModel.h @@ -6,6 +6,7 @@ #pragma once #include +#include #include #include @@ -61,6 +62,8 @@ Q_OBJECT QModelIndex indexForPath(const QString& path); QModelIndex indexForPath(const QString& path) const; + QVariant folderData(const QModelIndex& index, int role = Qt::DisplayRole) const; + void addEntriesList(const QList& items); void addEntriesTree(const QList& items); void addEntryInternal(const LibraryEntry& item); @@ -72,6 +75,7 @@ Q_OBJECT QStringList m_pathOrder; QHash> m_pathIndex; QHash m_gameIndex; + QHash m_icons; }; } diff --git a/src/platform/qt/resources.qrc b/src/platform/qt/resources.qrc index 737ec55f009..5dd3bb1ebeb 100644 --- a/src/platform/qt/resources.qrc +++ b/src/platform/qt/resources.qrc @@ -6,6 +6,15 @@ ../../../res/keymap.qpic ../../../res/patrons.txt ../../../res/no-cam.png + ../../../res/gb-icon-256.png + ../../../res/gb-icon-128.png + ../../../res/gb-icon.svg + ../../../res/gbc-icon-256.png + ../../../res/gbc-icon-128.png + ../../../res/gbc-icon.svg + ../../../res/gba-icon-256.png + ../../../res/gba-icon-128.png + ../../../res/gba-icon.svg ../../../res/exe4/chip-names.txt