summaryrefslogtreecommitdiffstats
path: root/kbruch/src/resultwidget.cpp
blob: 9735b046e05614d34b3405eab279d400c9f6e236 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/***************************************************************************
                          resultwidget.h  -  paint the result
                             -------------------
    begin                : 2004/05/30
    copyright            : (C) 2004 by Sebastian Stein
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "resultwidget.h"
#include "resultwidget.moc"

/* these includes are needed for TQt support */
#include <tqpainter.h>

#include "settingsclass.h"

ResultWidget::ResultWidget(TQWidget * parent, const char * name,
													const ratio para_result = *new ratio()) :
			FractionBaseWidget(parent, name), m_result(para_result)
{
#ifdef DEBUG
	kdDebug() << "constructor ResultWidget" << endl;
#endif
}

ResultWidget::~ResultWidget()
{
#ifdef DEBUG
	kdDebug() << "destructor ResultWidget" << endl;
#endif
}

void ResultWidget::setResult(const ratio para_result)
{
	m_result = para_result;
	update();
}

void ResultWidget::paintEvent(TQPaintEvent* /* p_paintEvent */)
{
	// our x position, we paint from left to right;
	// we don't want to start directly on the border, so add the margin
	int old_x = _MARGIN_X;

	// start the painter
	TQPainter paint(this);

	// ratios and operation signs are painted with the same font
	paint.setFont(m_font);

	// set the pen for painting
	TQPen pen(TQt::SolidLine);
	pen.setWidth(0);
	paint.setPen(pen);

	// get the font height; the font height doesn't change while painting
	TQFontMetrics fm(paint.fontMetrics());

	// now we can correctly set the height of the widget
	setMinimumHeight(2 * fm.lineSpacing() + 10);
	setMaximumHeight(2 * fm.lineSpacing() + 10);

	// result as normal ratio
	paintMiddle(paint, TQString("="), old_x, fm, m_colorOperation);
	paintRatio(paint, m_result, old_x, fm, false);

	if (SettingsClass::showSpecialRatioNotation() == true && TQABS(m_result.numerator()) >= TQABS(m_result.denominator()))
	{
		// result as mixed number
		paintMiddle(paint, TQString("="), old_x, fm, m_colorOperation);
		paintRatio(paint, m_result, old_x, fm, true);
	}

	// stop the painter
	paint.end();

	// the space we needed for painting is the minimum width of the widget
	setMinimumWidth(old_x);

	return;
}