引入sdk:左边栏

This commit is contained in:
zhaominyong 2022-05-06 17:58:37 +08:00
parent 15cccd834a
commit a196e58c4f
4 changed files with 36 additions and 35 deletions

View File

@ -12,7 +12,8 @@
#define CONTAIN_PERSONALSIE_TRAN_KEY "transparency" #define CONTAIN_PERSONALSIE_TRAN_KEY "transparency"
LeftsiderbarWidget::LeftsiderbarWidget(QWidget *parent, StartMode mode) LeftsiderbarWidget::LeftsiderbarWidget(QWidget *parent, StartMode mode)
: QWidget(parent) : QWidget(parent),
m_navigationBar(nullptr)
{ {
m_parent = parent; m_parent = parent;
m_mode = mode; m_mode = mode;
@ -65,49 +66,49 @@ void LeftsiderbarWidget::initUi()
m_deplayFuncs << "BACKUP_SYSTEM" << "RESTORE_SYSTEM" << "BACKUP_DATA" << "RESTORE_DATA" << "OPERATION_LOG" << "GHOST_IMAGE"; m_deplayFuncs << "BACKUP_SYSTEM" << "RESTORE_SYSTEM" << "BACKUP_DATA" << "RESTORE_DATA" << "OPERATION_LOG" << "GHOST_IMAGE";
} }
m_funcGroup = new QButtonGroup(this); m_idxToFunctype.clear();
int index = 0;
m_navigationBar = new KNavigationBar(this);
FuncTypeConverter kvConverter; FuncTypeConverter kvConverter;
for (int type = 0; type < funcNum; ++type) { for (int type = 0; type < funcNum; ++type) {
QString mnameString = kvConverter.keycodeTokeystring(type); //设置TEXT QString mnameString = kvConverter.keycodeTokeystring(type); //设置TEXT
if (!m_deplayFuncs.contains(mnameString)) if (!m_deplayFuncs.contains(mnameString))
continue ; continue ;
QStandardItem * item = new QStandardItem;
QString themeIconName = kvConverter.keycodeToThemeIconString(type); QString themeIconName = kvConverter.keycodeToThemeIconString(type);
QString mnamei18nString = kvConverter.keycodeTokeyi18nstring(type); //设置TEXT QString mnamei18nString = kvConverter.keycodeTokeyi18nstring(type); //设置TEXT
MyIconButton *funcButton = new MyIconButton(this);
QString btnName = mnameString;
funcButton->setObjectName(btnName);
funcButton->setFixedSize(this->width() - 20, 36);
funcButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
funcButton->setDesplayText(mnamei18nString);
funcButton->setFlat(true);
QString defaultIconName(":/symbos/"); QString defaultIconName(":/symbos/");
defaultIconName += themeIconName; defaultIconName += themeIconName;
defaultIconName += ".png"; defaultIconName += ".png";
funcButton->setThemeIcon(themeIconName, defaultIconName); QIcon icon = QIcon::fromTheme(themeIconName, QIcon(defaultIconName));
funcButton->setToolTip(mnamei18nString); item->setIcon(icon);
funcButton->setCheckable(true); item->setText(mnamei18nString);
connect(funcButton, &MyIconButton::clicked, [=](bool checked) { item->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
if (checked) item->setToolTip(mnamei18nString);
emit this->selected(type); item->setCheckable(true);
}); m_navigationBar->addItem(item);
m_funcGroup->addButton(funcButton, type); m_idxToFunctype.insert(index, type);
QHBoxLayout * hLayout = new QHBoxLayout; m_functypeToIdx.insert(type, index);
hLayout->setContentsMargins(10, 0, 10, 0); ++index;
hLayout->addWidget(funcButton);
m_leftSideBarVLayout->addLayout(hLayout);
} }
connect(m_navigationBar->listview(), &QListView::clicked, [=](const QModelIndex &index) {
int row = index.row();
emit this->selected(row);
});
connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::busy, this, [=](bool isBusy) { connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::busy, this, [=](bool isBusy) {
QList<QAbstractButton *> list = this->m_funcGroup->buttons();
bool enabled = !isBusy; bool enabled = !isBusy;
for (QAbstractButton * button : list) { this->m_navigationBar->setEnabled(enabled);
button->setEnabled(enabled);
}
}); });
QHBoxLayout * hbarLayout = new QHBoxLayout;
hbarLayout->setContentsMargins(10, 0, 10, 0);
hbarLayout->addWidget(m_navigationBar);
m_leftSideBarVLayout->addLayout(hbarLayout);
m_leftSideBarVLayout->addSpacing(8); m_leftSideBarVLayout->addSpacing(8);
m_leftSideBarVLayout->addStretch(); m_leftSideBarVLayout->addStretch();
} }
@ -124,13 +125,7 @@ void LeftsiderbarWidget::setCheckedFunc(int func_type)
if (!m_deplayFuncs.contains(mnameString)) if (!m_deplayFuncs.contains(mnameString))
return ; return ;
QList<QAbstractButton *> list = this->m_funcGroup->buttons(); m_navigationBar->listview()->setCurrentIndex(m_navigationBar->model()->index(m_functypeToIdx.value(func_type), 0));
for (QAbstractButton * button : list) {
if (button->objectName() == mnameString) {
button->setChecked(true);
break ;
}
}
} }
void LeftsiderbarWidget::paintEvent(QPaintEvent *event) void LeftsiderbarWidget::paintEvent(QPaintEvent *event)

