139 lines
3.7 KiB
C++
139 lines
3.7 KiB
C++
#include <qlistwidget.h>
|
|
#include <simpleTools/fileManager.h>
|
|
#include <qlinkedlist.h>
|
|
#include <qpushbutton.h>
|
|
#include <uiModule/components/fancyButton.h>
|
|
#include <qlayout.h>
|
|
#include <FrontendBackendBridge.h>
|
|
#include <qlabel.h>
|
|
|
|
class toolItemWidget :public QWidget
|
|
{
|
|
public:
|
|
QHBoxLayout* layout = new QHBoxLayout(this);
|
|
fancyButton* returnBtn;
|
|
fancyButton* homeBtn;
|
|
QLabel* dirLabel = new QLabel();
|
|
toolItemWidget(QString title)
|
|
{
|
|
QFont font("微软雅黑", 24, QFont::Bold);
|
|
QPalette palette;
|
|
palette.setColor(QPalette::WindowText, Qt::white);
|
|
|
|
returnBtn = new fancyButton(40,40, QIcon(":/topBar/icon/rollback.png"),"返回上一级");
|
|
layout->addWidget(returnBtn);
|
|
|
|
homeBtn = new fancyButton(40, 40, QIcon(":/topBar/icon/home2.png"), "返回目录");
|
|
layout->addWidget(homeBtn);
|
|
|
|
dirLabel->setText(title);
|
|
dirLabel->setFont(font);
|
|
dirLabel->setStyleSheet("QLabel { color: white; }");
|
|
|
|
layout->addWidget(dirLabel);
|
|
layout->setAlignment(Qt::AlignLeft);
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
}
|
|
};
|
|
|
|
class menuListWidget : public QListWidget
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
QString basePath = bridge.back.json.imgSavePath;
|
|
menuListWidget()
|
|
{
|
|
_toolItemWidget = new toolItemWidget(basePath);
|
|
pathList.append(basePath);
|
|
refreshListWidget();
|
|
targetDepth = pathList.size();
|
|
depth = targetDepth;
|
|
_toolItemWidget->returnBtn->setDisabled(true);
|
|
_toolItemWidget->homeBtn->setDisabled(true);
|
|
QObject::connect(this, &QListWidget::itemClicked, this, &menuListWidget::itemClick);
|
|
//jumpWithPath("D://////CCD/yuantu/2024-06-04/23H/TEST");
|
|
}
|
|
void addTools(QString title)
|
|
{
|
|
QListWidgetItem* item = new QListWidgetItem();
|
|
this->addItem(item);
|
|
if (_toolItemWidget != nullptr)
|
|
delete _toolItemWidget;
|
|
_toolItemWidget = new toolItemWidget(title);
|
|
item->setSizeHint(_toolItemWidget->sizeHint());
|
|
QObject::connect(_toolItemWidget->returnBtn, &QPushButton::clicked, this, &menuListWidget::returnLast);
|
|
QObject::connect(_toolItemWidget->homeBtn, &QPushButton::clicked, this, &menuListWidget::toMenu);
|
|
this->setItemWidget(item, _toolItemWidget);
|
|
}
|
|
void returnLast()
|
|
{
|
|
if (depth <= targetDepth)
|
|
return;
|
|
depth--;
|
|
pathList.removeLast();
|
|
refreshListWidget();
|
|
if (depth <= targetDepth)
|
|
{
|
|
_toolItemWidget->returnBtn->setDisabled(true);
|
|
_toolItemWidget->homeBtn->setDisabled(true);
|
|
}
|
|
}
|
|
void refreshListWidget()
|
|
{
|
|
this->clear();
|
|
addTools(pathList.last());
|
|
QString path;
|
|
for (auto p : pathList)
|
|
path.append(p + "/");
|
|
QFont font("微软雅黑", 18, QFont::Bold);
|
|
std::vector<std::string> result = fileManager::getAllDirs(path);
|
|
for (auto dirName : result)
|
|
{
|
|
QListWidgetItem* item = new QListWidgetItem(QString::fromStdString(dirName));
|
|
item->setFont(font);
|
|
item->setForeground(QBrush(QColor(Qt::white)));
|
|
this->addItem(item);
|
|
}
|
|
emit switchPathSignal(path);
|
|
}
|
|
void toMenu()
|
|
{
|
|
jumpWithPath(basePath+"\\");
|
|
}
|
|
void jumpWithPath(QString path)
|
|
{
|
|
//分割字符串
|
|
path = fileManager::normalizePathSeparators(path);
|
|
QStringList list = path.split("/");
|
|
if (list.size() == 0)
|
|
list = path.split("\\");
|
|
if (list.size() == 0)
|
|
return;
|
|
|
|
//写入
|
|
//std::string fileName = fileManager::getFileName(path.toStdString());
|
|
pathList.clear();
|
|
for (auto str : list)
|
|
//if (str.contains(QString::fromStdString(fileName)) == false)
|
|
pathList.append(str);
|
|
|
|
depth = pathList.size() - 1;
|
|
refreshListWidget();
|
|
}
|
|
private:
|
|
toolItemWidget* _toolItemWidget = nullptr;
|
|
int depth = 0,targetDepth = 0;
|
|
QLinkedList<QString> pathList;
|
|
private slots:
|
|
void itemClick(QListWidgetItem* item)
|
|
{
|
|
if (item->text().isEmpty())
|
|
return;
|
|
pathList.append(item->text());
|
|
depth++;
|
|
refreshListWidget();
|
|
}
|
|
signals:
|
|
void switchPathSignal(QString path);
|
|
};
|
|
#pragma once |