Crop Line Length in Graph

This commit is contained in:
Florian Märkl 2017-12-19 17:00:42 +01:00
parent e2357abf3d
commit 46e862a3b8
4 changed files with 62 additions and 1 deletions

View File

@ -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); }

View File

@ -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;
}

View File

@ -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

View File

@ -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;