moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kbruch / src / ratiowidget.cpp
blob5b9c803c6a6f07a2b3991580cb54774bcd2802d9
1 /***************************************************************************
2 ratiowidget.h - paint a ratio
3 -------------------
4 begin : 2004/06/03
5 copyright : (C) 2004 by Sebastian Stein
6 email : seb.kde@hpfsc.de
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #include "ratiowidget.h"
19 #include "ratiowidget.moc"
21 /* these includes are needed for Qt support */
22 #include <qpainter.h>
24 RatioWidget::RatioWidget(QWidget * parent = 0, const char * name = 0,
25 const ratio para_ratio = *new ratio()) :
26 FractionBaseWidget(parent, name), m_ratio(para_ratio)
28 #ifdef DEBUG
29 kdDebug() << "constructor RatioWidget" << endl;
30 #endif
33 RatioWidget::~RatioWidget()
35 #ifdef DEBUG
36 kdDebug() << "destructor RatioWidget" << endl;
37 #endif
40 void RatioWidget::setRatio(const ratio para_ratio)
42 m_ratio = para_ratio;
43 update();
46 void RatioWidget::paintEvent(QPaintEvent* /* p_paintEvent */)
48 // our x position, we paint from left to right;
49 // we don't want to start directly on the border, so add the margin
50 int x_pos = _MARGIN_X;
52 // start the painter
53 QPainter paint(this);
55 // ratios and operation signs are painted with the same font
56 paint.setFont(m_font);
58 // set the pen for painting
59 QPen pen(Qt::SolidLine);
60 pen.setWidth(0);
61 paint.setPen(pen);
63 // get the font height; the font height doesn't change while painting
64 QFontMetrics & fm = * new QFontMetrics(paint.fontMetrics());
66 // now we can correctly set the height of the widget
67 setMinimumHeight(2 * fm.lineSpacing() + 10);
68 setMaximumHeight(2 * fm.lineSpacing() + 10);
70 // result as normal ratio
71 paintRatio(paint, m_ratio, x_pos, fm, false);
73 // stop the painter
74 paint.end();
76 // the space we needed for painting is the minimum width of the widget
77 setMinimumWidth(x_pos);
79 return;