删除遗漏代码,补充应用菜单

This commit is contained in:
hewenfei 2023-04-10 11:21:02 +08:00
parent add2e6c597
commit 3b22b2bac8
5 changed files with 1 additions and 209 deletions

View File

@ -1,104 +0,0 @@
#include "push_button.h"
PushButton::PushButton(QWidget *parent) : QPushButton(parent)
{
m_btnLayout = new QHBoxLayout(this);
this->setLayout(m_btnLayout);
m_label = new IconLabel(this);
m_btnLayout->addWidget(m_label);
m_label->setAlignment(Qt::AlignCenter);
m_btnLayout->setAlignment(Qt::AlignCenter);
}
void PushButton::setLabel(QPixmap pixmap, int size)
{
m_label->setFixedSize(size, size);
m_label->setIcon(pixmap);
}
PushButton::~PushButton()
{
}
void PushButton::paintEvent(QPaintEvent *e)
{
Q_UNUSED(e);
QStylePainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
QStyleOptionButton option;
initStyleOption(&option);
if (option.state & QStyle::State_Sunken) {
painter.save();
painter.setPen(Qt::NoPen);
painter.setBrush(Qt::white);
if (g_curStyle == "ukui-dark" || g_isFullScreen) {
painter.setOpacity(0.25);
} else {
painter.setOpacity(0.65);
}
painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 6, 6);
painter.restore();
}
if (option.state & QStyle::State_MouseOver) {
painter.save();
painter.setPen(Qt::NoPen);
painter.setBrush(Qt::white);
if (g_curStyle == "ukui-dark" || g_isFullScreen) {
painter.setOpacity(0.1);
} else {
painter.setOpacity(0.35);
}
painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 6, 6);
painter.restore();
}
if (option.state & QStyle::State_On) {
painter.save();
painter.setPen(Qt::NoPen);
painter.setBrush(Qt::white);
if (g_curStyle == "ukui-dark" || g_isFullScreen) {
painter.setOpacity(0.2);
} else {
painter.setOpacity(0.5);
}
painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 6, 6);
painter.restore();
}
if (option.state & QStyle::State_HasFocus) {
painter.save();
QStyleOption opt;
QColor color = opt.palette.color(QPalette::Highlight);
painter.setPen(QPen(color, 2));
painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 6, 6);
painter.restore();
}
}
IconLabel::IconLabel(QWidget *parent)
: QLabel(parent)
{
this->setContentsMargins(0, 0, 0, 0);
}
void IconLabel::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHints(QPainter::SmoothPixmapTransform, true);
painter.drawPixmap(0, 0, m_pixmap);
return QLabel::paintEvent(event);
}
void IconLabel::setIcon(const QPixmap &pixmap)
{
m_pixmap = pixmap;
}

View File

@ -1,44 +0,0 @@
#ifndef PUSHBUTTON_H
#define PUSHBUTTON_H
#include <QObject>
#include <QLabel>
#include <QPushButton>
#include <QStylePainter>
#include <QStyleOption>
#include <QHBoxLayout>
#include "utility.h"
class IconLabel : public QLabel
{
Q_OBJECT
public:
IconLabel(QWidget *parent = nullptr);
void setIcon(const QPixmap &pixmap);
protected:
void paintEvent(QPaintEvent *event) override;
private:
QPixmap m_pixmap;
};
class PushButton : public QPushButton
{
Q_OBJECT
public:
explicit PushButton(QWidget *parent = nullptr);
~PushButton();
void setLabel(QPixmap pixmap, int size);
protected:
void paintEvent(QPaintEvent *e) override;
private:
QHBoxLayout *m_btnLayout = nullptr;
IconLabel *m_label = nullptr;
Q_SIGNALS:
};
#endif // PUSHBUTTON_H

View File

@ -1,34 +0,0 @@
#include "textlabel.h"
#include <QDebug>
TextLabel::TextLabel(QWidget *parent) : QLabel(parent)
{
}
void TextLabel::checkState(bool isChecked)
{
m_isChecked = isChecked;
}
void TextLabel::paintEvent(QPaintEvent *event)
{
if (m_isChecked) {
return QLabel::paintEvent(event);
}
QStylePainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
QStyleOptionFrame option;
initStyleOption(&option);
if (option.state & QStyle::State_HasFocus) {
painter.save();
QStyleOption opt;
QColor color = opt.palette.color(QPalette::Highlight);
painter.setPen(QPen(color, 2));
painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 6, 6);
painter.restore();
}
QLabel::paintEvent(event);
}

View File

@ -1,27 +0,0 @@
#ifndef TEXTLABEL_H
#define TEXTLABEL_H
#include <QObject>
#include <QLabel>
#include <QPaintEvent>
#include <QStylePainter>
#include <QStyleOption>
class TextLabel : public QLabel
{
Q_OBJECT
public:
explicit TextLabel(QWidget *parent = nullptr);
void checkState(bool isChecked);
private:
void paintEvent(QPaintEvent *event) override;
bool m_isChecked = false;
Q_SIGNALS:
};
#endif // TEXTLABEL_H

View File

@ -174,6 +174,7 @@ public:
MenuManager::MenuManager() : d(new MenuManagerPrivate) MenuManager::MenuManager() : d(new MenuManagerPrivate)
{ {
registerMenuProvider(new AppMenuProvider);
loadMenus(); loadMenus();
} }