Skip to content

Commit

Permalink
feat: DTK Change-Mainwindow and menu
Browse files Browse the repository at this point in the history
DTK Change-Mainwindow and menu.
  • Loading branch information
N0rthHXD authored and deepin-mozart committed Nov 13, 2023
1 parent 7e19f91 commit 934f4fa
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 71 deletions.
53 changes: 36 additions & 17 deletions src/plugins/core/mainframe/windowkeeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "aboutdialog.h"
#include "plugindialog.h"
#include "mainwindow.h"

#include "windowkeeper.h"
#include "windowstatusbar.h"
Expand Down Expand Up @@ -66,43 +65,46 @@ void WindowKeeper::createFileActions(DMenu *menu)
});

menu->addAction(actionOpenFile);

DMenu* menuOpenProject = new DMenu(MWMFA_OPEN_PROJECT);
menu->addMenu(menuOpenProject);
}

void WindowKeeper::createAnalyzeActions(DMenuBar *menuBar)
void WindowKeeper::createAnalyzeActions(DMenu *menu)
{
qInfo() << __FUNCTION__;
DMenu* analyzeMenu = new DMenu();
QAction* buildAction = menuBar->addMenu(analyzeMenu);
QAction* buildAction = menu->addMenu(analyzeMenu);
buildAction->setText(MWM_ANALYZE);
}

void WindowKeeper::createBuildActions(DMenuBar *menuBar)
void WindowKeeper::createBuildActions(DMenu *menu)
{
qInfo() << __FUNCTION__;
DMenu* buildMenu = new DMenu();
QAction* buildAction = menuBar->addMenu(buildMenu);
QAction* buildAction = menu->addMenu(buildMenu);
buildAction->setText(MWM_BUILD);
}

void WindowKeeper::createDebugActions(DMenuBar *menuBar)
void WindowKeeper::createDebugActions(DMenu *menu)
{
qInfo() << __FUNCTION__;
QAction* debugAction = menuBar->addMenu(new DMenu());
QAction* debugAction = menu->addMenu(new DMenu());
debugAction->setText(MWM_DEBUG);
}

void WindowKeeper::createToolsActions(DMenuBar *menuBar)
void WindowKeeper::createToolsActions(DMenu *menu)
{
qInfo() << __FUNCTION__;
auto toolsMenu = new DMenu(MWM_TOOLS);
menuBar->addMenu(toolsMenu);
menu->addMenu(toolsMenu);
}

