mirror of
https://gitee.com/gfdgd-xi/deep-wine-runner
synced 2025-12-14 02:52:03 +08:00
优化对话框
This commit is contained in:
@@ -1,3 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="zh_CN"></TS>
|
||||
<TS version="2.1" language="zh_CN">
|
||||
<context>
|
||||
<name>MainWindow</name>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="14"/>
|
||||
<source>MainWindow</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="30"/>
|
||||
<source>浏览</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="37"/>
|
||||
<source>安装</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="mainwindow.ui" line="60"/>
|
||||
<source>1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QObject>
|
||||
#include <qtermwidget5/qtermwidget.h>
|
||||
#include <DMainWindow>
|
||||
using namespace Dtk::Widget;
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
class InstallDEB
|
||||
{
|
||||
|
||||
2
main.cpp
2
main.cpp
@@ -6,7 +6,7 @@
|
||||
#include <DMessageBox>
|
||||
#include <iostream>
|
||||
#include <DApplicationSettings>
|
||||
using namespace Dtk::Widget;
|
||||
DWIDGET_USE_NAMESPACE
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
||||
@@ -4,20 +4,42 @@
|
||||
#include "messagebox.h"
|
||||
#include <qtermwidget5/qtermwidget.h>
|
||||
#include <QMessageBox>
|
||||
#include <qapt/debfile.h>
|
||||
using namespace QApt;
|
||||
#include <QFile>
|
||||
#include <DTitlebar>
|
||||
#include <QDesktopServices>
|
||||
#include <DApplication>
|
||||
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <DMainWindow>
|
||||
using namespace Dtk::Widget;
|
||||
#include <qtermwidget5/qtermwidget.h>
|
||||
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
|
||||
|
||||
@@ -2,29 +2,65 @@
|
||||
#include <QGridLayout>
|
||||
#include <DLabel>
|
||||
#include <DPushButton>
|
||||
#include <DTitlebar>
|
||||
|
||||
|
||||
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("<img src=':/Icon/MessageBox/dialog-information.svg'>"));
|
||||
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("<img src='" + iconPath + "'>"));
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -4,14 +4,16 @@
|
||||
#include <DMainWindow>
|
||||
#include <QObject>
|
||||
#include <DWidget>
|
||||
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:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user