]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiTabular.cpp
Compil fix.
[lyx.git] / src / frontends / qt4 / GuiTabular.cpp
index 4bd8ac77c898190b9183ab83fbcc3c5de7055fbb..8b8c2dbaf438e73bfaa55e47c1c1023002b24761 100644 (file)
 
 #include "GuiTabular.h"
 
-#include "BufferView.h"
-#include "Cursor.h"
-#include "FuncRequest.h"
 #include "GuiSetBorder.h"
+#include "GuiView.h"
 #include "LengthCombo.h"
-#include "LyXRC.h"
 #include "qt_helpers.h"
 #include "Validator.h"
 
+#include "BufferView.h"
+#include "Cursor.h"
+#include "FuncRequest.h"
+#include "LyXRC.h"
+
 #include "insets/InsetTabular.h"
 
-#include <QCloseEvent>
 #include <QCheckBox>
 #include <QPushButton>
 #include <QRadioButton>
@@ -37,12 +38,13 @@ namespace lyx {
 namespace frontend {
 
 GuiTabular::GuiTabular(GuiView & lv)
-       : GuiDialog(lv, "tabular")
+       : GuiDialog(lv, "tabular", qt_("Table Settings")),
+       // tabular_ is initialised at dialog construction in initialiseParams()
+       tabular_(*lv.buffer(), 0, 0)
 {
        active_cell_ = Tabular::npos;
 
        setupUi(this);
-       setViewTitle(_("Table Settings"));
 
        widthED->setValidator(unsignedLengthValidator(widthED));
        topspaceED->setValidator(new LengthValidator(topspaceED));
@@ -162,13 +164,6 @@ void GuiTabular::change_adaptor()
 }
 
 
-void GuiTabular::closeEvent(QCloseEvent * e)
-{
-       slotClose();
-       GuiDialog::closeEvent(e);
-}
-
-
 void GuiTabular::booktabsChanged(bool)
 {
        changed();
@@ -292,28 +287,28 @@ void GuiTabular::borderUnset_clicked()
 
 void GuiTabular::leftBorder_changed()
 {
-       toggleLeftLine();
+       set(Tabular::TOGGLE_LINE_LEFT);
        changed();
 }
 
 
 void GuiTabular::rightBorder_changed()
 {
-       toggleRightLine();
+       set(Tabular::TOGGLE_LINE_RIGHT);
        changed();
 }
 
 
 void GuiTabular::topBorder_changed()
 {
-       toggleTopLine();
+       set(Tabular::TOGGLE_LINE_TOP);
        changed();
 }
 
 
 void GuiTabular::bottomBorder_changed()
 {
-       toggleBottomLine();
+       set(Tabular::TOGGLE_LINE_BOTTOM);
        changed();
 }
 
@@ -398,6 +393,13 @@ void GuiTabular::ltNewpage_clicked()
 }
 
 
+void GuiTabular::on_captionStatusCB_toggled()
+{
+       set(Tabular::TOGGLE_LTCAPTION);
+       changed();
+}
+
+
 void GuiTabular::ltHeaderStatus_clicked()
 {
        bool enable = headerStatusCB->isChecked();
@@ -563,49 +565,47 @@ void GuiTabular::ltLastFooterEmpty_clicked()
 void GuiTabular::update_borders()
 {
        Tabular::idx_type const cell = getActiveCell();
-       bool const isMulticolumnCell = tabular_.isMultiColumn(cell);
-
-       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;
-       }
-
        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);
-       }
+       borders->setLeft(tabular_.leftLine(cell));
+       borders->setRight(tabular_.rightLine(cell));
        // repaint the setborder widget
        borders->update();
 }
 
 
+namespace {
+
+Length getColumnPWidth(Tabular const & t, size_t cell)
+{
+       return t.column_info[t.cellColumn(cell)].p_width;
+}
+
+
+Length getMColumnPWidth(Tabular const & t, size_t cell)
+{
+       if (t.isMultiColumn(cell))
+               return t.cellInfo(cell).p_width;
+       return Length();
+}
+
+
+docstring getAlignSpecial(Tabular const & t, size_t cell, int what)
+{
+       if (what == Tabular::SET_SPECIAL_MULTI)
+               return t.cellInfo(cell).align_special;
+       return t.column_info[t.cellColumn(cell)].align_special;
+}
+
+}
+
+
+
 void GuiTabular::updateContents()
 {
        initialiseParams(string());
 
-       Tabular::idx_type const cell = getActiveCell();
+       size_t const cell = getActiveCell();
 
        Tabular::row_type const row = tabular_.cellRow(cell);
        Tabular::col_type const col = tabular_.cellColumn(cell);
@@ -618,9 +618,9 @@ void GuiTabular::updateContents()
        multicolumnCB->setChecked(multicol);
 
        rotateCellCB->setChecked(tabular_.getRotateCell(cell));
-       rotateTabularCB->setChecked(tabular_.getRotateTabular());
+       rotateTabularCB->setChecked(tabular_.rotate);
 
-       longTabularCB->setChecked(tabular_.isLongTabular());
+       longTabularCB->setChecked(tabular_.is_long_tabular);
 
        update_borders();
 
@@ -628,11 +628,11 @@ void GuiTabular::updateContents()
        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));
