opencv_mv/QMainPro/QMacVisual/frmToolsTree.cpp

256 lines
9.8 KiB
C++
Raw Normal View History

2023-05-22 09:27:46 +00:00
#include "frmToolsTree.h"
#include <QHeaderView>
#include <QStyleFactory>
#include <QDir>
#include <QPluginLoader>
#include "GlobalVariable.h"
QString ThemeColor = "#20B2AA";
frmToolsTree::frmToolsTree(QWidget* parent)
: QWidget(parent)
{
ui.setupUi(this);
setWindowFlags(Qt::FramelessWindowHint);
ToolsTreeWidgetInit();
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD>ʼ<EFBFBD><CABC>
void frmToolsTree::ToolsTreeWidgetInit()
{
ToolTreeWidget = new QtTreeWidget(this);
QGridLayout* ToolGLayout = new QGridLayout(ui.ToolTreeFrame);
ToolGLayout->setContentsMargins(0, 0, 0, 0);
ToolGLayout->setSpacing(5);
ToolGLayout->addWidget(ToolTreeWidget, 0, 0);
ToolTreeWidget->setIconSize(QSize(24, 24));
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
ToolTreeWidget->setStyle(QStyleFactory::create("windows"));
//<2F><><EFBFBD><EFBFBD>ϵͳĬ<CDB3><C4AC>ͼ<EFBFBD><CDBC>
ToolTreeWidget->setStyleSheet("QTreeWidget::branch:has-children:!has-siblings:closed,\
QWidget{border: 1px;border-style: solid;border-color: #d9d9d9}\
QTreeWidget::item{color: #363636}\
QTreeWidget::item{height: 30px}\
QTreeView::item::selected{background-color:#96B5A8}\
QTreeWidget::branch:closed:has-children:!has-siblings{border-style: none; border-image: none; image: url(:/res/ico/unfold.png);}\
QTreeWidget::branch:closed:has-children:has-siblings{border-image: none; image: url(:/res/ico/unfold.png);}\
QTreeWidget::branch:open:has-children:!has-siblings{border-image: none; image: url(:/res/ico/fold.png);}\
QTreeWidget::branch:open:has-children:has-siblings{border-image: none; image: url(:/res/ico/fold.png);}"
"QScrollBar:vertical{" //<2F><><EFBFBD>ù<EFBFBD><C3B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
"background:#FFFFF2;" //<2F><><EFBFBD><EFBFBD>ɫ
"padding-top:20px;" //<2F><>Ԥ<EFBFBD><D4A4>λ<EFBFBD><CEBB>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD>ͷ<EFBFBD><CDB7>
"padding-bottom:20px;" //<2F><>Ԥ<EFBFBD><D4A4>λ<EFBFBD><CEBB>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>ͷ<EFBFBD><CDB7>
"padding-left:2px;" //<2F><>Ԥ<EFBFBD><D4A4>λ<EFBFBD><CEBB>
"padding-right:2px;" //<2F><>Ԥ<EFBFBD><D4A4>λ<EFBFBD><CEBB>
"border-left:1px solid #d7d7d7;}" //<2F><><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>
"QScrollBar::handle:vertical{" //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
"background:#dbdbdb;" //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
"border-radius:6px;" //<2F>߽<EFBFBD>Բ
"min-height:20px;}" //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>߶<EFBFBD>
"QScrollBar::handle:vertical:hover{" //<2F><><EFBFBD><EFBFBD><EAB4A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
"background:#d0d0d0;}" //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
"QScrollBar::add-line:vertical{" //<2F><><EFBFBD>¼<EFBFBD>ͷ<EFBFBD><CDB7>ʽ
"background:url(:/res/ico/down.png) center no-repeat;}"
"QScrollBar::sub-line:vertical{" //<2F><><EFBFBD>ϼ<EFBFBD>ͷ<EFBFBD><CDB7>ʽ
"background:url(:/res/ico/up.png) center no-repeat;}");
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E5BCB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
QFont font("Microsoft YaHei");
font.setPixelSize(16.5);
ToolTreeWidget->setFont(font);
ToolTreeWidget->header()->setVisible(false);
ToolTreeWidget->clear();
this->setAcceptDrops(false);
//<2F><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
ToolsPair toolPair;
//ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LoadPlugins("ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"); //<2F><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
toolPair.first = "ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
toolPair.second = ToolNameList;
ToolNamesVec.push_back(toolPair);
ToolNameList.clear();
//<2F><><EFBFBD><EFBFBD>ʶ<EFBFBD><CAB6>
LoadPlugins("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD>"); //<2F><><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD>ʶ<EFBFBD><CAB6>
toolPair.first = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD>";
toolPair.second = ToolNameList;
ToolNamesVec.push_back(toolPair);
ToolNameList.clear();
//<2F><EFBFBD><EAB6A8><EFBFBD><EFBFBD>
LoadPlugins("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"); //<2F><><EFBFBD>ر궨<D8B1><EAB6A8><EFBFBD><EFBFBD>
toolPair.first = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
toolPair.second = ToolNameList;
ToolNamesVec.push_back(toolPair);
ToolNameList.clear();
//<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>
LoadPlugins("<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"); //<2F><><EFBFBD>ض<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>
toolPair.first = "<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
toolPair.second = ToolNameList;
ToolNamesVec.push_back(toolPair);
ToolNameList.clear();
//<2F><><EFBFBD>ι<EFBFBD><CEB9><EFBFBD>
LoadPlugins("<EFBFBD><EFBFBD><EFBFBD>ι<EFBFBD><EFBFBD><EFBFBD>"); //<2F><><EFBFBD>ؼ<EFBFBD><D8BC>ι<EFBFBD><CEB9><EFBFBD>
toolPair.first = "<EFBFBD><EFBFBD><EFBFBD>ι<EFBFBD><EFBFBD><EFBFBD>";
toolPair.second = ToolNameList;
ToolNamesVec.push_back(toolPair);
ToolNameList.clear();
//<2F><><EFBFBD>β<EFBFBD><CEB2><EFBFBD>
LoadPlugins("<EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><EFBFBD><EFBFBD>"); //<2F><><EFBFBD>ؼ<EFBFBD><D8BC>β<EFBFBD><CEB2><EFBFBD>
toolPair.first = "<EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><EFBFBD><EFBFBD>";
toolPair.second = ToolNameList;
ToolNamesVec.push_back(toolPair);
ToolNameList.clear();
//<2F><>ά<EFBFBD><CEAC><EFBFBD><EFBFBD>
LoadPlugins("<EFBFBD><EFBFBD>ά<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ά<EFBFBD><CEAC><EFBFBD><EFBFBD>
toolPair.first = "<EFBFBD><EFBFBD>ά<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
toolPair.second = ToolNameList;
ToolNamesVec.push_back(toolPair);
ToolNameList.clear();
//<2F>߼<EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD>
LoadPlugins("<EFBFBD>߼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"); //<2F><><EFBFBD><EFBFBD><EFBFBD>߼<EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD>
toolPair.first = "<EFBFBD>߼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
toolPair.second = ToolNameList;
ToolNamesVec.push_back(toolPair);
ToolNameList.clear();
//ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD>
LoadPlugins("ͨѶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"); //<2F><><EFBFBD><EFBFBD>ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD>
toolPair.first = "ͨѶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
toolPair.second = ToolNameList;
ToolNamesVec.push_back(toolPair);
ToolNameList.clear();
//ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>
LoadPlugins("ϵͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"); //<2F><><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>
toolPair.first = "ϵͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
toolPair.second = ToolNameList;
ToolNamesVec.push_back(toolPair);
ToolNameList.clear();
//ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
for (int i = 0; i < ToolNamesVec.size(); i++)
{
QString toolBoxName = ToolNamesVec[i].first;
QStringList toolList = QStringList::fromStdList(ToolNamesVec[i].second);
QTreeWidgetItem* itemParent = new QTreeWidgetItem(ToolTreeWidget);
itemParent->setText(0, toolBoxName);
itemParent->setIcon(0, QIcon(":/res/ico/tool.ico"));
itemParent->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled);
for (int j = 0; j < toolList.count(); j++)
{
QTreeWidgetItem* treeItem = new QTreeWidgetItem(itemParent, QStringList(toolList[j]));
QPixmap pixmap = GetIcon(GetIconName(toolList[j]));
treeItem->setIcon(0, pixmap);
}
}
}
/*
* @function PluginsApp::LoadPlugins <EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Plugins<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return <EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><EFBFBD><EFBFBD>
*/
int frmToolsTree::LoadPlugins(QString str)
{
int count = 0;
QDir pluginsDir = QDir(qApp->applicationDirPath());
if (!pluginsDir.cd("Plugins")) return -1;
QStringList filters;
filters << "*.dll"; //<2F><><EFBFBD>Զ<EFBFBD><D4B6>ָ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD><EFBFBD>ʽ
pluginsDir.setFilter(QDir::Files | QDir::NoSymLinks); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͹<EFBFBD><CDB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻΪ<D6BB>ļ<EFBFBD><C4BC><EFBFBD>ʽ
pluginsDir.setNameFilters(filters); //<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD><EFBFBD><EFBFBD>
foreach(QString fileName, pluginsDir.entryList())
{
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
QObject* plugin = pluginLoader.instance();
if (plugin)
{
auto treeInterface = qobject_cast<MainInterface*>(plugin);
if (treeInterface)
{
++count;
//<2F><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Tree
PopulateTree(str, plugin, treeInterface);
}
}
}
return count;
}
/*
* @function PluginsApp::PopulateTree <EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Tree
* @param pluginInterface <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param i <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ֵĽӿ<EFBFBD>
*/
void frmToolsTree::PopulateTree(QString str, QObject* pluginInterface, MainInterface* i)
{
try
{
if (i->information() == str)
{
ToolNameList.push_back(i->name());
}
}
catch(...){}
}
// <20><>ȡͼ<C8A1><CDBC>
QPixmap frmToolsTree::GetIcon(QString fileName)
{
return IconHelper::Instance()->getPixmap(fileName);
}
// <20><>ȡͼ<C8A1><CDBC>·<EFBFBD><C2B7>
QString frmToolsTree::GetIconName(QString Name)
{
QString IconName;
if (Name.contains("<EFBFBD><EFBFBD>ȡͼ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/image_source.png";
if (Name.contains("ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ")) IconName = ":/res/ico/image_view.ico";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/export_image.png";
if (Name.contains("Ԥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/morphology.png";
if (Name.contains("ͼ<EFBFBD><EFBFBD>ƴ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/image_splice.png";
if (Name.contains("ͼ<EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>")) IconName = ":/res/ico/repair.png";
if (Name.contains("ͼ<EFBFBD><EFBFBD>ϸ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/skeleton.png";
if (Name.contains("ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת")) IconName = ":/res/ico/flip.png";
if (Name.contains("ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת")) IconName = ":/res/ico/rotate.png";
if (Name.contains("͸<EFBFBD>ӱ任")) IconName = ":/res/ico/perspective.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/crop.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ROI")) IconName = ":/res/ico/roi.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/barcode.png";
if (Name.contains("<EFBFBD>ߵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/blob.png";
if (Name.contains("<EFBFBD><EFBFBD>ά<EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/qrcode.png";
if (Name.contains("<EFBFBD>ַ<EFBFBD>ʶ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/ocr.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/classifier.png";
if (Name.contains("<EFBFBD><EFBFBD>ɫʶ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/color_r.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/brightness.png";
if (Name.contains("ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/clarity.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/shape.png";
if (Name.contains("N<EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/ert_calib.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/distortion_calib.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/measure_calib.png";
if (Name.contains("<EFBFBD>Ҷ<EFBFBD>ƥ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/match.png";
if (Name.contains("<EFBFBD><EFBFBD>״ƥ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/shape_match.png";
if (Name.contains("Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/track.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/affine.png";
if (Name.contains("Ѱ<EFBFBD><EFBFBD>Բ")) IconName = ":/res/ico/find_circle.png";
if (Name.contains("Ѱ<EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/find_line.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ")) IconName = ":/res/ico/fit_circle.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ")) IconName = ":/res/ico/fit_ellipse.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/fit_line.png";
if (Name.contains("<EFBFBD><EFBFBD>ȡ<EFBFBD>߽<EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/border_point.png";
if (Name.contains("<EFBFBD><EFBFBD>Բ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/line_circle.png";
if (Name.contains("<EFBFBD><EFBFBD>+<2B><>")) IconName = ":/res/ico/point_point.png";
if (Name.contains("<EFBFBD><EFBFBD>+<2B><>")) IconName = ":/res/ico/point_l.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD>߽<EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/intersection.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բȱ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/rounded_c.png";
if (Name.contains("<EFBFBD><EFBFBD>Ե<EFBFBD><EFBFBD><EFBFBD>Ȳ<EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/edge.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/flatness.png";
if (Name.contains("<EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/extension_library.png";
if (Name.contains("<EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/goto.png";
if (Name.contains("<EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/logic_judge.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/end.png";
if (Name.contains("<EFBFBD>ű<EFBFBD><EFBFBD>")) IconName = ":/res/ico/script_edit.png";
if (Name.contains("TCP/IP<49><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")) IconName = ":/res/ico/server.png";
if (Name.contains("TCP/IP<49>ͻ<EFBFBD><CDBB><EFBFBD>")) IconName = ":/res/ico/client.png";
if (Name.contains("PLCͨ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/plc_communicate.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>")) IconName = ":/res/ico/serial_port.png";
if (Name.contains("ͨ<EFBFBD><EFBFBD>I/O")) IconName = ":/res/ico/general_io.png";
if (Name.contains("<EFBFBD><EFBFBD>ʱ")) IconName = ":/res/ico/delay.png";
if (Name.contains("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>CSV")) IconName = ":/res/ico/export_csv.png";
return IconName;
}