阶段提交

This commit is contained in:
zhaominyong 2021-09-23 11:21:58 +08:00
parent 8fc9d1bbc4
commit b0963343af
22 changed files with 222 additions and 27 deletions

View File

@ -8,6 +8,12 @@
#include <QDebug>
#include "../common/reflect.h"
#include "mymountproxy.h"
#include "parsebackuplist.h"
void testXml()
{
ParseBackupList parse("/backup/snapshots/backuplist.xml");
}
// test end

View File

@ -323,7 +323,7 @@ bool Utils::generateExcludePathsFile()
in << "/var/lib/udisks2" << endl;
in << "/var/log" << endl;
// 系统安装后有的会将/data/home /data/root挂载到的/home /root上实际文件是存放在/data/home /data/root下面
// 系统安装后有的会将/data/home /data/root挂载到的/home /root上实际文件是存放在/data/home /data/root下面,为了统一标准保留/home /root排除/data/home /data/root
QStringList excludes;
Utils::excludeFstabBindPath(excludes);
for (const QString& item : excludes) {
@ -477,6 +477,31 @@ bool Utils::writeBackupLog(QString line)
return true;
}
/**
* @brief
* @param fileName
* @param content
* @return bool
*/
bool Utils::syncWriteFile(const QString &fileName, const QString& content)
{
std::unique_ptr<std::FILE, int (*)(std::FILE*)> fp(std::fopen(fileName.toStdString().data(), "a+"), std::fclose);
if (!fp) {
std::perror("file opening failed!");
return false;
}
QStringList lines = content.split("\n");
for (const QString& line : lines) {
std::fputs(line.toStdString().data(), fp.get());
}
std::fflush(fp.get());
fdatasync(fileno(fp.get()));
return true;
}
/**
* @brief GB等表示的字符串
* @param sizeqint64

View File

@ -139,6 +139,14 @@ public:
*/
static bool writeBackupLog(QString line);
/**
* @brief
* @param fileName
* @param content
* @return bool
*/
static bool syncWriteFile(const QString &fileName, const QString& content);
/**
* @brief GB等表示的字符串
* @param sizeqint64

View File

@ -5,5 +5,11 @@
<file alias="/images/ghost_image.svg">resource/images/ghost_image.svg</file>
<file alias="/images/system_restore.svg">resource/images/sysem_restore.svg</file>
<file alias="/images/system_backup.png">resource/images/system_backup.png</file>
<file alias="/images/system_backup.svg">resource/images/system_backup.svg</file>
<file alias="/images/data_backup_dark.svg">resource/images/data_backup_dark.svg</file>
<file alias="/images/data_restore_dark.svg">resource/images/data_restore_dark.svg</file>
<file alias="/images/ghost_image_dark.svg">resource/images/ghost_image_dark.svg</file>
<file alias="/images/system_restore_dark.svg">resource/images/sysem_restore_dark.svg</file>
<file alias="/images/system_backup_dark.svg">resource/images/system_backup_dark.svg</file>
</qresource>
</RCC>

View File

@ -19,7 +19,8 @@
*/
#include "clicklabel.h"
ClickLabel::ClickLabel(const QString &text, QWidget *parent)
ClickLabel::ClickLabel(const QString &text, QWidget *parent) :
QLabel(parent)
{
setText(text);
adjustSize();

View File

@ -2,8 +2,9 @@
#include <QPainter>
#include <QApplication>
#include <QIcon>
const QPixmap ImageUtil::loadSvg(const QString &path, const QString color, int size)
const QPixmap ImageUtil::loadSvg(const QString &path, const QString& color, int size)
{
int origSize = size;
const auto ratio = qApp->devicePixelRatio();
@ -25,7 +26,24 @@ const QPixmap ImageUtil::loadSvg(const QString &path, const QString color, int s
return drawSymbolicColoredPixmap(pixmap, color);
}
QPixmap ImageUtil::drawSymbolicColoredPixmap(const QPixmap &source, QString cgColor)
const QPixmap ImageUtil::loadSvgTheme(const QString &theme, const QString& color, int size)
{
int origSize = size;
const auto ratio = qApp->devicePixelRatio();
if ( 2 == ratio) {
size += origSize;
} else if (3 == ratio) {
size += origSize;
}
QIcon icon = QIcon::fromTheme(theme);
QPixmap pixmap = icon.pixmap(QSize(size, size));
pixmap.setDevicePixelRatio(ratio);
return drawSymbolicColoredPixmap(pixmap, color);
}
QPixmap ImageUtil::drawSymbolicColoredPixmap(const QPixmap &source, const QString& cgColor)
{
QImage img = source.toImage();
for (int x = 0; x < img.width(); x++) {

View File

@ -7,8 +7,9 @@
class ImageUtil
{
public:
static const QPixmap loadSvg(const QString &path, const QString color, int size = 16);
static QPixmap drawSymbolicColoredPixmap(const QPixmap &source, QString cgColor);
static const QPixmap loadSvg(const QString &path, const QString &color, int size = 16);
static const QPixmap loadSvgTheme(const QString &theme, const QString &color, int size = 16);
static QPixmap drawSymbolicColoredPixmap(const QPixmap &source, const QString &cgColor);
};
#endif // IMAGEUTIL_H

View File

@ -3,6 +3,8 @@
#include <QHBoxLayout>
#include <QStyleOptionButton>
#include <QPainter>
#include <QApplication>
#include "imageutil.h"
MyIconButton::MyIconButton(QWidget *parent) :
QPushButton(parent)
@ -20,7 +22,7 @@ MyIconButton::MyIconButton(QWidget *parent) :
textLabelPolicy.setHorizontalPolicy(QSizePolicy::Fixed);
textLabelPolicy.setVerticalPolicy(QSizePolicy::Fixed);
m_textLabel->setSizePolicy(textLabelPolicy);
m_textLabel->setScaledContents(true);
//m_textLabel->setScaledContents(true);
QHBoxLayout *hLayout = new QHBoxLayout();
hLayout->setContentsMargins(8, 0, 0, 0);
@ -29,21 +31,31 @@ MyIconButton::MyIconButton(QWidget *parent) :
hLayout->addStretch();
setLayout(hLayout);
connect(m_iconButton, &QPushButton::clicked, this, &QPushButton::click);
connect(m_iconButton, &QPushButton::clicked, this, &MyIconButton::clicked);
// connect(this, &QPushButton::toggled, this, [=] (bool checked) {
// if (checked)
// m_textLabel->setStyleSheet("color:white");
// else
// m_textLabel->setStyleSheet("color:palette(windowText)");
// });
connect(this, &QPushButton::toggled, this, &MyIconButton::changePalette);
}
MyIconButton::~MyIconButton()
{}
void MyIconButton::setThemeIcon(const QString &themeIconName)
void MyIconButton::setThemeIcon(const QString &themeIconName, int size)
{
m_themeIconName = themeIconName;
m_iconButton->setIcon(QIcon::fromTheme(themeIconName));
QIcon icon = QIcon::fromTheme(themeIconName);
m_iconButton->setIcon(icon.pixmap(icon.actualSize(QSize(size, size))));
}
void MyIconButton::setDesplayText(const QString &text)
{
m_textLabel->setFixedWidth(this->width() - 40);
m_originalText = text;
m_textLabel->setFixedWidth(this->width() - 30);
QFontMetrics fontMetrics(m_textLabel->font());
int fontSize = fontMetrics.width(text);
if (fontSize > m_textLabel->width()) {
@ -53,3 +65,18 @@ void MyIconButton::setDesplayText(const QString &text)
}
}
void MyIconButton::changePalette(bool checked)
{
QPalette pal(m_textLabel->palette());
QPixmap pix;
if (checked) {
pal.setColor(QPalette::ButtonText, pal.color(QPalette::HighlightedText));
pix = ImageUtil::loadSvgTheme(m_themeIconName, QString("white"));
} else {
pal.setColor(QPalette::ButtonText, pal.color(QPalette::WindowText));
pix = ImageUtil::loadSvgTheme(m_themeIconName, QString("default"));
}
m_textLabel->setPalette(pal);
m_iconButton->setIcon(pix);
}

View File

@ -3,6 +3,7 @@
#include <QPushButton>
#include <QLabel>
#include <QPalette>
class MyIconButton : public QPushButton
{
@ -11,14 +12,18 @@ public:
explicit MyIconButton(QWidget *parent = nullptr);
~MyIconButton();
void setThemeIcon(const QString &themeIconName);
void setThemeIcon(const QString &themeIconName, int size = 16);
void setDesplayText(const QString &text);
public slots:
void changePalette(bool checked);
private:
QPushButton *m_iconButton;
QLabel *m_textLabel;
QString m_themeIconName;
QString m_originalText;
};
#endif // MYICONBUTTON_H

View File

@ -1,14 +1,16 @@
#include "myiconlabel.h"
#include <QHBoxLayout>
#include <QIcon>
#include <QApplication>
#include "imageutil.h"
MyIconLabel::MyIconLabel(QWidget *parent /*= nullptr*/) :
QLabel(parent)
{
m_iconLabel = new QLabel(this);
// m_iconLabel->setFixedSize(QSize(24, 24));
// border:1px solid black;
const QString greySheetStyle = "min-width: 36px; min-height: 36px;max-width:36px; max-height: 36px;border-radius: 18px; background:grey";
// const QString greySheetStyle = "min-width: 36px; min-height: 36px;max-width:36px; max-height: 36px;border-radius: 18px; background:grey";
const QString greySheetStyle = "min-width: 36px; min-height: 36px;max-width:36px; max-height: 36px;border-radius: 18px";
m_iconLabel->setStyleSheet(greySheetStyle);
m_textLabel = new QLabel(this);
@ -16,7 +18,7 @@ MyIconLabel::MyIconLabel(QWidget *parent /*= nullptr*/) :
textLabelPolicy.setHorizontalPolicy(QSizePolicy::Fixed);
textLabelPolicy.setVerticalPolicy(QSizePolicy::Fixed);
m_textLabel->setSizePolicy(textLabelPolicy);
m_textLabel->setScaledContents(true);
// m_textLabel->setScaledContents(true);
QHBoxLayout *hLayout = new QHBoxLayout();
hLayout->setContentsMargins(8, 0, 0, 0);
@ -32,11 +34,13 @@ MyIconLabel::~MyIconLabel()
void MyIconLabel::setThemeIcon(const QString &themeIconName)
{
m_themeIconName = themeIconName;
m_textLabel->setPixmap(QIcon::fromTheme(themeIconName).pixmap(QSize(24,24)));
// m_textLabel->setPixmap(QIcon::fromTheme(themeIconName).pixmap(QSize(24,24)));
m_textLabel->setPixmap(ImageUtil::loadSvgTheme(m_themeIconName, QString("default")));
}
void MyIconLabel::setDesplayText(const QString &text)
{
m_originalText = text;
m_textLabel->setFixedWidth(this->width() - 40);
QFontMetrics fontMetrics(m_textLabel->font());
int fontSize = fontMetrics.width(text);
@ -46,3 +50,18 @@ void MyIconLabel::setDesplayText(const QString &text)
m_textLabel->setText(text);
}
}
void MyIconLabel::changePalette(bool dark)
{
QPalette pal(m_textLabel->palette());
QPixmap pix;
if (dark) {
pal.setColor(QPalette::WindowText, pal.color(QPalette::HighlightedText));
pix = ImageUtil::loadSvgTheme(m_themeIconName, QString("white"));
} else {
pal.setColor(QPalette::WindowText, this->palette().color(QPalette::WindowText));
pix = ImageUtil::loadSvgTheme(m_themeIconName, QString("default"));
}
m_textLabel->setPalette(pal);
m_iconLabel->setPixmap(pix);
}

View File

@ -14,10 +14,14 @@ public:
void setDesplayText(const QString &text);
public slots:
void changePalette(bool checked);
private:
QLabel *m_iconLabel;
QLabel *m_textLabel;
QString m_themeIconName;
QString m_originalText;
};
#endif // MYICONLABEL_H

View File

@ -35,11 +35,11 @@ HEADERS += \
backup_manager_interface.h \
component/clicklabel.h \
component/hoverwidget.h \
component/imageutil.h \
component/myiconbutton.h \
component/myiconlabel.h \
functypeconverter.h \
gsettingswrapper.h \
imageutil.h \
leftsiderbarwidget.h \
maindialog.h \
module/systembackup.h \
@ -55,11 +55,11 @@ SOURCES += \
backup_manager_interface.cpp \
component/clicklabel.cpp \
component/hoverwidget.cpp \
component/imageutil.cpp \
component/myiconbutton.cpp \
component/myiconlabel.cpp \
functypeconverter.cpp \
gsettingswrapper.cpp \
imageutil.cpp \
leftsiderbarwidget.cpp \
main.cpp \
maindialog.cpp \

View File

@ -5,6 +5,7 @@
#include <QPainter>
#include "../common/mydefine.h"
#include "component/myiconbutton.h"
#include <QToolButton>
LeftsiderbarWidget::LeftsiderbarWidget(QWidget *parent, StartMode mode)
: QWidget(parent)
@ -50,9 +51,10 @@ LeftsiderbarWidget::LeftsiderbarWidget(QWidget *parent, StartMode mode)
funcButton->setThemeIcon(themeIconName);
funcButton->setToolTip(mnamei18nString);
funcButton->setCheckable(true);
// 設置無邊框,跟隨背景色
funcButton->setFlat(true);
// 設置了setStyleSheet不能再跟隨主題捨棄此種方式
// 設置了setStyleSheet不能再跟隨主題舍弃此种方式
// funcButton->setStyleSheet("QPushButton:hover{background-color: rgba(55,144,250,0.30);border-radius: 4px;}"
// "QPushButton:checked{background-color: palette(highlight);border-radius: 4px;}"
// "QPushButton:!checked{border: none;}");
@ -73,9 +75,9 @@ LeftsiderbarWidget::~LeftsiderbarWidget()
}
void LeftsiderbarWidget::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QStyleOption opt;
opt.init(this);
QPainter p(this);

View File

@ -69,7 +69,7 @@ int main(int argc, char *argv[])
// 使得窗口无边框
// w.setWindowFlag(Qt::FramelessWindowHint);
// 指示窗口管理器模糊给定窗口后面指定区域的背景(毛玻璃化背景)
KWindowEffects::enableBlurBehind(w.winId(),true);
KWindowEffects::enableBlurBehind(w.winId(), true);
// 添加窗管协议
MotifWmHints hints;

View File

@ -25,15 +25,16 @@ MainDialog::~MainDialog()
void MainDialog::initUI()
{
m_totalHLayout = new QHBoxLayout(this);
m_totalHLayout = new QHBoxLayout(ui->centralwidget);
m_totalHLayout->setSpacing(0);
m_totalHLayout->setObjectName(QString::fromUtf8("m_totalHLayout"));
m_totalHLayout->setContentsMargins(0, 0, 0, 0);
this->setLayout(m_totalHLayout);
ui->centralwidget->setLayout(m_totalHLayout);
m_leftSiderBarWidget = new LeftsiderbarWidget(ui->centralwidget);
m_leftSiderBarWidget->setObjectName(QString::fromUtf8("m_leftSiderBarWidget"));
m_leftSiderBarWidget->setGeometry(QRect(0, 0, 200, 640));
m_leftSiderBarWidget->setFixedSize(QSize(200, 640));
m_totalHLayout->addWidget(m_leftSiderBarWidget);

View File

@ -19,7 +19,7 @@ void SystemBackup::initFirstWidget()
QLabel *imageBackup_firstPage = new QLabel(first);
imageBackup_firstPage->setGeometry(421, 120, 300, 326);
QPixmap pixmap(":/images/system_backup.png");
QPixmap pixmap(":/images/system_backup.svg");
imageBackup_firstPage->setPixmap(pixmap);
imageBackup_firstPage->setScaledContents(true);
@ -73,8 +73,13 @@ void SystemBackup::initFirstWidget()
iconSimple_firstPage->setDesplayText(tr("Simple"));
iconSimple_firstPage->setEnabled(false);
QPushButton *beginBackup = new QPushButton(this);
// beginBackup->setGeometry();
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);
addWidget(first);
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 34 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 75 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 49 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 84 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 69 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 74 KiB