Use r2 colors in graph

This commit is contained in:
Florian Märkl 2018-02-01 15:51:03 +01:00
parent 75bf8cf5b6
commit f21cdfa5c0
3 changed files with 53 additions and 4 deletions

View File

@ -2,6 +2,8 @@
#include "RichTextPainter.h"
#include "CachedFontMetrics.h"
#include <QPainter>
#include <QTextBlock>
#include <QTextFragment>
//TODO: fix performance (possibly use QTextLayout?)
void RichTextPainter::paintRichText(QPainter* painter, int x, int y, int w, int h, int xinc, const List & richText, CachedFontMetrics* fontMetrics)
@ -102,6 +104,49 @@ void RichTextPainter::htmlRichText(const List & richText, QString & textHtml, QS
}
}
RichTextPainter::List RichTextPainter::fromTextDocument(const QTextDocument &doc)
{
List r;
for (QTextBlock block = doc.begin(); block != doc.end(); block = block.next())
{
for (QTextBlock::iterator it = block.begin(); it != block.end(); it++)
{
QTextFragment fragment = it.fragment();
QTextCharFormat format = fragment.charFormat();
CustomRichText_t text;
text.text = fragment.text();
text.textColor = format.foreground().color();
text.textBackground = format.background().color();
bool hasForeground = format.hasProperty(QTextFormat::ForegroundBrush);
bool hasBackground = format.hasProperty(QTextFormat::BackgroundBrush);
if (hasForeground && !hasBackground)
{
text.flags = FlagColor;
}
else if (!hasForeground && hasBackground)
{
text.flags = FlagBackground;
}
else if (hasForeground && hasBackground)
{
text.flags = FlagAll;
}
else
{
text.flags = FlagNone;
}
r.push_back(text);
}
}
return r;
}
RichTextPainter::List RichTextPainter::cropped(const RichTextPainter::List &richText, int maxCols, const QString &indicator, bool *croppedOut)
{
List r;

View File

@ -3,6 +3,7 @@
#define RICHTEXTPAINTER_H
#include <QString>
#include <QTextDocument>
#include <QColor>
#include <vector>
@ -39,6 +40,8 @@ public:
static void paintRichText(QPainter* painter, int x, int y, int w, int h, int xinc, const List & richText, CachedFontMetrics* fontMetrics);
static void htmlRichText(const List & richText, QString & textHtml, QString & textPlain);
static List fromTextDocument(const QTextDocument &doc);
static List cropped(const List &richText, int maxCols, const QString &indicator = nullptr, bool *croppedOut = nullptr);
};

View File

@ -112,8 +112,9 @@ void DisassemblerGraphView::refreshView()
void DisassemblerGraphView::loadCurrentGraph()
{
TempConfig tempConfig;
tempConfig.set("scr.html", true);
QJsonDocument functionsDoc = Core()->cmdj("agJ@e:scr.html=true");
tempConfig.set("scr.html", true)
.set("scr.color", true);
QJsonDocument functionsDoc = Core()->cmdj("agJ");
QJsonArray functions = functionsDoc.array();
disassembly_blocks.clear();
@ -187,14 +188,14 @@ void DisassemblerGraphView::loadCurrentGraph()
// Skip last byte, otherwise it will overlap with next instruction
i.size -= 1;
RichTextPainter::List richText;
QString disas;
disas = op["text"].toString();
QTextDocument textDoc;
textDoc.setHtml(disas);
Colors::colorizeAssembly(richText, textDoc.toPlainText(), 0);
RichTextPainter::List richText = RichTextPainter::fromTextDocument(textDoc);
//Colors::colorizeAssembly(richText, textDoc.toPlainText(), 0);
bool cropped;
int blockLength = Config()->getGraphBlockMaxChars() + Core()->getConfigb("asm.bytes") * 24 + Core()->getConfigb("asm.emu") * 10;