]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiPrefs.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiPrefs.cpp
index 891970b69464a54674115ed2a653c30857388a4c..82073bcbe7cbb07e6d9786e6b31184e6ecec89a6 100644 (file)
@@ -19,6 +19,8 @@
 #include "GuiFontExample.h"
 #include "GuiFontLoader.h"
 #include "GuiKeySymbol.h"
+#include "GuiLyXFiles.h"
+#include "GuiView.h"
 #include "qt_helpers.h"
 #include "Validator.h"
 
@@ -61,7 +63,6 @@
 #include <QHeaderView>
 #include <QLineEdit>
 #include <QMessageBox>
-#include <QPixmapCache>
 #include <QPushButton>
 #include <QSpinBox>
 #include <QString>
@@ -112,7 +113,7 @@ QString browseFile(QString const & filename,
                lastPath = fallback_dir;
 
        FileDialog dlg(title);
-       dlg.setButton2(label1, dir1);
+       dlg.setButton1(label1, dir1);
        dlg.setButton2(label2, dir2);
 
        FileDialog::Result result;
@@ -126,46 +127,6 @@ QString browseFile(QString const & filename,
 }
 
 
-/** Wrapper around browseFile which tries to provide a filename
-*  relative to the user or system directory. The dir, name and ext
-*  parameters have the same meaning as in the
-*  support::LibFileSearch function.
-*/
-QString browseLibFile(QString const & dir,
-       QString const & name,
-       QString const & ext,
-       QString const & title,
-       QStringList const & filters)
-{
-       // FIXME UNICODE
-       QString const label1 = qt_("System files|#S#s");
-       QString const dir1 =
-               toqstr(addName(package().system_support().absFileName(), fromqstr(dir)));
-
-       QString const label2 = qt_("User files|#U#u");
-       QString const dir2 =
-               toqstr(addName(package().user_support().absFileName(), fromqstr(dir)));
-
-       QString const result = browseFile(toqstr(
-               libFileSearch(dir, name, ext).absFileName()),
-               title, filters, false, dir1, dir2, QString(), QString(), dir1);
-
-       // remove the extension if it is the default one
-       QString noextresult;
-       if (getExtension(result) == ext)
-               noextresult = removeExtension(result);
-       else
-               noextresult = result;
-
-       // remove the directory, if it is the default one
-       QString const file = onlyFileName(noextresult);
-       if (toqstr(libFileSearch(dir, file, ext).absFileName()) == result)
-               return file;
-       else
-               return noextresult;
-}
-
-
 /** Launch a file dialog and return the chosen directory.
        pathname: a suggested pathname.
        title: the title of the dialog.
@@ -287,8 +248,8 @@ static void setComboxFont(QComboBox * cb, string const & family,
 
        // We count in reverse in order to prefer the Xft foundry
        for (int i = cb->count(); --i >= 0;) {
-               string name, foundry;
-               parseFontName(cb->itemText(i), name, foundry);
+               string name, fnt_foundry;
+               parseFontName(cb->itemText(i), name, fnt_foundry);
                if (compare_ascii_no_case(name, family) == 0) {
                        cb->setCurrentIndex(i);
                        return;
@@ -301,9 +262,9 @@ static void setComboxFont(QComboBox * cb, string const & family,
 
        // We count in reverse in order to prefer the Xft foundry
        for (int i = cb->count(); --i >= 0; ) {
-               string name, foundry;
-               parseFontName(cb->itemText(i), name, foundry);
-               if (compare_ascii_no_case(name, foundry) == 0) {
+               string name, fnt_foundry;
+               parseFontName(cb->itemText(i), name, fnt_foundry);
+               if (compare_ascii_no_case(name, fnt_foundry) == 0) {
                        cb->setCurrentIndex(i);
                        return;
                }
@@ -349,35 +310,6 @@ static void setComboxFont(QComboBox * cb, string const & family,
 }
 
 
-/////////////////////////////////////////////////////////////////////
-//
-// StrftimeValidator
-//
-/////////////////////////////////////////////////////////////////////
-
-class StrftimeValidator : public QValidator
-{
-public:
-       StrftimeValidator(QWidget *);
-       QValidator::State validate(QString & input, int & pos) const;
-};
-
-
-StrftimeValidator::StrftimeValidator(QWidget * parent)
-       : QValidator(parent)
-{
-}
-
-
-QValidator::State StrftimeValidator::validate(QString & input, int & /*pos*/) const
-{
-       if (is_valid_strftime(fromqstr(input)))
-               return QValidator::Acceptable;
-       else
-               return QValidator::Intermediate;
-}
-
-
 /////////////////////////////////////////////////////////////////////
 //
 // PrefOutput
