game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
steamgriddb_selector_dialog.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// qt/steamgriddb_selector_dialog.h
4// ==============================================================================
5// Dialog for browsing and selecting game artwork from SteamGridDB
6// ==============================================================================
7
8#pragma once
9
11
12#include <QComboBox>
13#include <QDialog>
14#include <QLabel>
15#include <QLineEdit>
16#include <QListWidget>
17#include <QProgressBar>
18#include <QPushButton>
19#include <QStackedWidget>
20#include <QTabWidget>
21#include <QThread>
22#include <atomic>
23#include <memory>
24
25// Forward declarations
26class QScrollArea;
27class QGridLayout;
29class ThemeManager;
30
31// ==============================================================================
32// Image Type Enum
33// ==============================================================================
34
36{
37 Grid, // Cover art (600x900)
38 Hero, // Wide banner
39 Logo, // Logo with transparency
40 Icon // Small icon
41};
42
43// ==============================================================================
44// Search Worker - Runs searches in background thread
45// ==============================================================================
46
47class SteamGridDBSearchWorker : public QObject
48{
49 Q_OBJECT
50
51 public:
52 explicit SteamGridDBSearchWorker(QObject* parent = nullptr);
53
54 void setSearchQuery(const QString& query);
55 void setGameId(int gameId);
57 void setSteamAppId(int appId);
58
59 signals:
60 void searchComplete(const std::vector<SteamGridDBGame>& games);
61 void imagesLoaded(const std::vector<SteamGridDBImage>& images);
62 void downloadComplete(bool success, const QString& localPath);
63 void error(const QString& message);
64
65 public slots:
66 void doSearch();
67 void doLoadImages();
68 void doDownloadImage(const SteamGridDBImage& image, const QString& gameName);
69 void cancel();
70
71 private:
72 QString searchQuery_;
73 int gameId_ = 0;
74 int steamAppId_ = 0;
76 std::atomic<bool> cancelled_{false};
77};
78
79// ==============================================================================
80// Image Preview Widget - Shows a single artwork option
81// ==============================================================================
82
83class ArtworkPreviewWidget : public QFrame
84{
85 Q_OBJECT
86
87 public:
88 explicit ArtworkPreviewWidget(const SteamGridDBImage& image, QWidget* parent = nullptr,
89 ThemeManager* themeManager = nullptr);
90
91 const SteamGridDBImage& image() const
92 {
93 return image_;
94 }
95 void setSelected(bool selected);
96 bool isSelected() const
97 {
98 return selected_;
99 }
100 void setThumbnail(const QPixmap& pixmap);
101
102 signals:
103 void clicked();
105
106 protected:
107 void paintEvent(QPaintEvent* event) override;
108 void mousePressEvent(QMouseEvent* event) override;
109 void mouseDoubleClickEvent(QMouseEvent* event) override;
110 void enterEvent(QEnterEvent* event) override;
111 void leaveEvent(QEvent* event) override;
112
113 public slots:
114 void applyTheme();
115
116 private:
117 SteamGridDBImage image_;
118 QLabel* thumbnailLabel_ = nullptr;
119 QLabel* infoLabel_ = nullptr;
120 bool selected_ = false;
121 bool hovered_ = false;
122 ThemeManager* themeManager_;
123};
124
125// ==============================================================================
126// SteamGridDB Selector Dialog
127// ==============================================================================
128
129class SteamGridDBSelectorDialog : public QDialog
130{
131 Q_OBJECT
132
133 public:
134 explicit SteamGridDBSelectorDialog(QWidget* parent = nullptr,
135 ThemeManager* themeManager = nullptr);
137
138 // Set the game to find artwork for
139 void setGame(const QString& gameName, int steamAppId = 0);
140
141 // Get selected image paths after dialog closes
142 QString getSelectedGridPath() const
143 {
144 return selectedGridPath_;
145 }
146 QString getSelectedHeroPath() const
147 {
148 return selectedHeroPath_;
149 }
150 QString getSelectedLogoPath() const
151 {
152 return selectedLogoPath_;
153 }
154 QString getSelectedIconPath() const
155 {
156 return selectedIconPath_;
157 }
158
159 // Check if any selection was made
160 bool hasSelection() const;
161
162 private slots:
163 void onSearchClicked();
164 void onGameSelected(QListWidgetItem* item);
165 void onImageTypeChanged(int index);
166 void onSearchComplete(const std::vector<SteamGridDBGame>& games);
167 void onImagesLoaded(const std::vector<SteamGridDBImage>& images);
168 void onDownloadComplete(bool success, const QString& localPath);
169 void onError(const QString& message);
170 void onImageClicked(ArtworkPreviewWidget* widget);
171 void onImageDoubleClicked(ArtworkPreviewWidget* widget);
172 void onApplyClicked();
173 void applyTheme();
174
175 private:
176 void setupUI();
177 void setupSearchPanel(QWidget* panel);
178 void setupImagePanel(QWidget* panel);
179 void clearImageGrid();
180 void loadThumbnails();
181 void downloadSelectedImage();
182 void startSearch(const QString& query);
183 void loadImagesForGame(int gameId);
184
185 QString gameName_;
186 int steamAppId_ = 0;
187 int selectedGameId_ = 0;
188
189 // Selected image paths (result)
190 QString selectedGridPath_;
191 QString selectedHeroPath_;
192 QString selectedLogoPath_;
193 QString selectedIconPath_;
194
195 // Current type being viewed
197
198 // UI Components
199 QLineEdit* searchEdit_ = nullptr;
200 QPushButton* searchBtn_ = nullptr;
201 QListWidget* gameList_ = nullptr;
202 QLabel* gameInfoLabel_ = nullptr;
203 QComboBox* imageTypeCombo_ = nullptr;
204 QScrollArea* imageScrollArea_ = nullptr;
205 QWidget* imageGridWidget_ = nullptr;
206 QGridLayout* imageGridLayout_ = nullptr;
207 QLabel* statusLabel_ = nullptr;
208 QProgressBar* progressBar_ = nullptr;
209 QPushButton* applyBtn_ = nullptr;
210 QPushButton* cancelBtn_ = nullptr;
211 QStackedWidget* contentStack_ = nullptr;
212
213 // Current selection per type
214 ArtworkPreviewWidget* selectedGridWidget_ = nullptr;
215 ArtworkPreviewWidget* selectedHeroWidget_ = nullptr;
216 ArtworkPreviewWidget* selectedLogoWidget_ = nullptr;
217 ArtworkPreviewWidget* selectedIconWidget_ = nullptr;
218
219 // Image loading
220 std::vector<ArtworkPreviewWidget*> previewWidgets_;
221 AsyncImageLoader* thumbnailLoader_ = nullptr;
222
223 // Threading
224 QThread* workerThread_ = nullptr;
225 SteamGridDBSearchWorker* worker_ = nullptr;
226 std::atomic<bool> loading_{false};
227
228 ThemeManager* themeManager_;
229};
void setThumbnail(const QPixmap &pixmap)
void paintEvent(QPaintEvent *event) override
void mousePressEvent(QMouseEvent *event) override
void leaveEvent(QEvent *event) override
const SteamGridDBImage & image() const
void mouseDoubleClickEvent(QMouseEvent *event) override
void enterEvent(QEnterEvent *event) override
ArtworkPreviewWidget(const SteamGridDBImage &image, QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
Async image loader using QThreadPool.
void error(const QString &message)
void downloadComplete(bool success, const QString &localPath)
SteamGridDBSearchWorker(QObject *parent=nullptr)
void setSearchQuery(const QString &query)
void searchComplete(const std::vector< SteamGridDBGame > &games)
void setImageType(SteamGridImageType type)
void imagesLoaded(const std::vector< SteamGridDBImage > &images)
void doDownloadImage(const SteamGridDBImage &image, const QString &gameName)
SteamGridDBSelectorDialog(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
void setGame(const QString &gameName, int steamAppId=0)
Image result from SteamGridDB.