#pragma execution_character_set("utf-8") #include "frmmain.h" #include "ui_frmmain.h" #include "mainwindow.h" #include "quihelper.h" #include "appinit.h" frmMain::frmMain(QWidget *parent) : QWidget(parent), ui(new Ui::frmMain) { ui->setupUi(this); this->initForm(); this->initNav1(); this->initNav2(); this->changeBtnStyle(); ui->tbtn1->click(); } frmMain::~frmMain() { delete ui; } bool frmMain::eventFilter(QObject *watched, QEvent *event) { if (watched == ui->widgetTop) { if (event->type() == QEvent::MouseButtonDblClick) { on_btnMenu_Max_clicked(); } } return QWidget::eventFilter(watched, event); } void frmMain::initForm() { //将带菜单的窗体作为子窗体加入到界面中 MainWindow *mainWindow = new MainWindow; ui->widgetMain->layout()->addWidget(mainWindow); //设置无边框窗体 ui->widget->setProperty("form", true); //设置无边框 QUIHelper::setFramelessForm(this); this->setWindowTitle("数字化医疗系统"); ui->labTitle->setText(this->windowTitle()); ui->widgetTop->installEventFilter(this); ui->widgetNav1->setProperty("flag", "left"); ui->widgetNav2->setProperty("flag", "bottom"); ui->widgetLeft->setFixedWidth(80); ui->widgetNav2->setFixedHeight(220); ui->labLogo->setFixedHeight(55); //设置图形字体,logo可以换成图片 #if 0 QPixmap pix(":/image/logo.png"); pix = pix.scaled(ui->labLogo->size() - QSize(10, 10), Qt::KeepAspectRatio, Qt::SmoothTransformation); ui->labLogo->setPixmap(pix); #else IconHelper::setIcon(ui->labLogo, 0xf1b3, 35); #endif IconHelper::setIcon(ui->btnMenu_Min, 0xf068); IconHelper::setIcon(ui->btnMenu_Max, 0xf067); IconHelper::setIcon(ui->btnMenu_Close, 0xf00d); ui->line1->setFixedHeight(1); ui->line2->setFixedHeight(1); ui->line3->setFixedWidth(1); //绑定样式改变信号 connect(AppInit::Instance(), SIGNAL(changeStyle(QString)), this, SLOT(changeBtnStyle())); } void frmMain::initNav1() { icons1 << 0xf0e8 << 0xf080 << 0xf085; btns1 << ui->tbtn1 << ui->tbtn2 << ui->tbtn3; int count = btns1.count(); for (int i = 0; i < count; i++) { QToolButton *btn = (QToolButton *)btns1.at(i); btn->setCheckable(true); btn->setFixedHeight(60); btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); connect(btn, SIGNAL(clicked(bool)), this, SLOT(buttonClicked1())); } } void frmMain::initNav2() { icons2 << 0xf07c << 0xf04b << 0xf04c << 0xf04d; btns2 << ui->btnFile << ui->btnRun << ui->btnPause << ui->btnStop; int count = btns2.count(); for (int i = 0; i < count; i++) { QToolButton *btn = (QToolButton *)btns2.at(i); btn->setToolButtonStyle(Qt::ToolButtonIconOnly); connect(btn, SIGNAL(clicked(bool)), this, SLOT(buttonClicked2())); } } void frmMain::buttonClicked1() { QAbstractButton *b = (QAbstractButton *)sender(); int count = btns1.count(); for (int i = 0; i < count; i++) { QAbstractButton *btn = btns1.at(i); btn->setChecked(btn == b); } } void frmMain::buttonClicked2() { QAbstractButton *b = (QAbstractButton *)sender(); int count = btns2.count(); for (int i = 0; i < count; i++) { QAbstractButton *btn = btns2.at(i); btn->setChecked(btn == b); } } void frmMain::changeBtnStyle() { int iconSize = 25; int iconWidth = 30; int iconHeight = 30; IconHelper::StyleColor styleColor; styleColor.position = "left"; styleColor.iconSize = iconSize; styleColor.iconWidth = iconWidth; styleColor.iconHeight = iconHeight; styleColor.borderWidth = 3; styleColor.borderColor = QUIConfig::HighColor; styleColor.setColor(QUIConfig::NormalColorStart, QUIConfig::TextColor, QUIConfig::PanelColor, QUIConfig::TextColor); IconHelper::setStyle(ui->widgetNav1, btns1, icons1, styleColor); //采用三态设置方法 //IconHelper::StyleColor styleColor; styleColor.position = "bottom"; styleColor.iconSize = 20; styleColor.iconWidth = 22; styleColor.iconHeight = 22; styleColor.borderWidth = 0; styleColor.normalBgColor = QUIConfig::NormalColorStart; styleColor.normalTextColor = QUIConfig::TextColor; styleColor.hoverBgColor = QUIConfig::PanelColor; styleColor.hoverTextColor = QUIConfig::TextColor; styleColor.pressedBgColor = QUIConfig::DarkColorStart; styleColor.pressedTextColor = QUIConfig::TextColor; styleColor.checkedBgColor = QUIConfig::DarkColorStart; styleColor.checkedTextColor = QUIConfig::TextColor; IconHelper::setStyle(ui->widgetNav2, btns2, icons2, styleColor); } void frmMain::on_btnMenu_Min_clicked() { showMinimized(); } void frmMain::on_btnMenu_Max_clicked() { static bool max = false; static QRect location = this->geometry(); if (max) { this->setGeometry(location); } else { location = this->geometry(); this->setGeometry(QUIHelper::getScreenRect()); } IconHelper::setIcon(ui->btnMenu_Max, max ? QUIConfig::IconNormal : QUIConfig::IconMax); this->setProperty("canMove", max); max = !max; } void frmMain::on_btnMenu_Close_clicked() { exit(0); }