@@ -389,12 +321,9 @@ PrefOutput::PrefOutput(GuiPreferences * form)
 {
        setupUi(this);
 
-       DateED->setValidator(new StrftimeValidator(DateED));
        dviCB->setValidator(new NoNewLineValidator(dviCB));
        pdfCB->setValidator(new NoNewLineValidator(pdfCB));
 
-       connect(DateED, SIGNAL(textChanged(QString)),
-               this, SIGNAL(changed()));
        connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
                this, SIGNAL(changed()));
        connect(overwriteCO, SIGNAL(activated(int)),
@@ -430,19 +359,8 @@ PrefOutput::PrefOutput(GuiPreferences * form)
 }
 
 
-void PrefOutput::on_DateED_textChanged(const QString &)
-{
-       QString t = DateED->text();
-       int p = 0;
-       bool valid = DateED->validator()->validate(t, p)
-                    == QValidator::Acceptable;
-       setValid(DateLA, valid);
-}
-
-
 void PrefOutput::applyRC(LyXRC & rc) const
 {
-       rc.date_insert_format = fromqstr(DateED->text());
        rc.plaintext_linelen = plaintextLinelengthSB->value();
        rc.forward_search_dvi = fromqstr(dviCB->currentText());
        rc.forward_search_pdf = fromqstr(pdfCB->currentText());
@@ -467,7 +385,6 @@ void PrefOutput::applyRC(LyXRC & rc) const
 
 void PrefOutput::updateRC(LyXRC const & rc)
 {
-       DateED->setText(toqstr(rc.date_insert_format));
        plaintextLinelengthSB->setValue(rc.plaintext_linelen);
        dviCB->setEditText(toqstr(rc.forward_search_dvi));
        pdfCB->setEditText(toqstr(rc.forward_search_pdf));
@@ -725,7 +642,6 @@ PrefLatex::PrefLatex(GuiPreferences * form)
 {
        setupUi(this);
 
-       latexEncodingED->setValidator(new NoNewLineValidator(latexEncodingED));
        latexDviPaperED->setValidator(new NoNewLineValidator(latexDviPaperED));
        latexBibtexED->setValidator(new NoNewLineValidator(latexBibtexED));
        latexJBibtexED->setValidator(new NoNewLineValidator(latexJBibtexED));
@@ -734,10 +650,6 @@ PrefLatex::PrefLatex(GuiPreferences * form)
        latexNomenclED->setValidator(new NoNewLineValidator(latexNomenclED));
        latexChecktexED->setValidator(new NoNewLineValidator(latexChecktexED));
 
-       connect(latexEncodingCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(latexEncodingED, SIGNAL(textChanged(QString)),
-               this, SIGNAL(changed()));
        connect(latexChecktexED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
        connect(latexBibtexCO, SIGNAL(activated(int)),
@@ -771,12 +683,6 @@ PrefLatex::PrefLatex(GuiPreferences * form)
 }
 
 
-void PrefLatex::on_latexEncodingCB_stateChanged(int state)
-{
-       latexEncodingED->setEnabled(state == Qt::Checked);
-}
-
-
 void PrefLatex::on_latexBibtexCO_activated(int n)
 {
        QString const bibtex = latexBibtexCO->itemData(n).toString();
@@ -890,10 +796,6 @@ void PrefLatex::applyRC(LyXRC & rc) const
        else
                rc.index_command = fromqstr(index) + " " + fromqstr(idxopt);
 
-       if (latexEncodingCB->isChecked())
-               rc.fontenc = fromqstr(latexEncodingED->text());
-       else
-               rc.fontenc = "default";
        rc.chktex_command = fromqstr(latexChecktexED->text());
        rc.jindex_command = fromqstr(latexJIndexED->text());
        rc.nomencl_command = fromqstr(latexNomenclED->text());
@@ -990,14 +892,6 @@ void PrefLatex::updateRC(LyXRC const & rc)
                latexIndexOptionsLA->setText(qt_("Co&mmand:"));
        }
 
-       if (rc.fontenc == "default") {
-               latexEncodingCB->setChecked(false);
-               latexEncodingED->setEnabled(false);
-       } else {
-               latexEncodingCB->setChecked(true);
-               latexEncodingED->setEnabled(true);
-               latexEncodingED->setText(toqstr(rc.fontenc));
-       }
        latexChecktexED->setText(toqstr(rc.chktex_command));
        latexJIndexED->setText(toqstr(rc.jindex_command));
        latexNomenclED->setText(toqstr(rc.nomencl_command));
@@ -1062,8 +956,6 @@ PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
                this, SIGNAL(changed()));
        connect(screenHugerED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
-       connect(pixmapCacheCB, SIGNAL(toggled(bool)),
-               this, SIGNAL(changed()));
 
        screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
        screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
@@ -1089,31 +981,17 @@ void PrefScreenFonts::applyRC(LyXRC & rc) const
        parseFontName(screenTypewriterCO->currentText(),
                rc.typewriter_font_name, rc.typewriter_font_foundry);
 
-       rc.zoom = screenZoomSB->value();
-       rc.font_sizes[FONT_SIZE_TINY] = widgetToDoubleStr(screenTinyED);
-       rc.font_sizes[FONT_SIZE_SCRIPT] = widgetToDoubleStr(screenSmallestED);
-       rc.font_sizes[FONT_SIZE_FOOTNOTE] = widgetToDoubleStr(screenSmallerED);
-       rc.font_sizes[FONT_SIZE_SMALL] = widgetToDoubleStr(screenSmallED);
-       rc.font_sizes[FONT_SIZE_NORMAL] = widgetToDoubleStr(screenNormalED);
-       rc.font_sizes[FONT_SIZE_LARGE] = widgetToDoubleStr(screenLargeED);
-       rc.font_sizes[FONT_SIZE_LARGER] = widgetToDoubleStr(screenLargerED);
-       rc.font_sizes[FONT_SIZE_LARGEST] = widgetToDoubleStr(screenLargestED);
-       rc.font_sizes[FONT_SIZE_HUGE] = widgetToDoubleStr(screenHugeED);
-       rc.font_sizes[FONT_SIZE_HUGER] = widgetToDoubleStr(screenHugerED);
-       rc.use_pixmap_cache = pixmapCacheCB->isChecked();
-
-       if (rc.font_sizes != oldrc.font_sizes
-               || rc.roman_font_name != oldrc.roman_font_name
-               || rc.sans_font_name != oldrc.sans_font_name
-               || rc.typewriter_font_name != oldrc.typewriter_font_name
-               || rc.zoom != oldrc.zoom) {
-               // The global QPixmapCache is used in GuiPainter to cache text
-               // painting so we must reset it in case any of the above
-               // parameter is changed.
-               QPixmapCache::clear();
-               guiApp->fontLoader().update();
-               form_->updateScreenFonts();
-       }
+       rc.defaultZoom = screenZoomSB->value();
+       rc.font_sizes[TINY_SIZE] = widgetToDoubleStr(screenTinyED);
+       rc.font_sizes[SCRIPT_SIZE] = widgetToDoubleStr(screenSmallestED);
+       rc.font_sizes[FOOTNOTE_SIZE] = widgetToDoubleStr(screenSmallerED);
+       rc.font_sizes[SMALL_SIZE] = widgetToDoubleStr(screenSmallED);
+       rc.font_sizes[NORMAL_SIZE] = widgetToDoubleStr(screenNormalED);
+       rc.font_sizes[LARGE_SIZE] = widgetToDoubleStr(screenLargeED);
+       rc.font_sizes[LARGER_SIZE] = widgetToDoubleStr(screenLargerED);
+       rc.font_sizes[LARGEST_SIZE] = widgetToDoubleStr(screenLargestED);
+       rc.font_sizes[HUGE_SIZE] = widgetToDoubleStr(screenHugeED);
+       rc.font_sizes[HUGER_SIZE] = widgetToDoubleStr(screenHugerED);
 }
 
 
@@ -1130,29 +1008,23 @@ void PrefScreenFonts::updateRC(LyXRC const & rc)
        selectSans(screenSansCO->currentText());
        selectTypewriter(screenTypewriterCO->currentText());
 
-       screenZoomSB->setValue(rc.zoom);
+       screenZoomSB->setValue(rc.defaultZoom);
        updateScreenFontSizes(rc);
-
-       pixmapCacheCB->setChecked(rc.use_pixmap_cache);
-#if defined(Q_WS_X11) || defined(QPA_XCB)
-       pixmapCacheCB->setEnabled(false);
-#endif
-
 }
 
 
 void PrefScreenFonts::updateScreenFontSizes(LyXRC const & rc)
 {
-       doubleToWidget(screenTinyED, rc.font_sizes[FONT_SIZE_TINY]);
-       doubleToWidget(screenSmallestED, rc.font_sizes[FONT_SIZE_SCRIPT]);
-       doubleToWidget(screenSmallerED, rc.font_sizes[FONT_SIZE_FOOTNOTE]);
-       doubleToWidget(screenSmallED, rc.font_sizes[FONT_SIZE_SMALL]);
-       doubleToWidget(screenNormalED, rc.font_sizes[FONT_SIZE_NORMAL]);
-       doubleToWidget(screenLargeED, rc.font_sizes[FONT_SIZE_LARGE]);
-       doubleToWidget(screenLargerED, rc.font_sizes[FONT_SIZE_LARGER]);
-       doubleToWidget(screenLargestED, rc.font_sizes[FONT_SIZE_LARGEST]);
-       doubleToWidget(screenHugeED, rc.font_sizes[FONT_SIZE_HUGE]);
-       doubleToWidget(screenHugerED, rc.font_sizes[FONT_SIZE_HUGER]);
+       doubleToWidget(screenTinyED, rc.font_sizes[TINY_SIZE]);
+       doubleToWidget(screenSmallestED, rc.font_sizes[SCRIPT_SIZE]);
+       doubleToWidget(screenSmallerED, rc.font_sizes[FOOTNOTE_SIZE]);
+       doubleToWidget(screenSmallED, rc.font_sizes[SMALL_SIZE]);
+       doubleToWidget(screenNormalED, rc.font_sizes[NORMAL_SIZE]);
+       doubleToWidget(screenLargeED, rc.font_sizes[LARGE_SIZE]);
+       doubleToWidget(screenLargerED, rc.font_sizes[LARGER_SIZE]);
+       doubleToWidget(screenLargestED, rc.font_sizes[LARGEST_SIZE]);
+       doubleToWidget(screenHugeED, rc.font_sizes[HUGE_SIZE]);
+       doubleToWidget(screenHugerED, rc.font_sizes[HUGER_SIZE]);
 }
 
 
@@ -1230,6 +1102,10 @@ PrefColors::PrefColors(GuiPreferences * form)
 
        connect(colorChangePB, SIGNAL(clicked()),
                this, SLOT(changeColor()));
+       connect(colorResetPB, SIGNAL(clicked()),
+               this, SLOT(resetColor()));
+       connect(colorResetAllPB, SIGNAL(clicked()),
+               this, SLOT(resetAllColor()));
        connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()),
                this, SLOT(changeLyxObjectsSelection()));
        connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
@@ -1257,15 +1133,17 @@ void PrefColors::applyRC(LyXRC & rc) const
 
 void PrefColors::updateRC(LyXRC const & rc)
 {
-       for (unsigned int i = 0; i < lcolors_.size(); ++i) {
+       for (size_type i = 0; i < lcolors_.size(); ++i) {
                QColor color = QColor(guiApp->colorCache().get(lcolors_[i], false));
                QPixmap coloritem(32, 32);
                coloritem.fill(color);
-               lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
+               lyxObjectsLW->item(int(i))->setIcon(QIcon(coloritem));
                newcolors_[i] = curcolors_[i] = color.name();
        }
        syscolorsCB->setChecked(rc.use_system_colors);
        changeLyxObjectsSelection();
+
+       setDisabledResets();
 }
 
 
@@ -1277,25 +1155,115 @@ void PrefColors::changeColor()
        if (row < 0)
                return;
 
-       QString const color = newcolors_[row];
-       QColor c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
+       QString const color = newcolors_[size_t(row)];
+       QColor const c = QColorDialog::getColor(QColor(color), qApp->focusWidget());
 
-       if (c.isValid() && c.name() != color) {
-               newcolors_[row] = c.name();
-               QPixmap coloritem(32, 32);
-               coloritem.fill(c);
-               lyxObjectsLW->currentItem()->setIcon(QIcon(coloritem));
+       if (setColor(row, c, color)) {
+               setDisabledResets();
+               // emit signal
+               changed();
+       }
+}
+
+
+void PrefColors::resetColor()
+{
+       int const row = lyxObjectsLW->currentRow();
+
+       // just to be sure
+       if (row < 0)
+               return;
+
+       QString const color = newcolors_[size_t(row)];
+       QColor const c = getDefaultColorByRow(row);
+
+       if (setColor(row, c, color)) {
+               setDisabledResets();
                // emit signal
                changed();
        }
 }
 
+
+void PrefColors::resetAllColor()
+{
+       bool isChanged = false;
+
+       colorResetAllPB->setDisabled(true);
+
+       for (int irow = 0, count = lyxObjectsLW->count(); irow < count; ++irow) {
+               QString const color = newcolors_[size_t(irow)];
+               QColor const c = getDefaultColorByRow(irow);
+
+               if (setColor(irow, c, color))
+                       isChanged = true;
+       }
+
+       if (isChanged) {
+               setDisabledResets();
+               // emit signal
+               changed();
+       }
+}
+
+
+bool PrefColors::setColor(int const row, QColor const new_color,
+                         QString const old_color)
+{
+       if (new_color.isValid() && new_color.name() != old_color) {
+               newcolors_[size_t(row)] = new_color.name();
+               QPixmap coloritem(32, 32);
+               coloritem.fill(new_color);
+               lyxObjectsLW->item(row)->setIcon(QIcon(coloritem));
+               return true;
+       }
+       return false;
+}
+
+
+void PrefColors::setDisabledResets()
+{
+       int const row = lyxObjectsLW->currentRow();
+       // set disable reset buttons ...
+       if (row >= 0)
+               colorResetPB->setDisabled(isDefaultColor(row, newcolors_[size_t(row)]));
+
+       colorResetAllPB->setDisabled(true);
+
+       // ... in between process qt events to give quicker visual feedback to the user ...
+       guiApp->processEvents();
+
+       // ... set disable Reset All button
+       for (int irow = 0, count = lyxObjectsLW->count(); irow < count; ++irow) {
+               if (!isDefaultColor(irow, newcolors_[size_t(irow)])) {
+                       colorResetAllPB->setDisabled(false);
+                       // the break condition might hide performance issues
+                       // if a non-default color is at the top of the list
+                       break;
+               }
+       }
+}
+
+
+bool PrefColors::isDefaultColor(int const row, QString const color)
+{
+       return color == getDefaultColorByRow(row).name();
+}
+
+
+QColor PrefColors::getDefaultColorByRow(int const row)
+{
+       ColorSet const defaultcolor;
+       return defaultcolor.getX11Name(lcolors_[size_t(row)]).c_str();
+}
+
+
 void PrefColors::changeSysColor()
 {
        for (int row = 0 ; row < lyxObjectsLW->count() ; ++row) {
                // skip colors that are taken from system palette
                bool const disable = syscolorsCB->isChecked()
-                       && guiApp->colorCache().isSystem(lcolors_[row]);
+                       && guiApp->colorCache().isSystem(lcolors_[size_t(row)]);
 
                QListWidgetItem * const item = lyxObjectsLW->item(row);
                Qt::ItemFlags const flags = item->flags();
@@ -1307,9 +1275,17 @@ void PrefColors::changeSysColor()
        }
 }
 
+
 void PrefColors::changeLyxObjectsSelection()
 {
-       colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0);
+       int currentRow = lyxObjectsLW->currentRow();
+       colorChangePB->setDisabled(currentRow < 0);
+
+       if (currentRow < 0)
+               colorResetPB->setDisabled(true);
+       else
+               colorResetPB->setDisabled(
+                       isDefaultColor(currentRow, newcolors_[size_t(currentRow)]));
 }
 
 
@@ -1343,16 +1319,10 @@ void PrefDisplay::applyRC(LyXRC & rc) const
                        rc.preview = LyXRC::PREVIEW_OFF;
                        break;
                case 1:
-                       if (rc.preview != LyXRC::PREVIEW_NO_MATH) {
-                               rc.preview = LyXRC::PREVIEW_NO_MATH;
-                               form_->updatePreviews();
-                       }
+                       rc.preview = LyXRC::PREVIEW_NO_MATH;
                        break;
                case 2:
-                       if (rc.preview != LyXRC::PREVIEW_ON) {
-                               rc.preview = LyXRC::PREVIEW_ON;
-                               form_->updatePreviews();
-                       }
+                       rc.preview = LyXRC::PREVIEW_ON;
                        break;
        }
 
