void LineEditButton::setRotationEnable(bool enable)
{
if (enable) {
m_animator = new QPropertyAnimation(this);
m_animator->setTargetObject(this);
m_animator->setStartValue(0);
m_animator->setEndValue(360);
m_animator->setDuration(2000);
m_animator->start();
connect(m_animator, SIGNAL(valueChanged(const QVariant&)), SLOT(update()));
connect(m_animator, SIGNAL(finished()), m_animator, SLOT(start()));
}
else {
m_animator->stop();
delete m_animator;
m_animator = NULL;
}
}
{
Q_UNUSED(event);
initStyleOption(&option);
static QIcon s_emptyIcon;
// draw rest of button
const QPixmap
& pixmap
= option.
icon.
pixmap(16,
16, isEnabled
() ?
QIcon::Disabled : QIcon::Normal);
option.icon = s_emptyIcon;
p.
drawControl(QStyle::CE_PushButton, option
);
p.save();
// rotate
QRect pixmapRect
= style
()->itemPixmapRect
(rect
(), Qt
::AlignCenter, pixmap
);
p.translate(pixmapRect.center());
p.rotate(m_animator ? m_animator->currentValue().toInt() : 0);
p.
drawPixmap(QRect(-8,
-8,
16,
16), pixmap
);
p.restore();
}
void LineEditButton::setRotationEnable(bool enable)
{
if (enable) {
m_animator = new QPropertyAnimation(this);
m_animator->setTargetObject(this);
m_animator->setStartValue(0);
m_animator->setEndValue(360);
m_animator->setDuration(2000);
m_animator->start();
connect(m_animator, SIGNAL(valueChanged(const QVariant&)), SLOT(update()));
connect(m_animator, SIGNAL(finished()), m_animator, SLOT(start()));
}
else {
m_animator->stop();
delete m_animator;
m_animator = NULL;
}
}
void LineEditButton::paintEvent(QPaintEvent* event)
{
Q_UNUSED(event);
QStyleOptionButton option;
initStyleOption(&option);
static QIcon s_emptyIcon;
// draw rest of button
QStylePainter p(this);
const QPixmap& pixmap = option.icon.pixmap(16, 16, isEnabled() ? QIcon::Disabled : QIcon::Normal);
option.icon = s_emptyIcon;
p.drawControl(QStyle::CE_PushButton, option);
p.save();
// rotate
QRect pixmapRect = style()->itemPixmapRect(rect(), Qt::AlignCenter, pixmap);
p.translate(pixmapRect.center());
p.rotate(m_animator ? m_animator->currentValue().toInt() : 0);
p.drawPixmap(QRect(-8, -8, 16, 16), pixmap);
p.restore();
}
To copy to clipboard, switch view to plain text mode
Bookmarks