From a196e58c4f356f10c81e6b38a7c97f66b83bf1b4 Mon Sep 17 00:00:00 2001 From: zhaominyong Date: Fri, 6 May 2022 17:58:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E5=85=A5sdk=EF=BC=9A=E5=B7=A6?= =?UTF-8?q?=E8=BE=B9=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kybackup/leftsiderbarwidget.cpp | 61 +++++++++++++++----------------- kybackup/leftsiderbarwidget.h | 6 ++++ kybackup/module/databackup.cpp | 2 +- kybackup/module/systembackup.cpp | 2 +- 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/kybackup/leftsiderbarwidget.cpp b/kybackup/leftsiderbarwidget.cpp index 4001c34..0948c9e 100755 --- a/kybackup/leftsiderbarwidget.cpp +++ b/kybackup/leftsiderbarwidget.cpp @@ -12,7 +12,8 @@ #define CONTAIN_PERSONALSIE_TRAN_KEY "transparency" LeftsiderbarWidget::LeftsiderbarWidget(QWidget *parent, StartMode mode) - : QWidget(parent) + : QWidget(parent), + m_navigationBar(nullptr) { m_parent = parent; 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_funcGroup = new QButtonGroup(this); + m_idxToFunctype.clear(); + int index = 0; + m_navigationBar = new KNavigationBar(this); FuncTypeConverter kvConverter; for (int type = 0; type < funcNum; ++type) { QString mnameString = kvConverter.keycodeTokeystring(type); //设置TEXT if (!m_deplayFuncs.contains(mnameString)) continue ; + QStandardItem * item = new QStandardItem; + QString themeIconName = kvConverter.keycodeToThemeIconString(type); 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/"); defaultIconName += themeIconName; defaultIconName += ".png"; - funcButton->setThemeIcon(themeIconName, defaultIconName); - funcButton->setToolTip(mnamei18nString); - funcButton->setCheckable(true); - connect(funcButton, &MyIconButton::clicked, [=](bool checked) { - if (checked) - emit this->selected(type); - }); + QIcon icon = QIcon::fromTheme(themeIconName, QIcon(defaultIconName)); + item->setIcon(icon); + item->setText(mnamei18nString); + item->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); + item->setToolTip(mnamei18nString); + item->setCheckable(true); + m_navigationBar->addItem(item); - m_funcGroup->addButton(funcButton, type); - QHBoxLayout * hLayout = new QHBoxLayout; - hLayout->setContentsMargins(10, 0, 10, 0); - hLayout->addWidget(funcButton); - m_leftSideBarVLayout->addLayout(hLayout); + m_idxToFunctype.insert(index, type); + m_functypeToIdx.insert(type, index); + ++index; } + 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) { - QList list = this->m_funcGroup->buttons(); bool enabled = !isBusy; - for (QAbstractButton * button : list) { - button->setEnabled(enabled); - } + this->m_navigationBar->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->addStretch(); } @@ -124,13 +125,7 @@ void LeftsiderbarWidget::setCheckedFunc(int func_type) if (!m_deplayFuncs.contains(mnameString)) return ; - QList list = this->m_funcGroup->buttons(); - for (QAbstractButton * button : list) { - if (button->objectName() == mnameString) { - button->setChecked(true); - break ; - } - } + m_navigationBar->listview()->setCurrentIndex(m_navigationBar->model()->index(m_functypeToIdx.value(func_type), 0)); } void LeftsiderbarWidget::paintEvent(QPaintEvent *event) diff --git a/kybackup/leftsiderbarwidget.h b/kybackup/leftsiderbarwidget.h index 3cc7fc7..bd4a3f9 100755 --- a/kybackup/leftsiderbarwidget.h +++ b/kybackup/leftsiderbarwidget.h @@ -11,6 +11,9 @@ #include "functypeconverter.h" #include "component/mylabel.h" #include "component/pixmaplabel.h" +#include "knavigationbar.h" + +using namespace kdk; class LeftsiderbarWidget : public QWidget { @@ -45,6 +48,9 @@ private: QButtonGroup *m_funcGroup = nullptr; QStringList m_deplayFuncs; + QMap m_idxToFunctype; + QMap m_functypeToIdx; + KNavigationBar * m_navigationBar; }; #endif // LEFTSIDERBARWIDGET_H diff --git a/kybackup/module/databackup.cpp b/kybackup/module/databackup.cpp index 5f3d326..c3c0c57 100755 --- a/kybackup/module/databackup.cpp +++ b/kybackup/module/databackup.cpp @@ -282,7 +282,7 @@ void DataBackup::initSecondWidget() // 备份路径选择框 QComboBox* comboSelect = new QComboBox(second); comboSelect->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); - QPushButton *buttonBrowse = new QPushButton; + KBorderButton *buttonBrowse = new KBorderButton; buttonBrowse->setText(tr("Browse...")); hlayoutLine2->addWidget(comboSelect); hlayoutLine2->addWidget(buttonBrowse); diff --git a/kybackup/module/systembackup.cpp b/kybackup/module/systembackup.cpp index 67803d5..9d1e1b0 100755 --- a/kybackup/module/systembackup.cpp +++ b/kybackup/module/systembackup.cpp @@ -234,7 +234,7 @@ void SystemBackup::initSecondWidget() // 备份路径选择框 QComboBox* comboSelect = new QComboBox(second); comboSelect->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); - QPushButton *buttonBrowse = new QPushButton; + KBorderButton *buttonBrowse = new KBorderButton; buttonBrowse->setText(tr("Browse...")); hlayoutLine2->addWidget(comboSelect); hlayoutLine2->addWidget(buttonBrowse);