@@ -2033,6 +2003,8 @@ PrefFileformats::PrefFileformats(GuiPreferences * form)
                this, SIGNAL(changed()));
        connect(defaultOTFFormatCB, SIGNAL(activated(QString)),
                this, SIGNAL(changed()));
+       connect(defaultPlatexFormatCB, SIGNAL(activated(QString)),
+               this, SIGNAL(changed()));
        connect(viewerCO, SIGNAL(activated(int)),
                this, SIGNAL(changed()));
        connect(editorCO, SIGNAL(activated(int)),
@@ -2063,6 +2035,9 @@ void PrefFileformats::applyRC(LyXRC & rc) const
        QString const default_otf_format = defaultOTFFormatCB->itemData(
                defaultOTFFormatCB->currentIndex()).toString();
        rc.default_otf_view_format = fromqstr(default_otf_format);
+       QString const default_platex_format = defaultPlatexFormatCB->itemData(
+               defaultPlatexFormatCB->currentIndex()).toString();
+       rc.default_platex_view_format = fromqstr(default_platex_format);
 }
 
 
@@ -2079,6 +2054,9 @@ void PrefFileformats::updateRC(LyXRC const & rc)
                pos = defaultOTFFormatCB->findData(toqstr(rc.default_otf_view_format));
                                defaultOTFFormatCB->setCurrentIndex(pos);
                defaultOTFFormatCB->setCurrentIndex(pos);
