yhkylin-backup-tools/kybackup/aboutdialog.cpp

135 lines
4.7 KiB
C++
Raw Normal View History

2022-01-28 12:06:03 +08:00
#include "aboutdialog.h"
#include "ui_aboutdialog.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QRegularExpression>
#include <QSizePolicy>
#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;
}