暂存
This commit is contained in:
@@ -58,8 +58,10 @@ public:
|
||||
/// <param name="path"></param>
|
||||
/// <param name="files"></param>
|
||||
/// <param name="format"></param>
|
||||
static void getAllFiles(std::string path, std::vector<std::string>& files, std::string format)
|
||||
static void getAllFiles(std::string path, std::vector<std::string>& files, std::string format, int targetDepth = INT_MAX, int depth = 0)
|
||||
{
|
||||
if (depth >= targetDepth)
|
||||
return;
|
||||
intptr_t hFile = 0;
|
||||
struct _finddata_t fileinfo;
|
||||
std::string p;
|
||||
@@ -72,7 +74,8 @@ public:
|
||||
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
|
||||
{
|
||||
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
|
||||
getAllFiles(p.assign(path).append("\\").append(fileinfo.name), files, format);
|
||||
depth++;
|
||||
getAllFiles(p.assign(path).append("\\").append(fileinfo.name), files, format, targetDepth ,depth);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -84,6 +87,44 @@ public:
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取文件夹下的图片,以vector<string>返回
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="files"></param>
|
||||
/// <param name="format"></param>
|
||||
static void getAllImages(std::string path, std::vector<std::string>& files, std::string format, int targetDepth = INT_MAX, int depth = 0)
|
||||
{
|
||||
if (depth >= targetDepth)
|
||||
return;
|
||||
intptr_t hFile = 0;
|
||||
struct _finddata_t fileinfo;
|
||||
std::string p;
|
||||
if ((hFile = _findfirst(p.assign(path).append("\\*" + format).c_str(), &fileinfo)) != -1)
|
||||
{
|
||||
do
|
||||
{
|
||||
if ((fileinfo.attrib & _A_SUBDIR))
|
||||
{
|
||||
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
|
||||
{
|
||||
std::string filePath = p.assign(path).append("\\").append(fileinfo.name);
|
||||
if (fileManager::isImageFile(filePath) == true)
|
||||
files.push_back(filePath);
|
||||
depth++;
|
||||
getAllFiles(filePath, files, format, targetDepth, depth);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string filePath = p.assign(path).append("\\").append(fileinfo.name);
|
||||
if (fileManager::isImageFile(filePath) == true)
|
||||
files.push_back(filePath);
|
||||
}
|
||||
} while (_findnext(hFile, &fileinfo) == 0);
|
||||
_findclose(hFile);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 检查磁盘剩余空间,以GB为单位返回
|
||||
/// </summary>
|
||||
/// <param name="folderPath">example"E://""E://111/222"支持文件夹或者磁盘路径</param>
|
||||
@@ -191,6 +232,56 @@ public:
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//去除重复分割符
|
||||
static QString normalizePathSeparators(const QString& path) {
|
||||
QString normalizedPath = path;
|
||||
|
||||
// Replace backslashes with forward slashes
|
||||
normalizedPath.replace('\\', '/');
|
||||
|
||||
// Remove consecutive forward slashes
|
||||
QString doubleSlash = "//";
|
||||
while (normalizedPath.contains(doubleSlash)) {
|
||||
normalizedPath.replace(doubleSlash, "/");
|
||||
}
|
||||
|
||||
return normalizedPath;
|
||||
}
|
||||
|
||||
static bool isImageFile(const std::string& filename) {
|
||||
const std::string imageExtensions[] = { ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".webp" };
|
||||
|
||||
std::string lowerFilename = filename;
|
||||
std::transform(lowerFilename.begin(), lowerFilename.end(), lowerFilename.begin(), [](unsigned char c) { return std::tolower(c); });
|
||||
|
||||
for (const std::string& ext : imageExtensions) {
|
||||
if (lowerFilename.size() >= ext.size() &&
|
||||
lowerFilename.compare(lowerFilename.size() - ext.size(), ext.size(), ext) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
static std::string getFileName(std::string path)
|
||||
{
|
||||
return path.substr(path.find_last_of("\\") + 1, path.find_last_of(".") - path.find_last_of("\\") - 1);
|
||||
}
|
||||
static QString getFileName(const QString& path) {
|
||||
int lastSlashIndex = path.lastIndexOf('/');
|
||||
if (lastSlashIndex == -1) {
|
||||
lastSlashIndex = path.lastIndexOf('\\');
|
||||
}
|
||||
|
||||
int lastDotIndex = path.lastIndexOf('.');
|
||||
|
||||
if (lastDotIndex == -1 || lastDotIndex < lastSlashIndex) {
|
||||
return path.mid(lastSlashIndex + 1);
|
||||
}
|
||||
else {
|
||||
return path.mid(lastSlashIndex + 1, lastDotIndex - lastSlashIndex - 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
/// <summary>
|
||||
/// 自动删除文件夹,支持按日期删除,按磁盘剩余容量删除,或者两者都是,请在主线程声明qtimer
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#include <QWidget>
|
||||
#include <qlayout.h>
|
||||
#include <qtablewidget.h>
|
||||
#include <sqlManager/sqlManager.h>
|
||||
#include <qlabel.h>
|
||||
#include <qstackedwidget.h>
|
||||
#include <uiModule/components/fancyButton.h>
|
||||
#include <uiModule/uiModule_imageView.h>
|
||||
#include <uiModule/uiModule_historyListWidget.h>
|
||||
#include <uiModule/uiModule_menuListWdiget.h>
|
||||
|
||||
class historyWidget :public QWidget
|
||||
{
|
||||
public:
|
||||
QVBoxLayout* Layout = new QVBoxLayout(this);
|
||||
QHBoxLayout* btnLayout = new QHBoxLayout(this);
|
||||
std::vector<gradientButton*>btns;
|
||||
QLabel* icon, * Title;
|
||||
|
||||
QWidget* widgets = new QWidget();
|
||||
QGridLayout* mainWidgetLayout = new QGridLayout(widgets);
|
||||
|
||||
ImageWidget imageWidget;
|
||||
menuListWidget dirListWidget;
|
||||
historyShowListWidget _historyShowListWidget;
|
||||
historyWidget()
|
||||
{
|
||||
QPalette palette;
|
||||
palette.setColor(QPalette::WindowText, Qt::white);
|
||||
QFont font("微软雅黑", 24, QFont::Bold);
|
||||
QFont font2("微软雅黑", 108, QFont::Bold);
|
||||
|
||||
widgets->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
widgets->setMaximumSize(9999, 9999);
|
||||
|
||||
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
this->setMaximumSize(9999, 9999);
|
||||
this->setObjectName("historyWidget");
|
||||
|
||||
Layout->setContentsMargins(0, 0, 0, 0);
|
||||
Layout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
|
||||
Title = new QLabel(u8"历史图片");
|
||||
Title->setFont(font);
|
||||
Title->setPalette(palette);
|
||||
Title->setAlignment(Qt::AlignLeft);
|
||||
|
||||
Layout->addWidget(Title);
|
||||
|
||||
btnLayout->setContentsMargins(0, 0, 0, 0);
|
||||
btnLayout->setAlignment(Qt::AlignLeft);
|
||||
|
||||
Layout->addLayout(btnLayout);
|
||||
|
||||
mainWigetInit();
|
||||
Layout->addWidget(widgets);
|
||||
QObject::connect(&_historyShowListWidget._historyShowListSubThread, &historyShowListSubThread::readImgSignal, &imageWidget, &ImageWidget::showImgOnGraphicsView);
|
||||
}
|
||||
void mainWigetInit()
|
||||
{
|
||||
imageWidget.setTitle("图片查看");
|
||||
mainWidgetLayout->addWidget(&imageWidget , 0, 0);
|
||||
mainWidgetLayout->setColumnStretch(0, 5);
|
||||
|
||||
mainWidgetLayout->addWidget(&dirListWidget, 0, 1);
|
||||
mainWidgetLayout->addWidget(&_historyShowListWidget, 0, 2);
|
||||
mainWidgetLayout->setColumnStretch(1, 1);
|
||||
mainWidgetLayout->setColumnStretch(2, 2);
|
||||
|
||||
dirListWidget.setStyleSheet("background: transparent;");
|
||||
QObject::connect(&dirListWidget, &menuListWidget::switchPathSignal, &_historyShowListWidget, &historyShowListWidget::addImgFromPath);
|
||||
}
|
||||
};
|
||||
#pragma once
|
||||
@@ -101,10 +101,6 @@ static void cvMatToQPixMap(cv::Mat& src,QPixmap& pixmap)
|
||||
{
|
||||
pixmap = QPixmap::fromImage(cvMatToQImage(src));
|
||||
}
|
||||
static std::string getFileName(std::string path)
|
||||
{
|
||||
return path.substr(path.find_last_of("\\") + 1, path.find_last_of(".") - path.find_last_of("\\") - 1);
|
||||
}
|
||||
Q_DECLARE_METATYPE(imgWidgetShowType)
|
||||
Q_DECLARE_METATYPE(cv::Mat*)
|
||||
#pragma once
|
||||
@@ -23,6 +23,7 @@
|
||||
<file>icon/fullscreen-exit.png</file>
|
||||
<file>icon/minus.png</file>
|
||||
<file>icon/home.png</file>
|
||||
<file>icon/home2.png</file>
|
||||
<file>icon/config.png</file>
|
||||
<file>icon/menu.png</file>
|
||||
<file>icon/save.png</file>
|
||||
@@ -33,5 +34,7 @@
|
||||
<file>icon/loading.gif</file>
|
||||
<file>icon/sql.png</file>
|
||||
<file>icon/error.png</file>
|
||||
<file>icon/history.png</file>
|
||||
<file>icon/rollback.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
@@ -209,6 +209,7 @@ void MainWindow::leftBarInit()
|
||||
pageWidgets.addWidget(_configSettingWidget);
|
||||
pageBtns.push_back(configBtn);
|
||||
|
||||
//手动检测
|
||||
toolBarButton* manulDet = new toolBarButton(
|
||||
defaultWidth,
|
||||
defaultHeight,
|
||||
@@ -218,6 +219,16 @@ void MainWindow::leftBarInit()
|
||||
pageWidgets.addWidget(_manualDetWidget);
|
||||
pageBtns.push_back(manulDet);
|
||||
|
||||
//历史图片
|
||||
toolBarButton* historyImgs = new toolBarButton(
|
||||
defaultWidth,
|
||||
defaultHeight,
|
||||
QIcon(":/topBar/icon/history.png"),
|
||||
u8"历史图片");
|
||||
_historyWidget = new historyWidget();
|
||||
pageWidgets.addWidget(_historyWidget);
|
||||
pageBtns.push_back(historyImgs);
|
||||
|
||||
//日志页面
|
||||
toolBarButton* logBtn = new toolBarButton(
|
||||
defaultWidth,
|
||||
@@ -228,6 +239,7 @@ void MainWindow::leftBarInit()
|
||||
pageWidgets.addWidget(_logWidget);
|
||||
pageBtns.push_back(logBtn);
|
||||
|
||||
//SQL
|
||||
toolBarButton* sqlBtn = new toolBarButton(
|
||||
defaultWidth,
|
||||
defaultHeight,
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <pages/logPageWidget.h>
|
||||
#include <pages/sqlControlWidget.h>
|
||||
#include <pages/manualDetWidget.h>
|
||||
#include <front/pages/historyWidget.h>
|
||||
|
||||
#pragma execution_character_set("utf-8")
|
||||
|
||||
@@ -52,6 +53,7 @@ public:
|
||||
logWidget* _logWidget;
|
||||
sqlControlWidget* _sqlControlWidget;
|
||||
manualDetWidget* _manualDetWidget;
|
||||
historyWidget* _historyWidget;
|
||||
private:
|
||||
Ui::MainWindow* ui;
|
||||
fbBridge* fbBridgePtr;
|
||||
@@ -98,7 +100,6 @@ public slots:
|
||||
showMinimized();
|
||||
}
|
||||
|
||||
|
||||
void toggleMaximize(toggleMaximizeEnum toggleMaximizeEnumIn = reverse)
|
||||
{
|
||||
switch (toggleMaximizeEnumIn)
|
||||
|
||||
@@ -4,49 +4,152 @@
|
||||
#include <qlayout.h>
|
||||
#include <qgridlayout.h>
|
||||
#include <qicon.h>
|
||||
class historyItem : public QWidget
|
||||
#include <fileManager.h>
|
||||
#include <qthread.h>
|
||||
class historyItemWidget : public QWidget
|
||||
{
|
||||
public:
|
||||
QGridLayout* layout = new QGridLayout(this);
|
||||
|
||||
QLabel* resultShow = new QLabel("²âÊÔ²âÊÔ");
|
||||
QLabel* resultLabel = new QLabel(this);
|
||||
QLabel* fileNameLabel = new QLabel(this);
|
||||
QLabel* filePathHide = new QLabel(this);
|
||||
|
||||
QLabel* imgShow = new QLabel();
|
||||
//QIcon* icon = new QIcon(":/topBar/icon/fullscreen.png");
|
||||
historyItem()
|
||||
historyItemWidget(QString title,std::string filePath,QPixmap img , QSize parentSize)
|
||||
{
|
||||
layout->addWidget(resultShow,0,0);
|
||||
imgShow->setPixmap(QPixmap(":/topBar/icon/waiting.png"));
|
||||
if (img.isNull())
|
||||
return;
|
||||
QFont font("΢ÈíÑźÚ", 12, QFont::Bold);
|
||||
|
||||
resultLabel->setText(title);
|
||||
resultLabel->setFont(font);
|
||||
resultLabel->setStyleSheet("QLabel { color: white; }");
|
||||
layout->addWidget(resultLabel,0,0);
|
||||
|
||||
filePathHide->setText(QString::fromStdString(filePath));
|
||||
filePathHide->hide();
|
||||
filePathHide->setObjectName("path");
|
||||
|
||||
fileNameLabel->setText(QString::fromStdString(fileManager::getFileName(filePath)));
|
||||
fileNameLabel->setFont(font);
|
||||
fileNameLabel->setStyleSheet("QLabel { color: white; }");
|
||||
layout->addWidget(fileNameLabel, 1, 0);
|
||||
|
||||
int iHeight = img.size().height();
|
||||
int pHeight = (parentSize.height() / 5);
|
||||
double widthScale = iHeight / pHeight;
|
||||
|
||||
img = img.scaled(img.size().width() * widthScale, parentSize.height() / 5, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
imgShow->setPixmap(img);
|
||||
layout->addWidget(imgShow,0,1);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
}
|
||||
};
|
||||
class historyShowListSubThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QMutex queueMutex;
|
||||
QQueue<std::pair<int, std::string>> queue;
|
||||
void run()
|
||||
{
|
||||
while (queue.size() > 0)
|
||||
{
|
||||
queueMutex.lock();
|
||||
std::pair<int, std::string> data = queue.dequeue();
|
||||
queueMutex.unlock();
|
||||
if (data.first == 0)
|
||||
{
|
||||
cv::Mat mat = cv::imread(data.second, cv::IMREAD_REDUCED_COLOR_8);
|
||||
if (mat.empty() == true)
|
||||
continue;
|
||||
QPixmap map;
|
||||
cvMatToQPixMap(mat, map);
|
||||
addDataSignal((data.second.find("OK") != std::string::npos), data.second, map);
|
||||
}
|
||||
else if (data.first == 1)
|
||||
{
|
||||
cv::Mat mat = cv::imread(data.second, -1);
|
||||
if (mat.empty() == true)
|
||||
return;
|
||||
QPixmap map;
|
||||
cvMatToQPixMap(mat, map);
|
||||
emit readImgSignal(map);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public slots:
|
||||
void asyncReadIcons(std::vector<std::string> files)
|
||||
{
|
||||
for (auto file : files)
|
||||
{
|
||||
queueMutex.lock();
|
||||
queue.enqueue(std::make_pair(0, file));
|
||||
queueMutex.unlock();
|
||||
this->start();
|
||||
}
|
||||
}
|
||||
void asyncReadImg(std::string filePath)
|
||||
{
|
||||
queueMutex.lock();
|
||||
queue.enqueue(std::make_pair(1, filePath));
|
||||
queueMutex.unlock();
|
||||
this->start();
|
||||
}
|
||||
signals:
|
||||
void addDataSignal(bool isOk, std::string filePath, QPixmap img);
|
||||
void readImgSignal(QPixmap img);
|
||||
};
|
||||
class historyShowListWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QLabel* title = new QLabel(u8"ÀúÊ·¼Ç¼");
|
||||
QListWidget* showDataListWidget = new QListWidget();
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
historyShowListSubThread _historyShowListSubThread;
|
||||
historyShowListWidget()
|
||||
{
|
||||
QPalette palette;
|
||||
palette.setColor(QPalette::WindowText, Qt::white);
|
||||
QFont font("΢ÈíÑźÚ", 12, QFont::Bold);
|
||||
QFont font("΢ÈíÑźÚ", 16, QFont::Bold);
|
||||
QHBoxLayout* hLayout = new QHBoxLayout();
|
||||
|
||||
title->setPalette(palette);
|
||||
title->setFont(font);
|
||||
title->setStyleSheet("QLabel { color: white; }");
|
||||
|
||||
layout->addWidget(title);
|
||||
layout->addWidget(showDataListWidget);
|
||||
this->setStyleSheet("background: transparent;");
|
||||
|
||||
|
||||
//addData();
|
||||
QObject::connect(this, &historyShowListWidget::asyncReadImgSignal, &_historyShowListSubThread, &historyShowListSubThread::asyncReadImg);
|
||||
QObject::connect(this, &historyShowListWidget::asyncReadIconsSignal, &_historyShowListSubThread, &historyShowListSubThread::asyncReadIcons);
|
||||
QObject::connect(&_historyShowListSubThread, &historyShowListSubThread::addDataSignal, this, &historyShowListWidget::addData);
|
||||
QObject::connect(showDataListWidget, &QListWidget::itemClicked, this, &historyShowListWidget::itemClick);
|
||||
|
||||
}
|
||||
void addData(bool isOk,QPixmap& img)
|
||||
public slots:
|
||||
void addImgFromPath(QString path)
|
||||
{
|
||||
QWidget* widget = new historyItem();
|
||||
std::vector<std::string> files;
|
||||
fileManager::getAllImages(path.toStdString(), files, "",1);
|
||||
if (files.size() == 0)
|
||||
return;
|
||||
showDataListWidget->clear();
|
||||
emit asyncReadIconsSignal(files);
|
||||
|
||||
}
|
||||
void addData(bool isOk, std::string filePath, QPixmap img)
|
||||
{
|
||||
QString title;
|
||||
if (isOk == true)
|
||||
title = "OK";
|
||||
else
|
||||
title = "NG";
|
||||
QWidget* widget = new historyItemWidget(title, filePath, img, size());
|
||||
QListWidgetItem* item = new QListWidgetItem();
|
||||
showDataListWidget->addItem(item);
|
||||
showDataListWidget->setItemWidget(item, widget);
|
||||
@@ -57,4 +160,23 @@ public:
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
private slots:
|
||||
void itemClick(QListWidgetItem* item)
|
||||
{
|
||||
QWidget* widget = showDataListWidget->itemWidget(item);
|
||||
const QList<QLabel*> labels = widget->findChildren<QLabel*>();
|
||||
for (const QLabel* label : labels)
|
||||
{
|
||||
if (label->objectName() == "path")
|
||||
{
|
||||
QString path = label->text();
|
||||
emit asyncReadImgSignal(path.toStdString());
|
||||
}
|
||||
}
|
||||
}
|
||||
signals:
|
||||
void asyncReadImgSignal(std::string);
|
||||
void asyncReadIconsSignal(std::vector<std::string>);
|
||||
void itemClickSignal(QString path);
|
||||
};
|
||||
#pragma once
|
||||
@@ -173,6 +173,7 @@ private:
|
||||
QMutex mutex;
|
||||
};
|
||||
class ImageWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ImageWidget(QWidget* parent = nullptr) : QWidget(parent) {
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
@@ -236,6 +237,7 @@ public:
|
||||
void setTitle(const QString& text) {
|
||||
label->setText(text);
|
||||
}
|
||||
public slots:
|
||||
//set不一定显示,要根据当前显示的类型决定
|
||||
void setOriImg(QPixmap oriImgInput)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
#include <qlistwidget.h>
|
||||
#include <fileManager.h>
|
||||
#include <qlinkedlist.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <uiModule/components/fancyButton.h>
|
||||
#include <qlayout.h>
|
||||
#include <FrontendBackendBridge.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();
|
||||
_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;
|
||||
|
||||
//写入
|
||||
pathList.clear();
|
||||
depth = list.size() - 1;
|
||||
for (auto str : list)
|
||||
pathList.append(str);
|
||||
|
||||
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
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user