]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt/GuiPrefs.cpp
"System Default" viewer/editor option
[lyx.git] / src / frontends / qt / GuiPrefs.cpp
index b591f1d343528159a4d18633196a26f4d2c96d34..e6074712993a03234d4b073c27a6995db64e3a2b 100644 (file)
@@ -31,7 +31,6 @@
 #include "ConverterCache.h"
 #include "FontEnums.h"
 #include "FuncRequest.h"
-#include "KeyMap.h"
 #include "KeySequence.h"
 #include "Language.h"
 #include "LyXAction.h"
@@ -50,8 +49,6 @@
 #include "support/os.h"
 #include "support/Package.h"
 
-#include "graphics/GraphicsTypes.h"
-
 #include "frontends/alert.h"
 #include "frontends/Application.h"
 #include "frontends/FontLoader.h"
@@ -191,7 +188,11 @@ QString browseRelToSub(QString const & filename, QString const & relpath,
                toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(relpath)));
 
        QString testname = reloutname;
+#if QT_VERSION < 0x060000
        testname.remove(QRegExp("^(\\.\\./)+"));
+#else
+       testname.remove(QRegularExpression("^(\\.\\./)+"));
+#endif
 
        if (testname.contains("/"))
                return outname;
@@ -914,26 +915,48 @@ PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
 {
        setupUi(this);
 
+#if QT_VERSION < 0x050e00
        connect(screenRomanCO, SIGNAL(activated(QString)),
                this, SLOT(selectRoman(QString)));
        connect(screenSansCO, SIGNAL(activated(QString)),
                this, SLOT(selectSans(QString)));
        connect(screenTypewriterCO, SIGNAL(activated(QString)),
                this, SLOT(selectTypewriter(QString)));
+#else
+       connect(screenRomanCO, SIGNAL(textActivated(QString)),
+               this, SLOT(selectRoman(QString)));
+       connect(screenSansCO, SIGNAL(textActivated(QString)),
+               this, SLOT(selectSans(QString)));
+       connect(screenTypewriterCO, SIGNAL(textActivated(QString)),
+               this, SLOT(selectTypewriter(QString)));
+#endif
 
+#if QT_VERSION >= 0x060000
+       const QStringList families(QFontDatabase::families());
+#else
        QFontDatabase fontdb;
-       QStringList families(fontdb.families());
-       for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
-               screenRomanCO->addItem(*it);
-               screenSansCO->addItem(*it);
-               screenTypewriterCO->addItem(*it);
+       const QStringList families(fontdb.families());
+#endif
+       for (auto const & family : families) {
+               screenRomanCO->addItem(family);
+               screenSansCO->addItem(family);
+               screenTypewriterCO->addItem(family);
        }
+#if QT_VERSION < 0x050e00
        connect(screenRomanCO, SIGNAL(activated(QString)),
                this, SIGNAL(changed()));
        connect(screenSansCO, SIGNAL(activated(QString)),
                this, SIGNAL(changed()));
        connect(screenTypewriterCO, SIGNAL(activated(QString)),
                this, SIGNAL(changed()));
+#else
+       connect(screenRomanCO, SIGNAL(textActivated(QString)),
+               this, SIGNAL(changed()));
+       connect(screenSansCO, SIGNAL(textActivated(QString)),
+               this, SIGNAL(changed()));
+       connect(screenTypewriterCO, SIGNAL(textActivated(QString)),
+               this, SIGNAL(changed()));
+#endif
        connect(screenZoomSB, SIGNAL(valueChanged(int)),
                this, SIGNAL(changed()));
        connect(screenTinyED, SIGNAL(textChanged(QString)),
@@ -1134,7 +1157,7 @@ void PrefColors::applyRC(LyXRC & rc) const
 void PrefColors::updateRC(LyXRC const & rc)
 {
        for (size_type i = 0; i < lcolors_.size(); ++i) {
-               QColor color = QColor(guiApp->colorCache().get(lcolors_[i], false));
+               QColor color = guiApp->colorCache().get(lcolors_[i], false);
                QPixmap coloritem(32, 32);
                coloritem.fill(color);
                lyxObjectsLW->item(int(i))->setIcon(QIcon(coloritem));
@@ -1207,8 +1230,8 @@ void PrefColors::resetAllColor()
 }
 
 
-bool PrefColors::setColor(int const row, QColor const new_color,
-                         QString const old_color)
+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();
@@ -1245,7 +1268,7 @@ void PrefColors::setDisabledResets()
 }
 
 
-bool PrefColors::isDefaultColor(int const row, QString const color)
+bool PrefColors::isDefaultColor(int const row, QString const color)
 {
        return color == getDefaultColorByRow(row).name();
 }
@@ -1254,7 +1277,8 @@ bool PrefColors::isDefaultColor(int const row, QString const color)
 QColor PrefColors::getDefaultColorByRow(int const row)
 {
        ColorSet const defaultcolor;
-       return defaultcolor.getX11HexName(lcolors_[size_t(row)]).c_str();
+       return defaultcolor.getX11HexName(lcolors_[size_t(row)],
+                       guiApp->colorCache().isDarkMode()).c_str();
 }
 
 
@@ -1639,10 +1663,17 @@ PrefConverters::PrefConverters(GuiPreferences * form)
                this, SLOT(updateConverter()));
        connect(convertersLW, SIGNAL(currentRowChanged(int)),
                this, SLOT(switchConverter()));
+#if QT_VERSION < 0x050e00
        connect(converterFromCO, SIGNAL(activated(QString)),
                this, SLOT(changeConverter()));
        connect(converterToCO, SIGNAL(activated(QString)),
                this, SLOT(changeConverter()));
+#else
+       connect(converterFromCO, SIGNAL(textActivated(QString)),
+               this, SLOT(changeConverter()));
+       connect(converterToCO, SIGNAL(textActivated(QString)),
+               this, SLOT(changeConverter()));
+#endif
        connect(converterED, SIGNAL(textEdited(QString)),
                this, SLOT(changeConverter()));
        connect(converterFlagED, SIGNAL(textEdited(QString)),
@@ -1879,8 +1910,8 @@ class FormatValidator : public QValidator
 {
 public:
        FormatValidator(QWidget *, Formats const & f);
-       void fixup(QString & input) const;
-       QValidator::State validate(QString & input, int & pos) const;
+       void fixup(QString & input) const override;
+       QValidator::State validate(QString & input, int & pos) const override;
 private:
        virtual QString toString(Format const & format) const = 0;
        int nr() const;
@@ -1946,7 +1977,7 @@ public:
                : FormatValidator(parent, f)
        {}
 private:
-       QString toString(Format const & format) const
+       QString toString(Format const & format) const override
        {
                return toqstr(format.name());
        }
@@ -1966,7 +1997,7 @@ public:
                : FormatValidator(parent, f)
        {}
 private:
-       QString toString(Format const & format) const
+       QString toString(Format const & format) const override
        {
                return toqstr(translateIfPossible(format.prettyname()));
        }
@@ -2002,12 +2033,21 @@ PrefFileformats::PrefFileformats(GuiPreferences * form)
                this, SLOT(updatePrettyname()));
        connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)),
                this, SIGNAL(changed()));
