Improved rendering of buttons, in sync with breeze style

wilder-pre-rebase
Hugo Pereira Da Costa 11 years ago
parent b62adbe3b5
commit 3af38fef9c
  1. 8
      windec/kdecoration2/breezebutton.cpp
  2. 230
      windec/kdecoration2/breezeimageprovider.cpp
  3. 8
      windec/kdecoration2/breezeimageprovider.h

@ -118,6 +118,10 @@ namespace Breeze
return d->titleBarColor(); return d->titleBarColor();
} else if( ( type() == KDecoration2::DecorationButtonType::KeepBelow || type() == KDecoration2::DecorationButtonType::KeepAbove ) && isChecked() ) {
return d->titleBarColor();
} else if( m_animation->state() == QPropertyAnimation::Running ) { } else if( m_animation->state() == QPropertyAnimation::Running ) {
return KColorUtils::mix( d->fontColor(), d->titleBarColor(), m_opacity ); return KColorUtils::mix( d->fontColor(), d->titleBarColor(), m_opacity );
@ -145,6 +149,10 @@ namespace Breeze
if( type() == KDecoration2::DecorationButtonType::Close ) return QColor(237, 21, 21); if( type() == KDecoration2::DecorationButtonType::Close ) return QColor(237, 21, 21);
else return KColorUtils::mix( d->titleBarColor(), d->fontColor(), 0.3 ); else return KColorUtils::mix( d->titleBarColor(), d->fontColor(), 0.3 );
} else if( ( type() == KDecoration2::DecorationButtonType::KeepBelow || type() == KDecoration2::DecorationButtonType::KeepAbove ) && isChecked() ) {
return d->fontColor();
} else if( m_animation->state() == QPropertyAnimation::Running ) { } else if( m_animation->state() == QPropertyAnimation::Running ) {
if( type() == KDecoration2::DecorationButtonType::Close ) if( type() == KDecoration2::DecorationButtonType::Close )

@ -181,7 +181,32 @@ namespace Breeze
//__________________________________________________________________ //__________________________________________________________________
void ImageProvider::renderButton(QPainter *painter, Breeze::Button *decorationButton) const void ImageProvider::renderButton(QPainter *painter, Breeze::Button *decorationButton) const
{ {
switch (decorationButton->type()) {
// scale painter so that its window matches 18x18
// this makes all further rendering and painting simpler
painter->save();
painter->scale( decorationButton->geometry().width()/18, decorationButton->geometry().height()/18 );
painter->setRenderHints( QPainter::Antialiasing );
// render background
const QColor backgroundColor( decorationButton->backgroundColor() );
if( backgroundColor.isValid() )
{
painter->setPen( Qt::NoPen );
painter->setBrush( backgroundColor );
painter->drawEllipse( QRectF( 0, 0, 18, 18 ) );
}
// setup pen for rendering the mark
QPen pen( decorationButton->foregroundColor() );
pen.setCapStyle( Qt::RoundCap );
pen.setJoinStyle( Qt::MiterJoin );
pen.setWidth(2);
painter->setPen( pen );
painter->setBrush( Qt::NoBrush );
switch (decorationButton->type())
{
case KDecoration2::DecorationButtonType::Close: case KDecoration2::DecorationButtonType::Close:
renderCloseButton(painter, decorationButton); renderCloseButton(painter, decorationButton);
break; break;
@ -195,103 +220,94 @@ namespace Breeze
renderShadeButton(painter, decorationButton); renderShadeButton(painter, decorationButton);
break; break;
case KDecoration2::DecorationButtonType::Minimize: case KDecoration2::DecorationButtonType::Minimize:
drawGenericButtonBackground(painter, decorationButton); renderMinimizeButton( painter, decorationButton );
drawDownArrow(painter, decorationButton);
break; break;
case KDecoration2::DecorationButtonType::KeepBelow: case KDecoration2::DecorationButtonType::KeepBelow:
// TODO: Needs a checked state renderKeepBelowButton( painter, decorationButton );
drawGenericButtonBackground(painter, decorationButton);
drawDownArrow(painter, decorationButton, QPointF(0.0, -2.0));
drawDownArrow(painter, decorationButton, QPointF(0.0, 2.0));
break; break;
case KDecoration2::DecorationButtonType::KeepAbove: case KDecoration2::DecorationButtonType::KeepAbove:
// TODO: Needs a checked state renderKeepAboveButton( painter, decorationButton );
drawGenericButtonBackground(painter, decorationButton);
drawUpArrow(painter, decorationButton, QPointF(0.0, -2.0));
drawUpArrow(painter, decorationButton, QPointF(0.0, 2.0));
break; break;
default: default:
break; break;
} }
painter->restore();
return; return;
} }
//__________________________________________________________________ //__________________________________________________________________
void ImageProvider::renderCloseButton(QPainter *painter, Breeze::Button *decorationButton) const void ImageProvider::renderCloseButton(QPainter *painter, Breeze::Button* ) const
{ {
if (!decorationButton->decoration()) {
return;
}
const QColor backgroundColor( decorationButton->backgroundColor() );
if( backgroundColor.isValid() ) drawBackground(painter, decorationButton, backgroundColor);
// draw the X const qreal penWidth( painter->pen().width()/2 );
QPen pen( decorationButton->foregroundColor() ); painter->drawLine( QPointF( 5 + penWidth, 5 + penWidth ), QPointF( 13 - penWidth, 13 - penWidth ) );
pen.setWidth(2); painter->drawLine( 13 - penWidth, 5 + penWidth, 5 + penWidth, 13 - penWidth );
painter->setPen(pen);
const QSize &size = decorationButton->size().toSize();
painter->translate(size.width() / 2.0, size.height() / 2.0);
painter->rotate(45.0);
painter->drawLine(0, -size.height() / 4, 0, size.height() / 4);
painter->drawLine(-size.width() / 4, 0, size.width() / 4, 0);
} }
//__________________________________________________________________ //__________________________________________________________________
void ImageProvider::renderMaximizeButton(QPainter *painter, Breeze::Button *decorationButton) const void ImageProvider::renderMaximizeButton(QPainter *painter, Breeze::Button *decorationButton) const
{ {
painter->save();
drawGenericButtonBackground(painter, decorationButton);
QPen pen( decorationButton->foregroundColor() ); const qreal penWidth( painter->pen().width()/2 );
if (decorationButton->isChecked()) { if (decorationButton->isChecked())
// restore button {
const qreal width = (decorationButton->size().height() - 5) / 4;
painter->translate(decorationButton->size().width() / 2.0, decorationButton->size().height() / 2.0); QPen pen( painter->pen() );
painter->rotate(45.0); pen.setJoinStyle( Qt::RoundJoin );
pen.setWidth(2); painter->setPen( pen );
painter->setPen(pen);
painter->setBrush(Qt::NoBrush); painter->drawPolygon( QPolygonF()
painter->drawRect(-width, -width, width * 2, width * 2); << QPointF( 3.5 + penWidth, 9 )
<< QPointF( 9, 3.5 + penWidth )
<< QPointF( 14.5 - penWidth, 9 )
<< QPointF( 9, 14.5 - penWidth ) );
} else { } else {
// maximize button
drawUpArrow(painter, decorationButton); painter->drawPolyline( QPolygonF()
<< QPointF( 3.5 + penWidth, 11.5 - penWidth )
<< QPointF( 9, 5.5 + penWidth )
<< QPointF( 14.5 - penWidth, 11.5 - penWidth ) );
} }
painter->restore();
} }
//__________________________________________________________________ //__________________________________________________________________
void ImageProvider::renderOnAllDesktopsButton(QPainter *painter, Breeze::Button *decorationButton) const void ImageProvider::renderOnAllDesktopsButton(QPainter *painter, Breeze::Button *decorationButton) const
{ {
drawGenericButtonBackground(painter, decorationButton); // get foreground
const QColor foregroundColor( decorationButton->foregroundColor() ); const QColor foregroundColor( decorationButton->foregroundColor() );
painter->setPen( Qt::NoPen );
painter->setBrush( foregroundColor );
if( !decorationButton->isChecked()) if( decorationButton->isChecked())
{ {
Decoration *d = qobject_cast<Decoration*>( decorationButton->decoration() ); // outer ring
if( !d ) return; painter->drawEllipse( QRectF( 3, 3, 12, 12 ) );
// center dot
QColor backgroundColor( decorationButton->backgroundColor() ); QColor backgroundColor( decorationButton->backgroundColor() );
if( !backgroundColor.isValid() ) backgroundColor = d->titleBarColor(); Decoration *d = qobject_cast<Decoration*>( decorationButton->decoration() );
if( !backgroundColor.isValid() && d ) backgroundColor = d->titleBarColor();
// on all desktops
painter->setPen(Qt::NoPen);
painter->translate(decorationButton->size().width() / 2.0, decorationButton->size().height() / 2.0);
const int radius = decorationButton->size().width() / 2 - 3;
painter->setBrush( foregroundColor );
painter->drawEllipse(-radius, -radius, radius * 2, radius * 2);
painter->setBrush( backgroundColor ); if( backgroundColor.isValid() )
painter->drawEllipse(-1, -1, 2, 2); {
painter->setBrush( backgroundColor );
painter->drawEllipse( QRectF( 8, 8, 2, 2 ) );
}
} else { } else {
painter->drawRoundedRect( QRectF( 6, 2, 6, 9 ), 1.5, 1.5 );
painter->drawRect( QRectF( 4, 10, 10, 2 ) );
painter->drawRoundRect( QRectF( 8, 12, 2, 4 ) );
} }
} }
@ -299,71 +315,67 @@ namespace Breeze
//__________________________________________________________________ //__________________________________________________________________
void ImageProvider::renderShadeButton(QPainter *painter, Breeze::Button *decorationButton) const void ImageProvider::renderShadeButton(QPainter *painter, Breeze::Button *decorationButton) const
{ {
drawGenericButtonBackground(painter, decorationButton);
painter->save(); const qreal penWidth( painter->pen().width()/2 );
QPen pen( decorationButton->foregroundColor() ); if (decorationButton->isChecked())
pen.setWidth(2); {
painter->setPen(pen);
painter->translate(decorationButton->size().width() / 2.0, decorationButton->size().height() / 2.0); painter->drawLine( 3 + penWidth, 5.5 + penWidth, 15 - penWidth, 5.5+penWidth );
const qreal width = decorationButton->size().width() /2.0 - 3.0; painter->drawPolyline( QPolygonF()
painter->drawLine(-width, -4.0, width, -4.0); << QPointF( 3.5 + penWidth, 8.5 + penWidth )
painter->restore(); << QPointF( 9, 14.5 - penWidth )
if (decorationButton->isChecked()) { << QPointF( 14.5 - penWidth, 8.5 + penWidth ) );
drawDownArrow(painter, decorationButton, QPointF(0.0, 2.0));
} else { } else {
drawUpArrow(painter, decorationButton, QPointF(0.0, 2.0));
painter->drawLine( 3 + penWidth, 5.5 + penWidth, 15 - penWidth, 5.5+penWidth );
painter->drawPolyline( QPolygonF()
<< QPointF( 3.5 + penWidth, 14.5 - penWidth )
<< QPointF( 9, 8.5 + penWidth )
<< QPointF( 14.5 - penWidth, 14.5 - penWidth ) );
} }
}
//__________________________________________________________________ }
void ImageProvider::drawGenericButtonBackground(QPainter *painter, Breeze::Button *decorationButton) const
{
const QColor backgroundColor( decorationButton->backgroundColor() );
if( backgroundColor.isValid() ) drawBackground(painter, decorationButton, backgroundColor );
}
//__________________________________________________________________ //__________________________________________________________________
void ImageProvider::drawBackground(QPainter *painter, Breeze::Button *decorationButton, const QColor &color) const void ImageProvider::renderMinimizeButton(QPainter *painter, Breeze::Button*) const
{ {
painter->save(); const qreal penWidth( painter->pen().width()/2 );
painter->setPen(Qt::NoPen); painter->drawPolyline( QPolygonF()
painter->setBrush(decorationButton->isEnabled() ? color : QColor(color.red(), color.green(), color.blue(), color.alpha() * 0.6)); << QPointF( 3.5 + penWidth, 6.5 + penWidth )
painter->drawEllipse(QRectF(QPointF(0, 0), decorationButton->size())); << QPointF( 9, 12.5 - penWidth )
painter->restore(); << QPointF( 14.5 - penWidth, 6.5 + penWidth ) );
} }
//__________________________________________________________________ //__________________________________________________________________
void ImageProvider::drawDownArrow(QPainter *painter, Breeze::Button *decorationButton, const QPointF &offset) const void ImageProvider::renderKeepBelowButton(QPainter *painter, Breeze::Button *) const
{ {
painter->save(); const qreal penWidth( painter->pen().width()/2 );
QPen pen(decorationButton->foregroundColor()); painter->drawPolyline( QPolygonF()
// TODO: where do the magic values come from? << QPointF( 3.5 + penWidth, 4.5 + penWidth )
const qreal width = (decorationButton->size().height() - 5) / 2; << QPointF( 9, 10.5 - penWidth )
pen.setWidth(2); << QPointF( 14.5 - penWidth, 4.5 + penWidth ) );
painter->setPen(pen);
painter->translate(QPointF(decorationButton->size().width() / 2.0, decorationButton->size().height() / 2.0) + offset + QPointF(0.0, 0.707*width/2.0)); painter->drawPolyline( QPolygonF()
painter->rotate(45.0); << QPointF( 3.5 + penWidth, 8.5 + penWidth )
painter->drawLine(0, -width, 0, 0); << QPointF( 9, 14.5 - penWidth )
painter->rotate(-90.0); << QPointF( 14.5 - penWidth, 8.5 + penWidth ) );
painter->drawLine(0, -width, 0, 0);
painter->restore();
} }
//__________________________________________________________________ //__________________________________________________________________
void ImageProvider::drawUpArrow(QPainter *painter, Breeze::Button *decorationButton, const QPointF &offset) const void ImageProvider::renderKeepAboveButton(QPainter *painter, Breeze::Button *) const
{ {
painter->save(); const qreal penWidth( painter->pen().width()/2 );
QPen pen(decorationButton->foregroundColor()); painter->drawPolyline( QPolygonF()
// TODO: where do the magic values come from? << QPointF( 3.5 + penWidth, 9.5 - penWidth )
const qreal width = (decorationButton->size().height() - 5) / 2; << QPointF( 9, 3.5 + penWidth )
pen.setWidth(2); << QPointF( 14.5 - penWidth, 9.5 - penWidth ) );
painter->setPen(pen);
painter->translate(QPointF(decorationButton->size().width() / 2.0, decorationButton->size().height() / 2.0) + offset - QPointF(0.0, 0.707*width/2.0)); painter->drawPolyline( QPolygonF()
painter->rotate(225.0); << QPointF( 3.5 + penWidth, 13.5 - penWidth )
painter->drawLine(0, 0, 0, -width); << QPointF( 9, 7.5 + penWidth )
painter->rotate(-90.0); << QPointF( 14.5 - penWidth, 13.5 - penWidth ) );
painter->drawLine(0, 0, 0, -width);
painter->restore();
} }
} }

@ -63,13 +63,11 @@ namespace Breeze
void renderOnAllDesktopsButton(QPainter *p, Button *decorationButton) const; void renderOnAllDesktopsButton(QPainter *p, Button *decorationButton) const;
void drawGenericButtonBackground(QPainter *painter, Button *decorationButton) const; void renderMinimizeButton(QPainter *p, Button *decorationButton) const;
void drawBackground(QPainter *painter, Button *decorationButton, const QColor &color) const; void renderKeepBelowButton(QPainter *p, Button *decorationButton) const;
void drawDownArrow(QPainter *painter, Button *decorationButton, const QPointF &offset = QPointF(0.0, 0.0)) const; void renderKeepAboveButton(QPainter *p, Button *decorationButton) const;
void drawUpArrow(QPainter *painter, Button *decorationButton, const QPointF &offset = QPointF(0.0, 0.0)) const;
ColorSettings colorSettings(Button *decorationButton) const; ColorSettings colorSettings(Button *decorationButton) const;

Loading…
Cancel
Save