]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiBox.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiBox.cpp
index da2abe8f43f89837adcfe6db2ddc975d02b1910e..6a991b5df5063e4fc6a61827c70397038ed76466 100644 (file)
@@ -26,7 +26,6 @@
 #include "insets/InsetBox.h"
 
 #include "support/gettext.h"
-#include "support/foreach.h"
 #include "support/lstrings.h"
 
 #include <QComboBox>
@@ -80,7 +79,6 @@ static QStringList boxGuiSpecialLengthNames()
 static QList<ColorCode> colors()
 {
        QList<ColorCode> colors;
-       colors << Color_none;
        colors << Color_black;
        colors << Color_white;
        colors << Color_blue;
@@ -139,8 +137,8 @@ GuiBox::GuiBox(QWidget * parent) : InsetParamsWidget(parent)
        connect(shadowsizeED, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
        connect(shadowsizeUnitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
                this, SIGNAL(changed()));
-       connect(frameColorCO, SIGNAL(highlighted(QString)), this, SIGNAL(changed()));
-       connect(backgroundColorCO, SIGNAL(highlighted(QString)), this, SIGNAL(changed()));
+       connect(backgroundColorCO, SIGNAL(currentIndexChanged(int)),
+               this, SIGNAL(changed()));
 
        heightED->setValidator(unsignedLengthValidator(heightED));
        widthED->setValidator(unsignedLengthValidator(widthED));
@@ -157,8 +155,9 @@ GuiBox::GuiBox(QWidget * parent) : InsetParamsWidget(parent)
 
        // the background can be uncolored while the frame cannot
        color_codes_ = colors();
-       fillComboColor(frameColorCO, false);
+       qSort(color_codes_.begin(), color_codes_.end(), ColorSorter);
        fillComboColor(backgroundColorCO, true);
+       fillComboColor(frameColorCO, false);
 
        initDialog();
 }
@@ -166,13 +165,14 @@ GuiBox::GuiBox(QWidget * parent) : InsetParamsWidget(parent)
 
 void GuiBox::fillComboColor(QComboBox * combo, bool const is_none)
 {
+       combo->clear();
        QPixmap coloritem(32, 32);
        QColor color;
        // frameColorCO cannot be uncolored
        if (is_none)
                combo->addItem(toqstr(translateIfPossible(lcolor.getGUIName(Color_none))),
                               toqstr(lcolor.getLaTeXName(Color_none)));
-       QList<ColorCode>::const_iterator cit = color_codes_.begin() + 1;
+       QList<ColorCode>::const_iterator cit = color_codes_.begin();
        for (; cit != color_codes_.end(); ++cit) {
                QString const latexname = toqstr(lcolor.getLaTeXName(*cit));
                QString const guiname = toqstr(translateIfPossible(lcolor.getGUIName(*cit)));
@@ -183,10 +183,9 @@ void GuiBox::fillComboColor(QComboBox * combo, bool const is_none)
 }
 
 
-void GuiBox::on_innerBoxCO_activated(int /* index */)
+void GuiBox::on_innerBoxCO_activated(int index)
 {
-       QString itype =
-               innerBoxCO->itemData(innerBoxCO->currentIndex()).toString();
+       QString itype = innerBoxCO->itemData(index).toString();
        // handle parbox and minipage the same way
        bool const ibox = (itype != "none" && itype != "makebox");
        if (heightCB->isChecked() && !ibox)
@@ -233,8 +232,8 @@ void GuiBox::on_frameColorCO_currentIndexChanged(int index)
 {
        // if there is a non-black frame color the background cannot be uncolored
        // therefore remove the entry "none" in this case
+       int const n = backgroundColorCO->findData("none");
        if (index != frameColorCO->findData("black")) {
-               int const n = backgroundColorCO->findData("none");
                if (n != -1) {
                        if (backgroundColorCO->currentIndex() == n)
                                backgroundColorCO->setCurrentIndex(
@@ -242,7 +241,7 @@ void GuiBox::on_frameColorCO_currentIndexChanged(int index)
                        backgroundColorCO->removeItem(n);
                }
        } else {
-               if (backgroundColorCO->count() == color_codes_.count() - 1)
+               if (n == -1)
                        backgroundColorCO->insertItem(0, toqstr(translateIfPossible((lcolor.getGUIName(Color_none)))),
                                                      toqstr(lcolor.getLaTeXName(Color_none)));
        }
@@ -334,14 +333,16 @@ void GuiBox::paramsToDialog(Inset const * inset)
        ialignCO->setEnabled(ibox);
        setSpecial(ibox);
 
-       // halign is only allowed if a width is used
-       halignCO->setEnabled(widthCB->isChecked());
+       // halign is only allowed without inner box and if a width is used and if
+       // pagebreak is not used
+       halignCO->setEnabled(!pagebreakCB->isChecked() && widthCB->isChecked()
+                            && ((!ibox && type == "Boxed") || inner_type == "makebox"));
        // add the entry "Stretch" if the box is \makebox or \framebox and if not already there
        if ((inner_type == "makebox" || (type == "Boxed" && inner_type == "none"))
                && halignCO->count() < 4)
-               halignCO->addItem(toqstr("Stretch"));
+               halignCO->addItem(qt_("Stretch"));
        else if (inner_type != "makebox" && (type != "Boxed" && inner_type != "none"))
-               halignCO->removeItem(3); 
+               halignCO->removeItem(3);
        // pagebreak is only allowed for Boxed without inner box
        pagebreakCB->setEnabled(!ibox && type == "Boxed");
 
@@ -438,7 +439,7 @@ docstring GuiBox::dialogToParams() const
                if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
                        params.special = fromqstr(unit);
                        // Note: the unit is simply ignored in this case
-                       params.width = Length(value.toDouble(), Length::IN);
+                       params.width = Length(widgetToDouble(widthED), Length::IN);
                } else {
                        params.special = "none";
                        // we must specify a valid length in this case
@@ -464,7 +465,7 @@ docstring GuiBox::dialogToParams() const
                if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
                        params.height_special = fromqstr(unit);
                        // Note: the unit is simply ignored in this case
-                       params.height = Length(value.toDouble(), Length::IN);
+                       params.height = Length(widgetToDouble(heightED), Length::IN);
                } else {
                        params.height_special = "none";
                        params.height =
@@ -547,12 +548,14 @@ bool GuiBox::checkWidgets(bool readonly) const
                        widthED->setEnabled(false);
                        widthUnitsLC->setEnabled(false);
                }
-               // halign is only allowed if a width is used
-               halignCO->setEnabled(widthCB->isChecked());
+               // halign is only allowed without inner box and if a width is used and if
+               // pagebreak is not used
+               halignCO->setEnabled(!pagebreakCB->isChecked() && widthCB->isChecked()
+                                    && ((!ibox && outer == "Boxed") || itype == "makebox"));
                // add the entry "Stretch" if the box is \makebox or \framebox and if not already there
                if ((itype == "makebox" || (outer == "Boxed" && itype == "none"))
                        && halignCO->count() < 4)
-                       halignCO->addItem(toqstr("Stretch"));
+                       halignCO->addItem(qt_("Stretch"));
                else if (itype != "makebox" && (outer != "Boxed" && itype != "none"))
                        halignCO->removeItem(3);
                // pagebreak is only allowed for Boxed without inner box