+               pos = defaultPlatexFormatCB->findData(toqstr(rc.default_platex_view_format));
+                               defaultPlatexFormatCB->setCurrentIndex(pos);
+               defaultPlatexFormatCB->setCurrentIndex(pos);
        }
 }
 
@@ -2088,14 +2066,17 @@ void PrefFileformats::updateView()
        QString const current = formatsCB->currentText();
        QString const current_def = defaultFormatCB->currentText();
        QString const current_def_otf = defaultOTFFormatCB->currentText();
+       QString const current_def_platex = defaultPlatexFormatCB->currentText();
 
        // update comboboxes with formats
        formatsCB->blockSignals(true);
        defaultFormatCB->blockSignals(true);
        defaultOTFFormatCB->blockSignals(true);
+       defaultPlatexFormatCB->blockSignals(true);
        formatsCB->clear();
        defaultFormatCB->clear();
        defaultOTFFormatCB->clear();
+       defaultPlatexFormatCB->clear();
        form_->formats().sort();
        for (Format const & f : form_->formats()) {
                QString const prettyname = toqstr(translateIfPossible(f.prettyname()));
@@ -2111,10 +2092,15 @@ void PrefFileformats::updateView()
                                        QVariant(toqstr(f.name())));
                        defaultOTFFormatCB->addItem(prettyname,
                                        QVariant(toqstr(f.name())));
