mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-07 07:22:15 +00:00
Use r2 colors in graph
This commit is contained in:
parent
75bf8cf5b6
commit
f21cdfa5c0
@ -2,6 +2,8 @@
|
|||||||
#include "RichTextPainter.h"
|
#include "RichTextPainter.h"
|
||||||
#include "CachedFontMetrics.h"
|
#include "CachedFontMetrics.h"
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QTextBlock>
|
||||||
|
#include <QTextFragment>
|
||||||
|
|
||||||
//TODO: fix performance (possibly use QTextLayout?)
|
//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)
|
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)
|
RichTextPainter::List RichTextPainter::cropped(const RichTextPainter::List &richText, int maxCols, const QString &indicator, bool *croppedOut)
|
||||||
{
|
{
|
||||||
List r;
|
List r;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#define RICHTEXTPAINTER_H
|
#define RICHTEXTPAINTER_H
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QTextDocument>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <vector>
|
#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 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 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);
|
static List cropped(const List &richText, int maxCols, const QString &indicator = nullptr, bool *croppedOut = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -112,8 +112,9 @@ void DisassemblerGraphView::refreshView()
|
|||||||
void DisassemblerGraphView::loadCurrentGraph()
|
void DisassemblerGraphView::loadCurrentGraph()
|
||||||
{
|
{
|
||||||
TempConfig tempConfig;
|
TempConfig tempConfig;
|
||||||
tempConfig.set("scr.html", true);
|
tempConfig.set("scr.html", true)
|
||||||
QJsonDocument functionsDoc = Core()->cmdj("agJ@e:scr.html=true");
|
.set("scr.color", true);
|
||||||
|
QJsonDocument functionsDoc = Core()->cmdj("agJ");
|
||||||
QJsonArray functions = functionsDoc.array();
|
QJsonArray functions = functionsDoc.array();
|
||||||
|
|
||||||
disassembly_blocks.clear();
|
disassembly_blocks.clear();
|
||||||
@ -187,14 +188,14 @@ void DisassemblerGraphView::loadCurrentGraph()
|
|||||||
// Skip last byte, otherwise it will overlap with next instruction
|
// Skip last byte, otherwise it will overlap with next instruction
|
||||||
i.size -= 1;
|
i.size -= 1;
|
||||||
|
|
||||||
RichTextPainter::List richText;
|
|
||||||
QString disas;
|
QString disas;
|
||||||
disas = op["text"].toString();
|
disas = op["text"].toString();
|
||||||
|
|
||||||
QTextDocument textDoc;
|
QTextDocument textDoc;
|
||||||
textDoc.setHtml(disas);
|
textDoc.setHtml(disas);
|
||||||
|
|
||||||
Colors::colorizeAssembly(richText, textDoc.toPlainText(), 0);
|
RichTextPainter::List richText = RichTextPainter::fromTextDocument(textDoc);
|
||||||
|
//Colors::colorizeAssembly(richText, textDoc.toPlainText(), 0);
|
||||||
|
|
||||||
bool cropped;
|
bool cropped;
|
||||||
int blockLength = Config()->getGraphBlockMaxChars() + Core()->getConfigb("asm.bytes") * 24 + Core()->getConfigb("asm.emu") * 10;
|
int blockLength = Config()->getGraphBlockMaxChars() + Core()->getConfigb("asm.bytes") * 24 + Core()->getConfigb("asm.emu") * 10;
|
||||||
|
Loading…
Reference in New Issue
Block a user