mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 00:42:14 -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,
|
QWidget *parent,
|
||||||
VisualDeckStorageWidget *_visualDeckStorageWidget,
|
VisualDeckStorageWidget *_visualDeckStorageWidget,
|
||||||
QString _filePath,
|
QString _filePath,
|
||||||
bool canBeHidden)
|
bool canBeHidden,
|
||||||
: QWidget(parent), visualDeckStorageWidget(_visualDeckStorageWidget), filePath(_filePath)
|
bool _showFolders)
|
||||||
|
: QWidget(parent), showFolders(_showFolders), visualDeckStorageWidget(_visualDeckStorageWidget), filePath(_filePath)
|
||||||
{
|
{
|
||||||
layout = new QVBoxLayout(this);
|
layout = new QVBoxLayout(this);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
@ -63,12 +64,14 @@ void VisualDeckStorageFolderDisplayWidget::refreshUi()
|
||||||
header->setText(bannerText);
|
header->setText(bannerText);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QStringList getAllFiles(const QString &filePath)
|
static QStringList getAllFiles(const QString &filePath, bool recursive)
|
||||||
{
|
{
|
||||||
QStringList allFiles;
|
QStringList allFiles;
|
||||||
|
|
||||||
// QDirIterator with QDir::Files ensures only files are listed (no directories)
|
// 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()) {
|
while (it.hasNext()) {
|
||||||
allFiles << it.next(); // Add each file path to the list
|
allFiles << it.next(); // Add each file path to the list
|
||||||
|
|
@ -80,7 +83,7 @@ static QStringList getAllFiles(const QString &filePath)
|
||||||
void VisualDeckStorageFolderDisplayWidget::createWidgetsForFiles()
|
void VisualDeckStorageFolderDisplayWidget::createWidgetsForFiles()
|
||||||
{
|
{
|
||||||
QList<DeckPreviewWidget *> allDecks;
|
QList<DeckPreviewWidget *> allDecks;
|
||||||
for (const QString &file : getAllFiles(filePath)) {
|
for (const QString &file : getAllFiles(filePath, !showFolders)) {
|
||||||
auto *display = new DeckPreviewWidget(flowWidget, visualDeckStorageWidget, file);
|
auto *display = new DeckPreviewWidget(flowWidget, visualDeckStorageWidget, file);
|
||||||
|
|
||||||
connect(display, &DeckPreviewWidget::deckPreviewClicked, visualDeckStorageWidget,
|
connect(display, &DeckPreviewWidget::deckPreviewClicked, visualDeckStorageWidget,
|
||||||
|
|
@ -151,12 +154,64 @@ static QStringList getAllSubFolders(const QString &filePath)
|
||||||
|
|
||||||
void VisualDeckStorageFolderDisplayWidget::createWidgetsForFolders()
|
void VisualDeckStorageFolderDisplayWidget::createWidgetsForFolders()
|
||||||
{
|
{
|
||||||
|
if (!showFolders) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (const QString &dir : getAllSubFolders(filePath)) {
|
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);
|
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 VisualDeckStorageFolderDisplayWidget::gatherAllTagsFromFlowWidget() const
|
||||||
{
|
{
|
||||||
QStringList allTags;
|
QStringList allTags;
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,12 @@ public:
|
||||||
VisualDeckStorageFolderDisplayWidget(QWidget *parent,
|
VisualDeckStorageFolderDisplayWidget(QWidget *parent,
|
||||||
VisualDeckStorageWidget *_visualDeckStorageWidget,
|
VisualDeckStorageWidget *_visualDeckStorageWidget,
|
||||||
QString _filePath,
|
QString _filePath,
|
||||||
bool canBeHidden);
|
bool canBeHidden,
|
||||||
|
bool _showFolders);
|
||||||
void refreshUi();
|
void refreshUi();
|
||||||
void createWidgetsForFiles();
|
void createWidgetsForFiles();
|
||||||
void createWidgetsForFolders();
|
void createWidgetsForFolders();
|
||||||
|
void flattenFolderStructure();
|
||||||
QStringList gatherAllTagsFromFlowWidget() const;
|
QStringList gatherAllTagsFromFlowWidget() const;
|
||||||
FlowWidget *getFlowWidget() const
|
FlowWidget *getFlowWidget() const
|
||||||
{
|
{
|
||||||
|
|
@ -28,8 +30,10 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void updateVisibility();
|
void updateVisibility();
|
||||||
bool checkVisibility();
|
bool checkVisibility();
|
||||||
|
void updateShowFolders(bool enabled);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool showFolders;
|
||||||
QVBoxLayout *layout;
|
QVBoxLayout *layout;
|
||||||
VisualDeckStorageWidget *visualDeckStorageWidget;
|
VisualDeckStorageWidget *visualDeckStorageWidget;
|
||||||
QString filePath;
|
QString filePath;
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,6 @@ VisualDeckStorageWidget::VisualDeckStorageWidget(QWidget *parent) : QWidget(pare
|
||||||
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||||
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
|
||||||
folderWidget = new VisualDeckStorageFolderDisplayWidget(this, this, SettingsCache::instance().getDeckPath(), false);
|
|
||||||
|
|
||||||
scrollArea->setWidget(folderWidget);
|
scrollArea->setWidget(folderWidget);
|
||||||
scrollArea->setWidgetResizable(true);
|
scrollArea->setWidgetResizable(true);
|
||||||
|
|
||||||
|
|
@ -123,7 +121,12 @@ void VisualDeckStorageWidget::deckPreviewDoubleClickedEvent(QMouseEvent *event,
|
||||||
|
|
||||||
void VisualDeckStorageWidget::createRootFolderWidget()
|
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->setWidget(folderWidget);
|
||||||
scrollArea->widget()->setMaximumWidth(scrollArea->viewport()->width());
|
scrollArea->widget()->setMaximumWidth(scrollArea->viewport()->width());
|
||||||
scrollArea->widget()->adjustSize();
|
scrollArea->widget()->adjustSize();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue