245 lines
8.6 KiB
C++
245 lines
8.6 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
#include <QDesktopWidget>
|
|
#include <QTextCodec>
|
|
#include <QVBoxLayout>
|
|
#include <QDebug>
|
|
#include <QMutex>
|
|
#include <omp.h>
|
|
#include "globalStruct.h"
|
|
#include <QGraphicsDropShadowEffect>
|
|
int topBarHeight = 35;
|
|
MainWindow::MainWindow(QWidget* parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
this->setWindowFlags(Qt::FramelessWindowHint); // 设置无边框的样式
|
|
setMouseTracking(true);//鼠标追踪
|
|
this->setMinimumSize(1280, 720);
|
|
this->setMaximumSize(9999, 9999);
|
|
this->setObjectName("MainWidget");
|
|
this->setStyleSheet(QString("QWidget#MainWidget {background-color: rgb(%1)}").arg(sColor_blue));
|
|
this->setCentralWidget(&stackedWidgets);
|
|
|
|
//登录界面
|
|
stackedWidgets.addWidget(&_loginWindow);
|
|
connect(&_loginWindow, &loginWindow::login, this, &MainWindow::login);
|
|
|
|
//加载界面初始化
|
|
stackedWidgets.addWidget(&_loadingWidget);
|
|
|
|
//第一层 只有顶部菜单栏和第二层layout
|
|
mainWidget = new QWidget();
|
|
stackedWidgets.addWidget(mainWidget);
|
|
mainLayout = new QVBoxLayout(mainWidget);
|
|
mainLayout->setContentsMargins(0, 0, 0, 0);
|
|
topBarInit();
|
|
|
|
//第二层 只有左侧菜单栏和主界面
|
|
mainWidget2 = new QWidget();
|
|
mainLayout2 = new QHBoxLayout(mainWidget2);
|
|
mainLayout2->setAlignment(Qt::AlignLeft);
|
|
mainLayout2->setContentsMargins(0, 0, 0, 0);
|
|
mainLayout->addWidget(mainWidget2);
|
|
|
|
leftBarInit();
|
|
mainLayout2->addWidget(&pageWidgets);
|
|
|
|
//动画
|
|
blurEffect = new QGraphicsBlurEffect();
|
|
//毛玻璃效果
|
|
this->setGraphicsEffect(blurEffect);
|
|
blurEffectAnimation = new QPropertyAnimation(blurEffect, "blurRadius");
|
|
blurEffectAnimation->setDuration(50);
|
|
blurEffectAnimation->setEndValue(0);
|
|
blurEffectAnimation->start();
|
|
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
|
|
}
|
|
|
|
void MainWindow::topBarInit()
|
|
{
|
|
int buttonWidth = 50;
|
|
|
|
QWidget* menuBarWidget = new QWidget();//第一层QWidget
|
|
menuBarWidget->setStyleSheet(QString("QWidget { background-color: black;"
|
|
"border: 0px solid red;" // 显式设置边框
|
|
"border-radius: 0px;" // 设置边框半径为0,确保没有圆角
|
|
"}"));
|
|
menuBarWidget->setFixedHeight(topBarHeight);
|
|
QHBoxLayout* layout = new QHBoxLayout(menuBarWidget);
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
mainLayout->addWidget(menuBarWidget);
|
|
|
|
QWidget* leftWidget = new QWidget();
|
|
leftWidget->setFixedHeight(topBarHeight);
|
|
QHBoxLayout* leftLayout = new QHBoxLayout(leftWidget);
|
|
leftLayout->setContentsMargins(0, 0, 0, 0);
|
|
leftLayout->setAlignment(Qt::AlignLeft);
|
|
|
|
QWidget* midtWidget = new QWidget();
|
|
midtWidget->setFixedHeight(topBarHeight);
|
|
QHBoxLayout* midLayout = new QHBoxLayout(midtWidget);
|
|
midLayout->setContentsMargins(0, 0, 0, 0);
|
|
midLayout->setAlignment(Qt::AlignCenter);
|
|
|
|
QWidget* rightWidget = new QWidget();
|
|
rightWidget->setFixedHeight(topBarHeight);
|
|
QHBoxLayout* rightLayout = new QHBoxLayout(rightWidget);
|
|
rightLayout->setContentsMargins(0, 0, 0, 0);
|
|
rightLayout->setAlignment(Qt::AlignRight);
|
|
|
|
layout->addWidget(leftWidget);
|
|
layout->addWidget(midtWidget);
|
|
layout->addWidget(rightWidget);
|
|
|
|
// 左侧
|
|
QPalette palette;
|
|
palette.setColor(QPalette::WindowText, Qt::white);
|
|
QFont font("微软雅黑", 18, QFont::Bold);
|
|
font.setItalic(true);
|
|
|
|
QString title("CISCO AOI");
|
|
QLabel* iconLabel = new QLabel(title);
|
|
iconLabel->setFont(font);
|
|
iconLabel->setScaledContents(true); // 将 pixmap 自动填充 QLabel 的大小
|
|
iconLabel->setFixedHeight(topBarHeight);
|
|
leftLayout->addWidget(iconLabel);
|
|
iconLabel->setFixedWidth(buttonWidth);
|
|
iconLabel->setFixedWidth((buttonWidth/2)* title.size());
|
|
iconLabel->setPalette(palette);
|
|
|
|
// 右侧
|
|
//最小化
|
|
QPushButton* minimizeButton = new QPushButton();
|
|
minimizeButton->setIcon(QPixmap(":/topBar/icon/minus.png")); // 设置图标
|
|
minimizeButton->setStyleSheet(QString("QPushButton { background-color: transparent;"
|
|
"border: 0px solid red;" // 显式设置边框
|
|
"border-radius: 0px;" // 设置边框半径为0,确保没有圆角
|
|
"}"
|
|
"QPushButton:focus {"
|
|
" outline: none;"
|
|
"}"
|
|
"QPushButton:hover { background-color: rgb(%1); }").arg(sColor_Gold)); // 设置透明背景和悬停时的背景色
|
|
minimizeButton->setFixedHeight(topBarHeight);
|
|
minimizeButton->setFixedWidth(buttonWidth);
|
|
QObject::connect(minimizeButton, &QPushButton::clicked, this, &MainWindow::minimizeWindow); // 点击最小化按钮
|
|
rightLayout->addWidget(minimizeButton);
|
|
|
|
//最大化与缩小
|
|
maximizeRestoreButton = new QPushButton();
|
|
maximizeRestoreButton->setIcon(QPixmap(":/topBar/icon/fullscreen.png")); // 设置图标
|
|
maximizeRestoreButton->setStyleSheet(QString("QPushButton { background-color: transparent;"
|
|
"border: 0px solid red;" // 显式设置边框
|
|
"border-radius: 0px;" // 设置边框半径为0,确保没有圆角
|
|
"}"
|
|
"QPushButton:focus {"
|
|
" outline: none;"
|
|
"}"
|
|
"QPushButton:hover { background-color: rgb(%1); }").arg(sColor_Gold)); // 设置透明背景和悬停时的背景色
|
|
maximizeRestoreButton->setFixedHeight(topBarHeight);
|
|
maximizeRestoreButton->setFixedWidth(buttonWidth);
|
|
QObject::connect(maximizeRestoreButton, &QPushButton::clicked, this, &MainWindow::toggleMaximize); // 点击最大化/还原按钮
|
|
rightLayout->addWidget(maximizeRestoreButton);
|
|
|
|
//关闭窗口
|
|
QPushButton* exitButton = new QPushButton();
|
|
exitButton->setIcon(QPixmap(":/topBar/icon/close.png")); // 设置图标
|
|
rightLayout->addWidget(exitButton);
|
|
exitButton->setFixedHeight(topBarHeight);
|
|
exitButton->setStyleSheet(QString("QPushButton { background-color: transparent;"
|
|
"border: 0px solid red;" // 显式设置边框
|
|
"border-radius: 0px;" // 设置边框半径为0,确保没有圆角
|
|
"}"
|
|
"QPushButton:focus {"
|
|
" outline: none;"
|
|
"}"
|
|
"QPushButton:hover { background-color: rgb(%1); }").arg(sColor_Red)); // 设置透明背景和悬停时的背景色
|
|
exitButton->setFixedHeight(topBarHeight);
|
|
exitButton->setFixedWidth(buttonWidth);
|
|
QObject::connect(exitButton, &QPushButton::clicked, this, &QApplication::quit); // 点击退出按钮退出应用程序
|
|
// 将菜单栏添加到MainWindow的布局中
|
|
this->setMenuWidget(menuBarWidget);
|
|
_loadingWidget.start();
|
|
}
|
|
|
|
void MainWindow::leftBarInit()
|
|
{
|
|
int defaultWidth = 50;
|
|
int defaultHeight = 50;
|
|
|
|
QWidget* leftBarWidget = new QWidget();
|
|
leftBarWidget->setFixedWidth(defaultHeight);
|
|
leftBarWidget->setStyleSheet(QString("QWidget { background-color: black;"
|
|
"border: 0px solid red;" // 显式设置边框
|
|
"border-radius: 0px;" // 设置边框半径为0,确保没有圆角
|
|
"}"));
|
|
QVBoxLayout* layout = new QVBoxLayout(leftBarWidget);
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
mainLayout2->addWidget(leftBarWidget);
|
|
leftBarWidget->setFixedHeight(9999);
|
|
leftBarWidget->setFixedWidth(defaultWidth);
|
|
layout->setAlignment(Qt::AlignTop);
|
|
|
|
//主页面
|
|
toolBarButton* toMainBtn = new toolBarButton(
|
|
defaultWidth,
|
|
defaultHeight,
|
|
QIcon(":/topBar/icon/home.png"),
|
|
u8"主界面");
|
|
_displayWidget = new displayWidget();
|
|
pageWidgets.addWidget(_displayWidget);
|
|
pageBtns.push_back(toMainBtn);
|
|
|
|
//配置页面
|
|
toolBarButton* configBtn = new toolBarButton(
|
|
defaultWidth,
|
|
defaultHeight,
|
|
QIcon(":/topBar/icon/setting.png"),
|
|
u8"配置设置");
|
|
_configSettingWidget = new configSettingWidget();
|
|
pageWidgets.addWidget(_configSettingWidget);
|
|
pageBtns.push_back(configBtn);
|
|
|
|
//日志页面
|
|
toolBarButton* logBtn = new toolBarButton(
|
|
defaultWidth,
|
|
defaultHeight,
|
|
QIcon(":/topBar/icon/config.png"),
|
|
u8"日志");
|
|
_logWidget = new logWidget();
|
|
pageWidgets.addWidget(_logWidget);
|
|
pageBtns.push_back(logBtn);
|
|
|
|
toolBarButton* sqlBtn = new toolBarButton(
|
|
defaultWidth,
|
|
defaultHeight,
|
|
QIcon(":/topBar/icon/sql.png"),
|
|
u8"SQL可视化");
|
|
//_logWidget = new logWidget();
|
|
//pageWidgets.addWidget(_logWidget);
|
|
pageBtns.push_back(sqlBtn);
|
|
|
|
for (int index = 0; index < pageBtns.size(); index++)
|
|
{
|
|
layout->addWidget(pageBtns[index]);
|
|
connect(pageBtns[index], &QPushButton::clicked, [=]()
|
|
{
|
|
for (int index2 = 0; index2 < pageBtns.size(); index2++)
|
|
{
|
|
if (index2 != index)
|
|
pageBtns[index2]->toDefault();
|
|
}
|
|
pageBtns[index]->pressed();
|
|
pageWidgets.setCurrentIndex(index);
|
|
//qInfo() << "switch Page to Index:" << index;
|
|
qDebug() << "switch Page to Index:" << index;
|
|
});
|
|
}
|
|
toMainBtn->click();
|
|
} |