From 60e3e4035fafc9318b5630ada9c14e7c8305e59a Mon Sep 17 00:00:00 2001 From: duanshengchao <519970194@qq.com> Date: Thu, 21 Nov 2024 17:29:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0dataPanel=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E9=9D=A2=E6=9D=BF=E5=8F=AF=E4=BB=A5=E9=9A=8F?= =?UTF-8?q?=E5=A4=96=E9=83=A8=E5=AF=B9=E8=AF=9D=E6=A1=86=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E5=8F=98=E5=8C=96=E6=97=B6=E8=BF=9B=E8=A1=8C=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E7=BC=A9=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/dashboard.h | 1 + include/dataPanel.h | 6 +++ include/panelConfigurationWidget.h | 4 +- source/customTab.cpp | 4 +- source/dashboard.cpp | 24 ++++++++-- source/dashboardFrame.cpp | 37 ++++++++++------ source/dataPanel.cpp | 69 ++++++++++++++++++++++++++++- source/dvieMainWindow.cpp | 6 +-- source/main.cpp | 4 +- source/panelConfigurationWidget.cpp | 31 +++++++++++++ ui/dvieSecondaryWindow.ui | 4 +- 11 files changed, 163 insertions(+), 27 deletions(-) diff --git a/include/dashboard.h b/include/dashboard.h index 316d610..0f0cf4d 100644 --- a/include/dashboard.h +++ b/include/dashboard.h @@ -26,6 +26,7 @@ public: void setActive(bool); void addPanel(const QString&); void removePanel(const QString&); + void resizePanel(double, double); void deleteSubWidgets(); public slots: diff --git a/include/dataPanel.h b/include/dataPanel.h index 5827527..92a01c6 100644 --- a/include/dataPanel.h +++ b/include/dataPanel.h @@ -57,6 +57,11 @@ public: void setName(const QString&); const QString& getName(); + void setInitialSize(const QSize&); + void setDisplayAreaSize(const QSize&); + void resizeByRatio(double, double); //通过缩放比例做resize,在所属dasboard的resizeEvent中调用 + void resizeByNewSize(const QSize&); //通过新的尺寸(所在区域)做resize,当所属dashboard被激活(显示)时调用 + protected: bool event(QEvent*); /*void keyPressEvent(QKeyEvent*); @@ -85,6 +90,7 @@ private: bool m_bMouseEnter; QString m_strName; + QSize m_displayAreaSize; QRect m_curGeometry; CustomMenu* m_pToolMenu; QWidget* m_pContentWidget; diff --git a/include/panelConfigurationWidget.h b/include/panelConfigurationWidget.h index dcab638..1f89e3f 100644 --- a/include/panelConfigurationWidget.h +++ b/include/panelConfigurationWidget.h @@ -17,8 +17,10 @@ public: PanelConfigurationWidget(QWidget *parent = nullptr); ~PanelConfigurationWidget(); + //void zoomContent(int, int); + protected: - //void showEvent(QShowEvent*); + void resizeEvent(QResizeEvent*) override; signals: void sgl_configure(); diff --git a/source/customTab.cpp b/source/customTab.cpp index eb1be6a..8160b1d 100644 --- a/source/customTab.cpp +++ b/source/customTab.cpp @@ -86,7 +86,7 @@ void CustomTab::mouseMoveEvent(QMouseEvent* event) m_bDragging = true; Qt::DropAction dropAction = drag->exec(); - qDebug() << dropAction; + //qDebug() << dropAction; //exec之后的语句都会在drg操作完成之后(鼠标抬起)执行 delete drag; m_bLeftButtonPressed = false; @@ -94,7 +94,7 @@ void CustomTab::mouseMoveEvent(QMouseEvent* event) if(dropAction == Qt::IgnoreAction) //创建新的dvieSecondaryWindow { - qDebug() << "create dvieSecondaryWindow on" << QCursor::pos(); + //qDebug() << "create dvieSecondaryWindow on" << QCursor::pos(); m_pDashboard->frame()->moveDashboardToNewDVIEWindow(text(), QCursor::pos()); } } diff --git a/source/dashboard.cpp b/source/dashboard.cpp index 059c655..8e62a21 100644 --- a/source/dashboard.cpp +++ b/source/dashboard.cpp @@ -114,11 +114,21 @@ void Dashboard::setActive(bool bActive) { m_pDisplayAreaLayout->addWidget(m_pDisplayArea); m_pDisplayArea->show(); + for(int n = 0; n < m_dataPanels.count(); n++) + { + //让所有dataPanel根据当前area的size进行同步缩放 + m_dataPanels.at(n)->resizeByNewSize(m_pDisplayArea->size()); + } } else if(!bActive && m_pDisplayAreaLayout) { m_pDisplayAreaLayout->removeWidget(m_pDisplayArea); m_pDisplayArea->hide(); + for(int n = 0; n < m_dataPanels.count(); n++) + { + //让所有dataPanel记录area当前的size,当再次被激活时若size发生变化,让所有dataPanel进行同步缩放 + m_dataPanels.at(n)->setDisplayAreaSize(m_pDisplayArea->size()); + } } m_pTab->setActive(bActive); @@ -131,11 +141,13 @@ void Dashboard::addPanel(const QString& strType) QString strDefaultName = "dataPanel-" + QString::number(m_nPanenlNameNumber); m_nPanenlNameNumber++; panel->setName(strDefaultName); - //panel->setStyleSheet("QDialog{background-color:transparent;}"); + int nPanelWidth = m_pDisplayArea->width() * 0.25; + int nPanelHeight = nPanelWidth * 0.56; //16:9宽高比 + panel->setInitialSize(QSize(nPanelWidth, nPanelHeight)); int nCount = m_dataPanels.count(); //QPoint originPoint = m_pDisplayArea->mapToGlobal(QPoint(0, 0)); - int nX = /*originPoint.x() +*/ (m_pDisplayArea->width() - panel->width()) * 0.5 + nCount * 10; - int nY = /*originPoint.y() +*/ (m_pDisplayArea->height() - panel->height()) * 0.5 + nCount * 10; + int nX = /*originPoint.x() +*/ (m_pDisplayArea->width() - nPanelWidth) * 0.5 + nCount * 10; + int nY = /*originPoint.y() +*/ (m_pDisplayArea->height() - nPanelHeight) * 0.5 + nCount * 10; panel->move(nX, nY); panel->show(); m_dataPanels.push_back(panel); @@ -160,6 +172,12 @@ void Dashboard::removePanel(const QString& strName) } } +void Dashboard::resizePanel(double ratioX, double ratioY) +{ + for(int n = 0; n < m_dataPanels.count(); n++) + m_dataPanels.at(n)->resizeByRatio(ratioX, ratioY); +} + void Dashboard::contextMenu_tab(const QPoint& pos) { QPoint originPoint = m_pTab->mapToGlobal(QPoint(0, 0)); diff --git a/source/dashboardFrame.cpp b/source/dashboardFrame.cpp index 30b1454..0464cbf 100644 --- a/source/dashboardFrame.cpp +++ b/source/dashboardFrame.cpp @@ -83,21 +83,31 @@ bool DashboardFrame::eventFilter(QObject* obj, QEvent* event) void DashboardFrame::resizeEvent(QResizeEvent* event) { - if(m_pTransparentMask && m_pTransparentMask->isVisible()) - m_pTransparentMask->setGeometry(0, 0, this->width(), this->height()); - - if(m_pMessageDialog && m_pMessageDialog->isVisible()) + //qDebug() << "oldSize:" << event->oldSize() << " size:" << event->size(); + if(event->oldSize() != QSize(-1, -1)) //Qt默认的初始化创建过程中会有从QSize(-1, -1)的变化,需要忽略 { - int nX = (ui->navigationPanel->width() - m_pMessageDialog->width()) * 0.5; - int nY = ui->navigationPanel->y() + ui->navigationPanel->height() * 0.5; - m_pMessageDialog->move(nX, nY); - } + if(m_pTransparentMask && m_pTransparentMask->isVisible()) + m_pTransparentMask->setGeometry(0, 0, this->width(), this->height()); - if(m_pDashboardNamingDialog && m_pDashboardNamingDialog->isVisible()) - { - int nX = (ui->navigationPanel->width() - m_pDashboardNamingDialog->width()) * 0.5; - int nY = ui->navigationPanel->y() + ui->navigationPanel->height() * 0.5; - m_pDashboardNamingDialog->move(nX, nY); + if(m_pMessageDialog && m_pMessageDialog->isVisible()) + { + int nX = (ui->navigationPanel->width() - m_pMessageDialog->width()) * 0.5; + int nY = ui->navigationPanel->y() + ui->navigationPanel->height() * 0.5; + m_pMessageDialog->move(nX, nY); + } + + if(m_pDashboardNamingDialog && m_pDashboardNamingDialog->isVisible()) + { + int nX = (ui->navigationPanel->width() - m_pDashboardNamingDialog->width()) * 0.5; + int nY = ui->navigationPanel->y() + ui->navigationPanel->height() * 0.5; + m_pDashboardNamingDialog->move(nX, nY); + } + + double ratioX = (double)event->size().width() / (double)event->oldSize().width(); + double ratioY = (double)event->size().height() / (double)event->oldSize().height(); + //qDebug() << ratioX << ", " << ratioY; + if(m_curActiveDashboard) + m_curActiveDashboard->resizePanel(ratioX, ratioY); } QWidget::resizeEvent(event); @@ -371,6 +381,7 @@ void DashboardFrame::setCurrentDashboard(const QString& strName) CustomTab* tab = m_listDashboard.at(n)->tab(); m_pDashboardTabBar->ensureWidgetVisible(tab); m_curActiveDashboard = m_listDashboard.at(n); + return; } } } diff --git a/source/dataPanel.cpp b/source/dataPanel.cpp index f1f4d8c..c7b2c80 100644 --- a/source/dataPanel.cpp +++ b/source/dataPanel.cpp @@ -41,7 +41,7 @@ DataPanel::DataPanel(QWidget *parent) m_pConfigurationWidget = new PanelConfigurationWidget(); setWiget(m_pConfigurationWidget); - resize(533, 300); + //resize(533, 300); m_pCustomBorderContainer = new CustomBorderContainer(this); m_pCustomBorderContainer->setOperationOption(CustomBorderContainer::WidgetMovable | CustomBorderContainer::WidgetResizable | CustomBorderContainer::WidgetAutoAdjustGeometry); @@ -216,6 +216,72 @@ const QString& DataPanel::getName() return m_strName; } +void DataPanel::setInitialSize(const QSize& size) +{ + resize(size); + m_pCustomBorderContainer->updateBorder(); +} + +void DataPanel::setDisplayAreaSize(const QSize& size) +{ + m_displayAreaSize = size; +} + +void DataPanel::resizeByRatio(double ratioX, double ratioY) +{ + QString strCurState = m_pToolWidget->ui->btnFullScree->property("currentState").toString(); + if(strCurState == "exitFullScreen") //当前是全屏状态 + setGeometry(0, 0, parentWidget()->width(), parentWidget()->height()); + else + { + QRect geometry = this->geometry(); + QRect newGeometry; + //double转换为int默认只取整数部分,因此ratio若<1,执行默认操作,反之向上取整 + if(ratioX < 1) + { + newGeometry.setX(geometry.x() * ratioX); + newGeometry.setWidth(geometry.width() * ratioX); + } + else + { + newGeometry.setX(qCeil(geometry.x() * ratioX)); + newGeometry.setWidth(qCeil(geometry.width() * ratioX)); + } + if(ratioY < 1) + { + newGeometry.setY(geometry.y() * ratioY); + newGeometry.setHeight(geometry.height() * ratioY); + } + else + { + newGeometry.setY(qCeil(geometry.y() * ratioY)); + newGeometry.setHeight(qCeil(geometry.height() * ratioY)); + } + if(newGeometry.x() < 0) + newGeometry.setX(0); + if(newGeometry.y() < 0) + newGeometry.setY(0); + + setGeometry(newGeometry); + + // qDebug() << geometry.x() << "," << geometry.y() << "," << geometry.width() << "," << geometry.height(); + // qDebug() << ratioX << "," << ratioY; + // qDebug() << newGeometry.x() << "," << newGeometry.y() << "," << newGeometry.width() << "," << newGeometry.height(); + } + + m_curGeometry = QRect(m_curGeometry.x() * ratioX, m_curGeometry.y() * ratioY, m_curGeometry.width() * ratioX, m_curGeometry.height() * ratioY); + m_pCustomBorderContainer->updateBorder(); +} +void DataPanel::resizeByNewSize(const QSize& newSize) +{ + if(m_displayAreaSize == newSize) + return; + + double ratioX = (double)newSize.width() / (double)m_displayAreaSize.width(); + double ratioY = (double)newSize.height() / (double)m_displayAreaSize.height(); + resizeByRatio(ratioX, ratioY); +} + void DataPanel::onToolBtnClicked_setting() { @@ -259,6 +325,7 @@ void DataPanel::onToolBtnClicked_fullScreen() m_pCustomBorderContainer->setOperationOption(CustomBorderContainer::WidgetMovable | CustomBorderContainer::WidgetResizable | CustomBorderContainer::WidgetAutoAdjustGeometry); m_pCustomBorderContainer->showBorderDraw(); setGeometry(m_curGeometry); + m_pCustomBorderContainer->updateBorder(); } } diff --git a/source/dvieMainWindow.cpp b/source/dvieMainWindow.cpp index 9c9d649..bf66164 100644 --- a/source/dvieMainWindow.cpp +++ b/source/dvieMainWindow.cpp @@ -61,7 +61,7 @@ DashboardFrame* DvieMainWindow::getDashboardFrame(const QString& strName) if(nIndex != -1) { QString strDVIEWindowName = strName.left(nIndex); - qDebug() << strDVIEWindowName; + //qDebug() << strDVIEWindowName; auto itr = m_hashSecondaryWindow.find(strDVIEWindowName); if(itr != m_hashSecondaryWindow.end()) frame = itr.value()->dashboardFrame(); @@ -75,11 +75,11 @@ void DvieMainWindow::creatSecondaryWindowAndAddDashboard(QPoint pos, Dashboard* { QString strName = "secondaryDVIE_" + QDateTime::currentDateTime().toString("yyMMdd-HHmmss"); DvieSecondaryWindow* secondartWindow = new DvieSecondaryWindow(strName, this); - if(secondartWindow->dashboardFrame()) - secondartWindow->dashboardFrame()->addDashboard(dashboard); secondartWindow->setMainWindow(this); secondartWindow->move(pos); secondartWindow->show(); + if(secondartWindow->dashboardFrame()) + secondartWindow->dashboardFrame()->addDashboard(dashboard); m_hashSecondaryWindow.insert(strName, secondartWindow); //qDebug() << m_hashSecondaryWindow.count(); } diff --git a/source/main.cpp b/source/main.cpp index de474cb..7fca72c 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -18,8 +18,8 @@ int main(int argc, char *argv[]) // int a = 1; // } - QString osName = QSysInfo::productType(); - qDebug() << "Operating System Name:" << osName; + // QString osName = QSysInfo::productType(); + // qDebug() << "Operating System Name:" << osName; // qputenv("QT_ENABLE_HIGHDPI_SCALING", "1"); // QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); diff --git a/source/panelConfigurationWidget.cpp b/source/panelConfigurationWidget.cpp index c2becaf..d92c10e 100644 --- a/source/panelConfigurationWidget.cpp +++ b/source/panelConfigurationWidget.cpp @@ -15,6 +15,37 @@ PanelConfigurationWidget::~PanelConfigurationWidget() delete ui; } +void PanelConfigurationWidget::resizeEvent(QResizeEvent* event) +{ + +} + +/*void PanelConfigurationWidget::zoomContent(int ratioX, int ratioY) +{ + //子部件gemometry & frot + QRect geometry; + QFont font; + //lable + font = ui->label->font(); + int pixelSize = font.pixelSize(); + font.setPixelSize(pixelSize * ratioY); + ui->label->setFont(font); + //configureButton + font = ui->btnConfigure->font(); + pixelSize = font.pixelSize(); + font.setPixelSize(pixelSize * ratioY); + ui->btnConfigure->setFont(font); + QSize iconSize = ui->btnConfigure->iconSize(); + iconSize.setWidth(iconSize.width() * ratioX); + iconSize.setHeight(iconSize.height() * ratioY); + ui->btnConfigure->setIconSize(iconSize); + geometry = ui->btnConfigure->geometry(); + int width = geometry.width() * ratioX; + int height = geometry.height() * ratioY; + ui->btnConfigure->setMaximumSize(width, height); + ui->btnConfigure->setMinimumSize(width, height); +}*/ + void PanelConfigurationWidget::onBtnClicked_configure() { emit sgl_configure(); diff --git a/ui/dvieSecondaryWindow.ui b/ui/dvieSecondaryWindow.ui index afa3494..16a5200 100644 --- a/ui/dvieSecondaryWindow.ui +++ b/ui/dvieSecondaryWindow.ui @@ -6,8 +6,8 @@ 0 0 - 998 - 607 + 1168 + 676