Improve math packages GUI

This commit is contained in:
Juergen Spitzmueller 2013-03-01 15:59:37 +01:00
parent cc0c3d0427
commit e53b5972c3
4 changed files with 139 additions and 119 deletions

View File

@ -443,21 +443,31 @@ void BufferParams::use_package(std::string const & p, BufferParams::Package u)
} }
vector<string> const & BufferParams::auto_packages() map<string, string> const & BufferParams::auto_packages()
{ {
static vector<string> packages; static map<string, string> packages;
if (packages.empty()) { if (packages.empty()) {
// adding a package here implies a file format change! // adding a package here implies a file format change!
packages.push_back("amsmath"); packages["amsmath"] =
packages.push_back("amssymb"); N_("The LaTeX package amsmath is only used if AMS formula types or symbols from the AMS math toolbars are inserted into formulas");
packages.push_back("cancel"); packages["amssymb"] =
packages.push_back("esint"); N_("The LaTeX package amssymb is only used if symbols from the AMS math toolbars are inserted into formulas");
packages.push_back("mathdots"); packages["cancel"] =
packages.push_back("mathtools"); N_("The LaTeX package cancel is only used if \\cancel commands are used in formulas");
packages.push_back("mhchem"); packages["esint"] =
packages.push_back("stackrel"); N_("The LaTeX package esint is only used if special integral symbols are inserted into formulas");
packages.push_back("stmaryrd"); packages["mathdots"] =
packages.push_back("undertilde"); N_("The LaTeX package mathdots is only used if the command \\iddots is inserted into formulas");
packages["mathtools"] =
N_("The LaTeX package mathtools is only used if some mathematical relations are inserted into formulas");
packages["mhchem"] =
N_("The LaTeX package mhchem is only used if either the command \\ce or \\cf is inserted into formulas");
packages["stackrel"] =
N_("The LaTeX package stackrel is only used if the command \\stackrel with subscript is inserted into formulas");
packages["stmaryrd"] =
N_("The LaTeX package stmaryrd is only used if symbols from the St Mary's Road symbol font for theoretical computer science are inserted into formulas");
packages["undertilde"] =
N_("The LaTeX package undertilde is only used if you use the math frame decoration 'utilde'");
} }
return packages; return packages;
} }
@ -1026,10 +1036,11 @@ void BufferParams::writeFile(ostream & os) const
os << "\\papersize " << string_papersize[papersize] os << "\\papersize " << string_papersize[papersize]
<< "\n\\use_geometry " << convert<string>(use_geometry); << "\n\\use_geometry " << convert<string>(use_geometry);
vector<string> const & packages = auto_packages(); map<string, string> const & packages = auto_packages();
for (size_t i = 0; i < packages.size(); ++i) for (map<string, string>::const_iterator it = packages.begin();
os << "\n\\use_package " << packages[i] << ' ' it != packages.end(); ++it)
<< use_package(packages[i]); os << "\n\\use_package " << it->first << ' '
<< use_package(it->first);
os << "\n\\cite_engine "; os << "\n\\cite_engine ";

View File

@ -361,7 +361,7 @@ public:
/// Set whether to load a package such as amsmath or esint. /// Set whether to load a package such as amsmath or esint.
void use_package(std::string const & p, Package u); void use_package(std::string const & p, Package u);
/// All packages that can be switched on or off /// All packages that can be switched on or off
static std::vector<std::string> const & auto_packages(); static std::map<std::string, std::string> const & auto_packages();
/// Split bibliography? /// Split bibliography?
bool use_bibtopic; bool use_bibtopic;
/// Split the index? /// Split the index?

View File

