]> 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 573696464114917b323554e51376660f2c95f41d..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>
@@ -59,6 +60,7 @@
 using namespace std;
 using namespace lyx::support;
 
+
 ///
 template<class Pair>
 vector<typename Pair::second_type> const
@@ -70,6 +72,7 @@ getSecond(vector<Pair> const & pr)
         return tmp;
 }
 
+
 char const * const tex_graphics[] =
 {
        "default", "dvips", "dvitops", "emtex",
@@ -135,6 +138,19 @@ vector<pair<string, lyx::docstring> > pagestyles;
 namespace lyx {
 namespace frontend {
 
+
+/// 
+QModelIndex getSelectedIndex(QListView * lv)
+{
+       QModelIndex retval = QModelIndex();
+       QModelIndexList selIdx = 
+                       lv->selectionModel()->selectedIndexes();
+       if (!selIdx.empty())
+               retval = selIdx.first();
+       return retval;
+}
+
+
 namespace {
        vector<string> getRequiredList(string const & modName) 
        {
@@ -159,7 +175,7 @@ namespace {
                LyXModule const * const mod = moduleList[modName];
                if (!mod)
                        return _("Module not found!");
-               return from_ascii(mod->getDescription());
+               return _(mod->getDescription());
        }
 
 
@@ -195,19 +211,6 @@ GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
                     upPB, downPB, availableModel, selectedModel) 
 {}
        
-       
-namespace {
-QModelIndex getSelectedIndex(QListView * lv)
-{
-       QModelIndex retval = QModelIndex();
-       QModelIndexList selIdx = 
-                       lv->selectionModel()->selectedIndexes();
-       if (!selIdx.empty())
-               retval = selIdx.first();
-       return retval;
-}
-}
-
 
 void ModuleSelMan::updateAddPB() 
 {
@@ -488,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()));
@@ -516,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()));
@@ -534,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()), 
@@ -716,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(
@@ -730,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);
@@ -745,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>;
@@ -839,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, 
@@ -1031,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);
@@ -1087,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);
@@ -1116,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);
 }
 
 
@@ -1198,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();
        }
 }
 
@@ -1329,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();
@@ -1338,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);
                }
@@ -1418,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();
        }
@@ -1597,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);
 
@@ -1769,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);
@@ -1906,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
@@ -1960,7 +1987,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);
        }
 }
 
@@ -1973,13 +2000,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();
        
@@ -1988,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()));
 }
 
 
@@ -2062,7 +2113,7 @@ vector<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
 
 TextClass const & GuiDocument::textClass() const
 {
-       return textclasslist[bp_.getBaseClass()];
+       return textclasslist[bp_.baseClass()];
 }