mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Fix empty width support for Box inset
* InsetBox and GuiBox: Use proper empty length instead of the broken -9.99col% trick * some slight changes to the logic of GuiBox to make sure that values are set as needed. * lengthToWidget(): handle properly the empty length case. All the other related Qt helpers did it already, it was probably an oversight. Also set the default_unit parameter as optional (not needed in this patch actually, but I got carried away :) * allow generating LaTeX code for an empty length, since some broken code does that.
This commit is contained in:
parent
25ff2f8e2b
commit
f04c7711b0
@ -29,7 +29,7 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
|
||||
2013-03-22 Uwe Stöhr <uwestoehr@web.de>
|
||||
* Format incremented to 468: support for \mbox and \fbox
|
||||
New checkbox in the box dialog to avoid using an explicit
|
||||
width.
|
||||
width. An empty/missing length can be specified as "".
|
||||
|
||||
2013-03-19 Uwe Stöhr <uwestoehr@web.de>
|
||||
* Format incremented to 467: support for iwona fonts
|
||||
|
@ -4094,8 +4094,8 @@ def revert_mbox_fbox(document):
|
||||
continue
|
||||
BeginLayout = find_token(document.body, "\\begin_layout Plain Layout", j)
|
||||
EndLayout = find_token(document.body, "\\end_layout", BeginLayout)
|
||||
# replace if width is "-999col%"
|
||||
if (width == '"-999col%"'):
|
||||
# replace if width is ""
|
||||
if (width == '""'):
|
||||
document.body[EndLayout:k + 1] = put_cmd_in_ert("}")
|
||||
if document.body[i] == "\\begin_inset Box Frameless":
|
||||
document.body[i:BeginLayout + 1] = put_cmd_in_ert("\\mbox{")
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "LyXRC.h"
|
||||
|
||||
#include "support/docstream.h"
|
||||
#include "support/lassert.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
@ -106,8 +105,7 @@ string const Length::asLatexString() const
|
||||
os << val_ / 100.0 << "\\paperheight";
|
||||
break;
|
||||
case UNIT_NONE:
|
||||
// One should not try to ouput latex code for an empty length
|
||||
LASSERT(false, break);
|
||||
break;
|
||||
default:
|
||||
os << val_ << unit_name[unit_];
|
||||
break;
|
||||
|
@ -126,7 +126,7 @@ void GuiBox::on_innerBoxCO_activated(int /* index */)
|
||||
heightCB->setChecked(false);
|
||||
heightCB->setEnabled(ibox);
|
||||
// the width can only be selected for makebox or framebox
|
||||
widthCB->setEnabled(itype == "makebox"
|
||||
widthCB->setEnabled(itype == "makebox"
|
||||
|| (outer == "Boxed" && itype == "none"));
|
||||
widthCB->setChecked(itype != "none" && !widthCB->isEnabled());
|
||||
// except for frameless and boxed, the width cannot be specified if
|
||||
@ -175,12 +175,12 @@ void GuiBox::on_typeCO_activated(int index)
|
||||
setSpecial(ibox);
|
||||
}
|
||||
// the width can only be selected for makebox or framebox
|
||||
widthCB->setEnabled(itype == "makebox"
|
||||
widthCB->setEnabled(itype == "makebox"
|
||||
|| (type == "Boxed" && itype == "none"));
|
||||
widthCB->setChecked(itype != "none" && !widthCB->isEnabled());
|
||||
// except for frameless and boxed, the width cannot be specified if
|
||||
// there is no inner box
|
||||
bool const width_enabled =
|
||||
bool const width_enabled =
|
||||
itype != "none" || frameless || type == "Boxed";
|
||||
// enable if width_enabled, except if checkbaox is active but unset
|
||||
widthED->setEnabled(width_enabled || (widthCB->isEnabled() && widthCB->isChecked()));
|
||||
@ -305,16 +305,18 @@ void GuiBox::paramsToDialog(Inset const * inset)
|
||||
Length::UNIT const default_unit = Length::defaultUnit();
|
||||
|
||||
// the width can only be selected for makebox or framebox
|
||||
widthCB->setEnabled(inner_type == "makebox"
|
||||
|| (type == "Boxed" && !ibox && !pagebreakCB->isChecked()));
|
||||
// "-999col%" is the code for no width
|
||||
if ((params.width).asString() == "-999col%")
|
||||
widthCB->setCheckState(Qt::Unchecked);
|
||||
else {
|
||||
widthCB->setEnabled(inner_type == "makebox"
|
||||
|| (type == "Boxed"
|
||||
&& !ibox && !pagebreakCB->isChecked()));
|
||||
if (params.width.empty()) {
|
||||
widthCB->setChecked(false);
|
||||
lengthToWidgets(widthED, widthUnitsLC,
|
||||
params.width, default_unit);
|
||||
} else {
|
||||
if (widthCB->isEnabled())
|
||||
widthCB->setChecked(true);
|
||||
lengthToWidgets(widthED, widthUnitsLC,
|
||||
(params.width).asString(), default_unit);
|
||||
params.width, default_unit);
|
||||
QString const special = toqstr(params.special);
|
||||
if (!special.isEmpty() && special != "none")
|
||||
widthUnitsLC->setCurrentItem(special);
|
||||
@ -325,7 +327,7 @@ void GuiBox::paramsToDialog(Inset const * inset)
|
||||
|
||||
lengthToWidgets(heightED, heightUnitsLC,
|
||||
(params.height).asString(), default_unit);
|
||||
|
||||
|
||||
QString const height_special = toqstr(params.height_special);
|
||||
if (!height_special.isEmpty() && height_special != "none")
|
||||
heightUnitsLC->setCurrentItem(height_special);
|
||||
@ -369,21 +371,18 @@ docstring GuiBox::dialogToParams() const
|
||||
widthUnitsLC->itemData(widthUnitsLC->currentIndex()).toString();
|
||||
QString value = widthED->text();
|
||||
|
||||
if (widthCB->isChecked()) {
|
||||
if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
|
||||
params.special = fromqstr(unit);
|
||||
// Note: the unit is simply ignored in this case
|
||||
params.width = Length(value.toDouble(), Length::IN);
|
||||
} else {
|
||||
params.special = "none";
|
||||
params.width = Length(widgetsToLength(widthED, widthUnitsLC));
|
||||
}
|
||||
} else {
|
||||
if (widthCB->isEnabled()) {
|
||||
// use the code "-999col%" for the case that no width was selected
|
||||
if (widthED->isEnabled()) {
|
||||
if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
|
||||
params.special = fromqstr(unit);
|
||||
// Note: the unit is simply ignored in this case
|
||||
params.width = Length(value.toDouble(), Length::IN);
|
||||
} else {
|
||||
params.special = "none";
|
||||
params.width = Length("-999col%");
|
||||
params.width = Length(widgetsToLength(widthED, widthUnitsLC));
|
||||
}
|
||||
} else {
|
||||
params.special = "none";
|
||||
params.width = Length();
|
||||
}
|
||||
|
||||
// the height parameter is omitted if the value
|
||||
|
@ -118,12 +118,18 @@ Length widgetsToLength(QLineEdit const * input, QComboBox const * combo)
|
||||
|
||||
|
||||
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||
Length const & len, Length::UNIT /*defaultUnit*/)
|
||||
Length const & len, Length::UNIT /*defaultUnit*/)
|
||||
{
|
||||
combo->setCurrentItem(len.unit());
|
||||
QLocale loc;
|
||||
loc.setNumberOptions(QLocale::OmitGroupSeparator);
|
||||
input->setText(loc.toString(Length(len).value()));
|
||||
if (len.empty()) {
|
||||
// no length (UNIT_NONE)
|
||||
combo->setCurrentItem(Length::defaultUnit());
|
||||
input->setText("");
|
||||
} else {
|
||||
combo->setCurrentItem(len.unit());
|
||||
QLocale loc;
|
||||
loc.setNumberOptions(QLocale::OmitGroupSeparator);
|
||||
input->setText(loc.toString(Length(len).value()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -156,7 +162,7 @@ double widgetToDouble(QLineEdit const * input)
|
||||
QString const text = input->text();
|
||||
if (text.isEmpty())
|
||||
return 0.0;
|
||||
|
||||
|
||||
return text.trimmed().toDouble();
|
||||
}
|
||||
|
||||
@ -166,7 +172,7 @@ string widgetToDoubleStr(QLineEdit const * input)
|
||||
QString const text = input->text();
|
||||
if (text.isEmpty())
|
||||
return string();
|
||||
|
||||
|
||||
return convert<string>(text.trimmed().toDouble());
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ namespace lyx {
|
||||
namespace support { class FileName; }
|
||||
|
||||
class BufferParams;
|
||||
|
||||
|
||||
namespace frontend {
|
||||
|
||||
class LengthCombo;
|
||||
@ -41,13 +41,17 @@ std::string widgetsToLength(QLineEdit const * input, LengthCombo const * combo);
|
||||
/// method to get a Length from widgets (QComboBox)
|
||||
Length widgetsToLength(QLineEdit const * input, QComboBox const * combo);
|
||||
|
||||
//FIXME It would be nice if defaultUnit were a default argument
|
||||
/// method to set widgets from a Length
|
||||
//FIXME Remove default_unit argument for the first form. FIXME Change
|
||||
// all the code to remove default_unit argument when equal to the
|
||||
// default.
|
||||
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||
Length const & len, Length::UNIT default_unit);
|
||||
Length const & len,
|
||||
Length::UNIT default_unit = Length::defaultUnit());
|
||||
/// method to set widgets from a string
|
||||
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||
std::string const & len, Length::UNIT default_unit);
|
||||
std::string const & len,
|
||||
Length::UNIT default_unit = Length::defaultUnit());
|
||||
/// method to set widgets from a docstring
|
||||
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||
docstring const & len, Length::UNIT default_unit);
|
||||
|
@ -162,7 +162,7 @@ void InsetBox::setButtonLabel()
|
||||
|
||||
bool InsetBox::hasFixedWidth() const
|
||||
{
|
||||
return from_ascii(params_.width.asLatexString()) != "-9.99\\columnwidth";
|
||||
return !params_.width.empty();
|
||||
}
|
||||
|
||||
|
||||
@ -273,6 +273,7 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const
|
||||
|
||||
string width_string = params_.width.asLatexString();
|
||||
bool stdwidth = false;
|
||||
// FIXME: do not test explicitely values of width_string
|
||||
if (params_.inner_box &&
|
||||
(width_string.find("1.0\\columnwidth") != string::npos
|
||||
|| width_string.find("1.0\\textwidth") != string::npos)) {
|
||||
@ -316,8 +317,7 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const
|
||||
os << "\\begin{framed}%\n";
|
||||
break;
|
||||
case Boxed:
|
||||
// "-999col%" is the code for no width
|
||||
if (from_ascii(width_string) != "-9.99\\columnwidth") {
|
||||
if (width_string.empty()) {
|
||||
os << "\\framebox";
|
||||
if (!params_.inner_box) {
|
||||
// Special widths, see usrguide sec. 3.5
|
||||
@ -358,8 +358,7 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const
|
||||
if (params_.use_parbox)
|
||||
os << "\\parbox";
|
||||
else if (params_.use_makebox) {
|
||||
// "-999col%" is the code for no width
|
||||
if (from_ascii(width_string) != "-9.99\\columnwidth") {
|
||||
if (!width_string.empty()) {
|
||||
os << "\\makebox";
|
||||
// FIXME UNICODE
|
||||
// output the width and horizontal position
|
||||
|
@ -935,9 +935,8 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
|
||||
width_unit = "in";
|
||||
width_special = "width";
|
||||
} else if (latex_width.empty() && outer_type == "framebox") {
|
||||
outer_type == "fbox";
|
||||
width_value = "-999";
|
||||
width_unit = "col%";
|
||||
width_value.clear();
|
||||
width_unit.clear();
|
||||
width_special = "none";
|
||||
}
|
||||
if (use_ert) {
|
||||
@ -1038,7 +1037,7 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
|
||||
else
|
||||
os << "use_makebox " << (inner_type == "makebox") << '\n';
|
||||
if (outer_type == "fbox" || outer_type == "mbox")
|
||||
os << "width \"-999col%\"\n";
|
||||
os << "width \"\"\n";
|
||||
else
|
||||
os << "width \"" << width_value << width_unit << "\"\n";
|
||||
os << "special \"" << width_special << "\"\n";
|
||||
|
Loading…
Reference in New Issue
Block a user