24#include <tqsizepolicy.h>
27#include <kicontheme.h>
28#include <kiconloader.h>
30#include "knotebutton.h"
33KNoteButton::KNoteButton(
const TQString& icon, TQWidget *parent,
const char *name )
34 : TQPushButton( parent, name )
36 setFocusPolicy( TQWidget::NoFocus );
37 setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
41 if ( !icon.isEmpty() )
42 setIconSet( TDEGlobal::iconLoader()->loadIconSet( icon, TDEIcon::Small, 10 ) );
45KNoteButton::~KNoteButton()
49void KNoteButton::enterEvent( TQEvent * )
55void KNoteButton::leaveEvent( TQEvent * )
61TQSize KNoteButton::sizeHint()
const
63 return TQSize( TQPushButton::sizeHint().height(), TQPushButton::sizeHint().height() );
66void KNoteButton::drawButton( TQPainter* p )
68 TQStyle::SFlags flags = TQStyle::Style_Default;
71 flags |= TQStyle::Style_Enabled;
73 flags |= TQStyle::Style_Down;
75 flags |= TQStyle::Style_On;
76 if ( !isFlat() && !isDown() )
77 flags |= TQStyle::Style_Raised;
79 flags |= TQStyle::Style_MouseOver;
81 style().drawPrimitive( TQStyle::PE_ButtonTool, p, rect(), colorGroup(), flags );
85void KNoteButton::drawButtonLabel( TQPainter* p )
87 if ( iconSet() && !iconSet()->isNull() )
89 TQIconSet::Mode mode = TQIconSet::Disabled;
90 TQIconSet::State state = TQIconSet::Off;
93 mode = hasFocus() ? TQIconSet::Active : TQIconSet::Normal;
94 if ( isToggleButton() && isOn() )
95 state = TQIconSet::On;
97 TQPixmap pix = iconSet()->pixmap( TQIconSet::Small, mode, state );
99 int dx = ( width() - pix.width() ) / 2;
100 int dy = ( height() - pix.height() ) / 2;
103 if ( isOn() || isDown() )
105 dx += style().pixelMetric( TQStyle::PM_ButtonShiftHorizontal,
this );
106 dy += style().pixelMetric( TQStyle::PM_ButtonShiftVertical,
this );
109 p->drawPixmap( dx, dy, pix );