Skip to content

Commit a6e6c9c

Browse files
committed
show some level cover pictures
and it looks terrible... the data is comming thru, but its flashing or freezing the window in like 0.42 secunds also...
1 parent 69c2bda commit a6e6c9c

File tree

9 files changed

+115
-129
lines changed

9 files changed

+115
-129
lines changed

src/Controller.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* GNU General Public License for more details.
1212
*/
1313

14-
#include "Controller.hpp"
14+
#include "../src/Controller.hpp"
1515
#include <QDebug>
1616

1717
Controller::Controller() : controllerThread(new QThread()) {
@@ -99,6 +99,10 @@ void Controller::getList(QVector<ListItemData>* list) {
9999
model.getList(list);
100100
}
101101

102+
void Controller::getCoverList(QVector<ListItemData*>* list) {
103+
model.getCoverList(list);
104+
}
105+
102106
const InfoData Controller::getInfo(int id) {
103107
return model.getInfo(id);
104108
}

src/Controller.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define SRC_CONTROLLER_HPP_
1616
#include <QObject>
1717
#include <QThread>
18-
#include "Model.hpp"
18+
#include "../src/Model.hpp"
1919

2020
/**
2121
* The controller activate UI thread work or light instant work on the model
@@ -38,6 +38,7 @@ class Controller : public QObject {
3838
void setupLevel(int id);
3939

4040
void getList(QVector<ListItemData>* list);
41+
void getCoverList(QVector<ListItemData*>* list);
4142
const InfoData getInfo(int id);
4243
const QString getWalkthrough(int id);
4344
bool link(int id);

src/Data.cpp

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* TombRaiderLinuxLauncher
2-
* Martin Bångens Copyright (C) 2024
2+
* Martin Bångens Copyright (C) 2025
33
* This program is free software: you can redistribute it and/or modify
44
* it under the terms of the GNU General Public License as published by
55
* the Free Software Foundation, either version 3 of the License, or
@@ -56,7 +56,8 @@ QVector<ListItemData> Data::getListItems() {
5656
"JOIN Author ON AuthorList.authorID = Author.AuthorID "
5757
"GROUP BY Info.trleID");
5858
if (!status) {
59-
qDebug() << "Error preparing query getListItems:" << query.lastError().text();
59+
qDebug() << "Error preparing query getListItems:"
60+
<< query.lastError().text();
6061
}
6162

6263
if (status) {
@@ -73,51 +74,50 @@ QVector<ListItemData> Data::getListItems() {
7374
query.value("Info.duration").toInt()));
7475
}
7576
} else {
76-
qDebug() << "Error executing query getListItems:" << query.lastError().text();
77+
qDebug() << "Error executing query getListItems:"
78+
<< query.lastError().text();
7779
}
7880
}
7981

8082
return items;
8183
}
8284

83-
QVector<ListItemPicture> Data::getPictures(QList<qint64> trle_ids) {
84-
bool status = true;
85+
void Data::getCoverPictures(QVector<ListItemData*>* items) {
8586
QSqlQuery query(db);
86-
QVector<ListItemPicture> items;
8787

88-
foreach(const qint64 &id, trle_ids) {
89-
status = query.prepare(
90-
"SELECT Info.trleID, Picture.data "
91-
"FROM Level "
92-
"JOIN Info ON Level.infoID = Info.InfoID "
93-
"JOIN Screens ON Level.LevelID = Screens.levelID "
94-
"JOIN Picture ON Screens.pictureID = Picture.PictureID "
95-
"WHERE Info.trleID = :id AND Screens.position = 0 ");
96-
query.bindValue(":id", id);
97-
if (!status) {
98-
qDebug() << "Error preparing query getPictures:" << query.lastError().text();
99-
}
88+
bool status = query.prepare(
89+
"SELECT Info.trleID, Picture.data "
90+
"FROM Level "
91+
"JOIN Info ON Level.infoID = Info.InfoID "
92+
"JOIN Screens ON Level.LevelID = Screens.levelID "
93+
"JOIN Picture ON Screens.pictureID = Picture.PictureID "
94+
"WHERE Info.trleID = :id AND Screens.position = 0 ");
95+
if (!status) {
96+
qDebug() << "Error preparing query getPictures:"
97+
<< query.lastError().text();
98+
}
10099

101-
if (status) {
100+
if (status) {
101+
qint64 size = items->size();
102+
for (qint64 i = size-100; i < size; i++) {
103+
ListItemData* level = (*items)[i];
104+
query.bindValue(":id", level->m_trle_id);
102105
if (query.exec()) {
103106
if (query.next() == true) {
104-
items.append(ListItemPicture(
105-
query.value("Info.trleID").toInt(),
106-
query.value("Picture.data").toByteArray()));
107+
level->addPicture(
108+
query.value("Picture.data").toByteArray());
107109
}
108110
} else {
109-
qDebug() << "Error executing query getPictures:" << query.lastError().text();
111+
qDebug() << "Error executing query getPictures:"
112+
<< query.lastError().text();
110113
}
111114
}
112115
}
113-
114-
return items;
115116
}
116117

117118
InfoData Data::getInfo(const int id) {
118119
QSqlQuery query(db);
119120
bool status = false;
120-
QVector<QByteArray> imageList;
121121
InfoData result;
122122

123123
status = query.prepare(
@@ -131,6 +131,7 @@ InfoData Data::getInfo(const int id) {
131131
if (status) {
132132
if (query.exec() == true) {
133133
if (query.next() == true) {
134+
QVector<QByteArray> imageList;
134135
QString body = query.value("body").toString();
135136
// notice that we jump over the fist image
136137
// the first image is the cover image

src/Data.hpp

Lines changed: 37 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -92,35 +92,47 @@ struct ZipData {
9292
QString release;
9393
};
9494

95+
9596
/**
96-
* @struct ListItemPicture
97-
* @brief Represents a Tomb Raider Level Entry Card Picture.
97+
* @struct ListItemData
98+
* @brief Represents a Tomb Raider Level Entry Card Info.
9899
*
99-
* This struct is designed to store a single TRLE (Tomb Raider Level Editor) level picture record.
100-
* Each record is a cover image displayed as a card in the application.
100+
* This struct is designed to store a single TRLE (Tomb Raider Level Editor) level record.
101+
* Each record contains metadata and a cover image displayed as a card in the application.
102+
* The struct includes properties to facilitate searching, filtering, and sorting.
101103
*/
102-
struct ListItemPicture {
104+
struct ListItemData {
103105
/**
104-
* @brief Default constructor for `ListItemPicture`.
106+
* @brief Default constructor for `ListItemData`.
105107
*
106-
* Initializes an empty instance of `ListItemPicture`.
108+
* Initializes an empty instance of `ListItemData`.
107109
*/
108-
ListItemPicture() {}
110+
ListItemData() {}
109111

110112
/**
111-
* @brief Parameterized constructor for `ListItemPicture`.
113+
* @brief Parameterized constructor for `ListItemData`.
112114
*
113-
* This constructor initializes a `ListItemPicture` object with a cover image.
114-
* The image is converted from raw `QByteArray` to a `QIcon` after scaling it to
115-
* fit within 640x480 dimensions. The scaling maintains the aspect ratio and
116-
* smooths out pixels using `Qt::SmoothTransformation`. The image is centered
117-
* within a transparent background if its aspect ratio does not perfectly match the target.
115+
* This constructor initializes a `ListItemData` object with metadata.
118116
*
119117
* @param id The TRLE numeric level ID.
120-
* @param imageData The cover image as a `QByteArray`. Supported formats include JPEG, PNG, and WEBP.
118+
* @param title The TRLE title. Expected to contain a single name.
119+
* @param author The TRLE author(s). Can be a single name or multiple names.
120+
* @param type The TRLE type, represented by a numeric ID.
121+
* @param classInput The TRLE class, represented by a numeric ID.
122+
* @param releaseDate The release date in the format "YYYY-MM-DD" (e.g., "2000-01-01").
123+
* @param difficulty The TRLE difficulty, represented by a numeric ID.
124+
* @param duration The TRLE duration, represented by a numeric ID.
125+
* @param m_cover The cover image as a `m_cover`.
121126
*/
122-
ListItemPicture(
123-
qint64 id, QByteArray imageData) : m_trle_id(id) {
127+
ListItemData(
128+
qint64 id, const QString& title, const QStringList& authors,
129+
qint64 type, qint64 classInput, const QString& releaseDate,
130+
qint64 difficulty, qint64 duration) :
131+
m_trle_id(id), m_title(title), m_authors(authors), m_type(type),
132+
m_class(classInput), m_releaseDate(releaseDate),
133+
m_difficulty(difficulty), m_duration(duration) {}
134+
135+
void addPicture(const QByteArray& imageData) {
124136
// Load the image from the byte array
125137
QPixmap pixmap;
126138
pixmap.loadFromData(imageData, "WEBP");
@@ -151,57 +163,9 @@ struct ListItemPicture {
151163
painter.drawPixmap(xOffset, yOffset, scaledPixmap);
152164
painter.end();
153165

154-
// Store the resulting pixmap in a QIcon
155-
m_picture.addPixmap(centeredPixmap);
166+
// Store the resulting pixmap in m_picture
167+
m_cover = centeredPixmap;
156168
}
157-
158-
// Data members
159-
qint64 m_trle_id; ///< The TRLE level id.
160-
QIcon m_picture; ///< The cover image.
161-
};
162-
163-
/**
164-
* @struct ListItemData
165-
* @brief Represents a Tomb Raider Level Entry Card Info.
166-
*
167-
* This struct is designed to store a single TRLE (Tomb Raider Level Editor) level record.
168-
* Each record contains metadata and a cover image displayed as a card in the application.
169-
* The struct includes properties to facilitate searching, filtering, and sorting without
170-
* the cover image, just a pointer.
171-
*/
172-
struct ListItemData {
173-
/**
174-
* @brief Default constructor for `ListItemData`.
175-
*
176-
* Initializes an empty instance of `ListItemData`.
177-
*/
178-
ListItemData() {}
179-
180-
/**
181-
* @brief Parameterized constructor for `ListItemData`.
182-
*
183-
* This constructor initializes a `ListItemData` object with metadata.
184-
*
185-
* @param id The TRLE numeric level ID.
186-
* @param title The TRLE title. Expected to contain a single name.
187-
* @param author The TRLE author(s). Can be a single name or multiple names.
188-
* @param type The TRLE type, represented by a numeric ID.
189-
* @param classInput The TRLE class, represented by a numeric ID.
190-
* @param releaseDate The release date in the format "YYYY-MM-DD" (e.g., "2000-01-01").
191-
* @param difficulty The TRLE difficulty, represented by a numeric ID.
192-
* @param duration The TRLE duration, represented by a numeric ID.
193-
* @param m_cover The cover image as a `ListItemPicture*`.
194-
*/
195-
ListItemData(
196-
qint64 id, const QString& title, const QStringList& authors,
197-
qint64 type, qint64 classInput, const QString& releaseDate,
198-
qint64 difficulty, qint64 duration) :
199-
m_trle_id(id), m_title(title), m_authors(authors), m_type(type),
200-
m_class(classInput), m_releaseDate(releaseDate),
201-
m_difficulty(difficulty), m_duration(duration) {
202-
m_cover = nullptr;
203-
}
204-
205169
// Data members
206170
qint64 m_trle_id; ///< The TRLE level id.
207171
QString m_title; ///< The TRLE level title.
@@ -211,7 +175,7 @@ struct ListItemData {
211175
QString m_releaseDate; ///< The release date in "YYYY-MM-DD" format.
212176
qint64 m_difficulty; ///< ID of the difficulty of the level.
213177
qint64 m_duration; ///< ID of the estimated duration of the level.
214-
ListItemPicture* m_cover; ///< The TRLE cover image pointer.
178+
QPixmap m_cover; ///< The TRLE cover image pointer.
215179
};
216180

217181
/**
@@ -243,19 +207,18 @@ struct InfoData {
243207
: m_body(body) {
244208
for (const QByteArray& image : imageList) {
245209
QPixmap pixmap;
246-
QIcon finalIcon;
247210

248211
// Load image data into a QPixmap and convert it to a QIcon
249-
if (pixmap.loadFromData(image, "WEBP") == true) {
250-
finalIcon.addPixmap(pixmap);
212+
if (!pixmap.loadFromData(image, "WEBP")) {
213+
qDebug() << "Could not load webp data to QPixmap.";
251214
}
252215

253-
m_imageList.push_back(finalIcon);
216+
m_imageList.push_back(pixmap);
254217
}
255218
}
256219

257220
QString m_body; ///< The textual content associated with this object.
258-
QVector<QIcon> m_imageList; ///< A list of icons generated from image data.
221+
QVector<QPixmap> m_imageList; ///< A list of level large screen image data.
259222
};
260223

261224
class Data : public QObject {
@@ -298,7 +261,7 @@ class Data : public QObject {
298261

299262
qint64 getListRowCount();
300263
QVector<ListItemData> getListItems();
301-
QVector<ListItemPicture> getPictures(QList<qint64> trle_ids);
264+
void getCoverPictures(QVector<ListItemData*>* items);
302265
InfoData getInfo(int id);
303266
QString getWalkthrough(int id);
304267
int getType(int id);

src/Model.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ void Model::getList(QVector<ListItemData>* list) {
103103
*list = data.getListItems();
104104
}
105105

106+
void Model::getCoverList(QVector<ListItemData*>* list) {
107+
data.getCoverPictures(list);
108+
}
109+
106110
int Model::getItemState(int id) {
107111
int status = 0;
108112
if (id < 0) {

src/Model.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
#include <QBitArray>
2121
#include <QDebug>
2222
#include <QtCore>
23+
2324
#include <cassert>
24-
#include "Data.hpp"
25-
#include "FileManager.hpp"
26-
#include "Network.hpp"
27-
#include "Runner.hpp"
25+
26+
#include "../src/Data.hpp"
27+
#include "../src/FileManager.hpp"
28+
#include "../src/Network.hpp"
29+
#include "../src/Runner.hpp"
2830

2931
class InstructionManager : public QObject {
3032
Q_OBJECT
@@ -62,6 +64,7 @@ class Model : public QObject {
6264
int checkGameDirectory(int id);
6365
int checkLevelDirectory(int id);
6466
void getList(QVector<ListItemData>* list);
67+
void getCoverList(QVector<ListItemData*>* list);
6568
int getItemState(int id);
6669
bool runWine(const int id);
6770
bool setLink(int id);

src/TombRaiderLinuxLauncher.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
9898

9999
connect(ui->radioButtonLevelName, &QRadioButton::clicked,
100100
this, &TombRaiderLinuxLauncher::sortByTitle);
101-
connect(ui->radioButtonAuthor, &QRadioButton::clicked,
102-
this, &TombRaiderLinuxLauncher::sortByAuthor);
103101
connect(ui->radioButtonDifficulty, &QRadioButton::clicked,
104102
this, &TombRaiderLinuxLauncher::sortByDifficulty);
105103
connect(ui->radioButtonDuration, &QRadioButton::clicked,
@@ -150,10 +148,6 @@ void TombRaiderLinuxLauncher::sortByTitle() {
150148
model->sortItems(model->compareTitles);
151149
}
152150

153-
void TombRaiderLinuxLauncher::sortByAuthor() {
154-
// sortItems(compareAuthors);
155-
}
156-
157151
void TombRaiderLinuxLauncher::sortByDifficulty() {
158152
model->sortItems(model->compareDifficulties);
159153
}

src/TombRaiderLinuxLauncher.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,9 @@ class TombRaiderLinuxLauncher : public QMainWindow {
8989
*/
9090
void generateList(const QList<int>& availableGames);
9191
/**
92-
* Sorts the list by author.
92+
* Load more levels when scrolled to the end of the list.
9393
*/
9494
void loadMoreLevels(int value);
95-
void sortByAuthor();
9695
/**
9796
* Sorts the list by title.
9897
*/

0 commit comments

Comments
 (0)