123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- #pragma execution_character_set("utf-8")
- #include "quiwidget.h"
- #include <QtWidgets>
- #include "WindowMain.h"
- #include "WindowAppMdiFrame.h"
- #include "TaskManager.h"
- #include "WindowAppTaskMonitorView.h"
- #include "Preferences.h"
- #define TOOLBAR_WIDTH 30
- QUIWidget::QUIWidget(QWidget* widget, QWidget *parent) :
- QDialog(parent)
- , mainWidget(widget)
- {
- Init();
- // setMainWidget(widget);
- }
- QUIWidget::~QUIWidget()
- {
- }
- void QUIWidget::Init()
- {
- this->initControl();
- this->initForm();
- }
- bool QUIWidget::eventFilter(QObject* obj, QEvent* evt)
- {
- static QPoint mousePoint;
- static bool mousePressed = false;
- QMouseEvent* event = static_cast<QMouseEvent*>(evt);
- if (event->type() == QEvent::MouseButtonPress)
- {
- if (event->button() == Qt::LeftButton)
- {
- mousePressed = true;
- mousePoint = event->globalPos() - this->pos();
- }
- }
- else if (event->type() == QEvent::MouseButtonRelease)
- {
- mousePressed = false;
- }
- else if (event->type() == QEvent::MouseMove)
- {
- if (mousePressed && (event->buttons() && Qt::LeftButton))
- {
- if (this->property("canMove").toBool())
- {
- this->move(event->globalPos() - mousePoint);
- }
- }
- }
- else if (event->type() == QEvent::MouseButtonDblClick)
- {
- if (this->btnMenu_Max->isVisible() && obj == this->widgetTitle)
- {
- this->on_btnMenu_Max_clicked();
- }
- }
- if (event->type() == QEvent::KeyPress)
- {
- return true;
- }
- return QWidget::eventFilter(obj, evt);
- }
- QSize QUIWidget::sizeHint() const
- {
- return QSize(600, 450);
- }
- QSize QUIWidget::minimumSizeHint() const
- {
- return QSize(200, 10);
- }
- void QUIWidget::initControl()
- {
- // WindowMain* pWindowMain = new WindowMain;
- WindowMain* pWindowMain = (WindowMain*)mainWidget;
- verticalLayout1 = new QVBoxLayout(this);
- verticalLayout1->setSpacing(0);
- verticalLayout1->setContentsMargins(0, 0, 0, 0);
- widgetMain = new QWidget(this);
- verticalLayout2 = new QVBoxLayout(widgetMain);
- verticalLayout2->setSpacing(0);
- verticalLayout2->setContentsMargins(0, 0, 0, 0);
- widgetTitle = new QWidget(widgetMain);
- widgetTitle->setMinimumSize(QSize(0, TOOLBAR_WIDTH));
- widgetTitle->setStyleSheet("background-color:rgb(9, 101, 90);border:0px;");
- horizontalLayout4 = new QHBoxLayout(widgetTitle);
- horizontalLayout4->setSpacing(5);
- horizontalLayout4->setContentsMargins(30, 0, 0, 0);
- //文件按钮
- File = new QPushButton(widgetTitle);
- File->setText(" 文件");
- File->setMinimumSize(QSize(0, TOOLBAR_WIDTH));
- File->setStyleSheet("QPushButton{color:rgb(255, 255, 255);font:10pt'微软雅黑';}QPushButton::pressed{background-color:rgb(34, 136, 124);}QPushButton::hover{background-color:rgb(34, 136, 124);}QPushButton::menu-indicator{image:none;}QPushButton{ text - align:center; }");
- QMenu* menufile = new QMenu(this);
- QAction* NewAction = new QAction("新建", menufile);
- QAction* OpenAction = new QAction("打开...", menufile);
- QAction* CurOpenAction = new QAction("最近打开...", menufile);
- QAction* SaveAction = new QAction("保存...", menufile);
- QAction* SaveAsAction = new QAction("另存为...", menufile);
- QAction* ExitAction = new QAction("退出程序", menufile);
- menufile->addAction(NewAction);
- menufile->addAction(OpenAction);
- menufile->addAction(CurOpenAction);
- menufile->addAction(SaveAction);
- menufile->addAction(SaveAsAction);
- menufile->addSeparator();
- menufile->addAction(ExitAction);
- connect(NewAction, &QAction::triggered, pWindowMain, &WindowMain::onFileNew);
- connect(OpenAction, &QAction::triggered, pWindowMain, &WindowMain::onFileOpen);
- connect(SaveAction, &QAction::triggered, pWindowMain, &WindowMain::onFileSave);
- connect(SaveAsAction, &QAction::triggered, pWindowMain, &WindowMain::onFileSaveAs);
- //connect(ExitAction, &QAction::triggered, pWindowMain, &WindowMain::close);
- connect(ExitAction, &QAction::triggered, this, &QUIWidget::on_btnMenu_Close_clicked);
- File->setMenu(menufile);
- menufile->setStyleSheet("QMenu::item{padding-left:40px;height:35px;width:200px;}QMenu{background-color:rgb(9, 101, 90);color:white;font:9pt'微软雅黑';margin:0px 0px 0px 0px;}QMenu::item:selected{background-color:rgba(255, 255, 255,50);}");
- //视图
- View = new QPushButton(widgetTitle);
- View->setText(" 视图");
- View->setMinimumSize(QSize(0, TOOLBAR_WIDTH));
- View->setStyleSheet("QPushButton{color:rgb(255, 255, 255);font:12pt'微软雅黑';}QPushButton::pressed{background-color:rgb(34, 136, 124);}QPushButton::hover{background-color:rgb(34, 136, 124);}QPushButton::menu-indicator{image:none;}");
- QMenu* menuView = new QMenu(this);
- QAction* RuntimeAction = new QAction("运行视图", menuView);
- QAction* AppAction = new QAction("程序视图", menuView);
- menuView->addAction(RuntimeAction);
- menuView->addAction(AppAction);
- connect(RuntimeAction, &QAction::triggered, pWindowMain, &WindowMain::onViewRunTime);
- connect(AppAction, &QAction::triggered, pWindowMain, &WindowMain::onViewApp);
- View->setMenu(menuView);
- menuView->setStyleSheet("QMenu::item{padding-left:40px;height:35px;width:200px;}QMenu{background-color:rgb(9, 101, 90);color:white;font:9pt'微软雅黑';margin:0px 0px 0px 0px;}QMenu::item:selected{background-color:rgba(255, 255, 255,50);}");
- //任务
- Task = new QPushButton(widgetTitle);
- Task->setText(" 任务");
- Task->setMinimumSize(QSize(0, TOOLBAR_WIDTH));
- Task->setStyleSheet("QPushButton{color:rgb(255, 255, 255);font:12pt'微软雅黑';}QPushButton::pressed{background-color:rgb(34, 136, 124);}QPushButton::hover{background-color:rgb(34, 136, 124);}QPushButton::menu-indicator{image:none;}");
- QMenu* menuTask = new QMenu(this);
- QAction* SysRunAction = new QAction("循环运行", menuTask);
- QAction* SysRunOnceAction = new QAction("单步运行", menuTask);
- QAction* SysStopAction = new QAction("停止运行", menuTask);
- menuTask->addAction(SysRunAction);
- menuTask->addAction(SysRunOnceAction);
- menuTask->addAction(SysStopAction);
- connect(SysRunAction, &QAction::triggered, pWindowMain, &WindowMain::onTaskRun);
- connect(SysRunOnceAction, &QAction::triggered, pWindowMain, &WindowMain::onTaskRunonce);
- connect(SysStopAction, &QAction::triggered, pWindowMain, &WindowMain::onTaskStop);
- Task->setMenu(menuTask);
- menuTask->setStyleSheet("QMenu::item{padding-left:40px;height:35px;width:200px;}QMenu{background-color:rgb(9, 101, 90);color:white;font:9pt'微软雅黑';margin:0px 0px 0px 0px;}QMenu::item:selected{background-color:rgba(255, 255, 255,50);}");
- //系统
- System = new QPushButton(widgetTitle);
- System->setText(" 系统");
- System->setMinimumSize(QSize(0, TOOLBAR_WIDTH));
- System->setStyleSheet("QPushButton{color:rgb(255, 255, 255);font:12pt'微软雅黑';}QPushButton::pressed{background-color:rgb(34, 136, 124);}QPushButton::hover{background-color:rgb(34, 136, 124);}QPushButton::menu-indicator{image:none;}");
- QMenu* menuSys = new QMenu(this);
- QAction* PreferencesAction = new QAction("偏好设置", menuSys);
- QAction* SysInfoAction = new QAction("系统信息", menuSys);
- menuSys->addAction(PreferencesAction);
- menuSys->addAction(SysInfoAction);
- connect(PreferencesAction, &QAction::triggered, pWindowMain, &WindowMain::onPreferences);
- connect(SysInfoAction, &QAction::triggered, pWindowMain, &WindowMain::onAppInfo);
- System->setMenu(menuSys);
- menuSys->setStyleSheet("QMenu::item{padding-left:40px;height:35px;width:200px;}QMenu{background-color:rgb(9, 101, 90);color:white;font:9pt'微软雅黑';margin:0px 0px 0px 0px;}QMenu::item:selected{background-color:rgba(255, 255, 255,50);}");
- QLabel* text = new QLabel(widgetTitle);
- text->setText(thePrefs.m_strProductName);
- text->setStyleSheet("color:rgb(255, 255, 255);font:10pt'微软雅黑';");
- QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
- File->setSizePolicy(sizePolicy);
- horizontalLayout4->addWidget(File);
- horizontalLayout4->addWidget(View);
- horizontalLayout4->addWidget(Task);
- horizontalLayout4->addWidget(System);
- horizontalLayout4->addWidget(text);
- horizontalLayout4->addStretch(1);
- widgetMenu = new QWidget(widgetTitle);
- horizontalLayout = new QHBoxLayout(widgetMenu);
- horizontalLayout->setSpacing(0);
- horizontalLayout->setContentsMargins(0, 0, 0, 0);
- //最小化按钮
- btnMenu_Min = new QPushButton(widgetMenu);
- btnMenu_Min->setMinimumSize(QSize(30, 0));
- btnMenu_Min->setMaximumSize(QSize(30, 16777215));
- btnMenu_Min->setCursor(QCursor(Qt::ArrowCursor));
- btnMenu_Min->setFocusPolicy(Qt::NoFocus);
- horizontalLayout->addWidget(btnMenu_Min);
- btnMenu_Min->setIcon(QIcon(":/image/min.png"));
- btnMenu_Min->setStyleSheet("background:transparent;");
- //最大化按钮
- btnMenu_Max = new QPushButton(widgetMenu);
- btnMenu_Max->setMinimumSize(QSize(30, 0));
- btnMenu_Max->setMaximumSize(QSize(30, 16777215));
- btnMenu_Max->setCursor(QCursor(Qt::ArrowCursor));
- btnMenu_Max->setFocusPolicy(Qt::NoFocus);
- horizontalLayout->addWidget(btnMenu_Max);
- btnMenu_Max->setIcon(QIcon(":/image/max.png"));
- btnMenu_Max->setStyleSheet("background:transparent;");
- //关闭按钮
- btnMenu_Close = new QPushButton(widgetMenu);
- btnMenu_Close->setMinimumSize(QSize(30, 0));
- btnMenu_Close->setMaximumSize(QSize(30, 16777215));
- btnMenu_Close->setCursor(QCursor(Qt::ArrowCursor));
- btnMenu_Close->setFocusPolicy(Qt::NoFocus);
- horizontalLayout->addWidget(btnMenu_Close);
- btnMenu_Close->setIcon(QIcon(":/image/close.png"));
- btnMenu_Close->setStyleSheet("background:transparent;");
- horizontalLayout4->addWidget(widgetMenu);
- verticalLayout2->addWidget(widgetTitle);
- widget = new QWidget(widgetMain);
- verticalLayout3 = new QVBoxLayout(widget);
- verticalLayout3->setSpacing(0);
- verticalLayout3->setContentsMargins(0, 0, 0, 0);
- verticalLayout2->addWidget(widget);
- verticalLayout1->addWidget(widgetMain);
- connect(this->btnMenu_Min, SIGNAL(clicked()), this, SLOT(on_btnMenu_Min_clicked()));
- connect(this->btnMenu_Max, SIGNAL(clicked()), this, SLOT(on_btnMenu_Max_clicked()));
- connect(this->btnMenu_Close, SIGNAL(clicked()), this, SLOT(on_btnMenu_Close_clicked()));
- }
- void QUIWidget::triggeredSlot(bool ok)
- {
- Q_UNUSED(ok);
- // QAction* action = (QAction*)sender();
-
- }
- void QUIWidget::initForm()
- {
- this->setProperty("form", true);
- this->setProperty("canMove", true);
- this->widgetTitle->setProperty("form", "title");
- this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint);
- minHide = false;
- // mainWidget = 0;
-
- this->widget->layout()->addWidget(mainWidget);
- resize(mainWidget->width(), mainWidget->height() + this->widgetTitle->height());
- this->installEventFilter(this);
- this->widgetTitle->installEventFilter(this);
- }
- //void QUIWidget::setMainWidget(QWidget* mainWidget)
- //{
- // //if (this->mainWidget == 0)
- // //{
- // //this->widget->layout()->addWidget(mainWidget);
- // //resize(mainWidget->width(), mainWidget->height() + this->widgetTitle->height());
- // // this->mainWidget = mainWidget;
- // // }
- //}
- void QUIWidget::on_btnMenu_Min_clicked()
- {
- if (minHide)
- {
- hide();
- }
- else
- {
- showMinimized();
- }
- }
- void QUIWidget::on_btnMenu_Max_clicked()
- {
- static bool max = false;
- static QRect location = this->geometry();
- if (max)
- {
- this->setGeometry(location);
- btnMenu_Max->setIcon(QIcon(":/image/huanyuan.png"));
- btnMenu_Max->setStyleSheet("background:transparent;");
- }
- else
- {
- location = this->geometry();
- this->setGeometry(qApp->desktop()->availableGeometry());
- btnMenu_Max->setIcon(QIcon(":/image/max.png"));
- btnMenu_Max->setStyleSheet("background:transparent;");
- }
- this->setProperty("canMove", max);
- max = !max;
- }
- void QUIWidget::on_btnMenu_Close_clicked()
- {
- // 1011-5-16,退出时停止所有Task,防止出现崩溃问题
- // 但是此时如果还有各个Tool在执行的话,需要提前先退出每一个Tool,要不还是有可能崩溃在Tool里
- g_pTaskManager->stopAllTask();
-
- ::Sleep(200);
- emit closing();
- //exit(0);
- QApplication* app;
- app->quit();
- }
- void QUIWidget::dragEnterEvent(QDragEnterEvent* event)
- {
- event->accept();
- QDialog::dragEnterEvent(event);
- }
- /// <summary>
- /// 界面还原后执行刷新
- /// </summary>
- /// <param name="event"></param>
- void QUIWidget::changeEvent(QEvent* event)
- {
- switch (event->type())
- {
- case QEvent::WindowStateChange:
- // 给MDI框架发送消息,刷新内部所有页面
- QApplication::sendEvent(VPGlobal::getMdiFrame(), new QEvent(QResizeEvent::Resize));
- // QApplication::sendEvent(VPGlobal::getTaskMonitorView(), new QEvent(QResizeEvent::Resize));
- qDebug() << "QUIWidget::changeEvent";
- break;
- default:
- break;
- }
- }
|