+#if QT_VERSION < 0x050e00
        connect(defaultFormatCB, SIGNAL(activated(QString)),
                this, SIGNAL(changed()));
        connect(defaultOTFFormatCB, SIGNAL(activated(QString)),
                this, SIGNAL(changed()));
        connect(defaultPlatexFormatCB, SIGNAL(activated(QString)),
                this, SIGNAL(changed()));
+#else
+       connect(defaultFormatCB, SIGNAL(textActivated(QString)),
+               this, SIGNAL(changed()));
+       connect(defaultOTFFormatCB, SIGNAL(textActivated(QString)),
+               this, SIGNAL(changed()));
+       connect(defaultPlatexFormatCB, SIGNAL(textActivated(QString)),
+               this, SIGNAL(changed()));
+#endif
        connect(viewerCO, SIGNAL(activated(int)),
                this, SIGNAL(changed()));
        connect(editorCO, SIGNAL(activated(int)),
@@ -2285,6 +2325,7 @@ void PrefFileformats::updateViewers()
        viewerCO->blockSignals(true);
        viewerCO->clear();
        viewerCO->addItem(qt_("None"), QString());
+       viewerCO->addItem(qt_("System Default"), QString("auto"));
        updateComboBox(viewer_alternatives, f.name(), viewerCO);
        viewerCO->addItem(qt_("Custom"), QString("custom viewer"));
        viewerCO->blockSignals(false);
@@ -2308,6 +2349,7 @@ void PrefFileformats::updateEditors()
        editorCO->blockSignals(true);
        editorCO->clear();
        editorCO->addItem(qt_("None"), QString());
+       editorCO->addItem(qt_("System Default"), QString("auto"));
        updateComboBox(editor_alternatives, f.name(), editorCO);
        editorCO->addItem(qt_("Custom"), QString("custom editor"));
        editorCO->blockSignals(false);
@@ -2426,7 +2468,11 @@ PrefLanguage::PrefLanguage(GuiPreferences * form)
        startCommandED->setValidator(new NoNewLineValidator(startCommandED));
        endCommandED->setValidator(new NoNewLineValidator(endCommandED));
 
+#if QT_VERSION < 0x060000
        defaultDecimalSepED->setValidator(new QRegExpValidator(QRegExp("\\S"), this));
+#else
+       defaultDecimalSepED->setValidator(new QRegularExpressionValidator(QRegularExpression("\\S"), this));
+#endif
        defaultDecimalSepED->setMaxLength(1);
 
        defaultLengthUnitCO->addItem(lyx::qt_(unit_name_gui[Length::CM]), Length::CM);
@@ -2455,6 +2501,9 @@ PrefLanguage::PrefLanguage(GuiPreferences * form)
                                      index.data(Qt::UserRole).toString());
        }
        uiLanguageCO->blockSignals(false);
