diff --git a/src/plugins/codeeditor/mainframe/toolbarmanager.cpp b/src/plugins/codeeditor/mainframe/toolbarmanager.cpp index 8404fdfa8..a6b4ba5c5 100644 --- a/src/plugins/codeeditor/mainframe/toolbarmanager.cpp +++ b/src/plugins/codeeditor/mainframe/toolbarmanager.cpp @@ -63,6 +63,7 @@ bool ToolBarManager::addActionItem(const QString &id, QAction *action, const QSt break; } } + d->toolbar->insertAction(before, action); if (currentIterator.value() == nullptr) diff --git a/src/plugins/collaborators/collaborators.cpp b/src/plugins/collaborators/collaborators.cpp index aef088b94..37dc62b93 100644 --- a/src/plugins/collaborators/collaborators.cpp +++ b/src/plugins/collaborators/collaborators.cpp @@ -20,9 +20,9 @@ bool Collaborators::start() auto &ctx = dpfInstance.serviceContext(); WindowService *windowService = ctx.service(WindowService::name()); if (windowService) { - if (windowService->addNavigation) { - windowService->addNavigation("Git"); - windowService->addNavigation("Svn"); + if (windowService->addActionNavigation) { + windowService->addActionNavigation("Git", new AbstractAction(new QAction(QIcon::fromTheme("git"), QAction::tr("Git")))); + windowService->addActionNavigation("Svn", new AbstractAction(new QAction(QIcon::fromTheme("svn"), QAction::tr("Svn")))); } if (windowService->addCentralNavigation) { windowService->addCentralNavigation("Git", diff --git a/src/plugins/core/core.qrc b/src/plugins/core/core.qrc index 54c942f0e..37e9a1573 100644 --- a/src/plugins/core/core.qrc +++ b/src/plugins/core/core.qrc @@ -68,7 +68,11 @@ images/open_file.png images/open_project.png images/reverse.png - images/down_arrow.png + images/down_arrow.png + images/recent.svg + images/svn.svg + images/edit.svg + images/git.svg builtin/actions/recent_20px.svg diff --git a/src/plugins/core/images/edit.svg b/src/plugins/core/images/edit.svg new file mode 100644 index 000000000..1e52f550f --- /dev/null +++ b/src/plugins/core/images/edit.svg @@ -0,0 +1,7 @@ + + + ICON / sidebar / edit + + + + \ No newline at end of file diff --git a/src/plugins/core/images/git.svg b/src/plugins/core/images/git.svg new file mode 100644 index 000000000..5acdb4766 --- /dev/null +++ b/src/plugins/core/images/git.svg @@ -0,0 +1,7 @@ + + + ICON / sidebar / Git + + + + \ No newline at end of file diff --git a/src/plugins/core/images/recent.svg b/src/plugins/core/images/recent.svg new file mode 100644 index 000000000..8dadf5c28 --- /dev/null +++ b/src/plugins/core/images/recent.svg @@ -0,0 +1,7 @@ + + + ICON / sidebar / history + + + + \ No newline at end of file diff --git a/src/plugins/core/images/svn.svg b/src/plugins/core/images/svn.svg new file mode 100644 index 000000000..d93c26839 --- /dev/null +++ b/src/plugins/core/images/svn.svg @@ -0,0 +1,7 @@ + + + ICON / sidebar /svn + + + + \ No newline at end of file diff --git a/src/plugins/core/mainframe/windowkeeper.cpp b/src/plugins/core/mainframe/windowkeeper.cpp index e8bb5c8f7..c6cdbaa77 100644 --- a/src/plugins/core/mainframe/windowkeeper.cpp +++ b/src/plugins/core/mainframe/windowkeeper.cpp @@ -17,10 +17,9 @@ #include #include #include +#include #include #include -#include - #include #include #include @@ -39,14 +38,10 @@ class WindowKeeperPrivate QHash centrals{}; DMainWindow *window{nullptr}; QActionGroup *navActionGroup{nullptr}; + DToolBar *toolbar{nullptr}; DMenu *mainMenu{nullptr}; DToolBar *editToolBar{nullptr}; - DFrame *leftToolBar{nullptr}; - DWidget *topToolBar{nullptr}; - QHash leftToolBtns; - QList topToolBtnList; - friend class WindowKeeper; }; @@ -144,27 +139,38 @@ void WindowKeeper::createStatusBar(DMainWindow *window) window->setStatusBar(statusBar); } -void WindowKeeper::createNavIconBtn(const QString &navName) +void WindowKeeper::createNavRecent(DToolBar *toolbar) { qInfo() << __FUNCTION__; + if (!toolbar) + return; - DToolButton *toolBtn = new DToolButton; - toolBtn->setCheckable(true); - toolBtn->setChecked(true); - toolBtn->setIcon(QIcon::fromTheme(navName.toLower())); + QAction* navRecent = new QAction(QIcon::fromTheme("recent"), MWNA_RECENT, toolbar); + navRecent->setCheckable(true); + d->navActionGroup->addAction(navRecent); + QAction::connect(navRecent, &QAction::triggered, [=](){ + WindowKeeper::switchWidgetNavigation(MWNA_RECENT); + }); - toolBtn->setMinimumSize(QSize(48, 48)); - toolBtn->setIconSize(QSize(20, 20)); + toolbar->addAction(navRecent); + toolbar->widgetForAction(navRecent)->setObjectName("Recent"); +} - d->leftToolBtns.insert(navName, toolBtn); +void WindowKeeper::createNavEdit(DToolBar *toolbar) +{ + qInfo() << __FUNCTION__; + if (!toolbar) + return; - connect(toolBtn, &DIconButton::clicked, [=](){ - WindowKeeper::switchWidgetNavigation(navName); + QAction* navEdit = new QAction(QIcon::fromTheme("edit"), MWNA_EDIT, toolbar); + navEdit->setCheckable(true); + d->navActionGroup->addAction(navEdit); + QAction::connect(navEdit, &QAction::triggered, [=](){ + WindowKeeper::switchWidgetNavigation(MWNA_EDIT); }); - QVBoxLayout *toolbarLayout = static_cast(d->leftToolBar->layout()); - toolbarLayout->addSpacing(5); - toolbarLayout->addWidget(toolBtn); + toolbar->addAction(navEdit); + toolbar->widgetForAction(navEdit)->setObjectName("Edit"); } void WindowKeeper::createMainMenu(DMenu *menu) @@ -183,28 +189,44 @@ void WindowKeeper::createMainMenu(DMenu *menu) createHelpActions(menu); } -void WindowKeeper::initLeftToolBar() -{ - if (!d->leftToolBar) - return; - - d->leftToolBar->setLineWidth(0); - d->leftToolBar->setFixedWidth(58); - DStyle::setFrameRadius(d->leftToolBar, 0); - - QVBoxLayout *layout = new QVBoxLayout(); - layout->setAlignment(Qt::AlignTop | Qt::AlignHCenter); - d->leftToolBar->setLayout(layout); -} - void WindowKeeper::layoutWindow(DMainWindow *window) { qInfo() << __FUNCTION__; if (!d->navActionGroup) d->navActionGroup = new QActionGroup(window); - createNavIconBtn(MWNA_RECENT); - createNavIconBtn(MWNA_EDIT); + d->toolbar = new DToolBar(DToolBar::tr("Navigation")); + d->toolbar->setMovable(false); + d->toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly); + d->toolbar->setIconSize(QSize(20, 20)); + + DPalette palette = d->toolbar->palette(); + if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::ColorType::LightType) { + palette.setColor(DPalette::Button, QColor("#FFFFFF")); + d->toolbar->setPalette(palette); + } else { + palette.setColor(DPalette::Button, QColor("#262626")); + d->toolbar->setPalette(palette); + } + + QObject::connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, + this, [=](){ + DPalette palette = d->toolbar->palette(); + if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::ColorType::LightType) { + palette.setColor(DPalette::Button, QColor("#FFFFFF")); + d->toolbar->setPalette(palette); + } else { + palette.setColor(DPalette::Button, QColor("#262626")); + d->toolbar->setPalette(palette); + } + }); + + DWidget *titleWiget = new DWidget(); + titleWiget->setFixedSize(58, 29); + d->toolbar->addWidget(titleWiget); + + createNavRecent(d->toolbar); + createNavEdit(d->toolbar); createMainMenu(d->mainMenu); @@ -212,6 +234,7 @@ void WindowKeeper::layoutWindow(DMainWindow *window) window->setWindowTitle("Deepin Union Code"); window->setWindowIcon(QIcon(":/core/images/unioncode@128.png")); + window->addToolBar(Qt::LeftToolBarArea, d->toolbar); window->setMinimumSize(QSize(MW_MIN_WIDTH,MW_MIN_HEIGHT)); window->setAttribute(Qt::WA_DeleteOnClose); @@ -239,11 +262,6 @@ WindowKeeper::WindowKeeper(QObject *parent) if (!d->window) { d->window = new DMainWindow(); - if (!d->leftToolBar) { - d->leftToolBar = new DFrame(); - initLeftToolBar(); - } - if (!d->mainMenu) { d->mainMenu = new DMenu(d->window->titlebar()); } @@ -279,8 +297,8 @@ WindowKeeper::WindowKeeper(QObject *parent) windowService->addCentralNavigation = std::bind(&WindowKeeper::addCentralNavigation, this, _1, _2); } - if (!windowService->addNavigation) { - windowService->addNavigation = std::bind(&WindowKeeper::addNavigation, this, _1); + if (!windowService->addActionNavigation) { + windowService->addActionNavigation = std::bind(&WindowKeeper::addActionNavigation, this, _1, _2); } if (!windowService->addAction) { @@ -304,14 +322,31 @@ QStringList WindowKeeper::navActionTexts() const return d->centrals.keys(); } -void WindowKeeper::addNavigation(const QString &id) +void WindowKeeper::addActionNavigation(const QString &id, AbstractAction *action) { - createNavIconBtn(id); + if (!action || !action->qAction() || !d->toolbar || !d->navActionGroup) + return; + + auto qAction = (QAction*)action->qAction(); + qAction->setCheckable(true); + d->navActionGroup->addAction(qAction); + d->toolbar->addAction(qAction); + d->toolbar->widgetForAction(qAction)->setObjectName(id); + QObject::connect(qAction, &QAction::triggered,[=](){ + switchWidgetNavigation(qAction->text()); + }); } void WindowKeeper::addCentralNavigation(const QString &navName, AbstractCentral *central) { qInfo() << __FUNCTION__; + auto &ctx = dpfInstance.serviceContext(); + WindowService *windowService = ctx.service(WindowService::name()); + + if (navName == MWNA_EDIT) { + d->editToolBar = static_cast(windowService->getEditToolBar()); + } + DWidget* inputWidget = static_cast(central->qWidget()); if(!central || !inputWidget || navName.isEmpty()) return; @@ -319,17 +354,6 @@ void WindowKeeper::addCentralNavigation(const QString &navName, AbstractCentral if (d->centrals.values().contains(inputWidget)) return; - auto &ctx = dpfInstance.serviceContext(); - WindowService *windowService = ctx.service(WindowService::name()); - - if (navName == MWNA_EDIT) { - d->editToolBar = static_cast(windowService->getEditToolBar()); - d->topToolBar = new DWidget(); - QHBoxLayout *layout = new QHBoxLayout(); - d->topToolBar->setLayout(layout); - d->topToolBar->setMinimumHeight(d->window->titlebar()->height()); - } - inputWidget->setParent(d->window); d->centrals.insert(navName, inputWidget); } @@ -473,69 +497,52 @@ void WindowKeeper::addOpenProjectAction(const QString &name, AbstractAction *act void WindowKeeper::initUserWidget() { qApp->processEvents(); - if (!d->leftToolBar) + if (!d->toolbar) return; -// if (d->toolbar->actions().size() > 0) { -// d->toolbar->actions().at(0)->trigger(); -// } + if (d->toolbar->actions().size() > 0) { + d->toolbar->actions().at(0)->trigger(); + } } void WindowKeeper::switchWidgetNavigation(const QString &navName) { auto beforWidget = d->window->takeCentralWidget(); - if (beforWidget) { + if (beforWidget) beforWidget->hide(); - } - - if (d->centrals.isEmpty() || !d->window) - return; - - auto widget = d->centrals[navName]; - if (!widget) - return; - - for (auto btn : d->topToolBtnList) { - btn->hide(); - } + d->editToolBar->hide(); d->window->titlebar()->setTitle(QString(tr("Deepin Union Code"))); if (navName == MWNA_EDIT) { - for (auto action : d->editToolBar->actions()) { - DIconButton *iconBtn = new DIconButton(); - iconBtn->setIcon(action->icon()); - iconBtn->setMinimumSize(QSize(36, 36)); - iconBtn->setIconSize(QSize(20, 20)); - d->topToolBtnList.append(iconBtn); - - connect(iconBtn, &DIconButton::clicked, action, &QAction::triggered); - - QHBoxLayout *topToolBarLayout = static_cast(d->topToolBar->layout()); - topToolBarLayout->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); - topToolBarLayout->addWidget(iconBtn); - } + DPalette palette = d->window->palette(); + palette.setColor(DPalette::Button, palette.color(DPalette::Base)); + d->editToolBar->setPalette(palette); + + QObject::connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, + this, [=](){ + DPalette palette = d->window->palette(); + palette.setColor(DPalette::Button, palette.color(DPalette::Base)); + d->editToolBar->setPalette(palette); + }); + QHBoxLayout *titleBarLayout = static_cast(d->window->titlebar()->layout()); - titleBarLayout->insertWidget(1, d->topToolBar, Qt::AlignLeft); - titleBarLayout->insertSpacing(titleBarLayout->indexOf(d->topToolBar), 20); + titleBarLayout->insertWidget(1, d->editToolBar, Qt::AlignLeft); d->window->titlebar()->setTitle(QString()); - d->topToolBar->show(); + titleBarLayout->insertSpacing(1, 12); + d->editToolBar->show(); } + setNavActionChecked(navName, true); - showNavWidget(widget); -} + if (d->centrals.isEmpty() || !d->window) + return; -void WindowKeeper::showNavWidget(DWidget *widget) -{ - DWidget *navWidget = new DWidget(); - QHBoxLayout *layout = new QHBoxLayout(navWidget); - layout->setContentsMargins(0, 0, 0, 0); - layout->setSpacing(2); - layout->addWidget(d->leftToolBar); - layout->addWidget(widget); - - d->window->setCentralWidget(navWidget); + auto widget = d->centrals[navName]; + if (!widget) + return; + + d->window->setCentralWidget(widget); d->window->centralWidget()->show(); } @@ -544,10 +551,9 @@ void WindowKeeper::setNavActionChecked(const QString &actionName, bool checked) if (!d->navActionGroup) return; - for (auto it = d->leftToolBtns.begin(); it != d->leftToolBtns.end(); it++) { - it.value()->setChecked(false); - if (it.key() == actionName) { - it.value()->setChecked(checked); + for (auto action : d->navActionGroup->actions()) { + if (action->text() == actionName) { + action->setChecked(checked); } } } diff --git a/src/plugins/core/mainframe/windowkeeper.h b/src/plugins/core/mainframe/windowkeeper.h index 4c1483a8a..5425ad151 100644 --- a/src/plugins/core/mainframe/windowkeeper.h +++ b/src/plugins/core/mainframe/windowkeeper.h @@ -46,7 +46,7 @@ class WindowKeeper final :public QObject QStringList navActionTexts() const; public slots: - void addNavigation(const QString &id); + void addActionNavigation(const QString &id, AbstractAction *action); void addCentralNavigation(const QString &navName, AbstractCentral *central); void addMenu(AbstractMenu *menu); void insertAction(const QString &menuName, const QString &beforActionName, @@ -61,6 +61,8 @@ private : void showAboutDlg(); void showAboutPlugins(); void layoutWindow(DMainWindow *window); + void createNavEdit(DToolBar *toolbar); + void createNavRecent(DToolBar *toolbar); void createStatusBar(DMainWindow *window); void createHelpActions(DMenu *menu); @@ -72,9 +74,6 @@ private : void setNavActionChecked(const QString &actionName, bool checked); void createMainMenu(DMenu *mainMenu); - void initLeftToolBar(); - void showNavWidget(DWidget *widget); - void createNavIconBtn(const QString &navName); }; #endif // WINDOWKEEPER_H diff --git a/src/services/window/windowservice.h b/src/services/window/windowservice.h index 758f062da..645847060 100644 --- a/src/services/window/windowservice.h +++ b/src/services/window/windowservice.h @@ -40,7 +40,7 @@ class WindowService final : public dpf::PluginService, dpf::AutoServiceRegister< * \brief addActionNavigation 添加导航栏action * \param action 实例对象 */ - DPF_INTERFACE(void, addNavigation, const QString &id); + DPF_INTERFACE(void, addActionNavigation, const QString &id, AbstractAction *action); /*! * \brief addMenu 添加菜单项