chore: 格式化ElaWidgetTools代码
This commit is contained in:
@@ -17,44 +17,40 @@ Q_PROPERTY_CREATE_Q_CPP(ElaIconButton, QColor, DarkIconColor);
|
||||
Q_PROPERTY_CREATE_Q_CPP(ElaIconButton, QColor, LightHoverIconColor);
|
||||
Q_PROPERTY_CREATE_Q_CPP(ElaIconButton, QColor, DarkHoverIconColor);
|
||||
Q_PROPERTY_CREATE_Q_CPP(ElaIconButton, bool, IsSelected);
|
||||
ElaIconButton::ElaIconButton(QPixmap pix, QWidget* parent)
|
||||
: QPushButton(parent), d_ptr(new ElaIconButtonPrivate())
|
||||
{
|
||||
ElaIconButton::ElaIconButton(QPixmap pix, QWidget *parent) : QPushButton(parent), d_ptr(new ElaIconButtonPrivate()) {
|
||||
Q_D(ElaIconButton);
|
||||
d->q_ptr = this;
|
||||
d->_iconPix = pix.copy();
|
||||
d->_pHoverAlpha = 0;
|
||||
d->_pOpacity = 1;
|
||||
d->_pLightHoverColor = ElaThemeColor(ElaThemeType::Light, BasicHoverAlpha);
|
||||
d->_pDarkHoverColor = ElaThemeColor(ElaThemeType::Dark, BasicHoverAlpha);
|
||||
d->_pLightIconColor = ElaThemeColor(ElaThemeType::Light, BasicText);
|
||||
d->_pDarkIconColor = ElaThemeColor(ElaThemeType::Dark, BasicText);
|
||||
d->q_ptr = this;
|
||||
d->_iconPix = pix.copy();
|
||||
d->_pHoverAlpha = 0;
|
||||
d->_pOpacity = 1;
|
||||
d->_pLightHoverColor = ElaThemeColor(ElaThemeType::Light, BasicHoverAlpha);
|
||||
d->_pDarkHoverColor = ElaThemeColor(ElaThemeType::Dark, BasicHoverAlpha);
|
||||
d->_pLightIconColor = ElaThemeColor(ElaThemeType::Light, BasicText);
|
||||
d->_pDarkIconColor = ElaThemeColor(ElaThemeType::Dark, BasicText);
|
||||
d->_pLightHoverIconColor = ElaThemeColor(ElaThemeType::Light, BasicText);
|
||||
d->_pDarkHoverIconColor = ElaThemeColor(ElaThemeType::Dark, BasicText);
|
||||
d->_pIsSelected = false;
|
||||
d->_pBorderRadius = 0;
|
||||
d->_themeMode = eTheme->getThemeMode();
|
||||
d->_pDarkHoverIconColor = ElaThemeColor(ElaThemeType::Dark, BasicText);
|
||||
d->_pIsSelected = false;
|
||||
d->_pBorderRadius = 0;
|
||||
d->_themeMode = eTheme->getThemeMode();
|
||||
connect(this, &ElaIconButton::pIsSelectedChanged, this, [=]() { update(); });
|
||||
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) { d->_themeMode = themeMode; });
|
||||
}
|
||||
|
||||
ElaIconButton::ElaIconButton(ElaIconType::IconName awesome, QWidget* parent)
|
||||
: QPushButton(parent), d_ptr(new ElaIconButtonPrivate())
|
||||
{
|
||||
ElaIconButton::ElaIconButton(ElaIconType::IconName awesome, QWidget *parent) : QPushButton(parent), d_ptr(new ElaIconButtonPrivate()) {
|
||||
Q_D(ElaIconButton);
|
||||
d->q_ptr = this;
|
||||
d->_pHoverAlpha = 0;
|
||||
d->_pOpacity = 1;
|
||||
d->_pLightHoverColor = ElaThemeColor(ElaThemeType::Light, BasicHoverAlpha);
|
||||
d->_pDarkHoverColor = ElaThemeColor(ElaThemeType::Dark, BasicHoverAlpha);
|
||||
d->_pLightIconColor = ElaThemeColor(ElaThemeType::Light, BasicText);
|
||||
d->_pDarkIconColor = ElaThemeColor(ElaThemeType::Dark, BasicText);
|
||||
d->q_ptr = this;
|
||||
d->_pHoverAlpha = 0;
|
||||
d->_pOpacity = 1;
|
||||
d->_pLightHoverColor = ElaThemeColor(ElaThemeType::Light, BasicHoverAlpha);
|
||||
d->_pDarkHoverColor = ElaThemeColor(ElaThemeType::Dark, BasicHoverAlpha);
|
||||
d->_pLightIconColor = ElaThemeColor(ElaThemeType::Light, BasicText);
|
||||
d->_pDarkIconColor = ElaThemeColor(ElaThemeType::Dark, BasicText);
|
||||
d->_pLightHoverIconColor = ElaThemeColor(ElaThemeType::Light, BasicText);
|
||||
d->_pDarkHoverIconColor = ElaThemeColor(ElaThemeType::Dark, BasicText);
|
||||
d->_pIsSelected = false;
|
||||
d->_pBorderRadius = 0;
|
||||
d->_themeMode = eTheme->getThemeMode();
|
||||
QFont iconFont = QFont("ElaAwesome");
|
||||
d->_pDarkHoverIconColor = ElaThemeColor(ElaThemeType::Dark, BasicText);
|
||||
d->_pIsSelected = false;
|
||||
d->_pBorderRadius = 0;
|
||||
d->_themeMode = eTheme->getThemeMode();
|
||||
QFont iconFont = QFont("ElaAwesome");
|
||||
iconFont.setPixelSize(15);
|
||||
this->setFont(iconFont);
|
||||
d->_pAwesome = awesome;
|
||||
@@ -63,23 +59,21 @@ ElaIconButton::ElaIconButton(ElaIconType::IconName awesome, QWidget* parent)
|
||||
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) { d->_themeMode = themeMode; });
|
||||
}
|
||||
|
||||
ElaIconButton::ElaIconButton(ElaIconType::IconName awesome, int pixelSize, QWidget* parent)
|
||||
: QPushButton(parent), d_ptr(new ElaIconButtonPrivate())
|
||||
{
|
||||
ElaIconButton::ElaIconButton(ElaIconType::IconName awesome, int pixelSize, QWidget *parent) : QPushButton(parent), d_ptr(new ElaIconButtonPrivate()) {
|
||||
Q_D(ElaIconButton);
|
||||
d->q_ptr = this;
|
||||
d->_pHoverAlpha = 0;
|
||||
d->_pOpacity = 1;
|
||||
d->_pLightHoverColor = ElaThemeColor(ElaThemeType::Light, BasicHoverAlpha);
|
||||
d->_pDarkHoverColor = ElaThemeColor(ElaThemeType::Dark, BasicHoverAlpha);
|
||||
d->_pLightIconColor = ElaThemeColor(ElaThemeType::Light, BasicText);
|
||||
d->_pDarkIconColor = ElaThemeColor(ElaThemeType::Dark, BasicText);
|
||||
d->q_ptr = this;
|
||||
d->_pHoverAlpha = 0;
|
||||
d->_pOpacity = 1;
|
||||
d->_pLightHoverColor = ElaThemeColor(ElaThemeType::Light, BasicHoverAlpha);
|
||||
d->_pDarkHoverColor = ElaThemeColor(ElaThemeType::Dark, BasicHoverAlpha);
|
||||
d->_pLightIconColor = ElaThemeColor(ElaThemeType::Light, BasicText);
|
||||
d->_pDarkIconColor = ElaThemeColor(ElaThemeType::Dark, BasicText);
|
||||
d->_pLightHoverIconColor = ElaThemeColor(ElaThemeType::Light, BasicText);
|
||||
d->_pDarkHoverIconColor = ElaThemeColor(ElaThemeType::Dark, BasicText);
|
||||
d->_pIsSelected = false;
|
||||
d->_pBorderRadius = 0;
|
||||
d->_themeMode = eTheme->getThemeMode();
|
||||
QFont iconFont = QFont("ElaAwesome");
|
||||
d->_pDarkHoverIconColor = ElaThemeColor(ElaThemeType::Dark, BasicText);
|
||||
d->_pIsSelected = false;
|
||||
d->_pBorderRadius = 0;
|
||||
d->_themeMode = eTheme->getThemeMode();
|
||||
QFont iconFont = QFont("ElaAwesome");
|
||||
iconFont.setPixelSize(pixelSize);
|
||||
this->setFont(iconFont);
|
||||
d->_pAwesome = awesome;
|
||||
@@ -88,23 +82,22 @@ ElaIconButton::ElaIconButton(ElaIconType::IconName awesome, int pixelSize, QWidg
|
||||
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) { d->_themeMode = themeMode; });
|
||||
}
|
||||
|
||||
ElaIconButton::ElaIconButton(ElaIconType::IconName awesome, int pixelSize, int fixedWidth, int fixedHeight, QWidget* parent)
|
||||
: QPushButton(parent), d_ptr(new ElaIconButtonPrivate())
|
||||
{
|
||||
ElaIconButton::ElaIconButton(ElaIconType::IconName awesome, int pixelSize, int fixedWidth, int fixedHeight, QWidget *parent)
|
||||
: QPushButton(parent), d_ptr(new ElaIconButtonPrivate()) {
|
||||
Q_D(ElaIconButton);
|
||||
d->q_ptr = this;
|
||||
d->_pHoverAlpha = 0;
|
||||
d->_pOpacity = 1;
|
||||
d->_pLightHoverColor = ElaThemeColor(ElaThemeType::Light, BasicHoverAlpha);
|
||||
d->_pDarkHoverColor = ElaThemeColor(ElaThemeType::Dark, BasicHoverAlpha);
|
||||
d->_pLightIconColor = ElaThemeColor(ElaThemeType::Light, BasicText);
|
||||
d->_pDarkIconColor = ElaThemeColor(ElaThemeType::Dark, BasicText);
|
||||
d->q_ptr = this;
|
||||
d->_pHoverAlpha = 0;
|
||||
d->_pOpacity = 1;
|
||||
d->_pLightHoverColor = ElaThemeColor(ElaThemeType::Light, BasicHoverAlpha);
|
||||
d->_pDarkHoverColor = ElaThemeColor(ElaThemeType::Dark, BasicHoverAlpha);
|
||||
d->_pLightIconColor = ElaThemeColor(ElaThemeType::Light, BasicText);
|
||||
d->_pDarkIconColor = ElaThemeColor(ElaThemeType::Dark, BasicText);
|
||||
d->_pLightHoverIconColor = ElaThemeColor(ElaThemeType::Light, BasicText);
|
||||
d->_pDarkHoverIconColor = ElaThemeColor(ElaThemeType::Dark, BasicText);
|
||||
d->_pIsSelected = false;
|
||||
d->_pBorderRadius = 0;
|
||||
d->_themeMode = eTheme->getThemeMode();
|
||||
QFont iconFont = QFont("ElaAwesome");
|
||||
d->_pDarkHoverIconColor = ElaThemeColor(ElaThemeType::Dark, BasicText);
|
||||
d->_pIsSelected = false;
|
||||
d->_pBorderRadius = 0;
|
||||
d->_themeMode = eTheme->getThemeMode();
|
||||
QFont iconFont = QFont("ElaAwesome");
|
||||
iconFont.setPixelSize(pixelSize);
|
||||
this->setFont(iconFont);
|
||||
d->_pAwesome = awesome;
|
||||
@@ -114,45 +107,30 @@ ElaIconButton::ElaIconButton(ElaIconType::IconName awesome, int pixelSize, int f
|
||||
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) { d->_themeMode = themeMode; });
|
||||
}
|
||||
|
||||
ElaIconButton::~ElaIconButton()
|
||||
{
|
||||
}
|
||||
ElaIconButton::~ElaIconButton() {}
|
||||
|
||||
void ElaIconButton::setAwesome(ElaIconType::IconName awesome)
|
||||
{
|
||||
void ElaIconButton::setAwesome(ElaIconType::IconName awesome) {
|
||||
Q_D(ElaIconButton);
|
||||
d->_pAwesome = awesome;
|
||||
this->setText(QChar((unsigned short)awesome));
|
||||
}
|
||||
|
||||
ElaIconType::IconName ElaIconButton::getAwesome() const
|
||||
{
|
||||
return this->d_ptr->_pAwesome;
|
||||
}
|
||||
ElaIconType::IconName ElaIconButton::getAwesome() const { return this->d_ptr->_pAwesome; }
|
||||
|
||||
void ElaIconButton::setPixmap(QPixmap pix)
|
||||
{
|
||||
void ElaIconButton::setPixmap(QPixmap pix) {
|
||||
Q_D(ElaIconButton);
|
||||
d->_iconPix = pix.copy();
|
||||
}
|
||||
|
||||
bool ElaIconButton::event(QEvent* event)
|
||||
{
|
||||
bool ElaIconButton::event(QEvent *event) {
|
||||
Q_D(ElaIconButton);
|
||||
switch (event->type())
|
||||
{
|
||||
case QEvent::Enter:
|
||||
{
|
||||
if (isEnabled() && !d->_pIsSelected)
|
||||
{
|
||||
d->_isAlphaAnimationFinished = false;
|
||||
QPropertyAnimation* alphaAnimation = new QPropertyAnimation(d, "pHoverAlpha");
|
||||
connect(alphaAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
|
||||
update();
|
||||
});
|
||||
connect(alphaAnimation, &QPropertyAnimation::finished, this, [=]() {
|
||||
d->_isAlphaAnimationFinished = true;
|
||||
});
|
||||
switch (event->type()) {
|
||||
case QEvent::Enter: {
|
||||
if (isEnabled() && !d->_pIsSelected) {
|
||||
d->_isAlphaAnimationFinished = false;
|
||||
QPropertyAnimation *alphaAnimation = new QPropertyAnimation(d, "pHoverAlpha");
|
||||
connect(alphaAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant &value) { update(); });
|
||||
connect(alphaAnimation, &QPropertyAnimation::finished, this, [=]() { d->_isAlphaAnimationFinished = true; });
|
||||
alphaAnimation->setDuration(175);
|
||||
alphaAnimation->setStartValue(d->_pHoverAlpha);
|
||||
alphaAnimation->setEndValue(d->_themeMode == ElaThemeType::Light ? d->_pLightHoverColor.alpha() : d->_pDarkHoverColor.alpha());
|
||||
@@ -160,18 +138,12 @@ bool ElaIconButton::event(QEvent* event)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QEvent::Leave:
|
||||
{
|
||||
if (isEnabled() && !d->_pIsSelected)
|
||||
{
|
||||
d->_isAlphaAnimationFinished = false;
|
||||
QPropertyAnimation* alphaAnimation = new QPropertyAnimation(d, "pHoverAlpha");
|
||||
connect(alphaAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
|
||||
update();
|
||||
});
|
||||
connect(alphaAnimation, &QPropertyAnimation::finished, this, [=]() {
|
||||
d->_isAlphaAnimationFinished = true;
|
||||
});
|
||||
case QEvent::Leave: {
|
||||
if (isEnabled() && !d->_pIsSelected) {
|
||||
d->_isAlphaAnimationFinished = false;
|
||||
QPropertyAnimation *alphaAnimation = new QPropertyAnimation(d, "pHoverAlpha");
|
||||
connect(alphaAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant &value) { update(); });
|
||||
connect(alphaAnimation, &QPropertyAnimation::finished, this, [=]() { d->_isAlphaAnimationFinished = true; });
|
||||
alphaAnimation->setDuration(175);
|
||||
alphaAnimation->setStartValue(d->_pHoverAlpha);
|
||||
alphaAnimation->setEndValue(0);
|
||||
@@ -179,47 +151,41 @@ bool ElaIconButton::event(QEvent* event)
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return QPushButton::event(event);
|
||||
}
|
||||
|
||||
void ElaIconButton::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
void ElaIconButton::paintEvent(QPaintEvent *event) {
|
||||
Q_D(ElaIconButton);
|
||||
QPainter painter(this);
|
||||
painter.save();
|
||||
painter.setOpacity(d->_pOpacity);
|
||||
painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing | QPainter::TextAntialiasing);
|
||||
painter.setPen(Qt::NoPen);
|
||||
if (d->_isAlphaAnimationFinished || d->_pIsSelected)
|
||||
{
|
||||
if (d->_isAlphaAnimationFinished || d->_pIsSelected) {
|
||||
painter.setBrush(d->_pIsSelected ? d->_themeMode == ElaThemeType::Light ? d->_pLightHoverColor : d->_pDarkHoverColor
|
||||
: isEnabled() ? underMouse() ? d->_themeMode == ElaThemeType::Light ? d->_pLightHoverColor : d->_pDarkHoverColor : Qt::transparent
|
||||
: Qt::transparent);
|
||||
}
|
||||
else
|
||||
{
|
||||
: isEnabled()
|
||||
? underMouse() ? d->_themeMode == ElaThemeType::Light ? d->_pLightHoverColor : d->_pDarkHoverColor : Qt::transparent
|
||||
: Qt::transparent);
|
||||
} else {
|
||||
QColor hoverColor = d->_themeMode == ElaThemeType::Light ? d->_pLightHoverColor : d->_pDarkHoverColor;
|
||||
hoverColor.setAlpha(d->_pHoverAlpha);
|
||||
painter.setBrush(hoverColor);
|
||||
}
|
||||
painter.drawRoundedRect(rect(), d->_pBorderRadius, d->_pBorderRadius);
|
||||
// 图标绘制
|
||||
if (!d->_iconPix.isNull())
|
||||
{
|
||||
if (!d->_iconPix.isNull()) {
|
||||
QPainterPath path;
|
||||
path.addEllipse(rect());
|
||||
painter.setClipPath(path);
|
||||
painter.drawPixmap(rect(), d->_iconPix);
|
||||
}
|
||||
else
|
||||
{
|
||||
painter.setPen(isEnabled() ? d->_themeMode == ElaThemeType::Light ? underMouse() ? d->_pLightHoverIconColor : d->_pLightIconColor : underMouse() ? d->_pDarkHoverIconColor
|
||||
: d->_pDarkIconColor
|
||||
} else {
|
||||
painter.setPen(isEnabled() ? d->_themeMode == ElaThemeType::Light ? underMouse() ? d->_pLightHoverIconColor : d->_pLightIconColor
|
||||
: underMouse() ? d->_pDarkHoverIconColor
|
||||
: d->_pDarkIconColor
|
||||
: ElaThemeColor(d->_themeMode, BasicTextDisable));
|
||||
painter.drawText(rect(), Qt::AlignCenter, QChar((unsigned short)d->_pAwesome));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user