Preview: toggling between main text and fields would confuse the text format (plain/rich)

This commit is contained in:
Jean-Francois Dockes 2010-07-07 13:08:38 +02:00
parent e6d5f72886
commit 4cbdfd7f89
2 changed files with 11 additions and 5 deletions

View File

@ -954,6 +954,7 @@ bool Preview::loadDocInCurrentTab(const Rcl::Doc &idoc, int docnum)
PreviewTextEdit *editor = currentEditor();
editor->setText("");
editor->setTextFormat(Qt::RichText);
editor->m_data.format = Qt::RichText;
bool inputishtml = !fdoc.mimetype.compare("text/html");
#if 0
@ -1031,6 +1032,7 @@ bool Preview::loadDocInCurrentTab(const Rcl::Doc &idoc, int docnum)
qrichlst.push_back(qr);
} else {
editor->setTextFormat(Qt::PlainText);
editor->m_data.format = Qt::PlainText;
for (int pos = 0; pos < (int)qr.length(); pos += l) {
l = MIN(CHUNKL, qr.length() - pos);
qrichlst.push_back(qr.mid(pos, l));
@ -1127,6 +1129,7 @@ void PreviewTextEdit::toggleFields()
// If currently displaying fields, switch to body text
if (m_dspflds) {
setTextFormat(m_data.format);
setText(m_data.richtxt);
m_dspflds = false;
return;
@ -1134,6 +1137,7 @@ void PreviewTextEdit::toggleFields()
// Else display fields
m_dspflds = true;
setTextFormat(Qt::RichText);
QString txt = "<html><head></head><body>\n";
txt += "<b>" + QString::fromLocal8Bit(m_data.url.c_str());
if (!m_data.ipath.empty())
@ -1143,7 +1147,8 @@ void PreviewTextEdit::toggleFields()
for (map<string,string>::const_iterator it = m_data.fdoc.meta.begin();
it != m_data.fdoc.meta.end(); it++) {
txt += "<dt>" + QString::fromUtf8(it->first.c_str()) + "</dt> "
+ "<dd>" + QString::fromUtf8(it->second.c_str()) + "</dd>\n";
+ "<dd>" + QString::fromUtf8(escapeHtml(it->second).c_str())
+ "</dd>\n";
}
txt += "</dl></body></html>";
setText(txt);

View File

@ -57,10 +57,11 @@ public:
// doc out of internfile (previous fields come from the index) with
// main text erased (for space).
Rcl::Doc fdoc;
// Saved rich text: the textedit seems to sometimes (but not
// always) return its text stripped of tags, so this is needed
// (for printing for example)
QString richtxt;
// Saved rich (or plain actually) text: the textedit seems to
// sometimes (but not always) return its text stripped of tags, so
// this is needed (for printing for example)
QString richtxt;
Qt::TextFormat format;
TabData()
: docnum(-1)
{}