mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 00:42:14 -07:00
Add an option to sort by filename or last modified.
This commit is contained in:
parent
d7bd0b8b07
commit
6e7aa5c53e
2 changed files with 53 additions and 14 deletions
|
|
@ -5,18 +5,36 @@
|
||||||
#include "../../../../settings/cache_settings.h"
|
#include "../../../../settings/cache_settings.h"
|
||||||
|
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent) : QWidget(parent)
|
VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent)
|
||||||
|
: QWidget(parent), sortOrder(Alphabetical)
|
||||||
{
|
{
|
||||||
deckListModel = new DeckListModel(this);
|
deckListModel = new DeckListModel(this);
|
||||||
deckListModel->setObjectName("visualDeckModel");
|
deckListModel->setObjectName("visualDeckModel");
|
||||||
|
|
||||||
layout = new QHBoxLayout(this);
|
layout = new QVBoxLayout();
|
||||||
|
setLayout(layout);
|
||||||
|
|
||||||
flowWidget = new FlowWidget(this, Qt::ScrollBarAlwaysOff, Qt::ScrollBarPolicy::ScrollBarAsNeeded);
|
// ComboBox for sorting options
|
||||||
|
auto *sortComboBox = new QComboBox(this);
|
||||||
|
sortComboBox->addItem("Sort Alphabetically (Filename)", Alphabetical);
|
||||||
|
sortComboBox->addItem("Sort by Last Modified", ByLastModified);
|
||||||
|
|
||||||
|
// Add combo box to the main layout
|
||||||
|
layout->addWidget(sortComboBox);
|
||||||
|
|
||||||
|
flowWidget = new FlowWidget(this, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded);
|
||||||
layout->addWidget(flowWidget);
|
layout->addWidget(flowWidget);
|
||||||
|
|
||||||
getBannerCardsForDecks();
|
// Connect sorting change signal to refresh the file list
|
||||||
|
connect(sortComboBox, &QComboBox::currentIndexChanged, this, [this, sortComboBox]() {
|
||||||
|
sortOrder = static_cast<SortOrder>(sortComboBox->currentData().toInt());
|
||||||
|
refreshBannerCards(); // Refresh the banner cards with the new sort order
|
||||||
|
});
|
||||||
|
|
||||||
|
refreshBannerCards();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualDeckStorageWidget::imageClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance)
|
void VisualDeckStorageWidget::imageClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance)
|
||||||
|
|
@ -29,7 +47,7 @@ void VisualDeckStorageWidget::imageDoubleClickedEvent(QMouseEvent *event, DeckPr
|
||||||
emit imageDoubleClicked(event, instance);
|
emit imageDoubleClicked(event, instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList VisualDeckStorageWidget::getBannerCardsForDecks()
|
void VisualDeckStorageWidget::refreshBannerCards()
|
||||||
{
|
{
|
||||||
QStringList allFiles;
|
QStringList allFiles;
|
||||||
|
|
||||||
|
|
@ -41,6 +59,23 @@ QStringList VisualDeckStorageWidget::getBannerCardsForDecks()
|
||||||
allFiles << it.next(); // Add each file path to the list
|
allFiles << it.next(); // Add each file path to the list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort files based on the current sort order
|
||||||
|
std::sort(allFiles.begin(), allFiles.end(), [this](const QString &file1, const QString &file2) {
|
||||||
|
QFileInfo info1(file1);
|
||||||
|
QFileInfo info2(file2);
|
||||||
|
|
||||||
|
switch (sortOrder) {
|
||||||
|
case Alphabetical:
|
||||||
|
return info1.fileName().toLower() < info2.fileName().toLower();
|
||||||
|
case ByLastModified:
|
||||||
|
return info1.lastModified() < info2.lastModified();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false; // Default case
|
||||||
|
});
|
||||||
|
|
||||||
|
flowWidget->clearLayout(); // Clear existing widgets in the flow layout
|
||||||
|
|
||||||
foreach (const QString &file, allFiles) {
|
foreach (const QString &file, allFiles) {
|
||||||
qDebug() << file;
|
qDebug() << file;
|
||||||
auto deckLoader = new DeckLoader();
|
auto deckLoader = new DeckLoader();
|
||||||
|
|
@ -64,6 +99,4 @@ QStringList VisualDeckStorageWidget::getBannerCardsForDecks()
|
||||||
&VisualDeckStorageWidget::imageDoubleClickedEvent);
|
&VisualDeckStorageWidget::imageDoubleClickedEvent);
|
||||||
flowWidget->addWidget(display);
|
flowWidget->addWidget(display);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return QStringList("lol");
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -15,21 +15,27 @@ public:
|
||||||
explicit VisualDeckStorageWidget(QWidget *parent);
|
explicit VisualDeckStorageWidget(QWidget *parent);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void imageClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
void imageClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||||
void imageDoubleClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
void imageDoubleClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void imageClicked(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
void imageClicked(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||||
void imageDoubleClicked(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
void imageDoubleClicked(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHBoxLayout *layout;
|
enum SortOrder {
|
||||||
|
Alphabetical,
|
||||||
|
ByLastModified
|
||||||
|
};
|
||||||
|
|
||||||
|
QVBoxLayout *layout;
|
||||||
FlowWidget *flowWidget;
|
FlowWidget *flowWidget;
|
||||||
DeckListModel *deckListModel;
|
DeckListModel *deckListModel;
|
||||||
QMap<QString, DeckViewCardContainer *> cardContainers;
|
QMap<QString, DeckViewCardContainer *> cardContainers;
|
||||||
|
|
||||||
QStringList getBannerCardsForDecks();
|
SortOrder sortOrder; // Current sorting option
|
||||||
|
void refreshBannerCards(); // Refresh the display of cards based on the current sorting option
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VISUAL_DECK_STORAGE_WIDGET_H
|
#endif // VISUAL_DECK_STORAGE_WIDGET_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue