use Flag enumeration to describe button position

add horizontal offset for rendering
properly extend horizontal hit area for buttons in maximize mode, padding is preserved, but Fitts law is fullfilled.
wilder-pre-rebase
Hugo Pereira Da Costa 11 years ago
parent 95e084f4ca
commit b1244feb7c
  1. 11
      kdecoration/breezebutton.cpp
  2. 31
      kdecoration/breezebutton.h
  3. 24
      kdecoration/breezedecoration.cpp

@ -53,7 +53,7 @@ namespace Breeze
//__________________________________________________________________
Button::Button(QObject *parent, const QVariantList &args)
: DecorationButton(args.at(0).value<KDecoration2::DecorationButtonType>(), args.at(1).value<Decoration*>(), parent)
, m_standalone(true)
, m_flag(FlagStandalone)
, m_animation( new QPropertyAnimation( this ) )
{}
@ -83,7 +83,10 @@ namespace Breeze
if (!decoration()) return;
painter->save();
painter->translate( 0, m_verticalOffset );
// translate from offset
if( m_flag == FlagFirstInList ) painter->translate( m_offset );
else painter->translate( 0, m_offset.y() );
if (type() == KDecoration2::DecorationButtonType::Menu)
{
@ -112,7 +115,9 @@ namespace Breeze
all further rendering is preformed inside QRect( 0, 0, 18, 18 )
*/
painter->translate( geometry().topLeft() );
painter->scale( geometry().width()/20, geometry().width()/20 );
const int width( geometry().width() - m_offset.x() );
painter->scale( width/20, width/20 );
painter->translate( 1, 1 );
// render background

@ -52,12 +52,33 @@ namespace Breeze
//* create
static Button *create(KDecoration2::DecorationButtonType type, KDecoration2::Decoration *decoration, QObject *parent);
//* flag
enum Flag
{
FlagNone,
FlagStandalone,
FlagFirstInList,
FlagLastInList
};
//* flag
void setFlag( Flag value )
{ m_flag = value; }
//* standalone buttons
bool isStandAlone() const { return m_standalone; }
bool isStandAlone() const { return m_flag == FlagStandalone; }
//* offset
void setOffset( const QPointF& value )
{ m_offset = value; }
//* horizontal offset, for rendering
void setHorizontalOffset( qreal value )
{ m_offset.setX( value ); }
//* vertical offset, for rendering
void setVerticalOffset( int value )
{ m_verticalOffset = value; }
void setVerticalOffset( qreal value )
{ m_offset.setY( value ); }
//*@name active state change animation
//@{
@ -92,13 +113,13 @@ namespace Breeze
QColor backgroundColor( void ) const;
//@}
bool m_standalone = false;
Flag m_flag = FlagNone;
//* active state change animation
QPropertyAnimation *m_animation;
//* vertical offset (for rendering)
int m_verticalOffset = 0;
QPointF m_offset;
//* active state change opacity
qreal m_opacity = 0;

@ -330,7 +330,29 @@ namespace Breeze
foreach( const QPointer<KDecoration2::DecorationButton>& button, m_leftButtons->buttons() + m_rightButtons->buttons() )
{
button.data()->setGeometry( QRectF( QPoint( 0, 0 ), QSizeF( bWidth, bHeight ) ) );
static_cast<Button*>( button.data() )->setVerticalOffset( verticalOffset );
static_cast<Button*>( button.data() )->setOffset( QPointF( 0, verticalOffset ) );
}
if( isMaximized() )
{
// add offsets on the side buttons, to preserve padding, but satisfy Fitts law
const int hOffset = s->smallSpacing()*Metrics::TitleBar_SideMargin;
if( !m_leftButtons->buttons().isEmpty() )
{
auto button = static_cast<Button*>( m_leftButtons->buttons().front().data() );
button->setGeometry( QRectF( QPoint( 0, 0 ), QSizeF( bWidth + hOffset, bHeight ) ) );
button->setFlag( Button::FlagFirstInList );
button->setHorizontalOffset( hOffset );
}
if( !m_rightButtons->buttons().isEmpty() )
{
auto button = static_cast<Button*>( m_rightButtons->buttons().back().data() );
button->setGeometry( QRectF( QPoint( 0, 0 ), QSizeF( bWidth + hOffset, bHeight ) ) );
button->setFlag( Button::FlagLastInList );
button->setHorizontalOffset( hOffset );
}
}
// adjust buttons position

Loading…
Cancel
Save