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

View File

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

View File

@ -462,8 +462,37 @@ void ResListPager::displayPage(RclConfig *config)
chunk << "</p>" << endl; chunk << "</p>" << endl;
chunk << "</body></html>" << endl; chunk << "</body></html>" << endl;
append(chunk.rdbuf()->str()); 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 // Default implementations for things that should be implemented by
// specializations // specializations
string ResListPager::nextUrl() string ResListPager::nextUrl()

View File

@ -79,9 +79,16 @@ public:
} }
void resultPageNext(); void resultPageNext();
void resultPageFor(int docnum); void resultPageFor(int docnum);
/* Display page of results */
void displayPage(RclConfig *); 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, void displayDoc(RclConfig *, int idx, Rcl::Doc& doc,
const HighlightData& hdata, const string& sh = ""); const HighlightData& hdata, const string& sh = "");
bool pageEmpty() {return m_respage.size() == 0;} bool pageEmpty() {return m_respage.size() == 0;}
string queryDescription() { string queryDescription() {
@ -95,6 +102,9 @@ public:
virtual bool append(const string& data, int, const Rcl::Doc&) { virtual bool append(const string& data, int, const Rcl::Doc&) {
return append(data); 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 // Translation function. This is reimplemented in the qt reslist
// object For this to work, the strings must be duplicated inside // object For this to work, the strings must be duplicated inside
// reslist.cpp (see the QT_TR_NOOP in there). Very very unwieldy. // reslist.cpp (see the QT_TR_NOOP in there). Very very unwieldy.

View File

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