don't copy html if more than 2048 lines are selected
This commit is contained in:
parent
50bbdda757
commit
36a7fba118
|
|
@ -1405,9 +1405,17 @@ void CPUDisassembly::copySelectionSlot(bool copyBytes)
|
|||
QString selectionString = "";
|
||||
QString selectionHtmlString = "";
|
||||
QTextStream stream(&selectionString);
|
||||
QTextStream htmlStream(&selectionHtmlString);
|
||||
pushSelectionInto(copyBytes, stream, &htmlStream);
|
||||
Bridge::CopyToClipboard(selectionString, selectionHtmlString);
|
||||
if(getSelectionEnd() - getSelectionStart() < 2048)
|
||||
{
|
||||
QTextStream htmlStream(&selectionHtmlString);
|
||||
pushSelectionInto(copyBytes, stream, &htmlStream);
|
||||
Bridge::CopyToClipboard(selectionString, selectionHtmlString);
|
||||
}
|
||||
else
|
||||
{
|
||||
pushSelectionInto(copyBytes, stream, nullptr);
|
||||
Bridge::CopyToClipboard(selectionString);
|
||||
}
|
||||
}
|
||||
|
||||
void CPUDisassembly::copySelectionToFileSlot(bool copyBytes)
|
||||
|
|
@ -1449,7 +1457,7 @@ void CPUDisassembly::pushSelectionInto(bool copyBytes, QTextStream & stream, QTe
|
|||
QString bytes;
|
||||
QString bytesHtml;
|
||||
if(copyBytes)
|
||||
RichTextPainter::htmlRichText(getRichBytes(inst, false), bytesHtml, bytes);
|
||||
RichTextPainter::htmlRichText(getRichBytes(inst, false), &bytesHtml, bytes);
|
||||
QString disassembly;
|
||||
QString htmlDisassembly;
|
||||
if(htmlStream)
|
||||
|
|
@ -1459,7 +1467,7 @@ void CPUDisassembly::pushSelectionInto(bool copyBytes, QTextStream & stream, QTe
|
|||
ZydisTokenizer::TokenToRichText(inst.tokens, richText, &mHighlightToken);
|
||||
else
|
||||
ZydisTokenizer::TokenToRichText(inst.tokens, richText, 0);
|
||||
RichTextPainter::htmlRichText(richText, htmlDisassembly, disassembly);
|
||||
RichTextPainter::htmlRichText(richText, &htmlDisassembly, disassembly);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1616,25 +1624,46 @@ void CPUDisassembly::copyHeaderVaSlot()
|
|||
|
||||
void CPUDisassembly::copyDisassemblySlot()
|
||||
{
|
||||
QString clipboardHtml = QString("<div style=\"font-family: %1; font-size: %2px\">").arg(font().family()).arg(getRowHeight());
|
||||
QString clipboard = "";
|
||||
prepareDataRange(getSelectionStart(), getSelectionEnd(), [&](int i, const Instruction_t & inst)
|
||||
if(getSelectionEnd() - getSelectionStart() < 2048)
|
||||
{
|
||||
if(i)
|
||||
QString clipboardHtml = QString("<div style=\"font-family: %1; font-size: %2px\">").arg(font().family()).arg(getRowHeight());
|
||||
prepareDataRange(getSelectionStart(), getSelectionEnd(), [&](int i, const Instruction_t & inst)
|
||||
{
|
||||
clipboard += "\r\n";
|
||||
clipboardHtml += "<br/>";
|
||||
}
|
||||
RichTextPainter::List richText;
|
||||
if(mHighlightToken.text.length())
|
||||
ZydisTokenizer::TokenToRichText(inst.tokens, richText, &mHighlightToken);
|
||||
else
|
||||
ZydisTokenizer::TokenToRichText(inst.tokens, richText, 0);
|
||||
RichTextPainter::htmlRichText(richText, clipboardHtml, clipboard);
|
||||
return true;
|
||||
});
|
||||
clipboardHtml += QString("</div>");
|
||||
Bridge::CopyToClipboard(clipboard, clipboardHtml);
|
||||
if(i)
|
||||
{
|
||||
clipboard += "\r\n";
|
||||
clipboardHtml += "<br/>";
|
||||
}
|
||||
RichTextPainter::List richText;
|
||||
if(mHighlightToken.text.length())
|
||||
ZydisTokenizer::TokenToRichText(inst.tokens, richText, &mHighlightToken);
|
||||
else
|
||||
ZydisTokenizer::TokenToRichText(inst.tokens, richText, 0);
|
||||
RichTextPainter::htmlRichText(richText, &clipboardHtml, clipboard);
|
||||
return true;
|
||||
});
|
||||
clipboardHtml += QString("</div>");
|
||||
Bridge::CopyToClipboard(clipboard, clipboardHtml);
|
||||
}
|
||||
else
|
||||
{
|
||||
prepareDataRange(getSelectionStart(), getSelectionEnd(), [&](int i, const Instruction_t & inst)
|
||||
{
|
||||
if(i)
|
||||
{
|
||||
clipboard += "\r\n";
|
||||
}
|
||||
RichTextPainter::List richText;
|
||||
if(mHighlightToken.text.length())
|
||||
ZydisTokenizer::TokenToRichText(inst.tokens, richText, &mHighlightToken);
|
||||
else
|
||||
ZydisTokenizer::TokenToRichText(inst.tokens, richText, 0);
|
||||
RichTextPainter::htmlRichText(richText, nullptr, clipboard);
|
||||
return true;
|
||||
});
|
||||
Bridge::CopyToClipboard(clipboard);
|
||||
}
|
||||
}
|
||||
|
||||
void CPUDisassembly::labelCopySlot()
|
||||
|
|
|
|||
|
|
@ -1455,7 +1455,7 @@ void TraceBrowser::pushSelectionInto(bool copyBytes, QTextStream & stream, QText
|
|||
QString bytes;
|
||||
QString bytesHTML;
|
||||
if(copyBytes)
|
||||
RichTextPainter::htmlRichText(getRichBytes(inst), bytesHTML, bytes);
|
||||
RichTextPainter::htmlRichText(getRichBytes(inst), &bytesHTML, bytes);
|
||||
QString disassembly;
|
||||
QString htmlDisassembly;
|
||||
if(htmlStream)
|
||||
|
|
@ -1465,7 +1465,7 @@ void TraceBrowser::pushSelectionInto(bool copyBytes, QTextStream & stream, QText
|
|||
ZydisTokenizer::TokenToRichText(inst.tokens, richText, &mHighlightToken);
|
||||
else
|
||||
ZydisTokenizer::TokenToRichText(inst.tokens, richText, 0);
|
||||
RichTextPainter::htmlRichText(richText, htmlDisassembly, disassembly);
|
||||
RichTextPainter::htmlRichText(richText, &htmlDisassembly, disassembly);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1488,7 +1488,7 @@ void TraceBrowser::pushSelectionInto(bool copyBytes, QTextStream & stream, QText
|
|||
ZydisTokenizer::TokenToRichText(regTokens, richText, &mHighlightToken);
|
||||
else
|
||||
ZydisTokenizer::TokenToRichText(regTokens, richText, 0);
|
||||
RichTextPainter::htmlRichText(richText, registersHtml, registersText);
|
||||
RichTextPainter::htmlRichText(richText, ®istersHtml, registersText);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1506,7 +1506,7 @@ void TraceBrowser::pushSelectionInto(bool copyBytes, QTextStream & stream, QText
|
|||
ZydisTokenizer::TokenToRichText(memTokens, richText, &mHighlightToken);
|
||||
else
|
||||
ZydisTokenizer::TokenToRichText(memTokens, richText, 0);
|
||||
RichTextPainter::htmlRichText(richText, memoryHtml, memoryText);
|
||||
RichTextPainter::htmlRichText(richText, &memoryHtml, memoryText);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1572,9 +1572,17 @@ void TraceBrowser::copySelectionSlot(bool copyBytes)
|
|||
QString selectionString = "";
|
||||
QString selectionHtmlString = "";
|
||||
QTextStream stream(&selectionString);
|
||||
QTextStream htmlStream(&selectionHtmlString);
|
||||
pushSelectionInto(copyBytes, stream, &htmlStream);
|
||||
Bridge::CopyToClipboard(selectionString, selectionHtmlString);
|
||||
if(getSelectionEnd() - getSelectionStart() < 2048)
|
||||
{
|
||||
QTextStream htmlStream(&selectionHtmlString);
|
||||
pushSelectionInto(copyBytes, stream, &htmlStream);
|
||||
Bridge::CopyToClipboard(selectionString, selectionHtmlString);
|
||||
}
|
||||
else
|
||||
{
|
||||
pushSelectionInto(copyBytes, stream, nullptr);
|
||||
Bridge::CopyToClipboard(selectionString);
|
||||
}
|
||||
}
|
||||
|
||||
void TraceBrowser::copySelectionToFileSlot(bool copyBytes)
|
||||
|
|
@ -1623,22 +1631,40 @@ void TraceBrowser::copyDisassemblySlot()
|
|||
if(mTraceFile == nullptr || mTraceFile->Progress() < 100)
|
||||
return;
|
||||
|
||||
QString clipboardHtml = QString("<div style=\"font-family: %1; font-size: %2px\">").arg(font().family()).arg(getRowHeight());
|
||||
QString clipboard = "";
|
||||
for(auto i = getSelectionStart(); i <= getSelectionEnd(); i++)
|
||||
if(getSelectionEnd() - getSelectionStart() < 2048)
|
||||
{
|
||||
if(i != getSelectionStart())
|
||||
QString clipboardHtml = QString("<div style=\"font-family: %1; font-size: %2px\">").arg(font().family()).arg(getRowHeight());
|
||||
for(auto i = getSelectionStart(); i <= getSelectionEnd(); i++)
|
||||
{
|
||||
clipboard += "\r\n";
|
||||
clipboardHtml += "<br/>";
|
||||
if(i != getSelectionStart())
|
||||
{
|
||||
clipboard += "\r\n";
|
||||
clipboardHtml += "<br/>";
|
||||
}
|
||||
RichTextPainter::List richText;
|
||||
const Instruction_t & inst = mTraceFile->Instruction(i);
|
||||
ZydisTokenizer::TokenToRichText(inst.tokens, richText, 0);
|
||||
RichTextPainter::htmlRichText(richText, &clipboardHtml, clipboard);
|
||||
}
|
||||
RichTextPainter::List richText;
|
||||
const Instruction_t & inst = mTraceFile->Instruction(i);
|
||||
ZydisTokenizer::TokenToRichText(inst.tokens, richText, 0);
|
||||
RichTextPainter::htmlRichText(richText, clipboardHtml, clipboard);
|
||||
clipboardHtml += QString("</div>");
|
||||
Bridge::CopyToClipboard(clipboard, clipboardHtml);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(auto i = getSelectionStart(); i <= getSelectionEnd(); i++)
|
||||
{
|
||||
if(i != getSelectionStart())
|
||||
{
|
||||
clipboard += "\r\n";
|
||||
}
|
||||
RichTextPainter::List richText;
|
||||
const Instruction_t & inst = mTraceFile->Instruction(i);
|
||||
ZydisTokenizer::TokenToRichText(inst.tokens, richText, 0);
|
||||
RichTextPainter::htmlRichText(richText, nullptr, clipboard);
|
||||
}
|
||||
Bridge::CopyToClipboard(clipboard);
|
||||
}
|
||||
clipboardHtml += QString("</div>");
|
||||
Bridge::CopyToClipboard(clipboard, clipboardHtml);
|
||||
}
|
||||
|
||||
void TraceBrowser::copyRvaSlot()
|
||||
|
|
|
|||
|
|
@ -60,43 +60,47 @@ void RichTextPainter::paintRichText(QPainter* painter, int x, int y, int w, int
|
|||
* @param textHtml The HTML source. Any previous content will be preserved and new content will be appended at the end.
|
||||
* @param textPlain The plain text. Any previous content will be preserved and new content will be appended at the end.
|
||||
*/
|
||||
void RichTextPainter::htmlRichText(const List & richText, QString & textHtml, QString & textPlain)
|
||||
void RichTextPainter::htmlRichText(const List & richText, QString* textHtml, QString & textPlain)
|
||||
{
|
||||
for(const CustomRichText_t & curRichText : richText)
|
||||
{
|
||||
if(curRichText.text == " ") //blank
|
||||
{
|
||||
textHtml += " ";
|
||||
if(textHtml)
|
||||
*textHtml += " ";
|
||||
textPlain += " ";
|
||||
continue;
|
||||
}
|
||||
switch(curRichText.flags)
|
||||
if(textHtml)
|
||||
{
|
||||
case FlagNone: //defaults
|
||||
textHtml += "<span>";
|
||||
break;
|
||||
case FlagColor: //color only
|
||||
textHtml += QString("<span style=\"color:%1\">").arg(curRichText.textColor.name());
|
||||
break;
|
||||
case FlagBackground: //background only
|
||||
if(curRichText.textBackground != Qt::transparent) // QColor::name() returns "#000000" for transparent color. That's not desired. Leave it blank.
|
||||
textHtml += QString("<span style=\"background-color:%1\">").arg(curRichText.textBackground.name());
|
||||
else
|
||||
textHtml += QString("<span>");
|
||||
break;
|
||||
case FlagAll: //color+background
|
||||
if(curRichText.textBackground != Qt::transparent) // QColor::name() returns "#000000" for transparent color. That's not desired. Leave it blank.
|
||||
textHtml += QString("<span style=\"color:%1; background-color:%2\">").arg(curRichText.textColor.name(), curRichText.textBackground.name());
|
||||
else
|
||||
textHtml += QString("<span style=\"color:%1\">").arg(curRichText.textColor.name());
|
||||
break;
|
||||
switch(curRichText.flags)
|
||||
{
|
||||
case FlagNone: //defaults
|
||||
*textHtml += "<span>";
|
||||
break;
|
||||
case FlagColor: //color only
|
||||
*textHtml += QString("<span style=\"color:%1\">").arg(curRichText.textColor.name());
|
||||
break;
|
||||
case FlagBackground: //background only
|
||||
if(curRichText.textBackground != Qt::transparent) // QColor::name() returns "#000000" for transparent color. That's not desired. Leave it blank.
|
||||
*textHtml += QString("<span style=\"background-color:%1\">").arg(curRichText.textBackground.name());
|
||||
else
|
||||
*textHtml += QString("<span>");
|
||||
break;
|
||||
case FlagAll: //color+background
|
||||
if(curRichText.textBackground != Qt::transparent) // QColor::name() returns "#000000" for transparent color. That's not desired. Leave it blank.
|
||||
*textHtml += QString("<span style=\"color:%1; background-color:%2\">").arg(curRichText.textColor.name(), curRichText.textBackground.name());
|
||||
else
|
||||
*textHtml += QString("<span style=\"color:%1\">").arg(curRichText.textColor.name());
|
||||
break;
|
||||
}
|
||||
if(curRichText.underline) //Underline highlighted token
|
||||
*textHtml += "<u>";
|
||||
*textHtml += curRichText.text.toHtmlEscaped();
|
||||
if(curRichText.underline)
|
||||
*textHtml += "</u>";
|
||||
*textHtml += "</span>"; //Close the tag
|
||||
}
|
||||
if(curRichText.underline) //Underline highlighted token
|
||||
textHtml += "<u>";
|
||||
textHtml += curRichText.text.toHtmlEscaped();
|
||||
if(curRichText.underline)
|
||||
textHtml += "</u>";
|
||||
textHtml += "</span>"; //Close the tag
|
||||
textPlain += curRichText.text;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ 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 void htmlRichText(const List & richText, QString* textHtml, QString & textPlain);
|
||||
};
|
||||
|
||||
#endif // RICHTEXTPAINTER_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue