192 lines
5.6 KiB
C++
192 lines
5.6 KiB
C++
#include <qlistwidget.h>
|
|||
|
|
#include <qlabel.h>
|
||
|
|
#include <qwidget.h>
|
||
|
|
#include <qlayout.h>
|
||
|
|
#include <qgridlayout.h>
|
||
|
|
#include <qicon.h>
|
||
|
|
#include <simpleTools/fileManager.h>
|
||
|
|
#include <qthread.h>
|
||
|
|
#include <qmutex.h>
|
||
|
|
#include <opencv.hpp>
|
||
|
|
#include <qqueue.h>
|
||
|
|
#include <globalStruct.h>
|
||
|
|
|
||
|
|
class historyItemWidget : public QWidget
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
QGridLayout* layout = new QGridLayout(this);
|
||
|
|
historyPack _historyPack;
|
||
|
|
QLabel* resultLabel = new QLabel(this);
|
||
|
|
QLabel* fileNameLabel = new QLabel(this);
|
||
|
|
|
||
|
|
QLabel* imgShow = new QLabel();
|
||
|
|
historyItemWidget(QString title, QSize parentSize, historyPack historyPackIn)
|
||
|
|
{
|
||
|
|
if (historyPackIn.img.isNull())
|
||
|
|
return;
|
||
|
|
_historyPack = historyPackIn;
|
||
|
|
QFont font("΢ÈíÑźÚ", 12, QFont::Bold);
|
||
|
|
this->setObjectName("historyItemWidget");
|
||
|
|
QVBoxLayout* vlayout = new QVBoxLayout();
|
||
|
|
resultLabel->setText(title);
|
||
|
|
resultLabel->setFont(font);
|
||
|
|
resultLabel->setStyleSheet("QLabel { color: white; }");
|
||
|
|
vlayout->addWidget(resultLabel);
|
||
|
|
for (auto& str : historyPackIn.text)
|
||
|
|
{
|
||
|
|
QLabel* label = new QLabel(QString::fromStdString(str));
|
||
|
|
label->setFont(font);
|
||
|
|
label->setStyleSheet("QLabel { color: white; }");
|
||
|
|
vlayout->addWidget(label);
|
||
|
|
}
|
||
|
|
layout->addLayout(vlayout,0,0);
|
||
|
|
|
||
|
|
fileNameLabel->setText(QString::fromStdString(fileManager::getFileName(*historyPackIn.filePath)));
|
||
|
|
fileNameLabel->setFont(font);
|
||
|
|
fileNameLabel->setStyleSheet("QLabel { color: white; }");
|
||
|
|
layout->addWidget(fileNameLabel, 1, 0);
|
||
|
|
|
||
|
|
int iHeight = historyPackIn.img.size().height();
|
||
|
|
int pHeight = (parentSize.height() / 5);
|
||
|
|
double widthScale = iHeight / pHeight;
|
||
|
|
|
||
|
|
historyPackIn.img = historyPackIn.img.scaled(historyPackIn.img.size().width() * widthScale, parentSize.height() / 5, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||
|
|
imgShow->setPixmap(historyPackIn.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;
|
||
|
|
private:
|
||
|
|
void run() override
|
||
|
|
{
|
||
|
|
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_4);
|
||
|
|
if (mat.empty() == true)
|
||
|
|
continue;
|
||
|
|
QPixmap map;
|
||
|
|
cvMatToQPixMap(mat, map);
|
||
|
|
historyPack _historyPack;
|
||
|
|
_historyPack.filePath = std::shared_ptr<std::string>(new std::string(data.second));
|
||
|
|
_historyPack.img = map;
|
||
|
|
addDataSignal((data.second.find("OK") != std::string::npos), _historyPack);
|
||
|
|
}
|
||
|
|
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, historyPack _historyPack);
|
||
|
|
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("΢ÈíÑźÚ", 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;");
|
||
|
|
|
||
|
|
QObject::connect(this, &historyShowListWidget::asyncReadImgSignal, &_historyShowListSubThread, &historyShowListSubThread::asyncReadImg);
|
||
|
|
QObject::connect(this, &historyShowListWidget::asyncReadIconsSignal, &_historyShowListSubThread, &historyShowListSubThread::asyncReadIcons);
|
||
|
|
QObject::connect(showDataListWidget, &QListWidget::itemClicked, this, &historyShowListWidget::itemClick);
|
||
|
|
QObject::connect(&_historyShowListSubThread, &historyShowListSubThread::addDataSignal, this, &historyShowListWidget::addData);
|
||
|
|
}
|
||
|
|
public slots:
|
||
|
|
void addImgFromPath(QString path)
|
||
|
|
{
|
||
|
|
std::vector<std::string> files;
|
||
|
|
std::string pathStr = fileManager::normalizePathSeparators(path).toStdString();
|
||
|
|
fileManager::getAllImages(pathStr, files, "",1);
|
||
|
|
if (files.size() == 0)
|
||
|
|
return;
|
||
|
|
showDataListWidget->clear();
|
||
|
|
emit asyncReadIconsSignal(files);
|
||
|
|
|
||
|
|
}
|
||
|
|
void addData(bool isOk, historyPack _historyPack)
|
||
|
|
{
|
||
|
|
QString title;
|
||
|
|
if (isOk == true)
|
||
|
|
title = "OK";
|
||
|
|
else
|
||
|
|
title = "NG";
|
||
|
|
QWidget* widget = new historyItemWidget(title,size(), _historyPack);
|
||
|
|
QListWidgetItem* item = new QListWidgetItem();
|
||
|
|
showDataListWidget->addItem(item);
|
||
|
|
showDataListWidget->setItemWidget(item, widget);
|
||
|
|
item->setSizeHint(widget->sizeHint());
|
||
|
|
widget->show();
|
||
|
|
showDataListWidget->scrollToBottom();
|
||
|
|
}
|
||
|
|
void reset()
|
||
|
|
{
|
||
|
|
showDataListWidget->clear();
|
||
|
|
}
|
||
|
|
private slots:
|
||
|
|
void itemClick(QListWidgetItem* item)
|
||
|
|
{
|
||
|
|
historyItemWidget* widget = (historyItemWidget*)showDataListWidget->itemWidget(item);
|
||
|
|
std::string path = *widget->_historyPack.filePath;
|
||
|
|
QString pathQ = QString::fromStdString(path);
|
||
|
|
emit asyncReadImgSignal(path);
|
||
|
|
emit itemClickSignal(pathQ);
|
||
|
|
}
|
||
|
|
signals:
|
||
|
|
void asyncReadImgSignal(std::string);
|
||
|
|
void asyncReadIconsSignal(std::vector<std::string>);
|
||
|
|
void itemClickSignal(QString path);
|
||
|
|
};
|
||
|
|
#pragma once
|