NativeTabItem::NativeTabItem(NativeTabFolder* _parent, int index, int flags) : parent(_parent), style(flags), showClose(true), closeButton(nullptr) { parent->GetTabFolder()->insertTab(index, this); if (this->GetShowClose()) { parent->GetTabFolder()->setTabButton(index, QTabBar::RightSide, this->GetCloseButton()); this->connect(this->GetCloseButton(), SIGNAL(clicked()), this, SLOT(CloseButtonClicked())); } }
LogView::LogView(QWidget *parent) : QWidget(parent) { mUI.setupUi(this); setWindowFlags(Qt::Tool); connect(mUI.mCloseButton, SIGNAL(clicked()), this, SLOT(CloseButtonClicked())); connect(mUI.mClearButton, SIGNAL(clicked()), this, SLOT(ClearButtonClicked())); connect(mUI.mSaveButton, SIGNAL(clicked()), this, SLOT(SaveButtonClicked())); QSettings settings; resize(settings.value(SETTINGS_LOG_VIEW_WIDTH, 400).toInt(), settings.value(SETTINGS_LOG_VIEW_HEIGHT, 300).toInt()); }
LogView::LogView(QWidget *parent) : QWidget(parent) { mUI.setupUi(this); setWindowFlags(Qt::Tool); mUI.mButtonBox->button(QDialogButtonBox::Reset)->setText(tr("Clear")); connect(mUI.mButtonBox->button(QDialogButtonBox::Close), SIGNAL(clicked()), this, SLOT(CloseButtonClicked())); connect(mUI.mButtonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()), this, SLOT(ClearButtonClicked())); connect(mUI.mButtonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), this, SLOT(SaveButtonClicked())); QSettings settings; resize(settings.value(SETTINGS_LOG_VIEW_WIDTH, 400).toInt(), settings.value(SETTINGS_LOG_VIEW_HEIGHT, 300).toInt()); }
MainPage::MainPage(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags) { ui.setupUi(this); this->LoadQSS(); m_mousePressed = false; QObject::connect(ui.toolButtonHardware, SIGNAL(clicked()), this, SLOT(HardwareInforClicked())); QObject::connect(ui.toolButtonTempManagement, SIGNAL(clicked()), this, SLOT(TemperatureClicked())); QObject::connect(ui.toolButtonTestItem, SIGNAL(clicked()), this, SLOT(TestItemClicked())); QObject::connect(ui.pushButtonMin, SIGNAL(clicked()), this, SLOT(MinButtonClicked())); QObject::connect(ui.pushButtonClose, SIGNAL(clicked()), this, SLOT(CloseButtonClicked())); QObject::connect(ui.pushButtonUpdate, SIGNAL(clicked()), this, SLOT(UpdateButtonClicked())); QObject::connect(&m_checkNewTimer, SIGNAL(timeout()), this, SLOT(CheckNewTimerTimeout())); QObject::connect(&m_downloadNewTimer, SIGNAL(timeout()), this, SLOT(DownloadNewTimerTimeout())); // 隐藏默认窗口边框和标题栏 this->setWindowFlags(Qt::Window|Qt::FramelessWindowHint|Qt::WindowSystemMenuHint |Qt::WindowMinimizeButtonHint|Qt::WindowMaximizeButtonHint); this->setWindowIcon(QIcon(":/ControlImage/Main.png")); QString title = MAIN_TITLE; title += LAppParam::GetAppVersion(); this->ui.labelTitle->setText(title); this->ui.pushButtonUpdate->setVisible(false); // 获取当前系统DPI, 当前系统DPI除以设计时DPI值, 则得到UI放大系数 const float DESIGN_DPI = 96.0f; // 设计时DPI QPainter painter(this); QPaintDevice* pDevice = painter.device(); PrintLogW(L"System DPI X: %d, Y: %d", pDevice->logicalDpiX(), pDevice->logicalDpiY()); float ratioX = pDevice->logicalDpiX()/DESIGN_DPI; float ratioY = pDevice->logicalDpiY()/DESIGN_DPI; m_uiRatio = ratioX > ratioY ? ratioX : ratioY; if (m_uiRatio < 1.0f) m_uiRatio = 1.0f; PrintLogW(L"UI Ratio: %f", m_uiRatio); // 根据比例重新调整主UI大小, 并居中显示 int width = this->geometry().width() * m_uiRatio; int height = this->geometry().height() * m_uiRatio; this->setFixedSize(width, height); QDesktopWidget* pDesk = QApplication::desktop(); this->move((pDesk->width() - width) / 2, (pDesk->height() - height) / 2); // 显示启动画面 QPixmap originalImage(".\\Image\\Background\\splash.png"); QSize imageSize(originalImage.width() * m_uiRatio, originalImage.height() * m_uiRatio); QPixmap scaledImage = originalImage.scaled(imageSize, Qt::KeepAspectRatio); QFont splashFont("Microsoft YaHei UI", 10); m_splashScreen.setFont(splashFont); m_splashScreen.setPixmap(scaledImage); m_splashScreen.show(); width = ui.stackedWidget->width() * m_uiRatio; height = ui.stackedWidget->height() * m_uiRatio; m_splashScreen.showMessage(QObject::tr("Creating Hardware Page..."), Qt::AlignLeft | Qt::AlignTop, Qt::red); m_pHardwareInforPage = new HardwareInforPage(m_uiRatio); m_pHardwareInforPage->SetSplashScreen(&m_splashScreen); m_pHardwareInforPage->setFixedSize(width, height); m_pHardwareInforPage->InitHardwareInfor(); ui.stackedWidget->addWidget(m_pHardwareInforPage); m_splashScreen.showMessage(QObject::tr("Creating Temperature Page..."), Qt::AlignLeft | Qt::AlignTop, Qt::red); m_pTempManagementPage = new TempManagementPage(); m_pTempManagementPage->setFixedSize(width, height); ui.stackedWidget->addWidget(m_pTempManagementPage); m_splashScreen.showMessage(QObject::tr("Creating Test Item Page..."), Qt::AlignLeft | Qt::AlignTop, Qt::red); m_pTestItemPage = new TestItemPage(m_uiRatio); m_pTestItemPage->setFixedSize(width, height); ui.stackedWidget->addWidget(m_pTestItemPage); if (APP_NORMAL == LAppParam::GetStartMode()) ui.stackedWidget->setCurrentWidget(m_pHardwareInforPage); else if (APP_RESTARTAGING == LAppParam::GetStartMode()) ui.stackedWidget->setCurrentWidget(m_pTestItemPage); else ui.stackedWidget->setCurrentWidget(m_pTestItemPage); }