yhkylin-backup-tools/kybackup/module/systembackup.cpp

262 lines
8.9 KiB
C++
Raw Normal View History

2021-09-16 16:05:46 +08:00
#include "systembackup.h"
#include <QLabel>
#include <QPushButton>
2021-10-13 16:31:58 +08:00
#include <QComboBox>
#include <QMovie>
2021-09-16 16:05:46 +08:00
2021-10-13 16:31:58 +08:00
#include "../component/clicklabel.h"
#include "../component/circlelabel.h"
#include "../component/myiconlabel.h"
#include "../component/mylabel.h"
#include "../component/linelabel.h"
#include "../../common/utils.h"
2021-09-16 16:05:46 +08:00
SystemBackup::SystemBackup(QWidget *parent /*= nullptr*/) :
2021-10-13 16:31:58 +08:00
QStackedWidget(parent),
m_udector(new UdiskDetector()),
m_isLocal(true),
m_systemBackupState(SystemBackupState::IDEL),
m_movie(nullptr)
2021-09-16 16:05:46 +08:00
{
2021-10-13 16:31:58 +08:00
// 界面手写代码创建,作为练手
2021-09-16 16:05:46 +08:00
initFirstWidget();
2021-10-13 16:31:58 +08:00
initSecondWidget();
initThirdWidget();
2021-09-16 16:05:46 +08:00
}
SystemBackup::~SystemBackup()
2021-10-13 16:31:58 +08:00
{
delete m_udector;
delete m_movie;
}
2021-09-16 16:05:46 +08:00
2021-10-13 16:31:58 +08:00
/**
* @brief
*/
2021-09-16 16:05:46 +08:00
void SystemBackup::initFirstWidget()
{
QWidget *first = new QWidget;
QLabel *imageBackup_firstPage = new QLabel(first);
imageBackup_firstPage->setGeometry(421, 120, 300, 326);
2021-09-23 11:21:58 +08:00
QPixmap pixmap(":/images/system_backup.svg");
2021-09-16 16:05:46 +08:00
imageBackup_firstPage->setPixmap(pixmap);
imageBackup_firstPage->setScaledContents(true);
2021-10-13 16:31:58 +08:00
MyLabel *labelBackup_firstPage = new MyLabel(first);
labelBackup_firstPage->setDeplayText(tr("System Backup"));
labelBackup_firstPage->setFixedWidth(500);
2021-09-16 16:05:46 +08:00
labelBackup_firstPage->setFixedHeight(48);
labelBackup_firstPage->move(41, 120);
// 默认水平左对齐,上下居中对齐;故不需要设置
// labelBackup_firstPage->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
// labelBackup_firstPage->setText(tr("System Backup"));
QFont font;
font.setBold(true);
font.setPixelSize(36);
labelBackup_firstPage->setFont(font);
2021-10-13 16:31:58 +08:00
// labelBackup_firstPage->setAttribute(Qt::WA_TranslucentBackground);
labelBackup_firstPage->setScaledContents(true);
2021-09-16 16:05:46 +08:00
labelBackup_firstPage->adjustSize();
2021-10-13 16:31:58 +08:00
MyLabel *labelNote_firstPage = new MyLabel(first);
labelNote_firstPage->setFixedWidth(700);
2021-09-16 16:05:46 +08:00
labelNote_firstPage->setFixedHeight(24);
labelNote_firstPage->move(41, 180);
2021-10-13 16:31:58 +08:00
labelNote_firstPage->setDeplayText(tr("Can be restored when files are damaged or lost"));
2021-09-16 16:05:46 +08:00
font.setBold(false);
font.setPixelSize(18);
labelNote_firstPage->setFont(font);
2021-10-13 16:31:58 +08:00
labelNote_firstPage->setScaledContents(true);
2021-09-16 16:05:46 +08:00
labelNote_firstPage->adjustSize();
MyIconLabel *iconMultiBackup_firstPage = new MyIconLabel(first);
2021-10-13 16:31:58 +08:00
iconMultiBackup_firstPage->setGeometry(41, 244, 180, 36);
iconMultiBackup_firstPage->setThemeIcon("ukui-bf-many-spot-symbolic", ":/symbos/ukui-bf-many-spot-symbolic.png");
2021-09-16 16:05:46 +08:00
iconMultiBackup_firstPage->setDesplayText(tr("Multi-Spot"));
iconMultiBackup_firstPage->setEnabled(false);
MyIconLabel *iconSmallSize_firstPage = new MyIconLabel(first);
2021-10-13 16:31:58 +08:00
iconSmallSize_firstPage->setGeometry(201, 244, 180, 36);
iconSmallSize_firstPage->setThemeIcon("ukui-bf-volume-symbolic", ":/symbos/ukui-bf-volume-symbolic.png");
2021-09-16 16:05:46 +08:00
iconSmallSize_firstPage->setDesplayText(tr("Small Size"));
iconSmallSize_firstPage->setEnabled(false);
MyIconLabel *iconSecurity_firstPage = new MyIconLabel(first);
2021-10-13 16:31:58 +08:00
iconSecurity_firstPage->setGeometry(41, 296, 180, 36);
iconSecurity_firstPage->setThemeIcon("ukui-bf-security-symbolic", ":/symbos/ukui-bf-security-symbolic.png");
2021-09-16 16:05:46 +08:00
iconSecurity_firstPage->setDesplayText(tr("Security"));
iconSecurity_firstPage->setEnabled(false);
MyIconLabel *iconSimple_firstPage = new MyIconLabel(first);
2021-10-13 16:31:58 +08:00
iconSimple_firstPage->setGeometry(201, 296, 180, 36);
iconSimple_firstPage->setThemeIcon("ukui-bf-simple-symbolic", ":/symbos/ukui-bf-simple-symbolic.png");
2021-09-16 16:05:46 +08:00
iconSimple_firstPage->setDesplayText(tr("Simple"));
iconSimple_firstPage->setEnabled(false);
2021-09-23 11:21:58 +08:00
QPushButton *beginBackup = new QPushButton(first);
beginBackup->setGeometry(41, 372, 180, 52);
beginBackup->setText(tr("Start Backup"));
beginBackup->setEnabled(true);
beginBackup->setAutoRepeat(true);
font.setPixelSize(24);
beginBackup->setFont(font);
2021-10-13 16:31:58 +08:00
connect(beginBackup, &QPushButton::clicked, this, &SystemBackup::on_next_clicked);
ClickLabel * backupPointManage = new ClickLabel(tr("Backup Management >>"), first);
backupPointManage->setGeometry(551, 551, 200, 30);
QPalette pal(backupPointManage->palette());
pal.setColor(QPalette::WindowText, QColor(Qt::blue));
backupPointManage->setPalette(pal);
backupPointManage->setToolTip(tr("Backup Management >>"));
connect(backupPointManage, &ClickLabel::clicked, this, &SystemBackup::on_systemBackupManage_clicked);
2021-09-16 16:05:46 +08:00
addWidget(first);
}
2021-10-13 16:31:58 +08:00
/**
* @brief
* @param checked
*/
void SystemBackup::on_pre_clicked(bool checked)
{
Q_UNUSED(checked)
int index = this->currentIndex() - 1;
if (index >= 0) {
this->setCurrentIndex(index);
}
}
/**
* @brief
* @param checked
*/
void SystemBackup::on_next_clicked(bool checked)
{
Q_UNUSED(checked)
int index = this->currentIndex() + 1;
if (index < this->count()) {
this->setCurrentIndex(index);
}
}
/**
* @brief
*/
void SystemBackup::on_systemBackupManage_clicked()
{
// TODO:创建系统备份点管理界面
}
/**
* @brief
*/
void SystemBackup::initSecondWidget()
{
QWidget *second = new QWidget;
MyLabel* labelSelect = new MyLabel(second);
labelSelect->setDeplayText(tr("Please select backup position"));
labelSelect->setFixedWidth(600);
labelSelect->setFixedHeight(27);
labelSelect->move(41, 41);
QFont font;
font.setBold(true);
font.setPixelSize(18);
labelSelect->setFont(font);
labelSelect->setScaledContents(true);
labelSelect->adjustSize();
QComboBox* comboSelect = new QComboBox(second);
comboSelect->setGeometry(41, 84, 680, 36);
// 添加本地默认路径、移动设备目录
connect(m_udector, &UdiskDetector::udiskListChanged, this, [=](QList<QStorageInfo> diskList) {
comboSelect->clear();
QString qsLocalDefaultPath = Utils::getSysRootPath() + BACKUP_SNAPSHOTS_PATH;
qsLocalDefaultPath.replace("//", "/");
QIcon iconFolder = QIcon::fromTheme("insync-folder.png", QIcon(":/images/folder.png"));
comboSelect->addItem(iconFolder, tr("local default path : ") + qsLocalDefaultPath);
QString qsPreDevPath(tr("removable devices path : "));
for (QStorageInfo& disk : diskList) {
comboSelect->addItem(iconFolder, qsPreDevPath + disk.rootPath() + BACKUP_SNAPSHOTS_PATH);
}
});
m_udector->getStorageInfo();
connect(comboSelect, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) {
// 第一个选项是本地系统备份
m_isLocal = (index == 0);
});
QPushButton *preStep = new QPushButton(second);
preStep->setGeometry(271, 176, 97, 36);
preStep->setText(tr("back"));
preStep->setEnabled(true);
preStep->setAutoRepeat(true);
connect(preStep, &QPushButton::clicked, this, &SystemBackup::on_pre_clicked);
QPushButton *nextStep = new QPushButton(second);
nextStep->setGeometry(389, 176, 97, 36);
nextStep->setText(tr("next"));
nextStep->setEnabled(true);
nextStep->setAutoRepeat(true);
connect(nextStep, &QPushButton::clicked, this, [=](bool checked) {
this->on_next_clicked(checked);
emit this->startCheckEnv();
});
addWidget(second);
}
/**
* @brief
*/
void SystemBackup::initThirdWidget()
{
QWidget *third = new QWidget;
CircleLable *one = new CircleLable("1", third, 24, QColor(COLOR_BLUE));
one->move(QPoint(81, 41));
LineLabel *line1 = new LineLabel(third, QColor(COLOR_BLUE));
line1->move(QPoint(108, 41));
CircleLable *two = new CircleLable("2", third);
two->move(QPoint(261, 41));
LineLabel *line2 = new LineLabel(third);
line2->move(QPoint(288, 41));
CircleLable *three = new CircleLable("3", third);
three->move(QPoint(441, 41));
LineLabel *line3 = new LineLabel(third);
line3->move(QPoint(468, 41));
CircleLable *four = new CircleLable("4", third);
four->move(QPoint(621, 41));
MyLabel *label1 = new MyLabel(tr("checking"), third);
label1->setFontColor(QColor(COLOR_BLUE));
label1->setGeometry(11, 72, 164, 30);
MyLabel *label2 = new MyLabel(tr("preparing"), third);
label2->setGeometry(191, 72, 164, 30);
MyLabel *label3 = new MyLabel(tr("backuping"), third);
label3->setGeometry(371, 72, 164, 30);
MyLabel *label4 = new MyLabel(tr("finished"), third);
label4->setGeometry(551, 72, 164, 30);
QLabel *loadingGif = new QLabel(third);
QMovie *m_movie = new QMovie(":/images/loading.gif");
loadingGif->setMovie(m_movie);
loadingGif->setGeometry(180, 180, 20, 20);
m_movie->start();
QLabel *bigTitle = new QLabel(third);
QFont font = bigTitle->font();
font.setBold(true);
font.setPixelSize(24);
bigTitle->setFont(font);
bigTitle->setText(tr("env checking, wait a moment"));
bigTitle->setGeometry(210, 170, 500, 36);
addWidget(third);
}