100 lines
3.5 KiB
C++
100 lines
3.5 KiB
C++
#include "leftsiderbarwidget.h"
|
||
#include <QDebug>
|
||
#include <QGSettings>
|
||
#include <QStyleOption>
|
||
#include <QPainter>
|
||
#include "../common/mydefine.h"
|
||
#include "component/myiconbutton.h"
|
||
#include <QToolButton>
|
||
|
||
LeftsiderbarWidget::LeftsiderbarWidget(QWidget *parent, StartMode mode)
|
||
: QWidget(parent)
|
||
{
|
||
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();
|
||
m_titleLabel = new MyLabel();
|
||
m_titleLabel->setDeplayText(tr("Backup & Restore"));
|
||
m_titleLabel->setToolTip(tr("Backup & Restore"));
|
||
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))));
|
||
m_titleLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||
m_leftSideBarVLayout->addSpacing(10);
|
||
|
||
// 功能列表
|
||
int funcNum = FuncTypeConverter::FunType::TOTALMODULES;
|
||
if (StartMode::livecd == mode)
|
||
funcNum = 2;
|
||
m_funcGroup = new QButtonGroup(this);
|
||
FuncTypeConverter kvConverter;
|
||
for (int type = 0; type < funcNum; ++type) {
|
||
QString themeIconName = kvConverter.keycodeToThemeIconString(type);
|
||
QString mnamei18nString = kvConverter.keycodeTokeyi18nstring(type); //设置TEXT
|
||
|
||
|
||
MyIconButton *funcButton = new MyIconButton(this);
|
||
QString btnName = "btn" + QString::number(type + 1);
|
||
funcButton->setObjectName(btnName);
|
||
funcButton->setFixedSize(180, 40);
|
||
funcButton->setDesplayText(mnamei18nString);
|
||
QString defaultIconName(":/symbos/");
|
||
defaultIconName += themeIconName;
|
||
defaultIconName += ".png";
|
||
funcButton->setThemeIcon(themeIconName, defaultIconName);
|
||
funcButton->setToolTip(mnamei18nString);
|
||
funcButton->setCheckable(true);
|
||
|
||
// 設置無邊框,跟隨背景色
|
||
funcButton->setFlat(true);
|
||
// 設置了setStyleSheet,不能再跟隨主題,舍弃此种方式
|
||
// 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);
|
||
}
|
||
|
||
|
||
m_leftSideBarVLayout->addSpacing(8);
|
||
|
||
m_leftSideBarVLayout->addStretch();
|
||
}
|
||
|
||
LeftsiderbarWidget::~LeftsiderbarWidget()
|
||
{
|
||
|
||
}
|
||
|
||
void LeftsiderbarWidget::paintEvent(QPaintEvent *event)
|
||
{
|
||
Q_UNUSED(event);
|
||
QStyleOption opt;
|
||
opt.init(this);
|
||
QPainter p(this);
|
||
p.setPen(Qt::NoPen);
|
||
QColor color = palette().color(QPalette::Window);
|
||
color.setAlpha(transparency);
|
||
QPalette pal(this->palette());
|
||
pal.setColor(QPalette::Window,QColor(color));
|
||
this->setPalette(pal);
|
||
QBrush brush =QBrush(color);
|
||
p.setBrush(brush);
|
||
p.drawRoundedRect(opt.rect,0,0);
|
||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
||
}
|