Get the result table detail area to use the reslist HTML style (e.g. for dark mode)

This commit is contained in:
Jean-Francois Dockes 2020-09-10 10:53:38 +02:00
parent c1ef2187d3
commit 199abb9980
5 changed files with 125 additions and 69 deletions

View File

@ -79,22 +79,28 @@ public:
ResTablePager(ResTable *p)
: ResListPager(1, prefs.alwaysSnippets), m_parent(p)
{}
virtual bool append(const string& data, int idx, const Rcl::Doc& doc);
virtual string trans(const string& in);
virtual const string &parFormat();
virtual string absSep() {return (const char *)(prefs.abssep.toUtf8());}
virtual bool append(const string& data) override;
virtual bool flush() override;
virtual string trans(const string& in) override;
virtual const string &parFormat() override;
virtual string absSep() override {
return (const char *)(prefs.abssep.toUtf8());}
virtual string headerContent() override {
return qs2utf8s(prefs.reslistheadertext);}
private:
ResTable *m_parent;
string m_data;
};
bool ResTablePager::append(const string& data, int, const Rcl::Doc&)
bool ResTablePager::append(const string& data)
{
m_parent->m_detail->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor);
m_parent->m_detail->textCursor().insertBlock();
m_parent->m_detail->insertHtml(u8s2qs(data));
// LOGDEB("RESTABLEPAGER::APPEND: data : " << data << std::endl);
// m_parent->m_detail->setHtml(u8s2qs(data));
m_data += data;
return true;
}
bool ResTablePager::flush()
{
m_parent->m_detail->setHtml(u8s2qs(m_data));
m_data = "";
return true;
}
@ -147,6 +153,12 @@ void ResTableDetailArea::setFont()
}
}
void ResTableDetailArea::init()
{
setFont();
QTextBrowser::setHtml("");
}
//////////////////////////////////////////////////////////////////////////////
//// Data model methods
////
@ -474,51 +486,54 @@ public:
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
QVariant value = index.data(Qt::DisplayRole);
QString text;
if (value.isValid() && !value.isNull()) {
QString text = value.toString();
if (!text.isEmpty()) {
QTextDocument document;
painter->save();
QString fstyle;
if (prefs.reslistfontsize > 0) {
int fs = prefs.reslistfontsize <= fsadjusttable ?
prefs.reslistfontsize :
prefs.reslistfontsize - fsadjusttable;
fstyle = QString("font-size: %1pt").arg(fs);
}
if (opt.state & QStyle::State_Selected) {
painter->fillRect(opt.rect, opt.palette.highlight());
// Set the foreground color. Tried with pen
// approach did not seem to work, probably it's
// reset by the textdocument. Couldn't use
// setdefaultstylesheet() either. the div thing is
// an ugly hack. Works for now
QString ntxt("<div style='color: white");
if (!fstyle.isEmpty()) {
ntxt += QString(";") + fstyle;
}
ntxt += "'>";
ntxt += text + QString::fromUtf8("</div>");
text.swap(ntxt);
} else {
if (!fstyle.isEmpty()) {
QString ntxt("<div style='");
ntxt += fstyle;
ntxt += QString("'>") + text + QString("</div>");
text.swap(ntxt);
}
}
painter->setClipRect(option.rect);
QPoint where = option.rect.topLeft();
where.ry() += TEXTINCELLVTRANS;
painter->translate(where);
document.setHtml(text);
document.drawContents(painter);
painter->restore();
return;
}
text = value.toString();
}
QStyledItemDelegate::paint(painter, option, index);
if (text.isEmpty()) {
QStyledItemDelegate::paint(painter, option, index);
return;
}
painter->save();
QTextDocument document;
QString fstyle;
if (prefs.reslistfontsize > 0) {
int fs = prefs.reslistfontsize <= fsadjusttable ?
prefs.reslistfontsize :
prefs.reslistfontsize - fsadjusttable;
fstyle = QString("font-size: %1pt").arg(fs);
}
if (opt.state & QStyle::State_Selected) {
painter->fillRect(opt.rect, opt.palette.highlight());
// Set the foreground color. Tried with pen
// approach did not seem to work, probably it's
// reset by the textdocument. Couldn't use
// setdefaultstylesheet() either. the div thing is
// an ugly hack. Works for now
QString ntxt("<div style='color: white");
if (!fstyle.isEmpty()) {
ntxt += QString(";") + fstyle;
}
ntxt += "'>";
ntxt += text + QString::fromUtf8("</div>");
text.swap(ntxt);
} else {
if (!fstyle.isEmpty()) {
QString ntxt("<div style='");
ntxt += fstyle;
ntxt += QString("'>") + text + QString("</div>");
text.swap(ntxt);
}
}
painter->setClipRect(option.rect);
QPoint where = option.rect.topLeft();
where.ry() += TEXTINCELLVTRANS;
painter->translate(where);
document.setHtml(text);
document.drawContents(painter);
painter->restore();
}
};
@ -594,7 +609,7 @@ void ResTable::init()
m_detail->setReadOnly(true);
m_detail->setUndoRedoEnabled(false);
m_detail->setOpenLinks(false);
m_detail->setFont();
m_detail->init();
// signals and slots connections
connect(m_detail, SIGNAL(anchorClicked(const QUrl &)),
this, SLOT(linkWasClicked(const QUrl &)));
@ -652,8 +667,9 @@ void ResTable::setRclMain(RclMain *m, bool ismain)
void ResTable::onUiPrefsChanged()
{
if (m_detail)
m_detail->setFont();
if (m_detail) {
m_detail->init();
}
}
int ResTable::getDetailDocNumOrTopRow()
@ -670,7 +686,7 @@ void ResTable::makeRowVisible(int row)
QModelIndex modelIndex = m_model->index(row, 0);
tableView->scrollTo(modelIndex, QAbstractItemView::PositionAtTop);
tableView->selectionModel()->clear();
m_detail->clear();
m_detail->init();
m_detaildocnum = -1;
}
@ -715,11 +731,11 @@ void ResTable::onTableView_currentChanged(const QModelIndex& index)
return;
Rcl::Doc doc;
if (m_model->getDocSource()->getDoc(index.row(), doc)) {
m_detail->clear();
m_detail->init();
m_detaildocnum = index.row();
m_detaildoc = doc;
m_pager->displayDoc(theconfig, m_detaildocnum, m_detaildoc,
m_model->m_hdata);
m_pager->displaySingleDoc(theconfig, m_detaildocnum, m_detaildoc,
m_model->m_hdata);
emit(detailDocChanged(doc, m_model->getDocSource()));
} else {
m_detaildocnum = -1;
@ -748,7 +764,7 @@ void ResTable::setDocSource(std::shared_ptr<DocSequence> nsource)
if (m_pager)
m_pager->setDocSource(nsource, 0);
if (m_detail)
m_detail->clear();
m_detail->init();
m_detaildocnum = -1;
}
@ -828,7 +844,7 @@ void ResTable::readDocSource(bool resetPos)
m_model->m_hdata.clear();
}
m_model->readDocSource();
m_detail->clear();
m_detail->init();
m_detaildocnum = -1;
}
@ -916,7 +932,7 @@ void ResTable::onDoubleClick(const QModelIndex& index)
Rcl::Doc doc;
if (m_model->getDocSource()->getDoc(index.row(), doc)) {
if (m_detaildocnum != index.row()) {
m_detail->clear();
m_detail->init();
m_detaildocnum = index.row();
m_pager->displayDoc(theconfig, index.row(), m_detaildoc,
m_model->m_hdata);

View File

@ -96,7 +96,8 @@ class ResTableDetailArea : public QTextBrowser {
public slots:
virtual void createPopupMenu(const QPoint& pos);
virtual void setFont();
virtual void init();
private:
ResTable *m_table;
};

View File

@ -462,8 +462,37 @@ void ResListPager::displayPage(RclConfig *config)
chunk << "</p>" << endl;
chunk << "</body></html>" << endl;
append(chunk.rdbuf()->str());
flush();
}
void ResListPager::displaySingleDoc(RclConfig *config, int idx,
Rcl::Doc& doc,
const HighlightData& hdata)
{
ostringstream chunk;
// Header
// Note: have to append text in chunks that make sense
// html-wise. If we break things up too much, the editor
// gets confused.
string bdtag("<body ");
bdtag += bodyAttrs();
rtrimstring(bdtag, " ");
bdtag += ">";
chunk << "<html><head>\n"
<< "<meta http-equiv=\"content-type\""
<< " content=\"text/html; charset=utf-8\">\n"
<< headerContent()
<< "</head>\n" << bdtag << "\n";
append(chunk.rdbuf()->str());
// Document
displayDoc(config, idx, doc, hdata, string());
// Footer
append("</body></html>\n");
flush();
}
// Default implementations for things that should be implemented by
// specializations
string ResListPager::nextUrl()

View File

@ -79,9 +79,16 @@ public:
}
void resultPageNext();
void resultPageFor(int docnum);
/* Display page of results */
void displayPage(RclConfig *);
/* Display page with single document */
void displaySingleDoc(RclConfig *config, int idx,
Rcl::Doc& doc, const HighlightData& hdata);
/* Generate HTML for single document inside page */
void displayDoc(RclConfig *, int idx, Rcl::Doc& doc,
const HighlightData& hdata, const string& sh = "");
bool pageEmpty() {return m_respage.size() == 0;}
string queryDescription() {
@ -95,6 +102,9 @@ public:
virtual bool append(const string& data, int, const Rcl::Doc&) {
return append(data);
}
/* Implementing this allows accumulating the text and setting the HTML
at once */
virtual bool flush() {return true;}
// Translation function. This is reimplemented in the qt reslist
// object For this to work, the strings must be duplicated inside
// reslist.cpp (see the QT_TR_NOOP in there). Very very unwieldy.

View File

@ -29,7 +29,6 @@
/* Light on dark text everywhere*/
* {
/* font-size: 14pt;*/
background-color: #373737;
color: #ffffff;
selection-background-color: #424e72;
@ -61,9 +60,10 @@ QTabWidget QTabBar::tab:selected {
/*
* Slightly *darker* background for text entry areas, and brighter
* (lighter) foreground.
* QTableView excluded until we fix the font color...
*/
QComboBox[editable="true"], QTextEdit, QLineEdit,
QTextBrowser, QTableView, QWebView, QPlainTextEdit {
background-color: #101010; /*Changed*/
color: #ffffff; /*Changed*/
QTextBrowser, QWebView, QPlainTextEdit {
background-color: #101010;
color: #ffffff;
}