]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt/GuiDocument.cpp
Disable bookmarksopenlevel SL when bookmarksopen is false
[lyx.git] / src / frontends / qt / GuiDocument.cpp
index d08a648375b615c86bb9b3e1357194fe546b13d1..32cc899dc25306c12f4022d117c6897a0d0f23d3 100644 (file)
@@ -162,22 +162,21 @@ enum EncodingSets {
        custom = 2
 };
 
-} // anonymous namespace
-
-namespace lyx {
-
-RGBColor set_backgroundcolor;
+lyx::RGBColor set_backgroundcolor;
 bool is_backgroundcolor;
-RGBColor set_fontcolor;
+lyx::RGBColor set_fontcolor;
 bool is_fontcolor;
-RGBColor set_notefontcolor;
-RGBColor set_boxbgcolor;
+lyx::RGBColor set_notefontcolor;
+lyx::RGBColor set_boxbgcolor;
 bool forced_fontspec_activation;
 
+} // anonymous namespace
+
+namespace lyx {
+
 namespace {
 // used when sorting the textclass list.
 class less_textclass_avail_desc
-       : public binary_function<string, string, int>
 {
 public:
        bool operator()(string const & lhs, string const & rhs) const
@@ -269,17 +268,17 @@ class ModuleSelectionManager : public GuiSelectionManager
 public:
        ///
        ModuleSelectionManager(QObject * parent,
-                              QTreeView * availableLV,
-                              QTreeView * selectedLV,
-                              QPushButton * addPB,
-                              QPushButton * delPB,
-                              QPushButton * upPB,
-                              QPushButton * downPB,
-                              QStandardItemModel * availableModel,
-                              GuiIdListModel * selectedModel,
+                                                  QTreeView * availableLVarg,
+                                                  QTreeView * selectedLVarg,
+                                                  QPushButton * addPBarg,
+                                                  QPushButton * delPBarg,
+                                                  QPushButton * upPBarg,
+                                                  QPushButton * downPBarg,
+                                                  QStandardItemModel * availableModelarg,
+                                                  GuiIdListModel * selectedModelarg,
                               GuiDocument const * container)
-               : GuiSelectionManager(parent, availableLV, selectedLV, addPB, delPB,
-                                     upPB, downPB, availableModel, selectedModel),
+               : GuiSelectionManager(parent, availableLVarg, selectedLVarg, addPBarg, delPBarg,
+                                                         upPBarg, downPBarg, availableModelarg, selectedModelarg),
                  container_(container)
                {}
        ///
@@ -477,7 +476,7 @@ void ModuleSelectionManager::updateDelPB()
 /////////////////////////////////////////////////////////////////////
 
 PreambleModule::PreambleModule(QWidget * parent)
-       : UiWidget<Ui::PreambleUi>(parent), current_id_(0)
+       : UiWidget<Ui::PreambleUi>(parent), current_id_(nullptr)
 {
        // This is not a memory leak. The object will be destroyed
        // with this.
@@ -495,7 +494,13 @@ PreambleModule::PreambleModule(QWidget * parent)
        // https://stackoverflow.com/questions/13027091/how-to-override-tab-width-in-qt
        const int tabStop = 4;
        QFontMetrics metrics(preambleTE->currentFont());
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
+       // horizontalAdvance() is available starting in 5.11.0
+       // setTabStopDistance() is available starting in 5.10.0
+       preambleTE->setTabStopDistance(tabStop * metrics.horizontalAdvance(' '));
+#else
        preambleTE->setTabStopWidth(tabStop * metrics.width(' '));
+#endif
 }
 
 
@@ -602,7 +607,7 @@ void PreambleModule::editExternal() {
 
 
 LocalLayout::LocalLayout(QWidget * parent)
-       : UiWidget<Ui::LocalLayoutUi>(parent), current_id_(0), validated_(false)
+       : UiWidget<Ui::LocalLayoutUi>(parent), current_id_(nullptr), validated_(false)
 {
        locallayoutTE->setFont(guiApp->typewriterSystemFont());
        locallayoutTE->setWordWrapMode(QTextOption::NoWrap);
@@ -883,19 +888,27 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
                masterChildModule->childrenTW, SLOT(setEnabled(bool)));
        connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
-               masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
+               masterChildModule->maintainGB, SLOT(setEnabled(bool)));
        connect(masterChildModule->includeallRB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
        connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
-       connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
+       connect(masterChildModule->maintainCRNoneRB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(masterChildModule->maintainCRMostlyRB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(masterChildModule->maintainCRStrictRB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
        masterChildModule->childrenTW->setColumnCount(2);
        masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
        masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
-       masterChildModule->childrenTW->resizeColumnToContents(1);
-       masterChildModule->childrenTW->resizeColumnToContents(2);
-
+#if (QT_VERSION > 0x050000)
+        masterChildModule->childrenTW->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
+        masterChildModule->childrenTW->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
+#else
+        masterChildModule->childrenTW->header()->setResizeMode(0, QHeaderView::ResizeToContents);
+        masterChildModule->childrenTW->header()->setResizeMode(1, QHeaderView::ResizeToContents);
+#endif
 
        // Formats
        outputModule = new UiWidget<Ui::OutputUi>(this);
@@ -1683,6 +1696,8 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
                this, SLOT(change_adaptor()));
+       connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
+               this, SLOT(bookmarksopenChanged(bool)));
        connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
                this, SLOT(change_adaptor()));
        connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
@@ -1806,6 +1821,12 @@ void GuiDocument::shellescapeChanged()
        changed();
 }
 
+void GuiDocument::bookmarksopenChanged(bool state)
+{
+       pdfSupportModule->bookmarksopenlevelSB->setEnabled(state);
+       pdfSupportModule->bookmarksopenlevelLA->setEnabled(state);
+}
+
 
 void GuiDocument::slotApply()
 {
@@ -1911,7 +1932,7 @@ void GuiDocument::resetModuleFilter()
 
 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
 {
-       if (item == 0)
+       if (item == nullptr)
                return;
 
        string child = fromqstr(item->text(0));
@@ -1951,13 +1972,13 @@ void GuiDocument::setListingsMessage()
                if (isOK)
                        return;
                isOK = true;
-               // listingsTB->setTextColor("black");
+               // listingsModule->listingsTB->setTextColor("black");
                listingsModule->listingsTB->setPlainText(
                        qt_("Input listings parameters below. "
                            "Enter ? for a list of parameters."));
        } else {
                isOK = false;
-               // listingsTB->setTextColor("red");
+               // listingsModule->listingsTB->setTextColor("red");
                listingsModule->listingsTB->setPlainText(msg);
        }
 }
@@ -2270,7 +2291,7 @@ void GuiDocument::languageChanged(int i)
        Language const * lang = lyx::languages.getLanguage(
                fromqstr(langModule->languageCO->itemData(i).toString()));
        if (lang->babel().empty() && !lang->polyglossia().empty()
-               && lang->requires() != "CJK" && lang->requires() != "japanese") {
+               && lang->required() != "CJK" && lang->required() != "japanese") {
                        // If we force to switch fontspec on, store
                        // current state (#8717)
                        if (fontModule->osFontsCB->isEnabled())
@@ -2967,8 +2988,8 @@ void GuiDocument::updateEngineDependends()
                                biblioModule->citeEngineCO->currentIndex()).toString();
        LyXCiteEngine const * ce = theCiteEnginesList[fromqstr(engine)];
 
-       bool const citepack = ce->requires("biblatex.sty") || ce->requires("jurabib.sty")
-                       || ce->requires("natbib.sty");
+       bool const citepack = ce->required("biblatex.sty") || ce->required("jurabib.sty")
+                       || ce->required("natbib.sty");
        biblioModule->citePackageOptionsLE->setEnabled(citepack);
        biblioModule->citePackageOptionsL->setEnabled(citepack);
 }
@@ -3243,7 +3264,7 @@ void GuiDocument::updateNumbering()
        int const toc = numberingModule->tocSL->value();
        QString const no = qt_("No");
        QString const yes = qt_("Yes");
-       QTreeWidgetItem * item = 0;
+       QTreeWidgetItem * item = nullptr;
 
        DocumentClass::const_iterator lit = tclass.begin();
        DocumentClass::const_iterator len = tclass.end();
@@ -3638,8 +3659,16 @@ void GuiDocument::applyView()
                        bp_.addIncludedChildren(*it);
                }
        }