+
+       // FIXME: restore this when it works (see discussion in #6450).
+       respectOSkbdCB->hide();
 }
 
 
@@ -2583,9 +2632,12 @@ PrefUserInterface::PrefUserInterface(GuiPreferences * form)
        iconSetCO->addItem(qt_("Classic"), "classic");
        iconSetCO->addItem(qt_("Oxygen"), "oxygen");
 
-#if (!(defined Q_WS_X11 || defined(QPA_XCB)) || QT_VERSION < 0x040600)
-       useSystemThemeIconsCB->hide();
+#if QT_VERSION >= 0x040600
+       if (guiApp->platformName() != "qt4x11"
+           && guiApp->platformName() != "xcb"
+           && !guiApp->platformName().contains("wayland"))
 #endif
+               useSystemThemeIconsCB->hide();
 }
 
 
@@ -3037,11 +3089,11 @@ QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
        QTreeWidgetItem * newItem = nullptr;
        // for unbind items, try to find an existing item in the system bind list
        if (tag == KeyMap::UserUnbind) {
-               QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
-                       Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
-               for (int i = 0; i < items.size(); ++i) {
-                       if (items[i]->text(1) == shortcut) {
-                               newItem = items[i];
+               QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(shortcut,
+                       Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 1);
+               for (auto const & item : items) {
+                       if (item->text(0) == lfun_name || lfun == FuncRequest::unknown) {
+                               newItem = item;
                                break;
                        }
                }
@@ -3075,10 +3127,10 @@ QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
                        // this should not happen
                        newItem = new QTreeWidgetItem(shortcutsTW);
                }
+               newItem->setText(0, lfun_name);
+               newItem->setText(1, shortcut);
        }
 
-       newItem->setText(0, lfun_name);
-       newItem->setText(1, shortcut);
        // record BindFile representation to recover KeySequence when needed.
        newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
        setItemType(newItem, tag);
@@ -3128,8 +3180,7 @@ void PrefShortcuts::unhideEmpty(QString const & lfun, bool select)
        // list of items that match lfun
        QList<QTreeWidgetItem*> items = shortcutsTW->findItems(lfun,
             Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
-       for (int i = 0; i < items.size(); ++i) {
-               QTreeWidgetItem * item = items[i];
+       for (auto const & item : items) {
                if (isAlwaysHidden(*item)) {
                        setItemType(item, KeyMap::System);
                        if (select)
@@ -3145,24 +3196,24 @@ void PrefShortcuts::removeShortcut()
        // it seems that only one item can be selected, but I am
        // removing all selected items anyway.
        QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
-       for (int i = 0; i < items.size(); ++i) {
-               string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
-               string lfun = fromqstr(items[i]->text(0));
-               FuncRequest func = lyxaction.lookupFunc(lfun);
+       for (auto & item : items) {
+               string shortcut = fromqstr(item->data(1, Qt::UserRole).toString());
+               string lfun = fromqstr(item->text(0));
+               FuncRequest const func = lyxaction.lookupFunc(lfun);
 
-               switch (itemType(*items[i])) {
+               switch (itemType(*item)) {
                case KeyMap::System: {
                        // for system bind, we do not touch the item
                        // but add an user unbind item
                        user_unbind_.bind(shortcut, func);
-                       setItemType(items[i], KeyMap::UserUnbind);
+                       setItemType(item, KeyMap::UserUnbind);
                        removePB->setText(qt_("Res&tore"));
                        break;
                }
                case KeyMap::UserBind: {
                        // for user_bind, we remove this bind
-                       QTreeWidgetItem * parent = items[i]->parent();
-                       int itemIdx = parent->indexOfChild(items[i]);
+                       QTreeWidgetItem * parent = item->parent();
+                       int itemIdx = parent->indexOfChild(item);
                        parent->takeChild(itemIdx);
                        if (itemIdx > 0)
                                shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
@@ -3171,7 +3222,7 @@ void PrefShortcuts::removeShortcut()
                        user_bind_.unbind(shortcut, func);
                        // If this user binding hid an empty system binding, unhide the
                        // latter and select it.
-                       unhideEmpty(items[i]->text(0), true);
+                       unhideEmpty(item->text(0), true);
                        break;
                }
                case KeyMap::UserUnbind: {
@@ -3183,15 +3234,15 @@ void PrefShortcuts::removeShortcut()
                        if (!validateNewShortcut(func, seq, QString()))
                                break;
                        user_unbind_.unbind(shortcut, func);
-                       setItemType(items[i], KeyMap::System);
+                       setItemType(item, KeyMap::System);
                        removePB->setText(qt_("Remo&ve"));
                        break;
                }
                case KeyMap::UserExtraUnbind: {
                        // for user unbind that is not in system bind file,
                        // remove this unbind file
-                       QTreeWidgetItem * parent = items[i]->parent();
-                       parent->takeChild(parent->indexOfChild(items[i]));
+                       QTreeWidgetItem * parent = item->parent();
+                       parent->takeChild(parent->indexOfChild(item));
                        user_unbind_.unbind(shortcut, func);
                }
                }
@@ -3201,26 +3252,26 @@ void PrefShortcuts::removeShortcut()
 
 void PrefShortcuts::deactivateShortcuts(QList<QTreeWidgetItem*> const & items)
 {
-       for (int i = 0; i < items.size(); ++i) {
-               string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
-               string lfun = fromqstr(items[i]->text(0));
-               FuncRequest func = lyxaction.lookupFunc(lfun);
+       for (auto item : items) {
+               string shortcut = fromqstr(item->data(1, Qt::UserRole).toString());
+               string lfun = fromqstr(item->text(0));
+               FuncRequest const func = lyxaction.lookupFunc(lfun);
 
-               switch (itemType(*items[i])) {
+               switch (itemType(*item)) {
                case KeyMap::System:
                        // for system bind, we do not touch the item
                        // but add an user unbind item
                        user_unbind_.bind(shortcut, func);
-                       setItemType(items[i], KeyMap::UserUnbind);
+                       setItemType(item, KeyMap::UserUnbind);
                        break;
 
                case KeyMap::UserBind: {
                        // for user_bind, we remove this bind
-                       QTreeWidgetItem * parent = items[i]->parent();
-                       int itemIdx = parent->indexOfChild(items[i]);
+                       QTreeWidgetItem * parent = item->parent();
+                       int itemIdx = parent->indexOfChild(item);
                        parent->takeChild(itemIdx);
                        user_bind_.unbind(shortcut, func);
-                       unhideEmpty(items[i]->text(0), false);
+                       unhideEmpty(item->text(0), false);
                        break;
                }
                default:
@@ -3287,11 +3338,11 @@ void PrefShortcuts::on_searchLE_textEdited()
        while (*it)
                (*it++)->setHidden(true);
        // show matched items
-       for (int i = 0; i < matched.size(); ++i)
-               if (!isAlwaysHidden(*matched[i])) {
-                       matched[i]->setHidden(false);
-                       if (matched[i]->parent())
-                               matched[i]->parent()->setExpanded(true);
+       for (auto & item : matched)
+               if (!isAlwaysHidden(*item)) {
+                       item->setHidden(false);
+                       if (item->parent())
+                               item->parent()->setExpanded(true);
                }
 }
 
@@ -3377,7 +3428,7 @@ bool PrefShortcuts::validateNewShortcut(FuncRequest const & func,
 void PrefShortcuts::shortcutOkPressed()
 {
        QString const new_lfun = shortcut_->lfunLE->text();
-       FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun));
+       FuncRequest const func = lyxaction.lookupFunc(fromqstr(new_lfun));
        KeySequence k = shortcut_->shortcutWG->getKeySequence();
 
        // save_lfun_ contains the text of the lfun to modify, if the user clicked
@@ -3398,7 +3449,8 @@ void PrefShortcuts::shortcutOkPressed()
        if (item) {
                user_bind_.bind(&k, func);
                shortcutsTW->sortItems(0, Qt::AscendingOrder);
-               item->parent()->setExpanded(true);
+               if (item->parent())
+                       item->parent()->setExpanded(true);
                shortcutsTW->setCurrentItem(item);
                shortcutsTW->scrollToItem(item);
        } else {
@@ -3690,9 +3742,6 @@ QString GuiPreferences::browse(QString const & file,
 }
 
 
-Dialog * createGuiPreferences(GuiView & lv) { return new GuiPreferences(lv); }
-
-
 } // namespace frontend
 } // namespace lyx