]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiPrefs.cpp
Cleanup private part of Layout Box on destructor (probably not really an
[lyx.git] / src / frontends / qt4 / GuiPrefs.cpp
index a98d9f128cf962be24f4837866560c279e408d69..d56d3b068104371d5f95c21578f10f3ee3fbf795 100644 (file)
@@ -20,6 +20,7 @@
 #include "GuiFontLoader.h"
 #include "GuiKeySymbol.h"
 #include "qt_helpers.h"
+#include "Validator.h"
 
 #include "Author.h"
 #include "BufferList.h"
@@ -43,6 +44,7 @@
 #include "support/filetools.h"
 #include "support/foreach.h"
 #include "support/gettext.h"
+#include "support/lassert.h"
 #include "support/lstrings.h"
 #include "support/os.h"
 #include "support/Package.h"
@@ -90,7 +92,7 @@ namespace frontend {
 /** Launch a file dialog and return the chosen file.
        filename: a suggested filename.
        title: the title of the dialog.
-       pattern: *.ps etc.
+       filters: *.ps etc.
        dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
 */
 QString browseFile(QString const & filename,
@@ -194,19 +196,18 @@ QString browseDir(QString const & pathname,
 } // namespace frontend
 
 
-QString browseRelFile(QString const & filename, QString const & refpath,
+QString browseRelToParent(QString const & filename, QString const & relpath,
        QString const & title, QStringList const & filters, bool save,
        QString const & label1, QString const & dir1,
        QString const & label2, QString const & dir2)
 {
-       QString const fname = makeAbsPath(filename, refpath);
-
+       QString const fname = makeAbsPath(filename, relpath);
 
        QString const outname =
                frontend::browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
 
        QString const reloutname =
-               toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(refpath)));
+               toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(relpath)));
 
        if (reloutname.startsWith("../"))
                return outname;
@@ -215,6 +216,29 @@ QString browseRelFile(QString const & filename, QString const & refpath,
 }
 
 
+QString browseRelToSub(QString const & filename, QString const & relpath,
+       QString const & title, QStringList const & filters, bool save,
+       QString const & label1, QString const & dir1,
+       QString const & label2, QString const & dir2)
+{
+       QString const fname = makeAbsPath(filename, relpath);
+
+       QString const outname =
+               frontend::browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
+
+       QString const reloutname =
+               toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(relpath)));
+
+       QString testname = reloutname;
+       testname.remove(QRegExp("^(\\.\\./)+"));
+       
+       if (testname.contains("/"))
+               return outname;
+       else
+               return reloutname;
+}
+
+
 
 /////////////////////////////////////////////////////////////////////
 //
@@ -365,7 +389,11 @@ PrefOutput::PrefOutput(GuiPreferences * form)
        : PrefModule(qt_(catOutput), qt_("General"), 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)),
@@ -379,13 +407,13 @@ PrefOutput::PrefOutput(GuiPreferences * form)
        dviCB->addItem("");
        dviCB->addItem("xdvi -sourceposition '$$n:\\ $$t' $$o");
        dviCB->addItem("yap -1 -s \"$$n $$t\" $$o");
-       dviCB->addItem("okular --unique $$o#src:$$n$$t");
-       dviCB->addItem("synctex view -i $$n:0:$$t -o $$o -x \"evince -p %{page+1} $$o\"");
+       dviCB->addItem("okular --unique \"file:$$o#src:$$n $$t\"");
+       dviCB->addItem("synctex view -i $$n:0:$$t -o $$o -x \"evince -i %{page+1} $$o\"");
        pdfCB->addItem("");
        pdfCB->addItem("CMCDDE SUMATRA control [ForwardSearch(\\\"$$o\\\",\\\"$$t\\\",$$n,0,0,1)]");
        pdfCB->addItem("synctex view -i $$n:0:$$t -o $$o -x \"xpdf -raise -remote $$t.tmp $$o %{page+1}\"");
