Skip to content

Commit

Permalink
feat: DTK Changed-ToolBar and fix some bugs
Browse files Browse the repository at this point in the history
DTK Changed-ToolBar and fix some bugs.
  • Loading branch information
N0rthHXD authored and deepin-mozart committed Nov 22, 2023
1 parent 2723149 commit 871fede
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 151 deletions.
1 change: 1 addition & 0 deletions src/plugins/codeeditor/codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ bool CodeEditor::start()
if (windowService) {
NavEditMainWindow *navEditWindow = NavEditMainWindow::instance();
navEditWindow->setWidgetEdit(new AbstractCentral(editManager));
windowService->setTopToolBarWidget(new AbstractWidget(navEditWindow->getTopToolBarWidget()));
windowService->addCentralNavigation(MWNA_EDIT, new AbstractCentral(navEditWindow));

if (!windowService->addWidgetWorkspace) {
Expand Down
33 changes: 25 additions & 8 deletions src/plugins/codeeditor/mainframe/naveditmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ NavEditMainWindow::NavEditMainWindow(QWidget *parent, Qt::WindowFlags flags)
windowService->setToolBarItemDisable = std::bind(&NavEditMainWindow::setToolBarItemDisable, this, _1, _2);
}

if (!windowService->getEditToolBar) {
windowService->getEditToolBar = std::bind(&NavEditMainWindow::getEditToolBar, this);
}

QObject::connect(EditorCallProxy::instance(), &EditorCallProxy::toSwitchContext,
this, &NavEditMainWindow::switchWidgetContext);

Expand All @@ -83,6 +79,10 @@ NavEditMainWindow::NavEditMainWindow(QWidget *parent, Qt::WindowFlags flags)
mainToolBar = new ToolBarManager(tr("toolbar"));

titlebar()->setFixedHeight(0);

topToolBarWidget = new DWidget();
QHBoxLayout *toolBarLayout = new QHBoxLayout(topToolBarWidget);
toolBarLayout->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
}

NavEditMainWindow::~NavEditMainWindow()
Expand Down Expand Up @@ -286,6 +286,9 @@ void NavEditMainWindow::showValgrindBar()
bool NavEditMainWindow::addToolBarActionItem(const QString &id, QAction *action, const QString &group)
{
QMutexLocker locker(&mutex);

setToolBarButton(action);

if (!mainToolBar)
return false;

Expand All @@ -298,7 +301,22 @@ bool NavEditMainWindow::addToolBarWidgetItem(const QString &id, AbstractWidget *
if (!mainToolBar)
return false;

return mainToolBar->addWidgetItem(id, static_cast<QWidget*>(widget->qWidget()), group);
return mainToolBar->addWidgetItem(id, static_cast<DWidget*>(widget->qWidget()), group);
}

void NavEditMainWindow::setToolBarButton(QAction *action)
{
if (!action)
return;
DIconButton *iconBtn = new DIconButton();
iconBtn->setIcon(action->icon());
iconBtn->setMinimumSize(QSize(36, 36));
iconBtn->setIconSize(QSize(20, 20));
connect(iconBtn, &DIconButton::clicked, action, &QAction::triggered);

QHBoxLayout *toolBarLayout = static_cast<QHBoxLayout*>(topToolBarWidget->layout());
toolBarLayout->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
toolBarLayout->addWidget(iconBtn);
}

void NavEditMainWindow::removeToolBarItem(const QString &id)
Expand All @@ -324,8 +342,7 @@ void NavEditMainWindow::adjustWorkspaceItemOrder()
}
}

DWidget *NavEditMainWindow::getEditToolBar()
DWidget *NavEditMainWindow::getTopToolBarWidget()
{
DWidget *toolBar = static_cast<DWidget*>(mainToolBar->getToolBar());
return toolBar;
return topToolBarWidget;
}
5 changes: 4 additions & 1 deletion src/plugins/codeeditor/mainframe/naveditmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class NavEditMainWindow : public DMainWindow
ToolBarManager *mainToolBar{nullptr};
QList<QString> contextList;
QMutex mutex;

DWidget *topToolBarWidget{nullptr};
public:
static NavEditMainWindow *instance();
explicit NavEditMainWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
Expand All @@ -60,11 +62,12 @@ class NavEditMainWindow : public DMainWindow
void addValgrindBar(AbstractWidget *valgrindbar);
void showValgrindBar();
bool addToolBarActionItem(const QString &id, QAction *action, const QString &group);
void setToolBarButton(QAction *action);
bool addToolBarWidgetItem(const QString &id, AbstractWidget *widget, const QString &group);
void removeToolBarItem(const QString &id);
void setToolBarItemDisable(const QString &id, bool disable);

DWidget *getEditToolBar();
DWidget *getTopToolBarWidget();
private:
void adjustWorkspaceItemOrder();
};
Expand Down
1 change: 0 additions & 1 deletion src/plugins/codeeditor/transceiver/codeeditorreceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ void CodeEditorReceiver::eventProcess(const dpf::Event &event)
}else if (event.data() == editor.cleanRunning.name) {
return EditorCallProxy::instance()->toRunClean();
} else if (event.data() == editor.openFile.name) {
navigation.doSwitch(dpfservice::MWNA_EDIT);
using namespace support_file;
QString filePath = event.property(editor.openFile.pKeys[0]).toString();
QString language = Language::idAlias(Language::id(filePath));
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/collaborators/collaborators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ bool Collaborators::start()
auto &ctx = dpfInstance.serviceContext();
WindowService *windowService = ctx.service<WindowService>(WindowService::name());
if (windowService) {
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->addNavigation) {
windowService->addNavigation(MWNA_GIT, "git");
windowService->addNavigation(MWNA_SVN, "svn");
}
if (windowService->addCentralNavigation) {
windowService->addCentralNavigation("Git",
windowService->addCentralNavigation(MWNA_GIT,
new AbstractCentral(CVSkeeper::instance()->gitMainWidget()));
windowService->addCentralNavigation("Svn",
windowService->addCentralNavigation(MWNA_SVN,
new AbstractCentral(CVSkeeper::instance()->svnMainWidget()));
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/plugins/core/core.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@
<file>images/open_file.png</file>
<file>images/open_project.png</file>
<file>images/reverse.png</file>
<file>images/down_arrow.png</file>
<file>images/recent.svg</file>
<file>images/svn.svg</file>
<file>images/edit.svg</file>
<file>images/git.svg</file>
<file>images/down_arrow.png</file>
</qresource>
<qresource prefix="/icons/deepin/">
<file>builtin/actions/recent_20px.svg</file>
Expand Down
1 change: 0 additions & 1 deletion src/plugins/core/mainframe/aboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ AboutDialog::~AboutDialog()
void AboutDialog::setupUi()
{
DTitlebar *titleBar = new DTitlebar();
titleBar = new DTitlebar();
titleBar->setMenuVisible(false);
titleBar->setTitle(QString(tr("About Deepin Union Code")));

Expand Down
1 change: 0 additions & 1 deletion src/plugins/core/mainframe/plugindialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ PluginDialog::PluginDialog(QWidget *parent)
resize(1000, 600);

DTitlebar *titleBar = new DTitlebar();
titleBar = new DTitlebar();
titleBar->setMenuVisible(false);
titleBar->setTitle(QString(tr("Installed Plugins")));

Expand Down
Loading

0 comments on commit 871fede

Please sign in to comment.