diff --git a/src/frontends/qt4/GuiTabular.cpp b/src/frontends/qt4/GuiTabular.cpp index dbce9dc6f6..f91650d6b8 100644 --- a/src/frontends/qt4/GuiTabular.cpp +++ b/src/frontends/qt4/GuiTabular.cpp @@ -23,6 +23,8 @@ #include "BufferView.h" #include "Cursor.h" #include "FuncRequest.h" +#include "FuncStatus.h" +#include "LyXFunc.h" #include "insets/InsetTabular.h" @@ -784,6 +786,37 @@ void GuiTabular::updateContents() 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()); + // check if setting a first header is allowed + // additionally check firstheaderStatusCB because when this is the case + // a first header makes no sense + firstheaderStatusCB->setEnabled(funcEnabled(Tabular::SET_LTFIRSTHEAD) + && !firstheaderNoContentsCB->isChecked()); + //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()); + // 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()); + captionStatusCB->setEnabled(funcEnabled(Tabular::TOGGLE_LTCAPTION)); + Tabular::ltType ltt; bool use_empty; bool row_set = tabular_.getRowOfLTHead(row, ltt); @@ -813,7 +846,6 @@ void GuiTabular::updateContents() firstheaderBorderAboveCB->setChecked(false); firstheaderBorderBelowCB->setChecked(false); if (use_empty) { - firstheaderNoContentsCB->setChecked(ltt.empty); if (ltt.empty) firstheaderStatusCB->setEnabled(false); } @@ -846,7 +878,6 @@ void GuiTabular::updateContents() lastfooterBorderAboveCB->setChecked(false); lastfooterBorderBelowCB->setChecked(false); if (use_empty) { - lastfooterNoContentsCB->setChecked(ltt.empty); if (ltt.empty) lastfooterStatusCB->setEnabled(false); } @@ -1119,6 +1150,13 @@ void GuiTabular::longTabular(bool yes) } +// 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); } diff --git a/src/frontends/qt4/GuiTabular.h b/src/frontends/qt4/GuiTabular.h index 185bb800bd..f70d988daa 100644 --- a/src/frontends/qt4/GuiTabular.h +++ b/src/frontends/qt4/GuiTabular.h @@ -115,6 +115,8 @@ private: void longTabular(bool yes); + bool funcEnabled(Tabular::Feature f) const; + /// Tabular::idx_type active_cell_; /// diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 07eef6a3d9..3afcc41549 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -1750,8 +1750,14 @@ Tabular::idx_type Tabular::setLTCaption(row_type row, bool what) setBottomLine(i, false); setLeftLine(i, false); setRightLine(i, false); - } else + // FIXME: when a row is set as caption, then also insert a caption + // dispatch(FuncRequest(LFUN_CAPTION_INSERT)); + } else { unsetMultiColumn(i); + // FIXME: when unsetting a caption row, also all existing captions + // in this row must be dissolved, see (bug 5754) + // dispatch(FuncRequest(LFUN_INSET_DISSOLVE, "caption-insert")); + } row_info[row].caption = what; return i; } @@ -1763,6 +1769,15 @@ bool Tabular::ltCaption(row_type row) const } +bool Tabular::haveLTCaption() const +{ + for (row_type i = 0; i < row_info.size(); ++i) + if (row_info[i].caption) + return true; + return false; +} + + // end longtable support functions void Tabular::setRowAscent(row_type row, int height) @@ -3884,7 +3899,17 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, status.setOnOff(convert(argument) == tabular.getUsebox(cur.idx())); break; - case Tabular::SET_LTFIRSTHEAD: + // when a header/footer/caption is set, no other row can be the same + // furthermore, every row can only be one thing: + // either a footer or header or caption + case Tabular::SET_LTFIRSTHEAD: + status.setEnabled(sel_row_start == sel_row_end + && !tabular.getRowOfLTHead(sel_row_start, dummyltt) + && !tabular.getRowOfLTFoot(sel_row_start, dummyltt) + && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt) + && !tabular.ltCaption(sel_row_start) + && (!tabular.haveLTFirstHead() + || tabular.getRowOfLTFirstHead(sel_row_start, dummyltt))); status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt)); break; @@ -3893,6 +3918,13 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, break; case Tabular::SET_LTHEAD: + status.setEnabled(sel_row_start == sel_row_end + && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt) + && !tabular.getRowOfLTFoot(sel_row_start, dummyltt) + && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt) + && !tabular.ltCaption(sel_row_start) + && (!tabular.haveLTHead() + || tabular.getRowOfLTHead(sel_row_start, dummyltt))); status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt)); break; @@ -3901,6 +3933,13 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, break; case Tabular::SET_LTFOOT: + status.setEnabled(sel_row_start == sel_row_end + && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt) + && !tabular.getRowOfLTHead(sel_row_start, dummyltt) + && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt) + && !tabular.ltCaption(sel_row_start) + && (!tabular.haveLTFoot() + || tabular.getRowOfLTFoot(sel_row_start, dummyltt))); status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt)); break; @@ -3909,6 +3948,13 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, break; case Tabular::SET_LTLASTFOOT: + status.setEnabled(sel_row_start == sel_row_end + && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt) + && !tabular.getRowOfLTHead(sel_row_start, dummyltt) + && !tabular.getRowOfLTFoot(sel_row_start, dummyltt) + && !tabular.ltCaption(sel_row_start) + && (!tabular.haveLTLastFoot() + || tabular.getRowOfLTLastFoot(sel_row_start, dummyltt))); status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt)); break; @@ -3921,7 +3967,15 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, break; case Tabular::TOGGLE_LTCAPTION: - status.setEnabled(sel_row_start == sel_row_end); + status.setEnabled(sel_row_start == sel_row_end + && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt) + && !tabular.getRowOfLTHead(sel_row_start, dummyltt) + && !tabular.getRowOfLTFoot(sel_row_start, dummyltt) + && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt) + // Only the first row can be the caption. + && sel_row_start == 0 + && (!tabular.haveLTCaption() + || tabular.ltCaption(sel_row_start))); status.setOnOff(tabular.ltCaption(sel_row_start)); break; diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index 9f963114c7..1f71350aeb 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -426,6 +426,8 @@ public: /// bool haveLTLastFoot() const; /// + bool haveLTCaption() const; + /// // end longtable support /// boost::shared_ptr cellInset(idx_type cell) const;