-       pdfCB->addItem("okular --unique $$o#src:$$n$$t");
-       pdfCB->addItem("synctex view -i $$n:0:$$t -o $$o -x \"evince -p %{page+1} $$o\"");
+       pdfCB->addItem("okular --unique \"file:$$o#src:$$n $$t\"");
+       pdfCB->addItem("synctex view -i $$n:0:$$t -o $$o -x \"evince -i %{page+1} $$o\"");
        pdfCB->addItem("/Applications/Skim.app/Contents/SharedSupport/displayline $$n $$o $$t");
 }
 
@@ -668,6 +696,16 @@ PrefLatex::PrefLatex(GuiPreferences * form)
        : PrefModule(qt_(catOutput), qt_("LaTeX"), form)
 {
        setupUi(this);
+
+       latexEncodingED->setValidator(new NoNewLineValidator(latexEncodingED));
+       latexDviPaperED->setValidator(new NoNewLineValidator(latexDviPaperED));
+       latexBibtexED->setValidator(new NoNewLineValidator(latexBibtexED));
+       latexJBibtexED->setValidator(new NoNewLineValidator(latexJBibtexED));
+       latexIndexED->setValidator(new NoNewLineValidator(latexIndexED));
+       latexJIndexED->setValidator(new NoNewLineValidator(latexJIndexED));
+       latexNomenclED->setValidator(new NoNewLineValidator(latexNomenclED));
+       latexChecktexED->setValidator(new NoNewLineValidator(latexChecktexED));
+
        connect(latexEncodingCB, SIGNAL(clicked()),
                this, SIGNAL(changed()));
        connect(latexEncodingED, SIGNAL(textChanged(QString)),
@@ -692,6 +730,8 @@ PrefLatex::PrefLatex(GuiPreferences * form)
                this, SIGNAL(changed()));
        connect(latexPaperSizeCO, SIGNAL(activated(int)),
                this, SIGNAL(changed()));
+       connect(latexNomenclED, SIGNAL(textChanged(QString)),
+               this, SIGNAL(changed()));
 
 #if defined(__CYGWIN__) || defined(_WIN32)
        pathCB->setVisible(true);
@@ -1076,19 +1116,17 @@ PrefColors::PrefColors(GuiPreferences * form)
        for (int i = 0; i < Color_ignore; ++i) {
                ColorCode lc = static_cast<ColorCode>(i);
                if (lc == Color_none
-                       || lc == Color_black
-                       || lc == Color_white
-                       || lc == Color_red
-                       || lc == Color_green
-                       || lc == Color_blue
-                       || lc == Color_cyan
-                       || lc == Color_magenta
-                       || lc == Color_yellow
-                       || lc == Color_inherit
-                       || lc == Color_ignore
-                       || lc == Color_greyedouttext
-                       || lc == Color_shadedbg) continue;
-
+                   || lc == Color_black
+                   || lc == Color_white
+                   || lc == Color_red
+                   || lc == Color_green
+                   || lc == Color_blue
+                   || lc == Color_cyan
+                   || lc == Color_magenta
+                   || lc == Color_yellow
+                   || lc == Color_inherit
+                   || lc == Color_ignore)
+                       continue;
                lcolors_.push_back(lc);
        }
        sort(lcolors_.begin(), lcolors_.end(), ColorSorter());
@@ -1314,6 +1352,12 @@ PrefPaths::PrefPaths(GuiPreferences * form)
 
        connect(pathPrefixED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
+
+       connect(texinputsPrefixED, SIGNAL(textChanged(QString)),
+               this, SIGNAL(changed()));
+
+       pathPrefixED->setValidator(new NoNewLineValidator(pathPrefixED));
+       texinputsPrefixED->setValidator(new NoNewLineValidator(texinputsPrefixED));
 }
 
 
@@ -1327,6 +1371,7 @@ void PrefPaths::apply(LyXRC & rc) const
        rc.thesaurusdir_path = internal_path(fromqstr(thesaurusDirED->text()));
        rc.hunspelldir_path = internal_path(fromqstr(hunspellDirED->text()));
        rc.path_prefix = internal_path_list(fromqstr(pathPrefixED->text()));
