]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiTabular.cpp
QDialogButtonBox for the remaining dialogs.
[lyx.git] / src / frontends / qt4 / GuiTabular.cpp
index 8a14cb709392eff35519eab62ef44201f6613c78..4ac80ad77cd8722a51e8fd6685cd15bd919dac45 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "support/convert.h"
 #include "support/debug.h"
+#include "support/lstrings.h"
 
 #include <QCheckBox>
 #include <QPushButton>
@@ -45,7 +46,9 @@ namespace lyx {
 namespace frontend {
 
 GuiTabular::GuiTabular(QWidget * parent)
-       : InsetParamsWidget(parent)
+       : InsetParamsWidget(parent), firstheader_suppressable_(false),
+         lastfooter_suppressable_(false)
+
 {
        setupUi(this);
 
@@ -127,7 +130,7 @@ GuiTabular::GuiTabular(QWidget * parent)
                this, SLOT(checkEnabled()));
        connect(captionStatusCB, SIGNAL(clicked()),
                this, SLOT(checkEnabled()));
-       connect(specialAlignmentED, SIGNAL(editingFinished()),
+       connect(specialAlignmentED, SIGNAL(textEdited(const QString &)),
                this, SLOT(checkEnabled()));
        connect(columnWidthED, SIGNAL(textEdited(const QString &)),
                this, SLOT(checkEnabled()));
@@ -199,28 +202,46 @@ void GuiTabular::on_interlinespaceCO_activated(int index)
 }
 
 
-void GuiTabular::checkEnabled()
+void GuiTabular::on_columnTypeCO_activated(int index)
+{
+       checkEnabled();
+       if (index == 2)
+               columnWidthED->setFocus();
+}
+
+
+void GuiTabular::enableWidgets() const
 {
        // if there is a LaTeX argument, the width and alignment will be overwritten
        // therefore disable them in this case
-       columnWidthED->setEnabled(specialAlignmentED->text().isEmpty());
+       bool const fixed = specialAlignmentED->text().isEmpty()
+                       && columnTypeCO->currentIndex() == 2;
+       columnWidthED->setEnabled(fixed);
+       columnWidthUnitLC->setEnabled(fixed);
        // 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 = 
+       // decimal alignment is only possible for non-multicol and non-multirow cells
+       if ((multicolumnCB->isChecked() || multirowCB->isChecked() || columnTypeCO->currentIndex() == 1)
+               && hAlignCO->findData(toqstr("decimal")))
+               hAlignCO->removeItem(hAlignCO->findData(toqstr("decimal")));
+       else if (!multicolumnCB->isChecked() && !multirowCB->isChecked()
+               && hAlignCO->findData(toqstr("decimal")) == -1)
+               hAlignCO->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
+       bool const dalign =
                hAlignCO->itemData(hAlignCO->currentIndex()).toString() == QString("decimal");
        decimalPointED->setEnabled(dalign);
        decimalLA->setEnabled(dalign);
 
-       bool const setwidth = TableAlignCO->currentText() == qt_("Middle")
-               && !longTabularCB->isChecked();
+       bool const setwidth = TableAlignCO->currentText() == qt_("Middle");
        tabularWidthLA->setEnabled(setwidth);
        tabularWidthED->setEnabled(setwidth);
        tabularWidthUnitLC->setEnabled(setwidth);
 
-       rotateTabularAngleSB->setEnabled(rotateTabularCB->isChecked());
+       rotateTabularAngleSB->setEnabled(rotateTabularCB->isChecked()
+                                        && !longTabularCB->isChecked());
        rotateCellAngleSB->setEnabled(rotateCellCB->isChecked());
 
        bool const enable_valign =
@@ -240,7 +261,7 @@ void GuiTabular::checkEnabled()
 
        // setting as longtable is not allowed when table is inside a float
        bool const is_tabular_star = !tabularWidthED->text().isEmpty();
-       longTabularCB->setEnabled(!is_tabular_star && funcEnabled(Tabular::SET_LONGTABULAR));
+       longTabularCB->setEnabled(funcEnabled(Tabular::SET_LONGTABULAR));
        bool const longtabular = longTabularCB->isChecked();
        longtableGB->setEnabled(true);
        newpageCB->setEnabled(longtabular);
@@ -248,6 +269,9 @@ void GuiTabular::checkEnabled()
        // longtables and tabular* cannot have a vertical alignment
        TableAlignLA->setDisabled(is_tabular_star || longtabular);
        TableAlignCO->setDisabled(is_tabular_star || longtabular);
+       // longtable cannot be rotated with rotating package, only
+       // with [pdf]lscape, which only supports 90 deg.
+       rotateTabularAngleSB->setDisabled(longtabular);
 
        // FIXME: This Dialog is really horrible, disabling/enabling a checkbox
        // depending on the cursor position is very very unintuitive...
@@ -304,13 +328,24 @@ void GuiTabular::checkEnabled()
        captionStatusCB->setEnabled(funcEnabled(Tabular::TOGGLE_LTCAPTION)
                && longtabular);
 
-       multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN));
-       multirowCB->setEnabled(funcEnabled(Tabular::MULTIROW));
+       multicolumnCB->setEnabled(funcEnabled(Tabular::MULTICOLUMN)
+               && !dalign && !multirowCB->isChecked());
+       multirowCB->setEnabled(funcEnabled(Tabular::MULTIROW)
+               && !dalign && !multicolumnCB->isChecked());
        bool const enable_mr = multirowCB->isChecked();
        multirowOffsetLA->setEnabled(enable_mr);
        multirowOffsetED->setEnabled(enable_mr);
        multirowOffsetUnitLC->setEnabled(enable_mr);
 
+       // Vertical lines cannot be set in formal tables
+       borders->setLeftEnabled(!booktabsRB->isChecked());
+       borders->setRightEnabled(!booktabsRB->isChecked());
+}
+
+
+void GuiTabular::checkEnabled()
+{
+       enableWidgets();
        changed();
 }
 