-               } else if (form_->converters().isReachable("latex", f.name())
-                          || form_->converters().isReachable("pdflatex", f.name()))
-                       defaultFormatCB->addItem(prettyname,
+               } else {
+                       if (form_->converters().isReachable("latex", f.name())
+                           || form_->converters().isReachable("pdflatex", f.name()))
+                               defaultFormatCB->addItem(prettyname,
                                        QVariant(toqstr(f.name())));
+                       if (form_->converters().isReachable("platex", f.name()))
+                                       defaultPlatexFormatCB->addItem(prettyname,
+                                               QVariant(toqstr(f.name())));
+               }
        }
 
        // restore selections
@@ -2125,9 +2111,12 @@ void PrefFileformats::updateView()
        defaultFormatCB->setCurrentIndex(item < 0 ? 0 : item);
        item = defaultOTFFormatCB->findText(current_def_otf, Qt::MatchExactly);
        defaultOTFFormatCB->setCurrentIndex(item < 0 ? 0 : item);
+       item = defaultPlatexFormatCB->findText(current_def_platex, Qt::MatchExactly);
+       defaultPlatexFormatCB->setCurrentIndex(item < 0 ? 0 : item);
        formatsCB->blockSignals(false);
        defaultFormatCB->blockSignals(false);
        defaultOTFFormatCB->blockSignals(false);
