Logo Search packages:      
Sourcecode: kbruch version File versions  Download package

void ResultWidget::paintEvent ( QPaintEvent *   ) [private]

overrideing the paint event of FractionBaseWidget

Definition at line 195 of file resultwidget.cpp.

References ratio::denominator(), m_factors, m_result, ratio::numerator(), and FractionBaseWidget::paintRatio().

{
    // 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 = 30;
    int old_y = 123;
    int fontWidth; // to store the width of the last thing painted

    // start the painter
    QPainter paint (this);

    paint.setRenderHint (QPainter::Antialiasing);
    paint.setPen (QPen (Qt::NoPen));
    switch (m_kindView) {
    case 2:
        paint.setBrush (QColor (191, 0, 0));
        paint.drawRoundedRect (2.0, 2.0, 157.0, 209.0, 10, 10);
        break;
    case 1:
        paint.setBrush (QColor (0, 191, 0));
        paint.drawRoundedRect (2.0, 2.0, 157.0, 209.0, 10, 10);
        break;
    case 0:
        paint.setBrush (QColor (191, 0, 0));
        paint.drawRoundedRect (2.0, 2.0, width() - 3, 209.0, 10, 10); // 2.0, 2.0, 157.0, 209.0, 10, 10
        paint.setBrush (QColor (255, 255, 255));
        paint.drawRoundedRect (8.0, 110.0, width() - 15, 93.0, 10, 10); // 8.0, 110.0, 145.0, 93.0, 10, 10

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

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

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

        // m_ExerciseView != 1 only for exercise factorize!
        if (m_ExerciseView == 1) {
            if (SettingsClass::showSpecialRatioNotation() == true &&
                    qAbs (m_result.numerator()) >= qAbs (m_result.denominator()) &&
                    m_result.denominator() != 1 &&
                    m_answerMixed == true) {
                paintRatio (paint, m_result, old_x, old_y, fm, true, true, true);
            } else {
                paintRatio (paint, m_result, old_x, old_y, fm, false, true, true);
            }
        } else {
            // show solution of a factorization exercise
            old_y += 20;
            QString tmpStr;
            int fontHeight = fm.lineSpacing(); // get the font height

            int tmpWidth = 0;
            for (int tmpInt = 0; tmpInt < m_factors.count(); tmpInt++) {
                if (tmpInt != 0) {
                    tmpWidth += fm.width ("*");
                }
                tmpStr.setNum (m_factors[tmpInt]);
                fontWidth = fm.width (tmpStr);
                tmpWidth += fontWidth;
            }
            if (tmpWidth <= 100)
                old_x += 50 - tmpWidth / 2;

            for (int tmpInt = 0; tmpInt < m_factors.count(); tmpInt++) {
                if (tmpInt != 0) {
                    fontWidth = fm.width ("*");
                    paint.drawText (old_x, old_y, fontWidth, fontHeight, Qt::AlignCenter, "*");
                    old_x += fontWidth;
                }

                tmpStr.setNum (m_factors[tmpInt]);

                fontWidth = fm.width (tmpStr);
                paint.drawText (old_x, old_y, fontWidth, fontHeight, Qt::AlignCenter, tmpStr);
                old_x += fontWidth;
            }
        }
        old_x += 30;
        if (old_x > 160)
            setMinimumWidth (old_x);
        break;
    }
    // stop the painter
    paint.end();

    return;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index