@@ -114,7 +114,8 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
114114
115115 model = new LevelListModel (this );
116116 ui->listViewLevels ->setModel (model);
117- ui->listViewLevels ->setItemDelegate (new CardItemDelegate (ui->listViewLevels ));
117+ CardItemDelegate* delegate = new CardItemDelegate (ui->listViewLevels );
118+ ui->listViewLevels ->setItemDelegate (delegate);
118119 ui->listViewLevels ->setSpacing (8 );
119120 connect (
120121 ui->listViewLevels ->selectionModel (),
@@ -133,217 +134,35 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
133134
134135void TombRaiderLinuxLauncher::generateList (const QList<int >& availableGames) {
135136 model->setLevels ();
136- /*
137- ui->listViewLevels->clear();
138- const QString pictures = ":/pictures/";
139- OriginalGameData pictueData;
140-
141- foreach(const int &id, availableGames) {
142- int IdPositive;
143- bool linkedGameDir;
144- if (id < 0) {
145- linkedGameDir = false;
146- IdPositive = id*(-1);
147- } else {
148- linkedGameDir = true;
149- IdPositive = id;
150- }
151-
152- // Picture and title
153- QString iconPath = pictures + pictueData.getPicture(IdPositive);
154- QString itemName =
155- QString("Tomb Raider %1 Original")
156- .arg(pictueData.romanNumerals[IdPositive]);
157-
158- qDebug() << "iconPath :" << iconPath;
159- qDebug() << "itemName :" << itemName;
160- QListWidgetItem *wi = new QListWidgetItem(QIcon(iconPath), itemName);
161- wi->setData(Qt::UserRole, QVariant(IdPositive*(-1)));
162- wi->setData(Qt::UserRole + 1, QVariant(linkedGameDir));
163- ui->listViewLevels->addItem(wi);
164- originalGamesSet_m.insert(wi);
165- originalGamesList_m.append(wi);
166- }
167-
168- StaticData staticData;
169- auto mapType = staticData.getType();
170- auto mapClass = staticData.getClass();
171- auto mapDifficulty = staticData.getDifficulty();
172- auto mapDuration = staticData.getDuration();
173-
174- const qint64 s = list.size();
175- for (qint64 i = 0; i < s; i++) {
176- QString tag = QString("%1 by %2\n")
177- .arg(list[i].m_title)
178- .arg(list[i].m_author);
179-
180- // list[i].m_type
181- // list[i].m_class
182- // list[i].m_difficulty
183- // list[i].m_duration
184-
185- tag += QString(
186- "Type: %1\nClass: %2\nDifficulty: %3\nDuration: %4\nDate:%5")
187- .arg(mapType.at(list[i].m_type))
188- .arg(mapClass.at(list[i].m_class))
189- .arg(mapDifficulty.at(list[i].m_difficulty))
190- .arg(mapDuration.at(list[i].m_duration))
191- .arg(list[i].m_releaseDate);
192-
193- QListWidgetItem *wi =
194- new QListWidgetItem(list[i].m_picture, tag);
195-
196- wi->setData(Qt::UserRole, QVariant(list[i].m_id));
197- QVariantMap itemData;
198- itemData["title"] = list[i].m_title;
199- itemData["author"] = list[i].m_author;
200- itemData["type"] = list[i].m_type;
201- itemData["class_"] = list[i].m_class;
202- itemData["releaseDate"] = list[i].m_releaseDate;
203- itemData["difficulty"] = list[i].m_difficulty;
204- itemData["duration"] = list[i].m_duration;
205- // qDebug() << itemData << Qt::endl;
206- wi->setData(Qt::UserRole + 1, itemData);
207- ui->listViewLevels->addItem(wi);
208- }
209- sortByTitle();
210- */
211- }
212-
213- void TombRaiderLinuxLauncher::sortItems (
214- std::function<bool (QListWidgetItem*, QListWidgetItem*)> compare) {
215- QList<QListWidgetItem*> items;
216-
217- // Step 1: Extract items from the QListWidget
218- int count = 0 ;
219- if (ui->listViewLevels ->model ()) {
220- count = ui->listViewLevels ->model ()->rowCount ();
221- }
222- if (ui->checkBoxOriginalFirst ->isChecked () == true ) {
223- for (int i = 0 ; i < count; ++i) {
224- /*
225- QListWidgetItem* item = ui->listViewLevels->item(i);
226- // Append the item only if it's not in originalGamesSet_m
227- if (!originalGamesSet_m.contains(item)) {
228- items.append(item);
229- }
230- */
231- }
232- } else {
233- for (int i = 0 ; i < count; ++i) {
234- // items.append(ui->listViewLevels->item(i));
235- }
236- }
237-
238- // Step 2: Sort the items using the provided comparison lambda
239- std::sort (items.begin (), items.end (), compare);
240-
241- // Step 3: Adjust the position of each item without clearing the list
242- qint64 originalGamesSize =
243- ui->checkBoxOriginalFirst ->isChecked () ? originalGamesList_m.size () : 0 ;
244-
245- qint64 size = originalGamesSize + items.size ();
246- for (qint64 i = 0 ; i < size; ++i) {
247- if (i < originalGamesSize) {
248- // Handle originalGamesList_m items
249- /*
250- item = ui->listViewLevels->takeItem(
251- ui->listViewLevels->row(originalGamesList_m[i]));
252- ui->listViewLevels->insertItem(i, item);
253- */
254- } else {
255- // Handle items list
256- /*
257- item = ui->listViewLevels->takeItem(
258- ui->listViewLevels->row(items[i - originalGamesSize]));
259- ui->listViewLevels->insertItem(i, item);
260- */
261- }
262- }
263- }
264-
265- bool compareTitles (QListWidgetItem* a, QListWidgetItem* b) {
266- const QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
267- const QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
268-
269- return aData.value (" title" ).toString ().toLower ()
270- < bData.value (" title" ).toString ().toLower ();
271- }
272-
273- bool compareAuthors (QListWidgetItem* a, QListWidgetItem* b) {
274- const QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
275- const QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
276- return aData.value (" author" ).toString ().toLower ()
277- < bData.value (" author" ).toString ().toLower ();
278- }
279-
280- bool compareDifficulties (QListWidgetItem* a, QListWidgetItem* b) {
281- const QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
282- const QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
283- return aData.value (" difficulty" ).toInt ()
284- > bData.value (" difficulty" ).toInt ();
285- }
286-
287- bool compareDurations (QListWidgetItem* a, QListWidgetItem* b) {
288- const QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
289- const QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
290- return aData.value (" duration" ).toInt ()
291- > bData.value (" duration" ).toInt ();
292- }
293-
294- bool compareClasses (QListWidgetItem* a, QListWidgetItem* b) {
295- const QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
296- const QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
297- return aData.value (" class_" ).toInt ()
298- > bData.value (" class_" ).toInt ();
299- }
300-
301- bool compareTypes (QListWidgetItem* a, QListWidgetItem* b) {
302- const QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
303- const QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
304- return aData.value (" type" ).toInt ()
305- > bData.value (" type" ).toInt ();
306- }
307-
308- bool compareReleaseDates (QListWidgetItem* a, QListWidgetItem* b) {
309- const QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
310- const QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
311-
312- const QDate dateA = QDate::fromString (
313- aData.value (" releaseDate" ).toString (), " dd-MMM-yyyy" );
314- const QDate dateB = QDate::fromString (
315- bData.value (" releaseDate" ).toString (), " dd-MMM-yyyy" );
316-
317- return dateA > dateB; // descending order
318137}
319138
320139
321140void TombRaiderLinuxLauncher::sortByTitle () {
322- sortItems (compareTitles);
141+ model-> sortItems (model-> compareTitles );
323142}
324143
325144void TombRaiderLinuxLauncher::sortByAuthor () {
326- sortItems (compareAuthors);
145+ // sortItems(compareAuthors);
327146}
328147
329148void TombRaiderLinuxLauncher::sortByDifficulty () {
330- sortItems (compareDifficulties);
149+ model-> sortItems (model-> compareDifficulties );
331150}
332151
333152void TombRaiderLinuxLauncher::sortByDuration () {
334- sortItems (compareDurations);
153+ model-> sortItems (model-> compareDurations );
335154}
336155
337156void TombRaiderLinuxLauncher::sortByClass () {
338- sortItems (compareClasses);
157+ model-> sortItems (model-> compareClasses );
339158}
340159
341160void TombRaiderLinuxLauncher::sortByType () {
342- sortItems (compareTypes);
161+ model-> sortItems (model-> compareTypes );
343162}
344163
345164void TombRaiderLinuxLauncher::sortByReleaseDate () {
346- sortItems (compareReleaseDates);
165+ model-> sortItems (model-> compareReleaseDates );
347166}
348167
349168void TombRaiderLinuxLauncher::readSavedSettings () {
@@ -558,8 +377,9 @@ void TombRaiderLinuxLauncher::walkthroughClicked() {
558377 if (current.isValid ()) {
559378 qint64 id = model->getLid (current);
560379 if (id != 0 ) {
561- ui->walkthroughWebEngineView ->setHtml (controller.getWalkthrough (id));
562- ui->walkthroughWebEngineView ->show ();
380+ QWebEngineView* w = ui->walkthroughWebEngineView ;
381+ w->setHtml (controller.getWalkthrough (id));
382+ w->show ();
563383 ui->stackedWidget ->setCurrentWidget (
564384 ui->stackedWidget ->findChild <QWidget*>(" walkthrough" ));
565385 }
0 commit comments