void WindowKeeper::createHelpActions(DMenuBar *menuBar)
void WindowKeeper::createHelpActions(DMenu *menu)
{
qInfo() << __FUNCTION__;
auto helpMenu = new DMenu(MWM_HELP);
menuBar->addMenu(helpMenu);
menu->addMenu(helpMenu);

QAction *actionReportBug = new QAction(MWM_REPORT_BUG);
ActionManager::getInstance()->registerAction(actionReportBug, "Help.Report.Bug",
Expand Down Expand Up @@ -185,9 +187,17 @@ void WindowKeeper::createMainMenu(DMenu *menu)
return;

createFileActions(menu);
menu->addSeparator();

DMenu* menuOpenProject = new DMenu(MWMFA_OPEN_PROJECT);
menu->addMenu(menuOpenProject);
createBuildActions(menu);
createDebugActions(menu);
menu->addSeparator();

createAnalyzeActions(menu);
createToolsActions(menu);
menu->addSeparator();

createHelpActions(menu);
}

void WindowKeeper::layoutWindow(DMainWindow *window)
Expand Down Expand Up @@ -343,15 +353,15 @@ void WindowKeeper::addMenu(AbstractMenu *menu)
return;

//始终将Helper置末
for (QAction *action : d->window->menuBar()->actions()) {
if (action->text() == MWM_HELP) {
d->window->menuBar()->insertMenu(action, inputMenu);
for (QAction *action : d->mainMenu->actions()) {
if (action->text() == MWM_TOOLS) {

Check warning on line 357 in src/plugins/core/mainframe/windowkeeper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Consider using std::find_if algorithm instead of a raw loop.
d->mainMenu->insertMenu(action, inputMenu);
return; //提前返回
}
}

//直接添加到最后
d->window->menuBar()->addMenu(inputMenu);
d->mainMenu->addMenu(inputMenu);
}

void WindowKeeper::insertAction(const QString &menuName,
Expand Down Expand Up @@ -385,6 +395,15 @@ void WindowKeeper::addAction(const QString &menuName, AbstractAction *action)
if (!action || !inputAction)

Check warning on line 395 in src/plugins/core/mainframe/windowkeeper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Either the condition '!action' is redundant or there is possible null pointer dereference: action.
return;

if (inputAction->text() == MWMFA_NEW_FILE_OR_PROJECT) {
for (QAction *qAction : d->mainMenu->actions()) {
if (qAction->text() == MWM_BUILD) {

Check warning on line 400 in src/plugins/core/mainframe/windowkeeper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Consider using std::find_if algorithm instead of a raw loop.
d->mainMenu->insertAction(qAction, inputAction);
return;
}
}
}

for (QAction *qAction : d->mainMenu->actions()) {
if (qAction->text() == menuName) {
if (qAction->text() == MWM_FILE) {
Expand Down
12 changes: 7 additions & 5 deletions src/plugins/core/mainframe/windowkeeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ private :
void createNavEdit(DToolBar *toolbar);
void createNavRecent(DToolBar *toolbar);
void createStatusBar(DMainWindow *window);
void createHelpActions(DMenuBar *menuBar);
void createToolsActions(DMenuBar *menuBar);
void createDebugActions(DMenuBar *menuBar);
void createBuildActions(DMenuBar *menuBar);

void createHelpActions(DMenu *menu);
void createToolsActions(DMenu *menu);
void createDebugActions(DMenu *menu);
void createBuildActions(DMenu *menu);
void createFileActions(DMenu *menu);
void createAnalyzeActions(DMenuBar *menuBar);
void createAnalyzeActions(DMenu *menu);

void setNavActionChecked(const QString &actionName, bool checked);

void createMainMenu(DMenu *mainMenu);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/template/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ target_link_libraries(${PROJECT_NAME}
common
${QtUseModules}
${PkgUserModules}
${DtkWidget_LIBRARIES}
)

install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH})
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/template/templatemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ void TemplateManager::addMenu()
auto actionInit = [&](QAction *action, QString actionID, QKeySequence key, QString iconFileName){
ActionManager::getInstance()->registerAction(action, actionID, action->text(), key, iconFileName);
AbstractAction *actionImpl = new AbstractAction(action);
windowService->addAction(dpfservice::MWM_FILE, actionImpl);
windowService->addAction(dpfservice::MWMFA_NEW_FILE_OR_PROJECT, actionImpl);
};

d->newAction.reset(new QAction(MWMFA_NEW_FILE_OR_PROJECT));
actionInit(d->newAction.get(),
"Fiel.New.FileOrProject",
QKeySequence(Qt::Modifier::CTRL | Qt::Modifier::SHIFT | Qt::Key::Key_O), ":/template/images/new_project.png");
QKeySequence(Qt::Modifier::CTRL | Qt::Modifier::SHIFT | Qt::Key::Key_O), QString());
QObject::connect(d->newAction.get(), &QAction::triggered,
this, &TemplateManager::newWizard, Qt::DirectConnection);
}
Expand Down
43 changes: 23 additions & 20 deletions src/plugins/template/wizard/detailwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,61 @@

#include "common/util/custompaths.h"

#include <QLabel>
#include <DLabel>
#include <DComboBox>
#include <DPushButton>
#include <DMessageBox>
#include <DFileDialog>
#include <DLineEdit>

#include <QVBoxLayout>
#include <QPainter>
#include <QLineEdit>
#include <QComboBox>
#include <QPushButton>
#include <QFileDialog>
#include <QMessageBox>

DWIDGET_USE_NAMESPACE

class DetailWidgetPrivate
{
friend class DetailWidget;

QString templatePath;
QMap<QString, QLineEdit*> lineEditMap;
QMap<QString, QComboBox*> comboBoxMap;
QMap<QString, DLineEdit*> lineEditMap;
QMap<QString, DComboBox*> comboBoxMap;
WizardInfo wizardInfo;
};

DetailWidget::DetailWidget(QWidget *parent)
: QScrollArea(parent)
: DScrollArea(parent)
, d(new DetailWidgetPrivate())
{

}

DetailWidget::DetailWidget(const QString &templatePath, QWidget *parent)
: QScrollArea(parent)
: DScrollArea(parent)
, d(new DetailWidgetPrivate())
{
d->templatePath = templatePath;
if (!TemplateParser::readWizardConfig(d->templatePath, d->wizardInfo))
return;

QWidget *widget = new QWidget();
DWidget *widget = new DWidget();
QVBoxLayout *vLayout = new QVBoxLayout();
widget->setLayout(vLayout);

QLabel *titleLabel = new QLabel(d->wizardInfo.trDisplayName);
DLabel *titleLabel = new DLabel(d->wizardInfo.trDisplayName);
vLayout->addWidget(titleLabel);
vLayout->addSpacing(10);

auto iter = d->wizardInfo.configures.begin();
for (; iter != d->wizardInfo.configures.end(); ++iter) {
QHBoxLayout *hLayout = new QHBoxLayout();
QLabel *label = new QLabel(iter->displayName + ":");
DLabel *label = new DLabel(iter->displayName + ":");
label->setFixedSize(120, 30);
hLayout->addWidget(label, 0, Qt::AlignLeft);
hLayout->setStretchFactor(label, 1);

if ("lineEdit" == iter->type) {
QLineEdit *lineEdit = new QLineEdit();
DLineEdit *lineEdit = new DLineEdit();
if (!iter->defaultValues.isEmpty()) {
lineEdit->setText(iter->defaultValues.at(0));
}
Expand All @@ -68,15 +71,15 @@ DetailWidget::DetailWidget(const QString &templatePath, QWidget *parent)
d->lineEditMap.insert(iter->key, lineEdit);
if (iter->browse) {
lineEdit->setFixedSize(300, 30);
lineEdit->setReadOnly(true);
lineEdit->lineEdit()->setReadOnly(true);

QPushButton *browse = new QPushButton(tr("Browse..."));
DPushButton *browse = new DPushButton(tr("Browse..."));
browse->setFixedSize(100, 30);
hLayout->addWidget(browse, 0, Qt::AlignRight);
hLayout->setStretchFactor(browse, 1);

connect(browse, &QPushButton::clicked, [=]() {
QString path = QFileDialog::getExistingDirectory(this, tr("Choose path"), QDir::homePath());
connect(browse, &DPushButton::clicked, [=]() {
QString path = DFileDialog::getExistingDirectory(this, tr("Choose path"), QDir::homePath());
if (!path.isEmpty()) {
lineEdit->setText(path);
}
Expand All @@ -85,7 +88,7 @@ DetailWidget::DetailWidget(const QString &templatePath, QWidget *parent)
lineEdit->setFixedSize(400, 30);
}
} else if ("comboBox" == iter->type) {
QComboBox *comboBox = new QComboBox();
DComboBox *comboBox = new DComboBox();
comboBox->setFixedSize(400, 30);
hLayout->addWidget(comboBox, 0, Qt::AlignLeft);
hLayout->setStretchFactor(comboBox, 3);
Expand Down Expand Up @@ -115,7 +118,7 @@ bool DetailWidget::getGenParams(PojectGenParam &param)
auto lineEdit = d->lineEditMap.value(key);

if (lineEdit->text().trimmed().isEmpty()) {
QMessageBox::critical(this, "tip", "The value of " + key + " is empty");
DMessageBox::critical(this, "tip", "The value of " + key + " is empty");
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/template/wizard/detailwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

#include "projectgenerate.h"

#include <QScrollArea>
#include <DScrollArea>

using namespace templateMgr;

class DetailWidgetPrivate;
class DetailWidget : public QScrollArea
class DetailWidget : public DTK_WIDGET_NAMESPACE::DScrollArea
{
Q_OBJECT
public:
Expand Down
Loading

0 comments on commit 934f4fa

Please sign in to comment.