@@ -428,8 +463,7 @@ void GuiTabular::setTableAlignment(string & param_str) const
 
 docstring GuiTabular::dialogToParams() const
 {
-       // FIXME: We should use Tabular directly.
-       string param_str = "tabular from-dialog";
+       string param_str = "tabular";
 
        // table width
        string tabwidth = widgetsToLength(tabularWidthED, tabularWidthUnitLC);
@@ -441,13 +475,20 @@ docstring GuiTabular::dialogToParams() const
        // 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())
+       if (width.empty() || columnTypeCO->currentIndex() != 2)
                width = "0pt";
        if (multicolumnCB->isChecked())
                setParam(param_str, Tabular::SET_MPWIDTH, width);
        else
                setParam(param_str, Tabular::SET_PWIDTH, width);
 
+       bool const varwidth = specialAlignmentED->text().isEmpty()
+                       && columnTypeCO->currentIndex() == 1;
+       if (varwidth)
+               setParam(param_str, Tabular::TOGGLE_VARWIDTH_COLUMN, "on");
+       else
+               setParam(param_str, Tabular::TOGGLE_VARWIDTH_COLUMN, "off");
+
        // apply the column alignment
        // multirows inherit the alignment from the column; if a column width
        // is set, multirows are always left-aligned so that in this case
@@ -536,7 +577,7 @@ docstring GuiTabular::dialogToParams() const
 
        // apply the special alignment
        string special = fromqstr(specialAlignmentED->text());
-       if (special.empty())
+       if (support::trim(special).empty())
                special = "none";
        if (multicolumnCB->isChecked())
                setParam(param_str, Tabular::SET_SPECIAL_MULTICOLUMN, special);
@@ -580,6 +621,8 @@ docstring GuiTabular::dialogToParams() const
        //
        if (newpageCB->isChecked())
                setParam(param_str, Tabular::SET_LTNEWPAGE);
+       else
+               setParam(param_str, Tabular::UNSET_LTNEWPAGE);
        //
        if (captionStatusCB->isChecked())
                setParam(param_str, Tabular::SET_LTCAPTION);
@@ -715,12 +758,16 @@ void GuiTabular::paramsToDialog(Inset const * inset)
                        rotateCellAngleSB->setValue(90);
        }
 
-       rotateTabularCB->setChecked(tabular.rotate != 0);
-       if (rotateTabularCB->isChecked())
-               rotateTabularAngleSB->setValue(tabular.rotate != 0 ? tabular.rotate : 90);
-
        longTabularCB->setChecked(tabular.is_long_tabular);
 
+       rotateTabularCB->setChecked(tabular.rotate != 0);
+       if (rotateTabularCB->isChecked()) {
+               if (longTabularCB->isChecked())
+                       rotateTabularAngleSB->setValue(90);
+               else
+                       rotateTabularAngleSB->setValue(tabular.rotate != 0 ? tabular.rotate : 90);
+       }
+
        borders->setTop(tabular.topLine(cell));
        borders->setBottom(tabular.bottomLine(cell));
        borders->setLeft(tabular.leftLine(cell));
@@ -734,7 +781,8 @@ void GuiTabular::paramsToDialog(Inset const * inset)
        // Set width and alignment
 
        Length const tabwidth = tabular.tabularWidth();
