Skip to content

Commit

Permalink
Merge pull request #30 from Davide-sd/master
Browse files Browse the repository at this point in the history
V0.4.7
  • Loading branch information
kupiqu authored Sep 11, 2019
2 parents 737476c + 84802a3 commit cfa14d1
Show file tree
Hide file tree
Showing 10 changed files with 437 additions and 113 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

project(sierrabreezeenhanced)
set(PROJECT_VERSION "0.4.6")
set(PROJECT_VERSION "0.4.7")
set(PROJECT_VERSION_MAJOR 0)

cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
Expand Down
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
V0.4.7
---------

* Added a new style
* Added `Button horizontal padding` in the settings: when using "high" value of corner radius it may be useful to move the buttons a little bit more toward the inside.
* Aligned a few items in the General tab of the Settings

V0.4.6
---------

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SierraBreezeEnhanced is a fork of BreezeEnhanced decoration with the following c
* application menu button is considered special and stays as in vanilla breeze.
* no more option for non macOS-like buttons as it doesn't apply anymore.
* added, however, an option to either choose active vs. inactive style (default), always active style (also for non-active windows), or inactive style (also for the active window).
* horizontal padding to better adjust the button position in case of use of rounded corners.

## Credits:

Expand Down Expand Up @@ -42,3 +43,4 @@ sudo apt install sierrabreezeenhanced

![Active Buttons](screenshots/ActiveButtons.gif?raw=true "Active Buttons")
![Inactive Buttons](screenshots/InactiveButtons.gif?raw=true "Inactive Buttons")
![Inactive Buttons](screenshots/symbol-style.gif?raw=true "Symbol Style")
354 changes: 354 additions & 0 deletions breezebutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ namespace Breeze
drawIconAdwaitaStyle( painter );
else if ( d && ( d->internalSettings()->buttonStyle() == 5 || d->internalSettings()->buttonStyle() == 6 || d->internalSettings()->buttonStyle() == 7 ) )
drawIconDarkAuroraeStyle( painter );
else if ( d && d->internalSettings()->buttonStyle() == 8 )
drawIconSymbolStyle( painter );
else
drawIcon( painter );

Expand Down Expand Up @@ -1420,6 +1422,358 @@ namespace Breeze
}
}

