]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiTabular.cpp
If we are in a closeEvent, we don't want to close all buffers, because these may...
[lyx.git] / src / frontends / qt4 / GuiTabular.cpp
index 67062aa615f4f34a3f1890014e63fe115a7a35b5..25d5427685209530e292016148dc175876ff25df 100644 (file)
@@ -6,6 +6,7 @@
  * \author John Levon
  * \author Jürgen Spitzmüller
  * \author Herbert Voß
+ * \author Uwe Stöhr
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -52,6 +53,8 @@ GuiTabular::GuiTabular(GuiView & lv)
        bottomspaceED->setValidator(new LengthValidator(bottomspaceED));
        interlinespaceED->setValidator(new LengthValidator(interlinespaceED));
 
+       widthUnitCB->setCurrentItem(Length::defaultUnit());
+
        connect(topspaceED, SIGNAL(returnPressed()),
                this, SLOT(topspace_changed()));
        connect(topspaceUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
@@ -82,6 +85,11 @@ GuiTabular::GuiTabular(GuiView & lv)
                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(hAlign_changed(int)));
        connect(vAlignCB, SIGNAL(activated(int)),
@@ -122,7 +130,7 @@ GuiTabular::GuiTabular(GuiView & lv)
                this, SLOT(specialAlignment_changed()));
        connect(widthED, SIGNAL(editingFinished()),
                this, SLOT(width_changed()));
-       connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+       connect(widthUnitCB, SIGNAL(selectionChanged(lyx::Length::UNIT)),
                this, SLOT(width_changed()));
        connect(closePB, SIGNAL(clicked()),
                this, SLOT(close_clicked()));
@@ -138,9 +146,17 @@ GuiTabular::GuiTabular(GuiView & lv)
                this, SLOT(rotateTabular()));
        connect(rotateCellCB, SIGNAL(clicked()),
                this, SLOT(rotateCell()));
+       connect(TableAlignCB, SIGNAL(activated(int)),
+               this, SLOT(tableAlignment_changed(int)));
        connect(longTabularCB, SIGNAL(clicked()),
                this, SLOT(longTabular()));
-
+       connect(leftRB, SIGNAL(clicked()),
+               this, SLOT(ltAlignment_clicked()));
+       connect(centerRB, SIGNAL(clicked()),
+               this, SLOT(ltAlignment_clicked()));
+       connect(rightRB, SIGNAL(clicked()),
+               this, SLOT(ltAlignment_clicked()));
+               
        bc().setPolicy(ButtonPolicy::IgnorantPolicy);
        
        bc().addReadOnly(topspaceED);
@@ -160,9 +176,10 @@ GuiTabular::GuiTabular(GuiView & 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);
@@ -182,7 +199,10 @@ GuiTabular::GuiTabular(GuiView & 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);
@@ -365,7 +385,7 @@ void GuiTabular::specialAlignment_changed()
 void GuiTabular::width_changed()
 {
        changed();
-       string const width = widgetsToLength(widthED, widthUnit);
+       string const width = widgetsToLength(widthED, widthUnitCB);
        setWidth(width);
 }
 
@@ -420,6 +440,19 @@ void GuiTabular::vAlign_changed(int align)
 }
 
 
+void GuiTabular::tableAlignment_changed(int align)
+{
+       switch (align) {
+               case 0: set(Tabular::TABULAR_VALIGN_TOP);
+                       break;
+               case 1: set(Tabular::TABULAR_VALIGN_MIDDLE);
+                       break;
+               case 2: set(Tabular::TABULAR_VALIGN_BOTTOM);
+                       break;
+       }
+}
+
+
 void GuiTabular::longTabular()
 {
        longTabular(longTabularCB->isChecked());
@@ -448,9 +481,6 @@ void GuiTabular::ltHeaderStatus_clicked()
                set(Tabular::SET_LTHEAD, "");
        else
                set(Tabular::UNSET_LTHEAD, "");
-       headerBorderAboveCB->setEnabled(enable);
-       headerBorderBelowCB->setEnabled(enable);
-       firstheaderNoContentsCB->setEnabled(enable);
        changed();
 }
 
@@ -502,8 +532,6 @@ void GuiTabular::ltFirstHeaderStatus_clicked()
                set(Tabular::SET_LTFIRSTHEAD, "");
        else
                set(Tabular::UNSET_LTFIRSTHEAD, "");
-       firstheaderBorderAboveCB->setEnabled(enable);
-       firstheaderBorderBelowCB->setEnabled(enable);
        changed();
 }
 
@@ -515,9 +543,6 @@ void GuiTabular::ltFirstHeaderEmpty_clicked()
                set(Tabular::SET_LTFIRSTHEAD, "empty");
        else
                set(Tabular::UNSET_LTFIRSTHEAD, "empty");
-       firstheaderStatusCB->setEnabled(!enable);
-       firstheaderBorderAboveCB->setEnabled(!enable);
-       firstheaderBorderBelowCB->setEnabled(!enable);
        changed();
 }
 
@@ -529,9 +554,6 @@ void GuiTabular::ltFooterStatus_clicked()
                set(Tabular::SET_LTFOOT, "");
        else
                set(Tabular::UNSET_LTFOOT, "");
-       footerBorderAboveCB->setEnabled(enable);
-       footerBorderBelowCB->setEnabled(enable);
-       lastfooterNoContentsCB->setEnabled(enable);
        changed();
 }
 
@@ -563,8 +585,6 @@ void GuiTabular::ltLastFooterStatus_clicked()
                set(Tabular::SET_LTLASTFOOT, "");
        else
                set(Tabular::UNSET_LTLASTFOOT, "");
-       lastfooterBorderAboveCB->setEnabled(enable);
-       lastfooterBorderBelowCB->setEnabled(enable);
        changed();
 }
 
@@ -596,9 +616,18 @@ void GuiTabular::ltLastFooterEmpty_clicked()
                set(Tabular::SET_LTLASTFOOT, "empty");
        else
                set(Tabular::UNSET_LTLASTFOOT, "empty");
-       lastfooterStatusCB->setEnabled(!enable);
-       lastfooterBorderAboveCB->setEnabled(!enable);
-       lastfooterBorderBelowCB->setEnabled(!enable);
+       changed();
+}
+
+
+void GuiTabular::ltAlignment_clicked()
+{
+       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);
        changed();
 }
 
@@ -743,13 +772,15 @@ void GuiTabular::updateContents()
        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"));
@@ -803,6 +834,23 @@ void GuiTabular::updateContents()
        hAlignCB->setEnabled(true);
        vAlignCB->setEnabled(!pwidth.zero());
 
+       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);
@@ -824,6 +872,23 @@ void GuiTabular::updateContents()
                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));
@@ -838,20 +903,17 @@ void GuiTabular::updateContents()
        // 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(
@@ -859,12 +921,7 @@ void GuiTabular::updateContents()
        // 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));
        // When a row is set as longtable caption, it must not be allowed
@@ -890,6 +947,12 @@ void GuiTabular::updateContents()
        }
 
        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);
@@ -922,6 +985,12 @@ void GuiTabular::updateContents()
        }
 
        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);
@@ -952,7 +1021,7 @@ void GuiTabular::closeGUI()
        // apply the fixed width values
        size_t const cell = getActiveCell();
        bool const multicol = tabular_.isMultiColumn(cell);
-       string width = widgetsToLength(widthED, widthUnit);
+       string width = widgetsToLength(widthED, widthUnitCB);
        string width2;
 
        Length llen = getColumnPWidth(tabular_, cell);