]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDocument.cpp
Add support for column separation in page margins. Fixes bug 3337.
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
index 0938f455fd1974351dece1af93a3008672d7df21..a0054bf48bff912ec35a68f41ca460b7b1b35a63 100644 (file)
 
 #include "insets/InsetListingsParams.h"
 
-//#include "support/debug.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
 
+#include "frontends/alert.h"
+
 #include <boost/bind.hpp>
 
 #include <QCloseEvent>
@@ -174,7 +175,7 @@ namespace {
                LyXModule const * const mod = moduleList[modName];
                if (!mod)
                        return _("Module not found!");
-               return from_ascii(mod->getDescription());
+               return _(mod->getDescription());
        }
 
 
@@ -490,11 +491,10 @@ void PreambleModule::closeEvent(QCloseEvent * e)
 
 
 GuiDocument::GuiDocument(GuiView & lv)
-       : GuiDialog(lv, "document")
+       : GuiDialog(lv, "document", qt_("Document Settings")), current_id_(0)
 {
        setupUi(this);
-       setViewTitle(_("Document Settings"));
-
+       
        lang_ = getSecond(getLanguageData(false));
 
        connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
@@ -718,6 +718,10 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
                this, SLOT(change_adaptor()));
+       connect(marginsModule->columnsepLE, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_adaptor()));
+       connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
        marginsModule->topLE->setValidator(unsignedLengthValidator(
                marginsModule->topLE));
        marginsModule->bottomLE->setValidator(unsignedLengthValidator(
@@ -732,6 +736,8 @@ GuiDocument::GuiDocument(GuiView & lv)
                marginsModule->headheightLE));
        marginsModule->footskipLE->setValidator(unsignedLengthValidator(
                marginsModule->footskipLE));
+       marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
+               marginsModule->columnsepLE));
 
        bc().addCheckedLineEdit(marginsModule->topLE,
                marginsModule->topL);
@@ -747,6 +753,8 @@ GuiDocument::GuiDocument(GuiView & lv)
                marginsModule->headheightL);
        bc().addCheckedLineEdit(marginsModule->footskipLE,
                marginsModule->footskipL);
+       bc().addCheckedLineEdit(marginsModule->columnsepLE,
+               marginsModule->columnsepL);
 
 
        langModule = new UiWidget<Ui::LanguageUi>;
@@ -841,14 +849,14 @@ GuiDocument::GuiDocument(GuiView & lv)
 
        latexModule = new UiWidget<Ui::LaTeXUi>;
        // latex class
-       connect(latexModule->classCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
        connect(latexModule->optionsLE, SIGNAL(textChanged(const QString &)),
                this, SLOT(change_adaptor()));
        connect(latexModule->psdriverCO, SIGNAL(activated(int)),
                this, SLOT(change_adaptor()));
        connect(latexModule->classCO, SIGNAL(activated(int)),
                this, SLOT(classChanged()));
+       connect(latexModule->classCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
        
        selectionManager = 
                new ModuleSelMan(latexModule->availableLV, latexModule->selectedLV, 
@@ -1033,13 +1041,6 @@ void GuiDocument::set_listings_msg()
 }
 
 
-void GuiDocument::closeEvent(QCloseEvent * e)
-{
-       slotClose();
-       e->accept();
-}
-
-
 void GuiDocument::setLSpacing(int item)
 {
        textLayoutModule->lspacingLE->setEnabled(item == 3);
@@ -1118,6 +1119,10 @@ void GuiDocument::setCustomMargins(bool custom)
        marginsModule->footskipL->setEnabled(!custom);
        marginsModule->footskipLE->setEnabled(!custom);
        marginsModule->footskipUnit->setEnabled(!custom);
+
+       marginsModule->columnsepL->setEnabled(!custom);
+       marginsModule->columnsepLE->setEnabled(!custom);
+       marginsModule->columnsepUnit->setEnabled(!custom);
 }
 
 
@@ -1200,8 +1205,16 @@ void GuiDocument::classChanged()
        textclass_type const tc = latexModule->classCO->currentIndex();
        bp_.setBaseClass(tc);
        if (lyxrc.auto_reset_options) {
+               if (applyPB->isEnabled()) {
+                       int const ret = Alert::prompt(_("Unapplied changes"),
+                                       _("Some changes in the dialog were not yet applied."
+                                       "If you do not apply now, they will be lost after this action."),
+                                       1, 1, _("&Apply"), _("&Dismiss"));
+                       if (ret == 0)
+                               applyView();
+               }
                bp_.useClassDefaults();
-               updateContents();
+               forceUpdate();
        }
 }
 
@@ -1599,6 +1612,7 @@ void GuiDocument::apply(BufferParams & params)
        params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
        params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
        params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
+       params.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
 
        branchesModule->apply(params);
 
@@ -1908,6 +1922,9 @@ void GuiDocument::updateParams(BufferParams const & params)
        lengthToWidgets(m->footskipLE, m->footskipUnit,
                params.footskip, defaultUnit);
 
+       lengthToWidgets(m->columnsepLE, m->columnsepUnit,
+               params.columnsep, defaultUnit);
+
        branchesModule->update(params);
 
        // PDF support
@@ -1962,7 +1979,7 @@ void GuiDocument::updateAvailableModules()
        int const mSize = modInfoList.size();
        for (int i = 0; i < mSize; ++i) {
                modInfoStruct const & modInfo = modInfoList[i];
-               available_model_.insertRow(i, modInfo.name, modInfo.id);
+               available_model_.insertRow(i, qt_(modInfo.name), modInfo.id);
        }
 }
 
@@ -1975,13 +1992,16 @@ void GuiDocument::updateSelectedModules()
        int const sSize = selModList.size();
        for (int i = 0; i < sSize; ++i) {
                modInfoStruct const & modInfo = selModList[i];
-               selected_model_.insertRow(i, modInfo.name, modInfo.id);
+               selected_model_.insertRow(i, qt_(modInfo.name), modInfo.id);
        }
 }
 
 
 void GuiDocument::updateContents()
 {
+       if (id() == current_id_)
+               return;
+
        updateAvailableModules();
        updateSelectedModules();
        
@@ -1990,19 +2010,40 @@ void GuiDocument::updateContents()
        //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();
 }
 
+
 void GuiDocument::useClassDefaults()
 {
+       if (applyPB->isEnabled()) {
+               int const ret = Alert::prompt(_("Unapplied changes"),
+                               _("Some changes in the dialog were not yet applied."
+                                 "If you do not apply now, they will be lost after this action."),
+                               1, 1, _("&Apply"), _("&Dismiss"));
+               if (ret == 0)
+                       applyView();
+       }
+
        bp_.setBaseClass(latexModule->classCO->currentIndex());
        bp_.useClassDefaults();
-       updateContents();
+       forceUpdate();
 }
 
 
 bool GuiDocument::isValid()
 {
-       return validate_listings_params().empty();
+       return (validate_listings_params().empty() &&
+               (textLayoutModule->skipCO->currentIndex() != 3 ||
+                !textLayoutModule->skipLE->text().isEmpty()));
 }