diff --git a/lib/scripts/prefs2prefs_prefs.py b/lib/scripts/prefs2prefs_prefs.py index c7a5369741..5ce10511bc 100644 --- a/lib/scripts/prefs2prefs_prefs.py +++ b/lib/scripts/prefs2prefs_prefs.py @@ -28,6 +28,11 @@ # Incremented to format 4, r40028 by vfr # Remove support for default paper size. +# Incremented to format 5, r40030 by vfr +# Add a default length unit. +# No conversion necessary. + + import re @@ -141,4 +146,5 @@ conversions = [ [ 2, []], [ 3, [ zipped_native ]], [ 4, [ remove_default_papersize ]], + [ 5, []], ] diff --git a/src/Length.cpp b/src/Length.cpp index 4a7434435f..f8eb920c0f 100644 --- a/src/Length.cpp +++ b/src/Length.cpp @@ -320,8 +320,7 @@ int Length::inBP() const Length::UNIT Length::defaultUnit() { - // FIXME: use a preference - return Length::CM; + return lyxrc.default_length_unit; } diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index 145ac93d24..6f5a19e607 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -55,7 +55,7 @@ namespace os = support::os; namespace { -static unsigned int const LYXRC_FILEFORMAT = 4; // vfr: remove default paper size +static unsigned int const LYXRC_FILEFORMAT = 5; // vfr: add default length unit // when adding something to this array keep it sorted! LexerKeyword lyxrcTags[] = { @@ -91,6 +91,7 @@ LexerKeyword lyxrcTags[] = { { "\\def_file", LyXRC::RC_DEFFILE }, { "\\default_decimal_point", LyXRC::RC_DEFAULT_DECIMAL_POINT }, { "\\default_language", LyXRC::RC_DEFAULT_LANGUAGE }, + { "\\default_length_unit", LyXRC::RC_DEFAULT_LENGTH_UNIT }, { "\\default_view_format", LyXRC::RC_DEFAULT_VIEW_FORMAT }, { "\\dialogs_iconify_with_main", LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN }, { "\\display_graphics", LyXRC::RC_DISPLAY_GRAPHICS }, @@ -365,6 +366,7 @@ void LyXRC::setDefaults() completion_inline_dots = -1; completion_inline_delay = 0.2; default_decimal_point = "."; + default_length_unit = Length::CM; cursor_width = 1; } @@ -979,6 +981,10 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format) case RC_DEFAULT_DECIMAL_POINT: lexrc >> default_decimal_point; break; + case RC_DEFAULT_LENGTH_UNIT: + if (lexrc.next()) + default_length_unit = (Length::UNIT) lexrc.getInteger(); + break; case RC_DATE_INSERT_FORMAT: lexrc >> date_insert_format; break; @@ -2448,6 +2454,14 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c if (tag != RC_LAST) break; + case RC_DEFAULT_LENGTH_UNIT: + if (ignore_system_lyxrc || + default_length_unit != system_lyxrc.default_length_unit) { + os << "\\default_length_unit " << int(default_length_unit) << '\n'; + } + if (tag != RC_LAST) + break; + case RC_SPELLCHECKER: if (ignore_system_lyxrc || spellchecker != system_lyxrc.spellchecker) { @@ -2996,6 +3010,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new) case LyXRC::RC_FORWARD_SEARCH_PDF: case LyXRC::RC_EXPORT_OVERWRITE: case LyXRC::RC_DEFAULT_DECIMAL_POINT: + case LyXRC::RC_DEFAULT_LENGTH_UNIT: case LyXRC::RC_SCROLL_WHEEL_ZOOM: case LyXRC::RC_CURSOR_WIDTH: break; diff --git a/src/LyXRC.h b/src/LyXRC.h index 704fc75312..f80c7b5f51 100644 --- a/src/LyXRC.h +++ b/src/LyXRC.h @@ -19,6 +19,7 @@ #define LYXRC_H #include "paper.h" +#include "Length.h" #include "support/strfwd.h" @@ -68,6 +69,7 @@ public: RC_CURSOR_WIDTH, RC_DATE_INSERT_FORMAT, RC_DEFAULT_DECIMAL_POINT, + RC_DEFAULT_LENGTH_UNIT, RC_DEFAULT_LANGUAGE, RC_DEFAULT_VIEW_FORMAT, RC_DEFFILE, @@ -528,6 +530,8 @@ public: /// Default decimal point when aligning table columns on decimal std::string default_decimal_point; /// + Length::UNIT default_length_unit; + /// enum ScrollWheelZoom { SCROLL_WHEEL_ZOOM_OFF, SCROLL_WHEEL_ZOOM_CTRL, diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 3c74dedea3..b25406eb31 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -2255,6 +2255,8 @@ PrefLanguage::PrefLanguage(GuiPreferences * form) this, SIGNAL(changed())); connect(defaultDecimalPointLE, SIGNAL(textChanged(QString)), this, SIGNAL(changed())); + connect(defaultLengthUnitCO, SIGNAL(activated(int)), + this, SIGNAL(changed())); languagePackageED->setValidator(new NoNewLineValidator(languagePackageED)); startCommandED->setValidator(new NoNewLineValidator(startCommandED)); @@ -2268,6 +2270,9 @@ PrefLanguage::PrefLanguage(GuiPreferences * form) defaultDecimalPointLE->setInputMask("X; "); defaultDecimalPointLE->setMaxLength(1); + defaultLengthUnitCO->addItem(lyx::qt_(unit_name_gui[Length::CM]), Length::CM); + defaultLengthUnitCO->addItem(lyx::qt_(unit_name_gui[Length::IN]), Length::IN); + set added; uiLanguageCO->blockSignals(true); uiLanguageCO->addItem(qt_("Default"), toqstr("auto")); @@ -2327,6 +2332,7 @@ void PrefLanguage::apply(LyXRC & rc) const rc.gui_language = fromqstr( uiLanguageCO->itemData(uiLanguageCO->currentIndex()).toString()); rc.default_decimal_point = fromqstr(defaultDecimalPointLE->text()); + rc.default_length_unit = (Length::UNIT) defaultLengthUnitCO->itemData(defaultLengthUnitCO->currentIndex()).toInt(); } @@ -2348,8 +2354,10 @@ void PrefLanguage::update(LyXRC const & rc) startCommandED->setText(toqstr(rc.language_command_begin)); endCommandED->setText(toqstr(rc.language_command_end)); defaultDecimalPointLE->setText(toqstr(rc.default_decimal_point)); + int pos = defaultLengthUnitCO->findData(int(rc.default_length_unit)); + defaultLengthUnitCO->setCurrentIndex(pos); - int pos = uiLanguageCO->findData(toqstr(rc.gui_language)); + pos = uiLanguageCO->findData(toqstr(rc.gui_language)); uiLanguageCO->blockSignals(true); uiLanguageCO->setCurrentIndex(pos); uiLanguageCO->blockSignals(false); diff --git a/src/frontends/qt4/ui/PrefLanguageUi.ui b/src/frontends/qt4/ui/PrefLanguageUi.ui index d136f3a8e9..1027e7face 100644 --- a/src/frontends/qt4/ui/PrefLanguageUi.ui +++ b/src/frontends/qt4/ui/PrefLanguageUi.ui @@ -154,7 +154,20 @@ - + + + + Default length &unit: + + + defaultLengthUnitCO + + + + + + + Check to pass the language globally (to the document class), not locally (to the language package) @@ -164,7 +177,7 @@ - + If checked, the document language is not explicitly set by a language switch command @@ -174,7 +187,7 @@ - + If checked, the document language is not explicitly closed by a language switch command @@ -184,7 +197,7 @@ - + Check to highlight foreign languages visually in the work area @@ -194,7 +207,7 @@ - + @@ -272,7 +285,7 @@ - + Qt::Vertical