#include "insets/InsetTabular.h"
+#include "support/convert.h"
#include "support/debug.h"
#include <QCheckBox>
namespace frontend {
GuiTabular::GuiTabular(QWidget * parent)
- : InsetParamsWidget(parent)
+ : InsetParamsWidget(parent), firstheader_suppressable_(false),
+ lastfooter_suppressable_(false)
+
{
setupUi(this);
this, SLOT(checkEnabled()));
connect(captionStatusCB, SIGNAL(clicked()),
this, SLOT(checkEnabled()));
- connect(specialAlignmentED, SIGNAL(editingFinished()),
+ connect(specialAlignmentED, SIGNAL(textEdited(const QString &)),
this, SLOT(checkEnabled()));
connect(columnWidthED, SIGNAL(textEdited(const QString &)),
this, SLOT(checkEnabled()));
this, SLOT(checkEnabled()));
connect(rotateTabularCB, SIGNAL(clicked()),
this, SLOT(checkEnabled()));
+ connect(rotateTabularAngleSB, SIGNAL(valueChanged(int)),
+ this, SLOT(checkEnabled()));
connect(rotateCellCB, SIGNAL(clicked()),
this, SLOT(checkEnabled()));
+ connect(rotateCellAngleSB, SIGNAL(valueChanged(int)),
+ this, SLOT(checkEnabled()));
connect(TableAlignCO, SIGNAL(activated(int)),
this, SLOT(checkEnabled()));
connect(longTabularCB, SIGNAL(clicked()),
}
-void GuiTabular::checkEnabled()
+void GuiTabular::enableWidgets() const
{
// if there is a LaTeX argument, the width and alignment will be overwritten
// therefore disable them in this case
columnWidthED->setEnabled(specialAlignmentED->text().isEmpty());
+ columnWidthUnitLC->setEnabled(specialAlignmentED->text().isEmpty());
// if the column has a width, multirows are always left-aligned
// therefore disable hAlignCB in this case
hAlignCO->setEnabled(!(multirowCB->isChecked()
&& !widgetsToLength(columnWidthED, columnWidthUnitLC).empty())
&& specialAlignmentED->text().isEmpty());
+ // decimal alignment is only possible for non-multicol and non-multirow cells
+ if ((multicolumnCB->isChecked() || multirowCB->isChecked())
+ && hAlignCO->findData(toqstr("decimal")))
+ hAlignCO->removeItem(hAlignCO->findData(toqstr("decimal")));
+ else if (!multicolumnCB->isChecked() && !multirowCB->isChecked()
+ && hAlignCO->findData(toqstr("decimal")) == -1)
+ hAlignCO->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
bool const dalign =
hAlignCO->itemData(hAlignCO->currentIndex()).toString() == QString("decimal");
decimalPointED->setEnabled(dalign);
decimalLA->setEnabled(dalign);
bool const setwidth = TableAlignCO->currentText() == qt_("Middle")
- && !longTabularCB->isChecked() && !rotateTabularCB->isChecked();
+ && !longTabularCB->isChecked();
tabularWidthLA->setEnabled(setwidth);
tabularWidthED->setEnabled(setwidth);
tabularWidthUnitLC->setEnabled(setwidth);
- bool const is_tabular_star = !tabularWidthED->text().isEmpty();
- rotateTabularCB->setDisabled(is_tabular_star);
+ rotateTabularAngleSB->setEnabled(rotateTabularCB->isChecked());
+ rotateCellAngleSB->setEnabled(rotateCellCB->isChecked());
bool const enable_valign =
!multirowCB->isChecked()
interlinespaceUnitLC->setEnabled(interlinespaceCO->currentIndex() == 2);
// setting as longtable is not allowed when table is inside a float
+ bool const is_tabular_star = !tabularWidthED->text().isEmpty();
longTabularCB->setEnabled(!is_tabular_star && funcEnabled(Tabular::SET_LONGTABULAR));
bool const longtabular = longTabularCB->isChecked();
longtableGB->setEnabled(true);
// depending on the cursor position is very very unintuitive...
// We need some edit boxes to show which rows are header/footer/etc
// without having to move the cursor first.
- headerStatusCB->setEnabled(longtabular);
+ headerStatusCB->setEnabled(longtabular
+ && (headerStatusCB->isChecked() ?
+ funcEnabled(Tabular::UNSET_LTHEAD) :
+ funcEnabled(Tabular::SET_LTHEAD)));
headerBorderAboveCB->setEnabled(longtabular
&& headerStatusCB->isChecked());
headerBorderBelowCB->setEnabled(longtabular
// check if setting a first header is allowed
// additionally check firstheaderNoContentsCB because when this is
// the case a first header makes no sense
- firstheaderStatusCB->setEnabled(funcEnabled(Tabular::SET_LTFIRSTHEAD)
+ firstheaderStatusCB->setEnabled((firstheaderStatusCB->isChecked() ?
+ funcEnabled(Tabular::UNSET_LTFIRSTHEAD) :
+ funcEnabled(Tabular::SET_LTFIRSTHEAD))
&& longtabular && !firstheaderNoContentsCB->isChecked());
firstheaderBorderAboveCB->setEnabled(longtabular
&& firstheaderStatusCB->isChecked());
firstheaderBorderBelowCB->setEnabled(longtabular
&& firstheaderStatusCB->isChecked());
- footerStatusCB->setEnabled(longtabular);
+ footerStatusCB->setEnabled(longtabular
+ && (footerStatusCB->isChecked() ?
+ funcEnabled(Tabular::UNSET_LTFOOT) :
+ funcEnabled(Tabular::SET_LTFOOT)));
footerBorderAboveCB->setEnabled(longtabular
&& footerBorderAboveCB->isChecked());
footerBorderBelowCB->setEnabled(longtabular
// check if setting a last footer is allowed
// additionally check lastfooterNoContentsCB because when this is
// the case a last footer makes no sense
- lastfooterStatusCB->setEnabled(funcEnabled(Tabular::SET_LTLASTFOOT)
+ lastfooterStatusCB->setEnabled((lastfooterStatusCB->isChecked() ?
+ funcEnabled(Tabular::UNSET_LTLASTFOOT) :
+ funcEnabled(Tabular::SET_LTLASTFOOT))
&& longtabular && !lastfooterNoContentsCB->isChecked());
lastfooterBorderAboveCB->setEnabled(longtabular
&& lastfooterBorderAboveCB->isChecked());
captionStatusCB->setEnabled(funcEnabled(Tabular::TOGGLE_LTCAPTION)
&& longtabular);
- multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN));
- multirowCB->setEnabled(funcEnabled(Tabular::MULTIROW));
+ multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN)
+ && !dalign && !multirowCB->isChecked());
+ multirowCB->setEnabled(funcEnabled(Tabular::MULTIROW)
+ && !dalign && !multicolumnCB->isChecked());
bool const enable_mr = multirowCB->isChecked();
multirowOffsetLA->setEnabled(enable_mr);
multirowOffsetED->setEnabled(enable_mr);
multirowOffsetUnitLC->setEnabled(enable_mr);
+ // Vertical lines cannot be set in formal tables
+ borders->setLeftEnabled(!booktabsRB->isChecked());
+ borders->setRightEnabled(!booktabsRB->isChecked());
+}
+
+
+void GuiTabular::checkEnabled()
+{
+ enableWidgets();
changed();
}
docstring GuiTabular::dialogToParams() const
{
- // FIXME: We should use Tabular directly.
- string param_str = "tabular from-dialog";
+ string param_str = "tabular";
// table width
string tabwidth = widgetsToLength(tabularWidthED, tabularWidthUnitLC);
setParam(param_str, Tabular::SET_PWIDTH, width);
// apply the column alignment
- setHAlign(param_str);
+ // multirows inherit the alignment from the column; if a column width
+ // is set, multirows are always left-aligned so that in this case
+ // its alignment must not be applied (see bug #8084)
+ if (!(multirowCB->isChecked() && width != "0pt"))
+ setHAlign(param_str);
// SET_DECIMAL_POINT must come after setHAlign() (ALIGN_DECIMAL)
string decimal_point = fromqstr(decimalPointED->text());
setParam(param_str, Tabular::SET_MULTIROW);
else
setParam(param_str, Tabular::UNSET_MULTIROW);
- //
+ // store the table rotation angle
+ string const tabular_angle = convert<string>(rotateTabularAngleSB->value());
if (rotateTabularCB->isChecked())
- setParam(param_str, Tabular::SET_ROTATE_TABULAR);
+ setParam(param_str, Tabular::SET_ROTATE_TABULAR, tabular_angle);
else
- setParam(param_str, Tabular::UNSET_ROTATE_TABULAR);
- //
+ setParam(param_str, Tabular::UNSET_ROTATE_TABULAR, tabular_angle);
+ // store the cell rotation angle
+ string const cell_angle = convert<string>(rotateCellAngleSB->value());
if (rotateCellCB->isChecked())
- setParam(param_str, Tabular::SET_ROTATE_CELL);
+ setParam(param_str, Tabular::SET_ROTATE_CELL, cell_angle);
else
- setParam(param_str, Tabular::UNSET_ROTATE_CELL);
+ setParam(param_str, Tabular::UNSET_ROTATE_CELL, cell_angle);
//
if (longTabularCB->isChecked())
setParam(param_str, Tabular::SET_LONGTABULAR);
//
if (newpageCB->isChecked())
setParam(param_str, Tabular::SET_LTNEWPAGE);
+ else
+ setParam(param_str, Tabular::UNSET_LTNEWPAGE);
//
if (captionStatusCB->isChecked())
setParam(param_str, Tabular::SET_LTCAPTION);
bool const multirow = tabular.isMultiRow(cell);
multirowCB->setChecked(multirow);
- rotateCellCB->setChecked(tabular.getRotateCell(cell));
- rotateTabularCB->setChecked(tabular.rotate);
+ rotateCellCB->setChecked(tabular.getRotateCell(cell) != 0);
+ if (rotateCellCB->isChecked()) {
+ if (tabular.getRotateCell(cell) != 0)
+ rotateCellAngleSB->setValue(tabular.getRotateCell(cell));
+ else
+ rotateCellAngleSB->setValue(90);
+ }
+
+ rotateTabularCB->setChecked(tabular.rotate != 0);
+ if (rotateTabularCB->isChecked())
+ rotateTabularAngleSB->setValue(tabular.rotate != 0 ? tabular.rotate : 90);
longTabularCB->setChecked(tabular.is_long_tabular);
// Set width and alignment
Length const tabwidth = tabular.tabularWidth();
- if (tabwidth.zero())
+ if (tabwidth.zero()
+ && !(tabularWidthED->hasFocus() && tabularWidthED->text() == "0"))
tabularWidthED->clear();
else
lengthToWidgets(tabularWidthED, tabularWidthUnitLC,
pwidth = getColumnPWidth(tabular, cell);
}
string colwidth;
- if (pwidth.zero())
+ if (pwidth.zero()
+ && !(columnWidthED->hasFocus() && columnWidthED->text() == "0"))
columnWidthED->clear();
else {
colwidth = pwidth.asString();
if (multirow)
mroffset = getMROffset(tabular, cell);
string offset;
- if (mroffset.zero())
+ if (mroffset.zero()
+ && !(multirowOffsetED->hasFocus() && multirowOffsetED->text() == "0"))
multirowOffsetED->clear();
else {
offset = mroffset.asString();
hAlignCO->addItem(qt_("Right"), toqstr("right"));
if (!multicol && !pwidth.zero())
hAlignCO->addItem(qt_("Justified"), toqstr("justified"));
- if (!multicol)
+ if (!multicol && !multirow)
hAlignCO->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
string align;
}
case LYX_ALIGN_DECIMAL:
{
- if (!multicol)
+ if (!multicol && !multirow)
align = "decimal";
break;
}
}
+bool GuiTabular::checkWidgets(bool readonly) const
+{
+ tabularRowED->setReadOnly(readonly);
+ tabularColumnED->setReadOnly(readonly);
+ tabularWidthED->setReadOnly(readonly);
+ specialAlignmentED->setReadOnly(readonly);
+ columnWidthED->setReadOnly(readonly);
+ multirowOffsetED->setReadOnly(readonly);
+ decimalPointED->setReadOnly(readonly);
+
+ if (readonly) {
+ multicolumnCB->setEnabled(false);
+ multirowCB->setEnabled(false);
+ rotateCellCB->setEnabled(false);
+ rotateCellAngleSB->setEnabled(false);
+ rotateTabularCB->setEnabled(false);
+ rotateTabularAngleSB->setEnabled(false);
+ longTabularCB->setEnabled(false);
+ borders->setEnabled(false);
+ tabularWidthUnitLC->setEnabled(false);
+ columnWidthUnitLC->setEnabled(false);
+ multirowOffsetUnitLC->setEnabled(false);
+ setBordersGB->setEnabled(false);
+ allBordersGB->setEnabled(false);
+ borderStyleGB->setEnabled(false);
+ booktabsRB->setEnabled(false);
+ topspaceCO->setEnabled(false);
+ topspaceUnitLC->setEnabled(false);
+ bottomspaceCO->setEnabled(false);
+ bottomspaceUnitLC->setEnabled(false);
+ interlinespaceCO->setEnabled(false);
+ interlinespaceUnitLC->setEnabled(false);
+ hAlignCO->setEnabled(false);
+ vAlignCO->setEnabled(false);
+ TableAlignCO->setEnabled(false);
+ longtableGB->setEnabled(false);
+ alignmentGB->setEnabled(false);
+ } else
+ enableWidgets();
+
+ return InsetParamsWidget::checkWidgets();
+}
+
+
bool GuiTabular::funcEnabled(Tabular::Feature f) const
{
- string cmd = "tabular " + featureAsString(f);
- return getStatus(FuncRequest(LFUN_INSET_MODIFY, cmd)).enabled();
+ FuncRequest r(LFUN_INSET_MODIFY, "tabular for-dialog" + featureAsString(f));
+ return getStatus(r).enabled();
}