From 7f57df250ab6da1e764ac434c1e88af6c3b82307 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Wed, 28 Dec 2011 18:25:47 +0100 Subject: [PATCH] GUI: allow choosing a style sheet to be used by the recoll app --- src/doc/user/usermanual.sgml | 14 ++++++- src/qtgui/guiutils.cpp | 9 +++-- src/qtgui/guiutils.h | 4 +- src/qtgui/main.cpp | 9 +++++ src/qtgui/uiprefs.ui | 72 +++++++++++++++++++++++++++++------- src/qtgui/uiprefs_w.cpp | 27 ++++++++++++++ src/qtgui/uiprefs_w.h | 5 ++- src/recollinstall.in | 1 + src/sampleconf/recoll.qss | 44 ++++++++++++++++++++++ 9 files changed, 164 insertions(+), 21 deletions(-) create mode 100644 src/sampleconf/recoll.qss diff --git a/src/doc/user/usermanual.sgml b/src/doc/user/usermanual.sgml index 6fd504ba..8c323c5c 100644 --- a/src/doc/user/usermanual.sgml +++ b/src/doc/user/usermanual.sgml @@ -3263,10 +3263,20 @@ while query.next >= 0 and query.next < nres: Most of the parameters specific to the recoll GUI are set through the - Preferences menu and stored in the - standard Qt place ($HOME/.qt/recollrc). + Preferences menu and stored in the standard Qt + place ($HOME/.config/Recoll.org/recoll.conf). You probably do not want to edit this by hand. + One of these parameters is the name of a + Qt 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 + (recoll.qss) inside the + /usr/share/recoll/examples directory. Using a + style sheet, you can change most Recoll graphical parameters: colors, + fonts, etc. See the sample file for a few simple examples. + + &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 diff --git a/src/qtgui/guiutils.cpp b/src/qtgui/guiutils.cpp index 52d3d8c5..db7d9a26 100644 --- a/src/qtgui/guiutils.cpp +++ b/src/qtgui/guiutils.cpp @@ -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 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); } diff --git a/src/qtgui/guiutils.h b/src/qtgui/guiutils.h index 4e3d5d56..24774b37 100644 --- a/src/qtgui/guiutils.h +++ b/src/qtgui/guiutils.h @@ -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_ */ diff --git a/src/qtgui/main.cpp b/src/qtgui/main.cpp index 26814e88..d0779287 100644 --- a/src/qtgui/main.cpp +++ b/src/qtgui/main.cpp @@ -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; diff --git a/src/qtgui/uiprefs.ui b/src/qtgui/uiprefs.ui index 071f1e64..4c75f2da 100644 --- a/src/qtgui/uiprefs.ui +++ b/src/qtgui/uiprefs.ui @@ -22,7 +22,7 @@ - 1 + 0 @@ -61,19 +61,6 @@ - - - - If checked, results with the same content under different names will only be shown once. - - - Hide duplicate results. - - - false - - - @@ -201,6 +188,40 @@ + + + + + + Style sheet + + + false + + + + + + + Opens a dialog to select the style sheet file + + + Choose + + + + + + + Resets the style sheet to default + + + Reset + + + + + @@ -323,6 +344,19 @@ Search parameters + + + + If checked, results with the same content under different names will only be shown once. + + + Hide duplicate results. + + + false + + + @@ -342,6 +376,16 @@ + + + + QFrame::HLine + + + QFrame::Sunken + + + diff --git a/src/qtgui/uiprefs_w.cpp b/src/qtgui/uiprefs_w.cpp index 16fae8b8..fcee1482 100644 --- a/src/qtgui/uiprefs_w.cpp +++ b/src/qtgui/uiprefs_w.cpp @@ -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 = ""; diff --git a/src/qtgui/uiprefs_w.h b/src/qtgui/uiprefs_w.h index 2dc74586..3bc8a468 100644 --- a/src/qtgui/uiprefs_w.h +++ b/src/qtgui/uiprefs_w.h @@ -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(); diff --git a/src/recollinstall.in b/src/recollinstall.in index 0cd2827a..5950bae8 100755 --- a/src/recollinstall.in +++ b/src/recollinstall.in @@ -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 diff --git a/src/sampleconf/recoll.qss b/src/sampleconf/recoll.qss new file mode 100644 index 00000000..62e821bb --- /dev/null +++ b/src/sampleconf/recoll.qss @@ -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; +}