aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cli/displaytoolbox.cpp
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2019-02-12 23:59:24 +0100
committerRenaud G <renaud@rolisteam.org>2019-02-12 23:59:24 +0100
commitf2051fb35b1ad49c4d940e6fbba2acc98b216e13 (patch)
tree03117f493191d35104ac37eba72e916d41c849f2 /cli/displaytoolbox.cpp
parent210a222b894caa3c8af38ccb6653db0fd8491f6e (diff)
downloadOneRoll-f2051fb35b1ad49c4d940e6fbba2acc98b216e13.tar.gz
OneRoll-f2051fb35b1ad49c4d940e6fbba2acc98b216e13.zip
clang format
Diffstat (limited to 'cli/displaytoolbox.cpp')
-rw-r--r--cli/displaytoolbox.cpp233
1 files changed, 115 insertions, 118 deletions
diff --git a/cli/displaytoolbox.cpp b/cli/displaytoolbox.cpp
index 3c1048f..3474cf9 100644
--- a/cli/displaytoolbox.cpp
+++ b/cli/displaytoolbox.cpp
@@ -1,12 +1,12 @@
#include "displaytoolbox.h"
-#include <QJsonObject>
-#include <QJsonArray>
#include <QBuffer>
+#include <QJsonArray>
+#include <QJsonObject>
#ifdef PAINTER_OP
+#include <QFont>
#include <QFontMetrics>
#include <QPainter>
-#include <QFont>
//#include <QFontDatabase>
#endif
@@ -14,211 +14,209 @@
#define LINE_SPACING 5
-DisplayToolBox::DisplayToolBox()
-{
-
-}
+DisplayToolBox::DisplayToolBox() {}
#ifdef PAINTER_OP
-QString DisplayToolBox::makeImage(QString scalarText, QString resultStr,QJsonArray array, bool withColor, QString cmd, QString comment, bool allSameFaceCount,bool allSameColor)
+QString DisplayToolBox::makeImage(QString scalarText, QString resultStr, QJsonArray array, bool withColor, QString cmd,
+ QString comment, bool allSameFaceCount, bool allSameColor)
{
- //qDebug() <<"scarlarText:" <<scalarText << "resultStr:"<< resultStr<<"array" << array<< "with color:" << withColor << "cmd" << cmd << "comment" << comment << "allsamecolor"<< allSameColor;
+ // qDebug() <<"scarlarText:" <<scalarText << "resultStr:"<< resultStr<<"array" << array<< "with color:" << withColor
+ // << "cmd" << cmd << "comment" << comment << "allsamecolor"<< allSameColor;
QString textTotal("%1 Details:[%3 %2]");
-
- int lineCount=2;
+ int lineCount= 2;
if(!comment.isEmpty())
{
- lineCount = 3;
+ lineCount= 3;
}
if(resultStr.isEmpty())
{
- auto list = diceToText(array,false,allSameFaceCount,allSameColor);
- textTotal = textTotal.arg(scalarText).arg(list).arg(cmd);
+ auto list= diceToText(array, false, allSameFaceCount, allSameColor);
+ textTotal= textTotal.arg(scalarText).arg(list).arg(cmd);
}
else
{
--lineCount;
- textTotal = resultStr;
+ textTotal= resultStr;
}
- if(comment.size()>textTotal.size())
+ if(comment.size() > textTotal.size())
{
textTotal.prepend(QStringLiteral("%1\n").arg(comment));
}
- QFont font("Helvetica", 15); //QFontDatabase::systemFont(QFontDatabase::GeneralFont);
+ QFont font("Helvetica", 15); // QFontDatabase::systemFont(QFontDatabase::GeneralFont);
QFontMetrics fm(font);
- QRect rect = fm.boundingRect(textTotal);
+ QRect rect= fm.boundingRect(textTotal);
- QImage img(rect.width(),(rect.height()+LINE_SPACING)*lineCount,QImage::Format_ARGB32);
- img.fill(QColor(255,255,255,100));
+ QImage img(rect.width(), (rect.height() + LINE_SPACING) * lineCount, QImage::Format_ARGB32);
+ img.fill(QColor(255, 255, 255, 100));
QPainter painter(&img);
painter.setFont(font);
- int y = rect.height();
+ int y= rect.height();
if(!comment.isEmpty())
{
- QPen pen = painter.pen();
+ QPen pen= painter.pen();
pen.setColor(Qt::black);
painter.setPen(pen);
- painter.drawText(QPoint(0,y),comment);
- y += rect.height()+LINE_SPACING;
+ painter.drawText(QPoint(0, y), comment);
+ y+= rect.height() + LINE_SPACING;
}
if(!resultStr.isEmpty())
{
- QPen pen = painter.pen();
+ QPen pen= painter.pen();
pen.setColor(Qt::black);
painter.setPen(pen);
- painter.drawText(QPoint(0,y),resultStr);
+ painter.drawText(QPoint(0, y), resultStr);
}
else
{
painter.save();
- QPen pen = painter.pen();
+ QPen pen= painter.pen();
pen.setColor(Qt::red);
painter.setPen(pen);
- painter.drawText(QPoint(5,y),scalarText);
- y += rect.height()+LINE_SPACING;
+ painter.drawText(QPoint(5, y), scalarText);
+ y+= rect.height() + LINE_SPACING;
painter.restore();
- int x = 5;
- QString text=QStringLiteral("Details:[%1 (").arg(cmd);
- painter.drawText(QPoint(x,y),text);
- x += fm.boundingRect(text).width();
+ int x= 5;
+ QString text= QStringLiteral("Details:[%1 (").arg(cmd);
+ painter.drawText(QPoint(x, y), text);
+ x+= fm.boundingRect(text).width();
if(allSameFaceCount)
{
- int i = 0;
+ int i= 0;
for(auto item : array)
{
QStringList result;
- bool last = (array.size()-1==i);
- auto obj = item.toObject();
+ bool last= (array.size() - 1 == i);
+ auto obj= item.toObject();
auto values= obj["values"].toArray();
for(auto valRef : values)
{
result.append(diceResultToString(valRef.toObject()));
}
painter.save();
- QPen pen = painter.pen();
+ QPen pen= painter.pen();
QColor color;
- auto colorStr = obj["color"].toString();
+ auto colorStr= obj["color"].toString();
if(colorStr.isEmpty())
- color = QColor(Qt::black);
+ color= QColor(Qt::black);
else
color.setNamedColor(colorStr);
pen.setColor(color);
painter.setPen(pen);
- text = QStringLiteral("%1").arg(result.join(','));
+ text= QStringLiteral("%1").arg(result.join(','));
if(!last)
{
text.append(",");
}
- painter.drawText(QPoint(x,y),text);
- x += fm.boundingRect(text).width();
+ painter.drawText(QPoint(x, y), text);
+ x+= fm.boundingRect(text).width();
painter.restore();
++i;
}
}
else
{
- int i = 0;
+ int i= 0;
for(auto item : array)
{
QStringList result;
- auto obj = item.toObject();
- bool last = (array.size()-1==i);
+ auto obj= item.toObject();
+ bool last= (array.size() - 1 == i);
auto values= obj["values"].toArray();
for(auto valRef : values)
{
result.append(diceResultToString(valRef.toObject()));
}
- text =QStringLiteral("d%1:(").arg(obj["face"].toInt());
- painter.drawText(QPoint(x,y),text);
- x += fm.boundingRect(text).width();
+ text= QStringLiteral("d%1:(").arg(obj["face"].toInt());
+ painter.drawText(QPoint(x, y), text);
+ x+= fm.boundingRect(text).width();
painter.save();
- QPen pen = painter.pen();
+ QPen pen= painter.pen();
QColor color;
- auto colorStr = obj["color"].toString();
+ auto colorStr= obj["color"].toString();
if(colorStr.isEmpty())
- color = QColor(Qt::black);
+ color= QColor(Qt::black);
else
color.setNamedColor(colorStr);
-
+
pen.setColor(color);
painter.setPen(pen);
- text = QStringLiteral("%1").arg(result.join(','));
- painter.drawText(QPoint(x,y),text);
- x += fm.boundingRect(text).width();
+ text= QStringLiteral("%1").arg(result.join(','));
+ painter.drawText(QPoint(x, y), text);
+ x+= fm.boundingRect(text).width();
painter.restore();
painter.save();
- text = QStringLiteral(")");
+ text= QStringLiteral(")");
if(!last)
{
text.append(",");
}
- painter.drawText(QPoint(x,y),text);
- x += fm.boundingRect(text).width();
+ painter.drawText(QPoint(x, y), text);
+ x+= fm.boundingRect(text).width();
painter.restore();
++i;
}
}
- text = QStringLiteral(")");
- x += fm.boundingRect(text).width();
- painter.drawText(QPoint(x,y),text);
+ text= QStringLiteral(")");
+ x+= fm.boundingRect(text).width();
+ painter.drawText(QPoint(x, y), text);
}
painter.end();
- img.save("/home/renaud/image.png","PNG");
+ img.save("/home/renaud/image.png", "PNG");
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
img.save(&buffer, "PNG");
- //return {};
+ // return {};
return ba.toBase64();
}
#endif
QString DisplayToolBox::colorToTermCode(QString str)
{
- if(str.isEmpty()|| str==QStringLiteral("black"))
+ if(str.isEmpty() || str == QStringLiteral("black"))
{
return QStringLiteral("\e[0;31m");
}
- else if(str==QStringLiteral("white"))
+ else if(str == QStringLiteral("white"))
{
- return QStringLiteral("\e[97m");
+ return QStringLiteral("\e[97m");
}
- else if(str==QStringLiteral("blue"))
+ else if(str == QStringLiteral("blue"))
{
- return QStringLiteral("\e[34m");
+ return QStringLiteral("\e[34m");
}
- else if(str==QStringLiteral("red"))
+ else if(str == QStringLiteral("red"))
{
- return QStringLiteral("\e[31m");
+ return QStringLiteral("\e[31m");
}
- else if(str==QStringLiteral("black"))
+ else if(str == QStringLiteral("black"))
{
- return QStringLiteral("\e[30m");
+ return QStringLiteral("\e[30m");
}
- else if(str==QStringLiteral("green"))
+ else if(str == QStringLiteral("green"))
{
- return QStringLiteral("\e[32m");
+ return QStringLiteral("\e[32m");
}
- else if(str==QStringLiteral("yellow"))
+ else if(str == QStringLiteral("yellow"))
{
- return QStringLiteral("\e[33m");
+ return QStringLiteral("\e[33m");
}
- else if(str==QStringLiteral("reset"))
+ else if(str == QStringLiteral("reset"))
{
- return QStringLiteral("\e[0m");
+ return QStringLiteral("\e[0m");
}
return {};
}
-QString DisplayToolBox::diceToSvg(QJsonArray array,bool withColor,bool allSameColor,bool allSameFaceCount )
+QString DisplayToolBox::diceToSvg(QJsonArray array, bool withColor, bool allSameColor, bool allSameFaceCount)
{
Q_UNUSED(allSameColor)
if(allSameFaceCount)
@@ -227,7 +225,7 @@ QString DisplayToolBox::diceToSvg(QJsonArray array,bool withColor,bool allSameCo
for(auto item : array)
{
QStringList subResult;
- auto obj = item.toObject();
+ auto obj= item.toObject();
auto values= obj["values"].toArray();
for(auto valRef : values)
{
@@ -252,7 +250,7 @@ QString DisplayToolBox::diceToSvg(QJsonArray array,bool withColor,bool allSameCo
for(auto item : array)
{
QStringList subResult;
- auto obj = item.toObject();
+ auto obj= item.toObject();
auto values= obj["values"].toArray();
for(auto valRef : values)
@@ -277,67 +275,66 @@ QString DisplayToolBox::diceToSvg(QJsonArray array,bool withColor,bool allSameCo
return result.join("");
}
}
-QJsonArray DisplayToolBox::diceToJson(QList<ExportedDiceResult>& diceList,bool& allSameFaceCount,bool& allSameColor)
+QJsonArray DisplayToolBox::diceToJson(QList<ExportedDiceResult>& diceList, bool& allSameFaceCount, bool& allSameColor)
{
- allSameFaceCount = true;
- allSameColor = true;
+ allSameFaceCount= true;
+ allSameColor= true;
QJsonArray array;
for(auto dice : diceList)
{
- if(dice.size()>1)
+ if(dice.size() > 1)
{
- allSameFaceCount = false;
+ allSameFaceCount= false;
}
- for(int face: dice.keys())
+ for(int face : dice.keys())
{
- ListDiceResult diceResults = dice.value(face);
+ ListDiceResult diceResults= dice.value(face);
std::vector<QString> alreadyDoneColor;
std::vector<std::vector<HighLightDice>> sameColorDice;
- for(auto & diceResult : diceResults)
+ for(auto& diceResult : diceResults)
{
if(!diceResult.getColor().isEmpty())
{
- allSameColor = false;
+ allSameColor= false;
}
- auto it=std::find_if(alreadyDoneColor.begin(), alreadyDoneColor.end(),[diceResult](QString color){
- return color == diceResult.getColor();
- });
+ auto it= std::find_if(alreadyDoneColor.begin(), alreadyDoneColor.end(),
+ [diceResult](QString color) { return color == diceResult.getColor(); });
- if( it == alreadyDoneColor.end())
+ if(it == alreadyDoneColor.end())
{
sameColorDice.push_back(std::vector<HighLightDice>());
alreadyDoneColor.push_back(diceResult.getColor());
- it = alreadyDoneColor.end();
+ it= alreadyDoneColor.end();
--it;
}
- auto i = std::distance(alreadyDoneColor.begin(), it);
+ auto i= std::distance(alreadyDoneColor.begin(), it);
sameColorDice[static_cast<std::size_t>(i)].push_back(diceResult);
}
- int i = 0;
- for(auto it = alreadyDoneColor.begin() ; it != alreadyDoneColor.end() && i < sameColorDice.size() ; ++it)
+ int i= 0;
+ for(auto it= alreadyDoneColor.begin(); it != alreadyDoneColor.end() && i < sameColorDice.size(); ++it)
{
- auto list = sameColorDice[static_cast<std::size_t>(i)];
+ auto list= sameColorDice[static_cast<std::size_t>(i)];
QJsonObject object;
- object["color"]=*it;
- object["face"]=face;
+ object["color"]= *it;
+ object["face"]= face;
QJsonArray values;
for(auto const& dice : list)
{
QJsonObject diceObj;
- auto listValues = dice.getResult();
+ auto listValues= dice.getResult();
if(!listValues.isEmpty())
{
- diceObj["total"]=static_cast<qint64>(listValues.takeFirst());
+ diceObj["total"]= static_cast<qint64>(listValues.takeFirst());
QJsonArray subValues;
for(auto result : listValues)
{
subValues.push_back(static_cast<qint64>(result));
}
- diceObj["subvalues"]=subValues;
+ diceObj["subvalues"]= subValues;
}
values.push_back(diceObj);
}
- object["values"]=values;
+ object["values"]= values;
++i;
array.push_back(object);
}
@@ -347,8 +344,8 @@ QJsonArray DisplayToolBox::diceToJson(QList<ExportedDiceResult>& diceList,bool&
}
QString DisplayToolBox::diceResultToString(QJsonObject val)
{
- auto total = QString::number(val["total"].toDouble());
- auto subvalues = val["subvalues"].toArray();
+ auto total= QString::number(val["total"].toDouble());
+ auto subvalues= val["subvalues"].toArray();
QStringList subStr;
for(auto subval : subvalues)
{
@@ -360,45 +357,45 @@ QString DisplayToolBox::diceResultToString(QJsonObject val)
}
return total;
}
-QString DisplayToolBox::diceToText(QJsonArray array, bool withColor,bool allSameFaceCount, bool allSameColor)
+QString DisplayToolBox::diceToText(QJsonArray array, bool withColor, bool allSameFaceCount, bool allSameColor)
{
Q_UNUSED(allSameColor)
QStringList result;
for(auto item : array)
{
QString subResult("");
- auto obj = item.toObject();
+ auto obj= item.toObject();
auto values= obj["values"].toArray();
QStringList diceResult;
for(auto valRef : values)
{
- diceResult += diceResultToString(valRef.toObject());
+ diceResult+= diceResultToString(valRef.toObject());
}
- if (!diceResult.isEmpty())
+ if(!diceResult.isEmpty())
{
if(!allSameFaceCount)
{
- subResult += QStringLiteral("d%1:(").arg(obj["face"].toInt());
+ subResult+= QStringLiteral("d%1:(").arg(obj["face"].toInt());
}
if(withColor)
{
- subResult += DisplayToolBox::colorToTermCode(obj["color"].toString());
+ subResult+= DisplayToolBox::colorToTermCode(obj["color"].toString());
}
- subResult += diceResult.join(" ");
+ subResult+= diceResult.join(" ");
if(withColor)
{
- subResult += DisplayToolBox::colorToTermCode(QStringLiteral("reset"));
+ subResult+= DisplayToolBox::colorToTermCode(QStringLiteral("reset"));
}
if(!allSameFaceCount)
{
- subResult += QStringLiteral(")");
+ subResult+= QStringLiteral(")");
}
}
- if (!subResult.isEmpty())
+ if(!subResult.isEmpty())
{
- result += subResult;
+ result+= subResult;
}
}
return result.join(" - ");