]> git.lyx.org Git - lyx.git/commitdiff
GUI for categorized text classes
authorJuergen Spitzmueller <spitz@lyx.org>
Tue, 9 Oct 2012 05:22:48 +0000 (07:22 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Tue, 9 Oct 2012 05:22:48 +0000 (07:22 +0200)
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiDocument.h
src/frontends/qt4/ui/LaTeXUi.ui

index b461aa691036faa30d9286b215e32c1648f4800a..73ece2e62f2264d276ed3c2fd7bac51ce8598459 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "GuiDocument.h"
 
+#include "CategorizedCombo.h"
 #include "GuiApplication.h"
 #include "GuiBranches.h"
 #include "GuiIndices.h"
@@ -40,6 +41,7 @@
 #include "LaTeXFeatures.h"
 #include "LaTeXFonts.h"
 #include "Layout.h"
+#include "LayoutEnums.h"
 #include "LayoutModuleList.h"
 #include "LyXRC.h"
 #include "ModuleList.h"
@@ -1260,7 +1262,6 @@ GuiDocument::GuiDocument(GuiView & lv)
                latexModule->psdriverCO->addItem(enc);
        }
        // latex classes
-       latexModule->classCO->setModel(&classes_model_);
        LayoutFileList const & bcl = LayoutFileList::get();
        vector<LayoutFileIndex> classList = bcl.classList();
        sort(classList.begin(), classList.end(), less_textclass_avail_desc());
@@ -1269,10 +1270,22 @@ GuiDocument::GuiDocument(GuiView & lv)
        vector<LayoutFileIndex>::const_iterator cen = classList.end();
        for (int i = 0; cit != cen; ++cit, ++i) {
                LayoutFile const & tc = bcl[*cit];
-               docstring item = (tc.isTeXClassAvailable()) ?
-                       from_utf8(tc.description()) :
-                       bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
-               classes_model_.insertRow(i, toqstr(item), *cit);
+               bool const available = tc.isTeXClassAvailable();
+               docstring const guiname = translateIfPossible(from_utf8(tc.description()));
+               // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
+               QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
+               if (!available) {
+                       docstring const output_type = (tc.outputType() == lyx::DOCBOOK) ? _("DocBook") : _("LaTeX");
+                       tooltip += '\n' + toqstr(wrap(bformat(_("Class not found by LyX. "
+                                                          "Please check if you have the matching %1$s class "
+                                                          "and all requires packages (%2$s) installed."),
+                                                        output_type, from_utf8(tc.prerequisites(", ")))));
+               }
+               latexModule->classCO->addItemSort(toqstr(tc.name()),
+                                                 toqstr(guiname),
+                                                 toqstr(translateIfPossible(from_utf8(tc.category()))),
+                                                 tooltip,
+                                                 true, true, true, available);
        }
 
 
@@ -2086,12 +2099,19 @@ void GuiDocument::browseLayout()
                return;
 
        // add to combo box
-       int idx = latexModule->classCO->findText(toqstr(name));
-       if (idx == -1) {
-               classes_model_.insertRow(0, toqstr(name), name);
-               latexModule->classCO->setCurrentIndex(0);
-       } else
-               latexModule->classCO->setCurrentIndex(idx);
+       bool const avail = latexModule->classCO->set(toqstr(name));
+       if (!avail) {
+               LayoutFile const & tc = bcl[name];
+               docstring const guiname = translateIfPossible(from_utf8(tc.description()));
+               // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
+               QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
+               tooltip += '\n' + qt_("This is a local layout file.");
+               latexModule->classCO->addItemSort(toqstr(tc.name()), toqstr(guiname),
+                                                 toqstr(translateIfPossible(from_utf8(tc.category()))),
+                                                 tooltip,
+                                                 true, true, true, true);
+               latexModule->classCO->set(toqstr(name));
+       }
 
        classChanged();
 }
@@ -2117,7 +2137,7 @@ void GuiDocument::classChanged()
        int idx = latexModule->classCO->currentIndex();
        if (idx < 0)
                return;
-       string const classname = classes_model_.getIDString(idx);
+       string const classname = fromqstr(latexModule->classCO->getData(idx));
 
        // check whether the selected modules have changed.
        bool modules_changed = false;
@@ -2442,7 +2462,7 @@ void GuiDocument::updateDefaultFormat()
        param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
        int const idx = latexModule->classCO->currentIndex();
        if (idx >= 0) {
-               string const classname = classes_model_.getIDString(idx);
+               string const classname = fromqstr(latexModule->classCO->getData(idx));
                param_copy.setBaseClass(classname);
                param_copy.makeDocumentClass();
        }
@@ -2586,7 +2606,7 @@ void GuiDocument::applyView()
        // text layout
        int idx = latexModule->classCO->currentIndex();
        if (idx >= 0) {
-               string const classname = classes_model_.getIDString(idx);
+               string const classname = fromqstr(latexModule->classCO->getData(idx));
                bp_.setBaseClass(classname);
        }
 
@@ -3456,7 +3476,7 @@ void GuiDocument::useClassDefaults()
        }
 
        int idx = latexModule->classCO->currentIndex();
-       string const classname = classes_model_.getIDString(idx);
+       string const classname = fromqstr(latexModule->classCO->getData(idx));
        if (!bp_.setBaseClass(classname)) {
                Alert::error(_("Error"), _("Unable to set document class."));
                return;
@@ -3468,12 +3488,9 @@ void GuiDocument::useClassDefaults()
 
 void GuiDocument::setLayoutComboByIDString(string const & idString)
 {
-       int idx = classes_model_.findIDString(idString);
-       if (idx < 0)
+       if (!latexModule->classCO->set(toqstr(idString)))
                Alert::warning(_("Can't set layout!"),
                        bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
-       else
-               latexModule->classCO->setCurrentIndex(idx);
 }
 
 
index 9b0345003358e0ed1fbfedd936f231701b21c9df..a84c5a500585eec6d0854120d19e37b6a9839a72 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "BufferParams.h"
 #include "BulletsModule.h"
+#include "CategorizedCombo.h"
 #include "GuiDialog.h"
 #include "GuiIdListModel.h"
 
@@ -47,6 +48,7 @@ class TextClass;
 
 namespace frontend {
 
+class CategorizedCombo;
 class FloatPlacement;
 class GuiBranches;
 class GuiIndices;
@@ -176,8 +178,6 @@ private:
        ///
        void setLayoutComboByIDString(std::string const & idString);
 
-       /// available classes
-       GuiIdListModel classes_model_;
        /// available modules
        GuiIdListModel modules_av_model_;
        /// selected modules
index 02520b9aa489db5c4c5c22cedac842836f54e871..34208109909d82fe892a9d64d284e78b596d955a 100644 (file)
@@ -26,7 +26,7 @@
        <number>6</number>
       </property>
       <item row="0" column="0">
-       <widget class="QComboBox" name="classCO">
+       <widget class="CategorizedCombo" name="classCO">
         <property name="maxVisibleItems">
          <number>20</number>
         </property>
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>CategorizedCombo</class>
+   <extends>QComboBox</extends>
+   <header>CategorizedCombo.h</header>
+  </customwidget>
+ </customwidgets>
  <tabstops>
   <tabstop>classCO</tabstop>
   <tabstop>layoutPB</tabstop>