+       defaultPlatexFormatCB->blockSignals(false);
 }
 
 
@@ -2822,20 +2811,20 @@ PrefShortcuts::PrefShortcuts(GuiPreferences * form)
 
        shortcut_ = new GuiShortcutDialog(this);
        shortcut_bc_.setPolicy(ButtonPolicy::OkCancelPolicy);
-       shortcut_bc_.setOK(shortcut_->okPB);
-       shortcut_bc_.setCancel(shortcut_->cancelPB);
+       shortcut_bc_.setOK(shortcut_->buttonBox->button(QDialogButtonBox::Ok));
+       shortcut_bc_.setCancel(shortcut_->buttonBox->button(QDialogButtonBox::Cancel));
 
-       connect(shortcut_->okPB, SIGNAL(clicked()),
+       connect(shortcut_->buttonBox, SIGNAL(accepted()),
                this, SIGNAL(changed()));
-       connect(shortcut_->cancelPB, SIGNAL(clicked()),
+       connect(shortcut_->buttonBox, SIGNAL(rejected()),
                shortcut_, SLOT(reject()));
        connect(shortcut_->clearPB, SIGNAL(clicked()),
                this, SLOT(shortcutClearPressed()));
        connect(shortcut_->removePB, SIGNAL(clicked()),
                this, SLOT(shortcutRemovePressed()));
-       connect(shortcut_->okPB, SIGNAL(clicked()),
+       connect(shortcut_->buttonBox, SIGNAL(accepted()),
                this, SLOT(shortcutOkPressed()));
-       connect(shortcut_->cancelPB, SIGNAL(clicked()),
+       connect(shortcut_->buttonBox, SIGNAL(rejected()),
                this, SLOT(shortcutCancelPressed()));
 }
 
@@ -3414,17 +3403,14 @@ void PrefIdentity::updateRC(LyXRC const & rc)
 /////////////////////////////////////////////////////////////////////
 
 GuiPreferences::GuiPreferences(GuiView & lv)
-       : GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false),
-         update_previews_(false)
+       : GuiDialog(lv, "prefs", qt_("Preferences"))
 {
        setupUi(this);
 
        QDialog::setModal(false);
 
-       connect(savePB, SIGNAL(clicked()), this, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
-       connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
+       connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
+               this, SLOT(slotButtonBox(QAbstractButton *)));
 
        addModule(new PrefUserInterface(this));
        addModule(new PrefDocHandling(this));
@@ -3446,7 +3432,6 @@ GuiPreferences::GuiPreferences(GuiView & lv)
        addModule(new PrefLanguage(this));
        addModule(new PrefSpellchecker(this));
 
-       //for strftime validator
        PrefOutput * output = new PrefOutput(this);
        addModule(output);
        addModule(new PrefLatex(this));
@@ -3466,13 +3451,14 @@ GuiPreferences::GuiPreferences(GuiView & lv)
 #endif
 
        bc().setPolicy(ButtonPolicy::PreferencesPolicy);
-       bc().setOK(savePB);
-       bc().setApply(applyPB);
-       bc().setCancel(closePB);
-       bc().setRestore(restorePB);
+       bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
+       bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
+       bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
+       bc().setRestore(buttonBox->button(QDialogButtonBox::Reset));
 
-       // initialize the strftime validator
-       bc().addCheckedLineEdit(output->DateED);
+       guilyxfiles_ = new GuiLyXFiles(lv);
+       connect(guilyxfiles_, SIGNAL(fileSelected(QString)),
+                       this, SLOT(slotFileSelected(QString)));
 }
 
 
@@ -3524,8 +3510,6 @@ bool GuiPreferences::initialiseParams(string const &)
        converters_.update(formats_);
        movers_ = theMovers();
        colors_.clear();
-       update_screen_font_ = false;
-       update_previews_ = false;
 
        updateRC(rc_);
        // Make sure that the bc is in the INITIAL state
@@ -3559,26 +3543,12 @@ void GuiPreferences::dispatchParams()
 
        theMovers() = movers_;
 
-       vector<string>::const_iterator it = colors_.begin();
-       vector<string>::const_iterator const end = colors_.end();
-       for (; it != end; ++it)
-               dispatch(FuncRequest(LFUN_SET_COLOR, *it));
+       for (string const & color : colors_)
+               dispatch(FuncRequest(LFUN_SET_COLOR, color));
        colors_.clear();
 
-       if (update_screen_font_) {
-               dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
-               // resets flag in case second apply in same dialog
-               update_screen_font_ = false;
-       }
-
-        if (update_previews_) {
-               // resets flag in case second apply in same dialog
-               theBufferList().updatePreviews();
-               update_previews_ = false;
-       }
-
-       // The Save button has been pressed
-       if (isClosing())
+       // Save permanently
+       if (!tempSaveCB->isChecked())
                dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
 }
 
@@ -3589,36 +3559,54 @@ void GuiPreferences::setColor(ColorCode col, QString const & hex)
 }
 
 