View File

@ -11,6 +11,9 @@
#include "functypeconverter.h" #include "functypeconverter.h"
#include "component/mylabel.h" #include "component/mylabel.h"
#include "component/pixmaplabel.h" #include "component/pixmaplabel.h"
#include "knavigationbar.h"
using namespace kdk;
class LeftsiderbarWidget : public QWidget class LeftsiderbarWidget : public QWidget
{ {
@ -45,6 +48,9 @@ private:
QButtonGroup *m_funcGroup = nullptr; QButtonGroup *m_funcGroup = nullptr;
QStringList m_deplayFuncs; QStringList m_deplayFuncs;
QMap<int, int> m_idxToFunctype;
QMap<int, int> m_functypeToIdx;
KNavigationBar * m_navigationBar;
}; };
#endif // LEFTSIDERBARWIDGET_H #endif // LEFTSIDERBARWIDGET_H

View File

@ -282,7 +282,7 @@ void DataBackup::initSecondWidget()
// 备份路径选择框 // 备份路径选择框
QComboBox* comboSelect = new QComboBox(second); QComboBox* comboSelect = new QComboBox(second);
comboSelect->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); comboSelect->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
QPushButton *buttonBrowse = new QPushButton; KBorderButton *buttonBrowse = new KBorderButton;
buttonBrowse->setText(tr("Browse...")); buttonBrowse->setText(tr("Browse..."));
hlayoutLine2->addWidget(comboSelect); hlayoutLine2->addWidget(comboSelect);
hlayoutLine2->addWidget(buttonBrowse); hlayoutLine2->addWidget(buttonBrowse);

View File

@ -234,7 +234,7 @@ void SystemBackup::initSecondWidget()
// 备份路径选择框 // 备份路径选择框
QComboBox* comboSelect = new QComboBox(second); QComboBox* comboSelect = new QComboBox(second);
comboSelect->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); comboSelect->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
QPushButton *buttonBrowse = new QPushButton; KBorderButton *buttonBrowse = new KBorderButton;
buttonBrowse->setText(tr("Browse...")); buttonBrowse->setText(tr("Browse..."));
hlayoutLine2->addWidget(comboSelect); hlayoutLine2->addWidget(comboSelect);
hlayoutLine2->addWidget(buttonBrowse); hlayoutLine2->addWidget(buttonBrowse);