mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 08:22:15 -07:00
get it to work
This commit is contained in:
parent
3c7d1922c5
commit
0653a14a02
3 changed files with 72 additions and 10 deletions
|
|
@ -10,8 +10,9 @@ VisualDeckStorageFolderDisplayWidget::VisualDeckStorageFolderDisplayWidget(
|
|||
QWidget *parent,
|
||||
VisualDeckStorageWidget *_visualDeckStorageWidget,
|
||||
QString _filePath,
|
||||
bool canBeHidden)
|
||||
: QWidget(parent), visualDeckStorageWidget(_visualDeckStorageWidget), filePath(_filePath)
|
||||
bool canBeHidden,
|
||||
bool _showFolders)
|
||||
: QWidget(parent), showFolders(_showFolders), visualDeckStorageWidget(_visualDeckStorageWidget), filePath(_filePath)
|
||||
{
|
||||
layout = new QVBoxLayout(this);
|
||||
setLayout(layout);
|
||||
|
|
@ -63,12 +64,14 @@ void VisualDeckStorageFolderDisplayWidget::refreshUi()
|
|||
header->setText(bannerText);
|
||||
}
|
||||
|
||||
static QStringList getAllFiles(const QString &filePath)
|
||||
static QStringList getAllFiles(const QString &filePath, bool recursive)
|
||||
{
|
||||
QStringList allFiles;
|
||||
|
||||
// QDirIterator with QDir::Files ensures only files are listed (no directories)
|
||||
QDirIterator it(filePath, QDir::Files);
|
||||
auto flags =
|
||||
recursive ? QDirIterator::Subdirectories | QDirIterator::FollowSymlinks : QDirIterator::NoIteratorFlags;
|
||||
QDirIterator it(filePath, QDir::Files, flags);
|
||||
|
||||
while (it.hasNext()) {
|
||||
allFiles << it.next(); // Add each file path to the list
|
||||
|
|
@ -80,7 +83,7 @@ static QStringList getAllFiles(const QString &filePath)
|
|||
void VisualDeckStorageFolderDisplayWidget::createWidgetsForFiles()
|
||||
{
|
||||
QList<DeckPreviewWidget *> allDecks;
|
||||
for (const QString &file : getAllFiles(filePath)) {
|
||||
for (const QString &file : getAllFiles(filePath, !showFolders)) {
|
||||
auto *display = new DeckPreviewWidget(flowWidget, visualDeckStorageWidget, file);
|
||||
|
||||
connect(display, &DeckPreviewWidget::deckPreviewClicked, visualDeckStorageWidget,
|
||||
|
|
@ -151,12 +154,64 @@ static QStringList getAllSubFolders(const QString &filePath)
|
|||
|
||||
void VisualDeckStorageFolderDisplayWidget::createWidgetsForFolders()
|
||||
{
|
||||
if (!showFolders) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const QString &dir : getAllSubFolders(filePath)) {
|
||||
auto *display = new VisualDeckStorageFolderDisplayWidget(this, visualDeckStorageWidget, dir, true);
|
||||
auto *display = new VisualDeckStorageFolderDisplayWidget(this, visualDeckStorageWidget, dir, true, showFolders);
|
||||
containerLayout->addWidget(display);
|
||||
}
|
||||
}
|
||||
|
||||
void VisualDeckStorageFolderDisplayWidget::updateShowFolders(bool enabled)
|
||||
{
|
||||
showFolders = enabled;
|
||||
|
||||
if (!showFolders) {
|
||||
flattenFolderStructure();
|
||||
} else {
|
||||
// if setting was switched from disabled to enabled, we assume that there isn't any existing subfolders
|
||||
createWidgetsForFiles();
|
||||
createWidgetsForFolders();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively gets all DeckPreviewWidgets in this folder and its subfolders
|
||||
*/
|
||||
static QList<DeckPreviewWidget *> getAllDecksRecursive(VisualDeckStorageFolderDisplayWidget *folder)
|
||||
{
|
||||
QList<DeckPreviewWidget *> allDecks;
|
||||
|
||||
if (auto *flowWidget = folder->getFlowWidget()) {
|
||||
// Iterate through all DeckPreviewWidgets in this folder
|
||||
allDecks << flowWidget->findChildren<DeckPreviewWidget *>();
|
||||
}
|
||||
|
||||
for (auto *subFolder : folder->findChildren<VisualDeckStorageFolderDisplayWidget *>()) {
|
||||
allDecks << getAllDecksRecursive(subFolder);
|
||||
}
|
||||
|
||||
return allDecks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively steals all DeckPreviewWidgets from this widget's subfolders, and deletes all subfolders
|
||||
*/
|
||||
void VisualDeckStorageFolderDisplayWidget::flattenFolderStructure()
|
||||
{
|
||||
for (VisualDeckStorageFolderDisplayWidget *subFolder : findChildren<VisualDeckStorageFolderDisplayWidget *>()) {
|
||||
// steal all DeckPreviewWidgets from the subfolder and all its subfolders
|
||||
for (auto *deck : getAllDecksRecursive(subFolder)) {
|
||||
flowWidget->addWidget(deck);
|
||||
}
|
||||
|
||||
// delete the subfolder
|
||||
subFolder->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
QStringList VisualDeckStorageFolderDisplayWidget::gatherAllTagsFromFlowWidget() const
|
||||
{
|
||||
QStringList allTags;
|
||||
|
|
|
|||
|
|
@ -15,10 +15,12 @@ public:
|
|||
VisualDeckStorageFolderDisplayWidget(QWidget *parent,
|
||||
VisualDeckStorageWidget *_visualDeckStorageWidget,
|
||||
QString _filePath,
|
||||
bool canBeHidden);
|
||||
bool canBeHidden,
|
||||
bool _showFolders);
|
||||
void refreshUi();
|
||||
void createWidgetsForFiles();
|
||||
void createWidgetsForFolders();
|
||||
void flattenFolderStructure();
|
||||
QStringList gatherAllTagsFromFlowWidget() const;
|
||||
FlowWidget *getFlowWidget() const
|
||||
{
|
||||
|
|
@ -28,8 +30,10 @@ public:
|
|||
public slots:
|
||||
void updateVisibility();
|
||||
bool checkVisibility();
|
||||
void updateShowFolders(bool enabled);
|
||||
|
||||
private:
|
||||
bool showFolders;
|
||||
QVBoxLayout *layout;
|
||||
VisualDeckStorageWidget *visualDeckStorageWidget;
|
||||
QString filePath;
|
||||
|
|
|
|||
|
|
@ -56,8 +56,6 @@ VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent) : QWidget(pare
|
|||
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
folderWidget = new VisualDeckStorageFolderDisplayWidget(this, this, SettingsCache::instance().getDeckPath(), false);
|
||||
|
||||
scrollArea->setWidget(folderWidget);
|
||||
scrollArea->setWidgetResizable(true);
|
||||
|
||||
|
|
@ -123,7 +121,12 @@ void VisualDeckStorageWidget::deckPreviewDoubleClickedEvent(QMouseEvent *event,
|
|||
|
||||
void VisualDeckStorageWidget::createRootFolderWidget()
|
||||
{
|
||||
folderWidget = new VisualDeckStorageFolderDisplayWidget(this, this, SettingsCache::instance().getDeckPath(), false);
|
||||
folderWidget =
|
||||
new VisualDeckStorageFolderDisplayWidget(this, this, SettingsCache::instance().getDeckPath(), false, false);
|
||||
|
||||
connect(showFoldersCheckBox, &QCheckBox::QT_STATE_CHANGED, folderWidget,
|
||||
&VisualDeckStorageFolderDisplayWidget::updateShowFolders);
|
||||
|
||||
scrollArea->setWidget(folderWidget);
|
||||
scrollArea->widget()->setMaximumWidth(scrollArea->viewport()->width());
|
||||
scrollArea->widget()->adjustSize();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue