1 /***************************************************************************
2 factorizedwidget.h - paint a factorization
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 "factorizedwidget.h"
19 #include "factorizedwidget.moc"
21 /* these includes are needed for Qt support */
24 FactorizedWidget::FactorizedWidget(QWidget
* parent
, const char * name
, const uintList para_factors
) :
25 FractionBaseWidget(parent
, name
), m_factors(para_factors
)
28 kdDebug() << "constructor FactorizedWidget" << endl
;
32 FactorizedWidget::~FactorizedWidget()
35 kdDebug() << "destructor FactorizedWidget" << endl
;
39 void FactorizedWidget::setFactors(const uintList para_factors
)
41 m_factors
= para_factors
;
45 void FactorizedWidget::paintEvent(QPaintEvent
* /* p_paintEvent */)
47 // our x position, we paint from left to right;
48 // we don't want to start directly on the border, so add the margin
49 int x_pos
= _MARGIN_X
;
51 int fontWidth
; // to store the width of the last thing painted
56 // ratios and operation signs are painted with the same font
57 paint
.setFont(m_font
);
59 // set the pen for painting
60 QPen
pen(Qt::SolidLine
);
64 // get the font height; the font height doesn't change while painting
65 QFontMetrics
& fm
= * new QFontMetrics(paint
.fontMetrics());
67 // now we can correctly set the height of the widget
68 setMinimumHeight(fm
.lineSpacing());
69 setMaximumHeight(fm
.lineSpacing());
72 int fontHeight
= fm
.lineSpacing(); // get the font height
74 for (uint tmpInt
= 0; tmpInt
< m_factors
.count(); tmpInt
++)
76 // set color for operation sign
77 pen
.setColor(m_colorOperation
);
82 fontWidth
= fm
.width("=");
83 paint
.drawText(x_pos
, 0, fontWidth
, fontHeight
, AlignCenter
, "=");
87 fontWidth
= fm
.width("*");
88 paint
.drawText(x_pos
, 0, fontWidth
, fontHeight
, AlignCenter
, "*");
93 // set color for number
94 pen
.setColor(m_colorNumber
);
97 tmpStr
.setNum(m_factors
[tmpInt
]);
99 fontWidth
= fm
.width(tmpStr
);
100 paint
.drawText(x_pos
, 0, fontWidth
, fontHeight
, AlignCenter
, tmpStr
);
108 // the space we needed for painting is the minimum width of the widget
109 setMinimumWidth(x_pos
);