1 /***************************************************************************
2 ratiowidget.h - paint a ratio
5 copyright : (C) 2004 by Sebastian Stein
6 email : seb.kde@hpfsc.de
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
18 #include "ratiowidget.h"
19 #include "ratiowidget.moc"
21 /* these includes are needed for Qt support */
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
)
29 kdDebug() << "constructor RatioWidget" << endl
;
33 RatioWidget::~RatioWidget()
36 kdDebug() << "destructor RatioWidget" << endl
;
40 void RatioWidget::setRatio(const ratio para_ratio
)
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
;
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
);
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);
76 // the space we needed for painting is the minimum width of the widget
77 setMinimumWidth(x_pos
);