Skip to content

Commit 9e03bdf

Browse files
committed
filter installed
1 parent a2c924f commit 9e03bdf

File tree

7 files changed

+534
-423
lines changed

7 files changed

+534
-423
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ build
1616
.vscode
1717
.mypy_cache
1818
database/*.db-journal
19+
TombRaiderLinuxLauncher.kdev4

src/Data.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,19 @@ QVector<ListItemData> Data::getListItems() {
6464
if (status) {
6565
if (query.exec()) {
6666
while (query.next()) {
67-
items.append(ListItemData(
68-
query.value("Info.trleID").toInt(),
69-
query.value("Info.title").toString(),
70-
query.value("authors").toString().split(", "),
71-
query.value("Info.type").toInt(),
72-
query.value("Info.class").toInt(),
73-
query.value("Info.release").toString(),
74-
query.value("Info.difficulty").toInt(),
75-
query.value("Info.duration").toInt()));
67+
ListItemData item;
68+
// item.setGameId();
69+
item.setLid(query.value("Info.trleID").toInt());
70+
item.setTitle(query.value("Info.title").toString());
71+
item.setAuthors(query.value("authors").toString().split(", "));
72+
// item.setShortBody(),
73+
item.setType(query.value("Info.type").toInt());
74+
item.setClass(query.value("Info.class").toInt());
75+
item.setDifficulty(query.value("Info.difficulty").toInt());
76+
item.setDuration(query.value("Info.duration").toInt());
77+
item.setReleaseDate(query.value("Info.release").toString());
78+
// item.setPicture(const QByteArray& imageData),
79+
items.append(item);
7680
}
7781
} else {
7882
qDebug() << "Error executing query getListItems:"
@@ -104,7 +108,7 @@ void Data::getCoverPictures(QVector<ListItemData*>* items) {
104108
query.bindValue(":id", item->m_trle_id);
105109
if (query.exec()) {
106110
if (query.next() == true) {
107-
item->addPicture(
111+
item->setPicture(
108112
query.value("Picture.data").toByteArray());
109113
}
110114
} else {

src/Data.hpp

Lines changed: 74 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ struct GameRelease {
115115
{7, "1998-12-31"},
116116
{8, "1999-06-04"},
117117
{9, "2000-03-00"},
118-
{10, "1999-12"},
118+
{10, "1999-12-00"},
119119
};
120120
};
121121

@@ -218,7 +218,7 @@ struct ZipData {
218218
* @param release date of file release.
219219
*/
220220
inline void setRelease(const QString& release) {
221-
m_release = m_release;
221+
m_release = release;
222222
}
223223

224224
QString m_fileName; ///< The archive file name.
@@ -231,120 +231,97 @@ struct ZipData {
231231
};
232232

