diff --git a/kybackup/aboutdialog.cpp b/kybackup/aboutdialog.cpp new file mode 100644 index 0000000..6d3fbcc --- /dev/null +++ b/kybackup/aboutdialog.cpp @@ -0,0 +1,134 @@ +#include "aboutdialog.h" +#include "ui_aboutdialog.h" +#include +#include +#include +#include +#include +#include +#include "xatom-helper.h" +#include "gsettingswrapper.h" +#include "./component/mylabel.h" +#include "../common/utils.h" + +AboutDialog::AboutDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::AboutDialog) +{ + ui->setupUi(this); + + // 添加窗管协议 + MotifWmHints hints; + hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; + hints.functions = MWM_FUNC_ALL; + hints.decorations = MWM_DECOR_BORDER; + XAtomHelper::getInstance()->setWindowMotifHint(winId(), hints); + + // 设置背景色 + this->setAutoFillBackground(true); + QPalette palette = this->palette(); + palette.setColor(QPalette::Background, palette.color(QPalette::Base)); + this->setPalette(palette); + + this->setFixedWidth(420); + this->setMinimumHeight(420); + QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + this->setSizePolicy(sizePolicy); + + // 顶行,关闭按钮 + QPushButton *closeBtn = new QPushButton; + closeBtn->setToolTip(tr("Close")); + closeBtn->setProperty("isWindowButton", 0x2); + closeBtn->setProperty("useIconHighlightEffect", 0x8); + closeBtn->setFixedSize(30, 30); + closeBtn->setFlat(true); + closeBtn->setIcon(QIcon::fromTheme("window-close-symbolic")); + QHBoxLayout *hlayoutLine1 = new QHBoxLayout; + hlayoutLine1->addStretch(); + hlayoutLine1->addWidget(closeBtn); + connect(closeBtn, &QPushButton::clicked, this, &AboutDialog::close); + + // 第二行,备份还原图标 + QLabel *backupIconLabel = new QLabel; + QIcon titleIcon = QIcon::fromTheme("yhkylin-backup-tools"); + backupIconLabel->setPixmap(titleIcon.pixmap(titleIcon.actualSize(QSize(96, 96)))); + GSettingsWrapper::connectUkuiStyleSchema(backupIconLabel, QSize(96, 96)); + QHBoxLayout *hlayoutLine2 = new QHBoxLayout; + hlayoutLine2->addStretch(); + hlayoutLine2->addWidget(backupIconLabel); + hlayoutLine2->addStretch(); + + // 第三行,工具名称 + MyLabel *toolName = new MyLabel; + toolName->setFixedHeight(36); + toolName->setDeplayText(tr("Backup & Restore")); + toolName->setFontSize(28); + toolName->setIsOriginal(true); + QHBoxLayout *hlayoutLine3 = new QHBoxLayout; + hlayoutLine3->addStretch(); + hlayoutLine3->addWidget(toolName); + hlayoutLine3->addStretch(); + + // 第四行,工具版本 + MyLabel *toolVersion = new MyLabel; + toolName->setFixedHeight(36); + toolVersion->setDeplayText(tr("version: ") + getBackupVersion()); + toolVersion->setIsOriginal(true); + QHBoxLayout *hlayoutLine4 = new QHBoxLayout; + hlayoutLine4->addStretch(); + hlayoutLine4->addWidget(toolVersion); + hlayoutLine4->addStretch(); + + // 第五行,简介 + MyLabel *introduction = new MyLabel; + introduction->setFixedWidth(356); + introduction->setIsOriginal(true); + introduction->setWordWrap(true); + introduction->setSizePolicy(sizePolicy); + introduction->setDeplayText(tr("The backup tool is a tool that supports system backup and data backup. " + "When the user data is damaged or the system is attacked, the tool can flexibly restore " + "the status of the backup node. A lot of optimization and innovation have been " + "carried out for domestic hardware and software platforms.")); + QHBoxLayout *hlayoutLine5 = new QHBoxLayout; + hlayoutLine5->addStretch(); + hlayoutLine5->addWidget(introduction); + hlayoutLine5->addStretch(); + + QVBoxLayout *vlayout = new QVBoxLayout; + vlayout->addLayout(hlayoutLine1); + vlayout->addLayout(hlayoutLine2); + vlayout->addLayout(hlayoutLine3); + vlayout->addLayout(hlayoutLine4); + vlayout->addLayout(hlayoutLine5); + vlayout->addSpacing(20); + vlayout->addStretch(); + this->setLayout(vlayout); + this->adjustSize(); +} + +QString AboutDialog::getBackupVersion() +{ + QString version; + Utils::executeCMD("dpkg -l yhkylin-backup-tools | grep yhkylin-backup-tools", version); + // "ii yhkylin-backup-tools 4.0.13-kylin72 amd64 YHkylin backup tools\n" + QStringList fields = version.split(QRegularExpression("[ \t]+")); + if (fields.size() >= 3) + version = fields.at(2); + else + version = "none"; + + return version; +} + +//void AboutDialog::resizeEvent(QResizeEvent *event) +//{ +// // 警告:在resizeEvent()中调用resize()或setGeometry()可能导致无限递归。所以最好不要这样用 +// if (event->oldSize() != event->size()) { +// this->resize(event->size()); +// } +//} + +AboutDialog::~AboutDialog() +{ + delete ui; +} diff --git a/kybackup/aboutdialog.h b/kybackup/aboutdialog.h new file mode 100644 index 0000000..1cec9f6 --- /dev/null +++ b/kybackup/aboutdialog.h @@ -0,0 +1,27 @@ +#ifndef ABOUTDIALOG_H +#define ABOUTDIALOG_H + +#include +#include + +namespace Ui { +class AboutDialog; +} + +class AboutDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AboutDialog(QWidget *parent = nullptr); + ~AboutDialog(); + + QString getBackupVersion(); + + //virtual void resizeEvent(QResizeEvent *event); + +private: + Ui::AboutDialog *ui; +}; + +#endif // ABOUTDIALOG_H diff --git a/kybackup/aboutdialog.ui b/kybackup/aboutdialog.ui new file mode 100644 index 0000000..272eadc --- /dev/null +++ b/kybackup/aboutdialog.ui @@ -0,0 +1,18 @@ + + AboutDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + diff --git a/kybackup/gsettingswrapper.cpp b/kybackup/gsettingswrapper.cpp index 785096f..b760c9f 100755 --- a/kybackup/gsettingswrapper.cpp +++ b/kybackup/gsettingswrapper.cpp @@ -26,7 +26,6 @@ void GSettingsWrapper::connectUkuiStyleSchema(QWidget * widgetPtr, QSize size) QLabel *labelPtr = qobject_cast(widgetPtr); const QPixmap * pixmapPtr = labelPtr->pixmap(); if (pixmapPtr != nullptr) { - //labelPtr->setPixmap(titleIcon.pixmap(titleIcon.actualSize(pixmapPtr->size()))); labelPtr->setPixmap(titleIcon.pixmap(titleIcon.actualSize(size))); } else { labelPtr->setPixmap(titleIcon.pixmap(titleIcon.actualSize(QSize(24, 24)))); diff --git a/kybackup/kybackup.pro b/kybackup/kybackup.pro index 7fe9411..1451e67 100755 --- a/kybackup/kybackup.pro +++ b/kybackup/kybackup.pro @@ -35,6 +35,7 @@ HEADERS += \ ../common/singleton.h \ ../common/spinlock_mutex.h \ ../common/utils.h \ + aboutdialog.h \ backup_manager_interface.h \ backuppointlistdialog.h \ component/backuplistwidget.h \ @@ -78,6 +79,7 @@ SOURCES += \ ../common/mydefine.cpp \ ../common/mylittleparse.cpp \ ../common/utils.cpp \ + aboutdialog.cpp \ backup_manager_interface.cpp \ backuppointlistdialog.cpp \ component/backuplistwidget.cpp \ @@ -117,6 +119,7 @@ SOURCES += \ xatom-helper.cpp FORMS += \ + aboutdialog.ui \ backuppointlistdialog.ui \ deletebackupdialog.ui \ maindialog.ui diff --git a/kybackup/maindialog.cpp b/kybackup/maindialog.cpp index 77ecbda..700b831 100755 --- a/kybackup/maindialog.cpp +++ b/kybackup/maindialog.cpp @@ -17,6 +17,7 @@ #include "backup_manager_interface.h" #include "globalbackupinfo.h" #include "messageboxutils.h" +#include "aboutdialog.h" MainDialog::MainDialog(QWidget *parent) : QMainWindow(parent) @@ -157,7 +158,7 @@ void MainDialog::initStyleSheet() // 主窗口 this->setWindowTitle(tr("Backup & Restore")); - // 右侧title + // 右侧窗口背景色设置 m_rightWidget->setAutoFillBackground(true); QPalette palette = m_rightWidget->palette(); palette.setColor(QPalette::Background, palette.color(QPalette::Base)); @@ -175,8 +176,9 @@ void MainDialog::initConnect() // 关于 connect(m_backupAbout, &QAction::triggered, this, [=] { - // UkccAbout *ukcc = new UkccAbout(this); - // ukcc->exec(); + AboutDialog *about = new AboutDialog(this); + about->exec(); + about->deleteLater(); }); connect(m_backupHelp, &QAction::triggered, this, [=] {