From a6d835154635791414ec8a00534149b19a8eb1d6 Mon Sep 17 00:00:00 2001 From: brige Date: Sun, 2 Nov 2025 19:28:37 +0800 Subject: [PATCH] modify mainfram and remove chart plotmenu --- src/ui/MainFrame.cpp | 1 - src/ui/MainWindow.cpp | 62 +++++++++++++++++++++++++++++++++++ src/ui/Menu/ChartPlotMenu.cpp | 60 --------------------------------- src/ui/Menu/ChartPlotMenu.h | 25 -------------- 4 files changed, 62 insertions(+), 86 deletions(-) delete mode 100644 src/ui/Menu/ChartPlotMenu.cpp delete mode 100644 src/ui/Menu/ChartPlotMenu.h diff --git a/src/ui/MainFrame.cpp b/src/ui/MainFrame.cpp index 350df265..3fbc9538 100644 --- a/src/ui/MainFrame.cpp +++ b/src/ui/MainFrame.cpp @@ -22,7 +22,6 @@ #include "chartPlot/FitCurveDialog.h" #include "chartPlot/SurfaceDialog.h" -#include "ui/Menu/ChartPlotMenu.h" // lz 20140914 #include "common/SpdLogger.h" #include "ui/Menu/SimuRunMenu.h" diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index 21342c31..8efaa927 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -85,9 +85,22 @@ void MainWindow::InitUI() { //addDockWidget(pSettingUI->GetArea("PropertyBrowser"), attribte); propertyBrowser_ = new PropertyBrowser(0); propertyBrowser_->AttachDock(attribte); + // Ensure property panel has a reasonable minimum width; no maximum limit + attribte->setMinimumWidth(240); mapDockWidget_.insert("PropertyBrowser", attribte); addDockWidget(Qt::RightDockWidgetArea, attribte); + // Set an initial width for the property dock (no max constraint), + // this serves as default when there is no saved layout yet. + { + const int totalWidth = qMax(800, this->width()); + const int initialPropWidth = qBound(240, totalWidth / 4, 480); // ~25% of window, within [240, 480] + QList docksProp; + QList sizesProp; + docksProp << attribte; sizesProp << initialPropWidth; + resizeDocks(docksProp, sizesProp, Qt::Horizontal); + } + connect(modelBrowser_, &ModelBrowser::WorkSpaceChange, propertyBrowser_, &PropertyBrowser::OnWorkSpaceChange); connect(modelBrowser_, &ModelBrowser::EntityChange, propertyBrowser_, &PropertyBrowser::OnEntityChange); @@ -98,6 +111,10 @@ void MainWindow::InitUI() { viewDock->SetDockWidgetTitleBar(new DockTitleBar(viewDock)); viewDock->setObjectName("Dock.MainView"); viewDock->setWidget(qtOsgViewWidget_); + // Ensure main view has a reasonable minimum size to avoid being squeezed + // Use smaller minimum size to support smaller displays + qtOsgViewWidget_->setMinimumSize(640, 480); + viewDock->setMinimumSize(640, 480); addDockWidget(Qt::LeftDockWidgetArea, viewDock); mapDockWidget_.insert("MainView", viewDock); @@ -116,6 +133,51 @@ void MainWindow::InitUI() { UiLayoutManager::Restore(this, 1); LOG_INFO("MainWindow::InitUI - UiLayoutManager::Restore completed"); + // After restore, if the main view is too small, expand it + { + QDockWidget* mainViewDock = mapDockWidget_.value("MainView", nullptr); + QDockWidget* modelDock = mapDockWidget_.value("ModelBrowser", nullptr); + QDockWidget* propertyDock = mapDockWidget_.value("PropertyBrowser", nullptr); + if (mainViewDock) { + // Use percentage-based allocation instead of fixed pixel values + const int totalWidth = this->width(); + const int modelBrowserWidth = qMin(280, totalWidth / 6); // ~15% or max 280px + const int propertyBrowserWidth = qMin(320, totalWidth / 4); // ~25% or max 320px + const int mainViewMinWidth = totalWidth - modelBrowserWidth - propertyBrowserWidth - 50; // Reserve some margin + + // Only resize if main view is too small (less than 50% of available space) + if (mainViewDock->width() < mainViewMinWidth * 0.5) { + QList docks; + QList sizes; + if (modelDock) { docks << modelDock; sizes << modelBrowserWidth; } + docks << mainViewDock; sizes << mainViewMinWidth; + resizeDocks(docks, sizes, Qt::Horizontal); + } + } + + // Defer setting an initial width for the property dock once, without constraining max width + if (propertyDock) { + QDockWidget* capturedDock = propertyDock; + QMetaObject::invokeMethod(this, [this, capturedDock]() { + QDockWidget* pd = capturedDock; + if (!pd) return; + const int totalW = this->width(); + const int desired = qBound(240, totalW / 4, 480); // ~25% of window + LOG_INFO("PropertyDock pre-adjust width=%d, desired=%d, windowW=%d", pd->width(), desired, totalW); + const int oldMin = pd->minimumWidth(); + const int oldMax = pd->maximumWidth(); + pd->setMinimumWidth(desired); + pd->setMaximumWidth(desired); + QList docksProp; QList sizesProp; + docksProp << pd; sizesProp << desired; + resizeDocks(docksProp, sizesProp, Qt::Horizontal); + pd->setMinimumWidth(oldMin > 0 ? oldMin : 240); + pd->setMaximumWidth(QWIDGETSIZE_MAX); + LOG_INFO("PropertyDock post-adjust width=%d (min=%d,max=%d)", pd->width(), pd->minimumWidth(), pd->maximumWidth()); + }, Qt::QueuedConnection); + } + } + //ui->viewWidget->layout()->addWidget(qtOsgViewWidget_); qtOsgViewWidget_->LoadDefaultScene(); diff --git a/src/ui/Menu/ChartPlotMenu.cpp b/src/ui/Menu/ChartPlotMenu.cpp deleted file mode 100644 index 7389e9fe..00000000 --- a/src/ui/Menu/ChartPlotMenu.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "ChartPlotMenu.h" - -#include "../Matlab/MatlabObject.h" -#include "../../common/RecourceHelper.h" -#include "workspace/WorkSpace.h" -#include "workspace/WorkSpaceManager.h" -#include "workspace/LampStatus.h" -#include "utils/FileUtils.h" -#include - -#include -#include - -ChartPlotMenu::ChartPlotMenu(QWidget *parent) - : QWidget(parent) -{ - ui.setupUi(this); - - InitMenu(); -} - -ChartPlotMenu::~ChartPlotMenu() -{ - -} - -void ChartPlotMenu::InitMenu() -{ - // Deprecated: SimMatlab run action removed - - // Deprecated: SimMatlab selection removed - - // Deprecated: Wave file selection removed - - // Deprecated: RD file selection removed - - // Deprecated: Report file selection removed - - // Restore Lamp file selection with safe encoding - connect(ui.toolButton_6, &QToolButton::clicked, this, [this]() { - auto* ws = WorkSpaceManager::Get().GetCurrent(); - const QString defaultDir = ws ? ws->GetDir() : QDir::currentPath(); - const QString title = QString::fromLocal8Bit("选择Lamp文件"); - const QString filters = QString::fromLocal8Bit("文本文件 (*.txt);;所有文件 (*.*)"); - const QString file = QFileDialog::getOpenFileName(this, title, defaultDir, filters); - if (file.isEmpty()) { - return; - } - if (!ws) { - QMessageBox::warning(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("当前无工作区")); - return; - } - const bool ok = ws->SetLampPath(file); - if (ok) { - QMessageBox::information(this, QString::fromLocal8Bit("Lamp"), QString::fromLocal8Bit("已加载 Lamp 文件")); - } else { - QMessageBox::warning(this, QString::fromLocal8Bit("Lamp"), QString::fromLocal8Bit("加载 Lamp 文件失败")); - } - }); -} diff --git a/src/ui/Menu/ChartPlotMenu.h b/src/ui/Menu/ChartPlotMenu.h deleted file mode 100644 index 1009335e..00000000 --- a/src/ui/Menu/ChartPlotMenu.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include - -#include "ui_ChartPlotMenu.h" - -class DYTChart; -class ChartPlotMenu : public QWidget -{ - Q_OBJECT - -public: - ChartPlotMenu(QWidget *parent = nullptr); - ~ChartPlotMenu(); - -protected: - void InitMenu(); - bool IsRuning(); - -signals: - - -private: - Ui::ChartPlotMenuClass ui; -};