2024-07-30 11:42:36 +00:00
|
|
|
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
|
|
|
|
// SPDX-License-Identifier: GPL-3.0+
|
2021-12-13 12:12:54 +00:00
|
|
|
|
|
|
|
#pragma once
|
2023-05-13 04:30:41 +00:00
|
|
|
|
|
|
|
#include "pcsx2/GameList.h"
|
|
|
|
|
2022-07-17 05:24:59 +00:00
|
|
|
#include "common/LRUCache.h"
|
2023-05-13 04:30:41 +00:00
|
|
|
|
2021-12-13 12:12:54 +00:00
|
|
|
#include <QtCore/QAbstractTableModel>
|
|
|
|
#include <QtGui/QPixmap>
|
|
|
|
#include <algorithm>
|
2022-07-17 05:24:59 +00:00
|
|
|
#include <atomic>
|
2021-12-13 12:12:54 +00:00
|
|
|
#include <array>
|
|
|
|
#include <optional>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
class GameListModel final : public QAbstractTableModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum Column : int
|
|
|
|
{
|
|
|
|
Column_Type,
|
|
|
|
Column_Serial,
|
|
|
|
Column_Title,
|
|
|
|
Column_FileTitle,
|
|
|
|
Column_CRC,
|
2022-10-22 04:52:01 +00:00
|
|
|
Column_TimePlayed,
|
|
|
|
Column_LastPlayed,
|
2021-12-13 12:12:54 +00:00
|
|
|
Column_Size,
|
|
|
|
Column_Region,
|
|
|
|
Column_Compatibility,
|
|
|
|
Column_Cover,
|
|
|
|
|
|
|
|
Column_Count
|
|
|
|
};
|
|
|
|
|
|
|
|
static std::optional<Column> getColumnIdForName(std::string_view name);
|
|
|
|
static const char* getColumnName(Column col);
|
|
|
|
|
2022-07-09 08:52:33 +00:00
|
|
|
static QIcon getIconForType(GameList::EntryType type);
|
|
|
|
static QIcon getIconForRegion(GameList::Region region);
|
|
|
|
|
2023-09-09 04:02:43 +00:00
|
|
|
GameListModel(float cover_scale, bool show_cover_titles, QObject* parent = nullptr);
|
2021-12-13 12:12:54 +00:00
|
|
|
~GameListModel();
|
|
|
|
|
|
|
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
|
|
|
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
|
|
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
|
|
|
|
|
|
|
__fi const QString& getColumnDisplayName(int column) { return m_column_display_names[column]; }
|
|
|
|
|
|
|
|
void refresh();
|
2023-09-09 03:30:53 +00:00
|
|
|
void reloadThemeSpecificImages();
|
2021-12-13 12:12:54 +00:00
|
|
|
|
|
|
|
bool titlesLessThan(int left_row, int right_row) const;
|
|
|
|
|
|
|
|
bool lessThan(const QModelIndex& left_index, const QModelIndex& right_index, int column) const;
|
|
|
|
|
|
|
|
bool getShowCoverTitles() const { return m_show_titles_for_covers; }
|
|
|
|
void setShowCoverTitles(bool enabled) { m_show_titles_for_covers = enabled; }
|
|
|
|
|
|
|
|
float getCoverScale() const { return m_cover_scale; }
|
|
|
|
void setCoverScale(float scale);
|
|
|
|
int getCoverArtWidth() const;
|
|
|
|
int getCoverArtHeight() const;
|
|
|
|
int getCoverArtSpacing() const;
|
|
|
|
void refreshCovers();
|
2022-07-17 05:24:59 +00:00
|
|
|
void updateCacheSize(int width, int height);
|
2021-12-13 12:12:54 +00:00
|
|
|
|
2023-09-09 04:02:43 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
void coverScaleChanged();
|
|
|
|
|
2021-12-13 12:12:54 +00:00
|
|
|
private:
|
2023-11-04 11:15:20 +00:00
|
|
|
void loadSettings();
|
2021-12-13 12:12:54 +00:00
|
|
|
void loadCommonImages();
|
2023-09-09 03:30:53 +00:00
|
|
|
void loadThemeSpecificImages();
|
2021-12-13 12:12:54 +00:00
|
|
|
void setColumnDisplayNames();
|
2022-07-17 05:24:59 +00:00
|
|
|
void loadOrGenerateCover(const GameList::Entry* ge);
|
|
|
|
void invalidateCoverForPath(const std::string& path);
|
2021-12-13 12:12:54 +00:00
|
|
|
|
2024-05-14 22:11:44 +00:00
|
|
|
static QString formatTimespan(time_t timespan);
|
|
|
|
|
2022-07-17 05:24:59 +00:00
|
|
|
float m_cover_scale = 0.0f;
|
|
|
|
std::atomic<u32> m_cover_scale_counter{0};
|
2021-12-13 12:12:54 +00:00
|
|
|
bool m_show_titles_for_covers = false;
|
2023-09-09 22:36:10 +00:00
|
|
|
bool m_prefer_english_titles = false;
|
2021-12-13 12:12:54 +00:00
|
|
|
|
|
|
|
std::array<QString, Column_Count> m_column_display_names;
|
2022-07-09 08:52:33 +00:00
|
|
|
std::array<QPixmap, static_cast<u32>(GameList::EntryType::Count)> m_type_pixmaps;
|
|
|
|
std::array<QPixmap, static_cast<u32>(GameList::Region::Count)> m_region_pixmaps;
|
2021-12-13 12:12:54 +00:00
|
|
|
QPixmap m_placeholder_pixmap;
|
2022-07-17 05:24:59 +00:00
|
|
|
QPixmap m_loading_pixmap;
|
2021-12-13 12:12:54 +00:00
|
|
|
|
2022-05-29 09:14:12 +00:00
|
|
|
std::array<QPixmap, static_cast<int>(GameList::CompatibilityRatingCount)> m_compatibility_pixmaps;
|
2022-07-17 05:24:59 +00:00
|
|
|
mutable LRUCache<std::string, QPixmap> m_cover_pixmap_cache;
|
|
|
|
};
|