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

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

overrideing the paint event of FractionBaseWidget

Definition at line 61 of file taskwidget.cpp.

References task::get_op_n(), task::get_ratio_n(), task::getNumberOfOperations(), task::getNumberOfRatios(), m_task, FractionBaseWidget::paintMiddle(), 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 = _MARGIN_X;
    int old_y = 0;

    // strings holding numerator, denominator and the operation sign
    QString str_numerator, str_denominator, str_operation;

    // operation sign as number
    short tmp_operation;

    // start the painter
    QPainter paint (this);

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

    // 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());

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

    // loop through all ratios and paint them
    for (unsigned short tmp_counter = 0; tmp_counter < m_task.getNumberOfRatios(); tmp_counter++) {
        // get the current ratio and paint it
        paintRatio (paint, m_task.get_ratio_n (tmp_counter), old_x, old_y, fm, m_questionMixed);

        // now check if we have another operation to show
        // if not we will stop showing ratios as well
        if (tmp_counter < m_task.getNumberOfOperations()) {
            // get the operation sign
            tmp_operation = m_task.get_op_n (tmp_counter);

            // we have to convert the operation sign into a string
            switch (tmp_operation) {
            case ADD :
                str_operation = "+";
            case SUB :
                str_operation = "-";
            case MUL :
                str_operation = "x";
            case DIV :
                // there seems to be different division signs around the world
                // so please translate it to the right one for your country
                str_operation = i18nc ("division symbol", "/");
            } /* switch (operation) */

            // paint the operation
            paintMiddle (paint, str_operation, old_x, old_y, fm, m_colorOperation);

        } else {
            // no further operations to show, so we always show the = sign at the
            // end of a task
            paintMiddle (paint, "=", old_x, old_y, fm, m_colorOperation);

        } // if (tmp_counter < m_task.getNumberOfOperations())

    // stop the painter

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


Here is the call graph for this function:

Generated by  Doxygen 1.6.0   Back to index