]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDocument.cpp
proper fix for bug 4936.
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
index 3a90e3d33044c6c0d6e9510b15dc26a347b0b02f..9cbaec7436d01f5c9b03d1a537968002d92992ac 100644 (file)
@@ -50,6 +50,7 @@
 
 #include "frontends/alert.h"
 
+#include <QAbstractItemModel>
 #include <QCloseEvent>
 #include <QScrollBar>
 #include <QTextCursor>
@@ -508,7 +509,7 @@ void PreambleModule::closeEvent(QCloseEvent * e)
 
 
 GuiDocument::GuiDocument(GuiView & lv)
-       : GuiDialog(lv, "document", qt_("Document Settings")), current_id_(0)
+       : GuiDialog(lv, "document", qt_("Document Settings"))
 {
        setupUi(this);
 
@@ -604,6 +605,8 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
                this, SLOT(change_adaptor()));
+       connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
+               this, SLOT(change_adaptor()));
        connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
                this, SLOT(change_adaptor()));
        connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
@@ -787,7 +790,10 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
                this, SLOT(change_adaptor()));
        // language & quotes
-       langModule->languageCO->setModel(guiApp->languageModel());
+       QAbstractItemModel * language_model = guiApp->languageModel();
+       // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
+       language_model->sort(0);
+       langModule->languageCO->setModel(language_model);
 
        // Always put the default encoding in the first position.
        // It is special because the displayed text is translated.
@@ -1314,7 +1320,7 @@ void GuiDocument::classChanged()
                                applyView();
                }
                bp_.useClassDefaults();
-               forceUpdate();
+               paramsToDialog(bp_);
        }
 }
 
@@ -1643,6 +1649,9 @@ void GuiDocument::apply(BufferParams & params)
        params.fontsTypewriter =
                tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
 
+       params.fontsCJK =
+               fromqstr(fontModule->cjkFontLE->text());
+
        params.fontsSansScale = fontModule->scaleSansSB->value();
 
        params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
@@ -1729,13 +1738,7 @@ void GuiDocument::apply(BufferParams & params)
 }
 
 
-void GuiDocument::updateParams()
-{
-       updateParams(bp_);
-}
-
-
-void GuiDocument::updateParams(BufferParams const & params)
+void GuiDocument::paramsToDialog(BufferParams const & params)
 {
        // set the default unit
        Length::UNIT defaultUnit = Length::CM;
@@ -1947,6 +1950,12 @@ void GuiDocument::updateParams(BufferParams const & params)
                ttChanged(n);
        }
 
+       if (!params.fontsCJK.empty())
+               fontModule->cjkFontLE->setText(
+                       toqstr(params.fontsCJK));
+       else
+               fontModule->cjkFontLE->setText(QString());
+
        fontModule->fontScCB->setChecked(params.fontsSC);
        fontModule->fontOsfCB->setChecked(params.fontsOSF);
        fontModule->scaleSansSB->setValue(params.fontsSansScale);
@@ -2077,26 +2086,8 @@ void GuiDocument::updateSelectedModules()
 
 void GuiDocument::updateContents()
 {
-       if (id() == current_id_)
-               return;
-
-       updateAvailableModules();
-       updateSelectedModules();
-       
-       //FIXME It'd be nice to make sure here that the selected
-       //modules are consistent: That required modules are actually
-       //selected, and that we don't have conflicts. If so, we could
-       //at least pop up a warning.
-       updateParams(bp_);
-       current_id_ = id();
-}
-
-
-void GuiDocument::forceUpdate()
-{
-       // reset to force dialog update
-       current_id_ = 0;
-       updateContents();
+       // Nothing to do here as the document settings is not cursor dependant.
+       return;
 }
 
 
@@ -2118,7 +2109,7 @@ void GuiDocument::useClassDefaults()
                return;
        }
        bp_.useClassDefaults();
-       forceUpdate();
+       paramsToDialog(bp_);
 }
 
 
@@ -2153,10 +2144,21 @@ char const * GuiDocument::fontfamilies_gui[5] = {
 
 bool GuiDocument::initialiseParams(string const &)
 {
-       bp_ = buffer().params();
-       // Force update on next updateContent() round.
-       current_id_ = 0;
+       BufferView * view = bufferview();
+       if (!view) {
+               bp_ = BufferParams();
+               paramsToDialog(bp_);
+               return true;
+       }
+       bp_ = view->buffer().params();
        loadModuleInfo();
+       updateAvailableModules();
+       updateSelectedModules();
+       //FIXME It'd be nice to make sure here that the selected
+       //modules are consistent: That required modules are actually
+       //selected, and that we don't have conflicts. If so, we could
+       //at least pop up a warning.
+       paramsToDialog(bp_);
        return true;
 }
 
@@ -2169,7 +2171,8 @@ void GuiDocument::clearParams()
 
 BufferId GuiDocument::id() const
 {
-       return &buffer();
+       BufferView const * const view = bufferview();
+       return view? &view->buffer() : 0;
 }