-void GuiPreferences::updateScreenFonts()
+void GuiPreferences::slotFileSelected(QString const file)
 {
-       update_screen_font_ = true;
+       uifile_ = file;
 }
 
 
-void GuiPreferences::updatePreviews()
+QString GuiPreferences::browseLibFile(QString const & dir,
+       QString const & name, QString const & ext)
 {
-       update_previews_ = true;
+       uifile_.clear();
+
+       guilyxfiles_->passParams(fromqstr(dir));
+       guilyxfiles_->selectItem(name);
+       guilyxfiles_->exec();
+
+       QString const result = uifile_;
+
+       // remove the extension if it is the default one
+       QString noextresult;
+       if (getExtension(result) == ext)
+               noextresult = removeExtension(result);
+       else
+               noextresult = result;
+
+       // remove the directory, if it is the default one
+       QString const file = onlyFileName(noextresult);
+       if (toqstr(libFileSearch(dir, file, ext).absFileName()) == result)
+               return file;
+       else
+               return noextresult;
 }
 
 
-QString GuiPreferences::browsebind(QString const & file) const
+QString GuiPreferences::browsebind(QString const & file)
 {
-       return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
-                            QStringList(qt_("LyX bind files (*.bind)")));
+       return browseLibFile("bind", file, "bind");
 }
 
 
-QString GuiPreferences::browseUI(QString const & file) const
+QString GuiPreferences::browseUI(QString const & file)
 {
-       return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
-                            QStringList(qt_("LyX UI files (*.ui)")));
+       return browseLibFile("ui", file, "ui");
 }
 
 
-QString GuiPreferences::browsekbmap(QString const & file) const
+QString GuiPreferences::browsekbmap(QString const & file)
 {
-       return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
-                            QStringList(qt_("LyX keyboard maps (*.kmap)")));
+       return browseLibFile("kbd", file, "kmap");
 }