* Licence details can be found in the file COPYING.
*
* \author John Levon
- * \author Jürgen Spitzmüller
- * \author Herbert Voß
+ * \author Jürgen Spitzmüller
+ * \author Herbert Voß
+ * \author Uwe Stöhr
*
* Full author contact details are available in file CREDITS.
*/
#include "GuiTabular.h"
-#include "CheckedLineEdit.h"
+#include "GuiApplication.h"
#include "GuiSetBorder.h"
-#include "Qt2BC.h"
-
+#include "GuiView.h"
#include "LengthCombo.h"
-#include "Validator.h"
#include "qt_helpers.h"
+#include "Validator.h"
-#include "controllers/ButtonController.h"
+#include "BufferView.h"
+#include "Cursor.h"
+#include "FuncRequest.h"
+#include "FuncStatus.h"
+#include "LyX.h"
+#include "LyXRC.h"
-#include "support/convert.h"
+#include "insets/InsetTabular.h"
+
+#include "support/debug.h"
-#include <QCloseEvent>
#include <QCheckBox>
#include <QPushButton>
#include <QRadioButton>
#include <QLineEdit>
-using std::string;
+using namespace std;
namespace lyx {
namespace frontend {
-/////////////////////////////////////////////////////////////////////
-//
-// GuiTabularDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-GuiTabularDialog::GuiTabularDialog(GuiTabular * form)
- : form_(form)
+GuiTabular::GuiTabular(QWidget * parent)
+ : InsetParamsWidget(parent)
{
setupUi(this);
- widthED->setValidator(unsignedLengthValidator(widthED));
+ tabularWidthED->setValidator(unsignedLengthValidator(tabularWidthED));
+ columnWidthED->setValidator(unsignedLengthValidator(columnWidthED));
+ multirowOffsetED->setValidator(new LengthValidator(multirowOffsetED));
topspaceED->setValidator(new LengthValidator(topspaceED));
bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
- connect(topspaceED, SIGNAL(returnPressed()),
- this, SLOT(topspace_changed()));
- connect(topspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
- this, SLOT(topspace_changed()));
- connect(topspaceCO, SIGNAL(activated(int)), this, SLOT(topspace_changed()));
- connect(bottomspaceED, SIGNAL(returnPressed()),
- this, SLOT(bottomspace_changed()));
- connect(bottomspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
- this, SLOT(bottomspace_changed()));
- connect(bottomspaceCO, SIGNAL(activated(int)), this, SLOT(bottomspace_changed()));
- connect(interlinespaceED, SIGNAL(returnPressed()),
- this, SLOT(interlinespace_changed()));
- connect(interlinespaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
- this, SLOT(interlinespace_changed()));
- connect(interlinespaceCO, SIGNAL(activated(int)), this, SLOT(interlinespace_changed()));
- connect(booktabsRB, SIGNAL(clicked(bool)), this, SLOT(booktabsChanged(bool)));
- connect(borderDefaultRB, SIGNAL(clicked(bool)), this, SLOT(booktabsChanged(bool)));
- connect(borderSetPB, SIGNAL(clicked()), this, SLOT(borderSet_clicked()));
- connect(borderUnsetPB, SIGNAL(clicked()), this, SLOT(borderUnset_clicked()));
- connect(longTabularCB, SIGNAL(toggled(bool)), longtableGB, SLOT(setEnabled(bool)));
- connect(longTabularCB, SIGNAL(toggled(bool)), newpageCB, SLOT(setEnabled(bool)));
- connect(hAlignCB, SIGNAL(activated(int)), this, SLOT(hAlign_changed(int)));
- connect(vAlignCB, SIGNAL(activated(int)), this, SLOT(vAlign_changed(int)));
- connect(multicolumnCB, SIGNAL(clicked()), this, SLOT(multicolumn_clicked()));
- connect(newpageCB, SIGNAL(clicked()), this, SLOT(ltNewpage_clicked()));
- connect(headerStatusCB, SIGNAL(clicked()), this, SLOT(ltHeaderStatus_clicked()));
- connect(headerBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltHeaderBorderAbove_clicked()));
- connect(headerBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltHeaderBorderBelow_clicked()));
- connect(firstheaderStatusCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderStatus_clicked()));
- connect(firstheaderBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderBorderAbove_clicked()));
- connect(firstheaderBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderBorderBelow_clicked()));
- connect(firstheaderNoContentsCB, SIGNAL(clicked()), this, SLOT(ltFirstHeaderEmpty_clicked()));
- connect(footerStatusCB, SIGNAL(clicked()), this, SLOT(ltFooterStatus_clicked()));
- connect(footerBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltFooterBorderAbove_clicked()));
- connect(footerBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltFooterBorderBelow_clicked()));
- connect(lastfooterStatusCB, SIGNAL(clicked()), this, SLOT(ltLastFooterStatus_clicked()));
- connect(lastfooterBorderAboveCB, SIGNAL(clicked()), this, SLOT(ltLastFooterBorderAbove_clicked()));
- connect(lastfooterBorderBelowCB, SIGNAL(clicked()), this, SLOT(ltLastFooterBorderBelow_clicked()));
- connect(lastfooterNoContentsCB, SIGNAL(clicked()), this, SLOT(ltLastFooterEmpty_clicked()));
- connect(specialAlignmentED, SIGNAL(returnPressed()), this, SLOT(specialAlignment_changed()));
- connect(widthED, SIGNAL(returnPressed()), this, SLOT(width_changed()));
- connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)), this, SLOT(width_changed()));
- connect(closePB, SIGNAL(clicked()), this, SLOT(close_clicked()));
- connect(borders, SIGNAL(topSet(bool)), this, SLOT(topBorder_changed()));
- connect(borders, SIGNAL(bottomSet(bool)), this, SLOT(bottomBorder_changed()));
- connect(borders, SIGNAL(rightSet(bool)), this, SLOT(rightBorder_changed()));
- connect(borders, SIGNAL(leftSet(bool)), this, SLOT(leftBorder_changed()));
- connect(rotateTabularCB, SIGNAL(clicked()), this, SLOT(rotateTabular()));
- connect(rotateCellCB, SIGNAL(clicked()), this, SLOT(rotateCell()));
- connect(longTabularCB, SIGNAL(clicked()), this, SLOT(longTabular()));
+ tabularWidthUnitLC->setCurrentItem(Length::defaultUnit());
+ columnWidthUnitLC->setCurrentItem(Length::defaultUnit());
+ multirowOffsetUnitLC->setCurrentItem(Length::defaultUnit());
+ topspaceUnitLC->setCurrentItem(Length::defaultUnit());
+ bottomspaceUnitLC->setCurrentItem(Length::defaultUnit());
+ interlinespaceUnitLC->setCurrentItem(Length::defaultUnit());
+
+ connect(topspaceED, SIGNAL(textEdited(const QString &)),
+ this, SLOT(checkEnabled()));
+ connect(topspaceUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+ this, SLOT(checkEnabled()));
+ connect(bottomspaceED, SIGNAL(textEdited(const QString &)),
+ this, SLOT(checkEnabled()));
+ connect(bottomspaceUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+ this, SLOT(checkEnabled()));
+ connect(interlinespaceED, SIGNAL(textEdited(const QString &)),
+ this, SLOT(checkEnabled()));
+ connect(interlinespaceUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+ this, SLOT(checkEnabled()));
+ connect(booktabsRB, SIGNAL(clicked(bool)),
+ this, SLOT(checkEnabled()));
+ connect(borderDefaultRB, SIGNAL(clicked(bool)),
+ this, SLOT(checkEnabled()));
+ connect(borderSetPB, SIGNAL(clicked()),
+ this, SLOT(borderSet_clicked()));
+ connect(borderUnsetPB, SIGNAL(clicked()),
+ this, SLOT(borderUnset_clicked()));
+ connect(hAlignCO, SIGNAL(activated(int)),
+ this, SLOT(checkEnabled()));
+ connect(vAlignCO, SIGNAL(activated(int)),
+ this, SLOT(checkEnabled()));
+ connect(multicolumnCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(multirowCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(multirowOffsetED, SIGNAL(textEdited(const QString &)),
+ this, SLOT(checkEnabled()));
+ connect(multirowOffsetUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+ this, SLOT(checkEnabled()));
+ connect(newpageCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(headerStatusCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(headerBorderAboveCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(headerBorderBelowCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(firstheaderStatusCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(firstheaderBorderAboveCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(firstheaderBorderBelowCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(firstheaderNoContentsCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(footerStatusCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(footerBorderAboveCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(footerBorderBelowCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(lastfooterStatusCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(lastfooterBorderAboveCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(lastfooterBorderBelowCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(lastfooterNoContentsCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(captionStatusCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(specialAlignmentED, SIGNAL(editingFinished()),
+ this, SLOT(checkEnabled()));
+ connect(columnWidthED, SIGNAL(textEdited(const QString &)),
+ this, SLOT(checkEnabled()));
+ connect(columnWidthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+ this, SLOT(checkEnabled()));
+ connect(borders, SIGNAL(topSet(bool)),
+ this, SLOT(checkEnabled()));
+ connect(borders, SIGNAL(bottomSet(bool)),
+ this, SLOT(checkEnabled()));
+ connect(borders, SIGNAL(rightSet(bool)),
+ this, SLOT(checkEnabled()));
+ connect(borders, SIGNAL(leftSet(bool)),
+ this, SLOT(checkEnabled()));
+ connect(rotateTabularCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(rotateCellCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(TableAlignCO, SIGNAL(activated(int)),
+ this, SLOT(checkEnabled()));
+ connect(longTabularCB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(leftRB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(centerRB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(rightRB, SIGNAL(clicked()),
+ this, SLOT(checkEnabled()));
+ connect(tabularWidthED, SIGNAL(textEdited(const QString &)),
+ this, SLOT(checkEnabled()));
+
+ decimalPointED->setInputMask("X; ");
+ decimalPointED->setMaxLength(1);
+
+ // initialize the length validator
+ addCheckedWidget(columnWidthED, columnWidthLA);
+ addCheckedWidget(multirowOffsetED, multirowOffsetLA);
+ addCheckedWidget(topspaceED, topspaceLA);
+ addCheckedWidget(bottomspaceED, bottomspaceLA);
+ addCheckedWidget(interlinespaceED, interlinespaceLA);
+ addCheckedWidget(tabularWidthED, tabularWidthLA);
+}
+
+
+void GuiTabular::on_topspaceCO_activated(int index)
+{
+ bool const enable = (index == 2);
+ topspaceED->setEnabled(enable);
+ topspaceUnitLC->setEnabled(enable);
+}
+
+
+void GuiTabular::on_bottomspaceCO_activated(int index)
+{
+ bool const enable = (index == 2);
+ bottomspaceED->setEnabled(enable);
+ bottomspaceUnitLC->setEnabled(enable);
+}
+
+
+void GuiTabular::on_interlinespaceCO_activated(int index)
+{
+ bool const enable = (index == 2);
+ interlinespaceED->setEnabled(enable);
+ interlinespaceUnitLC->setEnabled(enable);
+}
+
+
+void GuiTabular::checkEnabled()
+{
+ // if there is a LaTeX argument, the width and alignment will be overwritten
+ // therefore disable them in this case
+ columnWidthED->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());
+ 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();
+ tabularWidthLA->setEnabled(setwidth);
+ tabularWidthED->setEnabled(setwidth);
+ tabularWidthUnitLC->setEnabled(setwidth);
+
+ bool const is_tabular_star = !tabularWidthED->text().isEmpty();
+ rotateTabularCB->setDisabled(is_tabular_star);
+
+ bool const enable_valign =
+ !multirowCB->isChecked()
+ && !widgetsToLength(columnWidthED, columnWidthUnitLC).empty()
+ && specialAlignmentED->text().isEmpty();
+ vAlignCO->setEnabled(enable_valign);
+ vAlignLA->setEnabled(enable_valign);
+
+ topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
+ topspaceED->setEnabled(topspaceCO->currentIndex() == 2);
+ topspaceUnitLC->setEnabled(topspaceCO->currentIndex() == 2);
+ bottomspaceED->setEnabled(bottomspaceCO->currentIndex() == 2);
+ bottomspaceUnitLC->setEnabled(bottomspaceCO->currentIndex() == 2);
+ interlinespaceED->setEnabled(interlinespaceCO->currentIndex() == 2);
+ interlinespaceUnitLC->setEnabled(interlinespaceCO->currentIndex() == 2);
+
+ // setting as longtable is not allowed when table is inside a float
+ longTabularCB->setEnabled(!is_tabular_star && funcEnabled(Tabular::SET_LONGTABULAR));
+ bool const longtabular = longTabularCB->isChecked();
+ longtableGB->setEnabled(true);
+ newpageCB->setEnabled(longtabular);
+ alignmentGB->setEnabled(longtabular);
+ // longtables and tabular* cannot have a vertical alignment
+ TableAlignLA->setDisabled(is_tabular_star || longtabular);
+ TableAlignCO->setDisabled(is_tabular_star || longtabular);
+
+ // FIXME: This Dialog is really horrible, disabling/enabling a checkbox
+ // 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);
+ headerBorderAboveCB->setEnabled(longtabular
+ && headerStatusCB->isChecked());
+ headerBorderBelowCB->setEnabled(longtabular
+ && headerStatusCB->isChecked());
+
+ // first header can only be suppressed when there is a header
+ // firstheader_suppressable_ is set in paramsToDialog
+ firstheaderNoContentsCB->setEnabled(longtabular && firstheader_suppressable_);
+ // 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)
+ && longtabular && !firstheaderNoContentsCB->isChecked());
+ firstheaderBorderAboveCB->setEnabled(longtabular
+ && firstheaderStatusCB->isChecked());
+ firstheaderBorderBelowCB->setEnabled(longtabular
+ && firstheaderStatusCB->isChecked());
+
+ footerStatusCB->setEnabled(longtabular);
+ footerBorderAboveCB->setEnabled(longtabular
+ && footerBorderAboveCB->isChecked());
+ footerBorderBelowCB->setEnabled(longtabular
+ && footerBorderAboveCB->isChecked());
+
+ // last footer can only be suppressed when there is a footer
+ // lastfooter_suppressable_ is set in paramsToDialog
+ lastfooterNoContentsCB->setEnabled(longtabular && lastfooter_suppressable_);
+ // 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)
+ && longtabular && !lastfooterNoContentsCB->isChecked());
+ lastfooterBorderAboveCB->setEnabled(longtabular
+ && lastfooterBorderAboveCB->isChecked());
+ lastfooterBorderBelowCB->setEnabled(longtabular
+ && lastfooterBorderAboveCB->isChecked());
+
+ captionStatusCB->setEnabled(funcEnabled(Tabular::TOGGLE_LTCAPTION)
+ && longtabular);
+
+ multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN));
+ multirowCB->setEnabled(funcEnabled(Tabular::MULTIROW));
+ bool const enable_mr = multirowCB->isChecked();
+ multirowOffsetLA->setEnabled(enable_mr);
+ multirowOffsetED->setEnabled(enable_mr);
+ multirowOffsetUnitLC->setEnabled(enable_mr);
+
+ changed();
+}
+
+
+void GuiTabular::borderSet_clicked()
+{
+ borders->setTop(true);
+ borders->setBottom(true);
+ borders->setLeft(true);
+ borders->setRight(true);
+ // repaint the setborder widget
+ borders->update();
+ checkEnabled();
}
-void GuiTabularDialog::change_adaptor()
+void GuiTabular::borderUnset_clicked()
{
- form_->changed();
+ borders->setTop(false);
+ borders->setBottom(false);
+ borders->setLeft(false);
+ borders->setRight(false);
+ // repaint the setborder widget
+ borders->update();
+ checkEnabled();
}
-void GuiTabularDialog::closeEvent(QCloseEvent * e)
+static void setParam(string & param_str, Tabular::Feature f, string const & arg = string())
{
- form_->slotWMHide();
- e->accept();
+ param_str += ' ';
+ param_str += featureAsString(f) + ' ' + arg;
}
-void GuiTabularDialog::booktabsChanged(bool)
+void GuiTabular::setHAlign(string & param_str) const
{
- form_->changed();
- form_->controller().booktabs(booktabsRB->isChecked());
- form_->update_borders();
+ Tabular::Feature num = Tabular::ALIGN_LEFT;
+ Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT;
+ string const align =
+ fromqstr(hAlignCO->itemData(hAlignCO->currentIndex()).toString());
+ if (align == "left") {
+ num = Tabular::ALIGN_LEFT;
+ multi_num = Tabular::M_ALIGN_LEFT;
+ } else if (align == "center") {
+ num = Tabular::ALIGN_CENTER;
+ multi_num = Tabular::M_ALIGN_CENTER;
+ } else if (align == "right") {
+ num = Tabular::ALIGN_RIGHT;
+ multi_num = Tabular::M_ALIGN_RIGHT;
+ } else if (align == "justified") {
+ num = Tabular::ALIGN_BLOCK;
+ //multi_num: no equivalent
+ } else if (align == "decimal") {
+ num = Tabular::ALIGN_DECIMAL;
+ //multi_num: no equivalent
+ }
+
+ if (multicolumnCB->isChecked())
+ setParam(param_str, multi_num);
+ else
+ setParam(param_str, num);
}
-void GuiTabularDialog::topspace_changed()
+void GuiTabular::setVAlign(string & param_str) const
{
- switch(topspaceCO->currentIndex()) {
- case 0: {
- form_->controller().set(Tabular::SET_TOP_SPACE, "");
- topspaceED->setEnabled(false);
- topspaceUnit->setEnabled(false);
- break;
- }
- case 1: {
- form_->controller().set(Tabular::SET_TOP_SPACE, "default");
- topspaceED->setEnabled(false);
- topspaceUnit->setEnabled(false);
- break;
- }
- case 2: {
- if (!topspaceED->text().isEmpty())
- form_->controller().set(Tabular::SET_TOP_SPACE,
- widgetsToLength(topspaceED, topspaceUnit));
- if (!form_->bc().policy().isReadOnly()) {
- topspaceED->setEnabled(true);
- topspaceUnit->setEnabled(true);
- }
- break;
- }
+ int const align = vAlignCO->currentIndex();
+ enum VALIGN { TOP, MIDDLE, BOTTOM };
+ VALIGN v = TOP;
+
+ switch (align) {
+ case 0: v = TOP; break;
+ case 1: v = MIDDLE; break;
+ case 2: v = BOTTOM; break;
}
- form_->changed();
-}
+ Tabular::Feature num = Tabular::VALIGN_MIDDLE;
+ Tabular::Feature multi_num = Tabular::M_VALIGN_MIDDLE;
-void GuiTabularDialog::bottomspace_changed()
-{
- switch(bottomspaceCO->currentIndex()) {
- case 0: {
- form_->controller().set(Tabular::SET_BOTTOM_SPACE, "");
- bottomspaceED->setEnabled(false);
- bottomspaceUnit->setEnabled(false);
+ switch (v) {
+ case TOP:
+ num = Tabular::VALIGN_TOP;
+ multi_num = Tabular::M_VALIGN_TOP;
break;
- }
- case 1: {
- form_->controller().set(Tabular::SET_BOTTOM_SPACE, "default");
- bottomspaceED->setEnabled(false);
- bottomspaceUnit->setEnabled(false);
+ case MIDDLE:
+ num = Tabular::VALIGN_MIDDLE;
+ multi_num = Tabular::M_VALIGN_MIDDLE;
break;
- }
- case 2: {
- if (!bottomspaceED->text().isEmpty())
- form_->controller().set(Tabular::SET_BOTTOM_SPACE,
- widgetsToLength(bottomspaceED, bottomspaceUnit));
- if (!form_->bc().policy().isReadOnly()) {
- bottomspaceED->setEnabled(true);
- bottomspaceUnit->setEnabled(true);
- }
+ case BOTTOM:
+ num = Tabular::VALIGN_BOTTOM;
+ multi_num = Tabular::M_VALIGN_BOTTOM;
break;
- }
}
- form_->changed();
+ if (multicolumnCB->isChecked() || multirowCB->isChecked())
+ setParam(param_str, multi_num);
+ else
+ setParam(param_str, num);
}
-void GuiTabularDialog::interlinespace_changed()
+void GuiTabular::setTableAlignment(string & param_str) const
{
- switch(interlinespaceCO->currentIndex()) {
- case 0: {
- form_->controller().set(Tabular::SET_INTERLINE_SPACE, "");
- interlinespaceED->setEnabled(false);
- interlinespaceUnit->setEnabled(false);
+ int const align = TableAlignCO->currentIndex();
+ switch (align) {
+ case 0: setParam(param_str, Tabular::TABULAR_VALIGN_TOP);
break;
- }
- case 1: {
- form_->controller().set(Tabular::SET_INTERLINE_SPACE, "default");
- interlinespaceED->setEnabled(false);
- interlinespaceUnit->setEnabled(false);
+ case 1: setParam(param_str, Tabular::TABULAR_VALIGN_MIDDLE);
break;
- }
- case 2: {
- if (!interlinespaceED->text().isEmpty())
- form_->controller().set(Tabular::SET_INTERLINE_SPACE,
- widgetsToLength(interlinespaceED, interlinespaceUnit));
- if (!form_->bc().policy().isReadOnly()) {
- interlinespaceED->setEnabled(true);
- interlinespaceUnit->setEnabled(true);
- }
+ case 2: setParam(param_str, Tabular::TABULAR_VALIGN_BOTTOM);
break;
- }
}
- form_->changed();
-}
-
-
-void GuiTabularDialog::close_clicked()
-{
- form_->closeGUI();
- form_->slotClose();
-}
-
-
-void GuiTabularDialog::borderSet_clicked()
-{
- form_->controller().set(Tabular::SET_ALL_LINES);
- form_->update_borders();
- form_->changed();
-}
-
-
-void GuiTabularDialog::borderUnset_clicked()
-{
- form_->controller().set(Tabular::UNSET_ALL_LINES);
- form_->update_borders();
- form_->changed();
-}
-
-
-void GuiTabularDialog::leftBorder_changed()
-{
- form_->controller().toggleLeftLine();
- form_->changed();
-}
-
-
-void GuiTabularDialog::rightBorder_changed()
-{
- form_->controller().toggleRightLine();
- form_->changed();
-}
-
-
-void GuiTabularDialog::topBorder_changed()
-{
- form_->controller().toggleTopLine();
- form_->changed();
-}
-
-
-void GuiTabularDialog::bottomBorder_changed()
-{
- form_->controller().toggleBottomLine();
- form_->changed();
-}
-
-
-void GuiTabularDialog::specialAlignment_changed()
-{
- string special = fromqstr(specialAlignmentED->text());
- form_->controller().setSpecial(special);
- form_->changed();
-}
-
-
-void GuiTabularDialog::width_changed()
-{
- form_->changed();
- string const width = widgetsToLength(widthED, widthUnit);
- form_->controller().setWidth(width);
-}
-
-
-void GuiTabularDialog::multicolumn_clicked()
-{
- form_->controller().toggleMultiColumn();
- form_->changed();
-}
-
-
-void GuiTabularDialog::rotateTabular()
-{
- form_->controller().rotateTabular(rotateTabularCB->isChecked());
- form_->changed();
}
-void GuiTabularDialog::rotateCell()
+docstring GuiTabular::dialogToParams() const
{
- form_->controller().rotateCell(rotateCellCB->isChecked());
- form_->changed();
-}
+ // FIXME: We should use Tabular directly.
+ string param_str = "tabular from-dialog";
+ // table width
+ string tabwidth = widgetsToLength(tabularWidthED, tabularWidthUnitLC);
+ if (tabwidth.empty())
+ tabwidth = "0pt";
+ setParam(param_str, Tabular::SET_TABULAR_WIDTH, tabwidth);
-void GuiTabularDialog::hAlign_changed(int align)
-{
- ControlTabular::HALIGN h = ControlTabular::LEFT;
+ // apply the fixed width values
+ // this must be done before applying the column alignment
+ // because its value influences the alignment of multirow cells
+ string width = widgetsToLength(columnWidthED, columnWidthUnitLC);
+ if (width.empty())
+ width = "0pt";
+ if (multicolumnCB->isChecked())
+ setParam(param_str, Tabular::SET_MPWIDTH, width);
+ else
+ setParam(param_str, Tabular::SET_PWIDTH, width);
+
+ // apply the column alignment
+ setHAlign(param_str);
+
+ // SET_DECIMAL_POINT must come after setHAlign() (ALIGN_DECIMAL)
+ string decimal_point = fromqstr(decimalPointED->text());
+ if (decimal_point.empty())
+ decimal_point = lyxrc.default_decimal_point;
+ setParam(param_str, Tabular::SET_DECIMAL_POINT, decimal_point);
+
+ setVAlign(param_str);
+ setTableAlignment(param_str);
+ //
+ if (booktabsRB->isChecked())
+ setParam(param_str, Tabular::SET_BOOKTABS);
+ else
+ setParam(param_str, Tabular::UNSET_BOOKTABS);
- switch (align) {
- case 0: h = ControlTabular::LEFT; break;
- case 1: h = ControlTabular::CENTER; break;
- case 2: h = ControlTabular::RIGHT; break;
- case 3: h = ControlTabular::BLOCK; break;
+ //
+ switch (topspaceCO->currentIndex()) {
+ case 0:
+ setParam(param_str, Tabular::SET_TOP_SPACE, "none");
+ break;
+ case 1:
+ setParam(param_str, Tabular::SET_TOP_SPACE, "default");
+ break;
+ case 2:
+ if (!topspaceED->text().isEmpty())
+ setParam(param_str, Tabular::SET_TOP_SPACE,
+ widgetsToLength(topspaceED, topspaceUnitLC));
+ break;
}
- form_->controller().halign(h);
-}
-
-
-void GuiTabularDialog::vAlign_changed(int align)
-{
- ControlTabular::VALIGN v = ControlTabular::TOP;
-
- switch (align) {
- case 0: v = ControlTabular::TOP; break;
- case 1: v = ControlTabular::MIDDLE; break;
- case 2: v = ControlTabular::BOTTOM; break;
+ //
+ switch (bottomspaceCO->currentIndex()) {
+ case 0:
+ setParam(param_str, Tabular::SET_BOTTOM_SPACE, "none");
+ break;
+ case 1:
+ setParam(param_str, Tabular::SET_BOTTOM_SPACE, "default");
+ break;
+ case 2:
+ if (!bottomspaceED->text().isEmpty())
+ setParam(param_str, Tabular::SET_BOTTOM_SPACE,
+ widgetsToLength(bottomspaceED,
+ bottomspaceUnitLC));
+ break;
}
- form_->controller().valign(v);
-}
-
-
-void GuiTabularDialog::longTabular()
-{
- form_->controller().longTabular(longTabularCB->isChecked());
- form_->changed();
-}
-
-
-void GuiTabularDialog::ltNewpage_clicked()
-{
- form_->controller().set(Tabular::SET_LTNEWPAGE);
- form_->changed();
-}
+ //
+ switch (interlinespaceCO->currentIndex()) {
+ case 0:
+ setParam(param_str, Tabular::SET_INTERLINE_SPACE, "none");
+ break;
+ case 1:
+ setParam(param_str, Tabular::SET_INTERLINE_SPACE, "default");
+ break;
+ case 2:
+ if (!interlinespaceED->text().isEmpty())
+ setParam(param_str, Tabular::SET_INTERLINE_SPACE,
+ widgetsToLength(interlinespaceED,
+ interlinespaceUnitLC));
+ break;
+ }
+ //
+ if (borders->getTop() && borders->getBottom() && borders->getLeft()
+ && borders->getRight())
+ setParam(param_str, Tabular::SET_ALL_LINES);
+ else if (!borders->getTop() && !borders->getBottom() && !borders->getLeft()
+ && !borders->getRight())
+ setParam(param_str, Tabular::UNSET_ALL_LINES);
+ else {
+ setParam(param_str, Tabular::SET_LINE_LEFT,
+ borders->getLeft() ? "true" : "false");
+ setParam(param_str, Tabular::SET_LINE_RIGHT,
+ borders->getRight() ? "true" : "false");
+ setParam(param_str, Tabular::SET_LINE_TOP,
+ borders->getTop() ? "true" : "false");
+ setParam(param_str, Tabular::SET_LINE_BOTTOM,
+ borders->getBottom() ? "true" : "false");
+ }
-void GuiTabularDialog::ltHeaderStatus_clicked()
-{
- bool enable(headerStatusCB->isChecked());
- if (enable)
- form_->controller().set(Tabular::SET_LTHEAD, "");
+ // apply the special alignment
+ string special = fromqstr(specialAlignmentED->text());
+ if (special.empty())
+ special = "none";
+ if (multicolumnCB->isChecked())
+ setParam(param_str, Tabular::SET_SPECIAL_MULTICOLUMN, special);
else
- form_->controller().set(Tabular::UNSET_LTHEAD, "");
- headerBorderAboveCB->setEnabled(enable);
- headerBorderBelowCB->setEnabled(enable);
- firstheaderNoContentsCB->setEnabled(enable);
- form_->changed();
-}
+ setParam(param_str, Tabular::SET_SPECIAL_COLUMN, special);
-
-void GuiTabularDialog::ltHeaderBorderAbove_clicked()
-{
+ //
+ if (multicolumnCB->isChecked())
+ setParam(param_str, Tabular::SET_MULTICOLUMN);
+ else
+ setParam(param_str, Tabular::UNSET_MULTICOLUMN);
+
+ // apply the multirow offset
+ string mroffset = widgetsToLength(multirowOffsetED, multirowOffsetUnitLC);
+ if (mroffset.empty())
+ mroffset = "0pt";
+ if (multirowCB->isChecked())
+ setParam(param_str, Tabular::SET_MROFFSET, mroffset);
+ //
+ if (multirowCB->isChecked())
+ setParam(param_str, Tabular::SET_MULTIROW);
+ else
+ setParam(param_str, Tabular::UNSET_MULTIROW);
+ //
+ if (rotateTabularCB->isChecked())
+ setParam(param_str, Tabular::SET_ROTATE_TABULAR);
+ else
+ setParam(param_str, Tabular::UNSET_ROTATE_TABULAR);
+ //
+ if (rotateCellCB->isChecked())
+ setParam(param_str, Tabular::SET_ROTATE_CELL);
+ else
+ setParam(param_str, Tabular::UNSET_ROTATE_CELL);
+ //
+ if (longTabularCB->isChecked())
+ setParam(param_str, Tabular::SET_LONGTABULAR);
+ else
+ setParam(param_str, Tabular::UNSET_LONGTABULAR);
+ //
+ if (newpageCB->isChecked())
+ setParam(param_str, Tabular::SET_LTNEWPAGE);
+ //
+ if (captionStatusCB->isChecked())
+ setParam(param_str, Tabular::SET_LTCAPTION);
+ else
+ setParam(param_str, Tabular::UNSET_LTCAPTION);
+ //
+ if (headerStatusCB->isChecked())
+ setParam(param_str, Tabular::SET_LTHEAD, "none");
+ else
+ setParam(param_str, Tabular::UNSET_LTHEAD, "none");
+ //
if (headerBorderAboveCB->isChecked())
- form_->controller().set(Tabular::SET_LTHEAD, "dl_above");
+ setParam(param_str, Tabular::SET_LTHEAD, "dl_above");
else
- form_->controller().set(Tabular::UNSET_LTHEAD, "dl_above");
- form_->changed();
-}
-
-
-void GuiTabularDialog::ltHeaderBorderBelow_clicked()
-{
+ setParam(param_str, Tabular::UNSET_LTHEAD, "dl_above");
+ //
if (headerBorderBelowCB->isChecked())
- form_->controller().set(Tabular::SET_LTHEAD, "dl_below");
+ setParam(param_str, Tabular::SET_LTHEAD, "dl_below");
else
- form_->controller().set(Tabular::UNSET_LTHEAD, "dl_below");
- form_->changed();
-}
-
-
-void GuiTabularDialog::ltFirstHeaderBorderAbove_clicked()
-{
+ setParam(param_str, Tabular::UNSET_LTHEAD, "dl_below");
if (firstheaderBorderAboveCB->isChecked())
- form_->controller().set(Tabular::SET_LTFIRSTHEAD, "dl_above");
+ setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_above");
else
- form_->controller().set(Tabular::UNSET_LTFIRSTHEAD, "dl_above");
- form_->changed();
-}
-
-
-void GuiTabularDialog::ltFirstHeaderBorderBelow_clicked()
-{
+ setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_above");
if (firstheaderBorderBelowCB->isChecked())
- form_->controller().set(Tabular::SET_LTFIRSTHEAD, "dl_below");
+ setParam(param_str, Tabular::SET_LTFIRSTHEAD, "dl_below");
else
- form_->controller().set(Tabular::UNSET_LTFIRSTHEAD, "dl_below");
- form_->changed();
-}
-
-
-void GuiTabularDialog::ltFirstHeaderStatus_clicked()
-{
- bool enable(firstheaderStatusCB->isChecked());
- if (enable)
- form_->controller().set(Tabular::SET_LTFIRSTHEAD, "");
+ setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "dl_below");
+ if (firstheaderStatusCB->isChecked())
+ setParam(param_str, Tabular::SET_LTFIRSTHEAD, "none");
else
- form_->controller().set(Tabular::UNSET_LTFIRSTHEAD, "");
- firstheaderBorderAboveCB->setEnabled(enable);
- firstheaderBorderBelowCB->setEnabled(enable);
- form_->changed();
-}
-
-
-void GuiTabularDialog::ltFirstHeaderEmpty_clicked()
-{
- bool enable(firstheaderNoContentsCB->isChecked());
- if (enable)
- form_->controller().set(Tabular::SET_LTFIRSTHEAD, "empty");
+ setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "none");
+ if (firstheaderNoContentsCB->isChecked())
+ setParam(param_str, Tabular::SET_LTFIRSTHEAD, "empty");
else
- form_->controller().set(Tabular::UNSET_LTFIRSTHEAD, "empty");
- firstheaderStatusCB->setEnabled(!enable);
- firstheaderBorderAboveCB->setEnabled(!enable);
- firstheaderBorderBelowCB->setEnabled(!enable);
- form_->changed();
-}
-
-
-void GuiTabularDialog::ltFooterStatus_clicked()
-{
- bool enable(footerStatusCB->isChecked());
- if (enable)
- form_->controller().set(Tabular::SET_LTFOOT, "");
+ setParam(param_str, Tabular::UNSET_LTFIRSTHEAD, "empty");
+ if (footerStatusCB->isChecked())
+ setParam(param_str, Tabular::SET_LTFOOT, "none");
else
- form_->controller().set(Tabular::UNSET_LTFOOT, "");
- footerBorderAboveCB->setEnabled(enable);
- footerBorderBelowCB->setEnabled(enable);
- lastfooterNoContentsCB->setEnabled(enable);
- form_->changed();
-}
-
-
-void GuiTabularDialog::ltFooterBorderAbove_clicked()
-{
+ setParam(param_str, Tabular::UNSET_LTFOOT, "none");
if (footerBorderAboveCB->isChecked())
- form_->controller().set(Tabular::SET_LTFOOT, "dl_above");
+ setParam(param_str, Tabular::SET_LTFOOT, "dl_above");
else
- form_->controller().set(Tabular::UNSET_LTFOOT, "dl_above");
- form_->changed();
-}
-
-
-void GuiTabularDialog::ltFooterBorderBelow_clicked()
-{
+ setParam(param_str, Tabular::UNSET_LTFOOT, "dl_above");
if (footerBorderBelowCB->isChecked())
- form_->controller().set(Tabular::SET_LTFOOT, "dl_below");
+ setParam(param_str, Tabular::SET_LTFOOT, "dl_below");
else
- form_->controller().set(Tabular::UNSET_LTFOOT, "dl_below");
- form_->changed();
-}
-
-
-void GuiTabularDialog::ltLastFooterStatus_clicked()
-{
- bool enable(lastfooterStatusCB->isChecked());
- if (enable)
- form_->controller().set(Tabular::SET_LTLASTFOOT, "");
+ setParam(param_str, Tabular::UNSET_LTFOOT, "dl_below");
+ if (lastfooterStatusCB->isChecked())
+ setParam(param_str, Tabular::SET_LTLASTFOOT, "none");
else
- form_->controller().set(Tabular::UNSET_LTLASTFOOT, "");
- lastfooterBorderAboveCB->setEnabled(enable);
- lastfooterBorderBelowCB->setEnabled(enable);
- form_->changed();
-}
-
-
-void GuiTabularDialog::ltLastFooterBorderAbove_clicked()
-{
+ setParam(param_str, Tabular::UNSET_LTLASTFOOT, "none");
if (lastfooterBorderAboveCB->isChecked())
- form_->controller().set(Tabular::SET_LTLASTFOOT, "dl_above");
+ setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_above");
else
- form_->controller().set(Tabular::UNSET_LTLASTFOOT, "dl_above");
- form_->changed();
-}
-
-
-void GuiTabularDialog::ltLastFooterBorderBelow_clicked()
-{
+ setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_above");
if (lastfooterBorderBelowCB->isChecked())
- form_->controller().set(Tabular::SET_LTLASTFOOT, "dl_below");
+ setParam(param_str, Tabular::SET_LTLASTFOOT, "dl_below");
else
- form_->controller().set(Tabular::UNSET_LTLASTFOOT, "dl_below");
- form_->changed();
-}
+ setParam(param_str, Tabular::UNSET_LTLASTFOOT, "dl_below");
+ if (lastfooterNoContentsCB->isChecked())
+ setParam(param_str, Tabular::SET_LTLASTFOOT, "empty");
+ else
+ setParam(param_str, Tabular::UNSET_LTLASTFOOT, "empty");
+ if (leftRB->isChecked())
+ setParam(param_str, Tabular::LONGTABULAR_ALIGN_LEFT);
+ else if (centerRB->isChecked())
+ setParam(param_str, Tabular::LONGTABULAR_ALIGN_CENTER);
+ else if (rightRB->isChecked())
+ setParam(param_str, Tabular::LONGTABULAR_ALIGN_RIGHT);
-void GuiTabularDialog::ltLastFooterEmpty_clicked()
-{
- bool enable(lastfooterNoContentsCB->isChecked());
- if (enable)
- form_->controller().set(Tabular::SET_LTLASTFOOT, "empty");
- else
- form_->controller().set(Tabular::UNSET_LTLASTFOOT, "empty");
- lastfooterStatusCB->setEnabled(!enable);
- lastfooterBorderAboveCB->setEnabled(!enable);
- lastfooterBorderBelowCB->setEnabled(!enable);
- form_->changed();
+ return from_utf8(param_str);
}
-/////////////////////////////////////////////////////////////////////
-//
-// GuiTabular
-//
-/////////////////////////////////////////////////////////////////////
+static Length getColumnPWidth(Tabular const & t, size_t cell)
+{
+ return t.column_info[t.cellColumn(cell)].p_width;
+}
-GuiTabular::GuiTabular(Dialog & parent)
- : GuiView<GuiTabularDialog>(parent, _("Table Settings"))
+static Length getMColumnPWidth(Tabular const & t, size_t cell)
{
+ if (t.isMultiColumn(cell) || t.isMultiRow(cell))
+ return t.cellInfo(cell).p_width;
+ return Length();
}
-void GuiTabular::build_dialog()
+static Length getMROffset(Tabular const & t, size_t cell)
{
- dialog_.reset(new GuiTabularDialog(this));
-
- bcview().setCancel(dialog_->closePB);
-
- bcview().addReadOnly(dialog_->topspaceED);
- bcview().addReadOnly(dialog_->topspaceUnit);
- bcview().addReadOnly(dialog_->topspaceCO);
- bcview().addReadOnly(dialog_->bottomspaceED);
- bcview().addReadOnly(dialog_->bottomspaceUnit);
- bcview().addReadOnly(dialog_->bottomspaceCO);
- bcview().addReadOnly(dialog_->interlinespaceED);
- bcview().addReadOnly(dialog_->interlinespaceUnit);
- bcview().addReadOnly(dialog_->interlinespaceCO);
- bcview().addReadOnly(dialog_->borderDefaultRB);
- bcview().addReadOnly(dialog_->booktabsRB);
-
- bcview().addReadOnly(dialog_->multicolumnCB);
- bcview().addReadOnly(dialog_->rotateCellCB);
- bcview().addReadOnly(dialog_->rotateTabularCB);
- bcview().addReadOnly(dialog_->specialAlignmentED);
- bcview().addReadOnly(dialog_->widthED);
- bcview().addReadOnly(dialog_->widthUnit);
- bcview().addReadOnly(dialog_->hAlignCB);
- bcview().addReadOnly(dialog_->vAlignCB);
- bcview().addReadOnly(dialog_->borderSetPB);
- bcview().addReadOnly(dialog_->borderUnsetPB);
- bcview().addReadOnly(dialog_->borders);
- bcview().addReadOnly(dialog_->longTabularCB);
- bcview().addReadOnly(dialog_->headerStatusCB);
- bcview().addReadOnly(dialog_->headerBorderAboveCB);
- bcview().addReadOnly(dialog_->headerBorderBelowCB);
- bcview().addReadOnly(dialog_->firstheaderStatusCB);
- bcview().addReadOnly(dialog_->firstheaderBorderAboveCB);
- bcview().addReadOnly(dialog_->firstheaderBorderBelowCB);
- bcview().addReadOnly(dialog_->firstheaderNoContentsCB);
- bcview().addReadOnly(dialog_->footerStatusCB);
- bcview().addReadOnly(dialog_->footerBorderAboveCB);
- bcview().addReadOnly(dialog_->footerBorderBelowCB);
- bcview().addReadOnly(dialog_->lastfooterStatusCB);
- bcview().addReadOnly(dialog_->lastfooterBorderAboveCB);
- bcview().addReadOnly(dialog_->lastfooterBorderBelowCB);
- bcview().addReadOnly(dialog_->lastfooterNoContentsCB);
- bcview().addReadOnly(dialog_->newpageCB);
-
- // initialize the length validator
- addCheckedLineEdit(bcview(), dialog_->widthED,
- dialog_->fixedWidthColLA);
- addCheckedLineEdit(bcview(), dialog_->topspaceED,
- dialog_->topspaceLA);
- addCheckedLineEdit(bcview(), dialog_->bottomspaceED,
- dialog_->bottomspaceLA);
- addCheckedLineEdit(bcview(), dialog_->interlinespaceED,
- dialog_->interlinespaceLA);
+ if (t.isMultiRow(cell))
+ return t.cellInfo(cell).mroffset;
+ return Length();
}
-bool GuiTabular::isValid()
+static docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
{
- return true;
+ if (what == Tabular::SET_SPECIAL_MULTICOLUMN)
+ return t.cellInfo(cell).align_special;
+ return t.column_info[t.cellColumn(cell)].align_special;
}
-void GuiTabular::update_borders()
+void GuiTabular::paramsToDialog(Inset const * inset)
{
- Tabular const & tabular = controller().tabular();
- Tabular::idx_type const cell = controller().getActiveCell();
- bool const isMulticolumnCell = tabular.isMultiColumn(cell);
-
- if (!isMulticolumnCell) {
- dialog_->borders->setLeftEnabled(true);
- dialog_->borders->setRightEnabled(true);
- dialog_->borders->setTop(tabular.topLine(cell, true));
- dialog_->borders->setBottom(tabular.bottomLine(cell, true));
- dialog_->borders->setLeft(tabular.leftLine(cell, true));
- dialog_->borders->setRight(tabular.rightLine(cell, true));
- // repaint the setborder widget
- dialog_->borders->update();
- return;
- }
+ InsetTabular const * itab = static_cast<InsetTabular const *>(inset);
+ // Copy Tabular of current inset.
+ Tabular const & tabular = itab->tabular;
- dialog_->borders->setTop(tabular.topLine(cell));
- dialog_->borders->setBottom(tabular.bottomLine(cell));
- // pay attention to left/right lines: they are only allowed
- // to set if we are in first/last cell of row or if the left/right
- // cell is also a multicolumn.
- if (tabular.isFirstCellInRow(cell) || tabular.isMultiColumn(cell - 1)) {
- dialog_->borders->setLeftEnabled(true);
- dialog_->borders->setLeft(tabular.leftLine(cell));
- } else {
- dialog_->borders->setLeft(false);
- dialog_->borders->setLeftEnabled(false);
- }
- if (tabular.isLastCellInRow(cell) || tabular.isMultiColumn(cell + 1)) {
- dialog_->borders->setRightEnabled(true);
- dialog_->borders->setRight(tabular.rightLine(cell));
- } else {
- dialog_->borders->setRight(false);
- dialog_->borders->setRightEnabled(false);
- }
- // repaint the setborder widget
- dialog_->borders->update();
-}
+ BufferView const * bv = guiApp->currentView()->currentBufferView();
+ size_t const cell = bv->cursor().idx();
+ Tabular::row_type const row = tabular.cellRow(cell);
+ Tabular::col_type const col = tabular.cellColumn(cell);
-void GuiTabular::update_contents()
-{
- controller().initialiseParams(string());
+ tabularRowED->setText(QString::number(row + 1));
+ tabularColumnED->setText(QString::number(col + 1));
- Tabular const & tabular(controller().tabular());
- Tabular::idx_type const cell = controller().getActiveCell();
+ bool const multicol = tabular.isMultiColumn(cell);
+ multicolumnCB->setChecked(multicol);
- Tabular::row_type const row(tabular.row_of_cell(cell));
- Tabular::col_type const col(tabular.column_of_cell(cell));
+ bool const multirow = tabular.isMultiRow(cell);
+ multirowCB->setChecked(multirow);
- dialog_->tabularRowED->setText(toqstr(convert<string>(row + 1)));
- dialog_->tabularColumnED->setText(toqstr(convert<string>(col + 1)));
+ rotateCellCB->setChecked(tabular.getRotateCell(cell));
+ rotateTabularCB->setChecked(tabular.rotate);
- bool const multicol(tabular.isMultiColumn(cell));
+ longTabularCB->setChecked(tabular.is_long_tabular);
- dialog_->multicolumnCB->setChecked(multicol);
+ borders->setTop(tabular.topLine(cell));
+ borders->setBottom(tabular.bottomLine(cell));
+ borders->setLeft(tabular.leftLine(cell));
+ borders->setRight(tabular.rightLine(cell));
+ // repaint the setborder widget
+ borders->update();
- dialog_->rotateCellCB->setChecked(tabular.getRotateCell(cell));
- dialog_->rotateTabularCB->setChecked(tabular.getRotateTabular());
+ Length::UNIT const default_unit = Length::defaultUnit();
- dialog_->longTabularCB->setChecked(tabular.isLongTabular());
+ ///////////////////////////////////
+ // Set width and alignment
- update_borders();
+ Length const tabwidth = tabular.tabularWidth();
+ if (tabwidth.zero())
+ tabularWidthED->clear();
+ else
+ lengthToWidgets(tabularWidthED, tabularWidthUnitLC,
+ tabwidth.asString(), default_unit);
Length pwidth;
docstring special;
-
if (multicol) {
- special = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_MULTI);
- pwidth = tabular.getMColumnPWidth(cell);
+ special = getAlignSpecial(tabular, cell,
+ Tabular::SET_SPECIAL_MULTICOLUMN);
+ pwidth = getMColumnPWidth(tabular, cell);
} else {
- special = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_COLUMN);
- pwidth = tabular.getColumnPWidth(cell);
+ special = getAlignSpecial(tabular, cell,
+ Tabular::SET_SPECIAL_COLUMN);
+ pwidth = getColumnPWidth(tabular, cell);
}
+ string colwidth;
+ if (pwidth.zero())
+ columnWidthED->clear();
+ else {
+ colwidth = pwidth.asString();
+ lengthToWidgets(columnWidthED, columnWidthUnitLC,
+ colwidth, default_unit);
+ }
+ Length mroffset;
+ if (multirow)
+ mroffset = getMROffset(tabular, cell);
+ string offset;
+ if (mroffset.zero())
+ multirowOffsetED->clear();
+ else {
+ offset = mroffset.asString();
+ lengthToWidgets(multirowOffsetED, multirowOffsetUnitLC,
+ offset, default_unit);
+ }
+ specialAlignmentED->setText(toqstr(special));
+ ///////////////////////////////////
- dialog_->specialAlignmentED->setText(toqstr(special));
-
- bool const isReadonly = bc().policy().isReadOnly();
- dialog_->specialAlignmentED->setEnabled(!isReadonly);
-
- Length::UNIT default_unit = controller().useMetricUnits() ? Length::CM : Length::IN;
- dialog_->borderDefaultRB->setChecked(!tabular.useBookTabs());
- dialog_->booktabsRB->setChecked(tabular.useBookTabs());
+ borderDefaultRB->setChecked(!tabular.use_booktabs);
+ booktabsRB->setChecked(tabular.use_booktabs);
if (tabular.row_info[row].top_space.empty()
&& !tabular.row_info[row].top_space_default) {
- dialog_->topspaceCO->setCurrentIndex(0);
+ topspaceCO->setCurrentIndex(0);
} else if (tabular.row_info[row].top_space_default) {
- dialog_->topspaceCO->setCurrentIndex(1);
+ topspaceCO->setCurrentIndex(1);
} else {
- dialog_->topspaceCO->setCurrentIndex(2);
- lengthToWidgets(dialog_->topspaceED,
- dialog_->topspaceUnit,
+ topspaceCO->setCurrentIndex(2);
+ lengthToWidgets(topspaceED,
+ topspaceUnitLC,
tabular.row_info[row].top_space.asString(),
default_unit);
}
- dialog_->topspaceED->setEnabled(!isReadonly
- && (dialog_->topspaceCO->currentIndex() == 2));
- dialog_->topspaceUnit->setEnabled(!isReadonly
- && (dialog_->topspaceCO->currentIndex() == 2));
- dialog_->topspaceCO->setEnabled(!isReadonly);
if (tabular.row_info[row].bottom_space.empty()
&& !tabular.row_info[row].bottom_space_default) {
- dialog_->bottomspaceCO->setCurrentIndex(0);
+ bottomspaceCO->setCurrentIndex(0);
} else if (tabular.row_info[row].bottom_space_default) {
- dialog_->bottomspaceCO->setCurrentIndex(1);
+ bottomspaceCO->setCurrentIndex(1);
} else {
- dialog_->bottomspaceCO->setCurrentIndex(2);
- lengthToWidgets(dialog_->bottomspaceED,
- dialog_->bottomspaceUnit,
+ bottomspaceCO->setCurrentIndex(2);
+ lengthToWidgets(bottomspaceED,
+ bottomspaceUnitLC,
tabular.row_info[row].bottom_space.asString(),
default_unit);
}
- dialog_->bottomspaceED->setEnabled(!isReadonly
- && (dialog_->bottomspaceCO->currentIndex() == 2));
- dialog_->bottomspaceUnit->setEnabled(!isReadonly
- && (dialog_->bottomspaceCO->currentIndex() == 2));
- dialog_->bottomspaceCO->setEnabled(!isReadonly);
if (tabular.row_info[row].interline_space.empty()
&& !tabular.row_info[row].interline_space_default) {
- dialog_->interlinespaceCO->setCurrentIndex(0);
+ interlinespaceCO->setCurrentIndex(0);
} else if (tabular.row_info[row].interline_space_default) {
- dialog_->interlinespaceCO->setCurrentIndex(1);
+ interlinespaceCO->setCurrentIndex(1);
} else {
- dialog_->interlinespaceCO->setCurrentIndex(2);
- lengthToWidgets(dialog_->interlinespaceED,
- dialog_->interlinespaceUnit,
+ interlinespaceCO->setCurrentIndex(2);
+ lengthToWidgets(interlinespaceED,
+ interlinespaceUnitLC,
tabular.row_info[row].interline_space.asString(),
default_unit);
}
- dialog_->interlinespaceED->setEnabled(!isReadonly
- && (dialog_->interlinespaceCO->currentIndex() == 2));
- dialog_->interlinespaceUnit->setEnabled(!isReadonly
- && (dialog_->interlinespaceCO->currentIndex() == 2));
- dialog_->interlinespaceCO->setEnabled(!isReadonly);
-
- string colwidth;
- if (!pwidth.zero())
- colwidth = pwidth.asString();
- lengthToWidgets(dialog_->widthED, dialog_->widthUnit,
- colwidth, default_unit);
- dialog_->widthED->setEnabled(!isReadonly);
- dialog_->widthUnit->setEnabled(!isReadonly);
-
- dialog_->hAlignCB->clear();
- dialog_->hAlignCB->addItem(qt_("Left"));
- dialog_->hAlignCB->addItem(qt_("Center"));
- dialog_->hAlignCB->addItem(qt_("Right"));
+ hAlignCO->clear();
+ hAlignCO->addItem(qt_("Left"), toqstr("left"));
+ hAlignCO->addItem(qt_("Center"), toqstr("center"));
+ hAlignCO->addItem(qt_("Right"), toqstr("right"));
if (!multicol && !pwidth.zero())
- dialog_->hAlignCB->addItem(qt_("Justified"));
+ hAlignCO->addItem(qt_("Justified"), toqstr("justified"));
+ if (!multicol)
+ hAlignCO->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
- int align = 0;
+ string align;
switch (tabular.getAlignment(cell)) {
- case LYX_ALIGN_LEFT:
- align = 0;
- break;
- case LYX_ALIGN_CENTER:
- align = 1;
- break;
- case LYX_ALIGN_RIGHT:
- align = 2;
- break;
- case LYX_ALIGN_BLOCK:
- {
- if (!multicol && !pwidth.zero())
- align = 3;
- break;
- }
- default:
- align = 0;
- break;
+ case LYX_ALIGN_LEFT:
+ align = "left";
+ break;
+ case LYX_ALIGN_CENTER:
+ align = "center";
+ break;
+ case LYX_ALIGN_RIGHT:
+ align = "right";
+ break;
+ case LYX_ALIGN_BLOCK:
+ {
+ if (!multicol && !pwidth.zero())
+ align = "justified";
+ break;
+ }
+ case LYX_ALIGN_DECIMAL:
+ {
+ if (!multicol)
+ align = "decimal";
+ break;
+ }
+ default:
+ // we should never end up here
+ break;
}
- dialog_->hAlignCB->setCurrentIndex(align);
+ hAlignCO->setCurrentIndex(hAlignCO->findData(toqstr(align)));
+
+ //
+ QString decimal_point = toqstr(tabular.column_info[col].decimal_point);
+ if (decimal_point.isEmpty())
+ decimal_point = toqstr(from_utf8(lyxrc.default_decimal_point));
+ decimalPointED->setText(decimal_point);
int valign = 0;
switch (tabular.getVAlignment(cell)) {
valign = 2;
break;
default:
- valign = 1;
+ valign = 0;
break;
}
if (pwidth.zero())
- valign = 1;
- dialog_->vAlignCB->setCurrentIndex(valign);
-
- dialog_->hAlignCB->setEnabled(true);
- dialog_->vAlignCB->setEnabled(!pwidth.zero());
-
- if (!tabular.isLongTabular()) {
- dialog_->headerStatusCB->setChecked(false);
- dialog_->headerBorderAboveCB->setChecked(false);
- dialog_->headerBorderBelowCB->setChecked(false);
- dialog_->firstheaderStatusCB->setChecked(false);
- dialog_->firstheaderBorderAboveCB->setChecked(false);
- dialog_->firstheaderBorderBelowCB->setChecked(false);
- dialog_->firstheaderNoContentsCB->setChecked(false);
- dialog_->footerStatusCB->setChecked(false);
- dialog_->footerBorderAboveCB->setChecked(false);
- dialog_->footerBorderBelowCB->setChecked(false);
- dialog_->lastfooterStatusCB->setChecked(false);
- dialog_->lastfooterBorderAboveCB->setChecked(false);
- dialog_->lastfooterBorderBelowCB->setChecked(false);
- dialog_->lastfooterNoContentsCB->setChecked(false);
- dialog_->newpageCB->setChecked(false);
- dialog_->newpageCB->setEnabled(false);
+ valign = 0;
+ vAlignCO->setCurrentIndex(valign);
+
+ int tableValign = 1;
+ switch (tabular.tabular_valignment) {
+ case Tabular::LYX_VALIGN_TOP:
+ tableValign = 0;
+ break;
+ case Tabular::LYX_VALIGN_MIDDLE:
+ tableValign = 1;
+ break;
+ case Tabular::LYX_VALIGN_BOTTOM:
+ tableValign = 2;
+ break;
+ default:
+ tableValign = 0;
+ break;
+ }
+ TableAlignCO->setCurrentIndex(tableValign);
+
+ if (!tabular.is_long_tabular) {
+ headerStatusCB->setChecked(false);
+ headerBorderAboveCB->setChecked(false);
+ headerBorderBelowCB->setChecked(false);
+ firstheaderStatusCB->setChecked(false);
+ firstheaderBorderAboveCB->setChecked(false);
+ firstheaderBorderBelowCB->setChecked(false);
+ firstheaderNoContentsCB->setChecked(false);
+ footerStatusCB->setChecked(false);
+ footerBorderAboveCB->setChecked(false);
+ footerBorderBelowCB->setChecked(false);
+ lastfooterStatusCB->setChecked(false);
+ lastfooterBorderAboveCB->setChecked(false);
+ lastfooterBorderBelowCB->setChecked(false);
+ lastfooterNoContentsCB->setChecked(false);
+ newpageCB->setChecked(false);
+ captionStatusCB->blockSignals(true);
+ captionStatusCB->setChecked(false);
+ captionStatusCB->blockSignals(false);
+ checkEnabled();
return;
+ } else {
+ // longtables cannot have a vertical alignment
+ TableAlignCO->setCurrentIndex(Tabular::LYX_VALIGN_MIDDLE);
+ }
+ switch (tabular.longtabular_alignment) {
+ case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
+ leftRB->setChecked(true);
+ break;
+ case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
+ centerRB->setChecked(true);
+ break;
+ case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
+ rightRB->setChecked(true);
+ break;
+ default:
+ centerRB->setChecked(true);
+ break;
}
+ captionStatusCB->blockSignals(true);
+ captionStatusCB->setChecked(tabular.ltCaption(row));
+ captionStatusCB->blockSignals(false);
Tabular::ltType ltt;
bool use_empty;
bool row_set = tabular.getRowOfLTHead(row, ltt);
- dialog_->headerStatusCB->setChecked(row_set);
+ headerStatusCB->setChecked(row_set);
if (ltt.set) {
- dialog_->headerBorderAboveCB->setChecked(ltt.topDL);
- dialog_->headerBorderBelowCB->setChecked(ltt.bottomDL);
+ headerBorderAboveCB->setChecked(ltt.topDL);
+ headerBorderBelowCB->setChecked(ltt.bottomDL);
use_empty = true;
} else {
- dialog_->headerBorderAboveCB->setChecked(false);
- dialog_->headerBorderBelowCB->setChecked(false);
- dialog_->headerBorderAboveCB->setEnabled(false);
- dialog_->headerBorderBelowCB->setEnabled(false);
- dialog_->firstheaderNoContentsCB->setChecked(false);
- dialog_->firstheaderNoContentsCB->setEnabled(false);
+ headerBorderAboveCB->setChecked(false);
+ headerBorderBelowCB->setChecked(false);
+ firstheaderNoContentsCB->setChecked(false);
use_empty = false;
}
row_set = tabular.getRowOfLTFirstHead(row, ltt);
- dialog_->firstheaderStatusCB->setChecked(row_set);
+ firstheaderStatusCB->setChecked(row_set);
if (ltt.set && (!ltt.empty || !use_empty)) {
- dialog_->firstheaderBorderAboveCB->setChecked(ltt.topDL);
- dialog_->firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
+ firstheaderBorderAboveCB->setChecked(ltt.topDL);
+ firstheaderBorderBelowCB->setChecked(ltt.bottomDL);
} else {
- dialog_->firstheaderBorderAboveCB->setEnabled(false);
- dialog_->firstheaderBorderBelowCB->setEnabled(false);
- dialog_->firstheaderBorderAboveCB->setChecked(false);
- dialog_->firstheaderBorderBelowCB->setChecked(false);
- if (use_empty) {
- dialog_->firstheaderNoContentsCB->setChecked(ltt.empty);
- if (ltt.empty)
- dialog_->firstheaderStatusCB->setEnabled(false);
- }
+ firstheaderBorderAboveCB->setChecked(false);
+ firstheaderBorderBelowCB->setChecked(false);
}
row_set = tabular.getRowOfLTFoot(row, ltt);
- dialog_->footerStatusCB->setChecked(row_set);
+ footerStatusCB->setChecked(row_set);
if (ltt.set) {
- dialog_->footerBorderAboveCB->setChecked(ltt.topDL);
- dialog_->footerBorderBelowCB->setChecked(ltt.bottomDL);
+ footerBorderAboveCB->setChecked(ltt.topDL);
+ footerBorderBelowCB->setChecked(ltt.bottomDL);
use_empty = true;
} else {
- dialog_->footerBorderAboveCB->setChecked(false);
- dialog_->footerBorderBelowCB->setChecked(false);
- dialog_->footerBorderAboveCB->setEnabled(false);
- dialog_->footerBorderBelowCB->setEnabled(false);
- dialog_->lastfooterNoContentsCB->setChecked(false);
- dialog_->lastfooterNoContentsCB->setEnabled(false);
+ footerBorderAboveCB->setChecked(false);
+ footerBorderBelowCB->setChecked(false);
+ lastfooterNoContentsCB->setChecked(false);
use_empty = false;
}
row_set = tabular.getRowOfLTLastFoot(row, ltt);
- dialog_->lastfooterStatusCB->setChecked(row_set);
+ lastfooterStatusCB->setChecked(row_set);
if (ltt.set && (!ltt.empty || !use_empty)) {
- dialog_->lastfooterBorderAboveCB->setChecked(ltt.topDL);
- dialog_->lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
+ lastfooterBorderAboveCB->setChecked(ltt.topDL);
+ lastfooterBorderBelowCB->setChecked(ltt.bottomDL);
} else {
- dialog_->lastfooterBorderAboveCB->setEnabled(false);
- dialog_->lastfooterBorderBelowCB->setEnabled(false);
- dialog_->lastfooterBorderAboveCB->setChecked(false);
- dialog_->lastfooterBorderBelowCB->setChecked(false);
- if (use_empty) {
- dialog_->lastfooterNoContentsCB->setChecked(ltt.empty);
- if (ltt.empty)
- dialog_->lastfooterStatusCB->setEnabled(false);
- }
- }
- dialog_->newpageCB->setChecked(tabular.getLTNewPage(row));
-}
-
-
-void GuiTabular::closeGUI()
-{
- // ugly hack to auto-apply the stuff that hasn't been
- // yet. don't let this continue to exist ...
-
- // Subtle here, we must /not/ apply any changes and
- // then refer to tabular, as it will have been freed
- // since the changes update the actual controller().tabular()
- Tabular const & tabular(controller().tabular());
-
- // apply the fixed width values
- Tabular::idx_type const cell = controller().getActiveCell();
- bool const multicol = tabular.isMultiColumn(cell);
- string width = widgetsToLength(dialog_->widthED, dialog_->widthUnit);
- string width2;
-
- Length llen = tabular.getColumnPWidth(cell);
- Length llenMulti = tabular.getMColumnPWidth(cell);
-
- if (multicol && !llenMulti.zero())
- width2 = llenMulti.asString();
- else if (!multicol && !llen.zero())
- width2 = llen.asString();
-
- // apply the special alignment
- docstring const sa1 = qstring_to_ucs4(dialog_->specialAlignmentED->text());
- docstring sa2;
-
- if (multicol)
- sa2 = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_MULTI);
- else
- sa2 = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_COLUMN);
-
- if (sa1 != sa2) {
- if (multicol)
- controller().set(Tabular::SET_SPECIAL_MULTI, to_utf8(sa1));
- else
- controller().set(Tabular::SET_SPECIAL_COLUMN, to_utf8(sa1));
+ lastfooterBorderAboveCB->setChecked(false);
+ lastfooterBorderBelowCB->setChecked(false);
}
+ newpageCB->setChecked(tabular.getLTNewPage(row));
- if (width != width2) {
- if (multicol)
- controller().set(Tabular::SET_MPWIDTH, width);
- else
- controller().set(Tabular::SET_PWIDTH, width);
- }
+ // first header can only be suppressed when there is a header
+ firstheader_suppressable_ = tabular.haveLTHead()
+ && !tabular.haveLTFirstHead();
+ // last footer can only be suppressed when there is a footer
+ lastfooter_suppressable_ = tabular.haveLTFoot()
+ && !tabular.haveLTLastFoot();
- /* DO WE NEED THIS?
- switch (dialog_->topspaceCO->currentIndex()) {
- case 0:
- controller().set(Tabular::SET_TOP_SPACE, "");
- break;
- case 1:
- controller().set(Tabular::SET_TOP_SPACE, "default");
- break;
- case 2:
- controller().set(Tabular::SET_TOP_SPACE,
- widgetsToLength(dialog_->topspaceED,
- dialog_->topspaceUnit));
- break;
- }
+ // after setting the features, check if they are enabled
+ checkEnabled();
+}
- switch (dialog_->bottomspaceCO->currentIndex()) {
- case 0:
- controller().set(Tabular::SET_BOTTOM_SPACE, "");
- break;
- case 1:
- controller().set(Tabular::SET_BOTTOM_SPACE, "default");
- break;
- case 2:
- controller().set(Tabular::SET_BOTTOM_SPACE,
- widgetsToLength(dialog_->bottomspaceED,
- dialog_->bottomspaceUnit));
- break;
- }
- switch (dialog_->interlinespaceCO->currentIndex()) {
- case 0:
- controller().set(Tabular::SET_INTERLINE_SPACE, "");
- break;
- case 1:
- controller().set(Tabular::SET_INTERLINE_SPACE, "default");
- break;
- case 2:
- controller().set(Tabular::SET_INTERLINE_SPACE,
- widgetsToLength(dialog_->interlinespaceED,
- dialog_->interlinespaceUnit));
- break;
- }
-*/
+bool GuiTabular::funcEnabled(Tabular::Feature f) const
+{
+ string cmd = "tabular " + featureAsString(f);
+ return getStatus(FuncRequest(LFUN_INSET_MODIFY, cmd)).enabled();
}
+
} // namespace frontend
} // namespace lyx
-#include "GuiTabular_moc.cpp"
+#include "moc_GuiTabular.cpp"