引入sdk:左边栏
This commit is contained in:
parent
15cccd834a
commit
a196e58c4f
|
@ -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<QAbstractButton *> 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<QAbstractButton *> 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)
|
||||
|
|
|
@ -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<int, int> m_idxToFunctype;
|
||||
QMap<int, int> m_functypeToIdx;
|
||||
KNavigationBar * m_navigationBar;
|
||||
};
|
||||
|
||||
#endif // LEFTSIDERBARWIDGET_H
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue