knotebutton.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qstyle.h>
00022 #include <qpainter.h>
00023 #include <qiconset.h>
00024 #include <qsizepolicy.h>
00025
00026 #include <kglobal.h>
00027 #include <kicontheme.h>
00028 #include <kiconloader.h>
00029
00030 #include "knotebutton.h"
00031
00032
00033 KNoteButton::KNoteButton( const QString& icon, QWidget *parent, const char *name )
00034 : QPushButton( parent, name )
00035 {
00036 setFocusPolicy( NoFocus );
00037 setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
00038
00039 m_flat = true;
00040
00041 if ( !icon.isEmpty() )
00042 setIconSet( KGlobal::iconLoader()->loadIconSet( icon, KIcon::Small, 10 ) );
00043 }
00044
00045 KNoteButton::~KNoteButton()
00046 {
00047 }
00048
00049 void KNoteButton::enterEvent( QEvent * )
00050 {
00051 m_flat = false;
00052 repaint( false );
00053 }
00054
00055 void KNoteButton::leaveEvent( QEvent * )
00056 {
00057 m_flat = true;
00058 repaint();
00059 }
00060
00061 QSize KNoteButton::sizeHint() const
00062 {
00063 return QSize( QPushButton::sizeHint().height(), QPushButton::sizeHint().height() );
00064 }
00065
00066 void KNoteButton::drawButton( QPainter* p )
00067 {
00068 QStyle::SFlags flags = QStyle::Style_Default;
00069
00070 if ( isEnabled() )
00071 flags |= QStyle::Style_Enabled;
00072 if ( isDown() )
00073 flags |= QStyle::Style_Down;
00074 if ( isOn() )
00075 flags |= QStyle::Style_On;
00076 if ( !isFlat() && !isDown() )
00077 flags |= QStyle::Style_Raised;
00078 if ( !m_flat )
00079 flags |= QStyle::Style_MouseOver;
00080
00081 style().drawPrimitive( QStyle::PE_ButtonTool, p, rect(), colorGroup(), flags );
00082 drawButtonLabel( p );
00083 }
00084
00085 void KNoteButton::drawButtonLabel( QPainter* p )
00086 {
00087 if ( iconSet() && !iconSet()->isNull() )
00088 {
00089 QIconSet::Mode mode = QIconSet::Disabled;
00090 QIconSet::State state = QIconSet::Off;
00091
00092 if ( isEnabled() )
00093 mode = hasFocus() ? QIconSet::Active : QIconSet::Normal;
00094 if ( isToggleButton() && isOn() )
00095 state = QIconSet::On;
00096
00097 QPixmap pix = iconSet()->pixmap( QIconSet::Small, mode, state );
00098
00099 int dx = ( width() - pix.width() ) / 2;
00100 int dy = ( height() - pix.height() ) / 2;
00101
00102
00103 if ( isOn() || isDown() )
00104 {
00105 dx += style().pixelMetric( QStyle::PM_ButtonShiftHorizontal, this );
00106 dy += style().pixelMetric( QStyle::PM_ButtonShiftVertical, this );
00107 }
00108
00109 p->drawPixmap( dx, dy, pix );
00110 }
00111 }
This file is part of the documentation for knotes Library Version 3.2.2.