From 1695174303adb50c98cd0be6e3ac8926c227d674 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Tue, 5 Feb 2019 21:32:13 +0100 Subject: [PATCH] Added fat lines around summary squares --- source/PrintableModel/PrintableModel.cpp | 24 +++++++++++-- source/PrintableModel/PrintableModel.h | 2 ++ source/SubTests/V2Svk/V2SvkModel.cpp | 8 +++-- source/SubTests/VerbEnd/VerbEndModel.cpp | 43 +++++++++++++++++++----- source/SubTests/VerbEnd/VerbEndModel.h | 5 +++ 5 files changed, 67 insertions(+), 15 deletions(-) diff --git a/source/PrintableModel/PrintableModel.cpp b/source/PrintableModel/PrintableModel.cpp index 85b6ed4..97b3fd8 100644 --- a/source/PrintableModel/PrintableModel.cpp +++ b/source/PrintableModel/PrintableModel.cpp @@ -32,6 +32,11 @@ QPen PrintableModel::tablePen() return QPen(Qt::black, 1, Qt::SolidLine); } +QPen PrintableModel::resultPen() +{ + return QPen(Qt::black, 2, Qt::SolidLine); +} + void PrintableModel::drawTextSquare(QPainter &painter, const QRectF &cell, const QString &text) { auto prevPen = painter.pen(); @@ -47,6 +52,19 @@ void PrintableModel::drawTextSquare(QPainter &painter, const QRectF &cell, const painter.setPen(prevPen); } +void PrintableModel::drawNumberSquare(QPainter &painter, double x, double y, int number) +{ + QRectF cell = {x, y, 0.03 * painter.device()->width(), + 1.5 * painter.fontMetrics().lineSpacing()}; + + painter.drawText(cell, Qt::AlignCenter, QString::number(number)); + + painter.drawLine(cell.topLeft(), cell.topRight()); + painter.drawLine(cell.topRight(), cell.bottomRight()); + painter.drawLine(cell.bottomRight(), cell.bottomLeft()); + painter.drawLine(cell.bottomLeft(), cell.topLeft()); +} + void PrintableModel::PrintableModel::drawCheckSquare(QPainter &painter, const QRectF &cell, bool checked) { @@ -138,14 +156,14 @@ void PrintableModel::printTests(QPainter &painter) const void PrintableModel::printSummary(QPainter &painter) const { painter.setFont(tableFont()); - painter.setPen(tablePen()); auto width = painter.device()->width(); auto height = 1.5 * painter.fontMetrics().lineSpacing(); - painter.drawText(0, 0, 0.85 * width, height, Qt::AlignRight | Qt::AlignVCenter, + painter.drawText(0, 0, 0.95 * width, height, Qt::AlignRight | Qt::AlignVCenter, "Rohwertpunkte Total:"); - drawResultSquare(painter, 0, true, getPoints()); + painter.setPen(resultPen()); + drawNumberSquare(painter, 0.97 * width, 0, getPoints()); painter.translate(0, 3 * height); } diff --git a/source/PrintableModel/PrintableModel.h b/source/PrintableModel/PrintableModel.h index 8dba378..e647585 100644 --- a/source/PrintableModel/PrintableModel.h +++ b/source/PrintableModel/PrintableModel.h @@ -22,8 +22,10 @@ public: static QFont tableFont(); static QPen tablePen(); + static QPen resultPen(); static void drawTextSquare(QPainter &painter, const QRectF &cell, const QString &text); + static void drawNumberSquare(QPainter &painter, double x, double y, int number); static void drawCheckSquare(QPainter &painter, const QRectF &cell, bool checked); static void drawResultSquare(QPainter &painter, double y, bool rightCell, unsigned int value); static void drawGreySquare(QPainter &painter, const QRectF &cell); diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index 5db51d4..5416064 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -116,10 +116,12 @@ void V2SvkModel::printSummary(QPainter &painter, unsigned int v2Points, unsigned auto width = painter.device()->width(); auto height = 1.5 * painter.fontMetrics().lineSpacing(); - painter.drawText(0, 0, 0.85 * width, height, Qt::AlignRight | Qt::AlignVCenter, + painter.drawText(0, 0, 0.91 * width, height, Qt::AlignRight | Qt::AlignVCenter, "Rohwertpunkte Total:"); - PrintableModel::drawResultSquare(painter, 0, false, v2Points); - PrintableModel::drawResultSquare(painter, 0, true, svkPoints); + + painter.setPen(resultPen()); + drawNumberSquare(painter, 0.93 * width, 0, v2Points); + drawNumberSquare(painter, 0.97 * width, 0, svkPoints); painter.translate(0, 3 * height); } diff --git a/source/SubTests/VerbEnd/VerbEndModel.cpp b/source/SubTests/VerbEnd/VerbEndModel.cpp index 6aa3503..afc21cc 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.cpp +++ b/source/SubTests/VerbEnd/VerbEndModel.cpp @@ -1,17 +1,14 @@ #include "VerbEndModel.h" VerbEndModel::VerbEndModel(QObject *parent) - : PrintableModel(parent) + : PrintableModel(parent) { m_title = "Subtest 2: Verbendstellungsregel (VE)"; - m_tests = { { "Telefonat", - { "Kausal", "Kausal", "Relativ", "Kausal", - "Final", "Temporal", "Temporal" } }, - { "Zaubertrick", { "Relativ", "Final", "Kausal", "Final", - "Temporal", "Kausal", "Temporal" } }, - { "Zauberregel", { "Temporal", "Kausal", "Final", "Relativ", - "Temporal", "Relativ" } } }; + m_tests = { + {"Telefonat", {"Kausal", "Kausal", "Relativ", "Kausal", "Final", "Temporal", "Temporal"}}, + {"Zaubertrick", {"Relativ", "Final", "Kausal", "Final", "Temporal", "Kausal", "Temporal"}}, + {"Zauberregel", {"Temporal", "Kausal", "Final", "Relativ", "Temporal", "Relativ"}}}; } void VerbEndModel::write(ESGRAF48::VerbEndModel &model) const @@ -100,4 +97,32 @@ void VerbEndModel::read(const ESGRAF48::VerbEndModel &model) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } - + +unsigned int VerbEndModel::getKausalPoints() const +{ + auto points = [&](unsigned int testId, unsigned int itemId) { + return m_tests.at(testId).items().at(itemId).points(); + }; + + return points(0, 0) + points(0, 1) + points(0, 3) + points(1, 2) + points(1, 5) + points(2, 1); +} + +void VerbEndModel::printSummary(QPainter &painter) const +{ + painter.setFont(tableFont()); + + auto width = painter.device()->width(); + auto height = 1.5 * painter.fontMetrics().lineSpacing(); + + painter.drawText(0, 0, 0.71 * width, height, Qt::AlignRight | Qt::AlignVCenter, + "Rohwertpunkte Kausalsätze:"); + painter.drawText(0, 0, 0.95 * width, height, Qt::AlignRight | Qt::AlignVCenter, + "Rohwertpunkte Total:"); + + drawNumberSquare(painter, 0.73 * width, 0, getKausalPoints()); + + painter.setPen(resultPen()); + drawNumberSquare(painter, 0.97 * width, 0, getKausalPoints()); + + painter.translate(0, 3 * height); +} diff --git a/source/SubTests/VerbEnd/VerbEndModel.h b/source/SubTests/VerbEnd/VerbEndModel.h index 8baee48..0211e4f 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.h +++ b/source/SubTests/VerbEnd/VerbEndModel.h @@ -12,4 +12,9 @@ public: void write(ESGRAF48::VerbEndModel &model) const; void read(const ESGRAF48::VerbEndModel &model); + + unsigned int getKausalPoints() const; + +protected: + void printSummary(QPainter &painter) const override; };