]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiPrefs.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiPrefs.cpp
index 6b07c214243d5dbc6b563ba955f85213ad127f70..4518838456d131f635df510acedb43869c3f44fb 100644 (file)
@@ -590,6 +590,8 @@ PrefLatex::PrefLatex(GuiPreferences * form)
        : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
 {
        setupUi(this);
+       connect(latexEncodingCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
        connect(latexEncodingED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
        connect(latexChecktexED, SIGNAL(textChanged(QString)),
@@ -623,6 +625,12 @@ 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();
@@ -631,7 +639,7 @@ void PrefLatex::on_latexBibtexCO_activated(int n)
                latexBibtexOptionsLA->setText(qt_("Co&mmand:"));
                return;
        }
-       for (set<string>::const_iterator it = bibtex_alternatives.begin();
+       for (LyXRC::CommandSet::const_iterator it = bibtex_alternatives.begin();
             it != bibtex_alternatives.end(); ++it) {
                QString const bib = toqstr(*it);
                int ind = bib.indexOf(" ");
@@ -656,7 +664,7 @@ void PrefLatex::on_latexIndexCO_activated(int n)
                latexIndexOptionsLA->setText(qt_("Co&mmand:"));
                return;
        }
-       for (set<string>::const_iterator it = index_alternatives.begin();
+       for (LyXRC::CommandSet::const_iterator it = index_alternatives.begin();
             it != index_alternatives.end(); ++it) {
                QString const idx = toqstr(*it);
                int ind = idx.indexOf(" ");
@@ -699,7 +707,10 @@ void PrefLatex::apply(LyXRC & rc) const
        else
                rc.index_command = fromqstr(index) + " " + fromqstr(idxopt);
 
-       rc.fontenc = fromqstr(latexEncodingED->text());
+       if (latexEncodingCB->isChecked())
+               rc.fontenc = fromqstr(latexEncodingED->text());
+       else
+               rc.fontenc = "default";
        rc.chktex_command = fromqstr(latexChecktexED->text());
        rc.jbibtex_command = fromqstr(latexJBibtexED->text());
        rc.jindex_command = fromqstr(latexJIndexED->text());
@@ -719,7 +730,7 @@ void PrefLatex::update(LyXRC const & rc)
        latexBibtexCO->clear();
 
        latexBibtexCO->addItem(qt_("Custom"), QString());
-       for (set<string>::const_iterator it = rc.bibtex_alternatives.begin();
+       for (LyXRC::CommandSet::const_iterator it = rc.bibtex_alternatives.begin();
                             it != rc.bibtex_alternatives.end(); ++it) {
                QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
                latexBibtexCO->addItem(command, command);
@@ -746,7 +757,7 @@ void PrefLatex::update(LyXRC const & rc)
        latexIndexCO->clear();
 
        latexIndexCO->addItem(qt_("Custom"), QString());
-       for (set<string>::const_iterator it = rc.index_alternatives.begin();
+       for (LyXRC::CommandSet::const_iterator it = rc.index_alternatives.begin();
                             it != rc.index_alternatives.end(); ++it) {
                QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
                latexIndexCO->addItem(command, command);
@@ -770,7 +781,14 @@ void PrefLatex::update(LyXRC const & rc)
                latexIndexOptionsLA->setText(qt_("Co&mmand:"));
        }
 
-       latexEncodingED->setText(toqstr(rc.fontenc));
+       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));
        latexJBibtexED->setText(toqstr(rc.jbibtex_command));
        latexJIndexED->setText(toqstr(rc.jindex_command));
@@ -1071,7 +1089,21 @@ PrefDisplay::PrefDisplay(GuiPreferences * form)
        setupUi(this);
        connect(displayGraphicsCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
        connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed()));
-       connect(paragraphMarkerCB, SIGNAL(toggled(bool)), this, SIGNAL(changed())); 
+       connect(previewSizeSB, SIGNAL(valueChanged(double)), this, SIGNAL(changed()));
+       connect(paragraphMarkerCB, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
+       if (instantPreviewCO->currentIndex() == 0)
+               previewSizeSB->setEnabled(false);
+       else
+               previewSizeSB->setEnabled(true);
+}
+
+
+void PrefDisplay::on_instantPreviewCO_currentIndexChanged(int index)
+{
+       if (index == 0)
+               previewSizeSB->setEnabled(false);
+       else
+               previewSizeSB->setEnabled(true);
 }
 
 
@@ -1084,6 +1116,7 @@ void PrefDisplay::apply(LyXRC & rc) const
        }
 
        rc.display_graphics = displayGraphicsCB->isChecked();
+       rc.preview_scale_factor = previewSizeSB->value();
        rc.paragraph_markers = paragraphMarkerCB->isChecked();
 
        // FIXME!! The graphics cache no longer has a changeDisplay method.
@@ -1112,6 +1145,7 @@ void PrefDisplay::update(LyXRC const & rc)
 
        displayGraphicsCB->setChecked(rc.display_graphics);
        instantPreviewCO->setEnabled(rc.display_graphics);
+       previewSizeSB->setValue(rc.preview_scale_factor);
        paragraphMarkerCB->setChecked(rc.paragraph_markers);
 }
 
@@ -1126,28 +1160,39 @@ PrefPaths::PrefPaths(GuiPreferences * form)
        : PrefModule(QString(), qt_("Paths"), form)
 {
        setupUi(this);
-       connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(selectExampledir()));
-       connect(templateDirPB, SIGNAL(clicked()), this, SLOT(selectTemplatedir()));
-       connect(tempDirPB, SIGNAL(clicked()), this, SLOT(selectTempdir()));
-       connect(backupDirPB, SIGNAL(clicked()), this, SLOT(selectBackupdir()));
+
        connect(workingDirPB, SIGNAL(clicked()), this, SLOT(selectWorkingdir()));
-       connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(selectLyxPipe()));
-       connect(thesaurusDirPB, SIGNAL(clicked()), this, SLOT(selectThesaurusdir()));
-       connect(hunspellDirPB, SIGNAL(clicked()), this, SLOT(selectHunspelldir()));
        connect(workingDirED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
-       connect(exampleDirED, SIGNAL(textChanged(QString)),
-               this, SIGNAL(changed()));
+
+       connect(templateDirPB, SIGNAL(clicked()), this, SLOT(selectTemplatedir()));
        connect(templateDirED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
-       connect(backupDirED, SIGNAL(textChanged(QString)),
+
+       connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(selectExampledir()));
+       connect(exampleDirED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
-       connect(tempDirED, SIGNAL(textChanged(QString)),
+
+       connect(backupDirPB, SIGNAL(clicked()), this, SLOT(selectBackupdir()));
+       connect(backupDirED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
+
+       connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(selectLyxPipe()));
        connect(lyxserverDirED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
+
+       connect(thesaurusDirPB, SIGNAL(clicked()), this, SLOT(selectThesaurusdir()));
        connect(thesaurusDirED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
+
+       connect(tempDirPB, SIGNAL(clicked()), this, SLOT(selectTempdir()));
+       connect(tempDirED, SIGNAL(textChanged(QString)),
+               this, SIGNAL(changed()));
+
+       connect(hunspellDirPB, SIGNAL(clicked()), this, SLOT(selectHunspelldir()));
+       connect(hunspellDirED, SIGNAL(textChanged(QString)),
+               this, SIGNAL(changed()));
+
        connect(pathPrefixED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
 }
@@ -1266,25 +1311,41 @@ PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
 {
        setupUi(this);
 
-       spellcheckerCB->addItem("aspell");
-       spellcheckerCB->addItem("hunspell");
+#if defined(USE_ASPELL)
+       spellcheckerCB->addItem(qt_("aspell"), QString("aspell"));
+#endif
+#if defined(USE_ENCHANT)
+       spellcheckerCB->addItem(qt_("enchant"), QString("enchant"));
+#endif
+#if defined(USE_HUNSPELL)
+       spellcheckerCB->addItem(qt_("hunspell"), QString("hunspell"));
+#endif
 
-       connect(spellcheckerCB, SIGNAL(currentIndexChanged(int)),
-               this, SIGNAL(changed()));
-       connect(altLanguageED, SIGNAL(textChanged(QString)),
-               this, SIGNAL(changed()));
-       connect(escapeCharactersED, SIGNAL(textChanged(QString)),
-               this, SIGNAL(changed()));
-       connect(compoundWordCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
-       connect(spellcheckContinuouslyCB, SIGNAL(clicked()),
-               this, SIGNAL(changed()));
+       if (theSpellChecker()) {
+               connect(spellcheckerCB, SIGNAL(currentIndexChanged(int)),
+                       this, SIGNAL(changed()));
+               connect(altLanguageED, SIGNAL(textChanged(QString)),
+                       this, SIGNAL(changed()));
+               connect(escapeCharactersED, SIGNAL(textChanged(QString)),
+                       this, SIGNAL(changed()));
+               connect(compoundWordCB, SIGNAL(clicked()),
+                       this, SIGNAL(changed()));
+               connect(spellcheckContinuouslyCB, SIGNAL(clicked()),
+                       this, SIGNAL(changed()));
+       } else {
+               spellcheckerCB->setEnabled(false);
+               altLanguageED->setEnabled(false);
+               escapeCharactersED->setEnabled(false);
+               compoundWordCB->setEnabled(false);
+               spellcheckContinuouslyCB->setEnabled(false);
+       }
 }
 
 
 void PrefSpellchecker::apply(LyXRC & rc) const
 {
-       rc.spellchecker = fromqstr(spellcheckerCB->currentText());
+       rc.spellchecker = fromqstr(spellcheckerCB->itemData(
+                       spellcheckerCB->currentIndex()).toString());
        rc.spellchecker_alt_lang = fromqstr(altLanguageED->text());
        rc.spellchecker_esc_chars = fromqstr(escapeCharactersED->text());
        rc.spellchecker_accept_compound = compoundWordCB->isChecked();
@@ -1294,8 +1355,8 @@ void PrefSpellchecker::apply(LyXRC & rc) const
 
 void PrefSpellchecker::update(LyXRC const & rc)
 {
-       spellcheckerCB->setCurrentIndex(spellcheckerCB->findText(
-               toqstr(rc.spellchecker)));
+       spellcheckerCB->setCurrentIndex(
+               spellcheckerCB->findData(toqstr(rc.spellchecker)));
        altLanguageED->setText(toqstr(rc.spellchecker_alt_lang));
        escapeCharactersED->setText(toqstr(rc.spellchecker_esc_chars));
        compoundWordCB->setChecked(rc.spellchecker_accept_compound);
@@ -1632,6 +1693,10 @@ PrefFileformats::PrefFileformats(GuiPreferences * form)
                this, SIGNAL(changed()));
        connect(defaultFormatCB, SIGNAL(activated(QString)),
                this, SIGNAL(changed()));
+       connect(viewerCO, SIGNAL(activated(int)),
+               this, SIGNAL(changed()));
+       connect(editorCO, SIGNAL(activated(int)),
+               this, SIGNAL(changed()));
 }
 
 
@@ -1660,11 +1725,13 @@ void PrefFileformats::apply(LyXRC & rc) const
 
 void PrefFileformats::update(LyXRC const & rc)
 {
+       viewer_alternatives = rc.viewer_alternatives;
+       editor_alternatives = rc.editor_alternatives;
        bool const init = defaultFormatCB->currentText().isEmpty();
        updateView();
        if (init) {
-               int const pos = defaultFormatCB->findData(toqstr(
-               rc.default_view_format));
+               int const pos =
+                       defaultFormatCB->findData(toqstr(rc.default_view_format));
                defaultFormatCB->setCurrentIndex(pos);
        }
 }
@@ -1713,10 +1780,10 @@ void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
        extensionED->setText(toqstr(f.extension()));
        shortcutED->setText(
                toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
-       viewerED->setText(toqstr(f.viewer()));
-       editorED->setText(toqstr(f.editor()));
        documentCB->setChecked((f.documentFormat()));
        vectorCB->setChecked((f.vectorFormat()));
+       updateViewers();
+       updateEditors();
 }
 
 
@@ -1813,6 +1880,91 @@ void PrefFileformats::updatePrettyname()
 }
 
 
+namespace {
+       void updateComboBox(LyXRC::Alternatives const & alts,
+                           string const & fmt, QComboBox * combo)
+       {
+               LyXRC::Alternatives::const_iterator it = 
+                               alts.find(fmt);
+               if (it != alts.end()) {
+                       LyXRC::CommandSet const & cmds = it->second;
+                       LyXRC::CommandSet::const_iterator sit = 
+                                       cmds.begin();
+                       LyXRC::CommandSet::const_iterator const sen = 
+                                       cmds.end();
+                       for (; sit != sen; ++sit) {
+                               QString const qcmd = toqstr(*sit);
+                               combo->addItem(qcmd, qcmd);
+                       }
+               }
+       }
+}
+
+
+void PrefFileformats::updateViewers()
+{
+       Format const f = currentFormat();
+       viewerCO->blockSignals(true);
+       viewerCO->clear();
+       viewerCO->addItem(qt_("None"), QString());
+       updateComboBox(viewer_alternatives, f.name(), viewerCO);
+       viewerCO->addItem(qt_("Custom"), QString("custom viewer"));
+       viewerCO->blockSignals(false);
+
+       int pos = viewerCO->findData(toqstr(f.viewer()));
+       if (pos != -1) {
+               viewerED->clear();
+               viewerED->setEnabled(false);
+               viewerCO->setCurrentIndex(pos);
+       } else {
+               viewerED->setEnabled(true);
+               viewerED->setText(toqstr(f.viewer()));
+               viewerCO->setCurrentIndex(viewerCO->findData(toqstr("custom viewer")));
+       }
+}
+
+
+void PrefFileformats::updateEditors()
+{
+       Format const f = currentFormat();
+       editorCO->blockSignals(true);
+       editorCO->clear();
+       editorCO->addItem(qt_("None"), QString());
+       updateComboBox(editor_alternatives, f.name(), editorCO);
+       editorCO->addItem(qt_("Custom"), QString("custom editor"));
+       editorCO->blockSignals(false);
+
+       int pos = editorCO->findData(toqstr(f.editor()));
+       if (pos != -1) {
+               editorED->clear();
+               editorED->setEnabled(false);
+               editorCO->setCurrentIndex(pos);
+       } else {
+               editorED->setEnabled(true);
+               editorED->setText(toqstr(f.editor()));
+               editorCO->setCurrentIndex(editorCO->findData(toqstr("custom editor")));
+       }
+}
+
+
+void PrefFileformats::on_viewerCO_currentIndexChanged(int i)
+{
+       bool const custom = viewerCO->itemData(i).toString() == "custom viewer";
+       viewerED->setEnabled(custom);
+       if (!custom)
+               currentFormat().setViewer(fromqstr(viewerCO->itemData(i).toString()));
+}
+
+
+void PrefFileformats::on_editorCO_currentIndexChanged(int i)
+{
+       bool const custom = editorCO->itemData(i).toString() == "custom editor";
+       editorED->setEnabled(custom);
+       if (!custom)
+               currentFormat().setEditor(fromqstr(editorCO->itemData(i).toString()));
+}
+
+
 Format & PrefFileformats::currentFormat()
 {
        int const i = formatsCB->currentIndex();
@@ -2070,6 +2222,11 @@ PrefUserInterface::PrefUserInterface(GuiPreferences * form)
                TextLabel1, SLOT(setEnabled(bool)));
        connect(openDocumentsInTabsCB, SIGNAL(clicked()),
                this, SIGNAL(changed()));
+#if QT_VERSION < 0x040500
+       singleCloseTabButtonCB->setEnabled(false);
+#endif
+       connect(singleCloseTabButtonCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
        connect(uiFilePB, SIGNAL(clicked()),
                this, SLOT(selectUi()));
        connect(uiFileED, SIGNAL(textChanged(QString)),
@@ -2084,6 +2241,8 @@ PrefUserInterface::PrefUserInterface(GuiPreferences * form)
                this, SIGNAL(changed()));
        connect(autoSaveCB, SIGNAL(clicked()),
                this, SIGNAL(changed()));
+       connect(backupCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
        connect(lastfilesSB, SIGNAL(valueChanged(int)),
                this, SIGNAL(changed()));
        connect(tooltipCB, SIGNAL(toggled(bool)),
@@ -2098,11 +2257,15 @@ void PrefUserInterface::apply(LyXRC & rc) const
        rc.use_lastfilepos = restoreCursorCB->isChecked();
        rc.load_session = loadSessionCB->isChecked();
        rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
-       rc.autosave = autoSaveSB->value() * 60;
-       rc.make_backup = autoSaveCB->isChecked();
+       rc.autosave = autoSaveCB->isChecked()?  autoSaveSB->value() * 60 : 0;
+       rc.make_backup = backupCB->isChecked();
        rc.num_lastfiles = lastfilesSB->value();
        rc.use_tooltip = tooltipCB->isChecked();
        rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked();
+       rc.single_close_tab_button = singleCloseTabButtonCB->isChecked();
+#if QT_VERSION < 0x040500
+       rc.single_close_tab_button = true;
+#endif
 }
 
 
@@ -2113,14 +2276,18 @@ void PrefUserInterface::update(LyXRC const & rc)
        loadSessionCB->setChecked(rc.load_session);
        allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
        // convert to minutes
-       int mins(rc.autosave / 60);
-       if (rc.autosave && !mins)
-               mins = 1;
+       bool autosave = rc.autosave > 0;
+       int mins = rc.autosave / 60;
+       if (!mins)
+               mins = 5;
        autoSaveSB->setValue(mins);
-       autoSaveCB->setChecked(rc.make_backup);
+       autoSaveCB->setChecked(autosave);
+       autoSaveSB->setEnabled(autosave);
+       backupCB->setChecked(rc.make_backup);
        lastfilesSB->setValue(rc.num_lastfiles);
        tooltipCB->setChecked(rc.use_tooltip);
        openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs);
+       singleCloseTabButtonCB->setChecked(rc.single_close_tab_button);
 }