From ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeedu@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kbruch/src/resultwidget.cpp | 90 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 kbruch/src/resultwidget.cpp (limited to 'kbruch/src/resultwidget.cpp') diff --git a/kbruch/src/resultwidget.cpp b/kbruch/src/resultwidget.cpp new file mode 100644 index 00000000..bc9fb285 --- /dev/null +++ b/kbruch/src/resultwidget.cpp @@ -0,0 +1,90 @@ +/*************************************************************************** + resultwidget.h - paint the result + ------------------- + begin : 2004/05/30 + copyright : (C) 2004 by Sebastian Stein + email : seb.kde@hpfsc.de + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 Qt support */ +#include + +#include "settingsclass.h" + +ResultWidget::ResultWidget(QWidget * parent = 0, const char * name = 0, + 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(QPaintEvent* /* 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 + 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); + + // result as normal ratio + paintMiddle(paint, QString("="), old_x, fm, m_colorOperation); + paintRatio(paint, m_result, old_x, fm, false); + + if (SettingsClass::showSpecialRatioNotation() == true && QABS(m_result.numerator()) >= QABS(m_result.denominator())) + { + // result as mixed number + paintMiddle(paint, QString("="), 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; +} -- cgit v1.2.1