X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiTabular.cpp;h=2a6a26bb3aa7b86aa0b6154e938eab4bc45e0d12;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=68df6cd1998bed8f62a65b45155311aa398c1d15;hpb=34492a9d033aef3d4369d4d758b01f3969ef3af0;p=lyx.git diff --git a/src/frontends/qt4/GuiTabular.cpp b/src/frontends/qt4/GuiTabular.cpp index 68df6cd199..2a6a26bb3a 100644 --- a/src/frontends/qt4/GuiTabular.cpp +++ b/src/frontends/qt4/GuiTabular.cpp @@ -4,8 +4,9 @@ * 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. */ @@ -14,91 +15,154 @@ #include "GuiTabular.h" -#include "ControlTabular.h" #include "GuiSetBorder.h" +#include "GuiView.h" #include "LengthCombo.h" -#include "Validator.h" #include "qt_helpers.h" +#include "Validator.h" + +#include "BufferView.h" +#include "Cursor.h" +#include "FuncRequest.h" +#include "FuncStatus.h" +#include "LyXFunc.h" -#include "support/convert.h" +#include "insets/InsetTabular.h" -#include #include #include #include #include -using std::string; - +using namespace std; namespace lyx { namespace frontend { -GuiTabularDialog::GuiTabularDialog(LyXView & lv) - : GuiDialog(lv, "tabular") +GuiTabular::GuiTabular(GuiView & lv) + : GuiDialog(lv, "tabular", qt_("Table Settings")), + // tabular_ is initialised at dialog construction in initialiseParams() + tabular_(&(lv.currentBufferView()->buffer()), 0, 0), + applying_(false) { + active_cell_ = Tabular::npos; + setupUi(this); - setViewTitle(_("Table Settings")); - setController(new ControlTabular(*this)); + + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); + connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore())); + + // Manage the restore, ok, apply, restore and cancel/close buttons + bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); + bc().setOK(okPB); + bc().setApply(applyPB); + bc().setCancel(closePB); + bc().setRestore(restorePB); widthED->setValidator(unsignedLengthValidator(widthED)); topspaceED->setValidator(new LengthValidator(topspaceED)); bottomspaceED->setValidator(new LengthValidator(bottomspaceED)); interlinespaceED->setValidator(new LengthValidator(interlinespaceED)); - connect(topspaceED, SIGNAL(returnPressed()), - this, SLOT(topspace_changed())); + widthUnitCB->setCurrentItem(Length::defaultUnit()); + + connect(topspaceED, SIGNAL(textChanged(QString)), + this, SLOT(change_adaptor())); connect(topspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)), + this, SLOT(change_adaptor())); + connect(topspaceCO, SIGNAL(activated(int)), this, SLOT(topspace_changed())); - connect(topspaceCO, SIGNAL(activated(int)), this, SLOT(topspace_changed())); - connect(bottomspaceED, SIGNAL(returnPressed()), - this, SLOT(bottomspace_changed())); + connect(bottomspaceED, SIGNAL(textChanged(QString)), + this, SLOT(change_adaptor())); connect(bottomspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)), + this, SLOT(change_adaptor())); + connect(bottomspaceCO, SIGNAL(activated(int)), this, SLOT(bottomspace_changed())); - connect(bottomspaceCO, SIGNAL(activated(int)), this, SLOT(bottomspace_changed())); - connect(interlinespaceED, SIGNAL(returnPressed()), - this, SLOT(interlinespace_changed())); + connect(interlinespaceED, SIGNAL(textChanged(QString)), + this, SLOT(change_adaptor())); connect(interlinespaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)), + this, SLOT(change_adaptor())); + connect(interlinespaceCO, SIGNAL(activated(int)), 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())); - - bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); - bc().setCancel(closePB); + 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(longTabularCB, SIGNAL(toggled(bool)), + alignmentGB, SLOT(setEnabled(bool))); + // longtables cannot have a vertical alignment + connect(longTabularCB, SIGNAL(toggled(bool)), + TableAlignCB, SLOT(setDisabled(bool))); + connect(hAlignCB, SIGNAL(activated(int)), + this, SLOT(change_adaptor())); + connect(vAlignCB, SIGNAL(activated(int)), + this, SLOT(change_adaptor())); + connect(multicolumnCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(newpageCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(captionStatusCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(headerStatusCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(headerBorderAboveCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(headerBorderBelowCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(firstheaderStatusCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(firstheaderBorderAboveCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(firstheaderBorderBelowCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(firstheaderNoContentsCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(footerStatusCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(footerBorderAboveCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(footerBorderBelowCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(lastfooterStatusCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(lastfooterBorderAboveCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(lastfooterBorderBelowCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(lastfooterNoContentsCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(specialAlignmentED, SIGNAL(textChanged(QString)), + this, SLOT(change_adaptor())); + connect(widthED, SIGNAL(textChanged(QString)), + this, SLOT(change_adaptor())); + connect(widthUnitCB, SIGNAL(selectionChanged(lyx::Length::UNIT)), + this, SLOT(change_adaptor())); + connect(borders, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(rotateTabularCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(rotateCellCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(TableAlignCB, SIGNAL(activated(int)), + this, SLOT(change_adaptor())); + connect(longTabularCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(leftRB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(centerRB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(rightRB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); bc().addReadOnly(topspaceED); bc().addReadOnly(topspaceUnit); @@ -117,9 +181,10 @@ GuiTabularDialog::GuiTabularDialog(LyXView & lv) bc().addReadOnly(rotateTabularCB); bc().addReadOnly(specialAlignmentED); bc().addReadOnly(widthED); - bc().addReadOnly(widthUnit); + bc().addReadOnly(widthUnitCB); bc().addReadOnly(hAlignCB); bc().addReadOnly(vAlignCB); + bc().addReadOnly(TableAlignCB); bc().addReadOnly(borderSetPB); bc().addReadOnly(borderUnsetPB); bc().addReadOnly(borders); @@ -139,7 +204,10 @@ GuiTabularDialog::GuiTabularDialog(LyXView & lv) bc().addReadOnly(lastfooterBorderBelowCB); bc().addReadOnly(lastfooterNoContentsCB); bc().addReadOnly(newpageCB); - + bc().addReadOnly(leftRB); + bc().addReadOnly(centerRB); + bc().addReadOnly(rightRB); + // initialize the length validator bc().addCheckedLineEdit(widthED, fixedWidthColLA); bc().addCheckedLineEdit(topspaceED, topspaceLA); @@ -148,52 +216,31 @@ GuiTabularDialog::GuiTabularDialog(LyXView & lv) } -ControlTabular & GuiTabularDialog::controller() const -{ - return static_cast(GuiDialog::controller()); -} - - -void GuiTabularDialog::change_adaptor() +GuiTabular::~GuiTabular() { - changed(); } -void GuiTabularDialog::closeEvent(QCloseEvent * e) -{ - slotClose(); - e->accept(); -} - - -void GuiTabularDialog::booktabsChanged(bool) +void GuiTabular::change_adaptor() { changed(); - controller().booktabs(booktabsRB->isChecked()); - update_borders(); } -void GuiTabularDialog::topspace_changed() +void GuiTabular::topspace_changed() { - switch(topspaceCO->currentIndex()) { + switch (topspaceCO->currentIndex()) { case 0: { - controller().set(Tabular::SET_TOP_SPACE, ""); - topspaceED->setEnabled(false); - topspaceUnit->setEnabled(false); + topspaceED->setEnabled(false); + topspaceUnit->setEnabled(false); break; } case 1: { - controller().set(Tabular::SET_TOP_SPACE, "default"); topspaceED->setEnabled(false); topspaceUnit->setEnabled(false); break; } case 2: { - if (!topspaceED->text().isEmpty()) - controller().set(Tabular::SET_TOP_SPACE, - widgetsToLength(topspaceED, topspaceUnit)); if (!bc().policy().isReadOnly()) { topspaceED->setEnabled(true); topspaceUnit->setEnabled(true); @@ -205,25 +252,20 @@ void GuiTabularDialog::topspace_changed() } -void GuiTabularDialog::bottomspace_changed() +void GuiTabular::bottomspace_changed() { - switch(bottomspaceCO->currentIndex()) { + switch (bottomspaceCO->currentIndex()) { case 0: { - controller().set(Tabular::SET_BOTTOM_SPACE, ""); - bottomspaceED->setEnabled(false); - bottomspaceUnit->setEnabled(false); + bottomspaceED->setEnabled(false); + bottomspaceUnit->setEnabled(false); break; } case 1: { - controller().set(Tabular::SET_BOTTOM_SPACE, "default"); bottomspaceED->setEnabled(false); bottomspaceUnit->setEnabled(false); break; } case 2: { - if (!bottomspaceED->text().isEmpty()) - controller().set(Tabular::SET_BOTTOM_SPACE, - widgetsToLength(bottomspaceED, bottomspaceUnit)); if (!bc().policy().isReadOnly()) { bottomspaceED->setEnabled(true); bottomspaceUnit->setEnabled(true); @@ -235,25 +277,20 @@ void GuiTabularDialog::bottomspace_changed() } -void GuiTabularDialog::interlinespace_changed() +void GuiTabular::interlinespace_changed() { - switch(interlinespaceCO->currentIndex()) { + switch (interlinespaceCO->currentIndex()) { case 0: { - controller().set(Tabular::SET_INTERLINE_SPACE, ""); - interlinespaceED->setEnabled(false); - interlinespaceUnit->setEnabled(false); + interlinespaceED->setEnabled(false); + interlinespaceUnit->setEnabled(false); break; } case 1: { - controller().set(Tabular::SET_INTERLINE_SPACE, "default"); interlinespaceED->setEnabled(false); interlinespaceUnit->setEnabled(false); break; } case 2: { - if (!interlinespaceED->text().isEmpty()) - controller().set(Tabular::SET_INTERLINE_SPACE, - widgetsToLength(interlinespaceED, interlinespaceUnit)); if (!bc().policy().isReadOnly()) { interlinespaceED->setEnabled(true); interlinespaceUnit->setEnabled(true); @@ -265,362 +302,360 @@ void GuiTabularDialog::interlinespace_changed() } -void GuiTabularDialog::close_clicked() +void GuiTabular::booktabsChanged(bool) { - closeGUI(); - slotClose(); -} - - -void GuiTabularDialog::borderSet_clicked() -{ - controller().set(Tabular::SET_ALL_LINES); - update_borders(); - changed(); -} - - -void GuiTabularDialog::borderUnset_clicked() -{ - controller().set(Tabular::UNSET_ALL_LINES); - update_borders(); + if (booktabsRB->isChecked()) { + borders->setLeft(false); + borders->setRight(false); + borders->setLeftEnabled(false); + borders->setRightEnabled(false); + } else { + borders->setLeftEnabled(true); + borders->setRightEnabled(true); + } + // repaint the setborder widget + borders->update(); changed(); } -void GuiTabularDialog::leftBorder_changed() +void GuiTabular::borderSet_clicked() { - controller().toggleLeftLine(); + borders->setTop(true); + borders->setBottom(true); + borders->setLeft(true); + borders->setRight(true); + // repaint the setborder widget + borders->update(); changed(); } -void GuiTabularDialog::rightBorder_changed() +void GuiTabular::borderUnset_clicked() { - controller().toggleRightLine(); + borders->setTop(false); + borders->setBottom(false); + borders->setLeft(false); + borders->setRight(false); + // repaint the setborder widget + borders->update(); changed(); } -void GuiTabularDialog::topBorder_changed() +void GuiTabular::update_borders() { - controller().toggleTopLine(); - changed(); + Tabular::idx_type const cell = getActiveCell(); + borders->setTop(tabular_.topLine(cell)); + borders->setBottom(tabular_.bottomLine(cell)); + borders->setLeft(tabular_.leftLine(cell)); + borders->setRight(tabular_.rightLine(cell)); + borders->setLeftEnabled(!booktabsRB->isChecked()); + borders->setRightEnabled(!booktabsRB->isChecked()); + // repaint the setborder widget + borders->update(); } -void GuiTabularDialog::bottomBorder_changed() -{ - controller().toggleBottomLine(); - changed(); -} +namespace { - -void GuiTabularDialog::specialAlignment_changed() +Length getColumnPWidth(Tabular const & t, size_t cell) { - string special = fromqstr(specialAlignmentED->text()); - controller().setSpecial(special); - changed(); + return t.column_info[t.cellColumn(cell)].p_width; } -void GuiTabularDialog::width_changed() +Length getMColumnPWidth(Tabular const & t, size_t cell) { - changed(); - string const width = widgetsToLength(widthED, widthUnit); - controller().setWidth(width); + if (t.isMultiColumn(cell)) + return t.cellInfo(cell).p_width; + return Length(); } -void GuiTabularDialog::multicolumn_clicked() +docstring getAlignSpecial(Tabular const & t, size_t cell, int what) { - controller().toggleMultiColumn(); - changed(); + if (what == Tabular::SET_SPECIAL_MULTI) + return t.cellInfo(cell).align_special; + return t.column_info[t.cellColumn(cell)].align_special; } - -void GuiTabularDialog::rotateTabular() -{ - controller().rotateTabular(rotateTabularCB->isChecked()); - changed(); } -void GuiTabularDialog::rotateCell() +void GuiTabular::applyView() { - controller().rotateCell(rotateCellCB->isChecked()); - changed(); -} + applying_ = true; + Tabular::idx_type const cell = getActiveCell(); + Tabular::row_type const row = tabular_.cellRow(cell); + bool const multicol = tabular_.isMultiColumn(cell); -void GuiTabularDialog::hAlign_changed(int align) -{ - ControlTabular::HALIGN h = ControlTabular::LEFT; + Tabular::Feature num = Tabular::ALIGN_LEFT; + Tabular::Feature multi_num = Tabular::M_ALIGN_LEFT; - 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 (hAlignCB->currentIndex()) { + case 0: + num = Tabular::ALIGN_LEFT; + multi_num = Tabular::M_ALIGN_LEFT; + break; + case 1: + num = Tabular::ALIGN_CENTER; + multi_num = Tabular::M_ALIGN_CENTER; + break; + case 2: + num = Tabular::ALIGN_RIGHT; + multi_num = Tabular::M_ALIGN_RIGHT; + break; + case 3: + num = Tabular::ALIGN_BLOCK; + //multi_num: no equivalent + break; } + if (multicol) + set(multi_num); + else + set(num); - controller().halign(h); -} - - -void GuiTabularDialog::vAlign_changed(int align) -{ - ControlTabular::VALIGN v = ControlTabular::TOP; + num = Tabular::VALIGN_MIDDLE; + multi_num = Tabular::M_VALIGN_MIDDLE; - switch (align) { - case 0: v = ControlTabular::TOP; break; - case 1: v = ControlTabular::MIDDLE; break; - case 2: v = ControlTabular::BOTTOM; break; + switch (vAlignCB->currentIndex()) { + case 0: + num = Tabular::VALIGN_TOP; + multi_num = Tabular::M_VALIGN_TOP; + break; + case 1: + num = Tabular::VALIGN_MIDDLE; + multi_num = Tabular::M_VALIGN_MIDDLE; + break; + case 2: + num = Tabular::VALIGN_BOTTOM; + multi_num = Tabular::M_VALIGN_BOTTOM; + break; } + if (multicol) + set(multi_num); + else + set(num); - controller().valign(v); -} + switch (TableAlignCB->currentIndex()) { + case 0: + set(Tabular::TABULAR_VALIGN_TOP); + break; + case 1: + set(Tabular::TABULAR_VALIGN_MIDDLE); + break; + case 2: + set(Tabular::TABULAR_VALIGN_BOTTOM); + break; + } + string value; -void GuiTabularDialog::longTabular() -{ - controller().longTabular(longTabularCB->isChecked()); - changed(); -} + value = fromqstr(specialAlignmentED->text()); + if (multicol) + set(Tabular::SET_SPECIAL_MULTI, value); + else + set(Tabular::SET_SPECIAL_COLUMN, value); + value = widgetsToLength(widthED, widthUnitCB); + if (multicol) + set(Tabular::SET_MPWIDTH, value); + else + set(Tabular::SET_PWIDTH, value); -void GuiTabularDialog::ltNewpage_clicked() -{ - controller().set(Tabular::SET_LTNEWPAGE); - changed(); -} + if (multicolumnCB->isChecked() != multicol) + set(Tabular::MULTICOLUMN);; + if (rotateTabularCB->isChecked()) + set(Tabular::SET_ROTATE_TABULAR); + else + set(Tabular::UNSET_ROTATE_TABULAR); -void GuiTabularDialog::ltHeaderStatus_clicked() -{ - bool enable(headerStatusCB->isChecked()); - if (enable) - controller().set(Tabular::SET_LTHEAD, ""); + if (rotateCellCB->isChecked()) + set(Tabular::SET_ROTATE_CELL); else - controller().set(Tabular::UNSET_LTHEAD, ""); - headerBorderAboveCB->setEnabled(enable); - headerBorderBelowCB->setEnabled(enable); - firstheaderNoContentsCB->setEnabled(enable); - changed(); -} + set(Tabular::UNSET_ROTATE_CELL); + + // Borders + if (borders->getLeft() != tabular_.leftLine(cell)) + set(Tabular::TOGGLE_LINE_LEFT); + if (borders->getRight() != tabular_.rightLine(cell)) + set(Tabular::TOGGLE_LINE_RIGHT); + if (borders->getTop() != tabular_.topLine(cell)) + set(Tabular::TOGGLE_LINE_TOP); + if (borders->getBottom() != tabular_.bottomLine(cell)) + set(Tabular::TOGGLE_LINE_BOTTOM); + + if (booktabsRB->isChecked()) + set(Tabular::SET_BOOKTABS); + else + set(Tabular::UNSET_BOOKTABS); + + switch (topspaceCO->currentIndex()) { + case 0: + set(Tabular::SET_TOP_SPACE, ""); + break; + case 1: + set(Tabular::SET_TOP_SPACE, "default"); + break; + case 2: + set(Tabular::SET_TOP_SPACE, + widgetsToLength(topspaceED, + topspaceUnit)); + break; + } + + switch (bottomspaceCO->currentIndex()) { + case 0: + set(Tabular::SET_BOTTOM_SPACE, ""); + break; + case 1: + set(Tabular::SET_BOTTOM_SPACE, "default"); + break; + case 2: + set(Tabular::SET_BOTTOM_SPACE, + widgetsToLength(bottomspaceED, + bottomspaceUnit)); + break; + } + + switch (interlinespaceCO->currentIndex()) { + case 0: + set(Tabular::SET_INTERLINE_SPACE, ""); + break; + case 1: + set(Tabular::SET_INTERLINE_SPACE, "default"); + break; + case 2: + set(Tabular::SET_INTERLINE_SPACE, + widgetsToLength(interlinespaceED, + interlinespaceUnit)); + break; + } + // Longtabular + if (longTabularCB->isChecked()) + set(Tabular::SET_LONGTABULAR); + else + set(Tabular::UNSET_LONGTABULAR); -void GuiTabularDialog::ltHeaderBorderAbove_clicked() -{ + if (headerStatusCB->isChecked()) + set(Tabular::SET_LTHEAD, ""); + else + set(Tabular::UNSET_LTHEAD, ""); + if (headerBorderAboveCB->isChecked()) - controller().set(Tabular::SET_LTHEAD, "dl_above"); + set(Tabular::SET_LTHEAD, "dl_above"); else - controller().set(Tabular::UNSET_LTHEAD, "dl_above"); - changed(); -} + set(Tabular::UNSET_LTHEAD, "dl_above"); + if (headerBorderAboveCB->isChecked()) + set(Tabular::SET_LTHEAD, "dl_above"); + else + set(Tabular::UNSET_LTHEAD, "dl_above"); -void GuiTabularDialog::ltHeaderBorderBelow_clicked() -{ if (headerBorderBelowCB->isChecked()) - controller().set(Tabular::SET_LTHEAD, "dl_below"); + set(Tabular::SET_LTHEAD, "dl_below"); else - controller().set(Tabular::UNSET_LTHEAD, "dl_below"); - changed(); -} + set(Tabular::UNSET_LTHEAD, "dl_below"); - -void GuiTabularDialog::ltFirstHeaderBorderAbove_clicked() -{ if (firstheaderBorderAboveCB->isChecked()) - controller().set(Tabular::SET_LTFIRSTHEAD, "dl_above"); + set(Tabular::SET_LTFIRSTHEAD, "dl_above"); else - controller().set(Tabular::UNSET_LTFIRSTHEAD, "dl_above"); - changed(); -} + set(Tabular::UNSET_LTFIRSTHEAD, "dl_above"); - -void GuiTabularDialog::ltFirstHeaderBorderBelow_clicked() -{ if (firstheaderBorderBelowCB->isChecked()) - controller().set(Tabular::SET_LTFIRSTHEAD, "dl_below"); + set(Tabular::SET_LTFIRSTHEAD, "dl_below"); else - controller().set(Tabular::UNSET_LTFIRSTHEAD, "dl_below"); - changed(); -} - + set(Tabular::UNSET_LTFIRSTHEAD, "dl_below"); -void GuiTabularDialog::ltFirstHeaderStatus_clicked() -{ - bool enable(firstheaderStatusCB->isChecked()); - if (enable) - controller().set(Tabular::SET_LTFIRSTHEAD, ""); + if (firstheaderStatusCB->isChecked()) + set(Tabular::SET_LTFIRSTHEAD, ""); else - controller().set(Tabular::UNSET_LTFIRSTHEAD, ""); - firstheaderBorderAboveCB->setEnabled(enable); - firstheaderBorderBelowCB->setEnabled(enable); - changed(); -} - + set(Tabular::UNSET_LTFIRSTHEAD, ""); -void GuiTabularDialog::ltFirstHeaderEmpty_clicked() -{ - bool enable(firstheaderNoContentsCB->isChecked()); - if (enable) - controller().set(Tabular::SET_LTFIRSTHEAD, "empty"); + if (firstheaderNoContentsCB->isChecked()) + set(Tabular::SET_LTFIRSTHEAD, "empty"); else - controller().set(Tabular::UNSET_LTFIRSTHEAD, "empty"); - firstheaderStatusCB->setEnabled(!enable); - firstheaderBorderAboveCB->setEnabled(!enable); - firstheaderBorderBelowCB->setEnabled(!enable); - changed(); -} + set(Tabular::UNSET_LTFIRSTHEAD, "empty"); - -void GuiTabularDialog::ltFooterStatus_clicked() -{ - bool enable(footerStatusCB->isChecked()); - if (enable) - controller().set(Tabular::SET_LTFOOT, ""); + if (footerStatusCB->isChecked()) + set(Tabular::SET_LTFOOT, ""); else - controller().set(Tabular::UNSET_LTFOOT, ""); - footerBorderAboveCB->setEnabled(enable); - footerBorderBelowCB->setEnabled(enable); - lastfooterNoContentsCB->setEnabled(enable); - changed(); -} + set(Tabular::UNSET_LTFOOT, ""); - -void GuiTabularDialog::ltFooterBorderAbove_clicked() -{ if (footerBorderAboveCB->isChecked()) - controller().set(Tabular::SET_LTFOOT, "dl_above"); + set(Tabular::SET_LTFOOT, "dl_above"); else - controller().set(Tabular::UNSET_LTFOOT, "dl_above"); - changed(); -} - + set(Tabular::UNSET_LTFOOT, "dl_above"); -void GuiTabularDialog::ltFooterBorderBelow_clicked() -{ if (footerBorderBelowCB->isChecked()) - controller().set(Tabular::SET_LTFOOT, "dl_below"); + set(Tabular::SET_LTFOOT, "dl_below"); else - controller().set(Tabular::UNSET_LTFOOT, "dl_below"); - changed(); -} - + set(Tabular::UNSET_LTFOOT, "dl_below"); -void GuiTabularDialog::ltLastFooterStatus_clicked() -{ - bool enable(lastfooterStatusCB->isChecked()); - if (enable) - controller().set(Tabular::SET_LTLASTFOOT, ""); + if (lastfooterStatusCB->isChecked()) + set(Tabular::SET_LTLASTFOOT, ""); else - controller().set(Tabular::UNSET_LTLASTFOOT, ""); - lastfooterBorderAboveCB->setEnabled(enable); - lastfooterBorderBelowCB->setEnabled(enable); - changed(); -} - + set(Tabular::UNSET_LTLASTFOOT, ""); -void GuiTabularDialog::ltLastFooterBorderAbove_clicked() -{ if (lastfooterBorderAboveCB->isChecked()) - controller().set(Tabular::SET_LTLASTFOOT, "dl_above"); + set(Tabular::SET_LTLASTFOOT, "dl_above"); else - controller().set(Tabular::UNSET_LTLASTFOOT, "dl_above"); - changed(); -} + set(Tabular::UNSET_LTLASTFOOT, "dl_above"); - -void GuiTabularDialog::ltLastFooterBorderBelow_clicked() -{ if (lastfooterBorderBelowCB->isChecked()) - controller().set(Tabular::SET_LTLASTFOOT, "dl_below"); + set(Tabular::SET_LTLASTFOOT, "dl_below"); else - controller().set(Tabular::UNSET_LTLASTFOOT, "dl_below"); - changed(); -} + set(Tabular::UNSET_LTLASTFOOT, "dl_below"); - -void GuiTabularDialog::ltLastFooterEmpty_clicked() -{ - bool enable(lastfooterNoContentsCB->isChecked()); - if (enable) - controller().set(Tabular::SET_LTLASTFOOT, "empty"); + if (lastfooterNoContentsCB->isChecked()) + set(Tabular::SET_LTLASTFOOT, "empty"); else - controller().set(Tabular::UNSET_LTLASTFOOT, "empty"); - lastfooterStatusCB->setEnabled(!enable); - lastfooterBorderAboveCB->setEnabled(!enable); - lastfooterBorderBelowCB->setEnabled(!enable); - changed(); -} + set(Tabular::UNSET_LTLASTFOOT, "empty"); + if (newpageCB->isChecked() != tabular_.getLTNewPage(row)) + set(Tabular::SET_LTNEWPAGE); -void GuiTabularDialog::update_borders() -{ - Tabular const & tabular = controller().tabular(); - Tabular::idx_type const cell = controller().getActiveCell(); - bool const isMulticolumnCell = tabular.isMultiColumn(cell); + if (captionStatusCB->isChecked() != tabular_.ltCaption(row)) + set(Tabular::TOGGLE_LTCAPTION); - if (!isMulticolumnCell) { - borders->setLeftEnabled(true); - borders->setRightEnabled(true); - borders->setTop(tabular.topLine(cell, true)); - borders->setBottom(tabular.bottomLine(cell, true)); - borders->setLeft(tabular.leftLine(cell, true)); - borders->setRight(tabular.rightLine(cell, true)); - // repaint the setborder widget - borders->update(); - return; - } + if (leftRB->isChecked()) + set(Tabular::LONGTABULAR_ALIGN_LEFT); + else if (centerRB->isChecked()) + set(Tabular::LONGTABULAR_ALIGN_CENTER); + else if (rightRB->isChecked()) + set(Tabular::LONGTABULAR_ALIGN_RIGHT); - borders->setTop(tabular.topLine(cell)); - 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)) { - borders->setLeftEnabled(true); - borders->setLeft(tabular.leftLine(cell)); - } else { - borders->setLeft(false); - borders->setLeftEnabled(false); - } - if (tabular.isLastCellInRow(cell) || tabular.isMultiColumn(cell + 1)) { - borders->setRightEnabled(true); - borders->setRight(tabular.rightLine(cell)); - } else { - borders->setRight(false); - borders->setRightEnabled(false); - } - // repaint the setborder widget - borders->update(); + applying_ = false; } -void GuiTabularDialog::update_contents() +void GuiTabular::updateContents() { - controller().initialiseParams(string()); + if (applying_) + return; + + initialiseParams(string()); - Tabular const & tabular(controller().tabular()); - Tabular::idx_type const cell = controller().getActiveCell(); + Tabular::idx_type const cell = getActiveCell(); - Tabular::row_type const row = tabular.cellRow(cell); - Tabular::col_type const col = tabular.cellColumn(cell); + Tabular::row_type const row = tabular_.cellRow(cell); + Tabular::col_type const col = tabular_.cellColumn(cell); - tabularRowED->setText(toqstr(convert(row + 1))); - tabularColumnED->setText(toqstr(convert(col + 1))); + tabularRowED->setText(QString::number(row + 1)); + tabularColumnED->setText(QString::number(col + 1)); - bool const multicol(tabular.isMultiColumn(cell)); + bool const multicol(tabular_.isMultiColumn(cell)); multicolumnCB->setChecked(multicol); - rotateCellCB->setChecked(tabular.getRotateCell(cell)); - rotateTabularCB->setChecked(tabular.getRotateTabular()); + rotateCellCB->setChecked(tabular_.getRotateCell(cell)); + rotateTabularCB->setChecked(tabular_.rotate); - longTabularCB->setChecked(tabular.isLongTabular()); + longTabularCB->setChecked(tabular_.is_long_tabular); update_borders(); @@ -628,11 +663,13 @@ void GuiTabularDialog::update_contents() docstring special; if (multicol) { - special = tabular.getAlignSpecial(cell, Tabular::SET_SPECIAL_MULTI); - pwidth = tabular.getMColumnPWidth(cell); + special = getAlignSpecial(tabular_, cell, + Tabular::SET_SPECIAL_MULTI); + 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); } specialAlignmentED->setText(toqstr(special)); @@ -640,22 +677,21 @@ void GuiTabularDialog::update_contents() bool const isReadonly = bc().policy().isReadOnly(); specialAlignmentED->setEnabled(!isReadonly); - Length::UNIT default_unit = - controller().useMetricUnits() ? Length::CM : Length::IN; + Length::UNIT const default_unit = Length::defaultUnit(); - borderDefaultRB->setChecked(!tabular.useBookTabs()); - 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) { + if (tabular_.row_info[row].top_space.empty() + && !tabular_.row_info[row].top_space_default) { topspaceCO->setCurrentIndex(0); - } else if (tabular.row_info[row].top_space_default) { + } else if (tabular_.row_info[row].top_space_default) { topspaceCO->setCurrentIndex(1); } else { topspaceCO->setCurrentIndex(2); lengthToWidgets(topspaceED, topspaceUnit, - tabular.row_info[row].top_space.asString(), + tabular_.row_info[row].top_space.asString(), default_unit); } topspaceED->setEnabled(!isReadonly @@ -664,16 +700,16 @@ void GuiTabularDialog::update_contents() && (topspaceCO->currentIndex() == 2)); topspaceCO->setEnabled(!isReadonly); - if (tabular.row_info[row].bottom_space.empty() - && !tabular.row_info[row].bottom_space_default) { + if (tabular_.row_info[row].bottom_space.empty() + && !tabular_.row_info[row].bottom_space_default) { bottomspaceCO->setCurrentIndex(0); - } else if (tabular.row_info[row].bottom_space_default) { + } else if (tabular_.row_info[row].bottom_space_default) { bottomspaceCO->setCurrentIndex(1); } else { bottomspaceCO->setCurrentIndex(2); lengthToWidgets(bottomspaceED, bottomspaceUnit, - tabular.row_info[row].bottom_space.asString(), + tabular_.row_info[row].bottom_space.asString(), default_unit); } bottomspaceED->setEnabled(!isReadonly @@ -682,16 +718,16 @@ void GuiTabularDialog::update_contents() && (bottomspaceCO->currentIndex() == 2)); bottomspaceCO->setEnabled(!isReadonly); - if (tabular.row_info[row].interline_space.empty() - && !tabular.row_info[row].interline_space_default) { + if (tabular_.row_info[row].interline_space.empty() + && !tabular_.row_info[row].interline_space_default) { interlinespaceCO->setCurrentIndex(0); - } else if (tabular.row_info[row].interline_space_default) { + } else if (tabular_.row_info[row].interline_space_default) { interlinespaceCO->setCurrentIndex(1); } else { interlinespaceCO->setCurrentIndex(2); lengthToWidgets(interlinespaceED, interlinespaceUnit, - tabular.row_info[row].interline_space.asString(), + tabular_.row_info[row].interline_space.asString(), default_unit); } interlinespaceED->setEnabled(!isReadonly @@ -701,13 +737,15 @@ void GuiTabularDialog::update_contents() interlinespaceCO->setEnabled(!isReadonly); string colwidth; - if (!pwidth.zero()) + if (!pwidth.zero()) { colwidth = pwidth.asString(); - lengthToWidgets(widthED, widthUnit, - colwidth, default_unit); + + lengthToWidgets(widthED, widthUnitCB, + colwidth, default_unit); + } widthED->setEnabled(!isReadonly); - widthUnit->setEnabled(!isReadonly); + widthUnitCB->setEnabled(!isReadonly); hAlignCB->clear(); hAlignCB->addItem(qt_("Left")); @@ -717,7 +755,7 @@ void GuiTabularDialog::update_contents() hAlignCB->addItem(qt_("Justified")); int align = 0; - switch (tabular.getAlignment(cell)) { + switch (tabular_.getAlignment(cell)) { case LYX_ALIGN_LEFT: align = 0; break; @@ -740,7 +778,7 @@ void GuiTabularDialog::update_contents() hAlignCB->setCurrentIndex(align); int valign = 0; - switch (tabular.getVAlignment(cell)) { + switch (tabular_.getVAlignment(cell)) { case Tabular::LYX_VALIGN_TOP: valign = 0; break; @@ -751,17 +789,34 @@ void GuiTabularDialog::update_contents() valign = 2; break; default: - valign = 1; + valign = 0; break; } if (pwidth.zero()) - valign = 1; + valign = 0; vAlignCB->setCurrentIndex(valign); hAlignCB->setEnabled(true); vAlignCB->setEnabled(!pwidth.zero()); - if (!tabular.isLongTabular()) { + 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; + } + TableAlignCB->setCurrentIndex(tableValign); + + if (!tabular_.is_long_tabular) { headerStatusCB->setChecked(false); headerBorderAboveCB->setChecked(false); headerBorderBelowCB->setChecked(false); @@ -778,12 +833,69 @@ void GuiTabularDialog::update_contents() lastfooterNoContentsCB->setChecked(false); newpageCB->setChecked(false); newpageCB->setEnabled(false); + captionStatusCB->blockSignals(true); + captionStatusCB->setChecked(false); + captionStatusCB->blockSignals(false); return; + } else + // longtables cannot have a vertical alignment + TableAlignCB->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); + + // FIXME: shouldn't this be handled by GuiDialog? + // FIXME: Some of them should be handled directly in TabularUI.ui + firstheaderBorderAboveCB->setEnabled( + funcEnabled(Tabular::SET_LTFIRSTHEAD)); + firstheaderBorderBelowCB->setEnabled( + funcEnabled(Tabular::SET_LTFIRSTHEAD)); + // first header can only be suppressed when there is a header + firstheaderNoContentsCB->setEnabled(tabular_.haveLTHead() + && !tabular_.haveLTFirstHead()); + + //firstheaderStatusCB->setEnabled( + // !firstheaderNoContentsCB->isChecked()); + headerBorderAboveCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD)); + headerBorderBelowCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD)); + headerStatusCB->setEnabled(funcEnabled(Tabular::SET_LTHEAD)); + + footerBorderAboveCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT)); + footerBorderBelowCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT)); + footerStatusCB->setEnabled(funcEnabled(Tabular::SET_LTFOOT)); + + lastfooterBorderAboveCB->setEnabled( + funcEnabled(Tabular::SET_LTLASTFOOT)); + lastfooterBorderBelowCB->setEnabled( + funcEnabled(Tabular::SET_LTLASTFOOT)); + // last footer can only be suppressed when there is a footer + lastfooterNoContentsCB->setEnabled(tabular_.haveLTFoot() + && !tabular_.haveLTLastFoot()); + + captionStatusCB->setEnabled( + funcEnabled(Tabular::TOGGLE_LTCAPTION)); + // When a row is set as longtable caption, it must not be allowed + // to unset that this row is a multicolumn. + multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN)); Tabular::ltType ltt; bool use_empty; - bool row_set = tabular.getRowOfLTHead(row, ltt); + bool row_set = tabular_.getRowOfLTHead(row, ltt); headerStatusCB->setChecked(row_set); if (ltt.set) { headerBorderAboveCB->setChecked(ltt.topDL); @@ -799,7 +911,13 @@ void GuiTabularDialog::update_contents() use_empty = false; } - row_set = tabular.getRowOfLTFirstHead(row, ltt); + row_set = tabular_.getRowOfLTFirstHead(row, ltt); + // 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) + && !firstheaderNoContentsCB->isChecked()); firstheaderStatusCB->setChecked(row_set); if (ltt.set && (!ltt.empty || !use_empty)) { firstheaderBorderAboveCB->setChecked(ltt.topDL); @@ -810,13 +928,12 @@ void GuiTabularDialog::update_contents() firstheaderBorderAboveCB->setChecked(false); firstheaderBorderBelowCB->setChecked(false); if (use_empty) { - firstheaderNoContentsCB->setChecked(ltt.empty); if (ltt.empty) firstheaderStatusCB->setEnabled(false); } } - row_set = tabular.getRowOfLTFoot(row, ltt); + row_set = tabular_.getRowOfLTFoot(row, ltt); footerStatusCB->setChecked(row_set); if (ltt.set) { footerBorderAboveCB->setChecked(ltt.topDL); @@ -832,8 +949,14 @@ void GuiTabularDialog::update_contents() use_empty = false; } - row_set = tabular.getRowOfLTLastFoot(row, ltt); - lastfooterStatusCB->setChecked(row_set); + row_set = tabular_.getRowOfLTLastFoot(row, ltt); + // 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) + && !lastfooterNoContentsCB->isChecked()); + lastfooterStatusCB->setChecked(row_set); if (ltt.set && (!ltt.empty || !use_empty)) { lastfooterBorderAboveCB->setChecked(ltt.topDL); lastfooterBorderBelowCB->setChecked(ltt.bottomDL); @@ -843,108 +966,82 @@ void GuiTabularDialog::update_contents() lastfooterBorderAboveCB->setChecked(false); lastfooterBorderBelowCB->setChecked(false); if (use_empty) { - lastfooterNoContentsCB->setChecked(ltt.empty); if (ltt.empty) lastfooterStatusCB->setEnabled(false); } } - newpageCB->setChecked(tabular.getLTNewPage(row)); + newpageCB->setChecked(tabular_.getLTNewPage(row)); } -void GuiTabularDialog::closeGUI() +bool GuiTabular::initialiseParams(string const & data) { - // 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()); + // try to get the current cell + BufferView const * const bv = bufferview(); + InsetTabular const * current_inset = 0; + if (bv) { + Cursor const & cur = bv->cursor(); + // get the innermost tabular inset; + // assume that it is "ours" + for (int i = cur.depth() - 1; i >= 0; --i) + if (cur[i].inset().lyxCode() == TABULAR_CODE) { + current_inset = + static_cast(&cur[i].inset()); + active_cell_ = cur[i].idx(); + break; + } + } - // apply the fixed width values - Tabular::idx_type const cell = controller().getActiveCell(); - bool const multicol = tabular.isMultiColumn(cell); - string width = widgetsToLength(widthED, widthUnit); - string width2; + if (current_inset && data.empty()) { + tabular_ = Tabular(current_inset->tabular); + return true; + } - Length llen = tabular.getColumnPWidth(cell); - Length llenMulti = tabular.getMColumnPWidth(cell); + InsetTabular tmp(const_cast(&buffer())); + InsetTabular::string2params(data, tmp); + tabular_ = Tabular(tmp.tabular); + return true; +} - 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(specialAlignmentED->text()); - docstring sa2; +void GuiTabular::clearParams() +{ + // This function is also called when LyX is closing and the dialog + // is still open. At that time, the buffer might not be available + // anymore. + if (isBufferAvailable()) { + InsetTabular tmp(const_cast(&buffer())); + tabular_ = tmp.tabular; + } + active_cell_ = Tabular::npos; +} - 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)); - } +Tabular::idx_type GuiTabular::getActiveCell() const +{ + return active_cell_; +} - if (width != width2) { - if (multicol) - controller().set(Tabular::SET_MPWIDTH, width); - else - controller().set(Tabular::SET_PWIDTH, width); - } - /* DO WE NEED THIS? - switch (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(topspaceED, - topspaceUnit)); - break; - } +void GuiTabular::set(Tabular::Feature f, string const & arg) +{ + string const data = featureAsString(f) + ' ' + arg; + dispatch(FuncRequest(getLfun(), data)); +} - switch (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(bottomspaceED, - bottomspaceUnit)); - break; - } - switch (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(interlinespaceED, - interlinespaceUnit)); - break; - } -*/ +// to get the status of the longtable row settings +bool GuiTabular::funcEnabled(Tabular::Feature f) const +{ + return getStatus( + FuncRequest(getLfun(), featureAsString(f))).enabled(); } + +Dialog * createGuiTabular(GuiView & lv) { return new GuiTabular(lv); } + + } // namespace frontend } // namespace lyx -#include "GuiTabular_moc.cpp" +#include "moc_GuiTabular.cpp"