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"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!DOCTYPE TS>
|
<!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 <QObject>
|
||||||
#include <qtermwidget5/qtermwidget.h>
|
#include <qtermwidget5/qtermwidget.h>
|
||||||
#include <DMainWindow>
|
#include <DMainWindow>
|
||||||
using namespace Dtk::Widget;
|
DWIDGET_USE_NAMESPACE
|
||||||
|
|
||||||
class InstallDEB
|
class InstallDEB
|
||||||
{
|
{
|
||||||
|
|||||||
2
main.cpp
2
main.cpp
@@ -6,7 +6,7 @@
|
|||||||
#include <DMessageBox>
|
#include <DMessageBox>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <DApplicationSettings>
|
#include <DApplicationSettings>
|
||||||
using namespace Dtk::Widget;
|
DWIDGET_USE_NAMESPACE
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|||||||
@@ -4,20 +4,42 @@
|
|||||||
#include "messagebox.h"
|
#include "messagebox.h"
|
||||||
#include <qtermwidget5/qtermwidget.h>
|
#include <qtermwidget5/qtermwidget.h>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <qapt/debfile.h>
|
#include <QFile>
|
||||||
using namespace QApt;
|
#include <DTitlebar>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
#include <DApplication>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: DMainWindow(parent)
|
: DMainWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
/*MessageBox *message = new MessageBox();
|
// 自定义标题栏
|
||||||
message->information("A", "B");
|
DTitlebar *bar = this->titlebar();
|
||||||
this->close();*/
|
bar->setTitle("应用安装器");
|
||||||
//QApt::DebFile *a = new QApt::DebFile();
|
bar->setIcon(QIcon(":/Icon/deepin-wine-runner.svg"));
|
||||||
//DebFile *abc = new DebFile("/tmp/apt_2.6.0-1deepin5_amd64.deb");
|
bar->setBackgroundTransparent(true);
|
||||||
//QMessageBox::information(this, "", abc->version());
|
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()
|
MainWindow::~MainWindow()
|
||||||
@@ -28,13 +50,21 @@ MainWindow::~MainWindow()
|
|||||||
|
|
||||||
void MainWindow::on_installPath_clicked()
|
void MainWindow::on_installPath_clicked()
|
||||||
{
|
{
|
||||||
QTermWidget *terminal = new QTermWidget(0);
|
if(ui->debPath->text().replace(" ", "") == ""){
|
||||||
terminal->setColorScheme("DarkPastels");
|
MessageBox *message = new MessageBox(this);
|
||||||
terminal->setAutoClose(1);
|
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);
|
InstallDEB *deb = new InstallDEB(terminal, this);
|
||||||
deb->AddCommand("aptss update");
|
deb->AddCommand("aptss update");
|
||||||
deb->AddCommand("aptss install \"" + ui->debPath->text() + "\"");
|
deb->AddCommand("aptss install \"" + ui->debPath->text() + "\" -y");
|
||||||
deb->RunCommand(1);
|
deb->RunCommand(1);
|
||||||
ui->gridLayout->addWidget(terminal, 1, 0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <DMainWindow>
|
#include <DMainWindow>
|
||||||
using namespace Dtk::Widget;
|
#include <qtermwidget5/qtermwidget.h>
|
||||||
|
DWIDGET_USE_NAMESPACE
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui { class MainWindow; }
|
namespace Ui { class MainWindow; }
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
@@ -19,6 +20,7 @@ private slots:
|
|||||||
void on_installPath_clicked();
|
void on_installPath_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QTermWidget *terminal = new QTermWidget(0);
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
@@ -2,29 +2,65 @@
|
|||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <DLabel>
|
#include <DLabel>
|
||||||
#include <DPushButton>
|
#include <DPushButton>
|
||||||
|
#include <DTitlebar>
|
||||||
|
|
||||||
|
|
||||||
MessageBox::MessageBox(DWidget *parent){
|
MessageBox::MessageBox(DWidget *parent){
|
||||||
this->parent = parent;
|
this->parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageBox::information(QString title, QString text){
|
void MessageBox::ShowMessageBox(QString iconPath, QString title, QString text){
|
||||||
DMainWindow *messageBox = new DMainWindow(this->parent);
|
DMainWindow *messageBox = new DMainWindow();
|
||||||
DWidget *widget = new DWidget();
|
DWidget *widget = new DWidget();
|
||||||
QGridLayout *layout = new QGridLayout();
|
QGridLayout *layout = new QGridLayout();
|
||||||
DPushButton *ok = new DPushButton("确定");
|
DPushButton *ok = new DPushButton("确定");
|
||||||
QObject::connect(ok, &DPushButton::clicked, messageBox, [messageBox](){
|
QObject::connect(ok, &DPushButton::clicked, messageBox, [messageBox](){
|
||||||
messageBox->close();
|
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(new DLabel(text), 0, 1);
|
||||||
layout->addWidget(ok, 1, 0, 1, 2);
|
layout->addWidget(ok, 1, 0, 1, 2);
|
||||||
widget->setLayout(layout);
|
widget->setLayout(layout);
|
||||||
//messageBox->setEnableSystemResize(true);
|
|
||||||
messageBox->setEnableBlurWindow(false);
|
messageBox->setEnableBlurWindow(false);
|
||||||
messageBox->setEnableSystemResize(false);
|
messageBox->setEnableSystemResize(false);
|
||||||
messageBox->setWindowFlags(messageBox->windowFlags() &~ Qt::WindowMaximizeButtonHint &~ Qt::Dialog &~ Qt::WindowMinimizeButtonHint);
|
messageBox->setWindowFlags(messageBox->windowFlags() &~ Qt::WindowMaximizeButtonHint &~ Qt::Dialog &~ Qt::WindowMinimizeButtonHint);
|
||||||
messageBox->setCentralWidget(widget);
|
messageBox->setCentralWidget(widget);
|
||||||
messageBox->setWindowTitle(title);
|
messageBox->setWindowTitle(title);
|
||||||
|
// 设置窗口顶置
|
||||||
|
messageBox->setWindowFlag(Qt::WindowStaysOnTopHint);
|
||||||
messageBox->show();
|
messageBox->show();
|
||||||
messageBox->resize(messageBox->frameSize().width(), messageBox->frameSize().height());
|
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 <DMainWindow>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <DWidget>
|
#include <DWidget>
|
||||||
using namespace Dtk::Widget;
|
DWIDGET_USE_NAMESPACE
|
||||||
class MessageBox
|
class MessageBox
|
||||||
{
|
{
|
||||||
//Q_OBJECT
|
//Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit MessageBox(DWidget *parent = nullptr);
|
explicit MessageBox(DWidget *parent = nullptr);
|
||||||
void information(QString title, QString text);
|
void information(QString title, QString text);
|
||||||
|
void critical(QString title, QString text);
|
||||||
private:
|
private:
|
||||||
|
void ShowMessageBox(QString iconPath, QString title, QString text);
|
||||||
DWidget *parent;
|
DWidget *parent;
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user