From 7c6c65566a7e780bd2e2d65e9cc7ec1ad576895f Mon Sep 17 00:00:00 2001 From: Zhang TingAn Date: Wed, 30 Oct 2024 19:06:24 +0800 Subject: [PATCH] feat: [controller] modified interface of windowService change the way of show dockWidget at right position Log: as title --- src/plugins/codegeex/codegeex.cpp | 30 +------ .../core/builtin/texts/uc_left_show_16px.svg | 9 ++ .../core/builtin/texts/uc_right_show_16px.svg | 7 ++ src/plugins/core/core.qrc | 2 + src/plugins/core/uicontroller/controller.cpp | 82 ++++++++++++++++++- src/plugins/core/uicontroller/controller.h | 2 + src/plugins/core/uicontroller/mainwindow.cpp | 2 +- src/plugins/debugger/debuggerplugin.cpp | 14 +--- src/services/window/windowelement.h | 1 + src/services/window/windowservice.h | 4 +- 10 files changed, 110 insertions(+), 43 deletions(-) create mode 100644 src/plugins/core/builtin/texts/uc_left_show_16px.svg create mode 100644 src/plugins/core/builtin/texts/uc_right_show_16px.svg diff --git a/src/plugins/codegeex/codegeex.cpp b/src/plugins/codegeex/codegeex.cpp index b9e214773..ca2e6ecc0 100644 --- a/src/plugins/codegeex/codegeex.cpp +++ b/src/plugins/codegeex/codegeex.cpp @@ -30,33 +30,9 @@ bool CodeGeex::start() { auto windowService = dpfGetService(dpfservice::WindowService); if (windowService) { - auto codeGeex = new CodeGeeXWidget; - auto codeGeexImpl = new AbstractWidget(codeGeex); - windowService->registerWidget(MWNA_CODEGEEX, codeGeexImpl); - windowService->deleteDockHeader(MWNA_CODEGEEX); // do not hide by header. - DToolButton *button = new DToolButton(codeGeex); - button->setIcon(QIcon::fromTheme("codegeex-navigation")); - button->setToolTip(MWNA_CODEGEEX); - button->setCheckable(true); - windowService->addStatusBarItem(button); - auto scAction = new QAction(tr("Quick Open CodeGeeX"), codeGeex); - auto cmd = ActionManager::instance()->registerAction(scAction, "CodeGeeX.Quick.Open"); - cmd->setDefaultKeySequence(QKeySequence(Qt::ALT + Qt::Key_L)); - - connect(scAction, &QAction::triggered, button, &DToolButton::clicked); - connect(button, &DToolButton::clicked, this, [=]() { - if (codeGeex->isVisible()) { - windowService->hideWidget(MWNA_CODEGEEX); - button->setChecked(false); - } else { - windowService->showWidgetAtPosition(MWNA_CODEGEEX, Position::Right, false); - button->setChecked(true); - } - }, Qt::DirectConnection); - connect(CodeGeeXCallProxy::instance(), &CodeGeeXCallProxy::switchToWidget, this, [=](const QString &name){ - if (button->isChecked()) - QMetaObject::invokeMethod(windowService, [=]() { windowService->showWidgetAtPosition(MWNA_CODEGEEX, Position::Right, false);}); - }, Qt::DirectConnection); + auto codeGeex = new CodeGeeXWidget; + auto codeGeexImpl = new AbstractWidget(codeGeex); + windowService->addWidgetRightspace(MWNA_CODEGEEX, codeGeexImpl, ""); } auto optionService = dpfGetService(dpfservice::OptionService); diff --git a/src/plugins/core/builtin/texts/uc_left_show_16px.svg b/src/plugins/core/builtin/texts/uc_left_show_16px.svg new file mode 100644 index 000000000..84bc4a028 --- /dev/null +++ b/src/plugins/core/builtin/texts/uc_left_show_16px.svg @@ -0,0 +1,9 @@ + + + ICON / view / right_show + + + + + + \ No newline at end of file diff --git a/src/plugins/core/builtin/texts/uc_right_show_16px.svg b/src/plugins/core/builtin/texts/uc_right_show_16px.svg new file mode 100644 index 000000000..92485d3a2 --- /dev/null +++ b/src/plugins/core/builtin/texts/uc_right_show_16px.svg @@ -0,0 +1,7 @@ + + + ICON / view / left_show + + + + \ No newline at end of file diff --git a/src/plugins/core/core.qrc b/src/plugins/core/core.qrc index 4b469bd8d..6ae831f7e 100644 --- a/src/plugins/core/core.qrc +++ b/src/plugins/core/core.qrc @@ -21,6 +21,8 @@ builtin/texts/hide_dock_16px.svg builtin/texts/docks_manager_16px.svg builtin/texts/context_widget_16px.svg + builtin/texts/uc_left_show_16px.svg + builtin/texts/uc_right_show_16px.svg builtin/texts/default_dock_16px.svg builtin/light/icons/notification_info_20px.svg builtin/light/icons/notification_warning_20px.svg diff --git a/src/plugins/core/uicontroller/controller.cpp b/src/plugins/core/uicontroller/controller.cpp index 0ff3adaf9..c71be109d 100644 --- a/src/plugins/core/uicontroller/controller.cpp +++ b/src/plugins/core/uicontroller/controller.cpp @@ -122,7 +122,8 @@ class ControllerPrivate { MainWindow *mainWindow { nullptr }; loadingWidget *loadingwidget { nullptr }; - WorkspaceWidget *workspace { nullptr }; + WorkspaceWidget *workspace { nullptr }; // left default dock widget + WorkspaceWidget *rightspace { nullptr }; // right default dock widget DWidget *navigationToolBar { nullptr }; NavigationBar *navigationBar { nullptr }; @@ -144,6 +145,8 @@ class ControllerPrivate QHBoxLayout *contextButtonLayout { nullptr }; WindowStatusBar *statusBar { nullptr }; + DToolButton *showContextBtn { nullptr }; + DToolButton *showRightspaceBtn { nullptr }; QStringList validModeList { CM_EDIT, CM_DEBUG, CM_RECENT }; QMap modePluginMap { { CM_EDIT, MWNA_EDIT }, { CM_RECENT, MWNA_RECENT }, { CM_DEBUG, MWNA_DEBUG } }; @@ -183,6 +186,7 @@ Controller::Controller(QObject *parent) initMainWindow(); initNavigationBar(); initStatusBar(); + initRightspaceWidget(); initContextWidget(); initWorkspaceWidget(); initTopToolBar(); @@ -311,9 +315,18 @@ void Controller::registerService() if (!windowService->addWidgetWorkspace) { windowService->addWidgetWorkspace = std::bind(&WorkspaceWidget::addWorkspaceWidget, d->workspace, _1, _2, _3); } + if (!windowService->addWidgetRightspace) { + windowService->addWidgetRightspace = std::bind(&WorkspaceWidget::addWorkspaceWidget, d->rightspace, _1, _2, _3); + } if (!windowService->registerToolBtnToWorkspaceWidget) { windowService->registerToolBtnToWorkspaceWidget = std::bind(&WorkspaceWidget::registerToolBtnToWidget, d->workspace, _1, _2); } + if (!windowService->registerToolBtnToRightspaceWidget) { + windowService->registerToolBtnToRightspaceWidget = std::bind(&WorkspaceWidget::registerToolBtnToWidget, d->rightspace, _1, _2); + } + if (!windowService->showWidgetAtRightspace) { + windowService->showWidgetAtRightspace = std::bind(&WorkspaceWidget::switchWidgetWorkspace, d->rightspace, _1); + } if (!windowService->registerWidgetToDockHeader) { windowService->registerWidgetToDockHeader = std::bind(&Controller::registerWidgetToDockHeader, this, _1, _2); } @@ -400,6 +413,7 @@ void Controller::raiseMode(const QString &mode) showTopToolBar(); showContextWidget(); + showRightspace(); d->mode = mode; uiController.modeRaised(mode); @@ -711,6 +725,38 @@ void Controller::showContextWidget() d->currentDocks.append(WN_CONTEXTWIDGET); } +void Controller::showRightspace() +{ + auto &rightSpaceInfo = d->allWidgets[WN_RIGHTSPACE]; + if (!rightSpaceInfo.created) { + createDockWidget(d->allWidgets[WN_RIGHTSPACE]); + d->mainWindow->showWidget(WN_RIGHTSPACE); + d->mainWindow->resizeDock(WN_RIGHTSPACE, QSize(300, 300)); + + for (auto btn : d->rightspace->getAllToolBtn()) + d->mainWindow->addWidgetToDockHeader(WN_RIGHTSPACE, btn); + + auto titles = d->rightspace->allWidgetTitles(); + QList headers; + for (auto title : titles) { + QAction *action = new QAction(title, d->rightspace); + connect(action, &QAction::triggered, this, [=]() { d->rightspace->switchWidgetWorkspace(title); }); + headers.append(action); + } + d->mainWindow->setDockHeaderList(WN_RIGHTSPACE, headers); + d->mainWindow->setDockHeaderName(WN_RIGHTSPACE, d->rightspace->currentTitle()); + + d->rightspace->addedToController = true; + connect(d->rightspace, &WorkspaceWidget::workSpaceWidgeSwitched, this, [=](const QString &title) { + d->mainWindow->setDockHeaderName(WN_RIGHTSPACE, title); + }); + connect(rightSpaceInfo.dockWidget, &QDockWidget::visibilityChanged, d->showRightspaceBtn, [=](bool visible){ d->showRightspaceBtn->setChecked(visible); }); + } else if (!rightSpaceInfo.hiddenByManual) { + d->mainWindow->showWidget(WN_RIGHTSPACE); + } + d->currentDocks.append(WN_RIGHTSPACE); +} + bool Controller::hasContextWidget(const QString &title) { return d->contextWidgets.contains(title); @@ -956,9 +1002,9 @@ void Controller::initContextWidget() info.icon = QIcon::fromTheme("context_widget"); if (d->statusBar) { - auto btn = createDockButton(info); - btn->setChecked(true); - d->statusBar->insertPermanentWidget(0, btn); + d->showContextBtn = createDockButton(info); + d->showContextBtn->setChecked(true); + d->statusBar->insertPermanentWidget(0, d->showContextBtn); } d->allWidgets.insert(WN_CONTEXTWIDGET, info); @@ -970,6 +1016,7 @@ void Controller::initStatusBar() return; d->statusBar = new WindowStatusBar(d->mainWindow); d->statusBar->hide(); + d->mainWindow->setStatusBar(d->statusBar); } @@ -988,6 +1035,31 @@ void Controller::initWorkspaceWidget() d->allWidgets.insert(WN_WORKSPACE, info); } +void Controller::initRightspaceWidget() +{ + if (d->rightspace) + return; + + d->rightspace = new WorkspaceWidget(d->mainWindow); + + WidgetInfo info; + info.name = WN_RIGHTSPACE; + info.setWidget(d->rightspace); + info.defaultPos = Position::Right; + info.replace = true; + info.icon = QIcon::fromTheme("uc_right_show"); + d->allWidgets.insert(WN_RIGHTSPACE, info); + + d->showRightspaceBtn = createDockButton(info); + d->showRightspaceBtn->setChecked(true); + auto scAction = new QAction(tr("Open rightspace"), d->rightspace); + auto cmd = ActionManager::instance()->registerAction(scAction, "Core.Open.Rightspace"); + cmd->setDefaultKeySequence(QKeySequence(Qt::ALT + Qt::Key_L)); + connect(scAction, &QAction::triggered, d->showRightspaceBtn, &DToolButton::clicked); + + d->statusBar->insertPermanentWidget(0, d->showRightspaceBtn); +} + void Controller::initTopToolBar() { d->leftTopToolBar = new DWidget(d->mainWindow); @@ -1276,6 +1348,8 @@ DToolButton *Controller::createDockButton(const WidgetInfo &info) btn->setCheckable(true); connect(btn, &DToolButton::clicked, this, [=]() { auto &dockInfo = d->allWidgets[info.name]; + if (!dockInfo.dockWidget) + return; if (dockInfo.dockWidget->isVisible()) { d->mainWindow->hideWidget(dockInfo.name); btn->setChecked(false); diff --git a/src/plugins/core/uicontroller/controller.h b/src/plugins/core/uicontroller/controller.h index f526e832d..800351170 100644 --- a/src/plugins/core/uicontroller/controller.h +++ b/src/plugins/core/uicontroller/controller.h @@ -81,6 +81,7 @@ public slots: //workspace void switchWorkspace(const QString &titleName); + void showRightspace(); void showCurrentDocksManager(); private: @@ -99,6 +100,7 @@ public slots: void initContextWidget(); void initStatusBar(); void initWorkspaceWidget(); + void initRightspaceWidget(); void initTopToolBar(); void initModules(); void initDocksManager(); diff --git a/src/plugins/core/uicontroller/mainwindow.cpp b/src/plugins/core/uicontroller/mainwindow.cpp index 11ce385d6..3666ff8e7 100644 --- a/src/plugins/core/uicontroller/mainwindow.cpp +++ b/src/plugins/core/uicontroller/mainwindow.cpp @@ -117,7 +117,7 @@ void MainWindow::setDockHeaderName(const QString &dockName, const QString &heade void MainWindow::setDockHeaderList(const QString &dockName, const QList &actions) { - if (!d->dockList.contains(dockName)) + if (!d->dockList.contains(dockName) || actions.isEmpty()) return; auto dock = d->dockList[dockName]; diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index dd4fe3bfc..74ce6437d 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -17,7 +17,6 @@ using namespace dpfservice; inline constexpr char mainWindow[] = "debugMainWindow"; -inline constexpr char localsPane[] = "debuggerWatcher"; void DebuggerPlugin::initialize() { @@ -55,22 +54,17 @@ bool DebuggerPlugin::start() windowService->bindWidgetToNavigation(mainWindow, actionImpl); windowService->setDockHeaderName(mainWindow, tr("debug")); auto localsPaneImpl = new AbstractWidget(debugManager->getLocalsPane()); - localsPaneImpl->setDisplayIcon(QIcon::fromTheme("variable_watchers")); - windowService->registerWidget(localsPane, localsPaneImpl); - windowService->deleteDockHeader(localsPane); + QString variablesPane = tr("Variables Watcher"); + windowService->addWidgetRightspace(variablesPane, localsPaneImpl, ""); connect(action, &QAction::triggered, this, [=]() { if (debugManager->getRunState() != AbstractDebugger::kNoRun) - windowService->showWidgetAtPosition(localsPane, Position::Right, false); + windowService->showWidgetAtRightspace(variablesPane); }, Qt::DirectConnection); connect(debugManager, &DebugManager::debugStarted, this, [=](){ uiController.doSwitch(MWNA_DEBUG); - windowService->showWidgetAtPosition(localsPane, Position::Right, false); - windowService->deleteDockHeader(localsPane); + windowService->showWidgetAtRightspace(variablesPane); uiController.switchContext(tr("&Application Output")); }, Qt::DirectConnection); - connect(debugManager, &DebugManager::debugStopped, this, [=](){ - windowService->hideWidget(localsPane); - }, Qt::DirectConnection); } return true; diff --git a/src/services/window/windowelement.h b/src/services/window/windowelement.h index 001aecfce..b87902265 100644 --- a/src/services/window/windowelement.h +++ b/src/services/window/windowelement.h @@ -30,6 +30,7 @@ inline const QString MWTG_DEBUG { "Debug" }; // WN = window name inline const QString WN_CONTEXTWIDGET = "contextWidget"; inline const QString WN_WORKSPACE = "workspaceWidget"; +inline const QString WN_RIGHTSPACE = "rightspaceWidget"; // MWM = MW menu // MWMFA = MWM File Action diff --git a/src/services/window/windowservice.h b/src/services/window/windowservice.h index d756ad3bb..0f12648fd 100644 --- a/src/services/window/windowservice.h +++ b/src/services/window/windowservice.h @@ -176,10 +176,12 @@ class WindowService final : public dpf::PluginService, dpf::AutoServiceRegister< * \param widget */ DPF_INTERFACE(void, addWidgetWorkspace, const QString &title, AbstractWidget *widget, const QString &iconName); + DPF_INTERFACE(void, addWidgetRightspace, const QString &title, AbstractWidget *widget, const QString &iconName); DPF_INTERFACE(void, registerWidgetToDockHeader,const QString &dockName, QWidget *widget); DPF_INTERFACE(void, registerToolBtnToWorkspaceWidget, Dtk::Widget::DToolButton *btn, const QString &title); + DPF_INTERFACE(void, registerToolBtnToRightspaceWidget, Dtk::Widget::DToolButton *btn, const QString &title); - DPF_INTERFACE(void, switchWorkspaceArea, const QString &title); + DPF_INTERFACE(void, showWidgetAtRightspace, const QString &title); DPF_INTERFACE(QWidget *, createFindPlaceHolder, QWidget *owner, AbstractDocumentFind *docFind);