Skip to content

Commit

Permalink
feat: DTK-Changed binarytools-plugin
Browse files Browse the repository at this point in the history
DTK-Changed binarytools-plugin
  • Loading branch information
JWWTSL authored and deepin-mozart committed Nov 27, 2023
1 parent d3ac443 commit 025acb4
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 78 deletions.
121 changes: 62 additions & 59 deletions src/plugins/binarytools/mainframe/binarytoolsconfigview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@
#include "common/util/custompaths.h"
#include "common/dialog/contextdialog.h"

#include <QComboBox>
#include <QPushButton>
#include <QLineEdit>
#include <QFileDialog>
#include <DWidget>
#include <DComboBox>
#include <DPushButton>
#include <DLineEdit>
#include <DFileDialog>
#include <DLabel>
#include <DScrollArea>

#include <QFont>
#include <QInputDialog>
#include <qmessagebox.h>
#include <QGridLayout>
#include <QLabel>
#include <QStandardPaths>
#include <QScrollArea>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
Expand All @@ -29,26 +31,27 @@ static QString CURRENT_COMMAND = "Current command";
static QString ALL_COMMAND = "All command";
static QString ENVIRONMENT = "Environment";

DWIDGET_USE_NAMESPACE
class BinaryToolsConfigViewPrivate
{
friend class BinaryToolsConfigView;

QGridLayout *gridLayout = nullptr;
QWidget *compatConfigWidget = nullptr;
QComboBox *runComandCombo = nullptr;
QLineEdit *toolArgsEdit = nullptr;
DWidget *compatConfigWidget = nullptr;
DComboBox *runComandCombo = nullptr;
DLineEdit *toolArgsEdit = nullptr;
QDialog *combinationDialog = nullptr;
QLabel *commandCombination = nullptr;
QLabel *nameLabel = nullptr;
QLabel *commandLabel = nullptr;
QLineEdit *executableDirEdit = nullptr;
QLineEdit *workingDirEdit = nullptr;
DLabel *commandCombination = nullptr;
DLabel *nameLabel = nullptr;
DLabel *commandLabel = nullptr;
DLineEdit *executableDirEdit = nullptr;
DLineEdit *workingDirEdit = nullptr;
EnvironmentView *envView = nullptr;
QPushButton *addButton = nullptr;
QPushButton *deleteButton = nullptr;
QPushButton *renameButton = nullptr;
QPushButton *combineButton = nullptr;
QPushButton *useCombinationButton = nullptr;
DPushButton *addButton = nullptr;
DPushButton *deleteButton = nullptr;
DPushButton *renameButton = nullptr;
DPushButton *combineButton = nullptr;
DPushButton *useCombinationButton = nullptr;
BinaryToolsSetting *settings = nullptr;
QList<QString> programList;
QList<QStringList> argsList;
Expand All @@ -60,23 +63,23 @@ BinaryToolsConfigView::BinaryToolsConfigView(QWidget *parent)
: QWidget(parent)
, d(new BinaryToolsConfigViewPrivate)
{
d->compatConfigWidget = new QWidget(this);
d->nameLabel = new QLabel();
d->compatConfigWidget = new DWidget(this);
d->nameLabel = new DLabel();

d->runComandCombo = new QComboBox(this);
d->runComandCombo = new DComboBox(this);
d->runComandCombo->setMinimumContentsLength(15);
d->runComandCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
d->runComandCombo->setSizeAdjustPolicy(DComboBox::AdjustToContents);

d->addButton = new QPushButton(tr("Add"), this);
d->deleteButton = new QPushButton(tr("Delete"), this);
d->renameButton = new QPushButton(tr("Rename"), this);
d->combineButton = new QPushButton(tr("Combine"), this);
d->addButton = new DPushButton(tr("Add"), this);
d->deleteButton = new DPushButton(tr("Delete"), this);
d->renameButton = new DPushButton(tr("Rename"), this);
d->combineButton = new DPushButton(tr("Combine"), this);

d->gridLayout = new QGridLayout(this);
d->gridLayout->setSpacing(6);
d->gridLayout->setContentsMargins(10, 10, 10, 10);

auto configLabel = new QLabel(this);
auto configLabel = new DLabel(this);
configLabel->setText(tr("Binary configuration:"));

d->gridLayout->addWidget(configLabel, 0, 0, 1, 1);
Expand All @@ -90,8 +93,8 @@ BinaryToolsConfigView::BinaryToolsConfigView(QWidget *parent)
setConfigWidget();

d->combinationDialog = new QDialog(this);
d->commandCombination = new QLabel(tr("command combination:"), d->combinationDialog);
d->useCombinationButton = new QPushButton(tr("Use Combination Command"), d->combinationDialog);
d->commandCombination = new DLabel(tr("command combination:"), d->combinationDialog);
d->useCombinationButton = new DPushButton(tr("Use Combination Command"), d->combinationDialog);
initializeCombinationDialog();

if (!d->settings) {
Expand All @@ -107,19 +110,19 @@ BinaryToolsConfigView::BinaryToolsConfigView(QWidget *parent)
}
readConfig();

connect(d->runComandCombo, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
connect(d->runComandCombo, static_cast<void (DComboBox::*)(const QString &)>(&DComboBox::currentIndexChanged),
this, &BinaryToolsConfigView::currentConfigChanged);

connect(d->addButton, &QPushButton::clicked,
connect(d->addButton, &DPushButton::clicked,
this, &BinaryToolsConfigView::addCompatConfig);

connect(d->deleteButton, &QPushButton::clicked,
connect(d->deleteButton, &DPushButton::clicked,
this, &BinaryToolsConfigView::deleteCompatConfig);

connect(d->renameButton, &QPushButton::clicked,
connect(d->renameButton, &DPushButton::clicked,
this, &BinaryToolsConfigView::renameCompatConfig);

connect(d->combineButton, &QPushButton::clicked,
connect(d->combineButton, &DPushButton::clicked,
this, &BinaryToolsConfigView::combineCompatConfig);
}

Expand Down Expand Up @@ -274,7 +277,7 @@ void BinaryToolsConfigView::initializeCombinationDialog()
gridLayout->setContentsMargins(30, 30, 30, 30);
gridLayout->addWidget(d->commandCombination, 0, 0, 1, 2);
gridLayout->addWidget(d->useCombinationButton, 1, 1, 1, 1);
QObject::connect(d->useCombinationButton, &QPushButton::clicked, [=](){
QObject::connect(d->useCombinationButton, &DPushButton::clicked, [=](){
d->combinationDialog->close();
emit useCombinationCommand();
});
Expand Down Expand Up @@ -386,33 +389,33 @@ void BinaryToolsConfigView::setConfigWidget()
{
d->compatConfigWidget->setContentsMargins(0, 0, 0, 0);
d->compatConfigWidget->setAutoFillBackground(true);
auto cmdLabel = new QLabel(d->compatConfigWidget);
auto cmdLabel = new DLabel(d->compatConfigWidget);
QFont ft;
ft.setBold(true);
cmdLabel->setFont(ft);
cmdLabel->setText(tr("Command:"));
d->commandLabel = new QLabel(d->compatConfigWidget);
d->commandLabel = new DLabel(d->compatConfigWidget);

auto argsLabel = new QLabel(d->compatConfigWidget);
auto argsLabel = new DLabel(d->compatConfigWidget);
argsLabel->setText(tr("Tool arguments:"));
d->toolArgsEdit = new QLineEdit(d->compatConfigWidget);
d->toolArgsEdit = new DLineEdit(d->compatConfigWidget);
d->toolArgsEdit->setPlaceholderText(tr("Input your arguments."));

auto exeLabel = new QLabel(d->compatConfigWidget);
auto exeLabel = new DLabel(d->compatConfigWidget);
exeLabel->setText(tr("Executable:"));
d->executableDirEdit = new QLineEdit(d->compatConfigWidget);
auto browseButton1 = new QPushButton(tr("Browse..."), d->compatConfigWidget);
d->executableDirEdit = new DLineEdit(d->compatConfigWidget);
auto browseButton1 = new DPushButton(tr("Browse..."), d->compatConfigWidget);

auto workLabel = new QLabel(d->compatConfigWidget);
auto workLabel = new DLabel(d->compatConfigWidget);
workLabel->setText(tr("Working directory:"));
d->workingDirEdit = new QLineEdit(d->compatConfigWidget);
auto browseButton2 = new QPushButton(tr("Browse..."), d->compatConfigWidget);
d->workingDirEdit = new DLineEdit(d->compatConfigWidget);
auto browseButton2 = new DPushButton(tr("Browse..."), d->compatConfigWidget);

auto envLabel = new QLabel(d->compatConfigWidget);
auto envLabel = new DLabel(d->compatConfigWidget);
envLabel->setText(tr("Envrioment: Base environment for this command configuration."));
auto appendButton = new QPushButton(tr("&Append"), d->compatConfigWidget);
auto deleteButton = new QPushButton(tr("&Delete"), d->compatConfigWidget);
auto resetButton = new QPushButton(tr("&Reset"), d->compatConfigWidget);
auto appendButton = new DPushButton(tr("&Append"), d->compatConfigWidget);
auto deleteButton = new DPushButton(tr("&Delete"), d->compatConfigWidget);
auto resetButton = new DPushButton(tr("&Reset"), d->compatConfigWidget);
deleteButton->setEnabled(false);
d->envView = new EnvironmentView();
d->envView->setFixedHeight(250);
Expand All @@ -438,31 +441,31 @@ void BinaryToolsConfigView::setConfigWidget()
gridLayout->addWidget(d->envView, 5, 1, 5, 2);
d->compatConfigWidget->setLayout(gridLayout);

connect(browseButton1, &QPushButton::clicked, [=]() {
connect(browseButton1, &DPushButton::clicked, [=]() {
QString dir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
QString filePath = QFileDialog::getOpenFileName(nullptr, tr("Select Executabel Path"), dir);
QString filePath = DFileDialog::getOpenFileName(nullptr, tr("Select Executabel Path"), dir);
if (filePath.isEmpty() && !QFileInfo(filePath).exists())
return;
d->executableDirEdit->setText(filePath);
});

connect(browseButton2, &QPushButton::clicked, [=]() {
connect(browseButton2, &DPushButton::clicked, [=]() {
QString dir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
QString filePath = QFileDialog::getExistingDirectory(nullptr, tr("Select Working Directory"), dir);
QString filePath = DFileDialog::getExistingDirectory(nullptr, tr("Select Working Directory"), dir);
if (filePath.isEmpty() && !QFileInfo(filePath).exists())
return;
d->workingDirEdit->setText(filePath);
});

connect(appendButton, &QPushButton::clicked, d->envView, &EnvironmentView::appendRow);
connect(deleteButton, &QPushButton::clicked, d->envView, &EnvironmentView::deleteRow);
connect(resetButton, &QPushButton::clicked, d->envView, &EnvironmentView::initModel);
connect(appendButton, &DPushButton::clicked, d->envView, &EnvironmentView::appendRow);
connect(deleteButton, &DPushButton::clicked, d->envView, &EnvironmentView::deleteRow);
connect(resetButton, &DPushButton::clicked, d->envView, &EnvironmentView::initModel);

connect(d->toolArgsEdit, &QLineEdit::textChanged, [=](){
connect(d->toolArgsEdit, &DLineEdit::textChanged, [=](){
d->commandLabel->setText(d->executableDirEdit->text() + " " + d->toolArgsEdit->text());
});

connect(d->executableDirEdit, &QLineEdit::textChanged, [=](){
connect(d->executableDirEdit, &DLineEdit::textChanged, [=](){
d->commandLabel->setText(d->executableDirEdit->text() + " " + d->toolArgsEdit->text());
});

Expand Down
28 changes: 15 additions & 13 deletions src/plugins/binarytools/mainframe/binarytoolsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
#include "binarytoolsconfigview.h"
#include "common/util/eventdefinitions.h"

#include <QPushButton>
#include <QDialogButtonBox>
#include <DPushButton>
#include <DDialogButtonBox>

#include <QProcess>
#include <QBoxLayout>
#include <QTextBlock>

DWIDGET_USE_NAMESPACE
class BinaryToolsDialogPrivate
{
friend class BinaryToolsDialog;
BinaryToolsConfigView *configView = nullptr;
QDialogButtonBox *buttons = nullptr;
DDialogButtonBox *buttons = nullptr;
};

BinaryToolsDialog::BinaryToolsDialog(QDialog *parent)
Expand All @@ -34,12 +36,12 @@ BinaryToolsDialog::BinaryToolsDialog(QDialog *parent)
vLayout->addStretch();

QHBoxLayout * buttonLayout = new QHBoxLayout();
d->buttons = new QDialogButtonBox(this);
d->buttons->setStandardButtons(QDialogButtonBox::Apply | QDialogButtonBox::Save | QDialogButtonBox::Cancel);
d->buttons->button(QDialogButtonBox::Apply)->setText(tr("Use Tool"));
d->buttons->button(QDialogButtonBox::Save)->setText(tr("Save"));
d->buttons->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
d->buttons->button(QDialogButtonBox::Apply)->setDefault(true);
d->buttons = new DDialogButtonBox(this);
d->buttons->setStandardButtons(DDialogButtonBox::Apply | DDialogButtonBox::Save | DDialogButtonBox::Cancel);
d->buttons->button(DDialogButtonBox::Apply)->setText(tr("Use Tool"));
d->buttons->button(DDialogButtonBox::Save)->setText(tr("Save"));
d->buttons->button(DDialogButtonBox::Cancel)->setText(tr("Cancel"));
d->buttons->button(DDialogButtonBox::Apply)->setDefault(true);
buttonLayout->addWidget(d->buttons);
vLayout->addLayout(buttonLayout);

Expand All @@ -48,14 +50,14 @@ BinaryToolsDialog::BinaryToolsDialog(QDialog *parent)
useClicked();
});
});
connect(d->buttons->button(QDialogButtonBox::Apply), &QPushButton::clicked, [=](){
connect(d->buttons->button(DDialogButtonBox::Apply), &DPushButton::clicked, [=](){
QtConcurrent::run([=](){
useClicked();
});
});
connect(d->buttons->button(QDialogButtonBox::Save), &QPushButton::clicked, this, &BinaryToolsDialog::saveClicked);
connect(d->buttons, &QDialogButtonBox::rejected, this, &BinaryToolsDialog::reject);
connect(d->buttons, &QDialogButtonBox::accepted, this, &BinaryToolsDialog::accept);
connect(d->buttons->button(DDialogButtonBox::Save), &DPushButton::clicked, this, &BinaryToolsDialog::saveClicked);
connect(d->buttons, &DDialogButtonBox::rejected, this, &BinaryToolsDialog::reject);
connect(d->buttons, &DDialogButtonBox::accepted, this, &BinaryToolsDialog::accept);
}

BinaryToolsDialog::~BinaryToolsDialog()
Expand Down
15 changes: 9 additions & 6 deletions src/plugins/binarytools/mainframe/environmentview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

#include "environmentview.h"

#include <DTableView>
#include <DCheckBox>
#include <DHeaderView>

#include <QVBoxLayout>
#include <QCheckBox>
#include <QHeaderView>
#include <QTableView>
#include <QProcessEnvironment>

DWIDGET_USE_NAMESPACE
class EnvironmentModelPrivate
{
friend class EnvironmentModel;
Expand Down Expand Up @@ -141,7 +144,7 @@ class EnvironmentViewPrivate
friend class EnvironmentView;

QVBoxLayout *vLayout = nullptr;
QTableView *tableView = nullptr;
DTableView *tableView = nullptr;
EnvironmentModel *model = nullptr;
};

Expand All @@ -156,10 +159,10 @@ EnvironmentView::EnvironmentView(QWidget *parent)
this->setLayout(d->vLayout);

if (!d->tableView) {
d->tableView = new QTableView();
d->tableView = new DTableView();
d->tableView->setShowGrid(false);
QHeaderView* headerView = d->tableView->horizontalHeader();
headerView->setSectionResizeMode(QHeaderView::ResizeToContents);
DHeaderView* headerView = d->tableView->horizontalHeader();
headerView->setSectionResizeMode(DHeaderView::ResizeToContents);
d->tableView->verticalHeader()->hide();
d->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
d->tableView->setSelectionBehavior(QAbstractItemView::SelectItems);
Expand Down

0 comments on commit 025acb4

Please sign in to comment.