@ -130,52 +130,6 @@ char const * backref_opts_gui[] =
}; };
char const * packages_gui[][4] =
{
{"amsmath",
N_("&Use amsmath package automatically"),
N_("Use ams&math package"),
N_("The LaTeX package amsmath is only used if AMS formula types or symbols from the AMS math toolbars are inserted into formulas")},
{"amssymb",
N_("&Use amssymb package automatically"),
N_("Use amssymb package"),
N_("The LaTeX package amssymb is only used if symbols from the AMS math toolbars are inserted into formulas")},
{"cancel",
N_("Use cancel package automatically"),
N_("Use cancel package"),
N_("The LaTeX package cancel is only used if \\cancel commands are used in formulas")},
{"esint",
N_("Use esint package &automatically"),
N_("Use &esint package"),
N_("The LaTeX package esint is only used if special integral symbols are inserted into formulas")},
{"mathdots",
N_("Use math&dots package automatically"),
N_("Use mathdo&ts package"),
N_("The LaTeX package mathdots is only used if the command \\iddots is inserted into formulas")},
{"mathtools",
N_("Use mathtools package automatically"),
N_("Use mathtools package"),
N_("The LaTeX package mathtools is only used if some mathematical relations are inserted into formulas")},
{"mhchem",
N_("Use mhchem &package automatically"),
N_("Use mh&chem package"),
N_("The LaTeX package mhchem is only used if either the command \\ce or \\cf is inserted into formulas")},
{"stackrel",
N_("Use stackrel package automatically"),
N_("Use stackrel package"),
N_("The LaTeX package stackrel is only used if the command \\stackrel with subscript is inserted into formulas")},
{"stmaryrd",
N_("Use stmaryrd package automatically"),
N_("Use stmaryrd package"),
N_("The LaTeX package stmaryrd is only used if symbols from the St Mary's Road symbol font for theoretical computer science are inserted into formulas")},
{"undertilde",
N_("Use u&ndertilde package automatically"),
N_("Use undertilde pac&kage"),
N_("The LaTeX package undertilde is only used if you use the math frame decoration 'utilde'")},
{"", "", "", ""}
};
vector<string> engine_types_; vector<string> engine_types_;
vector<pair<string, QString> > pagestyles; vector<pair<string, QString> > pagestyles;
@ -1195,49 +1149,59 @@ GuiDocument::GuiDocument(GuiView & lv)
// maths // maths
// FIXME This UI has problems:
// 1) It is not generic, packages_gui needs to be changed for each new package
// 2) Two checkboxes have 4 states, but one is invalid (both pressed)
// 3) The auto cb is not disabled if the use cb is checked
mathsModule = new UiWidget<Ui::MathsUi>; mathsModule = new UiWidget<Ui::MathsUi>;
vector<string> const & packages = BufferParams::auto_packages(); QStringList headers;
for (size_t i = 0; i < packages.size(); ++i) { headers << qt_("Package") << qt_("Load automatically")
// Use the order of BufferParams::auto_packages() for easier << qt_("Load always") << qt_("Do not load");
// access in applyView() and paramsToDialog() mathsModule->packagesTW->setHorizontalHeaderLabels(headers);
int n = 0; mathsModule->packagesTW->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
for (n = 0; packages_gui[n][0][0]; n++) map<string, string> const & packages = BufferParams::auto_packages();
if (packages_gui[n][0] == packages[i]) mathsModule->packagesTW->setRowCount(packages.size());
break; int i = 0;
// If this fires somebody changed for (map<string, string>::const_iterator it = packages.begin();
// BufferParams::auto_packages() without adjusting packages_gui it != packages.end(); ++it) {
LASSERT(packages_gui[n][0][0], /**/); docstring const package = from_ascii(it->first);
QString autoText = qt_(packages_gui[n][1]); QString autoTooltip = qt_(it->second);
QString alwaysText = qt_(packages_gui[n][2]);
QString autoTooltip = qt_(packages_gui[n][3]);
QString alwaysTooltip; QString alwaysTooltip;
if (packages[i] == "amsmath") if (package == "amsmath")
alwaysTooltip = alwaysTooltip =
qt_("The AMS LaTeX packages are always used"); qt_("The AMS LaTeX packages are always used");
else else
alwaysTooltip = toqstr(bformat( alwaysTooltip = toqstr(bformat(
_("The LaTeX package %1$s is always used"), _("The LaTeX package %1$s is always used"),
from_ascii(packages[i]))); package));
QCheckBox * autoCB = new QCheckBox(autoText, mathsModule); QString neverTooltip;
QCheckBox * alwaysCB = new QCheckBox(alwaysText, mathsModule); if (package == "amsmath")
mathsModule->gridLayout->addWidget(autoCB, 2 * i, 0); neverTooltip =
mathsModule->gridLayout->addWidget(alwaysCB, 2 * i + 1, 0); qt_("The AMS LaTeX packages are never used");
autoCB->setToolTip(autoTooltip); else
alwaysCB->setToolTip(alwaysTooltip); neverTooltip = toqstr(bformat(
connect(autoCB, SIGNAL(toggled(bool)), _("The LaTeX package %1$s is never used"),
alwaysCB, SLOT(setDisabled(bool))); package));
connect(autoCB, SIGNAL(clicked()), QRadioButton * autoRB = new QRadioButton(mathsModule);
QRadioButton * alwaysRB = new QRadioButton(mathsModule);
QRadioButton * neverRB = new QRadioButton(mathsModule);
QButtonGroup * packageGroup = new QButtonGroup(mathsModule);
packageGroup->addButton(autoRB);
packageGroup->addButton(alwaysRB);
packageGroup->addButton(neverRB);
autoRB->setToolTip(autoTooltip);
alwaysRB->setToolTip(alwaysTooltip);
neverRB->setToolTip(neverTooltip);
QTableWidgetItem * pack = new QTableWidgetItem(toqstr(package));
mathsModule->packagesTW->setItem(i, 0, pack);
mathsModule->packagesTW->setCellWidget(i, 1, autoRB);
mathsModule->packagesTW->setCellWidget(i, 2, alwaysRB);
mathsModule->packagesTW->setCellWidget(i, 3, neverRB);
connect(autoRB, SIGNAL(clicked()),
this, SLOT(change_adaptor())); this, SLOT(change_adaptor()));
connect(alwaysCB, SIGNAL(clicked()), connect(alwaysRB, SIGNAL(clicked()),
this, SLOT(change_adaptor())); this, SLOT(change_adaptor()));
connect(neverRB, SIGNAL(clicked()),
this, SLOT(change_adaptor()));
++i;
} }
QSpacerItem * spacer = new QSpacerItem(20, 20, QSizePolicy::Minimum,
QSizePolicy::Expanding);
mathsModule->gridLayout->addItem(spacer, 2 * packages.size(), 0);
// latex class // latex class
@ -2653,20 +2617,26 @@ void GuiDocument::applyView()
modulesToParams(bp_); modulesToParams(bp_);
// Math // Math
vector<string> const & packages = BufferParams::auto_packages(); map<string, string> const & packages = BufferParams::auto_packages();
for (size_t n = 0; n < packages.size(); ++n) { for (map<string, string>::const_iterator it = packages.begin();
QCheckBox * autoCB = static_cast<QCheckBox *>( it != packages.end(); ++it) {
mathsModule->gridLayout->itemAtPosition(2 * n, 0)->widget()); QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
if (autoCB->isChecked()) if (!item)
bp_.use_package(packages[n], BufferParams::package_auto); continue;
else { int row = mathsModule->packagesTW->row(item);
QCheckBox * alwaysCB = static_cast<QCheckBox *>( QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1);
mathsModule->gridLayout->itemAtPosition(2 * n + 1, 0)->widget()); if (rb->isChecked()) {
if (alwaysCB->isChecked()) bp_.use_package(it->first, BufferParams::package_auto);
bp_.use_package(packages[n], BufferParams::package_on); continue;
else
bp_.use_package(packages[n], BufferParams::package_off);
} }
rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2);
if (rb->isChecked()) {
bp_.use_package(it->first, BufferParams::package_on);
continue;
}
rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3);
if (rb->isChecked())
bp_.use_package(it->first, BufferParams::package_off);
} }
// Page Layout // Page Layout
@ -3078,14 +3048,30 @@ void GuiDocument::paramsToDialog()
latexModule->psdriverCO->setCurrentIndex(nitem); latexModule->psdriverCO->setCurrentIndex(nitem);
updateModuleInfo(); updateModuleInfo();
vector<string> const & packages = BufferParams::auto_packages(); map<string, string> const & packages = BufferParams::auto_packages();
for (size_t n = 0; n < packages.size(); ++n) { for (map<string, string>::const_iterator it = packages.begin();
QCheckBox * alwaysCB = static_cast<QCheckBox *>( it != packages.end(); ++it) {
mathsModule->gridLayout->itemAtPosition(2 * n + 1, 0)->widget()); QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
alwaysCB->setChecked(bp_.use_package(packages[n]) == BufferParams::package_on); if (!item)
QCheckBox * autoCB = static_cast<QCheckBox *>( continue;
mathsModule->gridLayout->itemAtPosition(2 * n, 0)->widget()); int row = mathsModule->packagesTW->row(item);
autoCB->setChecked(bp_.use_package(packages[n]) == BufferParams::package_auto); switch (bp_.use_package(it->first)) {
case BufferParams::package_off: {
QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3);
rb->setChecked(true);
break;
}
case BufferParams::package_on: {
QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2);
rb->setChecked(true);
break;
}
case BufferParams::package_auto: {
QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1);
rb->setChecked(true);
break;
}
}
} }
switch (bp_.spacing().getSpace()) { switch (bp_.spacing().getSpace()) {

View File

@ -6,14 +6,37 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>351</width> <width>432</width>
<height>261</height> <height>291</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string/> <string/>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QTableWidget" name="packagesTW">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="columnCount">
<number>4</number>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column/>
<column/>
<column/>
<column/>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<includes> <includes>