-       bp_.maintain_unincluded_children =
-               masterChildModule->maintainAuxCB->isChecked();
+       if (masterChildModule->maintainCRNoneRB->isChecked())
+               bp_.maintain_unincluded_children =
+                       BufferParams::CM_None;
+       else if (masterChildModule->maintainCRMostlyRB->isChecked())
+               bp_.maintain_unincluded_children =
+                       BufferParams::CM_Mostly;
+       else
+               bp_.maintain_unincluded_children =
+                       BufferParams::CM_Strict;
+       updateIncludeonlyDisplay();
 
        // Float Settings
        bp_.float_placement = floatModule->getPlacement();
@@ -4168,9 +4197,20 @@ void GuiDocument::paramsToDialog()
                masterChildModule->setEnabled(true);
                includeonlys_ = bp_.getIncludedChildren();
                updateIncludeonlys();
+               updateIncludeonlyDisplay();
+       }
+       switch (bp_.maintain_unincluded_children) {
+       case BufferParams::CM_None:
+               masterChildModule->maintainCRNoneRB->setChecked(true);
+               break;
+       case BufferParams::CM_Mostly:
+               masterChildModule->maintainCRMostlyRB->setChecked(true);
+               break;
+       case BufferParams::CM_Strict:
+       default:
+               masterChildModule->maintainCRStrictRB->setChecked(true);
+               break;
        }
