22 #include <tqpainter.h>
23 #include <tqiconset.h>
24 #include <tqsizepolicy.h>
26 #include <tdeglobal.h>
27 #include <kicontheme.h>
28 #include <kiconloader.h>
30 #include "knotebutton.h"
33 KNoteButton::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 ) );
45 KNoteButton::~KNoteButton()
49 void KNoteButton::enterEvent( TQEvent * )
55 void KNoteButton::leaveEvent( TQEvent * )
61 TQSize KNoteButton::sizeHint()
const
63 return TQSize( TQPushButton::sizeHint().height(), TQPushButton::sizeHint().height() );
66 void 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 );
85 void 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 );