233233
/**
234-
* @struct OriginalGameData
235-
* @brief Represents a Tomb Raider Game Entry Card Info.
234+
* @struct ListItemData
235+
* @brief Represents a Tomb Raider Level Entry Card Info.
236236
*
237-
* This struct is designed to store a Game data record.
238-
* Each record contains basic game data and a cover image displayed as a card in the application.
237+
* This struct is designed to store a single TRLE (Tomb Raider Level Editor) level record.
238+
* Each record contains metadata and a cover image displayed as a card in the application.
239+
* The struct includes properties to facilitate searching, filtering, and sorting.
239240
*/
240-
struct OriginalGameData {
241+
struct ListItemData {
241242
/**
242-
* @brief Default constructor for `OriginalGameData`.
243+
* @brief Default constructor for `ListItemData`.
243244
*
244-
* Initializes an empty instance of `OriginalGameData`.
245+
* Initializes an empty instance of `ListItemData`.
245246
*/
246-
OriginalGameData() {}
247+
ListItemData() {
248+
m_game_id = 0;
249+
m_trle_id = 0;
250+
m_type = 0;
251+
m_class = 0;
252+
m_difficulty = 0;
253+
m_duration = 0;
254+
m_installed = false;
255+
}
247256

248-
/**
249-
* @brief Parameterized constructor for `OriginalGameData`.
250-
*
251-
* This constructor initializes a `OriginalGameData` object with game metadata.
252-
*
253-
* @param id The numeric game database ID.
254-
* @param title The TRLE title. Expected to contain a single name.
255-
* @param shortBody some short game info text.
256-
* @param type The TRLE type, represented by a numeric ID.
257-
* @param releaseDate The release date in the format "YYYY-MM-DD" (e.g., "2000-01-01").
258-
* @param m_cover The cover image as a `m_cover`.
259-
*/
260-
OriginalGameData(
261-
qint64 id, const QString& title, const QString& shortBody,
262-
qint64 type, const QString& releaseDate, const QPixmap& cover) :
263-
m_game_id(id), m_title(title), m_shortBody(shortBody), m_type(type),
264-
m_releaseDate(releaseDate) {
265-
// Define target dimensions and maintain aspect ratio
266-
QSize targetSize(640, 480);
267-
QSize newSize = cover.size().scaled(targetSize, Qt::KeepAspectRatio);
268257

269-
// Scale the pixmap
270-
QPixmap scaledPixmap = cover.scaled(
271-
newSize,
272-
Qt::KeepAspectRatio,
273-
Qt::SmoothTransformation);
258+
void setGameId(const qint64 id) {
259+
m_game_id = id;
260+
}
274261

275-
// Create a centered pixmap with a transparent background
276-
QPixmap centeredPixmap(targetSize);
277-
// Ensure a transparent background
278-
centeredPixmap.fill(Qt::transparent);
262+
void setLid(const qint64 id) {
263+
m_trle_id = id;
264+
}
279265

280-
// Calculate offsets for centering the scaled image
281-
qint64 xOffset = (targetSize.width() - newSize.width()) / 2;
282-
qint64 yOffset = (targetSize.height() - newSize.height()) / 2;
266+
void setTitle(const QString& title) {
267+
m_title = title;
268+
}
283269

284-
// Draw the scaled image onto the centered pixmap
285-
QPainter painter(&centeredPixmap);
286-
painter.setRenderHint(QPainter::Antialiasing, true);
287-
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
288-
painter.drawPixmap(xOffset, yOffset, scaledPixmap);
289-
painter.end();
270+
void setAuthors(const QStringList& authors) {
271+
m_authors = authors;
272+
}
290273

291-
// Store the resulting pixmap in m_picture
292-
m_cover = centeredPixmap;
274+
void setShortBody(const QString& shortBody) {
275+
m_shortBody = shortBody;
293276
}
294277

295-
// Data members
296-
qint64 m_game_id; ///< The Game id.
297-
QString m_title; ///< The Game title.
298-
QString m_shortBody; ///< The Game info text.
299-
qint64 m_type; ///< ID of the type of game.
300-
QString m_releaseDate; ///< The release date in "YYYY-MM-DD" format.
301-
QPixmap m_cover; ///< The Game cover image.
302-
};
278+
void setType(const qint64 type) {
279+
m_type = type;
280+
}
303281

304-
/**
305-
* @struct ListItemData
306-
* @brief Represents a Tomb Raider Level Entry Card Info.
307-
*
308-
* This struct is designed to store a single TRLE (Tomb Raider Level Editor) level record.
309-
* Each record contains metadata and a cover image displayed as a card in the application.
310-
* The struct includes properties to facilitate searching, filtering, and sorting.
311-
*/
312-
struct ListItemData {
313-
/**
314-
* @brief Default constructor for `ListItemData`.
315-
*
316-
* Initializes an empty instance of `ListItemData`.
317-
*/
318-
ListItemData() {}
282+
void setClass(const qint64 _class) {
283+
m_class = _class;
284+
}
319285

320-
/**
321-
* @brief Parameterized constructor for `ListItemData`.
322-
*
323-
* This constructor initializes a `ListItemData` object with metadata.
324-
*
325-
* @param id The TRLE numeric level ID.
326-
* @param title The TRLE title. Expected to contain a single name.
327-
* @param author The TRLE author(s). Can be a single name or multiple names.
328-
* @param type The TRLE type, represented by a numeric ID.
329-
* @param classInput The TRLE class, represented by a numeric ID.
330-
* @param releaseDate The release date in the format "YYYY-MM-DD" (e.g., "2000-01-01").
331-
* @param difficulty The TRLE difficulty, represented by a numeric ID.
332-
* @param duration The TRLE duration, represented by a numeric ID.
333-
* @param m_cover The cover image as a `m_cover`.
334-
*/
335-
ListItemData(
336-
qint64 id, const QString& title, const QStringList& authors,
337-
qint64 type, qint64 classInput, const QString& releaseDate,
338-
qint64 difficulty, qint64 duration) :
339-
m_trle_id(id), m_title(title), m_authors(authors), m_type(type),
340-
m_class(classInput), m_releaseDate(releaseDate),
341-
m_difficulty(difficulty), m_duration(duration) {}
342-
343-
void addPicture(const QByteArray& imageData) {
286+
void setDifficulty(const qint64 difficulty) {
287+
m_difficulty = difficulty;
288+
}
289+
290+
void setDuration(const qint64 duration) {
291+
m_duration = duration;
292+
}
293+
294+
void setReleaseDate(const QString& releaseDate) {
295+
m_releaseDate = releaseDate;
296+
}
297+
298+
void setPicture(const QByteArray& imageData) {
344299
// Load the image from the byte array
345300
QPixmap pixmap;
346301
pixmap.loadFromData(imageData, "WEBP");
347302

303+
centerPixmap(pixmap);
304+
}
305+
306+
void setPicture(const QPixmap& pixmap) {
307+
centerPixmap(pixmap);
308+
}
309+
// Data members
310+
qint64 m_game_id; ///< The Game id.
311+
qint64 m_trle_id; ///< The TRLE level id.
312+
QString m_shortBody; ///< The Game info text.
313+
QString m_title; ///< The TRLE level title.
314+
QStringList m_authors; ///< The TRLE author(s), as a string list.
315+
qint64 m_type; ///< ID of the type of level.
316+
qint64 m_class; ///< ID of the class of the level.
317+
QString m_releaseDate; ///< The release date in "YYYY-MM-DD" format.
318+
qint64 m_difficulty; ///< ID of the difficulty of the level.
319+
qint64 m_duration; ///< ID of the estimated duration of the level.
320+
QPixmap m_cover; ///< The TRLE cover image.
321+
bool m_installed;
322+
323+
private:
324+
void centerPixmap(QPixmap pixmap) {
348325
// Define target dimensions and maintain aspect ratio
349326
QSize targetSize(640, 480);
350327
QSize newSize = pixmap.size().scaled(targetSize, Qt::KeepAspectRatio);
@@ -374,16 +351,6 @@ struct ListItemData {
374351
// Store the resulting pixmap in m_picture
375352
m_cover = centeredPixmap;
376353
}
377-
// Data members
378-
qint64 m_trle_id; ///< The TRLE level id.
379-
QString m_title; ///< The TRLE level title.
380-
QStringList m_authors; ///< The TRLE author(s), as a string list.
381-
qint64 m_type; ///< ID of the type of level.
382-
qint64 m_class; ///< ID of the class of the level.
383-
QString m_releaseDate; ///< The release date in "YYYY-MM-DD" format.
384-
qint64 m_difficulty; ///< ID of the difficulty of the level.
385-
qint64 m_duration; ///< ID of the estimated duration of the level.
386-
QPixmap m_cover; ///< The TRLE cover image.
387354
};
388355

389356
/**

src/TombRaiderLinuxLauncher.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
111111
this, &TombRaiderLinuxLauncher::sortByType);
112112
connect(ui->radioButtonReleaseDate, &QRadioButton::clicked,
113113
this, &TombRaiderLinuxLauncher::sortByReleaseDate);
114-
connect(ui->radioButtonOriginal, &QRadioButton::clicked,
114+
connect(ui->checkBoxOriginal, &QRadioButton::clicked,
115115
this, &TombRaiderLinuxLauncher::showtOriginal);
116116

117117
connect(ui->comboBoxClass, &QComboBox::currentTextChanged,
@@ -141,6 +141,10 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
141141
levelListModel->filterSearch(searchText);
142142
});
143143

144+
connect(ui->checkBoxInstalled, &QCheckBox::clicked, this, [=]() {
145+
levelListModel->filterInstalled();
146+
});
147+
144148
// Read settings
145149
QString value = m_settings.value("setup").toString();
146150
if (value != "yes") {
@@ -151,8 +155,8 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
151155
}
152156

153157
void TombRaiderLinuxLauncher::generateList(const QList<int>& availableGames) {
154-
setInstalled();
155158
levelListModel->setLevels(availableGames);
159+
setInstalled();
156160
}
157161

158162
void TombRaiderLinuxLauncher::setInstalled() {
@@ -246,20 +250,6 @@ void TombRaiderLinuxLauncher::setup() {
246250
ui->levelPathEdit->setText(homeDir + l);
247251
}
248252

249-
void TombRaiderLinuxLauncher::originalSelected(qint64 id) {
250-
if (id != 0) {
251-
// the game directory was a symbolic link and it has a level directory
252-
if (levelListModel->getInstalled(id)) {
253-
ui->pushButtonLink->setEnabled(true);
254-
ui->pushButtonDownload->setEnabled(false);
255-
} else {
256-
ui->pushButtonLink->setEnabled(false);
257-
ui->pushButtonDownload->setEnabled(true);
258-
}
259-
ui->pushButtonInfo->setEnabled(false);
260-
}
261-
}
262-
263253
void TombRaiderLinuxLauncher::levelDirSelected(qint64 id) {
264254
if (id != 0) {
265255
int state = controller.getItemState(id);
@@ -295,7 +285,14 @@ void TombRaiderLinuxLauncher::onCurrentItemChanged(
295285
if (current.isValid()) {
296286
qint64 id = levelListModel->getLid(current);
297287
if (levelListModel->getListType()) { // its the original game
298-
originalSelected(id);
288+
if (levelListModel->getInstalled(current)) {
289+
ui->pushButtonLink->setEnabled(true);
290+
ui->pushButtonDownload->setEnabled(false);
291+
} else {
292+
ui->pushButtonLink->setEnabled(false);
293+
ui->pushButtonDownload->setEnabled(true);
294+
}
295+
ui->pushButtonInfo->setEnabled(false);
299296
} else {
300297
levelDirSelected(id);
301298
}
@@ -552,4 +549,5 @@ void TombRaiderLinuxLauncher::LevelResetClicked() {
552549

553550
TombRaiderLinuxLauncher::~TombRaiderLinuxLauncher() {
554551
delete ui;
552+
QApplication::quit();
555553
}

src/TombRaiderLinuxLauncher.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,6 @@ class TombRaiderLinuxLauncher : public QMainWindow {
143143
*/
144144
void setInstalled();
145145

146-
/**
147-
*
148-
*/
149-
void originalSelected(qint64 id);
150-
151146
/**
152147
*
153148
*/

0 commit comments

Comments
 (0)