]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/FloatPlacement.cpp
Improve wording (#10670)
[lyx.git] / src / frontends / qt4 / FloatPlacement.cpp
index 145c98707103e0fd0b397c60a2e41d338237a46c..59bdf62ec83a87ab6c4950fd003f7ae5e009a72d 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * \file floatplacement.C
+ * \file FloatPlacement.cpp
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
 #include "FloatPlacement.h"
 #include "qt_helpers.h"
 
+#include "Buffer.h"
+#include "BufferParams.h"
+#include "FloatList.h"
+#include "TextClass.h"
+
 #include "insets/InsetFloat.h"
 #include "support/lstrings.h"
 
-using lyx::support::contains;
-using std::string;
+#include <map>
+
+using namespace std;
+using namespace lyx::support;
+
+
+namespace lyx {
 
-//namespace lyx {
+namespace frontend {
 
-FloatPlacement::FloatPlacement(QWidget *)
+FloatPlacement::FloatPlacement(bool show_options, QWidget * parent)
+       : InsetParamsWidget(parent), standardfloat_ (true),
+         allows_wide_(true), allows_sideways_(true), float_list_(0)
 {
        setupUi(this);
 
-       connect(topCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
-       connect(bottomCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
-       connect(pageCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
-       connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
-       connect(defaultsCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
-       connect(defaultsCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
-       connect(ignoreCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
+       connect(floatTypeCO, SIGNAL(activated(int)), this, SLOT(changedSlot()));
+       connect(topCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
+       connect(bottomCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
        connect(pageCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
-       connect(heredefinitelyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
        connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
-       connect(bottomCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
-       connect(topCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
+       connect(heredefinitelyCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
+       connect(ignoreCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
+       connect(spanCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
+       connect(sidewaysCB, SIGNAL(clicked()), this, SLOT(changedSlot()));
 
-       spanCB->hide();
-       sidewaysCB->hide();
+       floatTypeTitle->setVisible(show_options);
+       floatTypeCO->setVisible(show_options);
+       spanCB->setVisible(show_options);
+       sidewaysCB->setVisible(show_options);
+}
+
+
+docstring FloatPlacement::dialogToParams() const
+{
+       InsetFloatParams params;
+       params.type = fromqstr(floatTypeCO->itemData(floatTypeCO->currentIndex()).toString());
+       params.placement = get(params.wide, params.sideways);
+       return from_ascii(InsetFloat::params2string(params));
 }
 
 
@@ -56,10 +76,9 @@ void FloatPlacement::useSideways()
 }
 
 
-void FloatPlacement::changedSlot()
+bool FloatPlacement::possiblePlacement(char const & p) const
 {
-       // emit signal
-       changed();
+       return !spanCB->isVisible() || contains(allowed_placement_, p);
 }
 
 
@@ -75,22 +94,22 @@ void FloatPlacement::set(string const & placement)
 
        if (placement.empty()) {
                def_placement = true;
-       } else if (contains(placement, 'H')) {
+       } else if (contains(placement, 'H') && possiblePlacement('H')) {
                here_definitely = true;
        } else {
-               if (contains(placement, '!')) {
+               if (contains(placement, '!') && possiblePlacement('!')) {
                        force = true;
                }
-               if (contains(placement, 't')) {
+               if (contains(placement, 't') && possiblePlacement('t')) {
                        top = true;
                }
-               if (contains(placement, 'b')) {
+               if (contains(placement, 'b') && possiblePlacement('b')) {
                        bottom = true;
                }
-               if (contains(placement, 'p')) {
+               if (contains(placement, 'p') && possiblePlacement('p')) {
                        page = true;
                }
-               if (contains(placement, 'h')) {
+               if (contains(placement, 'h') && possiblePlacement('h')) {
                        here = true;
                }
        }
@@ -101,26 +120,57 @@ void FloatPlacement::set(string const & placement)
        pageCB->setChecked(page);
        herepossiblyCB->setChecked(here);
        ignoreCB->setChecked(force);
-       ignoreCB->setEnabled(top || bottom || page || here);
        heredefinitelyCB->setChecked(here_definitely);
        checkAllowed();
 }
 
 
-void FloatPlacement::set(lyx::InsetFloatParams const & params)
+void FloatPlacement::initFloatTypeCO(FloatList const & floats)
+{
+       if (float_list_ == &floats)
+               return;
+
+       float_list_ = &floats;
+       floatTypeCO->clear();
+       FloatList::const_iterator it = floats.begin();
+       FloatList::const_iterator const end = floats.end();
+       for (; it != end; ++it) {
+               floatTypeCO->addItem(qt_(it->second.name()),
+                                    toqstr(it->second.floattype()));
+       }
+}
+
+
+void FloatPlacement::paramsToDialog(Inset const * inset)
 {
+       InsetFloat const * fl = static_cast<InsetFloat const *>(inset);
+       InsetFloatParams const & params = fl->params();
+
+       BufferParams const & bp = fl->buffer().params();
+       FloatList const & floats = bp.documentClass().floats();
+       initFloatTypeCO(floats);
+
+       int const item = floatTypeCO->findData(toqstr(params.type));
+       floatTypeCO->setCurrentIndex(item);
+
+       allowed_placement_ = floats.allowedPlacement(params.type);
+       allows_sideways_ = floats.allowsSideways(params.type);
+       allows_wide_ = floats.allowsWide(params.type);
+
        set(params.placement);
 
+       standardfloat_ = (params.type == "figure"
+               || params.type == "table");
+
        if (params.wide) {
                herepossiblyCB->setChecked(false);
                heredefinitelyCB->setChecked(false);
                bottomCB->setChecked(false);
        }
 
-       spanCB->setChecked(params.wide);
-       sidewaysCB->setChecked(params.sideways);
-       sidewaysCB->setEnabled(params.type == "figure"
-               || params.type == "table");
+       spanCB->setChecked(params.wide && allows_wide_);
+       sidewaysCB->setChecked(params.sideways && allows_sideways_);
+
        checkAllowed();
 }
 
@@ -164,77 +214,92 @@ string const FloatPlacement::get() const
 }
 
 
-void FloatPlacement::tbhpClicked()
+void FloatPlacement::on_defaultsCB_stateChanged(int state)
 {
-       heredefinitelyCB->setChecked(false);
        checkAllowed();
-}
-
-
-void FloatPlacement::on_heredefinitelyCB_clicked()
-{
-       if (heredefinitelyCB->isChecked())
-               ignoreCB->setEnabled(false);
-
-       topCB->setChecked(false);
-       bottomCB->setChecked(false);
-       pageCB->setChecked(false);
-       herepossiblyCB->setChecked(false);
-       ignoreCB->setChecked(false);
-}
-
-
-void FloatPlacement::on_spanCB_clicked()
-{
-       checkAllowed();
-       changed();
-
-       if (!spanCB->isChecked())
+       if (state == Qt::Checked)
                return;
-
-       herepossiblyCB->setChecked(false);
-       heredefinitelyCB->setChecked(false);
-       bottomCB->setChecked(false);
+       if (topCB->isChecked() || bottomCB->isChecked()
+          || pageCB->isChecked() || herepossiblyCB->isChecked()
+          || heredefinitelyCB->isChecked() || ignoreCB->isChecked())
+               changed();
 }
 
 
-void FloatPlacement::on_sidewaysCB_clicked()
+void FloatPlacement::changedSlot()
 {
        checkAllowed();
        changed();
 }
 
 
-void FloatPlacement::checkAllowed()
+void FloatPlacement::checkAllowed() const
 {
        bool const defaults = defaultsCB->isChecked();
-       bool ignore = topCB->isChecked();
-       ignore |= bottomCB->isChecked();
-       ignore |= pageCB->isChecked();
-       ignore |= herepossiblyCB->isChecked();
+       bool const ignore = topCB->isChecked() || bottomCB->isChecked()
+                     || pageCB->isChecked() || herepossiblyCB->isChecked();
+       bool const heredefinitely = heredefinitelyCB->isChecked();
 
        // float or document dialog?
        if (spanCB->isVisible()) {
                bool const span = spanCB->isChecked();
                bool const sideways = sidewaysCB->isChecked();
-               defaultsCB->setEnabled(!sideways);
-               topCB->setEnabled(!sideways && !defaults);
-               bottomCB->setEnabled(!sideways && !defaults && !span);
-               pageCB->setEnabled(!sideways && !defaults);
-               ignoreCB->setEnabled(!sideways && !defaults && ignore);
-               herepossiblyCB->setEnabled(!sideways && !defaults && !span);
-               heredefinitelyCB->setEnabled(!sideways && !defaults && !span);
-               spanCB->setEnabled(!sideways);
+               topCB->setEnabled(!sideways && !defaults && !heredefinitely
+                                 && contains(allowed_placement_, 't'));
+               bottomCB->setEnabled(!sideways && !defaults && !span && !heredefinitely
+                                    && contains(allowed_placement_, 'b'));
+               pageCB->setEnabled(!sideways && !defaults && !heredefinitely
+                                  && contains(allowed_placement_, 'p'));
+               if (!pageCB->isChecked())
+                       pageCB->setChecked(sideways && contains(allowed_placement_, 'p'));
+               herepossiblyCB->setEnabled(!defaults && !span && !heredefinitely
+                                          && contains(allowed_placement_, 'h'));
+               heredefinitelyCB->setEnabled(!defaults && !span
+                                            && contains(allowed_placement_, 'H'));
+               ignoreCB->setEnabled(!defaults && ignore && !heredefinitely
+                                    && contains(allowed_placement_, '!'));
+               // handle special case with sideways
+               if ((!herepossiblyCB->isChecked() && sideways) || (span && sideways))
+                       ignoreCB->setEnabled(false);
+               // when disabled the options must be unchecked to avoid strange LaTeX export
+               // don't do it for pageCB because this case is handled with sideways
+               if (ignoreCB->isChecked() && !ignoreCB->isEnabled())
+                       ignoreCB->setChecked(false);
+               if (herepossiblyCB->isChecked() && !herepossiblyCB->isEnabled())
+                       herepossiblyCB->setChecked(false);
+               if (topCB->isChecked() && !topCB->isEnabled())
+                       topCB->setChecked(false);
+               if (bottomCB->isChecked() && !bottomCB->isEnabled())
+                       bottomCB->setChecked(false);
+               spanCB->setEnabled(allows_wide_ && (!sideways || standardfloat_));
+               sidewaysCB->setEnabled(allows_sideways_);
+               defaultsCB->setEnabled(!(sideways && span));
        } else {
-               topCB->setEnabled(!defaults);
-               bottomCB->setEnabled(!defaults);
-               pageCB->setEnabled(!defaults);
-               ignoreCB->setEnabled(!defaults && ignore);
-               herepossiblyCB->setEnabled(!defaults);
+               topCB->setEnabled(!defaults && !heredefinitely);
+               bottomCB->setEnabled(!defaults && !heredefinitely);
+               pageCB->setEnabled(!defaults && !heredefinitely);
+               herepossiblyCB->setEnabled(!defaults && !heredefinitely);
                heredefinitelyCB->setEnabled(!defaults);
+               ignoreCB->setEnabled(!defaults && ignore && !heredefinitely);
        }
 }
 
-//} // namespace lyx
 
-#include "FloatPlacement_moc.cpp"
+bool FloatPlacement::checkWidgets(bool readonly) const
+{
+       if (readonly) {
+               floatTypeCO->setEnabled(false);
+               defaultsCB->setEnabled(false);
+               options->setEnabled(false);
+               spanCB->setEnabled(false);
+               sidewaysCB->setEnabled(false);
+       } else
+               checkAllowed();
+
+       return InsetParamsWidget::checkWidgets();
+}
+
+} // namespace frontend
+} // namespace lyx
+
+#include "moc_FloatPlacement.cpp"