diff options
| author | 2022-04-29 10:48:09 +0200 | |
|---|---|---|
| committer | 2022-04-29 10:48:09 +0200 | |
| commit | 07c5f6ec23fcf9237a24e71adcfacabce677f818 (patch) | |
| tree | 588e8c5f82b9163181fad3581f610e6f1d88cba4 /cli/displaytoolbox.cpp | |
| parent | a9153f1615a842cfb9e9bcda4d9071e202618569 (diff) | |
| download | OneRoll-07c5f6ec23fcf9237a24e71adcfacabce677f818.tar.gz OneRoll-07c5f6ec23fcf9237a24e71adcfacabce677f818.zip | |
Change file organization.
Diffstat (limited to 'cli/displaytoolbox.cpp')
| -rw-r--r-- | cli/displaytoolbox.cpp | 168 |
1 files changed, 0 insertions, 168 deletions
diff --git a/cli/displaytoolbox.cpp b/cli/displaytoolbox.cpp deleted file mode 100644 index 1709d18..0000000 --- a/cli/displaytoolbox.cpp +++ /dev/null @@ -1,168 +0,0 @@ -#include "displaytoolbox.h" -#include <QBuffer> -#include <QJsonArray> -#include <QJsonObject> - -#ifdef PAINTER_OP -#include <QFont> -#include <QFontMetrics> -#include <QPainter> -#include <QSvgRenderer> -#endif - -#include <QDebug> - -#define LINE_SPACING 5 - -DisplayToolBox::DisplayToolBox() {} -#ifdef PAINTER_OP -QString DisplayToolBox::makeImage(QByteArray svgCode) -{ - QSvgRenderer svg(svgCode); - - QImage image(500, 60, QImage::Format_ARGB32); - image.fill(QColor(255, 255, 255, 100)); // partly transparent red-ish background - - // Get QPainter that paints to the image - QPainter painter(&image); - svg.render(&painter); - QByteArray ba; - QBuffer buffer(&ba); - buffer.open(QIODevice::WriteOnly); - image.save(&buffer, "PNG"); - return ba.toBase64(); -} -#endif - -QString DisplayToolBox::colorToIntCode(QString str) -{ - if(str.isEmpty() || str == QStringLiteral("black")) - { - return QStringLiteral("0;31"); - } - else if(str == QStringLiteral("white")) - { - return QStringLiteral("97"); - } - else if(str == QStringLiteral("blue")) - { - return QStringLiteral("34"); - } - else if(str == QStringLiteral("red")) - { - return QStringLiteral("31"); - } - else if(str == QStringLiteral("black")) - { - return QStringLiteral("30"); - } - else if(str == QStringLiteral("green")) - { - return QStringLiteral("32"); - } - else if(str == QStringLiteral("yellow")) - { - return QStringLiteral("33"); - } - else if(str == QStringLiteral("cyan")) - { - return QStringLiteral("36"); - } - else if(str == QStringLiteral("reset")) - { - return QStringLiteral("0"); - } - return {}; -} - -QString DisplayToolBox::colorToTermCode(QString str) -{ - return QStringLiteral("\e[").append(DisplayToolBox::colorToIntCode(str)).append("m"); -} - -QString DisplayToolBox::diceToSvg(QJsonArray array, bool withColor, bool allSameColor, bool allSameFaceCount) -{ - Q_UNUSED(allSameColor) - if(allSameFaceCount) - { - QStringList result; - for(auto item : array) - { - QStringList subResult; - auto obj= item.toObject(); - auto values= obj["values"].toArray(); - for(auto valRef : values) - { - subResult.append(diceResultToString(valRef.toObject(), Output::Svg, withColor)); - } - result.append(subResult.join(',')); - } - return result.join(""); - } - else - { - QStringList result; - for(auto item : array) - { - QStringList subResult; - auto obj= item.toObject(); - auto values= obj["values"].toArray(); - - for(auto valRef : values) - { - subResult.append(diceResultToString(valRef.toObject(), Output::Svg, withColor)); - } - result.append(QStringLiteral("d%1:(").arg(obj["face"].toInt())); - if(withColor) - { - result.append(QStringLiteral("<tspan fill=\"%1\">").arg(obj["color"].toString())); - } - result.append(subResult.join(',')); - if(withColor) - { - result.append(QStringLiteral("</tspan>)")); - } - else - { - result.append(QStringLiteral(")")); - } - } - return result.join(""); - } -} -#include <QVariantList> - -QString DisplayToolBox::diceResultToString(QJsonObject val, Output type, bool hasColor) -{ - auto total= QString::number(val["total"].toDouble()); - auto color= val["color"].toString(); - auto subvalues= val["subvalues"].toArray(); - QStringList subStr; - - for(auto subval : subvalues) - { - subStr << QString::number(subval.toDouble()); - } - if(!subStr.isEmpty()) - { - total.append(QStringLiteral(" [%1]").arg(subStr.join(','))); - } - if(hasColor && !color.isEmpty()) - { - if(type == Output::Terminal) - { - total= QStringLiteral("%1%2%3") - .arg(DisplayToolBox::colorToTermCode(color)) - .arg(total) - .arg(DisplayToolBox::colorToTermCode(QStringLiteral("reset"))); - } - else if(type == Output::Svg) - { - total= QStringLiteral("%1%2%3") - .arg(QStringLiteral("<tspan fill=\"%1\">").arg(color)) - .arg(total) - .arg(QStringLiteral("</tspan>")); - } - } - return total; -} |