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)
|
2022-05-06 17:58:37 +08:00
|
|
|
: QWidget(parent),
|
|
|
|
m_navigationBar(nullptr)
|
2021-09-16 16:05:46 +08:00
|
|
|
{
|
2022-02-16 17:47:06 +08:00
|
|
|
m_parent = parent;
|
2022-04-12 11:27:37 +08:00
|
|
|
m_mode = mode;
|
|
|
|
|
|
|
|
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();
|
|
|
|
// this->setWindowOpacity(m_transparency);
|
|
|
|
this->repaint();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LeftsiderbarWidget::initUi()
|
|
|
|
{
|
2022-03-02 11:24:54 +08:00
|
|
|
m_leftSideBarVLayout = new QVBoxLayout;
|
|
|
|
m_leftSideBarVLayout->setObjectName("m_leftSideBarVLayout");
|
2022-04-12 11:27:37 +08:00
|
|
|
m_leftSideBarVLayout->setContentsMargins(0,0,0,0);
|
2021-09-16 16:05:46 +08:00
|
|
|
m_leftSideBarVLayout->setSpacing(5);
|
2022-03-02 11:24:54 +08:00
|
|
|
setLayout(m_leftSideBarVLayout);
|
2021-09-16 16:05:46 +08:00
|
|
|
|
|
|
|
QWidget *titleWidget = new QWidget(this);
|
|
|
|
m_leftSideBarVLayout->addWidget(titleWidget);
|
|
|
|
|
2022-03-02 11:24:54 +08:00
|
|
|
QHBoxLayout * titleLayout = new QHBoxLayout;
|
|
|
|
m_mTitleIcon = new PixmapLabel;
|
|
|
|
m_mTitleIcon->setFixedSize(24, 24);
|
2022-06-29 17:34:08 +08:00
|
|
|
m_mTitleIcon->setThemeIconSchema(THEME_YHKYLIN_BACKUP_TOOLS, ":/images/yhkylin-backup-tools.png");
|
2022-03-02 11:24:54 +08:00
|
|
|
m_titleLabel = new MyLabel;
|
2022-06-15 13:52:02 +08:00
|
|
|
m_titleLabel->setFixedWidth(this->width() - 35);
|
|
|
|
m_titleLabel->setElidedText(tr("Backup & Restore"));
|
|
|
|
if (m_titleLabel->text() != tr("Backup & Restore"))
|
|
|
|
m_titleLabel->setToolTip(tr("Backup & Restore"));
|
2022-04-12 11:27:37 +08:00
|
|
|
m_titleLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
2021-09-16 16:05:46 +08:00
|
|
|
titleWidget->setLayout(titleLayout);
|
|
|
|
titleLayout->addWidget(m_mTitleIcon);
|
|
|
|
titleLayout->addWidget(m_titleLabel);
|
|
|
|
m_leftSideBarVLayout->addSpacing(10);
|
|
|
|
|
|
|
|
// 功能列表
|
|
|
|
int funcNum = FuncTypeConverter::FunType::TOTALMODULES;
|
2022-04-12 11:27:37 +08:00
|
|
|
if (StartMode::livecd == m_mode) {
|
2021-11-17 13:23:38 +08:00
|
|
|
m_deplayFuncs << "BACKUP_SYSTEM" << "RESTORE_SYSTEM";
|
2022-04-12 11:27:37 +08:00
|
|
|
} else if (StartMode::std_user == m_mode) {
|
2021-11-17 13:23:38 +08:00
|
|
|
m_deplayFuncs << "BACKUP_DATA" << "RESTORE_DATA" << "OPERATION_LOG";
|
|
|
|
} else {
|
|
|
|
m_deplayFuncs << "BACKUP_SYSTEM" << "RESTORE_SYSTEM" << "BACKUP_DATA" << "RESTORE_DATA" << "OPERATION_LOG" << "GHOST_IMAGE";
|
|
|
|
}
|
|
|
|
|
2022-05-06 17:58:37 +08:00
|
|
|
m_idxToFunctype.clear();
|
|
|
|
int index = 0;
|
|
|
|
m_navigationBar = new KNavigationBar(this);
|
2021-09-16 16:05:46 +08:00
|
|
|
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 ;
|
|
|
|
|
2022-05-06 17:58:37 +08:00
|
|
|
QStandardItem * item = new QStandardItem;
|
|
|
|
|
2021-09-16 16:05:46 +08:00
|
|
|
QString themeIconName = kvConverter.keycodeToThemeIconString(type);
|
|
|
|
QString mnamei18nString = kvConverter.keycodeTokeyi18nstring(type); //设置TEXT
|
2021-10-13 16:31:58 +08:00
|
|
|
QString defaultIconName(":/symbos/");
|
|
|
|
defaultIconName += themeIconName;
|
2022-05-06 17:58:37 +08:00
|
|
|
QIcon icon = QIcon::fromTheme(themeIconName, QIcon(defaultIconName));
|
|
|
|
item->setIcon(icon);
|
|
|
|
item->setText(mnamei18nString);
|
|
|
|
item->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
2022-06-15 13:52:02 +08:00
|
|
|
// item->setToolTip(mnamei18nString);
|
2022-05-06 17:58:37 +08:00
|
|
|
item->setCheckable(true);
|
|
|
|
m_navigationBar->addItem(item);
|
|
|
|
|
|
|
|
m_idxToFunctype.insert(index, type);
|
|
|
|
m_functypeToIdx.insert(type, index);
|
|
|
|
++index;
|
2021-09-16 16:05:46 +08:00
|
|
|
}
|
2022-05-06 17:58:37 +08:00
|
|
|
connect(m_navigationBar->listview(), &QListView::clicked, [=](const QModelIndex &index) {
|
|
|
|
int row = index.row();
|
2022-05-12 16:58:35 +08:00
|
|
|
int type = this->m_idxToFunctype.value(row);
|
|
|
|
emit this->selected(type);
|
2022-05-06 17:58:37 +08:00
|
|
|
});
|
2021-09-16 16:05:46 +08:00
|
|
|
|
2021-11-17 13:23:38 +08:00
|
|
|
connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::busy, this, [=](bool isBusy) {
|
2022-01-21 13:49:13 +08:00
|
|
|
bool enabled = !isBusy;
|
2022-05-06 17:58:37 +08:00
|
|
|
this->m_navigationBar->setEnabled(enabled);
|
2021-11-17 13:23:38 +08:00
|
|
|
});
|
2021-09-16 16:05:46 +08:00
|
|
|
|
2022-05-06 17:58:37 +08:00
|
|
|
QHBoxLayout * hbarLayout = new QHBoxLayout;
|
|
|
|
hbarLayout->setContentsMargins(10, 0, 10, 0);
|
|
|
|
hbarLayout->addWidget(m_navigationBar);
|
|
|
|
m_leftSideBarVLayout->addLayout(hbarLayout);
|
|
|
|
|
2021-09-16 16:05:46 +08:00
|
|
|
m_leftSideBarVLayout->addSpacing(8);
|
|
|
|
m_leftSideBarVLayout->addStretch();
|
|
|
|
}
|
|
|
|
|
|
|
|
LeftsiderbarWidget::~LeftsiderbarWidget()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-02-22 15:49:57 +08:00
|
|
|
void LeftsiderbarWidget::setCheckedFunc(int func_type)
|
|
|
|
{
|
|
|
|
FuncTypeConverter kvConverter;
|
|
|
|
QString mnameString = kvConverter.keycodeTokeystring(func_type); //设置TEXT
|
|
|
|
if (!m_deplayFuncs.contains(mnameString))
|
|
|
|
return ;
|
|
|
|
|
2022-05-06 17:58:37 +08:00
|
|
|
m_navigationBar->listview()->setCurrentIndex(m_navigationBar->model()->index(m_functypeToIdx.value(func_type), 0));
|
2022-02-22 15:49:57 +08:00
|
|
|
}
|
|
|
|
|
2021-09-16 16:05:46 +08:00
|
|
|
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);
|
|
|
|
}
|