#130485 #130477,修改字母/功能集导航页,禁用按钮样式

This commit is contained in:
lixueman 2022-07-21 11:31:06 +08:00
parent 89ad4de047
commit e9d7c5ac2d
7 changed files with 82 additions and 73 deletions

View File

@ -36,23 +36,11 @@ FunctionClassifyButton::FunctionClassifyButton(int width,
m_iconSize(iconSize),
m_category(category),
m_fullscreen(fullscreen),
m_enabled(enabled),
m_iconLabel(new QLabel),
m_textLabel(new QLabel)
m_enabled(enabled)
{
this->setFlat(true);
this->setFixedSize(m_width, m_height);
this->setFocusPolicy(Qt::NoFocus);
m_iconLabel->setFixedSize(m_iconSize, m_iconSize);
m_textLabel->adjustSize();
m_textLabel->setText(m_category);
m_textLabel->setAlignment(Qt::AlignCenter);
if (m_fullscreen) {
QPalette pe = m_textLabel->palette();
pe.setColor(QPalette::ButtonText, Qt::white);
m_textLabel->setPalette(pe);
}
if (m_fullscreen) {
updateIconState(Normal);
@ -67,12 +55,6 @@ FunctionClassifyButton::FunctionClassifyButton(int width,
this->setCheckable(false);
}
QHBoxLayout *mainlayout = new QHBoxLayout;
mainlayout->setContentsMargins(0, 0, 0, 0);
mainlayout->setSpacing(Style::LeftSpaceIconText);
this->setLayout(mainlayout);
// mainlayout->addWidget(m_iconLabel);
mainlayout->addWidget(m_textLabel);
connect(this, &FunctionClassifyButton::toggled, this, &FunctionClassifyButton::reactToToggle);
connect(this, &FunctionClassifyButton::clicked, this, &FunctionClassifyButton::buttonClickedSlot);
}
@ -115,6 +97,37 @@ void FunctionClassifyButton::paintEvent(QPaintEvent *e)
painter.restore();
}
if (!(option.state & QStyle::State_Enabled)) {
painter.save();
QColor color;
if (!m_fullscreen) {
if ( g_curStyle == "ukui-light") {
color = Qt::black;
} else {
color = Qt::white;
}
color.setAlphaF(0.2);
}
painter.setPen(color);
painter.drawText(option.rect, Qt::AlignCenter, m_category);
painter.restore();
}
if (option.state & QStyle::State_Enabled) {
painter.save();
QColor color;
if ( g_curStyle == "ukui-light") {
color = Qt::black;
} else {
color = Qt::white;
}
color.setAlphaF(0.9);
painter.setPen(color);
painter.drawText(option.rect, Qt::AlignCenter, m_category);
painter.restore();
}
if (m_fullscreen && (option.state & QStyle::State_On)) {
painter.save();
painter.setPen(Qt::NoPen);
@ -265,37 +278,7 @@ void FunctionClassifyButton::updateIconState(const FunctionClassifyButton::State
// }
// pixmap.setDevicePixelRatio(qApp->devicePixelRatio());
// m_iconLabel->setPixmap(pixmap);
updateTextState(state);
// updateTextState(state);
}
void FunctionClassifyButton::updateTextState(const FunctionClassifyButton::State state)
{
// QPalette p= m_textLabel->palette();
switch (state) {
case Enabled:
// p.setColor(QPalette::WindowText,QColor::fromRgbF(1, 1, 1));
// m_textLabel->setStyleSheet("background:transparent; color:rgba(255, 255, 255);");
break;
case Disabled:
// p.setColor(QPalette::WindowText,QColor::fromRgbF(1, 1, 1, 0.25));
// m_textLabel->setStyleSheet("background:transparent; color:rgba(255, 255, 255, 25%);");
break;
case Normal:
// p.setColor(QPalette::WindowText,QColor::fromRgbF(1, 1, 1, 0.50));
// m_textLabel->setStyleSheet("background:transparent; color:rgba(255, 255, 255, 50%);");
break;
case Checked:
// p.setColor(QPalette::WindowText,QColor::fromRgbF(1, 1, 1));
// m_textLabel->setStyleSheet("background:transparent;color:rgba(255, 255, 255);");
break;
default:
break;
}
// p.setColor(QPalette::Window,Qt::transparent);
// m_textLabel->setPalette(p);
}

View File

@ -58,8 +58,6 @@ public:
QString m_category;
bool m_fullscreen;
bool m_enabled;
QLabel *m_iconLabel = nullptr;
QLabel *m_textLabel = nullptr;
State m_state = Checked;
void updateBtnState();
@ -70,7 +68,6 @@ protected:
void leaveEvent(QEvent *e);
void paintEvent(QPaintEvent *e);
void updateIconState(const State state);
void updateTextState(const State state);
Q_SIGNALS:
void buttonClicked();

View File

@ -28,17 +28,17 @@ LetterClassifyButton::LetterClassifyButton(QWidget *parent,
m_fullscreen(fullscreen)
{
this->setFlat(true);
m_letter = letter;
// if (m_fullscreen) {
// QFont font;
// font.setPixelSize(Style::LeftLetterFontSize);
// this->setFont(font);
// QPalette pe = this->palette();
// pe.setColor(QPalette::ButtonText, Qt::white);
// this->setPalette(pe);
// }
if (m_fullscreen) {
QFont font;
font.setPixelSize(Style::LeftLetterFontSize);
this->setFont(font);
QPalette pe = this->palette();
pe.setColor(QPalette::ButtonText, Qt::white);
this->setPalette(pe);
}
this->setText(letter);
// this->setText(letter);
this->setFocusPolicy(Qt::NoFocus);
this->setCheckable(true);
this->setStyleSheet("padding: 0px;");
@ -82,6 +82,37 @@ void LetterClassifyButton::paintEvent(QPaintEvent *e)
painter.restore();
}
if (!(option.state & QStyle::State_Enabled)) {
painter.save();
QColor color;
if (!m_fullscreen) {
if ( g_curStyle == "ukui-light") {
color = Qt::black;
} else {
color = Qt::white;
}
color.setAlphaF(0.2);
}
painter.setPen(color);
painter.drawText(option.rect, Qt::AlignCenter, m_letter);
painter.restore();
}
if (option.state & QStyle::State_Enabled) {
painter.save();
QColor color;
if ( g_curStyle == "ukui-light") {
color = Qt::black;
} else {
color = Qt::white;
}
color.setAlphaF(0.9);
painter.setPen(color);
painter.drawText(option.rect, Qt::AlignCenter, m_letter);
painter.restore();
}
if (m_fullscreen && (option.state & QStyle::State_On)) {
painter.save();
painter.setPen(Qt::NoPen);
@ -118,7 +149,7 @@ void LetterClassifyButton::enterEvent(QEvent *e)
// this->setFixedSize(Style::LeftLetterBtnHeight*2,Style::LeftLetterBtnHeight*2);
tooltip = new LetterToolTip();
QPoint oPoint = this->mapToGlobal(QPoint(this->rect().x() + 35, this->rect().y() - 10));
tooltip->setText(this->text());
tooltip->setText(m_letter);
tooltip->raise();
tooltip->move(oPoint);
tooltip->show();

View File

@ -35,7 +35,7 @@ public:
);
bool is_pressed = false;
QString m_letter = QString();
private:
bool m_fullscreen = false;
LetterToolTip *tooltip = nullptr;

View File

@ -379,7 +379,7 @@ void FullLetterWidget::btnGroupClickedSlot(QAbstractButton *btn)
if (m_btnGroup->id(btn) == m_buttonList.indexOf(button)) {
letterbtn->setChecked(true);
//此处需实现将被选定的字母包含的应用列表移动到applistWid界面最顶端
QString letterstr = letterbtn->text();
QString letterstr = letterbtn->m_letter;
int num = m_letterList.indexOf(letterstr);
if (num != -1) {

View File

@ -76,7 +76,7 @@ void FunctionButtonWidget::initUi()
Q_FOREACH (QAbstractButton *btn, m_buttonList)
{
FunctionClassifyButton *fbtn = qobject_cast<FunctionClassifyButton *>(btn);
fbtn->updateIconState();
fbtn->updateBtnState();
}
});
}
@ -88,9 +88,7 @@ void FunctionButtonWidget::initUi()
void FunctionButtonWidget::functionBtnClickedSlot()
{
FunctionClassifyButton *btn = dynamic_cast<FunctionClassifyButton *>(sender());
QWidget *wid = btn->layout()->itemAt(0)->widget();
QLabel *label = qobject_cast<QLabel *>(wid);
Q_EMIT sendFunctionBtnSignal(label->text());
Q_EMIT sendFunctionBtnSignal(btn->m_category);
}
void FunctionButtonWidget::hideEvent(QHideEvent *event)

View File

@ -47,7 +47,7 @@ void LetterButtonWidget::initUi()
letterlist.append(QString(QChar(letter)));
}
letterlist.append("&&");
letterlist.append("&");
letterlist.append("#");
for (int row = 0; row < 6; row++) {
@ -78,7 +78,7 @@ void LetterButtonWidget::hideEvent(QHideEvent *event)
void LetterButtonWidget::letterBtnClickedSlot()
{
LetterClassifyButton *btn = dynamic_cast<LetterClassifyButton *>(QObject::sender());
QString btnname = btn->text();
QString btnname = btn->m_letter;
Q_EMIT sendLetterBtnSignal(btnname);
}
@ -93,7 +93,7 @@ void LetterButtonWidget::recvLetterBtnList(QStringList list)
for (int col = 0; col < 4; col++) {
QLayoutItem *item = gridLayout->itemAt(row * 4 + col);
LetterClassifyButton *btn = static_cast<LetterClassifyButton *>(item->widget());
QString letterstr = btn->text();
QString letterstr = btn->m_letter;
if (list.indexOf(letterstr.at(0)) == -1) {
btn->setEnabled(false);