game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
game_list_delegate.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// qt/game_list_delegate.h
4// ==============================================================================
5// Custom delegate for rendering game list items with rich visual information
6// ==============================================================================
7
8#pragma once
9
10#include "theme_manager.h"
11
12#include <QColor>
13#include <QFont>
14#include <QMouseEvent>
15#include <QPainter>
16#include <QPainterPath>
17#include <QStyledItemDelegate>
18
19// Forward declaration
20enum class ViewMode;
21
22// ==============================================================================
23// Custom data roles for game information
24// ==============================================================================
25
27{
28 GameIdRole = Qt::UserRole,
29 GameSourceRole = Qt::UserRole + 1,
30 GameRunnerRole = Qt::UserRole + 2,
31 GamePlayTimeRole = Qt::UserRole + 3,
32 GameLastPlayedRole = Qt::UserRole + 4,
33 GameLaunchCountRole = Qt::UserRole + 5,
34 GameIsRunningRole = Qt::UserRole + 6,
35 GameIsFavoriteRole = Qt::UserRole + 7,
36 GameProtonDBTierRole = Qt::UserRole + 8,
37 GamePlatformRole = Qt::UserRole + 9,
38 GameIsInstalledRole = Qt::UserRole + 10,
39 GameIsSteamRole = Qt::UserRole + 11,
40 GameNeedsUpdateRole = Qt::UserRole + 12,
41 GameIsDownloadingRole = Qt::UserRole + 13,
42 GameDownloadProgressRole = Qt::UserRole + 14,
43 GameCloudSaveEnabledRole = Qt::UserRole + 15,
44 GameInstallSizeRole = Qt::UserRole + 16,
45 GameSteamAppIdRole = Qt::UserRole + 17
46};
47
48// ==============================================================================
49// GameListDelegate - Rich rendering for game list items
50// ==============================================================================
51
52class GameListDelegate : public QStyledItemDelegate
53{
54 public:
55 explicit GameListDelegate(QObject* parent = nullptr);
56
58 {
59 viewMode_ = mode;
60 }
62 {
63 return viewMode_;
64 }
65
66 void setZoomLevel(int level);
67 int zoomLevel() const
68 {
69 return zoomLevel_;
70 }
71
72 // Call this when theme changes to update cached colors
74 {
75 cachedColors_ = ThemeManager::instance().colors();
76 }
77 const ThemeColors& colors() const
78 {
79 return cachedColors_;
80 }
81
82 // Get zoom factor as a multiplier
83 double zoomFactor() const
84 {
85 return zoomLevel_ / 100.0;
86 }
87
88 // Update cached fonts (call when zoom changes)
89 void updateCachedFonts();
90
91 QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
92 void paint(QPainter* painter, const QStyleOptionViewItem& option,
93 const QModelIndex& index) const override;
94 bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option,
95 const QModelIndex& index) override;
96
97 static QColor getProtonDBTierColor(const QString& tier);
98
99 private:
100 void paintListMode(QPainter* painter, const QRect& rect, const QIcon& icon, const QString& name,
101 const QString& source, const QString& runner, int playTimeSeconds,
102 qint64 lastPlayed, int launchCount, bool isRunning, bool isFavorite,
103 bool isInstalled, bool isSteam, bool isSelected, bool needsUpdate,
104 bool isDownloading, double downloadProgress, bool hasCloudSave,
105 qint64 installSize, const QString& protondbTier) const;
106
107 void paintCompactMode(QPainter* painter, const QRect& rect, const QIcon& icon,
108 const QString& name, const QString& source, const QString& runner,
109 int playTimeSeconds, bool isRunning, bool isFavorite, bool isInstalled,
110 bool isSteam, bool isSelected, bool needsUpdate, bool isDownloading,
111 double downloadProgress, bool hasCloudSave,
112 const QString& protondbTier) const;
113
114 void paintGridMode(QPainter* painter, const QStyleOptionViewItem& option,
115 const QModelIndex& index) const;
116
117 ViewMode viewMode_;
118 int zoomLevel_;
119 ThemeColors cachedColors_;
120
121 // Cached fonts (updated when zoom changes)
122 QFont nameFont_;
123 QFont infoFont_;
124 QFont smallFont_;
125};
static QColor getProtonDBTierColor(const QString &tier)
void setZoomLevel(int level)
ViewMode viewMode() const
GameListDelegate(QObject *parent=nullptr)
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
double zoomFactor() const
void setViewMode(ViewMode mode)
const ThemeColors & colors() const
static ThemeManager & instance()
const ThemeColors & colors() const
Get effective colors (with accent customization applied).
@ GameRunnerRole
@ GameProtonDBTierRole
@ GameNeedsUpdateRole
@ GameCloudSaveEnabledRole
@ GameIdRole
@ GameIsSteamRole
@ GamePlatformRole
@ GameSourceRole
@ GameInstallSizeRole
@ GameIsDownloadingRole
@ GameIsRunningRole
@ GameLastPlayedRole
@ GameDownloadProgressRole
@ GameIsInstalledRole
@ GameLaunchCountRole
@ GamePlayTimeRole
@ GameSteamAppIdRole
@ GameIsFavoriteRole
ViewMode
Definition mainwindow.h:75