Qt系列文章目录
文章目录
- Qt系列文章目录
- 前言
- 一、嵌套窗口
- 二、注意事项
前言
我们有一个主窗口mainwindow,需要向其中放入新的界面,你可以自己定义里面内容。
Qt的嵌套布局由QDockWidget完成,用Qt Creator拖界面得到的dock布置形式比较固定,不能得想要的任意组合形式,要得到如下图所示的效果,后续布局必须通过代码来完成。dock属性随便设置,保证都任意区域可以停靠即可
由于这里不需要MainWindow的中间窗口,整个视图都由dock组成,因此先把QMainWindow的中间窗口部件去除:
在MainWindow的构造函数加入如下语句,即可把MainWindow的中间窗口去除,这时整个MainWindow只有Dock组成。其中使用了分割窗口QSplitter类。一个QSplitter是一个可以包含其他控件的控件,这些控件被一个分隔条隔开,托拽这个分隔条,可以改变splitter的子控件的大小。
QSplitter控件经常做为布局管理器使用,给用户提供更多的界面控制。
一、嵌套窗口
嵌套窗口最重要的就是构造窗口时,传入的父窗口之间关系,一般第一个参数就是此窗口的父类
层级关系如下:
首先是:1、class MainFramework : public QMainWindow 这时主框架窗口(标注:一)
2、左侧是QDockWidget,垂直分割成3份(标注:二)
3、中间是QDockWidget,主视口,里面包含GraphicsView、GraphicsScene、GraphicsItem(标注:三)
4、右侧也是QDockWidget,副视口,里面包含GraphicsView、GraphicsScene、GraphicsItem(标注:四)
5、右侧也是QDockWidget,(标注:五)
#ifndef FLYPROPERTYWIN_H
#define FLYPROPERTYWIN_H
#include <QWidget>
#include <QStandardPaths>
#include <QDir>
#include <QDebug>
#include "opencv2/opencv.hpp"
#include "GraphicsItem.h"
#include "GraphicsView.h"
#include "GraphicsScene.h"
using namespace cv;
#pragma execution_character_set("utf-8")
namespace Ui {
class FlyPropertyWin;
}
class FlyPropertyWin : public QWidget
{
Q_OBJECT
public:
explicit FlyPropertyWin(QWidget *parent = nullptr);
~FlyPropertyWin();
private:
GraphicsScene* m_sceneCheck;
GraphicsView* m_viewCheck;
GraphicsItem* m_itemCheck;
QVector<GraphicsItem*> m_itemsCheck4;
QVector<GraphicsItem*> m_itemsCheck2;
QVector<GraphicsItem*> m_itemsCheck5;
QMap<QString, GraphicsItem*> m_imageItemCheckMap;
QVBoxLayout* m_layoutCheck;
QSet<QString> m_totalImageNameCheckSet;
QString m_watchPath;
QString m_checkedPath;
private:
void initWidget();
void pictureSortCheck4(QVector<QString> &filesVec);
void pictureSortCheck2();
void pictureSortCheck5(QVector<QString> &filesVec);
void pictureCheckRight(QVector<QString> &filesVec);
void pictureCheckLeft(QVector<QString> &filesVec);
void createCheckDir(const QString& checkDir);
private:
Ui::FlyPropertyWin *ui;
public Q_SLOTS:
void setImagePositionCheck(QVector<QString> &filesVec, QString &path, int groupType);
};
#endif // FLYPROPERTYWIN_H
二、注意事项
我们在新建窗口时如果默认不使用ui文件,我们需要手动使用布局器
FlyPropertyWin::FlyPropertyWin(QWidget *parent) :
QWidget(parent),
ui(new Ui::FlyPropertyWin)
{
// ui->setupUi(this);
initWidget();
m_sceneCheck = new GraphicsScene(this);
m_viewCheck = new GraphicsView;
// 设置水平滚动条策略
m_viewCheck->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
// 设置垂直滚动条策略
m_viewCheck->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
//确保在内容改变时,视口始终更新整个区域,而不是仅更新已更改的部分
m_viewCheck->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
//确保在视口大小改变时,视图中心始终保持在场景中心
m_viewCheck->setResizeAnchor(QGraphicsView::AnchorViewCenter);
m_viewCheck->setRenderHint(QPainter::Antialiasing);
m_layoutCheck = new QVBoxLayout(this);
m_layoutCheck->addWidget(m_viewCheck);
setLayout(m_layoutCheck);
int winWidth = 2048; //1442 2048
int winHeight = 1050; //710 1050
// setFixedSize(winWidth, winHeight);
resize(winWidth, winHeight);
}
这里面的代码
ui->setupUi(this);
这行代码必须注释掉,否则窗口中包含的GraphicsView、GraphicsScene、GraphicsItem将会重新弹出窗口,而不能嵌入到三和四的窗口上
#ifndef MAINFRAMEWORK_H
#define MAINFRAMEWORK_H
#include <QMainWindow>
#include <QDockWidget>
#include <QTextEdit>
#include <QPushButton>
#include <QKeyEvent>
#include <QFileDialog>
#include <QVector>
#include "FlyPropertyWin.h"
#include "ProjectWin.h"
#include "MsgBox.h"
#include "ImageManager.h"
#include "FileMonitorMgr.h"
#include "ImageNorth.h"
#pragma execution_character_set("utf-8")
QT_BEGIN_NAMESPACE
namespace Ui { class MainFramework; }
QT_END_NAMESPACE
class MainFramework : public QMainWindow
{
Q_OBJECT
public:
MainFramework(QWidget *parent = nullptr);
~MainFramework();
Q_SIGNALS:
void sigInitPicTree(QVector<QString> fileLst, QString filePath);
void sigInitParaFileList(const QVector<QString>& fileLst, QString filePath);
void sigInitNavi(const QString& file);
void sigInitImgPos(QVector<QString> &fileLst, QString &filePath, int grouptype);
void sigInitImgNorthPos(QVector<QString> &fileLst, QString &filePath, int grouptype); //转正北
void sigInitImgCheckPos(QVector<QString> &fileLst, QString &filePath, int grouptype); //彩C校正
void sigClearImage(bool flag);
void sigClearImageNorth(bool flag);
private slots:
void addLog(const QString&);
//标题栏槽函数
void s_showToolBar();
void s_showPorjectWin();
void s_showPropertyWin();
void s_showLogWin();
void s_close();
void s_min();
void s_hideProj();
void s_propertyWinHide(bool);
void s_logWinHide(bool);
void s_timeout();
void s_newProject();
void s_saveFile();
void s_runAc();
void s_cesiumAc();
void s_debugAc();
void s_anaysisAc();
void s_recordAc();
void s_grabAc();
void s_capacityAc();
void s_paramterAc();
void s_publishAc();
void s_exportAc();
void s_MonitorFolder(); //监控文件夹
void s_toNorth();//转正北
void s_toCheck();//彩C矫正
void s_selectedPicCesium(const QString& pic);
private:
void initTitleBar();
void initLogView();
void initWorkSpaceView();
void initPropertyView();
void initProjectView();
void initToolBar();
void dockLayout();
void initMaxMinWin();
void showMessageBox(const QString&);
void readCaiCFile(const QString &folderPath);
void readCaiCParaFile(const QString &folderPath);
void groupStrips();
bool sortStrips(const QString &a, const QString &b);
QString separateFiles(const QString &files);
void cesiumPicPath(const QString& picName);
private:
Ui::MainFramework *ui;
//标题栏
QAction* m_toolBarAc = NULL;
QAction* m_projectAc = NULL;
QAction* m_logAc = NULL;
QAction* m_propertyAc = NULL;
//工具栏
QAction* m_newAc = NULL;
QAction* m_saveAc = NULL;
QAction* m_runAc = NULL;
QAction* m_stopAc = NULL;
QAction* m_debugAc = NULL;
QAction* m_anaysisAc = NULL;
QAction* m_recordAc = NULL;
QAction* m_grabAc = NULL;
QAction* m_capacityAc = NULL;
QAction* m_paramterAc = NULL;
QAction* m_publishAc = NULL;
QAction* m_exportAc = NULL;
QDockWidget* m_logView = NULL;
QDockWidget* m_flyPropertyView = NULL;
QDockWidget* m_projManagerView = NULL;
QSplitter* m_splitter;
QTextEdit* m_logBody = NULL;
QWidget* m_maxminWin = NULL;
QWidget* m_workspace = NULL;
// ProjectWin* m_projectWin = NULL;
FlyPropertyWin* m_flyPropertyWin = NULL;
MsgBox* m_msgBox = NULL;
QPushButton* m_minBtn = NULL;
QPushButton* m_closeBtn = NULL;
QString m_strMonitorDirectory;
QString m_currSelectedPic;
QVector<QString> m_colorCfiles04;
QVector<QString> m_colorCfiles02;
QVector<QString> m_colorCfiles03;
QVector<QString> m_colorCfiles05;
QVector<QString> m_colorCAllFiles;
QVector<QString> m_colorCParaFiles;
QVector<QString> m_colorCAllFilesWithPath;
ImageManager* m_imgMgr;
ImageNorth* m_imgNorth;
FileMonitorMgr* m_fileMonitor;
};
#endif // MAINFRAMEWORK_H
#include "MainFramework.h"
#include "ui_MainFramework.h"
#include "ProjectWin.h"
#include "FlyPropertyWin.h"
#include "ImageManager.h"
#include <QDesktopWidget>
#include <QDebug>
#include <QStandardPaths>
#include <QTimer>
#include <QHBoxLayout>
#include <QSpacerItem>
#pragma execution_character_set("utf-8")
Q_DECLARE_METATYPE(QDockWidget::DockWidgetFeatures)
QString MenuBarStyle =
"QMenuBar{background-color:#FFFFFF; font:14px; color:#232323;}"
"QMenuBar::item{\
min-height:40px; \
margin:1 10 0 10px; \
padding:10 10 10 10px; /* 条目内边框 */ \
background:#FFFFFF; /* 背景颜色 */ \
border-radius:4px; /* 倒角 */ \
}"
"QMenuBar::item:selected{background: #E5E5E5; }"
;
QString MenuStyle =
"QMenu{/*整个背景*/}"
"QMenu::item{ \
font-size: 14px; \
color: rgb(225,225,225); /*字体颜色*/\
border: 3px solid rgb(60,60,60); /*item选框*/\
background-color:rgb(89,87,87); \
padding:16px 16px; /*设置菜单项文字上下和左右的内边距,效果就是菜单中的条目左右上下有了间隔*/\
margin:0px 2px;/*设置菜单项的外边距*/\
}"
"QMenu::item:selected{background-color:#1E1E1E;/*选中的样式*/}"
"QMenu::item:pressed{/*菜单项按下效果*/ border: 1px solid rgb(60,60,61); background-color: rgb(220,80,6);}"
;
QString tabBarStyle =
"QTabBar::tab{min-height: 28px; min-width:80px ; font:14px; }"
"QTabBar::tab:!selected{}"
"QTabBar::tab:!selected:hover{ background-color: #d9fffe; color: black;}"
"QToolBar{background-color:#e5e5e5; margin:3px;}"
"QToolBar::separator{height:1px; background-color:#000000;}"
"QToolBar QToolButton{min-width:60px; min-height:40px; background-color:transparent;}"
"QToolBar QToolButton:hover{background-color:rgba(255,255,255,0.8);}"
"QToolBar QToolButton:pressed{background-color:rgba(255,255,255,0.5);}"
;
MainFramework::MainFramework(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainFramework)
{
qRegisterMetaType<QDockWidget::DockWidgetFeatures>();
ui->setupUi(this);
this->setWindowTitle(u8"图像处理系统");
this->setWindowIcon(QIcon(":/images/logo.png"));
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
this->setStyleSheet(tabBarStyle);
//this->setStyleSheet("QMainWindow::separator {width: 2px;height: 2px;margin: 2px;padding: 2,2px;}");
//On the top menu bar add toolbar,menubar and dockwidget.
initTitleBar();
initToolBar();
initLogView();
initProjectView(); //项目区初始化在前。
initWorkSpaceView(); //工作区初始化在后。
initPropertyView();
dockLayout();
// 创建 QSplitter 控件
m_splitter = new QSplitter(Qt::Horizontal, this);
// 将 m_projManagerView 和 m_propertyView 添加到 QSplitter
m_splitter->addWidget(m_workspace);
m_splitter->addWidget(m_flyPropertyView);
// 设置 QSplitter 为中心部件
this->setCentralWidget(m_splitter);
this->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North);
//This property holds the tab shape used for tabbed dock widgets.
this->setTabShape(QTabWidget::Triangular);
this->statusBar()->showMessage(tr("Status Bar"));
addLog(u8"启动完成,欢迎进入主框架!");
m_imgMgr = new ImageManager(m_workspace);
m_imgNorth = new ImageNorth();
connect(this, &MainFramework::sigInitPicTree, ProjectWin::getInstance(), &ProjectWin::slotPicTree);
connect(this, &MainFramework::sigInitParaFileList, ProjectWin::getInstance(), &ProjectWin::slotParaFileList);
connect(this, &MainFramework::sigInitNavi, ProjectWin::getInstance(), &ProjectWin::slotNavi);
connect(this, &MainFramework::sigInitImgPos, m_imgMgr, &ImageManager::setImagePosition);
connect(this, &MainFramework::sigClearImage, m_imgMgr, &ImageManager::slotClearImage);
connect(this, &MainFramework::sigClearImageNorth, m_imgNorth, &ImageNorth::slotClearImageNorth);
connect(this, &MainFramework::sigInitImgNorthPos, m_imgNorth, &ImageNorth::setImagePositionNorth);
// connect(m_imgMgr, &ImageManager::sigSelectedPic, this, &MainFramework::s_selectedPicCesium);
connect(ProjectWin::getInstance(), &ProjectWin::sigSelectedPic, this, &MainFramework::s_selectedPicCesium);
QTimer::singleShot(2, this, SLOT(s_timeout()));
}
MainFramework::~MainFramework()
{
delete ui;
}
void MainFramework::initWorkSpaceView() {
if (NULL == m_workspace) {
m_workspace = new QWidget;
m_workspace->setWindowTitle("工作区");
this->setCentralWidget(m_workspace);
}
qDebug() << "工作区 id:" << m_workspace->winId() << ", name:" << m_workspace->windowTitle();
}
void MainFramework::initTitleBar()
{
QMenuBar* m_MenuBar = this->menuBar();
m_MenuBar->setStyleSheet(MenuBarStyle);
QMenu* m_viewMenu = this->menuBar()->addMenu(u8"快视");
m_viewMenu->setStyleSheet(MenuStyle);
m_toolBarAc = new QAction(u8"工具栏");
connect(m_toolBarAc, &QAction::triggered, this, &MainFramework::s_showToolBar);
m_toolBarAc->setCheckable(true);
m_toolBarAc->setChecked(true);
m_projectAc = new QAction(u8"图像列表");
connect(m_projectAc, &QAction::triggered, this, &MainFramework::s_showPorjectWin);
m_projectAc->setCheckable(true);
m_projectAc->setChecked(true);
m_propertyAc = new QAction(u8"属性");
connect(m_propertyAc, &QAction::triggered, this, &MainFramework::s_showPropertyWin);
m_propertyAc->setCheckable(true);
m_propertyAc->setChecked(true);
m_logAc = new QAction(u8"输出");
connect(m_logAc, &QAction::triggered, this, &MainFramework::s_showLogWin);
m_logAc->setCheckable(true);
m_logAc->setChecked(true);
m_viewMenu->addAction(m_toolBarAc);
m_viewMenu->addAction(m_projectAc);
m_viewMenu->addAction(m_propertyAc);
m_viewMenu->addAction(m_logAc);
QMenu* m_setView = this->menuBar()->addMenu(u8"浏览");
QMenu* m_toolMenu = this-> menuBar()->addMenu(u8"SAR处理");
QMenu* m_helpMenu = this->menuBar()->addMenu(u8"帮助");
initMaxMinWin();
}
void MainFramework::initMaxMinWin() {
m_maxminWin = new QWidget(this);
QHBoxLayout* horizontalLayout;
QSpacerItem* horizontalSpacer;
horizontalLayout = new QHBoxLayout(m_maxminWin);
horizontalLayout->setSpacing(0);
horizontalLayout->setContentsMargins(11, 11, 11, 11);
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
horizontalLayout->setContentsMargins(0, 0, 0, 0);
horizontalSpacer = new QSpacerItem(241, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
m_minBtn = new QPushButton(m_maxminWin);
connect(m_minBtn, &QPushButton::clicked, this, &MainFramework::s_min);
m_minBtn->setObjectName(QString::fromUtf8("minBtn"));
m_minBtn->setMinimumSize(QSize(40, 40));
m_minBtn->setMaximumSize(QSize(40, 40));
m_minBtn->setStyleSheet(QString::fromUtf8("QPushButton{border:none;}\n"
"QPushButton::hover{background-color:#E5E5E5;}\n"
""));
QIcon icon;
icon.addFile(QString::fromUtf8(":/images/min_main.png"), QSize(), QIcon::Normal, QIcon::Off);
m_minBtn->setIcon(icon);
m_minBtn->setIconSize(QSize(25, 25));
m_minBtn->setAutoDefault(false);
m_minBtn->setFlat(false);
m_minBtn->setDefault(false);
m_closeBtn = new QPushButton(m_maxminWin);
connect(m_closeBtn, &QPushButton::clicked, this, &MainFramework::s_close);
m_closeBtn->setObjectName(QString::fromUtf8("closeBtn"));
m_closeBtn->setMinimumSize(QSize(40, 40));
m_closeBtn->setMaximumSize(QSize(40, 40));
m_closeBtn->setStyleSheet(QString::fromUtf8("QPushButton{border:none;}\n"
"QPushButton::hover{background-color:#E81123;}\n"
));
QIcon icon1;
icon1.addFile(QString::fromUtf8(":/images/close_release.png"), QSize(), QIcon::Normal, QIcon::Off);
m_closeBtn->setIcon(icon1);
m_closeBtn->setIconSize(QSize(20, 20));
m_closeBtn->setFlat(false);
horizontalLayout->addItem(horizontalSpacer);
horizontalLayout->addWidget(m_minBtn);
horizontalLayout->addWidget(m_closeBtn);
horizontalLayout->setStretch(0, 1);
m_maxminWin->setLayout(horizontalLayout);
this->menuBar()->setCornerWidget(m_maxminWin, Qt::TopRightCorner);
}
void MainFramework::s_showToolBar() {
if (m_toolBarAc->isChecked()) {
ui->mainToolBar->show();
addLog(u8"显示 工具栏");
}
else {
ui->mainToolBar->hide();
addLog(u8"隐藏 工具栏");
}
}
void MainFramework::s_showPorjectWin() {
if (m_projectAc->isChecked()) {
m_projManagerView->show();
addLog(u8"显示 项目区");
}
else {
m_projManagerView->hide();
addLog(u8"隐藏 项目区");
}
}
void MainFramework::s_showPropertyWin() {
if (m_propertyAc->isChecked()) {
m_flyPropertyView->show();
addLog(u8"显示 属性区");
}
else {
m_flyPropertyView->hide();
addLog(u8"隐藏 属性区");
}
}
void MainFramework::s_showLogWin() {
if (m_logAc->isChecked()) {
m_logView->show();
addLog(u8"显示 日志区");
}
else {
m_logView->hide();
addLog(u8"隐藏 日志区");
}
}
void MainFramework::s_timeout() {
this->showMaximized();
}
void MainFramework::s_close() {
this->close();
}
void MainFramework::s_min() {
this->showMinimized();
}
void MainFramework::addLog(const QString& log)
{
m_logBody->setReadOnly(true);
m_logBody->append(log);
}
void MainFramework::initLogView() {
if (NULL == m_logView) {
m_logView = new QDockWidget(this);
//set dock widget feature: not move, enable close.
m_logView->setFeatures(QDockWidget::DockWidgetClosable);
m_logView->setWindowTitle(u8"输出");
m_logBody = new QTextEdit(this);
m_logView->setWidget(m_logBody);
}
QPalette pl = m_logBody->palette();
pl.setBrush(QPalette::Base, QBrush(QColor(255, 0, 0, 0)));
m_logBody->setPalette(pl);
}
void MainFramework::initPropertyView() {
if (NULL == m_flyPropertyView) {
m_flyPropertyView = new QDockWidget(m_workspace);
m_flyPropertyView->setFeatures(QDockWidget::DockWidgetClosable);
m_flyPropertyView->setWindowTitle(u8"彩C校正");
m_flyPropertyWin = new FlyPropertyWin(this);
m_flyPropertyView->setWidget(m_flyPropertyWin);
connect(this, &MainFramework::sigInitImgCheckPos, m_flyPropertyWin, &FlyPropertyWin::setImagePositionCheck); //彩C校正
qDebug() << "属性区 id:" << m_flyPropertyView->winId() << ", name:" << m_flyPropertyView->windowTitle();
}
// m_flyPropertyWin->resize(500, 300); // 设置初始大小为 500x300 像素
// m_flyPropertyView->resize(500, 300); // 设置初始大小为 500x300 像素
m_flyPropertyView->resize(280, 300); // 设置初始大小为 500x300 像素
}
void MainFramework::initProjectView() {
if (NULL == m_projManagerView) {
m_projManagerView = new QDockWidget(this);
m_projManagerView->setFeatures(QDockWidget::DockWidgetClosable);
m_projManagerView->setWindowTitle(u8"图像列表");
delete title bar
//QWidget* lTitleBar = m_projManagerView->titleBarWidget();
//QWidget* lEmptyWidget = new QWidget();
//m_projManagerView->setTitleBarWidget(lEmptyWidget);
//delete lTitleBar;
// m_projectWin = new ProjectWin(this);
ProjectWin::getInstance();
m_projManagerView->setWidget(ProjectWin::getInstance());
qDebug() << "项目区 id:" << m_projManagerView->winId() << ", name:" << m_projManagerView->windowTitle();
}
}
void MainFramework::dockLayout() {
this->addDockWidget(Qt::LeftDockWidgetArea, m_projManagerView, Qt::Orientation::Vertical);
// m_flyPropertyView->resize(50, 300);
// m_flyPropertyView->setMinimumSize(180, 300);
// m_flyPropertyView->setMaximumSize(180, 300);
this->addDockWidget(Qt::RightDockWidgetArea, m_flyPropertyView, Qt::Orientation::Vertical);
this->addDockWidget(Qt::BottomDockWidgetArea, m_logView, Qt::Orientation::Vertical);
}
void MainFramework::initToolBar() {
QSize toolIconSize(50, 30);
ui->mainToolBar->setIconSize(toolIconSize); //设置工具栏图标大小
QIcon newFileIcon(u8":/images/新建文件.png");
QIcon openFileIcon(u8":/images/打开文件.png");
QIcon saveFileIcon(":/images/保存.png");
QIcon runIcon(u8":/images/运行.png");
QIcon stopIcon(":/images/停止.png");
QIcon debugIcon(u8":/images/调试.png");
QIcon anaysisIcon(u8":/images/分析.png");
QIcon recordIcon(u8":/images/录制.png");
QIcon grabIcon(u8":/images/抓取.png");
QIcon capacityIcon(u8":/images/应用中心.png");
QIcon paramterIcon(u8":/images/参数.png");
QIcon publishIcon(u8":/images/发布.png");
QIcon exportIcon(u8":/images/导出.png");
m_newAc = new QAction(newFileIcon, u8"新添加监控文件夹", this);
m_saveAc = new QAction(saveFileIcon, u8"转正北", this);
m_runAc = new QAction(runIcon, u8"矫正", this);
m_stopAc = new QAction(stopIcon, u8"三维交互", this);
m_debugAc = new QAction(debugIcon, u8"调试", this);
m_anaysisAc = new QAction(anaysisIcon, u8"分析", this);
m_recordAc = new QAction(recordIcon, u8"录制", this);
m_grabAc = new QAction(grabIcon, u8"抓取", this);
m_capacityAc = new QAction(capacityIcon, u8"能力中心", this);
m_paramterAc = new QAction(paramterIcon, u8"参数", this);
m_publishAc = new QAction(publishIcon, u8"发布", this);
m_exportAc = new QAction(exportIcon, u8"导出", this);
//add QAction to Widget.
ui->mainToolBar->addAction(m_newAc);
ui->mainToolBar->addAction(m_saveAc);
ui->mainToolBar->addAction(m_saveAc);
ui->mainToolBar->addSeparator();
ui->mainToolBar->addAction(m_runAc);
ui->mainToolBar->addAction(m_stopAc);
ui->mainToolBar->addAction(m_debugAc);
ui->mainToolBar->addAction(m_anaysisAc);
ui->mainToolBar->addSeparator();
ui->mainToolBar->addAction(m_recordAc);
ui->mainToolBar->addAction(m_grabAc);
ui->mainToolBar->addSeparator();
ui->mainToolBar->addAction(m_capacityAc);
ui->mainToolBar->addSeparator();
ui->mainToolBar->addAction(m_paramterAc);
ui->mainToolBar->addAction(m_publishAc);
ui->mainToolBar->addAction(m_exportAc);
ui->mainToolBar->addSeparator();
// connect(m_newAc, &QAction::triggered, this, &MainFramework::s_newProject);
// connect(m_saveAc, &QAction::triggered, this, &MainFramework::s_saveFile);
connect(m_runAc, &QAction::triggered, this, &MainFramework::s_runAc);
connect(m_stopAc, &QAction::triggered, this, &MainFramework::s_cesiumAc);
connect(m_debugAc, &QAction::triggered, this, &MainFramework::s_debugAc);
connect(m_anaysisAc, &QAction::triggered, this, &MainFramework::s_anaysisAc);
connect(m_recordAc, &QAction::triggered, this, &MainFramework::s_recordAc);
connect(m_grabAc, &QAction::triggered, this, &MainFramework::s_grabAc);
connect(m_capacityAc, &QAction::triggered, this, &MainFramework::s_capacityAc);
connect(m_paramterAc, &QAction::triggered, this, &MainFramework::s_paramterAc);
connect(m_publishAc, &QAction::triggered, this, &MainFramework::s_publishAc);
connect(m_exportAc, &QAction::triggered, this, &MainFramework::s_exportAc);
connect(m_newAc, &QAction::triggered, this, &MainFramework::s_MonitorFolder);
connect(m_saveAc, &QAction::triggered, this, &MainFramework::s_toNorth);
}
void MainFramework::s_hideProj() {
m_projectAc->setChecked(false);
m_projManagerView->hide();
}
void MainFramework::s_propertyWinHide(bool visible) {
if (!visible) {
m_propertyAc->setChecked(false);
m_flyPropertyView->hide();
}
}
void MainFramework::s_logWinHide(bool visible) {
if (!visible) {
m_logAc->setChecked(false);
m_logView->hide();
}
}
void MainFramework::s_newProject() {
}
void MainFramework::s_saveFile() {
QString log = QString(u8"功能正在开发中,请耐心等待!");
showMessageBox(log);
addLog(log);
}
void MainFramework::s_runAc() {
QString log = QString(u8"彩C校正");
emit sigInitImgCheckPos(m_colorCfiles04, m_strMonitorDirectory, 4);
emit sigInitImgCheckPos(m_colorCfiles02, m_strMonitorDirectory, 2);
emit sigInitImgCheckPos(m_colorCfiles05, m_strMonitorDirectory, 5);
// showMessageBox(log);
addLog(log);
}
//三维交互
void MainFramework::s_cesiumAc() {
QString log = QString(u8"Qt和Cesium之间传递数据!");
// showMessageBox(log);
addLog(log);
}
void MainFramework::s_debugAc() {
QString log = QString(u8"功能正在开发中,请耐心等待!");
showMessageBox(log);
addLog(log);
}
void MainFramework::s_anaysisAc() {
QString log = QString(u8"功能正在开发中,请耐心等待!");
showMessageBox(log);
addLog(log);
}
void MainFramework::s_recordAc() {
QString log = QString(u8"功能正在开发中,请耐心等待!");
showMessageBox(log);
addLog(log);
}
void MainFramework::s_grabAc() {
QString log = QString(u8"功能正在开发中,请耐心等待!");
showMessageBox(log);
addLog(log);
}
void MainFramework::s_capacityAc() {
QString log = QString(u8"功能正在开发中,请耐心等待!");
showMessageBox(log);
addLog(log);
}
void MainFramework::s_paramterAc() {
QString log = QString(u8"功能正在开发中,请耐心等待!");
showMessageBox(log);
addLog(log);
}
void MainFramework::s_publishAc() {
QString log = QString(u8"功能正在开发中,请耐心等待!");
showMessageBox(log);
addLog(log);
}
void MainFramework::s_exportAc() {
QString log = QString(u8"功能正在开发中,请耐心等待!");
showMessageBox(log);
addLog(log);
}
void MainFramework::showMessageBox(const QString& text) {
if (NULL == m_msgBox) {
m_msgBox = new MsgBox();
}
m_msgBox->setMsgText(text);
m_msgBox->show();
}
QString MainFramework::separateFiles(const QString &files)
{
return "null";
}
void MainFramework::cesiumPicPath(const QString& picName)
{
}
void MainFramework::readCaiCFile(const QString &folderPath)
{
m_colorCfiles04.clear();
m_colorCfiles02.clear();
m_colorCfiles05.clear();
m_colorCAllFiles.clear();
m_colorCAllFilesWithPath.clear();
QDir directory(folderPath);
QStringList filters;
filters << "*.jpg";
directory.setNameFilters(filters);
directory.setFilter(QDir::Files | QDir::NoDotAndDotDot);
QFileInfoList fileInfoList = directory.entryInfoList();
for (const QFileInfo &fileInfo : fileInfoList) {
// qDebug() << "Found:" << fileInfo.absoluteFilePath();
QString fullPath = fileInfo.absoluteFilePath();
m_colorCAllFiles.push_back(fileInfo.fileName());
m_colorCAllFilesWithPath.push_back(fullPath);
}
groupStrips();
}
void MainFramework::readCaiCParaFile(const QString &folderPath)
{
QDir directory(folderPath);
QStringList filters;
filters << "*.txt";
directory.setNameFilters(filters);
directory.setFilter(QDir::Files | QDir::NoDotAndDotDot);
QFileInfoList fileInfoList = directory.entryInfoList();
for (const QFileInfo &fileInfo : fileInfoList) {
// qDebug() << "Found:" << fileInfo.absoluteFilePath();
QString fullPath = fileInfo.absoluteFilePath();
m_colorCParaFiles.push_back(fileInfo.fileName());
// m_colorCAllFilesWithPath.push_back(fullPath);
}
}
bool MainFramework::sortStrips(const QString &a, const QString &b)
{
QStringList aSplit = a.split('_');
QStringList bSplit = b.split('_');
int aFirstPart = aSplit[0].toInt();
int bFirstPart = bSplit[0].toInt();
if (aFirstPart == bFirstPart) {
int aSecondPart = aSplit[6].toInt();
int bSecondPart = bSplit[6].toInt();
return aSecondPart > bSecondPart;
} else {
return aFirstPart < bFirstPart;
}
}
void MainFramework::groupStrips()
{
for(const QString& fileName : m_colorCAllFiles)
{
if(fileName.contains("_04_")) {
m_colorCfiles04.append(fileName);
} else if(fileName.contains("_02_")) {
m_colorCfiles02.append(fileName);
} else if(fileName.contains("_05_")) {
m_colorCfiles05.append(fileName);
}
}
auto sortStripsLambda = [this](const QString &a, const QString &b) {
return this->sortStrips(a, b);
};
//条带排序
std::sort(m_colorCfiles04.begin(), m_colorCfiles04.end(), sortStripsLambda);
std::sort(m_colorCfiles02.begin(), m_colorCfiles02.end(), sortStripsLambda);
std::sort(m_colorCfiles05.begin(), m_colorCfiles05.end(), sortStripsLambda);
}
void MainFramework::s_MonitorFolder()
{
m_strMonitorDirectory = QFileDialog::getExistingDirectory(this, u8"请选择共享文件夹", "./");
QString monitorFolder = u8"开始监控文件夹:" + m_strMonitorDirectory;
// QString monitorPaht = monitorFolder + "/";
m_fileMonitor = new FileMonitorMgr(m_strMonitorDirectory);
// connect(this, &MainFramework::sigInitImgPos, m_imgMgr, &ImageManager::setImagePosition);
connect(m_fileMonitor, &FileMonitorMgr::sigAddFiles, ProjectWin::getInstance(), &ProjectWin::slotUpdatePicTree); //添加新的任务开机节点
connect(m_fileMonitor, &FileMonitorMgr::sigAddFilesPos, m_imgMgr, &ImageManager::addNewPicResort);
// connect(m_fileMonitor, &FileMonitorMgr::sigAddFilesTree, ProjectWin::getInstance(), &ProjectWin::slotAddNewPicNode);
// connect(m_fileMonitor, &FileMonitorMgr::sigAddFiles, m_imgMgr, &ImageManager::slotUpdatePicTree);
readCaiCFile(m_strMonitorDirectory);
readCaiCParaFile(m_strMonitorDirectory);
// emit sigClearImage(true);//清空主窗口图片
emit sigInitParaFileList(m_colorCParaFiles, m_strMonitorDirectory);
emit sigInitPicTree(m_colorCAllFiles, m_strMonitorDirectory);
emit sigInitNavi("navi");
//emit sigInitImgPos(m_colorCAllFiles, m_strMonitorDirectory);
//主窗口显示图片
emit sigInitImgPos(m_colorCfiles04, m_strMonitorDirectory, 4);
emit sigInitImgPos(m_colorCfiles02, m_strMonitorDirectory, 2);
emit sigInitImgPos(m_colorCfiles05, m_strMonitorDirectory, 5);
// emit sigInitPicTree(m_colorCfiles02, m_strMonitorDirectory);
// emit sigInitPicTree(m_colorCfiles05, m_strMonitorDirectory);
addLog(monitorFolder);
}
void MainFramework::s_toNorth()
{
m_imgNorth->show();
m_strMonitorDirectory = QFileDialog::getExistingDirectory(this, u8"请选择共享文件夹", "./");
QString monitorFolder = u8"转正北文件夹:" + m_strMonitorDirectory;
// QString monitorPaht = monitorFolder + "/";
m_fileMonitor = new FileMonitorMgr(m_strMonitorDirectory);
// connect(m_fileMonitor, &FileMonitorMgr::sigAddFiles, ProjectWin::getInstance(), &ProjectWin::slotUpdatePicTree);
readCaiCFile(m_strMonitorDirectory);
// readCaiCParaFile(m_strMonitorDirectory);
// emit sigClearImageNorth(true); //清除转正北窗口中所有图片
emit sigInitImgNorthPos(m_colorCfiles04, m_strMonitorDirectory, 4);
emit sigInitImgNorthPos(m_colorCfiles02, m_strMonitorDirectory, 2);
emit sigInitImgNorthPos(m_colorCfiles05, m_strMonitorDirectory, 5);
addLog(monitorFolder);
}
void MainFramework::s_toCheck()
{
m_imgNorth->show();
m_strMonitorDirectory = QFileDialog::getExistingDirectory(this, u8"请选择共享文件夹", "./");
QString monitorFolder = u8"矫正文件夹:" + m_strMonitorDirectory;
readCaiCFile(m_strMonitorDirectory);
emit sigInitImgNorthPos(m_colorCfiles04, m_strMonitorDirectory, 4);
emit sigInitImgNorthPos(m_colorCfiles02, m_strMonitorDirectory, 2);
emit sigInitImgNorthPos(m_colorCfiles05, m_strMonitorDirectory, 5);
addLog(monitorFolder);
}
void MainFramework::s_selectedPicCesium(const QString& pic)
{
QString cesiumFile = "D:/filePath.txt";
// if(QFile::exists(cesiumFile))
// {
// QFile::remove(cesiumFile);
// }
QString preMonitor = m_strMonitorDirectory + "/";
QString monitorJpg = preMonitor + pic;
qDebug() << "monitorJpg=" << monitorJpg;
QString moniterTxt;
QString moniterMark;
int pos = pic.indexOf(".jpg");
moniterTxt = pic.left(pos);
moniterTxt += ".txt";
moniterTxt = preMonitor + moniterTxt;
qDebug() << "moniterTxt=" << moniterTxt;
moniterMark = pic.left(pos);
moniterMark += ".mark";
moniterMark = preMonitor + moniterMark;
qDebug() << "moniterMark=" << moniterMark;
QString content = monitorJpg + "," + moniterTxt + "," + moniterMark;
QFile file(cesiumFile);
if(file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
{
QTextStream stream(&file);
stream << content;
file.close();
}
}