GUI: try to improve font size consistency.

- Use px everywhere.
- Get rid of confusing never used compile time option.
- Fix reslist not reacting to zoomIn/zoomOut
- Other small adjustements.
This commit is contained in:
Jean-Francois Dockes 2022-06-28 15:56:42 +02:00
parent 96ebb369a5
commit 7ceb9c6837
9 changed files with 39 additions and 83 deletions

View File

@ -427,7 +427,7 @@ void rwSettings(bool writing)
}
#ifdef USE_REGEX
/* font-size: 10pt; */
/* font-size: 10px; */
static const std::string fntsz_exp(
R"((\s*font-size\s*:\s*)([0-9]+)(p[tx]\s*;\s*))"
);
@ -463,24 +463,6 @@ std::string PrefsPack::scaleFonts(const std::string& style, float multiplier)
return nstyle;
}
int PrefsPack::fontsize()
{
// While building the kio, we don't really care about QT Gui
// defaults and referencing QFont introduces a useless dependency
#ifdef BUILDING_RECOLLGUI
int fs;
if (prefs.reslistfontsize > 0) {
fs = prefs.reslistfontsize;
} else {
fs = QWidget().font().pixelSize();
}
fs = round(fs * prefs.wholeuiscale);
return fs;
#else
return 12;
#endif
}
std::string PrefsPack::htmlHeaderContents()
{
auto comfn = path_cat(path_cat(theconfig->getDatadir(), "examples"), "recoll-common.css");
@ -489,13 +471,10 @@ std::string PrefsPack::htmlHeaderContents()
std::ostringstream oss;
oss << comcss << "\n";
oss << "<style type=\"text/css\">\nhtml,body,form, fieldset,table,tr,td,img,select,input {\n";
#ifdef SETFONT_WITH_HEADSTYLE
if (!prefs.reslistfontfamily.isEmpty()) {
oss << "font-family: \"" << qs2utf8s(prefs.reslistfontfamily) << "\";\n";
}
oss << "font-size: " << round(prefs.reslistfontsize * 1.2) << "px;\n";
#endif
oss << "color: " << qs2utf8s(prefs.fontcolor) << ";\n";
oss << "font-size: " << round(prefs.reslistfontsize * 1.1) << "px;\n";
oss << "}\n</style>\n";
oss << qs2utf8s(prefs.darkreslistheadertext) << qs2utf8s(prefs.reslistheadertext);

View File

@ -51,10 +51,6 @@ public:
int maxhltextkbs;
QString reslistfontfamily;
int reslistfontsize;
// Not saved in prefs for now. Computed from qt defaults and used to
// set main character color for webkit/textbrowser reslist and
// snippets window.
QString fontcolor;
QString qtermstyle; // CSS style for query terms in reslist and other places
// Result list format string
QString reslistformat;
@ -190,7 +186,6 @@ public:
// Scale font-sizes inside css or qss input and return changed sheet. The font-size statements
// need to be on their own line.
static std::string scaleFonts(const std::string& style, float multiplier);
int fontsize();
};
/** Global preferences record */

View File

@ -318,7 +318,9 @@ void RclMain::zoomIn()
}
void RclMain::zoomOut()
{
prefs.reslistfontsize--;
if (prefs.reslistfontsize > 1) {
prefs.reslistfontsize--;
}
emit uiPrefsChanged();
}

View File

@ -5,11 +5,6 @@ VPATH = @srcdir@
DEFINES += BUILDING_RECOLL
DEFINES += BUILDING_RECOLLGUI
# Decide if we set font family and style with a css section in the html <head> or with qwebsettings
# setfont... calls. We used to do it with websettings because it gave a faster redisplay, and the
# css has a tendancy to not find some system fonts. We currently do it with css anyway.
DEFINES += SETFONT_WITH_HEADSTYLE=1
@QMAKE_ENABLE_WEBKIT@ QT += webkit
@QMAKE_ENABLE_WEBKIT@ DEFINES += USING_WEBKIT

