//__________________________________________________________________________________________________
{
updateButtonSize();
painter.
setRenderHint(QPainter::Antialiasing);
painter.save();//save the painter state
painter.translate(center); //translate coordinate system to center of shape
/*
Test for state changes
*/
if(this->isEnabled())
{
m_hovered ? button_color = b_highlight : button_color = b_color;
if(m_pressed)
button_color = b_highlight.darker(250);
}
else
button_color
= QColor(50,
50,
50);
/*
Rotate painter wrt to button center if the button has been rotated
*/
if(rot_angle != 0)
painter.rotate(-rot_angle);
/*
Draw the button
*/
painter.
setPen(QPen(QBrush(Qt
::black), bw, Qt
::SolidLine, Qt
::RoundCap, Qt
::RoundJoin));
//button outline QLinearGradient gradient
(0., 0., 0., height
());
//button inside color gradient gradient.setColorAt(0., button_color);
painter.setBrush(gradient);
outline.addEllipse(-s_width/2, -s_height/2, s_width, s_height); //button outline shape
/*
Define visible/active region (add 2pixel extra all around)
*/
const qreal b = bw/2 + 4;
QRegion maskedRegion
((int)(-s_width
/2 -b
),
(int)(-s_height
/2 -b
),
(int)( s_width
+b
*2),
(int)( s_height
+b
*2),
QRegion::Ellipse);
if (rot_angle != 0)
{
matrix.rotate(-rot_angle);
maskedRegion = maskedRegion * matrix;
maskedRegion.translate(center.toPoint());
}
else
{
maskedRegion.translate((int)center.x(),(int)center.y());
}
setMask(maskedRegion); //Funny looking after masking, very slow ????
painter.drawPath(outline);
painter.restore();
/*
Add button text if any
*/
if(!text.isNull())
{
QFont font
= this
->font
();
painter.setFont(font);
painter.setPen(t_color);
painter.setOpacity(1.0);
painter.drawText(0, 0, width(), height(), Qt::AlignCenter, text);
}
}
//__________________________________________________________________________________________________
void ShapedButtonEllipse::paintButton(QPaintEvent* )
{
updateButtonSize();
QPointF center = QPointF(width()/2., height()/2.);
QStylePainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.save();//save the painter state
painter.translate(center); //translate coordinate system to center of shape
/*
Test for state changes
*/
QColor button_color;
if(this->isEnabled())
{
m_hovered ? button_color = b_highlight : button_color = b_color;
if(m_pressed)
button_color = b_highlight.darker(250);
}
else
button_color = QColor(50, 50, 50);
/*
Rotate painter wrt to button center if the button has been rotated
*/
if(rot_angle != 0)
painter.rotate(-rot_angle);
/*
Draw the button
*/
painter.setPen(QPen(QBrush(Qt::black), bw, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); //button outline
QLinearGradient gradient(0., 0., 0., height()); //button inside color gradient
gradient.setColorAt(0., button_color);
gradient.setSpread(QGradient::PadSpread);
painter.setBrush(gradient);
QPainterPath outline;
outline.addEllipse(-s_width/2, -s_height/2, s_width, s_height); //button outline shape
/*
Define visible/active region (add 2pixel extra all around)
*/
const qreal b = bw/2 + 4;
QRegion maskedRegion((int)(-s_width/2 -b ), (int)(-s_height/2 -b ),
(int)( s_width +b*2), (int)( s_height +b*2), QRegion::Ellipse);
if (rot_angle != 0)
{
QMatrix matrix;
matrix.rotate(-rot_angle);
maskedRegion = maskedRegion * matrix;
maskedRegion.translate(center.toPoint());
}
else
{
maskedRegion.translate((int)center.x(),(int)center.y());
}
setMask(maskedRegion); //Funny looking after masking, very slow ????
painter.drawPath(outline);
painter.restore();
/*
Add button text if any
*/
QString text = this->text();
if(!text.isNull())
{
QFont font = this->font();
painter.setFont(font);
painter.setPen(t_color);
painter.setOpacity(1.0);
painter.drawText(0, 0, width(), height(), Qt::AlignCenter, text);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks