1 Star 0 Fork 0

tongy boys/material-pri

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
qtmaterialflatbutton.cpp 21.77 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
#include "qtmaterialflatbutton.h"
#include "lib/qtmaterialripple.h"
#include "lib/qtmaterialrippleoverlay.h"
#include "lib/qtmaterialstyle.h"
#include "qtmaterialflatbutton_internal.h"
#include "qtmaterialflatbutton_p.h"
#include <QBitmap>
#include <QEventTransition>
#include <QGraphicsDropShadowEffect>
#include <QIcon>
#include <QMouseEvent>
#include <QPainter>
#include <QPainterPath>
#include <QResizeEvent>
/*!
* \class QtMaterialFlatButtonPrivate
* \internal
*/
/*!
* \internal
*/
QtMaterialFlatButtonPrivate::QtMaterialFlatButtonPrivate(QtMaterialFlatButton *q)
: q_ptr(q)
{
}
/*!
* \internal
*/
QtMaterialFlatButtonPrivate::~QtMaterialFlatButtonPrivate()
{
}
/*!
* \internal
*/
void QtMaterialFlatButtonPrivate::init()
{
Q_Q(QtMaterialFlatButton);
role = Material::Default;
type = Material::ButtonText;
rippleStyle = Material::PositionedRipple;
iconPlacement = Material::LeftIcon;
overlayStyle = Material::NoOverlay;
textAlignment = Qt::AlignHCenter;
fixedRippleRadius = 64;
cornerRadius = 3;
baseOpacity = 0.13;
useThemeColors = true;
useFixedRippleRadius = false;
haloVisible = false;
shadowEffect = nullptr;
shadowStateMachine = nullptr;
q->setStyle(&QtMaterialStyle::instance());
q->setAttribute(Qt::WA_Hover);
q->setMouseTracking(true);
q->setFont(QtMaterialStyle::instance().themeFont(Material::FontButton));
QPainterPath path;
path.addRoundedRect(q->rect(), cornerRadius, cornerRadius);
rippleOverlay = new QtMaterialRippleOverlay(q);
rippleOverlay->setClipPath(path);
rippleOverlay->setClipping(true);
stateMachine = new QtMaterialFlatButtonStateMachine(q);
stateMachine->setupProperties();
stateMachine->startAnimations();
}
/*!
* \internal
*/
void QtMaterialFlatButtonPrivate::initRaiseEffect()
{
Q_Q(QtMaterialFlatButton);
shadowEffect = new QGraphicsDropShadowEffect;
shadowEffect->setBlurRadius(7);
shadowEffect->setOffset(QPointF(0, 2));
shadowEffect->setColor(QColor(0, 0, 0, 75));
if (!q->isEnabled())
{
shadowEffect->setEnabled(false);
}
q->setGraphicsEffect(shadowEffect);
q->setMinimumHeight(42);
q->setBaseOpacity(0.3);
shadowStateMachine = new QStateMachine(q);
shadowNormalState = new QState;
shadowNormalState->assignProperty(shadowEffect, "offset", QPointF(0, 2));
shadowNormalState->assignProperty(shadowEffect, "blurRadius", 7);
shadowStateMachine->addState(shadowNormalState);
shadowPressedState = new QState;
shadowPressedState->assignProperty(shadowEffect, "offset", QPointF(0, 5));
shadowPressedState->assignProperty(shadowEffect, "blurRadius", 29);
shadowStateMachine->addState(shadowPressedState);
QAbstractTransition *transition;
transition = new QEventTransition(q, QEvent::MouseButtonPress);
transition->setTargetState(shadowPressedState);
shadowNormalState->addTransition(transition);
transition = new QEventTransition(q, QEvent::MouseButtonDblClick);
transition->setTargetState(shadowPressedState);
shadowNormalState->addTransition(transition);
transition = new QEventTransition(q, QEvent::MouseButtonRelease);
transition->setTargetState(shadowNormalState);
shadowPressedState->addTransition(transition);
QPropertyAnimation *animation;
animation = new QPropertyAnimation(shadowEffect, "offset", q);
animation->setDuration(100);
shadowStateMachine->addDefaultAnimation(animation);
animation = new QPropertyAnimation(shadowEffect, "blurRadius", q);
animation->setDuration(100);
shadowStateMachine->addDefaultAnimation(animation);
shadowStateMachine->setInitialState(shadowNormalState);
shadowStateMachine->start();
}
void QtMaterialFlatButtonPrivate::removeRaiseEffect()
{
Q_Q(QtMaterialFlatButton);
q->setGraphicsEffect(nullptr);
delete shadowStateMachine;
shadowEffect = nullptr;
shadowStateMachine = nullptr;
}
bool QtMaterialFlatButtonPrivate::isTranparent() const
{
return (type == Material::ButtonText || type == Material::ButtonOutlined);
}
/*!
* \class QtMaterialFlatButton
*/
QtMaterialFlatButton::QtMaterialFlatButton(QWidget *parent)
: QPushButton(parent),
d_ptr(new QtMaterialFlatButtonPrivate(this))
{
d_func()->init();
applyPreset(Material::ButtonTextDefault);
}
QtMaterialFlatButton::QtMaterialFlatButton(const QString &text, Material::ButtonPreset preset, QWidget *parent)
: QPushButton(text, parent),
d_ptr(new QtMaterialFlatButtonPrivate(this))
{
d_func()->init();
applyPreset(preset);
}
QtMaterialFlatButton::QtMaterialFlatButton(const QIcon &icon, const QString &text, Material::ButtonPreset preset, QWidget *parent)
: QPushButton(text, parent),
d_ptr(new QtMaterialFlatButtonPrivate(this))
{
d_func()->init();
applyPreset(preset);
setIcon(icon);
}
QtMaterialFlatButton::~QtMaterialFlatButton()
{
}
void QtMaterialFlatButton::applyPreset(Material::ButtonPreset preset)
{
switch (preset)
{
case Material::ButtonTextDefault:
case Material::ButtonTextPrimary:
case Material::ButtonTextSecondary:
setType(Material::ButtonText);
break;
case Material::ButtonOutlinedDefault:
case Material::ButtonOutlinedPrimary:
case Material::ButtonOutlinedSecondary:
setType(Material::ButtonOutlined);
break;
case Material::ButtonRaisedDefault:
case Material::ButtonRaisedPrimary:
case Material::ButtonRaisedSecondary:
setType(Material::ButtonRaised);
break;
case Material::ButtonFlatDefault:
case Material::ButtonFlatPrimary:
case Material::ButtonFlatSecondary:
setType(Material::ButtonFlat);
break;
}
switch (preset)
{
case Material::ButtonTextDefault:
case Material::ButtonOutlinedDefault:
case Material::ButtonRaisedDefault:
case Material::ButtonFlatDefault:
setRole(Material::Default);
break;
case Material::ButtonTextPrimary:
case Material::ButtonOutlinedPrimary:
case Material::ButtonRaisedPrimary:
case Material::ButtonFlatPrimary:
setRole(Material::Primary);
break;
case Material::ButtonTextSecondary:
case Material::ButtonOutlinedSecondary:
case Material::ButtonRaisedSecondary:
case Material::ButtonFlatSecondary:
setRole(Material::Secondary);
break;
}
}
void QtMaterialFlatButton::setUseThemeColors(bool value)
{
Q_D(QtMaterialFlatButton);
if (d->useThemeColors == value)
{
return;
}
d->useThemeColors = value;
d->stateMachine->setupProperties();
}
bool QtMaterialFlatButton::useThemeColors() const
{
Q_D(const QtMaterialFlatButton);
return d->useThemeColors;
}
void QtMaterialFlatButton::setRole(Material::Role role)
{
Q_D(QtMaterialFlatButton);
d->role = role;
d->stateMachine->setupProperties();
}
Material::Role QtMaterialFlatButton::role() const
{
Q_D(const QtMaterialFlatButton);
return d->role;
}
void QtMaterialFlatButton::setType(Material::ButtonType type)
{
Q_D(QtMaterialFlatButton);
if (type == d->type)
{
return;
}
if (type == Material::ButtonRaised)
{
d->initRaiseEffect();
}
else
{
d->removeRaiseEffect();
}
d->type = type;
d->stateMachine->setupProperties();
}
Material::ButtonType QtMaterialFlatButton::type() const
{
Q_D(const QtMaterialFlatButton);
return d->type;
}
void QtMaterialFlatButton::setForegroundColor(const QColor &color)
{
Q_D(QtMaterialFlatButton);
d->foregroundColor = color;
d->useThemeColors = false;
update();
}
QColor QtMaterialFlatButton::foregroundColor() const
{
Q_D(const QtMaterialFlatButton);
if (d->useThemeColors || !d->foregroundColor.isValid())
{
if (!d->isTranparent())
{
return QtMaterialStyle::instance().themeColor(Material::ColorThemeCanvas);
}
switch (d->role)
{
case Material::Primary:
return QtMaterialStyle::instance().themeColor(Material::ColorThemePrimaryMain);
case Material::Secondary:
return QtMaterialStyle::instance().themeColor(Material::ColorThemeSecondaryMain);
case Material::Default:
default:
return QtMaterialStyle::instance().themeColor(Material::ColorThemeText);
}
}
return d->foregroundColor;
}
void QtMaterialFlatButton::setBackgroundColor(const QColor &color)
{
Q_D(QtMaterialFlatButton);
d->backgroundColor = color;
d->useThemeColors = false;
update();
}
QColor QtMaterialFlatButton::backgroundColor() const
{
Q_D(const QtMaterialFlatButton);
if (d->useThemeColors || !d->backgroundColor.isValid())
{
switch (d->role)
{
case Material::Primary:
return QtMaterialStyle::instance().themeColor(Material::ColorThemePrimaryMain);
case Material::Secondary:
return QtMaterialStyle::instance().themeColor(Material::ColorThemeSecondaryMain);
case Material::Default:
default:
return QtMaterialStyle::instance().themeColor(Material::ColorThemeText);
}
}
return d->backgroundColor;
}
void QtMaterialFlatButton::setOverlayColor(const QColor &color)
{
Q_D(QtMaterialFlatButton);
d->overlayColor = color;
d->useThemeColors = false;
setOverlayStyle(Material::TintedOverlay);
update();
}
QColor QtMaterialFlatButton::overlayColor() const
{
Q_D(const QtMaterialFlatButton);
if (d->useThemeColors || !d->overlayColor.isValid())
{
return foregroundColor();
}
return d->overlayColor;
}
void QtMaterialFlatButton::setDisabledForegroundColor(const QColor &color)
{
Q_D(QtMaterialFlatButton);
d->disabledColor = color;
d->useThemeColors = false;
update();
}
QColor QtMaterialFlatButton::disabledForegroundColor() const
{
Q_D(const QtMaterialFlatButton);
if (d->useThemeColors || !d->disabledColor.isValid())
{
return QtMaterialStyle::instance().themeColor(Material::ColorThemeDisabled1);
}
return d->disabledColor;
}
void QtMaterialFlatButton::setDisabledBackgroundColor(const QColor &color)
{
Q_D(QtMaterialFlatButton);
d->disabledBackgroundColor = color;
d->useThemeColors = false;
update();
}
QColor QtMaterialFlatButton::disabledBackgroundColor() const
{
Q_D(const QtMaterialFlatButton);
if (d->useThemeColors || !d->disabledBackgroundColor.isValid())
{
return QtMaterialStyle::instance().themeColor(Material::ColorThemeDisabled3);
}
return d->disabledBackgroundColor;
}
void QtMaterialFlatButton::setFontSize(qreal size)
{
Q_D(QtMaterialFlatButton);
d->fontSize = size;
QFont f(font());
f.setPointSizeF(size);
setFont(f);
updateGeometry();
update();
}
qreal QtMaterialFlatButton::fontSize() const
{
return font().pointSize();
}
void QtMaterialFlatButton::setHaloVisible(bool visible)
{
Q_D(QtMaterialFlatButton);
d->haloVisible = visible;
update();
}
bool QtMaterialFlatButton::isHaloVisible() const
{
Q_D(const QtMaterialFlatButton);
return d->haloVisible;
}
void QtMaterialFlatButton::setOverlayStyle(Material::OverlayStyle style)
{
Q_D(QtMaterialFlatButton);
d->overlayStyle = style;
update();
}
Material::OverlayStyle QtMaterialFlatButton::overlayStyle() const
{
Q_D(const QtMaterialFlatButton);
return d->overlayStyle;
}
void QtMaterialFlatButton::setRippleStyle(Material::RippleStyle style)
{
Q_D(QtMaterialFlatButton);
d->rippleStyle = style;
}
Material::RippleStyle QtMaterialFlatButton::rippleStyle() const
{
Q_D(const QtMaterialFlatButton);
return d->rippleStyle;
}
void QtMaterialFlatButton::setIconPlacement(Material::ButtonIconPlacement placement)
{
Q_D(QtMaterialFlatButton);
d->iconPlacement = placement;
update();
}
Material::ButtonIconPlacement QtMaterialFlatButton::iconPlacement() const
{
Q_D(const QtMaterialFlatButton);
return d->iconPlacement;
}
void QtMaterialFlatButton::setCornerRadius(qreal radius)
{
Q_D(QtMaterialFlatButton);
d->cornerRadius = radius;
updateClipPath();
update();
}
qreal QtMaterialFlatButton::cornerRadius() const
{
Q_D(const QtMaterialFlatButton);
return d->cornerRadius;
}
void QtMaterialFlatButton::setBaseOpacity(qreal opacity)
{
Q_D(QtMaterialFlatButton);
d->baseOpacity = opacity;
d->stateMachine->setupProperties();
}
qreal QtMaterialFlatButton::baseOpacity() const
{
Q_D(const QtMaterialFlatButton);
return d->baseOpacity;
}
void QtMaterialFlatButton::setCheckable(bool value)
{
Q_D(QtMaterialFlatButton);
d->stateMachine->updateCheckedStatus();
QPushButton::setCheckable(value);
}
void QtMaterialFlatButton::setHasFixedRippleRadius(bool value)
{
Q_D(QtMaterialFlatButton);
d->useFixedRippleRadius = value;
}
bool QtMaterialFlatButton::hasFixedRippleRadius() const
{
Q_D(const QtMaterialFlatButton);
return d->useFixedRippleRadius;
}
void QtMaterialFlatButton::setFixedRippleRadius(qreal radius)
{
Q_D(QtMaterialFlatButton);
d->fixedRippleRadius = radius;
setHasFixedRippleRadius(true);
}
void QtMaterialFlatButton::setTextAlignment(Qt::Alignment alignment)
{
Q_D(QtMaterialFlatButton);
d->textAlignment = alignment;
}
Qt::Alignment QtMaterialFlatButton::textAlignment() const
{
Q_D(const QtMaterialFlatButton);
return d->textAlignment;
}
/*!
* \reimp
*/
QSize QtMaterialFlatButton::sizeHint() const
{
ensurePolished();
QSize labelSize(fontMetrics().size(Qt::TextSingleLine, text()));
int w = labelSize.width() + 20;
int h = labelSize.height();
if (!icon().isNull())
{
w += iconSize().width() + QtMaterialFlatButton::IconPadding;
h = qMax(h, iconSize().height());
}
return QSize(w, h + 20);
}
QtMaterialFlatButton::QtMaterialFlatButton(QtMaterialFlatButtonPrivate &d, QWidget *parent, Material::ButtonPreset preset)
: QPushButton(parent),
d_ptr(&d)
{
d_func()->init();
applyPreset(preset);
}
/*!
* \reimp
*/
void QtMaterialFlatButton::checkStateSet()
{
Q_D(QtMaterialFlatButton);
d->stateMachine->updateCheckedStatus();
QPushButton::checkStateSet();
}
/*!
* \reimp
*/
bool QtMaterialFlatButton::event(QEvent *event)
{
Q_D(QtMaterialFlatButton);
if (d->shadowStateMachine != nullptr && d->shadowEffect != nullptr)
{
if (QEvent::EnabledChange == event->type())
{
if (isEnabled())
{
/*if (!d->shadowStateMachine->isRunning())
{
d->shadowStateMachine->start();
}*/
d->shadowEffect->setEnabled(true);
}
else
{
//d->shadowStateMachine->stop();
d->shadowEffect->setEnabled(false);
}
}
}
return QPushButton::event(event);
}
/*!
* \reimp
*/
void QtMaterialFlatButton::mousePressEvent(QMouseEvent *event)
{
Q_D(QtMaterialFlatButton);
if (d->rippleStyle != Material::NoRipple)
{
QPoint pos;
qreal radiusEndValue;
if (d->rippleStyle == Material::CenteredRipple)
{
pos = rect().center();
}
else
{
pos = event->pos();
}
if (d->useFixedRippleRadius)
{
radiusEndValue = d->fixedRippleRadius;
}
else
{
radiusEndValue = static_cast<qreal>(width()) / 2;
}
QtMaterialRipple *ripple = new QtMaterialRipple(pos);
ripple->setRadiusEndValue(radiusEndValue);
ripple->setOpacityStartValue(0.35);
ripple->setColor(foregroundColor());
ripple->radiusAnimation()->setDuration(600);
ripple->opacityAnimation()->setDuration(1300);
d->rippleOverlay->addRipple(ripple);
}
QPushButton::mousePressEvent(event);
}
/*!
* \reimp
*/
void QtMaterialFlatButton::mouseReleaseEvent(QMouseEvent *event)
{
Q_D(QtMaterialFlatButton);
QPushButton::mouseReleaseEvent(event);
d->stateMachine->updateCheckedStatus();
}
/*!
* \reimp
*/
void QtMaterialFlatButton::resizeEvent(QResizeEvent *event)
{
QPushButton::resizeEvent(event);
updateClipPath();
}
/*!
* \reimp
*/
void QtMaterialFlatButton::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)
Q_D(QtMaterialFlatButton);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
const qreal cr = d->cornerRadius;
if (cr > 0)
{
QPainterPath path;
path.addRoundedRect(rect(), cr, cr);
painter.setClipPath(path);
painter.setClipping(true);
}
paintBackground(&painter);
if (d->haloVisible)
{
paintHalo(&painter);
}
painter.setOpacity(1);
painter.setClipping(false);
paintForeground(&painter);
}
/*!
* \internal
*/
void QtMaterialFlatButton::paintBackground(QPainter *painter)
{
Q_D(QtMaterialFlatButton);
const qreal overlayOpacity = d->stateMachine->overlayOpacity();
const qreal checkedProgress = d->stateMachine->checkedOverlayProgress();
if (!d->isTranparent())
{
QBrush brush;
brush.setStyle(Qt::SolidPattern);
if (isEnabled())
{
brush.setColor(backgroundColor());
}
else
{
brush.setColor(disabledBackgroundColor());
}
painter->setOpacity(1);
painter->setBrush(brush);
painter->setPen(Qt::NoPen);
painter->drawRect(rect());
}
if (!isEnabled())
{
return;
}
painter->setPen(Qt::NoPen);
if ((d->overlayStyle != Material::NoOverlay) && (overlayOpacity > 0))
{
QBrush brush;
brush.setStyle(Qt::SolidPattern);
if (d->overlayStyle == Material::TintedOverlay)
{
brush.setColor(overlayColor());
}
else
{
brush.setColor(Qt::gray);
}
painter->setOpacity(overlayOpacity);
painter->setBrush(brush);
painter->drawRect(rect());
}
if (isCheckable() && checkedProgress > 0)
{
QBrush brush;
brush.setStyle(Qt::SolidPattern);
const qreal q = (d->isTranparent()) ? 0.45 : 0.7;
brush.setColor(foregroundColor());
painter->setOpacity(q * checkedProgress);
painter->setBrush(brush);
QRect r(rect());
r.setHeight(static_cast<qreal>(r.height()) * checkedProgress);
painter->drawRect(r);
}
}
/*!
* \internal
*/
void QtMaterialFlatButton::paintHalo(QPainter *painter)
{
Q_D(QtMaterialFlatButton);
const qreal opacity = d->stateMachine->haloOpacity();
const qreal s = d->stateMachine->haloScaleFactor() * d->stateMachine->haloSize();
const qreal radius = static_cast<qreal>(width()) * s;
if (isEnabled() && opacity > 0)
{
QBrush brush;
brush.setStyle(Qt::SolidPattern);
brush.setColor(foregroundColor());
painter->setOpacity(opacity);
painter->setBrush(brush);
painter->setPen(Qt::NoPen);
const QPointF center = rect().center();
painter->drawEllipse(center, radius, radius);
}
}
#define COLOR_INTERPOLATE(CH) (1 - progress) * source.CH() + progress *dest.CH()
/*!
* \internal
*/
void QtMaterialFlatButton::paintForeground(QPainter *painter)
{
Q_D(QtMaterialFlatButton);
if (isEnabled())
{
painter->setPen(foregroundColor());
const qreal progress = d->stateMachine->checkedOverlayProgress();
if (isCheckable() && progress > 0)
{
QColor source = foregroundColor();
QColor dest = (d->isTranparent()) ? Qt::white : backgroundColor();
if (qFuzzyCompare(1, progress))
{
painter->setPen(dest);
}
else
{
painter->setPen(QColor(COLOR_INTERPOLATE(red), COLOR_INTERPOLATE(green), COLOR_INTERPOLATE(blue), COLOR_INTERPOLATE(alpha)));
}
}
}
else
{
painter->setPen(disabledForegroundColor());
}
if (d->type == Material::ButtonOutlined)
{
painter->setBrush(Qt::NoBrush);
painter->drawPath(painter->clipPath());
}
if (icon().isNull())
{
if (d->textAlignment == Qt::AlignLeft)
{
painter->drawText(rect().adjusted(TextPadding, 0, 0, 0), Qt::AlignLeft | Qt::AlignVCenter, text());
}
else
{
painter->drawText(rect(), Qt::AlignHCenter | Qt::AlignVCenter, text());
}
return;
}
QSize iconSize(this->iconSize());
QSize textSize(fontMetrics().size(Qt::TextSingleLine, text()));
QSize base(size() - textSize);
const int iw = iconSize.width() + IconPadding;
QPoint pos((d->textAlignment == Qt::AlignLeft) ? TextPadding : (base.width() - iw) / 2, 0);
QRect textGeometry(pos + QPoint(0, base.height() / 2), textSize);
QRect iconGeometry(pos + QPoint(0, (height() - iconSize.height()) / 2), iconSize);
if (d->iconPlacement == Material::LeftIcon)
{
textGeometry.translate(iw, 0);
}
else
{
iconGeometry.translate(textSize.width() + IconPadding, 0);
}
painter->drawText(textGeometry, Qt::AlignHCenter | Qt::AlignVCenter, text());
QPixmap pixmap = icon().pixmap(iconSize);
QPainter icon(&pixmap);
icon.setCompositionMode(QPainter::CompositionMode_SourceIn);
icon.fillRect(pixmap.rect(), painter->pen().color());
painter->drawPixmap(iconGeometry, pixmap);
}
/*!
* \internal
*/
void QtMaterialFlatButton::updateClipPath()
{
Q_D(QtMaterialFlatButton);
const qreal radius = d->cornerRadius;
QPainterPath path;
path.addRoundedRect(rect(), radius, radius);
d->rippleOverlay->setClipPath(path);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/tongynj/material-pri.git
git@gitee.com:tongynj/material-pri.git
tongynj
material-pri
material-pri
master

搜索帮助