aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/painter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/painter.cpp')
-rw-r--r--src/ui/painter.cpp60
1 files changed, 56 insertions, 4 deletions
diff --git a/src/ui/painter.cpp b/src/ui/painter.cpp
index b04e389..74f140e 100644
--- a/src/ui/painter.cpp
+++ b/src/ui/painter.cpp
@@ -1,14 +1,66 @@
#include "ui/painter.h"
-#include "ui_painter.h"
+
+#include "debugtools.h"
+
+#include <cmath>
+
Painter::Painter(QWidget *parent) :
QWidget(parent),
- _ui(new Ui::Painter)
+ _font("Latin Modern Roman"),
+ _fontMetrics(_font)
{
- _ui->setupUi(this);
+ // default font size
+ _font.setPixelSize(15);
}
Painter::~Painter()
{
- delete _ui;
+
+}
+
+void Painter::paintEvent(QPaintEvent *event)
+{
+ Q_UNUSED(event);
+
+ if (_structogram == nullptr) {
+ return;
+ }
+
+ if (*_structogram == nullptr) {
+ return;
+ }
+
+ QPainter qp(this);
+ qp.setFont(_font);
+
+ // TODO default values should not be magic numbers
+ QRect rect(50, 50, 600, 00);
+ for (auto it = (*_structogram)->begin(); it != (*_structogram)->end(); ++it) {
+ drawStatement(qp, *it, rect);
+ rect.setY(rect.y() + rect.height());
+ }
+}
+
+void Painter::drawStatement(QPainter &qp, samb::Statement &statement, const QRect &rect)
+{
+ QRect textRect(rect.x() + _margin,
+ rect.y() + _margin,
+ rect.width() - 2*_margin,
+ rect.height() - 2*_margin);
+
+ int textHeight;
+ if (textRect.width() < _fontMetrics.width(statement.text())) {
+ textHeight = (_fontMetrics.height() + _fontMetrics.lineSpacing()) *
+ (int) ceil(_fontMetrics.width(statement.text()) / (double) textRect.width());
+ } else {
+ textHeight = _fontMetrics.height();
+ }
+
+ if (textRect.height() < textHeight) {
+ debug_msg("painter error, textRect.height() < height");
+ }
+
+ qp.drawRect(rect);
+ qp.drawText(textRect, Qt::AlignVCenter, statement.text());
}