-       masterChildModule->maintainAuxCB->setChecked(
-               bp_.maintain_unincluded_children);
 
        // Float Settings
        floatModule->setPlacement(bp_.float_placement);
@@ -4192,7 +4232,7 @@ void GuiDocument::paramsToDialog()
                        langModule->languageCO->currentIndex()).toString()));
        bool const need_fontspec =
                lang->babel().empty() && !lang->polyglossia().empty()
-               && lang->requires() != "CJK" && lang->requires() != "japanese";
+               && lang->required() != "CJK" && lang->required() != "japanese";
        bool const os_fonts_available =
                bp_.baseClass()->outputType() == lyx::LATEX
                && LaTeXFeatures::isAvailable("fontspec");
@@ -4403,6 +4443,8 @@ void GuiDocument::paramsToDialog()
        pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
 
        pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
+       pdfSupportModule->bookmarksopenlevelSB->setEnabled(pdf.bookmarksopen);
+       pdfSupportModule->bookmarksopenlevelLA->setEnabled(pdf.bookmarksopen);
 
        pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
        pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
@@ -4463,12 +4505,13 @@ void GuiDocument::updateAvailableModules()
        unavbrush.setColor(Qt::gray);
        for (modInfoStruct const & m : modInfoList) {
                QStandardItem * item = new QStandardItem();
-               QStandardItem * catItem = new QStandardItem();
+               QStandardItem * catItem;
                QString const catname = m.category;
                QList<QStandardItem *> fcats = modules_av_model_.findItems(catname, Qt::MatchExactly);
                if (!fcats.empty())
                        catItem = fcats.first();
                else {
+                       catItem = new QStandardItem();
                        catItem->setText(catname);
                        catItem->setFont(catfont);
                        modules_av_model_.insertRow(i, catItem);
@@ -4503,21 +4546,26 @@ void GuiDocument::updateSelectedModules()
 }
 
 
-void GuiDocument::updateIncludeonlys()
+void GuiDocument::updateIncludeonlyDisplay()
 {
-       masterChildModule->childrenTW->clear();
-       QString const no = qt_("No");
-       QString const yes = qt_("Yes");
-
        if (includeonlys_.empty()) {
                masterChildModule->includeallRB->setChecked(true);
                masterChildModule->childrenTW->setEnabled(false);
-               masterChildModule->maintainAuxCB->setEnabled(false);
+               masterChildModule->maintainGB->setEnabled(false);
        } else {
                masterChildModule->includeonlyRB->setChecked(true);
                masterChildModule->childrenTW->setEnabled(true);
-               masterChildModule->maintainAuxCB->setEnabled(true);
+               masterChildModule->maintainGB->setEnabled(true);
        }
+}
+
+
+void GuiDocument::updateIncludeonlys()
+{
+       masterChildModule->childrenTW->clear();
+       QString const no = qt_("No");
+       QString const yes = qt_("Yes");
+
        ListOfBuffers children = buffer().getChildren();
        ListOfBuffers::const_iterator it  = children.begin();
        ListOfBuffers::const_iterator end = children.end();
@@ -4536,17 +4584,10 @@ void GuiDocument::updateIncludeonlys()
                else
                        all_unincluded = false;
        }
-       // Both if all childs are included and if none is included
+       // Both if all children are included and if none is included
        // is equal to "include all" (i.e., omit \includeonly).
-       // Thus, reset the GUI.
-       if (!has_unincluded || all_unincluded) {
-               masterChildModule->includeallRB->setChecked(true);
-               masterChildModule->childrenTW->setEnabled(false);
+       if (!has_unincluded || all_unincluded)
                includeonlys_.clear();
-       }
-       // If all are included, we need to update again.
-       if (!has_unincluded)
-               updateIncludeonlys();
 }
 
 
@@ -4815,7 +4856,7 @@ void GuiDocument::clearParams()
 BufferId GuiDocument::id() const
 {
        BufferView const * const view = bufferview();
-       return view? &view->buffer() : 0;
+       return view? &view->buffer() : nullptr;
 }