• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

knotes

  • sources
  • kde-4.12
  • kdepim
  • knotes
  • notes
knotebutton.cpp
Go to the documentation of this file.
1 /*******************************************************************
2  KNotes -- Notes for the KDE project
3 
4  Copyright (c) 2002-2007, The KNotes Developers
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *******************************************************************/
20 
21 #include "knotebutton.h"
22 
23 #include <kiconloader.h>
24 #include <kicontheme.h>
25 
26 #include <QIcon>
27 #include <QPainter>
28 #include <QPixmap>
29 #include <QSizePolicy>
30 #include <QStyle>
31 #include <QStyleOption>
32 
33 
34 KNoteButton::KNoteButton( const QString &icon, QWidget *parent )
35  : QPushButton( parent )
36 {
37  setFocusPolicy( Qt::NoFocus );
38  setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
39 
40  setFlat( true );
41 
42  if ( !icon.isEmpty() ) {
43  setIcon( KIconLoader::global()->loadIcon( icon, KIconLoader::Small, 10 ) );
44  }
45 }
46 
47 KNoteButton::~KNoteButton()
48 {
49 }
50 
51 void KNoteButton::enterEvent( QEvent * )
52 {
53  setFlat( false );
54  repaint();
55 }
56 
57 void KNoteButton::leaveEvent( QEvent * )
58 {
59  setFlat( true );
60  repaint();
61 }
62 
63 int KNoteButton::heightForWidth( int w ) const
64 {
65  return w;
66 }
67 
68 QSize KNoteButton::sizeHint() const
69 {
70  return QSize( QPushButton::sizeHint().height(),
71  QPushButton::sizeHint().height() );
72 }
73 
74 void KNoteButton::paintEvent( QPaintEvent * )
75 {
76  QPainter p( this );
77 
78  // the button
79  QStyleOption opt;
80  opt.initFrom( this );
81 
82  if ( isEnabled() ) {
83  opt.state |= QStyle::State_Enabled;
84  }
85  if ( isDown() ) {
86  opt.state |= QStyle::State_DownArrow;
87  }
88  if ( isCheckable() && isChecked() ) {
89  opt.state |= QStyle::State_On;
90  }
91  if ( !isFlat() ) {
92  if ( !isDown() ) {
93  opt.state |= QStyle::State_Raised;
94  } else {
95  opt.state |= QStyle::State_MouseOver;
96  }
97  }
98 
99  if ( ( opt.state & QStyle::State_MouseOver ) && ( ! ( opt.state & QStyle::State_DownArrow ) ) ) {
100  style()->drawPrimitive( QStyle::PE_PanelButtonTool, &opt, &p, this );
101  }
102 
103  // the button label
104  if ( !icon().isNull() ) {
105  QIcon::Mode mode = QIcon::Disabled;
106  QIcon::State state = QIcon::Off;
107 
108  if ( opt.state & QStyle::State_Enabled ) {
109  mode = hasFocus() ? QIcon::Active : QIcon::Normal;
110  }
111  if ( opt.state & QStyle::State_On ) {
112  state = QIcon::On;
113  }
114 
115  QPixmap pix = icon().pixmap( style()->pixelMetric(
116  QStyle::PM_SmallIconSize ), mode, state );
117 
118  int dx = ( width() - pix.width() ) / 2;
119  int dy = ( height() - pix.height() ) / 2;
120 
121  // Shift button contents if pushed.
122  if ( ( opt.state & QStyle::State_On ) || ( opt.state & QStyle::State_DownArrow ) ) {
123  dx += style()->pixelMetric( QStyle::PM_ButtonShiftHorizontal );
124  dy += style()->pixelMetric( QStyle::PM_ButtonShiftVertical );
125  }
126 
127  p.drawPixmap( dx, dy, pix );
128  }
129 }
130 
131 #include "knotebutton.moc"
KNoteButton::enterEvent
void enterEvent(QEvent *)
Definition: knotebutton.cpp:51
QWidget
QPushButton
KNoteButton::heightForWidth
virtual int heightForWidth(int w) const
Definition: knotebutton.cpp:63
knotebutton.h
KNoteButton::sizeHint
virtual QSize sizeHint() const
Definition: knotebutton.cpp:68
KNoteButton::~KNoteButton
~KNoteButton()
Definition: knotebutton.cpp:47
KNoteButton::paintEvent
void paintEvent(QPaintEvent *e)
Definition: knotebutton.cpp:74
KNoteButton::KNoteButton
KNoteButton(const QString &icon, QWidget *parent=0)
Definition: knotebutton.cpp:34
KNoteButton::leaveEvent
void leaveEvent(QEvent *)
Definition: knotebutton.cpp:57
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knotes

Skip menu "knotes"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal