GUI: allow choosing a style sheet to be used by the recoll app

This commit is contained in:
Jean-Francois Dockes 2011-12-28 18:25:47 +01:00
parent b5cfacb2f9
commit 7f57df250a
9 changed files with 164 additions and 21 deletions

View File

@ -3263,10 +3263,20 @@ while query.next >= 0 and query.next < nres:
<para>Most of the parameters specific to the
<command>recoll</command> GUI are set through the
<guilabel>Preferences</guilabel> menu and stored in the
standard Qt place (<filename>$HOME/.qt/recollrc</filename>).
<guilabel>Preferences</guilabel> menu and stored in the standard Qt
place (<filename>$HOME/.config/Recoll.org/recoll.conf</filename>).
You probably do not want to edit this by hand.</para>
<note><para>One of these parameters is the name of a
<application>Qt</application> style sheet text file which is applied
to the whole Recoll application on startup. The default value is
empty, but there is a skeleton style sheet
(<filename>recoll.qss</filename>) inside the
<filename>/usr/share/recoll/examples</filename> directory. Using a
style sheet, you can change most Recoll graphical parameters: colors,
fonts, etc. See the sample file for a few simple examples.</para>
</note>
<para>&RCL; indexing options are set inside text configuration
files located in a configuration directory. There can be
several such directories, each of which define the parameters

View File

@ -152,6 +152,7 @@ void rwSettings(bool writing)
prefs.creslistformat = (const char*)prefs.reslistformat.toUtf8();
}
}
SETTING_RW(prefs.stylesheetFile, "/Recoll/prefs/stylesheet", String, "");
SETTING_RW(prefs.queryStemLang, "/Recoll/prefs/query/stemLang", String,
"english");
SETTING_RW(prefs.useDesktopOpen,
@ -330,7 +331,7 @@ void rwSettings(bool writing)
}
}
QString myGetFileName(bool isdir, QString caption)
QString myGetFileName(bool isdir, QString caption, bool filenosave)
{
LOGDEB1(("myFileDialog: isdir %d\n", isdir));
QFileDialog dialog(0, caption);
@ -340,7 +341,10 @@ QString myGetFileName(bool isdir, QString caption)
dialog.setOptions(QFileDialog::ShowDirsOnly);
} else {
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setAcceptMode(QFileDialog::AcceptSave);
if (filenosave)
dialog.setAcceptMode(QFileDialog::AcceptOpen);
else
dialog.setAcceptMode(QFileDialog::AcceptSave);
}
dialog.setViewMode(QFileDialog::List);
QFlags<QDir::Filter> flags = QDir::NoDotAndDotDot | QDir::Hidden;
@ -350,7 +354,6 @@ QString myGetFileName(bool isdir, QString caption)
flags |= QDir::Dirs | QDir::Files;
dialog.setFilter(flags);
if (dialog.exec() == QDialog::Accepted) {
return dialog.selectedFiles().value(0);
}

View File