+       rc.texinputs_prefix = internal_path_list(fromqstr(texinputsPrefixED->text()));
        // FIXME: should be a checkbox only
        rc.lyxpipes = internal_path(fromqstr(lyxserverDirED->text()));
 }
@@ -1342,6 +1387,7 @@ void PrefPaths::update(LyXRC const & rc)
        thesaurusDirED->setText(toqstr(external_path(rc.thesaurusdir_path)));
        hunspellDirED->setText(toqstr(external_path(rc.hunspelldir_path)));
        pathPrefixED->setText(toqstr(external_path_list(rc.path_prefix)));
+       texinputsPrefixED->setText(toqstr(external_path_list(rc.texinputs_prefix)));
        // FIXME: should be a checkbox only
        lyxserverDirED->setText(toqstr(external_path(rc.lyxpipes)));
 }
@@ -1460,6 +1506,9 @@ PrefSpellchecker::PrefSpellchecker(GuiPreferences * form)
                        this, SIGNAL(changed()));
                connect(spellcheckNotesCB, SIGNAL(clicked()),
                        this, SIGNAL(changed()));
+
+               altLanguageED->setValidator(new NoNewLineValidator(altLanguageED));
+               escapeCharactersED->setValidator(new NoNewLineValidator(escapeCharactersED));
        #else
                spellcheckerCB->setEnabled(false);
                altLanguageED->setEnabled(false);
@@ -1501,7 +1550,7 @@ void PrefSpellchecker::on_spellcheckerCB_currentIndexChanged(int index)
 {
        QString spellchecker = spellcheckerCB->itemData(index).toString();
        
-       compoundWordCB->setEnabled(spellchecker != QString("native"));
+       compoundWordCB->setEnabled(spellchecker == QString("aspell"));
 }
        
        
@@ -1543,6 +1592,8 @@ PrefConverters::PrefConverters(GuiPreferences * form)
        connect(maxAgeLE, SIGNAL(textEdited(QString)),
                this, SIGNAL(changed()));
 
+       converterED->setValidator(new NoNewLineValidator(converterED));
+       converterFlagED->setValidator(new NoNewLineValidator(converterFlagED));
        maxAgeLE->setValidator(new QDoubleValidator(maxAgeLE));
        //converterDefGB->setFocusProxy(convertersLW);
 }
@@ -1823,13 +1874,21 @@ PrefFileformats::PrefFileformats(GuiPreferences * form)
        : PrefModule(qt_(catFiles), qt_("File Formats"), form)
 {
        setupUi(this);
+
        formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
        formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
+       extensionsED->setValidator(new NoNewLineValidator(extensionsED));
+       shortcutED->setValidator(new NoNewLineValidator(shortcutED));
+       editorED->setValidator(new NoNewLineValidator(editorED));
+       viewerED->setValidator(new NoNewLineValidator(viewerED));
+       copierED->setValidator(new NoNewLineValidator(copierED));
 
        connect(documentCB, SIGNAL(clicked()),
                this, SLOT(setFlags()));
        connect(vectorCB, SIGNAL(clicked()),
                this, SLOT(setFlags()));
+       connect(exportMenuCB, SIGNAL(clicked()),
+               this, SLOT(setFlags()));
        connect(formatsCB->lineEdit(), SIGNAL(editingFinished()),
                this, SLOT(updatePrettyname()));
        connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
@@ -1897,7 +1956,10 @@ void PrefFileformats::updateView()
                formatsCB->addItem(qt_(cit->prettyname()),
                                QVariant(form_->formats().getNumber(cit->name())));
                if (form_->converters().isReachable("latex", cit->name())
-                   || form_->converters().isReachable("pdflatex", cit->name()))
+                   || form_->converters().isReachable("dviluatex", cit->name())
+                   || form_->converters().isReachable("pdflatex", cit->name())
+                   || form_->converters().isReachable("luatex", cit->name())
+                   || form_->converters().isReachable("xetex", cit->name()))
                        defaultFormatCB->addItem(qt_(cit->prettyname()),
                                        QVariant(toqstr(cit->name())));
        }
