diff --git a/aptss-installer_zh_CN.ts b/aptss-installer_zh_CN.ts index 630fd35..aeca9fe 100644 --- a/aptss-installer_zh_CN.ts +++ b/aptss-installer_zh_CN.ts @@ -1,3 +1,27 @@ - + + + MainWindow + + + MainWindow + + + + + 浏览 + + + + + 安装 + + + + + 1 + + + + diff --git a/installdeb.h b/installdeb.h index 58b7ec9..b2250d2 100644 --- a/installdeb.h +++ b/installdeb.h @@ -4,7 +4,7 @@ #include #include #include -using namespace Dtk::Widget; +DWIDGET_USE_NAMESPACE class InstallDEB { diff --git a/main.cpp b/main.cpp index 8a3406e..c65206b 100644 --- a/main.cpp +++ b/main.cpp @@ -6,7 +6,7 @@ #include #include #include -using namespace Dtk::Widget; +DWIDGET_USE_NAMESPACE using namespace std; int main(int argc, char *argv[]) diff --git a/mainwindow.cpp b/mainwindow.cpp index 5fd9372..b64f38f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -4,20 +4,42 @@ #include "messagebox.h" #include #include -#include -using namespace QApt; +#include +#include +#include +#include MainWindow::MainWindow(QWidget *parent) : DMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); - /*MessageBox *message = new MessageBox(); - message->information("A", "B"); - this->close();*/ - //QApt::DebFile *a = new QApt::DebFile(); - //DebFile *abc = new DebFile("/tmp/apt_2.6.0-1deepin5_amd64.deb"); - //QMessageBox::information(this, "", abc->version()); + // 自定义标题栏 + DTitlebar *bar = this->titlebar(); + bar->setTitle("应用安装器"); + bar->setIcon(QIcon(":/Icon/deepin-wine-runner.svg")); + bar->setBackgroundTransparent(true); + QMenu *openProgramWebsite = bar->menu()->addMenu("项目地址"); + QAction *openProgramGitee = new QAction(DApplication::style()->standardIcon(QStyle::SP_DirLinkOpenIcon), "Gitee"); + QAction *openProgramGithub = new QAction("Github"); + QAction *openProgramSourceforge = new QAction("Sourceforge"); + openProgramWebsite->addAction(openProgramGitee); + openProgramWebsite->addAction(openProgramGithub); + openProgramWebsite->addAction(openProgramSourceforge); + connect(openProgramGitee, &QAction::triggered, this, [](){ + QDesktopServices::openUrl(QUrl("https://gitee.com/gfdgd-xi/deep-wine-runner")); + }); + connect(openProgramGithub, &QAction::triggered, this, [](){ + QDesktopServices::openUrl(QUrl("https://github.com/gfdgd-xi/deep-wine-runner")); + }); + connect(openProgramSourceforge, &QAction::triggered, this, [](){ + QDesktopServices::openUrl(QUrl("https://sourceforge.net/project/deep-wine-runner")); + }); + + terminal = new QTermWidget(0); + terminal->setColorScheme("DarkPastels"); + terminal->setAutoClose(0); + ui->gridLayout->addWidget(terminal, 1, 0); } MainWindow::~MainWindow() @@ -28,13 +50,21 @@ MainWindow::~MainWindow() void MainWindow::on_installPath_clicked() { - QTermWidget *terminal = new QTermWidget(0); - terminal->setColorScheme("DarkPastels"); - terminal->setAutoClose(1); + if(ui->debPath->text().replace(" ", "") == ""){ + MessageBox *message = new MessageBox(this); + message->critical("提示", "您没有输入 deb 包,无法继续"); + return; + } + if(!QFile::exists(ui->debPath->text())){ + MessageBox *message = new MessageBox(this); + message->critical("提示", "您选择的 deb 包不存在"); + return; + } InstallDEB *deb = new InstallDEB(terminal, this); deb->AddCommand("aptss update"); - deb->AddCommand("aptss install \"" + ui->debPath->text() + "\""); + deb->AddCommand("aptss install \"" + ui->debPath->text() + "\" -y"); deb->RunCommand(1); - ui->gridLayout->addWidget(terminal, 1, 0); + + } diff --git a/mainwindow.h b/mainwindow.h index fe4a233..c3bbcb5 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -2,7 +2,8 @@ #define MAINWINDOW_H #include -using namespace Dtk::Widget; +#include +DWIDGET_USE_NAMESPACE QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE @@ -19,6 +20,7 @@ private slots: void on_installPath_clicked(); private: + QTermWidget *terminal = new QTermWidget(0); Ui::MainWindow *ui; }; #endif // MAINWINDOW_H diff --git a/messagebox.cpp b/messagebox.cpp index 89c1245..8b4eb9a 100644 --- a/messagebox.cpp +++ b/messagebox.cpp @@ -2,29 +2,65 @@ #include #include #include +#include + MessageBox::MessageBox(DWidget *parent){ this->parent = parent; } -void MessageBox::information(QString title, QString text){ - DMainWindow *messageBox = new DMainWindow(this->parent); +void MessageBox::ShowMessageBox(QString iconPath, QString title, QString text){ + DMainWindow *messageBox = new DMainWindow(); DWidget *widget = new DWidget(); QGridLayout *layout = new QGridLayout(); DPushButton *ok = new DPushButton("确定"); QObject::connect(ok, &DPushButton::clicked, messageBox, [messageBox](){ messageBox->close(); }); - layout->addWidget(new DLabel("")); + DTitlebar *bar = messageBox->titlebar(); + bar->setTitle(title); + bar->setIcon(QIcon(":/Icon/deepin-wine-runner.svg")); + bar->setMenuVisible(false); + bar->setBackgroundTransparent(true); + layout->addWidget(new DLabel("")); layout->addWidget(new DLabel(text), 0, 1); layout->addWidget(ok, 1, 0, 1, 2); widget->setLayout(layout); - //messageBox->setEnableSystemResize(true); messageBox->setEnableBlurWindow(false); messageBox->setEnableSystemResize(false); messageBox->setWindowFlags(messageBox->windowFlags() &~ Qt::WindowMaximizeButtonHint &~ Qt::Dialog &~ Qt::WindowMinimizeButtonHint); messageBox->setCentralWidget(widget); messageBox->setWindowTitle(title); + // 设置窗口顶置 + messageBox->setWindowFlag(Qt::WindowStaysOnTopHint); messageBox->show(); messageBox->resize(messageBox->frameSize().width(), messageBox->frameSize().height()); + + //// 根据窗口信息获取中点 + // 获取窗口信息 + int parentWindowX = this->parent->frameGeometry().x(); + int parentWindowY = this->parent->frameGeometry().y(); + int parentWindowWidth = this->parent->frameGeometry().width(); + int parentWindowHeight = this->parent->frameGeometry().height(); + int messageBoxWidth = messageBox->frameSize().width(); + int messageBoxHeight = messageBox->frameSize().height(); + // 计算 X 坐标 + int x = parentWindowX + ((parentWindowWidth / 2) - (messageBoxWidth / 2)); + int y = parentWindowY + ((parentWindowHeight / 2) - (messageBoxHeight / 2)); + messageBox->move(x, y); + qDebug() << parentWindowX; + qDebug() << parentWindowY; + qDebug() << parentWindowWidth; + qDebug() << parentWindowHeight; + qDebug() << messageBoxWidth; + qDebug() << messageBoxHeight; + qDebug() << x << y; +} + +void MessageBox::information(QString title, QString text){ + ShowMessageBox(":/Icon/MessageBox/dialog-information.svg", title, text); +} + +void MessageBox::critical(QString title, QString text){ + ShowMessageBox(":/Icon/MessageBox/dialog-error.svg", title, text); } diff --git a/messagebox.h b/messagebox.h index ba9c3bd..d20fe0b 100644 --- a/messagebox.h +++ b/messagebox.h @@ -4,14 +4,16 @@ #include #include #include -using namespace Dtk::Widget; +DWIDGET_USE_NAMESPACE class MessageBox { //Q_OBJECT public: explicit MessageBox(DWidget *parent = nullptr); void information(QString title, QString text); + void critical(QString title, QString text); private: + void ShowMessageBox(QString iconPath, QString title, QString text); DWidget *parent; signals: