From 450867c45b48e6420a339fff8305006563a545cf Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Tue, 3 Mar 2020 18:56:55 +0100 Subject: [PATCH] Adjust the restable font sizes based on the result list ones --- src/qtgui/rclmain_w.cpp | 8 ++- src/qtgui/rclmain_w.h | 1 + src/qtgui/reslist.cpp | 5 ++ src/qtgui/reslist.h | 3 +- src/qtgui/restable.cpp | 130 +++++++++++++++++++++++++++------------- src/qtgui/restable.h | 6 +- 6 files changed, 107 insertions(+), 46 deletions(-) diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index cca8df87..f31120a4 100644 --- a/src/qtgui/rclmain_w.cpp +++ b/src/qtgui/rclmain_w.cpp @@ -297,6 +297,7 @@ void RclMain::init() this, SLOT(onSetDescription(QString))); connect(sSearch, SIGNAL(clearSearch()), this, SLOT(resetSearch())); + connect(this, SIGNAL(uiPrefsChanged()), sSearch, SLOT(setPrefs())); connect(preferencesMenu, SIGNAL(triggered(QAction*)), this, SLOT(setStemLang(QAction*))); connect(preferencesMenu, SIGNAL(aboutToShow()), @@ -373,6 +374,7 @@ void RclMain::init() restable, SLOT(readDocSource())); connect(this, SIGNAL(sortDataChanged(DocSeqSortSpec)), restable, SLOT(onSortDataChanged(DocSeqSortSpec))); + connect(this, SIGNAL(uiPrefsChanged()), restable, SLOT(onUiPrefsChanged())); connect(restable->getModel(), SIGNAL(sortDataChanged(DocSeqSortSpec)), this, SLOT(onSortDataChanged(DocSeqSortSpec))); @@ -399,7 +401,8 @@ void RclMain::init() reslist, SLOT(resetList())); connect(this, SIGNAL(resultsReady()), reslist, SLOT(readDocSource())); - + connect(this, SIGNAL(uiPrefsChanged()), reslist, SLOT(onUiPrefsChanged())); + connect(reslist, SIGNAL(hasResults(int)), this, SLOT(resultCount(int))); connect(reslist, SIGNAL(wordSelect(QString)), @@ -1091,8 +1094,7 @@ void RclMain::setUIPrefs() if (!uiprefs) return; LOGDEB("Recollmain::setUIPrefs\n"); - reslist->setFont(); - sSearch->setPrefs(); + emit uiPrefsChanged(); enbSynAction->setDisabled(prefs.synFile.isEmpty()); enbSynAction->setChecked(prefs.synFileEnable); } diff --git a/src/qtgui/rclmain_w.h b/src/qtgui/rclmain_w.h index df9235cc..9b07687c 100644 --- a/src/qtgui/rclmain_w.h +++ b/src/qtgui/rclmain_w.h @@ -168,6 +168,7 @@ signals: void sortDataChanged(DocSeqSortSpec); void resultsReady(); void searchReset(); + void uiPrefsChanged(); protected: virtual void closeEvent(QCloseEvent *); diff --git a/src/qtgui/reslist.cpp b/src/qtgui/reslist.cpp index d46a6b97..2e87db50 100644 --- a/src/qtgui/reslist.cpp +++ b/src/qtgui/reslist.cpp @@ -453,6 +453,11 @@ void ResList::runJS(const QString& js) #endif } +void ResList::onUiPrefsChanged() +{ + setFont(); +} + void ResList::setFont() { #if defined(USING_WEBKIT) || defined(USING_WEBENGINE) diff --git a/src/qtgui/reslist.h b/src/qtgui/reslist.h index be9542cb..5c02c88f 100644 --- a/src/qtgui/reslist.h +++ b/src/qtgui/reslist.h @@ -93,7 +93,8 @@ public slots: virtual void highlighted(const QString& link); virtual void createPopupMenu(const QPoint& pos); virtual void showQueryDetails(); - + virtual void onUiPrefsChanged(); + signals: void nextPageAvailable(bool); void prevPageAvailable(bool); diff --git a/src/qtgui/restable.cpp b/src/qtgui/restable.cpp index e8389344..6e909e62 100644 --- a/src/qtgui/restable.cpp +++ b/src/qtgui/restable.cpp @@ -63,6 +63,10 @@ static const QKeySequence closeKeySeq("Ctrl+w"); static const int ROWHEIGHTPAD = 2; static const int TEXTINCELLVTRANS = -4; +// Adjust font size from prefs, display is slightly different here +static const int fsadjustdetail = 1; +static const int fsadjusttable = 1; + static PlainToRichQtReslist g_hiliter; ////////////////////////////////////////////////////////////////////////// @@ -144,6 +148,21 @@ void ResTableDetailArea::createPopupMenu(const QPoint& pos) } } +void ResTableDetailArea::setFont() +{ + if (prefs.reslistfontsize) { + // fs shows slightly bigger in qtextbrowser? adjust. + int fs = prefs.reslistfontsize; + if (prefs.reslistfontsize > fsadjustdetail) { + fs -= fsadjustdetail; + } + QFont nfont(prefs.reslistfontfamily, fs); + QTextBrowser::setFont(nfont); + } else { + QTextBrowser::setFont(QFont()); + } +} + ////////////////////////////////////////////////////////////////////////////// //// Data model methods //// @@ -356,6 +375,18 @@ QVariant RecollModel::data(const QModelIndex& index, int role) const { LOGDEB2("RecollModel::data: row " << index.row() << " col " << index.column() << " role " << role << "\n"); + + // The font is actually set in the custom delegate, but we need + // this to adjust the row height (there is probably a better way + // to do it in the delegate?) + if (role == Qt::FontRole && prefs.reslistfontsize > 0) { + QFont font = m_table->font(); + int fs = prefs.reslistfontsize <= fsadjusttable ? prefs.reslistfontsize: + prefs.reslistfontsize - fsadjusttable; + font.setPointSize(fs); + return font; + } + if (!m_source || role != Qt::DisplayRole || !index.isValid() || index.column() >= int(m_fields.size())) { return QVariant(); @@ -460,44 +491,56 @@ public: // and a way to pass an indicator from data(), a bit more // difficult. Anyway, the display seems fast enough as is. void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const - { - QStyleOptionViewItem opt = option; - initStyleOption(&opt, index); - QVariant value = index.data(Qt::DisplayRole); - if (value.isValid() && !value.isNull()) { - QString text = value.toString(); - if (!text.isEmpty()) { - QTextDocument document; - painter->save(); - if (opt.state & QStyle::State_Selected) { - painter->fillRect(opt.rect, opt.palette.highlight()); - // Set the foreground color. The pen approach does - // 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 -#if 0 - QPen pen = painter->pen(); - pen.setBrush(opt.palette.brush(QPalette::HighlightedText)); - painter->setPen(pen); -#else - text = QString::fromUtf8("
") + - text + QString::fromUtf8("
"); -#endif - } - painter->setClipRect(option.rect); - QPoint where = option.rect.topLeft(); - where.ry() += TEXTINCELLVTRANS; - painter->translate(where); - document.setHtml(text); - document.drawContents(painter); - painter->restore(); - return; - } - } - QStyledItemDelegate::paint(painter, option, index); + const QModelIndex &index) const { + QStyleOptionViewItem opt = option; + initStyleOption(&opt, index); + QVariant value = index.data(Qt::DisplayRole); + 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("
"; + ntxt += text + QString::fromUtf8("
"); + text.swap(ntxt); + } else { + if (!fstyle.isEmpty()) { + QString ntxt("
") + text + QString("
"); + 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; + } } + QStyledItemDelegate::paint(painter, option, index); + } }; void ResTable::init() @@ -543,6 +586,7 @@ void ResTable::init() if (header) { header->setDefaultSectionSize(QApplication::fontMetrics().height() + ROWHEIGHTPAD); + header->setSectionResizeMode(QHeaderView::ResizeToContents); } QShortcut *sc = new QShortcut(QKeySequence(Qt::Key_Escape), this); @@ -571,6 +615,7 @@ void ResTable::init() m_detail->setReadOnly(true); m_detail->setUndoRedoEnabled(false); m_detail->setOpenLinks(false); + m_detail->setFont(); // signals and slots connections connect(m_detail, SIGNAL(anchorClicked(const QUrl &)), this, SLOT(linkWasClicked(const QUrl &))); @@ -626,6 +671,12 @@ void ResTable::setRclMain(RclMain *m, bool ismain) m_rclmain, SLOT(showSnippets(Rcl::Doc))); } +void ResTable::onUiPrefsChanged() +{ + if (m_detail) + m_detail->setFont(); +} + int ResTable::getDetailDocNumOrTopRow() { if (m_detaildocnum >= 0) @@ -835,8 +886,8 @@ void ResTable::linkWasClicked(const QUrl &url) // Open parent folder case 'F': { - emit editRequested(ResultPopup::getParent(std::shared_ptr(), - m_detaildoc)); + emit editRequested(ResultPopup::getParent( + std::shared_ptr(), m_detaildoc)); } break; @@ -1084,4 +1135,3 @@ void ResTable::addColumn() qs2utf8s(action->data().toString()) << "\n"); m_model->addColumn(m_popcolumn, qs2utf8s(action->data().toString())); } - diff --git a/src/qtgui/restable.h b/src/qtgui/restable.h index 9c0fafbb..2bf814a9 100644 --- a/src/qtgui/restable.h +++ b/src/qtgui/restable.h @@ -94,7 +94,8 @@ class ResTableDetailArea : public QTextBrowser { public slots: virtual void createPopupMenu(const QPoint& pos); - + virtual void setFont(); + private: ResTable *m_table; }; @@ -156,7 +157,8 @@ public slots: virtual void linkWasClicked(const QUrl&); virtual void makeRowVisible(int row); virtual void takeFocus(); - + virtual void onUiPrefsChanged(); + signals: void docPreviewClicked(int, Rcl::Doc, int); void docSaveToFileClicked(Rcl::Doc);