GUI: support Ctrl+Plus/Ctrl+Minus to increase or decrease the font size (results and preview)
This commit is contained in:
parent
d54ee6040a
commit
fbec7a6adb
@ -30,6 +30,7 @@
|
||||
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
#include <QFont>
|
||||
|
||||
RclDynConf *g_dynconf;
|
||||
AdvSearchHist *g_advshistory;
|
||||
@ -200,7 +201,7 @@ void rwSettings(bool writing)
|
||||
SETTING_RW(prefs.reslistfontfamily, "/Recoll/prefs/reslist/fontFamily",
|
||||
String, "");
|
||||
SETTING_RW(prefs.reslistfontsize, "/Recoll/prefs/reslist/fontSize", Int,
|
||||
10);
|
||||
QFont().pointSize());
|
||||
|
||||
QString rlfDflt = QString::fromUtf8(prefs.dfltResListFormat);
|
||||
if (writing) {
|
||||
|
||||
@ -49,12 +49,12 @@ public:
|
||||
int historysize{0};
|
||||
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
|
||||
int reslistfontsize;
|
||||
// Result list format string
|
||||
QString reslistformat;
|
||||
string creslistformat;
|
||||
|
||||
@ -123,11 +123,20 @@ void Preview::init()
|
||||
resize(QSize(640, 480).expandedTo(minimumSizeHint()));
|
||||
}
|
||||
|
||||
if (prefs.reslistfontfamily != "") {
|
||||
m_font = QFont(prefs.reslistfontfamily, prefs.reslistfontsize);
|
||||
} else {
|
||||
m_font = QFont();
|
||||
m_font.setPointSize(prefs.reslistfontsize);
|
||||
}
|
||||
|
||||
(void)new HelpClient(this);
|
||||
HelpClient::installMap((const char *)objectName().toUtf8(),
|
||||
"RCL.SEARCH.GUI.PREVIEW");
|
||||
|
||||
// signals and slots connections
|
||||
connect(new QShortcut(QKeySequence::ZoomIn,this), SIGNAL (activated()), this, SLOT (zoomIn()));
|
||||
connect(new QShortcut(QKeySequence::ZoomOut,this),SIGNAL (activated()), this, SLOT (zoomOut()));
|
||||
connect(searchTextCMB, SIGNAL(editTextChanged(const QString&)),
|
||||
this, SLOT(searchTextChanged(const QString&)));
|
||||
connect(nextPB, SIGNAL(clicked()), this, SLOT(nextPressed()));
|
||||
@ -168,6 +177,24 @@ void Preview::onNewShortcuts()
|
||||
}
|
||||
}
|
||||
|
||||
void Preview::zoomIn()
|
||||
{
|
||||
m_font.setPointSize(m_font.pointSize()+1);
|
||||
PreviewTextEdit *edit = currentEditor();
|
||||
if (edit) {
|
||||
edit->displayText();
|
||||
}
|
||||
}
|
||||
|
||||
void Preview::zoomOut()
|
||||
{
|
||||
m_font.setPointSize(m_font.pointSize()-1);
|
||||
PreviewTextEdit *edit = currentEditor();
|
||||
if (edit) {
|
||||
edit->displayText();
|
||||
}
|
||||
}
|
||||
|
||||
void Preview::listShortcuts()
|
||||
{
|
||||
LISTSHORTCUT(null, "preview:151", tr("Preview Window"),
|
||||
@ -806,6 +833,7 @@ bool Preview::loadDocInCurrentTab(const Rcl::Doc &idoc, int docnum)
|
||||
}
|
||||
#endif
|
||||
|
||||
editor->setFont(m_font);
|
||||
editor->setHtml("");
|
||||
editor->m_format = Qt::RichText;
|
||||
bool inputishtml = !lthr.fdoc.mimetype.compare("text/html");
|
||||
@ -1048,10 +1076,27 @@ void PreviewTextEdit::createPopupMenu(const QPoint& pos)
|
||||
void PreviewTextEdit::displayText()
|
||||
{
|
||||
LOGDEB1("PreviewTextEdit::displayText()\n");
|
||||
// Ensuring that the view does not move when changing the font
|
||||
// size and redisplaying the text: can't find a good way to do
|
||||
// it. The only imperfect way I found was to get the position for
|
||||
// the last line (approximately), and make the position visible
|
||||
// after the change.
|
||||
auto c = cursorForPosition(QPoint(0,height()-20));
|
||||
int pos = c.position();
|
||||
// static int lastpos;
|
||||
// std::cerr << "POSITION: " << pos << " DELTA " << pos -lastpos << "\n";
|
||||
// lastpos = pos;
|
||||
setFont(m_preview->m_font);
|
||||
if (m_format == Qt::PlainText)
|
||||
setPlainText(m_richtxt);
|
||||
else
|
||||
setHtml(m_richtxt);
|
||||
if (m_curdsp == PTE_DSPTXT) {
|
||||
auto cursor = textCursor();
|
||||
cursor.setPosition(pos);
|
||||
setTextCursor(cursor);
|
||||
ensureCursorVisible();
|
||||
}
|
||||
m_curdsp = PTE_DSPTXT;
|
||||
}
|
||||
|
||||
@ -1060,6 +1105,7 @@ void PreviewTextEdit::displayFields()
|
||||
{
|
||||
LOGDEB1("PreviewTextEdit::displayFields()\n");
|
||||
|
||||
setFont(m_preview->m_font);
|
||||
QString txt = "<html><head></head><body>\n";
|
||||
txt += "<b>" + path2qs(m_url);
|
||||
if (!m_ipath.empty())
|
||||
@ -1080,6 +1126,7 @@ void PreviewTextEdit::displayFields()
|
||||
void PreviewTextEdit::displayImage()
|
||||
{
|
||||
LOGDEB1("PreviewTextEdit::displayImage()\n");
|
||||
setFont(m_preview->m_font);
|
||||
if (m_image.isNull())
|
||||
displayText();
|
||||
|
||||
|
||||
@ -29,8 +29,9 @@
|
||||
#include <memory>
|
||||
|
||||
#include <QComboBox>
|
||||
#include <qvariant.h>
|
||||
#include <qwidget.h>
|
||||
#include <QVariant>
|
||||
#include <QWidget>
|
||||
#include <QFont>
|
||||
|
||||
#ifdef PREVIEW_TEXTBROWSER
|
||||
#include <QTextBrowser>
|
||||
@ -68,7 +69,7 @@ public:
|
||||
PreviewTextEdit(QWidget* parent, const char* name, Preview *pv);
|
||||
void moveToAnchor(const QString& name);
|
||||
enum DspType {PTE_DSPTXT, PTE_DSPFLDS, PTE_DSPIMG};
|
||||
|
||||
|
||||
public slots:
|
||||
virtual void displayFields();
|
||||
virtual void displayText();
|
||||
@ -164,6 +165,9 @@ public slots:
|
||||
virtual void emitEditRequested();
|
||||
virtual void togglePlainPre();
|
||||
virtual void onNewShortcuts();
|
||||
// Other
|
||||
virtual void zoomIn();
|
||||
virtual void zoomOut();
|
||||
|
||||
signals:
|
||||
void previewClosed(Preview *);
|
||||
@ -190,6 +194,7 @@ private:
|
||||
bool m_loading{false};
|
||||
HighlightData m_hData;
|
||||
bool m_justCreated{true}; // First tab create is different
|
||||
QFont m_font;
|
||||
QShortcut *m_closewinsc{nullptr};
|
||||
QShortcut *m_nextdocsc{nullptr};
|
||||
QShortcut *m_prevdocsc{nullptr};
|
||||
|
||||
@ -288,6 +288,8 @@ void RclMain::init()
|
||||
connect(this, SIGNAL(resultsReady()),
|
||||
reslist, SLOT(readDocSource()));
|
||||
connect(this, SIGNAL(uiPrefsChanged()), reslist, SLOT(onUiPrefsChanged()));
|
||||
connect(new QShortcut(QKeySequence::ZoomIn,this), SIGNAL (activated()), this, SLOT (zoomIn()));
|
||||
connect(new QShortcut(QKeySequence::ZoomOut,this),SIGNAL (activated()), this, SLOT (zoomOut()));
|
||||
|
||||
connect(reslist, SIGNAL(hasResults(int)),
|
||||
this, SLOT(resultCount(int)));
|
||||
@ -337,6 +339,17 @@ void RclMain::init()
|
||||
periodictimer->start(1000);
|
||||
}
|
||||
|
||||
void RclMain::zoomIn()
|
||||
{
|
||||
prefs.reslistfontsize++;
|
||||
emit uiPrefsChanged();
|
||||
}
|
||||
void RclMain::zoomOut()
|
||||
{
|
||||
prefs.reslistfontsize--;
|
||||
emit uiPrefsChanged();
|
||||
}
|
||||
|
||||
void RclMain::onNewShortcuts()
|
||||
{
|
||||
SCBase& scb = SCBase::scBase();
|
||||
|
||||
@ -168,7 +168,9 @@ public slots:
|
||||
virtual void onNewShortcuts();
|
||||
virtual void toggleTable();
|
||||
virtual void hideToolTip();
|
||||
|
||||
virtual void zoomIn();
|
||||
virtual void zoomOut();
|
||||
|
||||
private slots:
|
||||
virtual void updateIdxStatus();
|
||||
virtual void onWebcacheDestroyed(QObject *);
|
||||
|
||||
@ -439,7 +439,7 @@ void ResList::setFont()
|
||||
{
|
||||
#if defined(USING_WEBKIT) || defined(USING_WEBENGINE)
|
||||
# ifndef SETFONT_WITH_HEADSTYLE
|
||||
if (prefs.reslistfontfamily.length()) {
|
||||
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,
|
||||
@ -447,16 +447,18 @@ void ResList::setFont()
|
||||
settings()->setFontFamily(QWEBSETTINGS::StandardFont,
|
||||
prefs.reslistfontfamily);
|
||||
} else {
|
||||
settings()->resetFontSize(QWEBSETTINGS::DefaultFontSize);
|
||||
settings()->setFontSize(QWEBSETTINGS::DefaultFontSize, prefs.reslistfontsize + 3);
|
||||
settings()->resetFontFamily(QWEBSETTINGS::StandardFont);
|
||||
}
|
||||
# endif
|
||||
#else
|
||||
if (prefs.reslistfontfamily.length()) {
|
||||
if (prefs.reslistfontfamily != "") {
|
||||
QFont nfont(prefs.reslistfontfamily, prefs.reslistfontsize);
|
||||
QTextBrowser::setFont(nfont);
|
||||
} else {
|
||||
QTextBrowser::setFont(QFont());
|
||||
QFont font;
|
||||
font.setPointSize(prefs.reslistfontsize);
|
||||
QTextBrowser::setFont(font);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -156,16 +156,18 @@ 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;
|
||||
}
|
||||
int fs = prefs.reslistfontsize;
|
||||
// fs shows slightly bigger in qtextbrowser? adjust.
|
||||
if (prefs.reslistfontsize > fsadjustdetail) {
|
||||
fs -= fsadjustdetail;
|
||||
}
|
||||
if (prefs.reslistfontfamily != "") {
|
||||
QFont nfont(prefs.reslistfontfamily, fs);
|
||||
QTextBrowser::setFont(nfont);
|
||||
} else {
|
||||
QTextBrowser::setFont(QFont());
|
||||
QFont font;
|
||||
font.setPointSize(fs);
|
||||
QTextBrowser::setFont(font);
|
||||
}
|
||||
}
|
||||
|
||||
@ -807,8 +809,12 @@ void ResTable::toggleVHeader()
|
||||
void ResTable::onUiPrefsChanged()
|
||||
{
|
||||
if (m_detail) {
|
||||
m_detail->init();
|
||||
m_detail->setFont();
|
||||
}
|
||||
// Not sure that this is the right way, but something is needed to
|
||||
// repaint with a possible new font. Toggling alternaterowcolors
|
||||
// works too
|
||||
tableView->update(tableView->indexAt(QPoint(0, 0)));
|
||||
if (prefs.noResTableHeader) {
|
||||
tableView->horizontalHeader()->hide();
|
||||
} else {
|
||||
|
||||
@ -142,7 +142,7 @@ void SnippetsW::init()
|
||||
browser->setUndoRedoEnabled(false);
|
||||
browser->setOpenLinks(false);
|
||||
browser->setTabChangesFocus(true);
|
||||
if (prefs.reslistfontfamily.length()) {
|
||||
if (prefs.reslistfontfamily != "") {
|
||||
QFont nfont(prefs.reslistfontfamily, prefs.reslistfontsize);
|
||||
browser->setFont(nfont);
|
||||
} else {
|
||||
|
||||
@ -627,7 +627,7 @@ void UIPrefsDialog::showSynFileDialog()
|
||||
void UIPrefsDialog::resetReslistFont()
|
||||
{
|
||||
reslistFontFamily = "";
|
||||
reslistFontSize = 0;
|
||||
reslistFontSize = QFont().pointSize();
|
||||
setupReslistFontPB();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user