261 lines
9.2 KiB
C++
261 lines
9.2 KiB
C++
#include "MainWindow.h"
|
||
#include "windows.h"
|
||
#include "QWindow.h"
|
||
#include <iostream>
|
||
#include <tlhelp32.h>
|
||
#include <QProcess>
|
||
#include <QDebug>
|
||
#include <QPushButton>
|
||
#include <QGraphicsView>
|
||
#include <QHBoxLayout>
|
||
#include <QStackedWidget>
|
||
#include <QStatusBar>
|
||
#include <QVBoxLayout>
|
||
|
||
#include "ElaContentDialog.h"
|
||
#include "ElaDockWidget.h"
|
||
#include "ElaEventBus.h"
|
||
#include "ElaLog.h"
|
||
#include "ElaMenu.h"
|
||
#include "ElaMenuBar.h"
|
||
#include "ElaProgressBar.h"
|
||
#include "ElaStatusBar.h"
|
||
#include "ElaText.h"
|
||
#include "ElaTheme.h"
|
||
#include "ElaToolBar.h"
|
||
#include "ElaToolButton.h"
|
||
#include "ElaMessageBar.h"
|
||
#include "GenerateReportBase.h"
|
||
#include "CreateNewReport.h"
|
||
#include "GemerateFinalReport.h"
|
||
//#include "T_Navigation.h"
|
||
|
||
void SendMsgToParentProcess(QString msg)
|
||
{
|
||
fputs(msg.toLocal8Bit(), stdout);
|
||
fflush(stdout);
|
||
}
|
||
|
||
DWORD GetProcessIdByName1(const char* processName)
|
||
{
|
||
DWORD processId = 0;
|
||
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||
if (snapshot != INVALID_HANDLE_VALUE)
|
||
{
|
||
PROCESSENTRY32 processEntry;
|
||
processEntry.dwSize = sizeof(PROCESSENTRY32);
|
||
if (Process32First(snapshot, &processEntry))
|
||
{
|
||
do
|
||
{
|
||
if (strcmp(processEntry.szExeFile, processName) == 0)
|
||
{
|
||
processId = processEntry.th32ProcessID;
|
||
break;
|
||
}
|
||
} while (Process32Next(snapshot, &processEntry));
|
||
}
|
||
CloseHandle(snapshot);
|
||
}
|
||
return processId;
|
||
}
|
||
|
||
namespace GenerateReport
|
||
{
|
||
MainWindow::MainWindow(QWidget* parent)
|
||
: ElaWindow(parent)
|
||
{
|
||
initWindow();
|
||
|
||
//额外布局
|
||
initEdgeLayout();
|
||
|
||
// 拦截默认关闭事件
|
||
_closeDialog = new ElaContentDialog(this);
|
||
connect(_closeDialog, &ElaContentDialog::rightButtonClicked, this, &MainWindow::closeWindow);
|
||
connect(_closeDialog, &ElaContentDialog::middleButtonClicked, this, &MainWindow::showMinimized);
|
||
this->setIsDefaultClosed(false);
|
||
connect(this, &MainWindow::closeButtonClicked, this, [=]() {
|
||
_closeDialog->exec();
|
||
});
|
||
|
||
//移动到中心
|
||
moveToCenter();
|
||
SendMsgToParentProcess(QString("{--}winId{||}%1{--}\n").arg(winId()));
|
||
}
|
||
|
||
MainWindow::~MainWindow()
|
||
{
|
||
const char* targetProcessName = "soffice.bin";
|
||
DWORD processId = GetProcessIdByName1(targetProcessName);
|
||
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, processId);
|
||
if (hProcess != NULL)
|
||
{
|
||
TerminateProcess(hProcess, 0);
|
||
CloseHandle(hProcess);
|
||
}
|
||
if (m_libreOffice)
|
||
{
|
||
m_libreOffice->close();
|
||
delete m_libreOffice;
|
||
m_libreOffice = Q_NULLPTR;
|
||
}
|
||
destructionCenterWidget();
|
||
|
||
}
|
||
void MainWindow::destructionCenterWidget()
|
||
{
|
||
if (m_widget)
|
||
{
|
||
m_centWidget->layout()->removeWidget(m_widget);
|
||
delete m_widget;
|
||
m_widget = Q_NULLPTR;
|
||
}
|
||
}
|
||
|
||
void MainWindow::initWindow()
|
||
{
|
||
setIsNavigationBarEnable(false);
|
||
setWindowButtonFlags(ElaAppBarType::StayTopButtonHint | ElaAppBarType::MinimizeButtonHint | ElaAppBarType::MaximizeButtonHint | ElaAppBarType::CloseButtonHint);
|
||
setAppBarHeight(30);
|
||
setWindowIcon(QIcon(":/include/Image/GenerateReport.png"));
|
||
resize(1678, 921);
|
||
setWindowTitle("报告生成");
|
||
}
|
||
|
||
void MainWindow::initEdgeLayout()
|
||
{
|
||
initToolBar();
|
||
statusBarPromptInformation(QString("初始化成功!"));
|
||
}
|
||
|
||
void MainWindow::libreOfficeProcess(WId hwnd)
|
||
{
|
||
handleChildLibreOfficeProcessMsg(hwnd);
|
||
}
|
||
|
||
void MainWindow::handleChildLibreOfficeProcessMsg(WId hwnd)
|
||
{
|
||
if (m_centWidget == nullptr)
|
||
{
|
||
m_centWidget = new QFrame(this);
|
||
addPageNode("CenterWidget", m_centWidget, ElaIconType::LocationArrow);
|
||
}
|
||
|
||
auto childWin = QWindow::fromWinId(hwnd);
|
||
m_widget = QWidget::createWindowContainer(childWin, m_centWidget, Qt::Widget);
|
||
auto layout = m_centWidget->layout();
|
||
if (layout)
|
||
{
|
||
layout->addWidget(m_widget);
|
||
}
|
||
else
|
||
{
|
||
layout = new QGridLayout();
|
||
layout->setContentsMargins(0, 0, 0, 0);
|
||
layout->addWidget(m_widget);
|
||
m_centWidget->setLayout(layout);
|
||
}
|
||
}
|
||
|
||
void MainWindow::slot_toolBtnClick_CreateNewReport()
|
||
{
|
||
ElaToolButton* _btn = dynamic_cast<ElaToolButton*>(sender());
|
||
if (_btn)
|
||
{
|
||
auto _currentReportNum = GenerateReportBaseInstance->getCurrentReportNumber();
|
||
if (_currentReportNum == 1)
|
||
{
|
||
statusBarPromptInformation(QString("当前正在编辑一份报告,请先关闭或保存当前报告!"));
|
||
return;
|
||
}
|
||
|
||
GenerateReportBaseInstance->initUno();
|
||
//ElaMessageBar::success(ElaMessageBarType::PositionPolicy::BottomLeft, _btn->text(), "成功", 1000, this);
|
||
GenerateReport::CreateNewReport tes;
|
||
tes.actionSlot_CreateNewReport();
|
||
}
|
||
}
|
||
|
||
void MainWindow::slot_toolBtnClick_GemerateFinalReport()
|
||
{
|
||
ElaToolButton* _btn = dynamic_cast<ElaToolButton*>(sender());
|
||
if (_btn)
|
||
{
|
||
auto _currentReportNum = GenerateReportBaseInstance->getCurrentReportNumber();
|
||
if (_currentReportNum == 0)
|
||
{
|
||
statusBarPromptInformation(QString("当前没有正在编辑的报告,请先新建一份报告!"));
|
||
return;
|
||
}
|
||
//ElaMessageBar::success(ElaMessageBarType::PositionPolicy::BottomLeft, _btn->text(), "成功", 1000, this);
|
||
GenerateReport::GemerateFinalReport gfp;
|
||
gfp.actionSlot_GemerateFinalReport();
|
||
}
|
||
}
|
||
|
||
|
||
void MainWindow::initToolBar()
|
||
{
|
||
//工具栏
|
||
ElaToolBar* toolBar = new ElaToolBar("工具栏", this);
|
||
toolBar->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
|
||
toolBar->setAllowedAreas(Qt::NoToolBarArea);
|
||
toolBar->setToolBarSpacing(5);
|
||
toolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||
toolBar->setIconSize(QSize(25, 25));
|
||
toolBar->setFloatable(false);
|
||
toolBar->setMovable(false);
|
||
toolBar->setContentsMargins(QMargins(5, 5, 5, 5));
|
||
|
||
ElaToolButton* toolButtonCreateNewReport = new ElaToolButton(this);
|
||
toolButtonCreateNewReport->setElaIcon(ElaIconType::FileCirclePlus);
|
||
toolButtonCreateNewReport->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||
toolButtonCreateNewReport->setText("新建报告");
|
||
toolBar->addWidget(toolButtonCreateNewReport);
|
||
connect(toolButtonCreateNewReport, &ElaToolButton::clicked, this, &MainWindow::slot_toolBtnClick_CreateNewReport);
|
||
|
||
ElaToolButton* toolButtonTemplateDefined = new ElaToolButton(this);
|
||
toolButtonTemplateDefined->setElaIcon(ElaIconType::FileCertificate);
|
||
toolButtonTemplateDefined->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||
toolButtonTemplateDefined->setText("模板定义");
|
||
toolBar->addWidget(toolButtonTemplateDefined);
|
||
//connect(toolButtonTemplateDefined, &ElaToolButton::clicked, this, &MainWindow::slot_toolBtnClick);
|
||
|
||
ElaToolButton* toolButtontoolButtonTemplateImport = new ElaToolButton(this);
|
||
toolButtontoolButtonTemplateImport->setElaIcon(ElaIconType::FileImport);
|
||
toolButtontoolButtonTemplateImport->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||
toolButtontoolButtonTemplateImport->setText("导入模板");
|
||
toolBar->addWidget(toolButtontoolButtonTemplateImport);
|
||
//connect(toolButtontoolButtonTemplateImport, &ElaToolButton::clicked, this, &MainWindow::slot_toolBtnClick);
|
||
|
||
ElaToolButton* toolButtonTemplateExport = new ElaToolButton(this);
|
||
toolButtonTemplateExport->setElaIcon(ElaIconType::FileExport);
|
||
toolButtonTemplateExport->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||
toolButtonTemplateExport->setText("导出模板");
|
||
toolBar->addWidget(toolButtonTemplateExport);
|
||
//connect(toolButton1, &ElaToolButton::clicked, this, &MainWindow::slot_toolBtnClick);
|
||
|
||
ElaToolButton* toolButtonGenerateResultReport = new ElaToolButton(this);
|
||
toolButtonGenerateResultReport->setElaIcon(ElaIconType::FileDoc);
|
||
toolButtonGenerateResultReport->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||
toolButtonGenerateResultReport->setText("报告生成");
|
||
toolBar->addWidget(toolButtonGenerateResultReport);
|
||
connect(toolButtonGenerateResultReport, &ElaToolButton::clicked, this, &MainWindow::slot_toolBtnClick_GemerateFinalReport);
|
||
|
||
this->addToolBar(Qt::TopToolBarArea, toolBar);
|
||
}
|
||
|
||
|
||
void MainWindow::statusBarPromptInformation(QString informationText)
|
||
{
|
||
//状态栏
|
||
ElaStatusBar* statusBar = new ElaStatusBar(this);
|
||
//ElaText* statusText = new ElaText(informationText, this);
|
||
//statusText->setTextPixelSize(14);
|
||
//statusBar->addWidget(statusText);
|
||
statusBar->showMessage(informationText, 3000);//显示提示信息,3s后自动消失
|
||
this->setStatusBar(statusBar);
|
||
}
|
||
|
||
} |