mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 20:06:12 +00:00
Crop Line Length in Graph
This commit is contained in:
parent
e2357abf3d
commit
46e862a3b8
@ -38,6 +38,10 @@ public:
|
||||
void setDarkTheme(bool set);
|
||||
bool getDarkTheme() { return s.value("dark").toBool(); }
|
||||
|
||||
// Graph
|
||||
int getGraphBlockMaxChars() const { return s.value("graph.maxcols", 50).toInt(); }
|
||||
void setGraphBlockMaxChars(int ch) { s.setValue("graph.maxcols", ch); }
|
||||
|
||||
// TODO Imho it's wrong doing it this way. Should find something else.
|
||||
bool getAsmESIL() const { return s.value("asm.esil", false).toBool(); }
|
||||
void setAsmESIL(bool v) { s.setValue("asm.esil", v); }
|
||||
|
@ -101,3 +101,58 @@ void RichTextPainter::htmlRichText(const List & richText, QString & textHtml, QS
|
||||
textPlain += curRichText.text;
|
||||
}
|
||||
}
|
||||
|
||||
RichTextPainter::List RichTextPainter::cropped(const RichTextPainter::List &richText, int maxCols, const QString &indicator)
|
||||
{
|
||||
List r;
|
||||
r.reserve(richText.size());
|
||||
|
||||
int cols = 0;
|
||||
bool cropped = false;
|
||||
for(const auto &text : richText)
|
||||
{
|
||||
int textLength = text.text.size();
|
||||
if(cols + textLength <= maxCols)
|
||||
{
|
||||
r.push_back(text);
|
||||
cols += textLength;
|
||||
}
|
||||
else if(cols == maxCols)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
CustomRichText_t croppedText = text;
|
||||
croppedText.text.truncate(maxCols - cols);
|
||||
r.push_back(croppedText);
|
||||
cropped = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(cropped && !indicator.isEmpty())
|
||||
{
|
||||
int indicatorCropLength = indicator.length();
|
||||
if(indicatorCropLength > maxCols)
|
||||
{
|
||||
indicatorCropLength = maxCols;
|
||||
}
|
||||
|
||||
while(!r.empty())
|
||||
{
|
||||
auto &text = r.back();
|
||||
|
||||
if(text.text.length() >= indicatorCropLength)
|
||||
{
|
||||
text.text.replace(text.text.length() - indicatorCropLength, indicatorCropLength, indicator);
|
||||
break;
|
||||
}
|
||||
|
||||
indicatorCropLength -= text.text.length();
|
||||
r.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -38,6 +38,8 @@ public:
|
||||
//functions
|
||||
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 cropped(const List &richText, int maxCols, const QString &indicator = nullptr);
|
||||
};
|
||||
|
||||
#endif // RICHTEXTPAINTER_H
|
||||
|
@ -165,7 +165,7 @@ void DisassemblerGraphView::loadCurrentGraph()
|
||||
comment.flags = RichTextPainter::FlagColor;
|
||||
richText.insert(richText.end(), comment);
|
||||
}
|
||||
i.text = Text(richText);
|
||||
i.text = Text(RichTextPainter::cropped(richText, Config()->getGraphBlockMaxChars(), "..."));
|
||||
db.instrs.push_back(i);
|
||||
}
|
||||
disassembly_blocks[db.entry] = db;
|
||||
|
Loading…
Reference in New Issue
Block a user