#include "MainWindow.h" #include "CustomTitleBar.h" #include "HomeView.h" #include "ProjectView.h" #include "ExpertManageView.h" #include "EvaluateView.h" #include "LoginView.h" #include "AboutView.h" #include "SettingView.h" #include "UserView.h" #include "ProjectManager.h" #include "dbService/ClassSet.h" #include "QFDConfig.h" #include "common/QFDIcon.h" #include "QFDAlert.h" #include #include #include #include #include StackedWidget::StackedWidget(QWidget *parent) : QFrame(parent) { m_hBoxLayout = new QHBoxLayout(this); m_view = new PopUpAniStackedWidget(this); m_hBoxLayout->setContentsMargins(0, 0, 0, 0); m_hBoxLayout->addWidget(m_view); connect(m_view, &PopUpAniStackedWidget::currentChanged, this, [this](int index) { emit currentWidgetChanged(m_view->widget(index)); }); QPalette pal(palette()); pal.setColor(QPalette::Background, QColor("#fffff8")); setAutoFillBackground(true); setPalette(pal); } void StackedWidget::addWidget(QWidget *widget) { m_view->addWidget(widget); } QWidget *StackedWidget::widget(int index) const { return m_view->widget(index); } void StackedWidget::removeWidget(QWidget *widget) { m_view->removeWidget(widget); } /// /// @todo widget.verticalScrollBar().setValue(0) /// void StackedWidget::setCurrentWidget(QWidget *widget, bool popOut) { if (popOut) { m_view->setCurrentWidget(widget, true, false, 200, QEasingCurve::InQuad); } else { m_view->setCurrentWidget(widget, false, true, 300); } } void StackedWidget::setCurrentIndex(int index, bool popOut) { if (index < 0 || index >= view()->count()) { return; } setCurrentWidget(m_view->widget(index), popOut); } PopUpAniStackedWidget *StackedWidget::view() const { return m_view; } int StackedWidget::index(const QString routeKey) { for (int i = 0; i < view()->count(); i++) { QWidget *w = view()->widget(i); if (w->objectName() == routeKey) { return i; } } return -1; } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { m_titleBar = new CustomTitleBar(this); QFramelessHelper *helper = new QFramelessHelper(this); helper->setTitleBar(m_titleBar); setWindowTitle("伪装防护评估系统软件"); QIcon icon = QIcon(":/resource/logo.png"); qApp->setWindowIcon(icon); m_titleBar->setIcon(icon); m_mainStackedWidget = new QStackedWidget(this); setCentralWidget(m_mainStackedWidget); initLoginPage(); setMinimumSize(QSize(1200, 900)); } MainWindow::~MainWindow() { } void MainWindow::initLoginPage() { m_loginView = new LoginView(this); m_mainStackedWidget->addWidget(m_loginView); connect(m_loginView, &LoginView::signalLogin, this, &MainWindow::slotLogin); connect(m_loginView, &LoginView::signalCancelLogin, this, &MainWindow::slotCancelLogin); } void MainWindow::initMainPage() { m_mainWidget = new QWidget(this); m_hBoxLayout = new QHBoxLayout(m_mainWidget); m_widgetLayout = new QHBoxLayout(); m_stackWidget = new StackedWidget(m_mainWidget); m_naviInterface = new NavigationInterface(true, true, m_mainWidget); m_homeView = new HomeView(m_mainWidget); m_aboutView = new AboutView(m_mainWidget); m_settingView = new SettingView(m_mainWidget); m_userView = new UserView(m_mainWidget); m_mainStackedWidget->addWidget(m_mainWidget); m_hBoxLayout->setSpacing(0); m_hBoxLayout->setContentsMargins(0, 0, 0, 0); m_hBoxLayout->addWidget(m_naviInterface); m_hBoxLayout->addLayout(m_widgetLayout); m_hBoxLayout->setStretchFactor(m_widgetLayout, 1); m_widgetLayout->addWidget(m_stackWidget); m_widgetLayout->setContentsMargins(0, 32, 0, 0); initNavigation(); m_naviInterface->panel->expand(); connect(m_naviInterface, &NavigationInterface::displayModeChanged, m_titleBar, &StandardTitleBar::raise); connect(m_userView, &UserView::signalLogout, this, &MainWindow::slotLogout); connect(m_homeView, &HomeView::sigOpenProject, this, &MainWindow::slotOpenProject); connect(m_homeView, &HomeView::sigDeleteProject, this, &MainWindow::slotDeleteProject); } void MainWindow::initNavigation() { m_homeView->setObjectName("homeView"); m_stackWidget->addWidget(m_homeView); m_naviInterface->addItem(m_homeView->objectName(), NEWFLICON(FluentIcon, HOME), "评估项目管理", this, SLOT(slotNaviItemClicked())); m_settingView->setObjectName("settingView"); m_stackWidget->addWidget(m_settingView); m_naviInterface->addItem(m_settingView->objectName(), NEWFLICON(FluentIcon, SETTING), "系统资源管理", this, SLOT(slotNaviItemClicked())); m_naviInterface->addSeparator(); m_userView->setObjectName("userView"); m_stackWidget->addWidget(m_userView); m_naviInterface->addItem(m_userView->objectName(), NEWFLICON(QFDIcon, User), "用户", this, SLOT(slotNaviItemClicked()), true, NavigationItemPosition::BOTTOM); m_aboutView->setObjectName("aboutView"); m_stackWidget->addWidget(m_aboutView); m_naviInterface->addItem(m_aboutView->objectName(), NEWFLICON(FluentIcon, INFO), "关于", this, SLOT(slotNaviItemClicked()), true, NavigationItemPosition::BOTTOM); connect(m_stackWidget, &StackedWidget::currentWidgetChanged, this, [this](QWidget *w) { m_naviInterface->setCurrentItem(w->objectName()); }); m_naviInterface->setDefaultRouteKey(m_homeView->objectName()); m_naviInterface->setCurrentItem(m_homeView->objectName()); m_stackWidget->setCurrentIndex(0); } void MainWindow::setNaviInterfaceHidden(bool hidden) { m_naviInterface->setHidden(hidden); m_titleBar->setGeometry(QRect(titleBarIndent(), 0, width() - titleBarIndent(), m_titleBar->height())); } int MainWindow::titleBarIndent() const { if (m_mainStackedWidget->currentIndex() > 0 && m_naviInterface != nullptr && m_naviInterface->isHidden() == false) { return 48; } return 0; } void MainWindow::resizeEvent(QResizeEvent *event) { Q_UNUSED(event) m_titleBar->resize(width() - titleBarIndent(), m_titleBar->height()); } void MainWindow::slotLogin() { initMainPage(); m_mainStackedWidget->setCurrentWidget(m_mainWidget); showMaximized(); m_titleBar->setGeometry(QRect(titleBarIndent(), 0, width() - titleBarIndent(), m_titleBar->height())); } void MainWindow::slotLogout() { qfReloadHomeProjectsAtShow = true; m_mainStackedWidget->setCurrentWidget(m_loginView); m_mainStackedWidget->removeWidget(m_mainWidget); delete m_mainWidget; m_mainWidget = nullptr; showNormal(); m_titleBar->setGeometry(QRect(titleBarIndent(), 0, width() - titleBarIndent(), m_titleBar->height())); } void MainWindow::slotCancelLogin() { exit(0); } void MainWindow::slotNaviItemClicked() { int index = m_stackWidget->index(sender()->property("routeKey").toString()); m_stackWidget->setCurrentIndex(index); } void MainWindow::slotOpenProject(ProjectInfo *proj) { QList l = ProjectManager::evalTypeList(*proj); if (l.count() <= 0) { QFDAlert::showAlertWithCode(QF_CODE_EVAL_NOT_SUPPORTED, this); return; } QString n = QString("project_%1").arg(proj->id); int index = m_stackWidget->index(n); if (index >= 0) { m_stackWidget->setCurrentIndex(index); } else { ProjectView *p = new ProjectView(proj, m_mainWidget); p->setObjectName(n); m_stackWidget->addWidget(p); QString t = QString("打开项目-%1").arg(proj->projectName); m_naviInterface->addItem(p->objectName(), NEWFLICON(QFDIcon, Project1), t, this, SLOT(slotNaviItemClicked()), true, NavigationItemPosition::SCROLL); m_stackWidget->setCurrentWidget(p); connect(p, &ProjectView::sigClose, this, &MainWindow::slotCloseProject); } } void MainWindow::slotCloseProject() { ProjectView *p = dynamic_cast(sender()); m_stackWidget->removeWidget(p); m_naviInterface->removeWidget(sender()->objectName()); m_stackWidget->setCurrentIndex(0); } void MainWindow::slotDeleteProject(ProjectInfo *proj) { QString n = QString("project_%1").arg(proj->id); int index = m_stackWidget->index(n); if (index >= 0) { QWidget *w = m_stackWidget->widget(index); m_stackWidget->removeWidget(w); m_naviInterface->removeWidget(n); m_stackWidget->setCurrentIndex(0); } }