@@ -1922,11 +1984,13 @@ void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
 
        formatED->setText(toqstr(f.name()));
        copierED->setText(toqstr(form_->movers().command(f.name())));
-       extensionED->setText(toqstr(f.extension()));
+       extensionsED->setText(toqstr(f.extensions()));
        shortcutED->setText(
                toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
        documentCB->setChecked((f.documentFormat()));
        vectorCB->setChecked((f.vectorFormat()));
+       exportMenuCB->setChecked((f.inExportMenu()));
+       exportMenuCB->setEnabled((f.documentFormat()));
        updateViewers();
        updateEditors();
 }
@@ -1939,7 +2003,10 @@ void PrefFileformats::setFlags()
                flags |= Format::document;
        if (vectorCB->isChecked())
                flags |= Format::vector;
+       if (exportMenuCB->isChecked())
+               flags |= Format::export_menu;
        currentFormat().setFlags(flags);
+       exportMenuCB->setEnabled(documentCB->isChecked());
        changed();
 }
 
@@ -1952,12 +2019,13 @@ void PrefFileformats::on_copierED_textEdited(const QString & s)
 }
 
 
-void PrefFileformats::on_extensionED_textEdited(const QString & s)
+void PrefFileformats::on_extensionsED_textEdited(const QString & s)
 {
-       currentFormat().setExtension(fromqstr(s));
+       currentFormat().setExtensions(fromqstr(s));
        changed();
 }
 