-       if (tabwidth.zero())
+       if (tabwidth.zero()
+           && !(tabularWidthED->hasFocus() && tabularWidthED->text() == "0"))
                tabularWidthED->clear();
        else
                lengthToWidgets(tabularWidthED, tabularWidthUnitLC,
@@ -751,19 +799,27 @@ void GuiTabular::paramsToDialog(Inset const * inset)
                        Tabular::SET_SPECIAL_COLUMN);
                pwidth = getColumnPWidth(tabular, cell);
        }
+       bool const varwidth = tabular.column_info[tabular.cellColumn(cell)].varwidth;
+       if (varwidth)
+               columnTypeCO->setCurrentIndex(1);
        string colwidth;
-       if (pwidth.zero())
+       if (pwidth.zero()
+           && !(columnWidthED->hasFocus() && columnWidthED->text() == "0")) {
                columnWidthED->clear();
-       else {
+               if (!varwidth)
+                       columnTypeCO->setCurrentIndex(0);
+       } else {
                colwidth = pwidth.asString();
                lengthToWidgets(columnWidthED, columnWidthUnitLC,
                        colwidth, default_unit);
+               columnTypeCO->setCurrentIndex(2);
        }
        Length mroffset;
        if (multirow)
                mroffset = getMROffset(tabular, cell);
        string offset;
-       if (mroffset.zero())
+       if (mroffset.zero()
+           && !(multirowOffsetED->hasFocus() && multirowOffsetED->text() == "0"))
                multirowOffsetED->clear();
        else {
                offset = mroffset.asString();
@@ -822,7 +878,7 @@ void GuiTabular::paramsToDialog(Inset const * inset)
        hAlignCO->addItem(qt_("Right"), toqstr("right"));
        if (!multicol && !pwidth.zero())
                hAlignCO->addItem(qt_("Justified"), toqstr("justified"));
-       if (!multicol)
+       if (!multicol && !multirow)
                hAlignCO->addItem(qt_("At Decimal Separator"), toqstr("decimal"));
 
        string align;
@@ -844,7 +900,7 @@ void GuiTabular::paramsToDialog(Inset const * inset)
                }
                case LYX_ALIGN_DECIMAL:
                {
-                       if (!multicol)
+                       if (!multicol && !multirow)
                                align = "decimal";
                        break;
                }
@@ -1000,10 +1056,55 @@ void GuiTabular::paramsToDialog(Inset const * inset)
 }
 
 
+bool GuiTabular::checkWidgets(bool readonly) const
+{
+       tabularRowED->setReadOnly(readonly);
+       tabularColumnED->setReadOnly(readonly);
+       tabularWidthED->setReadOnly(readonly);
+       specialAlignmentED->setReadOnly(readonly);
+       columnWidthED->setReadOnly(readonly);
+       multirowOffsetED->setReadOnly(readonly);
+       decimalPointED->setReadOnly(readonly);
+
+       if (readonly) {
+               multicolumnCB->setEnabled(false);
+               multirowCB->setEnabled(false);
+               rotateCellCB->setEnabled(false);
+               rotateCellAngleSB->setEnabled(false);
+               rotateTabularCB->setEnabled(false);
+               rotateTabularAngleSB->setEnabled(false);
+               longTabularCB->setEnabled(false);
+               borders->setEnabled(false);
+               tabularWidthUnitLC->setEnabled(false);
+               columnWidthUnitLC->setEnabled(false);
+               columnTypeCO->setEnabled(false);
+               multirowOffsetUnitLC->setEnabled(false);
+               setBordersGB->setEnabled(false);
+               allBordersGB->setEnabled(false);
+               borderStyleGB->setEnabled(false);
+               booktabsRB->setEnabled(false);
+               topspaceCO->setEnabled(false);
+               topspaceUnitLC->setEnabled(false);
+               bottomspaceCO->setEnabled(false);
+               bottomspaceUnitLC->setEnabled(false);
+               interlinespaceCO->setEnabled(false);
+               interlinespaceUnitLC->setEnabled(false);
+               hAlignCO->setEnabled(false);
+               vAlignCO->setEnabled(false);
+               TableAlignCO->setEnabled(false);
+               longtableGB->setEnabled(false);
+               alignmentGB->setEnabled(false);
+       } else
+               enableWidgets();
+
+       return InsetParamsWidget::checkWidgets();
+}
+
+
 bool GuiTabular::funcEnabled(Tabular::Feature f) const
 {
-       string cmd = "tabular " + featureAsString(f);
-       return getStatus(FuncRequest(LFUN_INSET_MODIFY, cmd)).enabled();
+       FuncRequest r(LFUN_INSET_MODIFY, "tabular for-dialog" + featureAsString(f));
+       return getStatus(r).enabled();
 }