yhkylin-backup-tools/kybackup/leftsiderbarwidget.cpp

140 lines
5.4 KiB
C++
Raw Normal View History

2021-09-16 16:05:46 +08:00
#include "leftsiderbarwidget.h"
#include <QDebug>
#include <QStyleOption>
#include <QPainter>
#include "../common/mydefine.h"
#include "component/myiconbutton.h"
2021-11-17 13:23:38 +08:00
#include "globalbackupinfo.h"
2022-02-15 16:51:03 +08:00
#include "gsettingswrapper.h"
#define PERSONALSIE_SCHEMA "org.ukui.control-center.personalise"
#define PERSONALSIE_TRAN_KEY "transparency"
#define CONTAIN_PERSONALSIE_TRAN_KEY "transparency"
2021-09-16 16:05:46 +08:00
LeftsiderbarWidget::LeftsiderbarWidget(QWidget *parent, StartMode mode)
: QWidget(parent)
{
2022-02-16 17:47:06 +08:00
m_parent = parent;
2021-09-16 16:05:46 +08:00
m_leftSideBarVLayout = new QVBoxLayout();
m_leftSideBarVLayout->setObjectName(QString::fromUtf8("m_leftSideBarVLayout"));
m_leftSideBarVLayout->setContentsMargins(5,0,0,0);
setLayout(m_leftSideBarVLayout);
m_leftSideBarVLayout->setSpacing(5);
QWidget *titleWidget = new QWidget(this);
m_leftSideBarVLayout->addWidget(titleWidget);
QHBoxLayout * titleLayout = new QHBoxLayout();
m_mTitleIcon = new QLabel();
2021-10-13 16:31:58 +08:00
m_titleLabel = new MyLabel();
m_titleLabel->setDeplayText(tr("Backup & Restore"));
m_titleLabel->setToolTip(tr("Backup & Restore"));
2021-09-16 16:05:46 +08:00
titleWidget->setLayout(titleLayout);
titleLayout->addWidget(m_mTitleIcon);
titleLayout->addWidget(m_titleLabel);
m_mTitleIcon->setFixedSize(24, 24);
QIcon titleIcon = QIcon::fromTheme(THEME_YHKYLIN_BACKUP_TOOLS);
m_mTitleIcon->setPixmap(titleIcon.pixmap(titleIcon.actualSize(QSize(24, 24))));
2022-02-15 16:51:03 +08:00
g_GSettingWrapper.connectUkuiIconSchema(m_mTitleIcon);
2021-09-16 16:05:46 +08:00
m_titleLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
m_leftSideBarVLayout->addSpacing(10);
// 功能列表
int funcNum = FuncTypeConverter::FunType::TOTALMODULES;
2021-11-17 13:23:38 +08:00
if (StartMode::livecd == mode) {
m_deplayFuncs << "BACKUP_SYSTEM" << "RESTORE_SYSTEM";
} else if (StartMode::std_user == mode) {
m_deplayFuncs << "BACKUP_DATA" << "RESTORE_DATA" << "OPERATION_LOG";
} else {
m_deplayFuncs << "BACKUP_SYSTEM" << "RESTORE_SYSTEM" << "BACKUP_DATA" << "RESTORE_DATA" << "OPERATION_LOG" << "GHOST_IMAGE";
}
2021-09-16 16:05:46 +08:00
m_funcGroup = new QButtonGroup(this);
FuncTypeConverter kvConverter;
for (int type = 0; type < funcNum; ++type) {
2021-11-17 13:23:38 +08:00
QString mnameString = kvConverter.keycodeTokeystring(type); //设置TEXT
if (!m_deplayFuncs.contains(mnameString))
continue ;
2021-09-16 16:05:46 +08:00
QString themeIconName = kvConverter.keycodeToThemeIconString(type);
QString mnamei18nString = kvConverter.keycodeTokeyi18nstring(type); //设置TEXT
MyIconButton *funcButton = new MyIconButton(this);
2021-11-17 13:23:38 +08:00
QString btnName = mnameString;
2021-09-16 16:05:46 +08:00
funcButton->setObjectName(btnName);
funcButton->setFixedSize(180, 40);
funcButton->setDesplayText(mnamei18nString);
2021-10-13 16:31:58 +08:00
QString defaultIconName(":/symbos/");
defaultIconName += themeIconName;
defaultIconName += ".png";
funcButton->setThemeIcon(themeIconName, defaultIconName);
2021-09-16 16:05:46 +08:00
funcButton->setToolTip(mnamei18nString);
funcButton->setCheckable(true);
2021-11-17 13:23:38 +08:00
connect(funcButton, &MyIconButton::clicked, [=](bool checked) {
if (checked)
emit this->selected(type);
});
2021-09-23 11:21:58 +08:00
2021-09-16 16:05:46 +08:00
// 設置無邊框,跟隨背景色
funcButton->setFlat(true);
2021-09-23 11:21:58 +08:00
// 設置了setStyleSheet不能再跟隨主題舍弃此种方式
2021-09-16 16:05:46 +08:00
// 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;}");
m_funcGroup->addButton(funcButton, type);
m_leftSideBarVLayout->addWidget(funcButton);
}
2021-11-17 13:23:38 +08:00
connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::busy, this, [=](bool isBusy) {
QList<QAbstractButton *> list = this->m_funcGroup->buttons();
2022-01-21 13:49:13 +08:00
bool enabled = !isBusy;
2021-11-17 13:23:38 +08:00
for (QAbstractButton * button : list) {
2022-01-21 13:49:13 +08:00
button->setEnabled(enabled);
2021-11-17 13:23:38 +08:00
}
});
2021-09-16 16:05:46 +08:00
m_leftSideBarVLayout->addSpacing(8);
m_leftSideBarVLayout->addStretch();
2022-02-15 16:51:03 +08:00
m_personalQgsettings = nullptr;
if (QGSettings::isSchemaInstalled(PERSONALSIE_SCHEMA)) {
m_personalQgsettings = new QGSettings(PERSONALSIE_SCHEMA, QByteArray(), this);
m_transparency = m_personalQgsettings->get(PERSONALSIE_TRAN_KEY).toDouble();
connect(m_personalQgsettings,&QGSettings::changed,this,[=](QString changedKey) { //监听透明度变化
if (changedKey == CONTAIN_PERSONALSIE_TRAN_KEY) {
m_transparency = m_personalQgsettings->get(PERSONALSIE_TRAN_KEY).toDouble();
2022-02-16 17:47:06 +08:00
// this->setWindowOpacity(m_transparency);
2022-02-15 16:51:03 +08:00
this->repaint();
}
});
}
2021-09-16 16:05:46 +08:00
}
LeftsiderbarWidget::~LeftsiderbarWidget()
{
}
void LeftsiderbarWidget::paintEvent(QPaintEvent *event)
{
2021-09-23 11:21:58 +08:00
Q_UNUSED(event);
2022-02-16 17:47:06 +08:00
2021-09-16 16:05:46 +08:00
QStyleOption opt;
opt.init(this);
QPainter p(this);
p.setPen(Qt::NoPen);
2022-02-16 17:47:06 +08:00
QColor color = palette().color(QPalette::Window);
if (m_parent != nullptr) {
color = m_parent->palette().color(QPalette::Window);
}
2022-02-15 16:51:03 +08:00
color.setAlphaF(m_transparency);
2021-09-16 16:05:46 +08:00
QPalette pal(this->palette());
2022-02-15 16:51:03 +08:00
pal.setColor(QPalette::Window, QColor(color));
2021-09-16 16:05:46 +08:00
this->setPalette(pal);
2022-02-15 16:51:03 +08:00
QBrush brush = QBrush(color);
2021-09-16 16:05:46 +08:00
p.setBrush(brush);
p.drawRoundedRect(opt.rect,0,0);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}