Use QTextDocument instead of html to build text display
Continued work on rendering disassembly level text.
This commit is contained in:
@@ -9,6 +9,14 @@ FunctionViewWidget::FunctionViewWidget(QWidget *parent) :
|
||||
ui(new Ui::FunctionViewWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
m_current_rendering = new QTextDocument(ui->textEdit);
|
||||
m_doc_cursor = new QTextCursor(m_current_rendering);
|
||||
ui->textEdit->setTextBackgroundColor(Qt::black);
|
||||
m_current_format = m_doc_cursor->blockFormat();
|
||||
m_current_format.setNonBreakableLines(true); // each block is single line
|
||||
m_current_format.setBackground(Qt::black);
|
||||
m_chars_format.setBackground(Qt::black);
|
||||
m_chars_format.setForeground(Qt::white);
|
||||
//ui->label->setTextFormat(Qt::RichText);
|
||||
}
|
||||
|
||||
@@ -19,21 +27,33 @@ FunctionViewWidget::~FunctionViewWidget()
|
||||
|
||||
void FunctionViewWidget::prtt(const char *s)
|
||||
{
|
||||
m_doc_cursor->insertText(s);
|
||||
collected_text+=s;
|
||||
//collected_text+="<br>";
|
||||
}
|
||||
void FunctionViewWidget::prtt(const QString &s)
|
||||
{
|
||||
m_doc_cursor->insertText(s);
|
||||
collected_text+=s;
|
||||
//collected_text+="<br>";
|
||||
}
|
||||
|
||||
void FunctionViewWidget::addEOL()
|
||||
{
|
||||
m_doc_cursor->insertBlock(m_current_format);
|
||||
m_doc_cursor->setBlockFormat(m_current_format);
|
||||
}
|
||||
void FunctionViewWidget::TAGbegin(TAG_TYPE tag_type, void *p)
|
||||
{
|
||||
QColor col= RenderTag_2_Color(tag_type);
|
||||
|
||||
switch(tag_type)
|
||||
{
|
||||
case XT_Function:
|
||||
collected_text+="<body style='color: #FFFFFF; background-color: #000000'>";
|
||||
m_current_rendering->clear();
|
||||
m_chars_format.setForeground(Qt::white);
|
||||
m_doc_cursor->setBlockFormat(m_current_format);
|
||||
m_doc_cursor->setCharFormat(m_chars_format);
|
||||
break;
|
||||
case XT_FuncName:
|
||||
case XT_Symbol:
|
||||
@@ -42,7 +62,8 @@ void FunctionViewWidget::TAGbegin(TAG_TYPE tag_type, void *p)
|
||||
case XT_Number:
|
||||
case XT_AsmOffset:
|
||||
case XT_AsmLabel:
|
||||
collected_text+="<font color='"+col.name()+"'>";
|
||||
m_chars_format.setForeground(col);
|
||||
m_doc_cursor->setCharFormat(m_chars_format);
|
||||
break;
|
||||
default:
|
||||
qDebug()<<"Tag type:"<<tag_type;
|
||||
@@ -56,13 +77,11 @@ void FunctionViewWidget::TAGend(TAG_TYPE tag_type)
|
||||
{
|
||||
collected_text+="</body>";
|
||||
// TODO: What about attributes with spaces?
|
||||
collected_text.replace(" ", " ");
|
||||
QFile res("result.html");
|
||||
res.open(QFile::WriteOnly);
|
||||
res.write(collected_text.toUtf8());
|
||||
res.write(m_current_rendering->toHtml().toUtf8());
|
||||
res.close();
|
||||
collected_text.replace(QChar('\n'),"<br>");
|
||||
ui->textEdit->setHtml(collected_text);
|
||||
ui->textEdit->setDocument(m_current_rendering);
|
||||
collected_text.clear();
|
||||
break;
|
||||
}
|
||||
@@ -73,7 +92,9 @@ void FunctionViewWidget::TAGend(TAG_TYPE tag_type)
|
||||
case XT_Number:
|
||||
case XT_AsmOffset:
|
||||
case XT_AsmLabel:
|
||||
collected_text+="</font>";
|
||||
m_chars_format.setForeground(Qt::white);
|
||||
m_doc_cursor->setCharFormat(m_chars_format);
|
||||
m_doc_cursor->setBlockFormat(m_current_format);
|
||||
break;
|
||||
default:
|
||||
qDebug()<<"Tag end:"<<tag_type;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#ifndef FUNCTIONVIEWWIDGET_H
|
||||
#define FUNCTIONVIEWWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "StructuredTextTarget.h"
|
||||
#include "RenderTags.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTextDocument>
|
||||
#include <QTextBlockFormat>
|
||||
//#include "XmlPrt.h"
|
||||
namespace Ui {
|
||||
class FunctionViewWidget;
|
||||
@@ -11,12 +14,16 @@ class FunctionViewWidget;
|
||||
class FunctionViewWidget : public QWidget,public IStructuredTextTarget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QTextDocument *m_current_rendering;
|
||||
QTextCursor* m_doc_cursor;
|
||||
QTextBlockFormat m_current_format;
|
||||
QTextCharFormat m_chars_format;
|
||||
public:
|
||||
explicit FunctionViewWidget(QWidget *parent = 0);
|
||||
~FunctionViewWidget();
|
||||
void prtt(const char * s);
|
||||
void prtt(const QString &s);
|
||||
void addEOL() override;
|
||||
void TAGbegin(enum TAG_TYPE tag_type, void * p);
|
||||
void TAGend(enum TAG_TYPE tag_type);
|
||||
private:
|
||||
|
||||
@@ -16,9 +16,22 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTextEdit" name="textEdit">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="undoRedoEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="lineWrapMode">
|
||||
<enum>QTextEdit::NoWrap</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="html">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'Corbel'; font-size:10pt; font-weight:400; font-style:normal;" bgcolor="#000000">
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
||||
@@ -7,10 +7,7 @@ public:
|
||||
virtual void TAGend(TAG_TYPE t)=0;
|
||||
virtual void prtt(const QString &v)=0;
|
||||
|
||||
virtual void addEOL() // some targets might want to disable newlines
|
||||
{
|
||||
prtt("\n");
|
||||
}
|
||||
virtual void addEOL() = 0; // some targets might want to disable newlines
|
||||
void addSpace(int n=1) {
|
||||
while(n--)
|
||||
prtt(" ");
|
||||
|
||||
Reference in New Issue
Block a user