+
 void PrefFileformats::on_viewerED_textEdited(const QString & s)
 {
        currentFormat().setViewer(fromqstr(s));
@@ -2194,6 +2262,10 @@ PrefLanguage::PrefLanguage(GuiPreferences * form)
        connect(defaultDecimalPointLE, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
 
+       languagePackageED->setValidator(new NoNewLineValidator(languagePackageED));
+       startCommandED->setValidator(new NoNewLineValidator(startCommandED));
+       endCommandED->setValidator(new NoNewLineValidator(endCommandED));
+
        uiLanguageCO->clear();
 
        QAbstractItemModel * language_model = guiApp->languageModel();
@@ -2337,6 +2409,24 @@ PrefPrinter::PrefPrinter(GuiPreferences * form)
                this, SIGNAL(changed()));
        connect(printerPaperSizeED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
+
+       printerNameED->setValidator(new NoNewLineValidator(printerNameED));
+       printerCommandED->setValidator(new NoNewLineValidator(printerCommandED));
+       printerEvenED->setValidator(new NoNewLineValidator(printerEvenED));
+       printerPageRangeED->setValidator(new NoNewLineValidator(printerPageRangeED));
+       printerCopiesED->setValidator(new NoNewLineValidator(printerCopiesED));
+       printerReverseED->setValidator(new NoNewLineValidator(printerReverseED));
+       printerToFileED->setValidator(new NoNewLineValidator(printerToFileED));
+       printerPaperTypeED->setValidator(new NoNewLineValidator(printerPaperTypeED));
+       printerExtraED->setValidator(new NoNewLineValidator(printerExtraED));
+       printerOddED->setValidator(new NoNewLineValidator(printerOddED));
+       printerCollatedED->setValidator(new NoNewLineValidator(printerCollatedED));
+       printerLandscapeED->setValidator(new NoNewLineValidator(printerLandscapeED));
+       printerToPrinterED->setValidator(new NoNewLineValidator(printerToPrinterED));
+       printerExtensionED->setValidator(new NoNewLineValidator(printerExtensionED));
+       printerPaperSizeED->setValidator(new NoNewLineValidator(printerPaperSizeED));
+       printerSpoolCommandED->setValidator(new NoNewLineValidator(printerSpoolCommandED));
+       printerSpoolPrefixED->setValidator(new NoNewLineValidator(printerSpoolPrefixED));
 }
 
 
@@ -2416,6 +2506,8 @@ PrefUserInterface::PrefUserInterface(GuiPreferences * form)
                this, SLOT(selectUi()));
        connect(uiFileED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
+       connect(iconSetCO, SIGNAL(activated(int)),
+               this, SIGNAL(changed()));
        connect(restoreCursorCB, SIGNAL(clicked()),
                this, SIGNAL(changed()));
        connect(loadSessionCB, SIGNAL(clicked()),
@@ -2435,11 +2527,18 @@ PrefUserInterface::PrefUserInterface(GuiPreferences * form)
        connect(tooltipCB, SIGNAL(toggled(bool)),
                this, SIGNAL(changed()));
        lastfilesSB->setMaximum(maxlastfiles);
+
+       iconSetCO->addItem(qt_("Default"), QString());
+       iconSetCO->addItem(qt_("Classic"), "classic");
+       iconSetCO->addItem(qt_("Oxygen"), "oxygen");
 }
 
 
 void PrefUserInterface::apply(LyXRC & rc) const
 {
+       rc.icon_set = fromqstr(iconSetCO->itemData(
+               iconSetCO->currentIndex()).toString());
+
        rc.ui_file = internal_path(fromqstr(uiFileED->text()));
        rc.use_lastfilepos = restoreCursorCB->isChecked();
        rc.load_session = loadSessionCB->isChecked();
@@ -2460,6 +2559,10 @@ void PrefUserInterface::apply(LyXRC & rc) const
 
 void PrefUserInterface::update(LyXRC const & rc)
 {
+       int iconset = iconSetCO->findData(toqstr(rc.icon_set));
+       if (iconset < 0)
+               iconset = 0;
+       iconSetCO->setCurrentIndex(iconset);
        uiFileED->setText(toqstr(external_path(rc.ui_file)));
        restoreCursorCB->setChecked(rc.use_lastfilepos);
        loadSessionCB->setChecked(rc.load_session);
@@ -2521,6 +2624,8 @@ PrefEdit::PrefEdit(GuiPreferences * form)
                this, SIGNAL(changed()));
        connect(macroEditStyleCO, SIGNAL(activated(int)),
                this, SIGNAL(changed()));
+       connect(cursorWidthSB, SIGNAL(valueChanged(int)),
+               this, SIGNAL(changed()));
        connect(fullscreenLimitGB, SIGNAL(clicked()),
                this, SIGNAL(changed()));
        connect(fullscreenWidthSB, SIGNAL(valueChanged(int)),
@@ -2548,6 +2653,7 @@ void PrefEdit::apply(LyXRC & rc) const
                case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
                case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST;   break;
        }
+       rc.cursor_width = cursorWidthSB->value();
        rc.full_screen_toolbars = toggleToolbarsCB->isChecked();
        rc.full_screen_scrollbar = toggleScrollbarCB->isChecked();
        rc.full_screen_tabbar = toggleTabbarCB->isChecked();
@@ -2565,6 +2671,7 @@ void PrefEdit::update(LyXRC const & rc)
        sortEnvironmentsCB->setChecked(rc.sort_layouts);
        groupEnvironmentsCB->setChecked(rc.group_layouts);
        macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
+       cursorWidthSB->setValue(rc.cursor_width);
        toggleScrollbarCB->setChecked(rc.full_screen_scrollbar);
        toggleToolbarsCB->setChecked(rc.full_screen_toolbars);
        toggleTabbarCB->setChecked(rc.full_screen_tabbar);
@@ -3060,6 +3167,9 @@ PrefIdentity::PrefIdentity(GuiPreferences * form)
                this, SIGNAL(changed()));
        connect(emailED, SIGNAL(textChanged(QString)),
                this, SIGNAL(changed()));
+
+       nameED->setValidator(new NoNewLineValidator(nameED));
+       emailED->setValidator(new NoNewLineValidator(emailED));
 }