View File

@ -409,23 +409,13 @@ void ResList::runJS(const QString& js)
void ResList::onUiPrefsChanged()
{
setFont();
displayPage();
}
void ResList::setFont()
{
#if defined(USING_WEBKIT) || defined(USING_WEBENGINE)
#ifndef SETFONT_WITH_HEADSTYLE
if (prefs.reslistfontfamily != "") {
// For some reason there is (12-2014) an offset of 3 between what
// we request from webkit and what we get.
settings()->setFontSize(QWEBSETTINGS::DefaultFontSize, prefs.reslistfontsize + 3);
settings()->setFontFamily(QWEBSETTINGS::StandardFont, prefs.reslistfontfamily);
} else {
settings()->setFontSize(QWEBSETTINGS::DefaultFontSize, prefs.reslistfontsize + 3);
settings()->resetFontFamily(QWEBSETTINGS::StandardFont);
}
#endif
#else
#if !defined(USING_WEBKIT) && !defined(USING_WEBENGINE)
// Using QTextBrowser
if (prefs.reslistfontfamily != "") {
QFont nfont(prefs.reslistfontfamily, prefs.reslistfontsize);
QTextBrowser::setFont(nfont);

View File

@ -67,8 +67,8 @@ 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;
// Adjust font size from prefs, display is slightly different in the table??
static const int fsadjustdetail = -1;
static PlainToRichQtReslist g_hiliter;
@ -92,9 +92,7 @@ public:
virtual string absSep() override {
return (const char *)(prefs.abssep.toUtf8());}
virtual string headerContent() override {
// Note: the detail area is a qtextbrowser which gets confused by the general Html
// header. So we manage it differently from the snippets or main result list.
return qs2utf8s(prefs.darkreslistheadertext) + qs2utf8s(prefs.reslistheadertext);
return prefs.htmlHeaderContents();
}
private:
ResTable *m_parent;
@ -156,13 +154,13 @@ void ResTableDetailArea::createPopupMenu(const QPoint& pos)
void ResTableDetailArea::setFont()
{
int fs = prefs.fontsize() - fsadjustdetail;
int fs = m_table->fontsize();
if (prefs.reslistfontfamily != "") {
QFont nfont(prefs.reslistfontfamily, fs);
QTextBrowser::setFont(nfont);
} else {
QFont font;
font.setPointSize(fs);
font.setPixelSize(fs);
QTextBrowser::setFont(font);
}
}
@ -390,8 +388,8 @@ QVariant RecollModel::data(const QModelIndex& index, int role) const
// 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 || prefs.wholeuiscale != 1.0)) {
if (m_reslfntszforcached != prefs.fontsize() - fsadjustdetail) {
m_reslfntszforcached = prefs.fontsize() - fsadjustdetail;
if (m_reslfntszforcached != m_table->fontsize() - fsadjustdetail) {
m_reslfntszforcached = m_table->fontsize() - fsadjustdetail;
m_table->setDefRowHeight();
m_cachedfont = m_table->font();
m_cachedfont.setPixelSize(m_reslfntszforcached);
@ -533,13 +531,11 @@ public:
QString color = opt.palette.color(QPalette::Base).name();
QString textcolor = opt.palette.color(QPalette::Text).name();
QString selcolor = opt.palette.color(QPalette::Highlight).name();
QString seltextcolor =
opt.palette.color(QPalette::HighlightedText).name();
QString seltextcolor = opt.palette.color(QPalette::HighlightedText).name();
QString fstyle;
if (prefs.reslistfontsize > 0 || prefs.wholeuiscale != 1.0) {
int fs = prefs.fontsize() - fsadjustdetail;
fstyle = QString("font-size: %1pt").arg(fs);
}
QFont fnt = qvariant_cast<QFont>(index.data(Qt::FontRole));
int fs = fnt.pixelSize();
fstyle = QString("font-size: %1px").arg(fs) + ";";
QString ntxt("<div style='");
ntxt += " color:";
ntxt += (opt.state & QStyle::State_Selected)? seltextcolor:textcolor;
@ -550,7 +546,6 @@ public:
ntxt += fstyle;
ntxt += QString("'>") + text + QString("</div>");
text.swap(ntxt);
painter->setClipRect(opt.rect);
QPoint where = option.rect.topLeft();
where.ry() += TEXTINCELLVTRANS;
@ -562,6 +557,19 @@ public:
}
};
int ResTable::fontsize()
{
int fs;
if (prefs.reslistfontsize > 0) {
fs = prefs.reslistfontsize;
} else {
fs = QWidget(this).font().pixelSize();
}
fs = round(fs * prefs.wholeuiscale);
return fs;
}
void ResTable::setDefRowHeight()
{
QHeaderView *header = tableView->verticalHeader();
@ -574,9 +582,9 @@ void ResTable::setDefRowHeight()
// header->setSectionResizeMode(QHeaderView::ResizeToContents);
// Compute ourselves instead, for one row.
QFont font = tableView->font();
int fs = prefs.fontsize() - fsadjustdetail;
int fs = fontsize() - fsadjustdetail;
if (fs > 0)
font.setPointSize(fs);
font.setPixelSize(fs);
QFontMetrics fm(font);
header->setDefaultSectionSize(fm.height() + ROWHEIGHTPAD);
header->setSectionResizeMode(QHeaderView::Fixed);

View File

@ -139,9 +139,9 @@ class ResTable : public QWidget, public Ui::ResTable
public:
ResTable(QWidget* parent = 0, QStringList fields = QStringList())
: QWidget(parent) {
setupUi(this);
init(fields);
}
setupUi(this);
init(fields);
}
virtual ~ResTable() {}
ResTable(const ResTable&) = delete;
@ -152,6 +152,7 @@ public:
void setRclMain(RclMain *m, bool ismain);
void setDefRowHeight();
int fontsize();
public slots:
virtual void onTableView_currentChanged(const QModelIndex&);

View File

@ -106,13 +106,6 @@ void SnippetsW::init()
connect(browser, SIGNAL(linkClicked(const QUrl &)), this, SLOT(onLinkClicked(const QUrl &)));
browser->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
browser->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
#ifndef SETFONT_WITH_HEADSTYLE
QWEBSETTINGS *ws = browser->page()->settings();
if (prefs.reslistfontfamily != "") {
ws->setFontFamily(QWEBSETTINGS::StandardFont, prefs.reslistfontfamily);
ws->setFontSize(QWEBSETTINGS::DefaultFontSize, prefs.reslistfontsize);
}
#endif
browserw->setContextMenuPolicy(Qt::CustomContextMenu);
connect(browserw, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT(createPopupMenu(const QPoint&)));
@ -120,13 +113,6 @@ void SnippetsW::init()
browserw = new QWebEngineView(this);
verticalLayout->insertWidget(0, browserw);
browser->setPage(new SnipWebPage(this));
#ifndef SETFONT_WITH_HEADSTYLE
QWEBSETTINGS *ws = browser->page()->settings();
if (prefs.reslistfontfamily != "") {
ws->setFontFamily(QWEBSETTINGS::StandardFont, prefs.reslistfontfamily);
ws->setFontSize(QWEBSETTINGS::DefaultFontSize, prefs.reslistfontsize);
}
#endif
// Stylesheet TBD
browserw->setContextMenuPolicy(Qt::CustomContextMenu);
connect(browserw, SIGNAL(customContextMenuRequested(const QPoint&)),

View File

@ -53,5 +53,5 @@ Preview QTextEdit {
background: white;
color: black;
font-family: Serif;
font-size: 12pt;
font-size: 12px;
}