summaryrefslogtreecommitdiffstats
path: root/kbruch/src/ratiowidget.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitce599e4f9f94b4eb00c1b5edb85bce5431ab3df2 (patch)
treed3bb9f5d25a2dc09ca81adecf39621d871534297 /kbruch/src/ratiowidget.cpp
downloadtdeedu-ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2.tar.gz
tdeedu-ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2.zip
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
Diffstat (limited to 'kbruch/src/ratiowidget.cpp')
-rw-r--r--kbruch/src/ratiowidget.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/kbruch/src/ratiowidget.cpp b/kbruch/src/ratiowidget.cpp
new file mode 100644
index 00000000..43d4d317
--- /dev/null
+++ b/kbruch/src/ratiowidget.cpp
@@ -0,0 +1,80 @@
+/***************************************************************************
+ ratiowidget.h - paint a ratio
+ -------------------
+ begin : 2004/06/03
+ 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 "ratiowidget.h"
+#include "ratiowidget.moc"
+
+/* these includes are needed for Qt support */
+#include <qpainter.h>
+
+RatioWidget::RatioWidget(QWidget * parent = 0, const char * name = 0,
+ const ratio para_ratio = *new ratio()) :
+ FractionBaseWidget(parent, name), m_ratio(para_ratio)
+{
+#ifdef DEBUG
+ kdDebug() << "constructor RatioWidget" << endl;
+#endif
+}
+
+RatioWidget::~RatioWidget()
+{
+#ifdef DEBUG
+ kdDebug() << "destructor RatioWidget" << endl;
+#endif
+}
+
+void RatioWidget::setRatio(const ratio para_ratio)
+{
+ m_ratio = para_ratio;
+ update();
+}
+
+void RatioWidget::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 x_pos = _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
+ paintRatio(paint, m_ratio, x_pos, fm, false);
+
+ // stop the painter
+ paint.end();
+
+ // the space we needed for painting is the minimum width of the widget
+ setMinimumWidth(x_pos);
+
+ return;
+}