For an unknown reason LyX supports \framebox and \makebox only _with_ command options. \framebox{}
and \makebox{} (which is the same as \fbox{} and \mbox{}) are not supported.
Support for them would be very useful because one often has the case that one wants to simply draw a
box around a single word or phrase and for that purpose you cannot use \framebox with options.
The attached patch adds support for \fbox and \mbox.
I have there used a hack where I code the case of no option to the length "-999col%". This works but
I am not happy with this. There must be a way to omit specifying a length but I can't figure out
how. Any help is highly appreciated.
(The patch would be a fileformat change.)
thanks and regards
Uwe
src/frontends/qt4/GuiBox.cpp | 76 ++++++++----
src/frontends/qt4/GuiBox.h | 1 +
src/frontends/qt4/ui/BoxUi.ui | 266 +++++++++++++++++++++++------------------
src/insets/InsetBox.cpp | 58 +++++----
4 files changed, 236 insertions(+), 165 deletions(-)
diff --git a/src/frontends/qt4/GuiBox.cpp b/src/frontends/qt4/GuiBox.cpp
index c4ddeed..bf98683 100644
--- a/src/frontends/qt4/GuiBox.cpp
+++ b/src/frontends/qt4/GuiBox.cpp
@@ -103,7 +103,7 @@ GuiBox::GuiBox(QWidget * parent) : InsetParamsWidget(parent)
widthED->setValidator(unsignedLengthValidator(widthED));
// initialize the length validator
- addCheckedWidget(widthED, widthLA);
+ addCheckedWidget(widthED, widthCB);
addCheckedWidget(heightED, heightCB);
initDialog();
@@ -125,12 +125,17 @@ void GuiBox::on_innerBoxCO_activated(int /* index */)
if (heightCB->isChecked() && !ibox)
heightCB->setChecked(false);
heightCB->setEnabled(ibox);
+ // the width can only be selected for makebox or framebox
+ widthCB->setEnabled(itype == "makebox"
+ || (outer == "Boxed" && itype == "none"));
+ if (!widthCB->isEnabled())
+ widthCB->setCheckState(Qt::Checked);
// except for frameless and boxed, the width cannot be specified if
// there is no inner box
bool const width_enabled =
ibox || outer == "Frameless" || outer == "Boxed";
- widthED->setEnabled(width_enabled);
- widthUnitsLC->setEnabled(width_enabled);
+ widthED->setEnabled(width_enabled && widthCB->isChecked());
+ widthUnitsLC->setEnabled(width_enabled && widthCB->isChecked());
// halign is only allowed for Boxed without inner box or for makebox
halignCO->setEnabled((!ibox && outer == "Boxed")
|| (itype == "makebox"));
@@ -164,12 +169,17 @@ void GuiBox::on_typeCO_activated(int index)
heightCB->setEnabled(ibox);
setSpecial(ibox);
}
+ // the width can only be selected for makebox or framebox
+ widthCB->setEnabled(itype == "makebox"
+ || (type == "Boxed" && itype == "none"));
+ if (!widthCB->isEnabled())
+ widthCB->setCheckState(Qt::Checked);
// except for frameless and boxed, the width cannot be specified if
// there is no inner box
bool const width_enabled =
itype != "none" || frameless || type == "Boxed";
- widthED->setEnabled(width_enabled);
- widthUnitsLC->setEnabled(width_enabled);
+ widthED->setEnabled(width_enabled && widthCB->isChecked());
+ widthUnitsLC->setEnabled(width_enabled && widthCB->isChecked());
// halign is only allowed for Boxed without inner box or for makebox
halignCO->setEnabled((type == "Boxed" && itype == "none") || (itype == "makebox"));
// pagebreak is only allowed for Boxed without inner box
@@ -188,6 +198,12 @@ void GuiBox::initDialog()
}
+void GuiBox::on_widthCB_stateChanged(int state)
+{
+ changed();
+}
+
+
void GuiBox::on_heightCB_stateChanged(int state)
{
bool const enable = (innerBoxCO->currentText() != qt_("None"))
@@ -261,20 +277,27 @@ void GuiBox::paramsToDialog(Inset const * inset)
// pagebreak is only allowed for Boxed without inner box
pagebreakCB->setEnabled(!ibox && type == "Boxed");
- // except for frameless and boxed, the width cannot be specified if
- // there is no inner box
- bool const width_enabled = (ibox || frameless || type == "Boxed");
- widthED->setEnabled(width_enabled);
- widthUnitsLC->setEnabled(width_enabled);
-
Length::UNIT const default_unit = Length::defaultUnit();
- lengthToWidgets(widthED, widthUnitsLC,
- (params.width).asString(), default_unit);
-
- QString const special = toqstr(params.special);
- if (!special.isEmpty() && special != "none")
- widthUnitsLC->setCurrentItem(special);
+ // the width can only be selected for makebox or framebox
+ widthCB->setEnabled(inner_type == "makebox"
+ || (type == "Boxed" && inner_type == "none"));
+ // "-999col%" is the code for no width
+ if ((params.width).asString() == "-999col%")
+ widthCB->setCheckState(Qt::Unchecked);
+ else {
+ widthCB->setCheckState(Qt::Checked);
+ // except for frameless and boxed, the width cannot be specified if
+ // there is no inner box
+ bool const width_enabled = (ibox || frameless || type == "Boxed");
+ widthED->setEnabled(width_enabled);
+ widthUnitsLC->setEnabled(width_enabled);
+ lengthToWidgets(widthED, widthUnitsLC,
+ (params.width).asString(), default_unit);
+ QString const special = toqstr(params.special);
+ if (!special.isEmpty() && special != "none")
+ widthUnitsLC->setCurrentItem(special);
+ }
lengthToWidgets(heightED, heightUnitsLC,
(params.height).asString(), default_unit);
@@ -292,6 +315,8 @@ void GuiBox::paramsToDialog(Inset const * inset)
heightCB->setCheckState(Qt::Checked);
heightCB->setEnabled(ibox);
+ widthED->setEnabled(widthCB->isChecked());
+ widthUnitsLC->setEnabled(widthCB->isChecked());
}
@@ -321,13 +346,20 @@ docstring GuiBox::dialogToParams() const
QString unit =
widthUnitsLC->itemData(widthUnitsLC->currentIndex()).toString();
QString value = widthED->text();
- 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);
+
+ 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 {
+ // use a the code "-999col%" if no width was selected
params.special = "none";
- params.width = Length(widgetsToLength(widthED, widthUnitsLC));
+ params.width = Length("-999col%");
}
// the height parameter is omitted if the value
diff --git a/src/frontends/qt4/GuiBox.h b/src/frontends/qt4/GuiBox.h
index b4fb8c3..5020f5c 100644
--- a/src/frontends/qt4/GuiBox.h
+++ b/src/frontends/qt4/GuiBox.h
@@ -31,6 +31,7 @@ private Q_SLOTS:
void on_innerBoxCO_activated(int);
void on_typeCO_activated(int);
void initDialog();
+ void on_widthCB_stateChanged(int state);
void on_heightCB_stateChanged(int state);
void on_pagebreakCB_stateChanged();
diff --git a/src/frontends/qt4/ui/BoxUi.ui b/src/frontends/qt4/ui/BoxUi.ui
index 9a6fd9a..867aa71 100644
--- a/src/frontends/qt4/ui/BoxUi.ui
+++ b/src/frontends/qt4/ui/BoxUi.ui
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BoxUi</class>
<widget class="QWidget" name="BoxUi">
@@ -15,13 +16,121 @@
<property name="sizeGripEnabled" stdset="0">
<bool>true</bool>
</property>
- <layout class="QGridLayout">
- <property name="margin">
- <number>9</number>
- </property>
- <property name="spacing">
- <number>6</number>
- </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="typeLA">
+ <property name="toolTip">
+ <string/>
+ </property>
+ <property name="text">
+ <string>&Decoration:</string>
+ </property>
+ <property name="buddy">
+ <cstring>typeCO</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QComboBox" name="typeCO">
+ <property name="toolTip">
+ <string>Supported box types</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="innerBoxLA">
+ <property name="toolTip">
+ <string/>
+ </property>
+ <property name="text">
+ <string>Inner Bo&x:</string>
+ </property>
+ <property name="buddy">
+ <cstring>innerBoxCO</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="innerBoxCO">
+ <property name="toolTip">
+ <string>Inner box -- needed for fixed width & line breaks</string>
+ </property>
+ <item>
+ <property name="text">
+ <string>None</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Parbox</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Minipage</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QCheckBox" name="widthCB">
+ <property name="toolTip">
+ <string/>
+ </property>
+ <property name="text">
+ <string>&Width:</string>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ <property name="tristate">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QLineEdit" name="widthED">
+ <property name="toolTip">
+ <string>Width value</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2">
+ <widget class="LengthCombo" name="widthUnitsLC"/>
+ </item>
+ <item row="3" column="0">
+ <widget class="QCheckBox" name="heightCB">
+ <property name="toolTip">
+ <string/>
+ </property>
+ <property name="text">
+ <string>&Height:</string>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ <property name="tristate">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QLineEdit" name="heightED">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="toolTip">
+ <string>Height value</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="2">
+ <widget class="LengthCombo" name="heightUnitsLC">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="pagebreakCB">
<property name="toolTip">
@@ -181,117 +290,6 @@
</layout>
</widget>
</item>
- <item row="3" column="2">
- <widget class="LengthCombo" name="heightUnitsLC">
- <property name="enabled">
- <bool>false</bool>
- </property>
- </widget>
- </item>
- <item row="3" column="0">
- <widget class="QCheckBox" name="heightCB">
- <property name="toolTip">
- <string/>
- </property>
- <property name="text">
- <string>&Height:</string>
- </property>
- <property name="checked">
- <bool>false</bool>
- </property>
- <property name="tristate">
- <bool>false</bool>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="innerBoxLA">
- <property name="toolTip">
- <string/>
- </property>
- <property name="text">
- <string>Inner Bo&x:</string>
- </property>
- <property name="buddy">
- <cstring>innerBoxCO</cstring>
- </property>
- </widget>
- </item>
- <item row="2" column="2">
- <widget class="LengthCombo" name="widthUnitsLC"/>
- </item>
- <item row="0" column="0">
- <widget class="QLabel" name="typeLA">
- <property name="toolTip">
- <string/>
- </property>
- <property name="text">
- <string>&Decoration:</string>
- </property>
- <property name="buddy">
- <cstring>typeCO</cstring>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QLabel" name="widthLA">
- <property name="toolTip">
- <string/>
- </property>
- <property name="text">
- <string>&Width:</string>
- </property>
- <property name="buddy">
- <cstring>widthED</cstring>
- </property>
- </widget>
- </item>
- <item row="3" column="1">
- <widget class="QLineEdit" name="heightED">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="toolTip">
- <string>Height value</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="QLineEdit" name="widthED">
- <property name="toolTip">
- <string>Width value</string>
- </property>
- </widget>
- </item>
- <item row="1" column="1" colspan="2">
- <widget class="QComboBox" name="innerBoxCO">
- <property name="toolTip">
- <string>Inner box -- needed for fixed width & line breaks</string>
- </property>
- <item>
- <property name="text">
- <string>None</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Parbox</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Minipage</string>
- </property>
- </item>
- </widget>
- </item>
- <item row="0" column="1" colspan="2">
- <widget class="QComboBox" name="typeCO">
- <property name="toolTip">
- <string>Supported box types</string>
- </property>
- </widget>
- </item>
</layout>
</widget>
<customwidgets>
@@ -350,5 +348,37 @@
</hint>
</hints>
</connection>
+ <connection>
+ <sender>widthCB</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>widthED</receiver>
+ <slot>setEnabled(bool)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>37</x>
+ <y>70</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>124</x>
+ <y>70</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>widthCB</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>widthUnitsLC</receiver>
+ <slot>setEnabled(bool)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>37</x>
+ <y>70</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>217</x>
+ <y>70</y>
+ </hint>
+ </hints>
+ </connection>
</connections>
</ui>
diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp
index 68bca75..6e06827 100644
--- a/src/insets/InsetBox.cpp
+++ b/src/insets/InsetBox.cpp
@@ -301,20 +301,24 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const
os << "\\begin{framed}%\n";
break;
case Boxed:
- os << "\\framebox";
- if (!params_.inner_box) {
- // Special widths, see usrguide §3.5
- // FIXME UNICODE
- if (params_.special != "none") {
- os << "[" << params_.width.value()
- << '\\' << from_utf8(params_.special)
- << ']';
- } else
- os << '[' << from_ascii(width_string)
- << ']';
- if (params_.hor_pos != 'c')
- os << "[" << params_.hor_pos << "]";
- }
+ // "-999col%" is the code for no width
+ if (from_ascii(width_string) != "-9.99\\columnwidth") {
+ os << "\\framebox";
+ if (!params_.inner_box) {
+ // Special widths, see usrguide §3.5
+ // FIXME UNICODE
+ if (params_.special != "none") {
+ os << "[" << params_.width.value()
+ << '\\' << from_utf8(params_.special)
+ << ']';
+ } else
+ os << '[' << from_ascii(width_string)
+ << ']';
+ if (params_.hor_pos != 'c')
+ os << "[" << params_.hor_pos << "]";
+ }
+ } else
+ os << "\\fbox";
os << "{";
break;
case ovalbox:
@@ -339,18 +343,22 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const
if (params_.use_parbox)
os << "\\parbox";
else if (params_.use_makebox) {
- os << "\\makebox";
- // FIXME UNICODE
- // output the width and horizontal position
- if (params_.special != "none") {
- os << "[" << params_.width.value()
- << '\\' << from_utf8(params_.special)
- << ']';
+ // "-999col%" is the code for no width
+ if (from_ascii(width_string) != "-9.99\\columnwidth") {
+ os << "\\makebox";
+ // FIXME UNICODE
+ // output the width and horizontal position
+ if (params_.special != "none") {
+ os << "[" << params_.width.value()
+ << '\\' << from_utf8(params_.special)
+ << ']';
+ } else
+ os << '[' << from_ascii(width_string)
+ << ']';
+ if (params_.hor_pos != 'c')
+ os << "[" << params_.hor_pos << "]";
} else
- os << '[' << from_ascii(width_string)
- << ']';
- if (params_.hor_pos != 'c')
- os << "[" << params_.hor_pos << "]";
+ os << "\\mbox";
os << "{";
}
else