moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kalzium / src / elementbutton.cpp
bloba6913d81b635fa1be4c6e2506442db009730f857
1 /***************************************************************************
2 * Copyright (C) 2003 by Carsten Niehaus *
3 * cniehaus@kde.org *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #include "elementbutton.h"
21 #include "prefs.h"
22 #include "infodialog_small_impl.h"
23 #include "detailinfodlg.h"
24 #include <qpainter.h>
26 #include <kdebug.h>
28 ElementButton::ElementButton(int number, Element *el, QWidget *parent, const char *name)
29 : QFrame(parent, name)
31 m_ElementNumber = number;
33 e = el;
35 setMaximumSize( 40, 40 );
36 setFrameStyle( QFrame::Box );
37 setLineWidth( 2 );
38 setMidLineWidth( 3 );
39 setFrameShadow( QFrame::Sunken );
42 void ElementButton::mouseReleaseEvent( QMouseEvent *mouse )
44 int small = Prefs::lMBbeh();
45 if ( small == 1 )
47 if ( mouse->button() == LeftButton )
49 infoDlgSmallImpl *smallDlg = new infoDlgSmallImpl( e, this , "smallDlg" );
50 smallDlg->show();
51 }else
53 DetailedInfoDlg *detailedDlg = new DetailedInfoDlg( e, this , "detailedDlg" );
54 detailedDlg->show();
57 if ( small == 0 )
59 if ( mouse->button() == LeftButton )
61 DetailedInfoDlg *detailedDlg = new DetailedInfoDlg( e, this , "detailedDlg" );
62 detailedDlg->show();
63 }else
65 infoDlgSmallImpl *smallDlg = new infoDlgSmallImpl( e, this , "smallDlg" );
66 smallDlg->show();
71 ElementButton::~ElementButton()
77 /*!
78 \fn ElementButton::m_ElementNumber
80 int ElementButton::ElementNumber()
82 return m_ElementNumber;
86 /*!
87 \fn ElementButton::paintEvent( QPaintEvent* )
89 void ElementButton::paintEvent( QPaintEvent* )
91 int h, w;
92 h = w = 40;
93 QPainter p;
95 QFont f = p.font();
96 f.setBold( true );
97 f.setPointSize( f.pointSize() + 2 );
99 p.begin( this );
101 //Draw the colored background
102 p.setPen( elementColor() );
103 // p.setBrush( elementColor() );
104 p.fillRect( 3, 3, w-6, h-6, elementColor() );
105 p.drawRoundRect( 2, 2, w-4, h-4 );
107 //Draw text and border
108 p.setPen( paletteForegroundColor() );
109 p.drawText( 4, h/2-6, QString::number( m_ElementNumber ) );
110 p.setFont( f );
111 p.drawText( w/5, h*3/4, sym );
112 p.drawRoundRect( 1, 1, w-2, h-2 );
114 p.end();
117 void ElementButton::mousePressEvent( QMouseEvent* /*e*/ )
119 emit num( m_ElementNumber );
122 #include "elementbutton.moc"