@ -50,6 +50,7 @@ class PrefsPack {
string creslistformat;
// Abstract snippet separator
QString abssep;
QString stylesheetFile;
QString queryStemLang;
int mainwidth;
int mainheight;
@ -136,6 +137,7 @@ extern QString g_stringAllStem, g_stringNoStem;
/** Specialized version of the qt file dialog. Can't use getOpenFile()
etc. cause they hide dot files... */
extern QString myGetFileName(bool isdir, QString caption = QString());
extern QString myGetFileName(bool isdir, QString caption = QString(),
bool filenosave = false);
#endif /* _GUIUTILS_H_INCLUDED_ */

View File

@ -45,6 +45,8 @@
#include "rclaspell.h"
#endif
#include "smallut.h"
#include "readfile.h"
#include "recollq.h"
RclConfig *theconfig;
@ -315,6 +317,13 @@ int main(int argc, char **argv)
havereadsettings = true;
// fprintf(stderr, "Settings done\n");
if (!prefs.stylesheetFile.isEmpty()) {
string stylesheet;
file_to_string((const char *)prefs.stylesheetFile.toLocal8Bit(),
stylesheet);
if (!stylesheet.empty())
app.setStyleSheet(QString::fromAscii(stylesheet.c_str()));
}
// Create main window and set its size to previous session's
RclMain w;

View File

@ -22,7 +22,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@ -61,19 +61,6 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="collapseDupsCB">
<property name="toolTip">
<string>If checked, results with the same content under different names will only be shown once.</string>
</property>
<property name="text">
<string>Hide duplicate results.</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<item>
@ -201,6 +188,40 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="tLSTL">
<property name="text">
<string>Style sheet</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="stylesheetPB">
<property name="toolTip">
<string>Opens a dialog to select the style sheet file</string>
</property>
<property name="text">
<string>Choose</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="resetSSPB">
<property name="toolTip">
<string>Resets the style sheet to default</string>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<item>
@ -323,6 +344,19 @@
<string>Search parameters</string>
</attribute>
<layout class="QVBoxLayout">
<item>
<widget class="QCheckBox" name="collapseDupsCB">
<property name="toolTip">
<string>If checked, results with the same content under different names will only be shown once.</string>
</property>
<property name="text">
<string>Hide duplicate results.</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout">
<item>
@ -342,6 +376,16 @@
</item>
</layout>
</item>
<item>
<widget class="Line" name="lineX">
<property name="frameShape">
<enum>QFrame::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="autoPhraseCB">
<property name="toolTip">

View File

@ -57,6 +57,8 @@ void UIPrefsDialog::init()
connect(viewActionPB, SIGNAL(clicked()), this, SLOT(showViewAction()));
connect(reslistFontPB, SIGNAL(clicked()), this, SLOT(showFontDialog()));
connect(resetFontPB, SIGNAL(clicked()), this, SLOT(resetReslistFont()));
connect(stylesheetPB, SIGNAL(clicked()), this, SLOT(showStylesheetDialog()));
connect(resetSSPB, SIGNAL(clicked()), this, SLOT(resetStylesheet()));
connect(addExtraDbPB, SIGNAL(clicked()),
this, SLOT(addExtraDbPB_clicked()));
@ -116,6 +118,16 @@ void UIPrefsDialog::setFromPrefs()
reslistFontPB->setText(reslistFontFamily + "-" +
s.setNum(reslistFontSize));
}
// Style sheet
stylesheetFile = prefs.stylesheetFile;
if (stylesheetFile.isEmpty()) {
stylesheetPB->setText(tr("Choose"));
} else {
string nm = path_getsimple((const char *)stylesheetFile.toLocal8Bit());
stylesheetPB->setText(QString::fromLocal8Bit(nm.c_str()));
}
rlfTE->setPlainText(prefs.reslistformat);
// Stemming language combobox
@ -185,11 +197,13 @@ void UIPrefsDialog::accept()
prefs.reslistfontfamily = reslistFontFamily;
prefs.reslistfontsize = reslistFontSize;
prefs.stylesheetFile = stylesheetFile;
prefs.reslistformat = rlfTE->toPlainText();
if (prefs.reslistformat.trimmed().isEmpty()) {
prefs.reslistformat = prefs.dfltResListFormat;
rlfTE->setPlainText(prefs.reslistformat);
}
prefs.creslistformat = (const char*)prefs.reslistformat.toUtf8();
if (stemLangCMB->currentIndex() == 0) {
@ -289,6 +303,19 @@ void UIPrefsDialog::showFontDialog()
}
}
void UIPrefsDialog::showStylesheetDialog()
{
stylesheetFile = myGetFileName(false, "Select stylesheet file", true);
string nm = path_getsimple((const char *)stylesheetFile.toLocal8Bit());
stylesheetPB->setText(QString::fromLocal8Bit(nm.c_str()));
}
void UIPrefsDialog::resetStylesheet()
{
stylesheetFile = "";
stylesheetPB->setText(tr("Choose"));
}
void UIPrefsDialog::resetReslistFont()
{
reslistFontFamily = "";

View File

@ -39,14 +39,17 @@ public:
QString reslistFontFamily;
int reslistFontSize;
QString stylesheetFile;
virtual void init();
public slots:
virtual void showFontDialog();
virtual void resetReslistFont();
virtual void showStylesheetDialog();
virtual void resetStylesheet();
virtual void showViewAction();
virtual void showViewAction(const QString& mt);
virtual void resetReslistFont();
virtual void addExtraDbPB_clicked();
virtual void delExtraDbPB_clicked();
virtual void togExtraDbPB_clicked();

View File

@ -117,6 +117,7 @@ ${INSTALL} -m 0444 \
sampleconf/recoll.conf \
sampleconf/mimemap \
sampleconf/fields \
sampleconf/recoll.qss \
${datadir}/recoll/examples/ || exit 1
${INSTALL} -m 0755 index/rclmon.sh ${datadir}/recoll/examples/ || exit 1

44
src/sampleconf/recoll.qss Normal file
View File

@ -0,0 +1,44 @@
/* Copyright (C) 2004 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
This is an embryonic example Qt style sheet for Recoll. It is not really
supposed to be less ugly than the default look, it's just provided in
hope that someone with better taste will want to step in, or you can use
it to indulge your preference for bright red backgrounds...
If you do want to use it, and encounter a difficulty due to (lack of)
widget object names or whatever, please get in touch, I'll fix what
needs to be.
*/
* {
background: #eeeeee;
}
QComboBox[editable="true"], QTextEdit, QLineEdit, QTextBrowser, QTableView {
background: #ffffee;
}
Preview QTextEdit {
background: white;
font-family: Serif;
font-size: 12pt;
}