1 /***************************************************************************
2 taskwidget.cpp - paint a task
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 "taskwidget.h"
19 #include "taskwidget.moc"
21 /* these includes are needed for KDE support */
24 /* these includes are needed for Qt support */
27 TaskWidget::TaskWidget(QWidget
* parent
= 0, const char * name
= 0,
28 const task para_task
= *new task()) :
29 FractionBaseWidget(parent
, name
), m_task(para_task
)
32 kdDebug() << "constructor TaskWidget" << endl
;
36 TaskWidget::~TaskWidget()
39 kdDebug() << "destructor TaskWidget" << endl
;
43 void TaskWidget::setTask(const task para_task
)
49 void TaskWidget::paintEvent(QPaintEvent
* /* p_paintEvent */)
51 // our x position, we paint from left to right;
52 // we don't want to start directly on the border, so add the margin
53 int old_x
= _MARGIN_X
;
55 // strings holding numerator, denominator and the operation sign
56 QString str_numerator
, str_denominator
, str_operation
;
58 // operation sign as number
64 // ratios and operation signs are painted with the same font
65 paint
.setFont(m_font
);
67 // set the pen for painting
68 QPen
pen(Qt::SolidLine
);
72 // get the font height; the font height doesn't change while painting
73 QFontMetrics
& fm
= * new QFontMetrics(paint
.fontMetrics());
75 // now we can correctly set the height of the widget
76 setMinimumHeight(2 * fm
.lineSpacing() + 10);
77 setMaximumHeight(2 * fm
.lineSpacing() + 10);
79 // loop through all ratios and paint them
80 for (unsigned short tmp_counter
= 0; tmp_counter
< m_task
.getNumberOfRatios(); tmp_counter
++)
82 // get the current ratio and paint it
83 paintRatio(paint
, m_task
.get_ratio_n(tmp_counter
), old_x
, fm
, false);
85 // now check if we have another operation to show
86 // if not we will stop showing ratios as well
87 if (tmp_counter
< m_task
.getNumberOfOperations())
89 // get the operation sign
90 tmp_operation
= m_task
.get_op_n(tmp_counter
);
92 // we have to convert the operation sign into a string
93 switch (tmp_operation
)
105 // there seems to be different division signs around the world
106 // so please translate it to the right one for your country
107 str_operation
= i18n("division symbol", "/");
109 } /* switch (operation) */
111 // paint the operation
112 paintMiddle(paint
, str_operation
, old_x
, fm
, m_colorOperation
);
115 // no further operations to show, so we always show the = sign at the
117 paintMiddle(paint
, "=", old_x
, fm
, m_colorOperation
);
120 } // if (tmp_counter < m_task.getNumberOfOperations())
126 // the space we needed for painting is the minimum width of the widget
127 setMinimumWidth(old_x
);