From ea4e1d5da7635c4037df26fbf101e61f7f4f5c8a Mon Sep 17 00:00:00 2001 From: gfdgd_xi <3025613752@qq.com> Date: Mon, 22 Jan 2024 22:51:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8DTK=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Icon/MessageBox/dialog-apply.svg | 15 +++++++++++++ Icon/MessageBox/dialog-cancel.svg | 15 +++++++++++++ Icon/MessageBox/dialog-error.svg | 15 +++++++++++++ Icon/MessageBox/dialog-information.svg | 15 +++++++++++++ Icon/MessageBox/dialog-ok.svg | 14 ++++++++++++ Icon/MessageBox/dialog-question.svg | 15 +++++++++++++ Icon/MessageBox/dialog-warning.svg | 15 +++++++++++++ Resources.qrc | 11 ++++++++++ aptss-installer.pro | 12 ++++++++--- main.cpp | 5 +++-- mainwindow.cpp | 13 ++++++++--- mainwindow.h | 6 +++--- mainwindow.ui | 5 +++++ messagebox.cpp | 30 ++++++++++++++++++++++++++ messagebox.h | 20 +++++++++++++++++ 15 files changed, 195 insertions(+), 11 deletions(-) create mode 100644 Icon/MessageBox/dialog-apply.svg create mode 100644 Icon/MessageBox/dialog-cancel.svg create mode 100644 Icon/MessageBox/dialog-error.svg create mode 100644 Icon/MessageBox/dialog-information.svg create mode 100644 Icon/MessageBox/dialog-ok.svg create mode 100644 Icon/MessageBox/dialog-question.svg create mode 100644 Icon/MessageBox/dialog-warning.svg create mode 100644 Resources.qrc create mode 100644 messagebox.cpp create mode 100644 messagebox.h diff --git a/Icon/MessageBox/dialog-apply.svg b/Icon/MessageBox/dialog-apply.svg new file mode 100644 index 0000000..3a1ab0b --- /dev/null +++ b/Icon/MessageBox/dialog-apply.svg @@ -0,0 +1,15 @@ + + + + dialog-apply + Created with Sketch. + + + + + + + + + + \ No newline at end of file diff --git a/Icon/MessageBox/dialog-cancel.svg b/Icon/MessageBox/dialog-cancel.svg new file mode 100644 index 0000000..91bd21f --- /dev/null +++ b/Icon/MessageBox/dialog-cancel.svg @@ -0,0 +1,15 @@ + + + + dialog-cancel + Created with Sketch. + + + + + + + + + + \ No newline at end of file diff --git a/Icon/MessageBox/dialog-error.svg b/Icon/MessageBox/dialog-error.svg new file mode 100644 index 0000000..998f48a --- /dev/null +++ b/Icon/MessageBox/dialog-error.svg @@ -0,0 +1,15 @@ + + + + dialog-error + Created with Sketch. + + + + + + + + + + \ No newline at end of file diff --git a/Icon/MessageBox/dialog-information.svg b/Icon/MessageBox/dialog-information.svg new file mode 100644 index 0000000..0d5ad3f --- /dev/null +++ b/Icon/MessageBox/dialog-information.svg @@ -0,0 +1,15 @@ + + + + dialog-information + Created with Sketch. + + + + + + + + + + \ No newline at end of file diff --git a/Icon/MessageBox/dialog-ok.svg b/Icon/MessageBox/dialog-ok.svg new file mode 100644 index 0000000..970e68c --- /dev/null +++ b/Icon/MessageBox/dialog-ok.svg @@ -0,0 +1,14 @@ + + + + dialog-ok + Created with Sketch. + + + + + + + + + \ No newline at end of file diff --git a/Icon/MessageBox/dialog-question.svg b/Icon/MessageBox/dialog-question.svg new file mode 100644 index 0000000..611355c --- /dev/null +++ b/Icon/MessageBox/dialog-question.svg @@ -0,0 +1,15 @@ + + + + dialog-question + Created with Sketch. + + + + + + + + + + \ No newline at end of file diff --git a/Icon/MessageBox/dialog-warning.svg b/Icon/MessageBox/dialog-warning.svg new file mode 100644 index 0000000..1bf157d --- /dev/null +++ b/Icon/MessageBox/dialog-warning.svg @@ -0,0 +1,15 @@ + + + + dialog-warning + Created with Sketch. + + + + + + + + + + \ No newline at end of file diff --git a/Resources.qrc b/Resources.qrc new file mode 100644 index 0000000..98f4baa --- /dev/null +++ b/Resources.qrc @@ -0,0 +1,11 @@ + + + Icon/MessageBox/dialog-apply.svg + Icon/MessageBox/dialog-cancel.svg + Icon/MessageBox/dialog-error.svg + Icon/MessageBox/dialog-information.svg + Icon/MessageBox/dialog-ok.svg + Icon/MessageBox/dialog-question.svg + Icon/MessageBox/dialog-warning.svg + + diff --git a/aptss-installer.pro b/aptss-installer.pro index 8a1cb81..531aac0 100644 --- a/aptss-installer.pro +++ b/aptss-installer.pro @@ -1,8 +1,9 @@ QT += core gui +PKGCONFIG += dtkcore dtkgui dtkwidget greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -CONFIG += c++17 +CONFIG += c++17 link_pkgconfig # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. @@ -11,11 +12,13 @@ CONFIG += c++17 SOURCES += \ installdeb.cpp \ main.cpp \ - mainwindow.cpp + mainwindow.cpp \ + messagebox.cpp HEADERS += \ installdeb.h \ - mainwindow.h + mainwindow.h \ + messagebox.h FORMS += \ mainwindow.ui @@ -30,3 +33,6 @@ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target unix:!macx: LIBS += -lqtermwidget5 # 这一行让我查了好久 + +RESOURCES += \ + Resources.qrc diff --git a/main.cpp b/main.cpp index 30f5b09..c63e44e 100644 --- a/main.cpp +++ b/main.cpp @@ -1,12 +1,13 @@ #include "mainwindow.h" -#include #include #include +#include +using namespace Dtk::Widget; int main(int argc, char *argv[]) { - QApplication a(argc, argv); + DApplication a(argc, argv); QTranslator translator; const QStringList uiLanguages = QLocale::system().uiLanguages(); diff --git a/mainwindow.cpp b/mainwindow.cpp index a63aec5..b85c550 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,15 +1,18 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include "installdeb.h" +#include "messagebox.h" #include #include MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) + : DMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); - + MessageBox *message = new MessageBox(); + message->information("A", "B"); + this->close(); } MainWindow::~MainWindow() @@ -24,7 +27,11 @@ void MainWindow::on_installPath_clicked() terminal->setColorScheme("DarkPastels"); terminal->setShellProgram("/usr/bin/bash"); terminal->setArgs(QStringList() << "-c" << "gedit"); - connect(terminal, &QTermWidget::finished, this, [&, this](){QMessageBox::information(NULL, "提示", "系统安装完成"); }); + connect(terminal, &QTermWidget::finished, this, [&, this](){ + //QMessageBox::information(NULL, "提示", "系统安装完成"); + MessageBox *message = new MessageBox(); + message->information("A", "B"); + }); terminal->startShellProgram(); diff --git a/mainwindow.h b/mainwindow.h index 57cd5cb..fe4a233 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -1,13 +1,13 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include - +#include +using namespace Dtk::Widget; QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE -class MainWindow : public QMainWindow +class MainWindow : public DMainWindow { Q_OBJECT diff --git a/mainwindow.ui b/mainwindow.ui index 8ad743a..5a49cd5 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -31,6 +31,11 @@ + + + 1 + + diff --git a/messagebox.cpp b/messagebox.cpp new file mode 100644 index 0000000..89c1245 --- /dev/null +++ b/messagebox.cpp @@ -0,0 +1,30 @@ +#include "messagebox.h" +#include +#include +#include + +MessageBox::MessageBox(DWidget *parent){ + this->parent = parent; +} + +void MessageBox::information(QString title, QString text){ + DMainWindow *messageBox = new DMainWindow(this->parent); + 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("")); + 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->show(); + messageBox->resize(messageBox->frameSize().width(), messageBox->frameSize().height()); +} diff --git a/messagebox.h b/messagebox.h new file mode 100644 index 0000000..ba9c3bd --- /dev/null +++ b/messagebox.h @@ -0,0 +1,20 @@ +#ifndef MESSAGEBOX_H +#define MESSAGEBOX_H + +#include +#include +#include +using namespace Dtk::Widget; +class MessageBox +{ + //Q_OBJECT +public: + explicit MessageBox(DWidget *parent = nullptr); + void information(QString title, QString text); +private: + DWidget *parent; +signals: + +}; + +#endif // MESSAGEBOX_H