//__________________________________________________________________
void Button::drawIconSymbolStyle( QPainter *painter ) const
{
painter->setRenderHints( QPainter::Antialiasing );

/*
scale painter so that its window matches QRect( -1, -1, 20, 20 )
this makes all further rendering and scaling simpler
all further rendering is preformed inside QRect( 0, 0, 18, 18 )
*/
painter->translate( geometry().topLeft() );

const qreal width( m_iconSize.width() );
painter->scale( width/20, width/20 );
painter->translate( 1, 1 );

auto d = qobject_cast<Decoration*>( decoration() );
// bool inactiveWindow( d && !d->client().data()->isActive() );
// bool useActiveButtonStyle( d && d->internalSettings()->buttonStyle() == 1 );
// bool useInactiveButtonStyle( d && d->internalSettings()->buttonStyle() == 2 );
bool isMatchTitleBarColor( d && d->internalSettings()->matchColorForTitleBar() );

// const QColor darkSymbolColor( ( inactiveWindow && isMatchTitleBarColor ) ? QColor(81, 102, 107) : QColor(34, 45, 50) );
// const QColor lightSymbolColor( ( inactiveWindow && isMatchTitleBarColor ) ? QColor(192, 193, 194) : QColor(250, 251, 252) );

// // symbols color

// QColor symbolColor( this->autoColor( inactiveWindow, useActiveButtonStyle, useInactiveButtonStyle, isMatchTitleBarColor, darkSymbolColor, lightSymbolColor ) );

// don't really want to invest time to update autoColor to deal with inactiveWindow=True and qGray(titleBarColor.rgb()) > 128
// which is causing lightSymbolColor to be used on inactive windows... Therefore, alway use darkSymbolColor.

const QColor darkSymbolColor = QColor(34, 45, 50);
const QColor lightSymbolColor = QColor(250, 251, 252);
QColor symbolColor = darkSymbolColor;

// symbols pen

QPen symbol_pen( symbolColor );
symbol_pen.setJoinStyle( Qt::MiterJoin );
symbol_pen.setWidthF( 1.7*qMax((qreal)1.0, 20/width ) );

switch( type() )
{

case DecorationButtonType::Close:
{
QColor button_color = QColor( 242, 80, 86 );
button_color.setAlpha( button_color.alpha()*m_opacity );
painter->setPen( Qt::NoPen );
painter->setBrush( button_color );

qreal r = static_cast<qreal>(7)
+ static_cast<qreal>(2) * m_animation->currentValue().toReal();
QPointF c(static_cast<qreal>(9), static_cast<qreal>(9));
painter->drawEllipse( c, r, r );
painter->setBrush( Qt::NoBrush );

button_color.setAlpha( 255 );
QColor mycolor = this->mixColors(button_color, symbolColor, m_opacity);
symbol_pen.setColor(mycolor);
painter->setPen( symbol_pen );
// it's a cross
painter->drawLine( QPointF( 6, 6 ), QPointF( 12, 12 ) );
painter->drawLine( QPointF( 6, 12 ), QPointF( 12, 6 ) );

break;
}

case DecorationButtonType::Maximize:
{
QColor button_color = QColor(19, 209, 61);
button_color.setAlpha( button_color.alpha()*m_opacity );
painter->setPen( Qt::NoPen );
painter->setBrush( button_color );

qreal r = static_cast<qreal>(7)
+ static_cast<qreal>(2) * m_animation->currentValue().toReal();
QPointF c(static_cast<qreal>(9), static_cast<qreal>(9));
painter->drawEllipse( c, r, r );
painter->setBrush( Qt::NoBrush );
painter->setPen( Qt::NoPen );

button_color.setAlpha( 255 );
QColor mycolor = this->mixColors(button_color, symbolColor, m_opacity);

// two triangles
QPainterPath path1, path2;
if( isChecked() )
{
path1.moveTo(8.5, 9.5);
path1.lineTo(2.5, 9.5);
path1.lineTo(8.5, 15.5);

path2.moveTo(9.5, 8.5);
path2.lineTo(15.5, 8.5);
path2.lineTo(9.5, 2.5);
}
else
{
path1.moveTo(5, 13);
path1.lineTo(11, 13);
path1.lineTo(5, 7);

path2.moveTo(13, 5);
path2.lineTo(7, 5);
path2.lineTo(13, 11);
}

painter->fillPath(path1, QBrush(mycolor));
painter->fillPath(path2, QBrush(mycolor));

break;
}

case DecorationButtonType::Minimize:
{
QColor button_color = QColor(252, 190, 7);
button_color.setAlpha( button_color.alpha()*m_opacity );
painter->setPen( Qt::NoPen );
painter->setBrush( button_color );

qreal r = static_cast<qreal>(7)
+ static_cast<qreal>(2) * m_animation->currentValue().toReal();
QPointF c(static_cast<qreal>(9), static_cast<qreal>(9));
painter->drawEllipse( c, r, r );
painter->setBrush( Qt::NoBrush );

button_color.setAlpha( 255 );
QColor mycolor = this->mixColors(button_color, symbolColor, m_opacity);
symbol_pen.setColor(mycolor);
painter->setPen( symbol_pen );
// it's a horizontal line
painter->drawLine( QPointF( 5, 9 ), QPointF( 13, 9 ) );

break;
}

case DecorationButtonType::OnAllDesktops:
{
QColor button_color = QColor(125, 209, 200);
if ( !isChecked() )
button_color.setAlpha( button_color.alpha()*m_opacity );
painter->setPen( Qt::NoPen );
painter->setBrush( button_color );

qreal r = static_cast<qreal>(7)
+ static_cast<qreal>(2) * m_animation->currentValue().toReal();
QPointF c(static_cast<qreal>(9), static_cast<qreal>(9));
painter->drawEllipse( c, r, r );
painter->setBrush( Qt::NoBrush );

button_color.setAlpha( 255 );
QColor mycolor = symbolColor;
if ( !isChecked() )
mycolor = this->mixColors(button_color, symbolColor, m_opacity);
symbol_pen.setColor(mycolor);
// painter->setPen( symbol_pen );
painter->setPen( Qt::NoPen );
painter->setBrush(QBrush(mycolor));
painter->drawEllipse( QRectF( 6, 6, 6, 6 ) );

break;
}

case DecorationButtonType::Shade:
{
QColor button_color = QColor(204, 176, 213);
button_color.setAlpha( button_color.alpha()*m_opacity );
painter->setPen( Qt::NoPen );
painter->setBrush( button_color );

qreal r = static_cast<qreal>(7)
+ static_cast<qreal>(2) * m_animation->currentValue().toReal();
QPointF c(static_cast<qreal>(9), static_cast<qreal>(9));
painter->drawEllipse( c, r, r );
painter->setBrush( Qt::NoBrush );

button_color.setAlpha( 255 );
QColor mycolor = this->mixColors(button_color, symbolColor, m_opacity);
symbol_pen.setColor(mycolor);
painter->setPen( symbol_pen );
// it's a triangle with a dash
if (isChecked())
{
painter->setPen( symbol_pen );
painter->drawLine( QPointF( 6, 12 ), QPointF( 12, 12 ) );
painter->setPen( Qt::NoPen );
QPainterPath path;
path.moveTo(9, 11);
path.lineTo(5, 6);
path.lineTo(13, 6);
painter->fillPath(path, QBrush(mycolor));

}
else {
painter->setPen( symbol_pen );
painter->drawLine( QPointF( 6, 6 ), QPointF( 12, 6 ) );
painter->setPen( Qt::NoPen );
QPainterPath path;
path.moveTo(9, 7);
path.lineTo(5, 12);
path.lineTo(13, 12);
painter->fillPath(path, QBrush(mycolor));
}

break;

}

case DecorationButtonType::KeepBelow:
{
QColor button_color = QColor(255, 137, 241);
if ( !isChecked() )
button_color.setAlpha( button_color.alpha()*m_opacity );
painter->setPen( Qt::NoPen );
painter->setBrush( button_color );

qreal r = static_cast<qreal>(7)
+ static_cast<qreal>(2) * m_animation->currentValue().toReal();
QPointF c(static_cast<qreal>(9), static_cast<qreal>(9));
painter->drawEllipse( c, r, r );
painter->setBrush( Qt::NoBrush );

button_color.setAlpha( 255 );
QColor mycolor = symbolColor;
if ( !isChecked() )
mycolor = this->mixColors(button_color, symbolColor, m_opacity);
painter->setPen( Qt::NoPen );

// it's a downward pointing triangle
QPainterPath path;
path.moveTo(9, 12);
path.lineTo(5, 6);
path.lineTo(13, 6);
painter->fillPath(path, QBrush(mycolor));

break;

}

case DecorationButtonType::KeepAbove:
{
QColor button_color = QColor(135, 206, 249);
if ( !isChecked() )
button_color.setAlpha( button_color.alpha()*m_opacity );
painter->setPen( Qt::NoPen );
painter->setBrush( button_color );

qreal r = static_cast<qreal>(7)
+ static_cast<qreal>(2) * m_animation->currentValue().toReal();
QPointF c(static_cast<qreal>(9), static_cast<qreal>(9));
painter->drawEllipse( c, r, r );
painter->setBrush( Qt::NoBrush );

button_color.setAlpha( 255 );
QColor mycolor = symbolColor;
if ( !isChecked() )
mycolor = this->mixColors(button_color, symbolColor, m_opacity);
painter->setPen( Qt::NoPen );

// it's a upward pointing triangle
QPainterPath path;
path.moveTo(9, 6);
path.lineTo(5, 12);
path.lineTo(13, 12);
painter->fillPath(path, QBrush(mycolor));

break;
}

case DecorationButtonType::ApplicationMenu:
{
auto d = qobject_cast<Decoration*>( decoration() );

const QColor matchedTitleBarColor(d->client().data()->palette().color(QPalette::Window));

const QColor titleBarColor ( isMatchTitleBarColor ? matchedTitleBarColor : d->titleBarColor() );

QColor menuSymbolColor;
if ( qGray(titleBarColor.rgb()) > 128 )
menuSymbolColor = darkSymbolColor;
else
menuSymbolColor = lightSymbolColor;

QPen menuSymbol_pen( menuSymbolColor );
menuSymbol_pen.setJoinStyle( Qt::MiterJoin );
menuSymbol_pen.setWidthF( 1.7*qMax((qreal)1.0, 20/width ) );

painter->setPen( menuSymbol_pen );

painter->drawLine( QPointF( 3.5, 5 ), QPointF( 14.5, 5 ) );
painter->drawLine( QPointF( 3.5, 9 ), QPointF( 14.5, 9 ) );
painter->drawLine( QPointF( 3.5, 13 ), QPointF( 14.5, 13 ) );

break;
}

case DecorationButtonType::ContextHelp:
{
QColor button_color = QColor(102, 156, 246);
button_color.setAlpha( button_color.alpha()*m_opacity );
painter->setPen( Qt::NoPen );
painter->setBrush( button_color );

qreal r = static_cast<qreal>(7)
+ static_cast<qreal>(2) * m_animation->currentValue().toReal();
QPointF c(static_cast<qreal>(9), static_cast<qreal>(9));
painter->drawEllipse( c, r, r );
painter->setBrush( Qt::NoBrush );

button_color.setAlpha( 255 );
QColor mycolor = this->mixColors(button_color, symbolColor, m_opacity);
symbol_pen.setColor(mycolor);
painter->setPen( symbol_pen );
// it's a question mark
QPainterPath path;
path.moveTo( 6, 6 );
path.arcTo( QRectF( 5.5, 4, 7.5, 4.5 ), 180, -180 );
path.cubicTo( QPointF(11, 9), QPointF( 9, 6 ), QPointF( 9, 10 ) );
painter->drawPath( path );
painter->drawPoint( 9, 13 );

break;
}

default: break;
}
}

//__________________________________________________________________
// https://stackoverflow.com/questions/25514812/how-to-animate-color-of-qbrush
QColor Button::mixColors(const QColor &cstart, const QColor &cend, qreal progress) const
{
int sh = cstart.hsvHue();
int eh = cend.hsvHue();
int ss = cstart.hsvSaturation();
int es = cend.hsvSaturation();
int sv = cstart.value();
int ev = cend.value();
int hr = qAbs( sh - eh );
int sr = qAbs( ss - es );
int vr = qAbs( sv - ev );
int dirh = sh > eh ? -1 : 1;
int dirs = ss > es ? -1 : 1;
int dirv = sv > ev ? -1 : 1;

return QColor::fromHsv( sh + dirh * progress * hr,
ss + dirs * progress * sr,
sv + dirv * progress * vr);
}

//__________________________________________________________________
QColor Button::foregroundColor() const
{
Expand Down
Loading

0 comments on commit cfa14d1

Please sign in to comment.