@@ -643,8 +643,8 @@ void GuiTabular::updateContents()
        Length::UNIT default_unit =
                useMetricUnits() ? Length::CM : Length::IN;
 
-       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) {
@@ -761,7 +761,7 @@ void GuiTabular::updateContents()
        hAlignCB->setEnabled(true);
        vAlignCB->setEnabled(!pwidth.zero());
 
-       if (!tabular_.isLongTabular()) {
+       if (!tabular_.is_long_tabular) {
                headerStatusCB->setChecked(false);
                headerBorderAboveCB->setChecked(false);
                headerBorderBelowCB->setChecked(false);
@@ -778,8 +778,14 @@ void GuiTabular::updateContents()
                lastfooterNoContentsCB->setChecked(false);
                newpageCB->setChecked(false);
                newpageCB->setEnabled(false);
+               captionStatusCB->blockSignals(true);
+               captionStatusCB->setChecked(false);
+               captionStatusCB->blockSignals(false);
                return;
        }
+       captionStatusCB->blockSignals(true);
+       captionStatusCB->setChecked(tabular_.ltCaption(row));
+       captionStatusCB->blockSignals(false);
 
        Tabular::ltType ltt;
        bool use_empty;
@@ -862,13 +868,13 @@ void GuiTabular::closeGUI()
        // since the changes update the actual tabular_
        //
        // apply the fixed width values
-       Tabular::idx_type const cell = getActiveCell();
+       size_t const cell = getActiveCell();
        bool const multicol = tabular_.isMultiColumn(cell);
        string width = widgetsToLength(widthED, widthUnit);
        string width2;
 
-       Length llen = tabular_.getColumnPWidth(cell);
-       Length llenMulti = tabular_.getMColumnPWidth(cell);
+       Length llen = getColumnPWidth(tabular_, cell);
+       Length llenMulti = getMColumnPWidth(tabular_, cell);
 
        if (multicol && !llenMulti.zero())
                width2 = llenMulti.asString();
@@ -880,9 +886,9 @@ void GuiTabular::closeGUI()
        docstring sa2;
 
        if (multicol)
-               sa2 = tabular_.getAlignSpecial(cell, Tabular::SET_SPECIAL_MULTI);
+               sa2 = getAlignSpecial(tabular_, cell, Tabular::SET_SPECIAL_MULTI);
        else
-               sa2 = tabular_.getAlignSpecial(cell, Tabular::SET_SPECIAL_COLUMN);
+               sa2 = getAlignSpecial(tabular_, cell, Tabular::SET_SPECIAL_COLUMN);
 
        if (sa1 != sa2) {
                if (multicol)
@@ -964,7 +970,7 @@ bool GuiTabular::initialiseParams(string const & data)
        }
 
        InsetTabular tmp(buffer());
-       InsetTabularMailer::string2params(data, tmp);
+       InsetTabular::string2params(data, tmp);
        tabular_ = Tabular(tmp.tabular);
        return true;
 }
@@ -997,42 +1003,6 @@ bool GuiTabular::useMetricUnits() const
 }
 
 
-void GuiTabular::toggleTopLine()
-{
-       if (tabular_.isMultiColumn(getActiveCell()))
-               set(Tabular::M_TOGGLE_LINE_TOP);
-       else
-               set(Tabular::TOGGLE_LINE_TOP);
-}
-
-
-void GuiTabular::toggleBottomLine()
-{
-       if (tabular_.isMultiColumn(getActiveCell()))
-               set(Tabular::M_TOGGLE_LINE_BOTTOM);
-       else
-               set(Tabular::TOGGLE_LINE_BOTTOM);
-}
-
-
-void GuiTabular::toggleLeftLine()
-{
-       if (tabular_.isMultiColumn(getActiveCell()))
-               set(Tabular::M_TOGGLE_LINE_LEFT);
-       else
-               set(Tabular::TOGGLE_LINE_LEFT);
-}
-
-
-void GuiTabular::toggleRightLine()
-{
-       if (tabular_.isMultiColumn(getActiveCell()))
-               set(Tabular::M_TOGGLE_LINE_RIGHT);
-       else
-               set(Tabular::TOGGLE_LINE_RIGHT);
-}
-
-
 void GuiTabular::setSpecial(string const & special)
 {
        if (tabular_.isMultiColumn(getActiveCell()))