]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDocument.cpp
Andre's s/getBaseClass/baseClass/ cleanup.
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
index 4d4c6530cdf337fe8f285df4a801123e9a5dcdec..6adc1f52e9a7ce7c5c568410b03b9c4294a6b7f9 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>
@@ -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()));
@@ -518,7 +518,7 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
                this, SLOT(setLSpacing(int)));
-       connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)),
+       connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
                this, SLOT(change_adaptor()));
        connect(textLayoutModule->skipRB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
@@ -536,6 +536,8 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(enableSkip(bool)));
        connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
+       connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
+               this, SLOT(setColSep()));
        connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
                this, SLOT(change_adaptor()));
        connect(textLayoutModule->bypassCB, SIGNAL(clicked()), 
@@ -718,6 +720,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 +738,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 +755,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 +851,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 +1043,6 @@ void GuiDocument::set_listings_msg()
 }
 
 
-void GuiDocument::closeEvent(QCloseEvent * e)
-{
-       slotClose();
-       e->accept();
-}
-
-
 void GuiDocument::setLSpacing(int item)
 {
        textLayoutModule->lspacingLE->setEnabled(item == 3);
@@ -1089,6 +1092,12 @@ void GuiDocument::setCustomPapersize(int papersize)
 }
 
 
+void GuiDocument::setColSep()
+{
+       setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
+}
+
+
 void GuiDocument::setCustomMargins(bool custom)
 {
        marginsModule->topL->setEnabled(!custom);
@@ -1118,6 +1127,12 @@ void GuiDocument::setCustomMargins(bool custom)
        marginsModule->footskipL->setEnabled(!custom);
        marginsModule->footskipLE->setEnabled(!custom);
        marginsModule->footskipUnit->setEnabled(!custom);
+
+       bool const enableColSep = !custom && 
+                       textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
+       marginsModule->columnsepL->setEnabled(enableColSep);
+       marginsModule->columnsepLE->setEnabled(enableColSep);
+       marginsModule->columnsepUnit->setEnabled(enableColSep);
 }
 
 
@@ -1200,8 +1215,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();
        }
 }
 
@@ -1331,7 +1354,7 @@ void GuiDocument::updateEmbeddedFileList()
 
 void GuiDocument::updateNumbering()
 {
-       TextClass const & tclass = bp_.getTextClass();
+       TextClass const & tclass = bp_.textClass();
 
        numberingModule->tocTW->setUpdatesEnabled(false);
        numberingModule->tocTW->clear();
@@ -1340,15 +1363,13 @@ void GuiDocument::updateNumbering()
        int const toc = numberingModule->tocSL->value();
        QString const no = qt_("No");
        QString const yes = qt_("Yes");
-       TextClass::const_iterator end = tclass.end();
-       TextClass::const_iterator cit = tclass.begin();
        QTreeWidgetItem * item = 0;
-       for ( ; cit != end ; ++cit) {
-               int const toclevel = (*cit)->toclevel;
-               if (toclevel != Layout::NOT_IN_TOC
-                   && (*cit)->labeltype == LABEL_COUNTER) {
+       for (size_t i = 0; i != tclass.layoutCount(); ++i) {
+               Layout const & lt = *tclass.layout(i);
+               int const toclevel = lt.toclevel;
+               if (toclevel != Layout::NOT_IN_TOC && lt.labeltype == LABEL_COUNTER) {
                        item = new QTreeWidgetItem(numberingModule->tocTW);
-                       item->setText(0, toqstr(translateIfPossible((*cit)->name())));
+                       item->setText(0, toqstr(translateIfPossible(lt.name())));
                        item->setText(1, (toclevel <= depth) ? yes : no);
                        item->setText(2, (toclevel <= toc) ? yes : no);
                }
@@ -1420,7 +1441,7 @@ void GuiDocument::apply(BufferParams & params)
        params.language = lyx::languages.getLanguage(lang_[pos]);
 
        // numbering
-       if (params.getTextClass().hasTocLevels()) {
+       if (params.textClass().hasTocLevels()) {
                params.tocdepth = numberingModule->tocSL->value();
                params.secnumdepth = numberingModule->depthSL->value();
        }
@@ -1599,6 +1620,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);
 
@@ -1771,7 +1793,7 @@ void GuiDocument::updateParams(BufferParams const & params)
        }
 
        // text layout
-       latexModule->classCO->setCurrentIndex(params.getBaseClass());
+       latexModule->classCO->setCurrentIndex(params.baseClass());
        
        updatePagestyle(textClass().opt_pagestyle(),
                                 params.pagestyle);
@@ -1908,6 +1930,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
@@ -1982,6 +2007,9 @@ void GuiDocument::updateSelectedModules()
 
 void GuiDocument::updateContents()
 {
+       if (id() == current_id_)
+               return;
+
        updateAvailableModules();
        updateSelectedModules();
        
@@ -1990,19 +2018,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()));
 }
 
 
@@ -2064,7 +2113,7 @@ vector<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
 
 TextClass const & GuiDocument::textClass() const
 {
-       return textclasslist[bp_.getBaseClass()];
+       return textclasslist[bp_.baseClass()];
 }