1818#include < QFileInfo>
1919#include < QIcon>
2020#include < QObject>
21+ #include < QPainter>
2122#include < QPixmap>
23+ #include < QSize>
2224#include < QSqlDatabase>
2325#include < QSqlError>
2426#include < QSqlQuery>
2527
2628/* *
2729 * @struct FolderNames
28- * @brief Folder names game used on windows
29- * @details These names are used by steam and installed in the common folder on linux.
30+ * @brief Folder names game used on Windows
31+ * These names are used by steam and installed in the common folder on Linux.
32+ * Except for `TombEngine (TEN)` I made that one up.
3033 */
3134struct FolderNames {
3235 const QString TR1 = " /Tomb Raider (I)" ;
3336 const QString TR2 = " /Tomb Raider (II)" ;
3437 const QString TR3 = " /TombRaider (III)" ;
3538 const QString TR4 = " /Tomb Raider (IV) The Last Revelation" ;
3639 const QString TR5 = " /Tomb Raider (V) Chronicles" ;
40+ const QString TEN = " TombEngine (TEN)" ;
3741};
3842
3943struct ZipData {
@@ -45,18 +49,10 @@ struct ZipData {
4549 */
4650 ZipData () {}
4751 ZipData (
48- QString zipName,
49- float zipSize,
50- QString md5sum,
51- QString url,
52- int version,
53- const QString& release) :
54- name (zipName),
55- megabyteSize (zipSize),
56- md5sum (md5sum),
57- url (url),
58- version (version),
59- release (release) {}
52+ QString zipName, float zipSize, QString md5sum, QString url,
53+ int version, const QString& release) :
54+ name (zipName), megabyteSize(zipSize), md5sum(md5sum),
55+ url (url), version(version), release(release) {}
6056 QString name;
6157 float megabyteSize;
6258 QString md5sum;
@@ -65,51 +61,90 @@ struct ZipData {
6561 QString release;
6662};
6763
64+ /* *
65+ * @struct ListItemData
66+ * @brief Represents a Tomb Raider Level Entry Card.
67+ *
68+ * This struct is designed to store a single TRLE (Tomb Raider Level Editor) level record.
69+ * Each record contains metadata and a cover image displayed as a card in the application.
70+ * The struct includes properties to facilitate searching, filtering, and sorting.
71+ */
6872struct ListItemData {
6973 /* *
70- * @struct InfoData
71- * @brief
72- * @param
73- * @details
74+ * @brief Default constructor for `ListItemData`.
75+ *
76+ * Initializes an empty instance of `ListItemData`.
7477 */
7578 ListItemData () {}
79+
80+ /* *
81+ * @brief Parameterized constructor for `ListItemData`.
82+ *
83+ * This constructor initializes a `ListItemData` object with metadata and a cover image.
84+ * The image is converted from raw `QByteArray` to a `QIcon` after scaling it to
85+ * fit within 640x480 dimensions. The scaling maintains the aspect ratio and
86+ * smooths out pixels using `Qt::SmoothTransformation`. The image is centered
87+ * within a transparent background if its aspect ratio does not perfectly match the target.
88+ *
89+ * @param title The TRLE title. Expected to contain a single name.
90+ * @param author The TRLE author(s). Can be a single name or multiple names separated by commas and spaces.
91+ * @param type The TRLE type, represented by a numeric ID.
92+ * @param classInput The TRLE class, represented by a numeric ID.
93+ * @param releaseDate The release date in the format "DD-MMM-YYYY" (e.g., "01-Jan-2000").
94+ * @param difficulty The TRLE difficulty, represented by a numeric ID.
95+ * @param duration The TRLE duration, represented by a numeric ID.
96+ * @param imageData The cover image as a `QByteArray`. Supported formats include JPEG, PNG, and WEBP.
97+ */
7698 ListItemData (
77- QString title,
78- QString author,
79- qint64 type,
80- qint64 classIn,
81- QString releaseDate,
82- qint64 difficulty,
83- qint64 duration,
99+ QString title, QString author, qint64 type, qint64 classInput,
100+ QString releaseDate, qint64 difficulty, qint64 duration,
84101 QByteArray imageData):
85- title (title),
86- author (author),
87- type (type),
88- class_ (classIn),
89- releaseDate (releaseDate),
90- difficulty (difficulty),
91- duration (duration) {
102+ m_title (title), m_author(author), m_type(type),
103+ m_class (classInput), m_releaseDate(releaseDate),
104+ m_difficulty (difficulty), m_duration(duration) {
105+ // Load the image from the byte array
92106 QPixmap pixmap;
93107 pixmap.loadFromData (imageData, " WEBP" );
94- picture.addPixmap (pixmap);
95- // Scale the pixmap while maintaining aspect ratio
96- QSize newSize = pixmap.size ().scaled (640 , 480 , Qt::KeepAspectRatio);
97- // Resize the pixmap to the scaled size
98- pixmap = pixmap.scaled (
108+
109+ // Define target dimensions and maintain aspect ratio
110+ QSize targetSize (640 , 480 );
111+ QSize newSize = pixmap.size ().scaled (targetSize, Qt::KeepAspectRatio);
112+
113+ // Scale the pixmap
114+ QPixmap scaledPixmap = pixmap.scaled (
99115 newSize,
100116 Qt::KeepAspectRatio,
101117 Qt::SmoothTransformation);
102- // Create QIcon and add the scaled pixmap
103- picture.addPixmap (pixmap);
118+
119+ // Create a centered pixmap with a transparent background
120+ QPixmap centeredPixmap (targetSize);
121+ // Ensure a transparent background
122+ centeredPixmap.fill (Qt::transparent);
123+
124+ // Calculate offsets for centering the scaled image
125+ qint64 xOffset = (targetSize.width () - newSize.width ()) / 2 ;
126+ qint64 yOffset = (targetSize.height () - newSize.height ()) / 2 ;
127+
128+ // Draw the scaled image onto the centered pixmap
129+ QPainter painter (¢eredPixmap);
130+ painter.setRenderHint (QPainter::Antialiasing, true );
131+ painter.setRenderHint (QPainter::SmoothPixmapTransform, true );
132+ painter.drawPixmap (xOffset, yOffset, scaledPixmap);
133+ painter.end ();
134+
135+ // Store the resulting pixmap in a QIcon
136+ m_picture.addPixmap (centeredPixmap);
104137 }
105- QString title;
106- QString author;
107- qint64 type;
108- qint64 class_;
109- QString releaseDate;
110- qint64 difficulty;
111- qint64 duration;
112- QIcon picture;
138+
139+ // Data members
140+ QString m_title; // /< The TRLE level title.
141+ QString m_author; // /< The TRLE author(s), as a string.
142+ qint64 m_type; // /< ID of the type of level.
143+ qint64 m_class; // /< ID of the class of the level.
144+ QString m_releaseDate; // /< The release date in "DD-MMM-YYYY" format.
145+ qint64 m_difficulty; // /< ID of the difficulty of the level.
146+ qint64 m_duration; // /< ID of the estimated duration of the level.
147+ QIcon m_picture; // /< The cover image.
113148};
114149
115150/* *
0 commit comments