]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiGraphics.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiGraphics.cpp
index a7398a17b71992dc254acd76f610ae8f80ccf297..e89bd4cfe6467e0e050ea0d0c88df64609a2b07a 100644 (file)
@@ -6,7 +6,7 @@
  * \author Angus Leeming
  * \author John Levon
  * \author Edwin Leuven
- * \author Herbert Voß
+ * \author Herbert Voß
  * \author Richard Heck
  *
  * Full author contact details are available in file CREDITS.
 #include <config.h>
 
 #include "GuiGraphics.h"
+#include "frontends/alert.h"
+#include "qt_helpers.h"
+#include "Validator.h"
 
 #include "Buffer.h"
+#include "FuncRequest.h"
 #include "LengthCombo.h"
 #include "Length.h"
 #include "LyXRC.h"
-#include "qt_helpers.h"
-#include "Validator.h"
-
-#include "FuncRequest.h"
+#include "Undo.h"
 
 #include "graphics/GraphicsCache.h"
 #include "graphics/GraphicsCacheItem.h"
 #include "graphics/GraphicsImage.h"
 
-#include "frontends/alert.h"
-
-#include "insets/InsetGraphicsParams.h"
+#include "insets/InsetGraphics.h"
 
 #include "support/convert.h"
 #include "support/debug.h"
-#include "support/ExceptionMessage.h"
-#include "support/FileFilterList.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
 using namespace std;
 using namespace lyx::support;
 
+namespace {
+
+// These are the strings that are stored in the LyX file and which
+// correspond to the LaTeX identifiers shown in the comments at the
+// end of each line.
+char const * const rorigin_lyx_strs[] = {
+       // the LaTeX default is leftBaseline
+       "",
+       "leftTop",  "leftBottom", "leftBaseline", // lt lb lB
+       "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
+       "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
+
+// These are the strings, corresponding to the above, that the GUI should
+// use. Note that they can/should be translated.
+char const * const rorigin_gui_strs[] = {
+       N_("Default"),
+       N_("Top left"), N_("Bottom left"), N_("Baseline left"),
+       N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
+       N_("Top right"), N_("Bottom right"), N_("Baseline right") };
+
+size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
+
+static string autostr = N_("automatically");
+
+} // namespace anon
+
+
 namespace lyx {
 namespace frontend {
 
 //FIXME setAutoTextCB should really take an argument, as indicated, that
 //determines what text is to be written for "auto". But making
 //that work involves more extensive revisions than we now want
-//to make, since "auto" also appears in updateContents() (see
-//GuiGraphics.cpp).
+//to make, since "auto" also appears in paramsToDialog().
 //The right way to do this, I think, would be to define a class
 //checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
 //the checkbox, line edit, and length combo together, and then made e.g.
@@ -79,42 +102,13 @@ static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
 {
        if (!checkBox->isChecked())
                lengthToWidgets(lineEdit, lengthCombo,
-                               "auto", lengthCombo->currentLengthItem());
-       else if (lineEdit->text() == "auto")
+                               _(autostr), lengthCombo->currentLengthItem());
+       else if (lineEdit->text() == qt_(autostr))
                lengthToWidgets(lineEdit, lengthCombo, string(),
                                lengthCombo->currentLengthItem());
 }
 
 
-template<class Pair>
-vector<typename Pair::first_type> getFirst(vector<Pair> const & pr)
-{
-       size_t const n = pr.size();
-       vector<typename Pair::first_type> tmp(n);
-       for (size_t i = 0; i != n; ++i)
-               tmp[i] = pr[i].first;
-       return tmp;
-}
-
-
-///
-template<class Pair>
-vector<typename Pair::second_type> getSecond(vector<Pair> const & pr)
-{
-       size_t const n = pr.size();
-       vector<typename Pair::second_type> tmp(n);
-       for (size_t i = 0; i != n; ++i)
-               tmp[i] = pr[i].second;
-       return tmp;
-}
-
-
-/// The (tranlated) GUI string and it's LaTeX equivalent.
-typedef pair<docstring, string> RotationOriginPair;
-///
-vector<RotationOriginPair> getRotationOriginData();
-
-
 GuiGraphics::GuiGraphics(GuiView & lv)
        : GuiDialog(lv, "graphics", qt_("Graphics"))
 {
@@ -129,11 +123,9 @@ GuiGraphics::GuiGraphics(GuiView & lv)
        //graphics pane
        connect(filename, SIGNAL(textChanged(const QString &)),
                this, SLOT(change_adaptor()));
-       connect(embedCB, SIGNAL(toggled(bool)),
+       connect(WidthCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
-       connect(WidthCB, SIGNAL( clicked()),
-               this, SLOT(change_adaptor()));
-       connect(HeightCB, SIGNAL( clicked()),
+       connect(HeightCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
        connect(Width, SIGNAL(textChanged(const QString &)),
                this, SLOT(change_adaptor()));
@@ -159,33 +151,34 @@ GuiGraphics::GuiGraphics(GuiView & lv)
        filename->setValidator(new PathValidator(true, filename));
        setFocusProxy(filename);
 
-       QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
+       QDoubleValidator * scaleValidator = 
+               new DoubleAutoValidator(Scale, qt_(autostr));
        scaleValidator->setBottom(0);
        scaleValidator->setDecimals(256); //I guess that will do
        Scale->setValidator(scaleValidator);
-       Height->setValidator(unsignedLengthAutoValidator(Height));
-       Width->setValidator(unsignedLengthAutoValidator(Width));
+       Height->setValidator(unsignedLengthAutoValidator(Height, qt_(autostr)));
+       Width->setValidator(unsignedLengthAutoValidator(Width, qt_(autostr)));
        angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
 
        //clipping pane
        connect(clip, SIGNAL(stateChanged(int)),
                this, SLOT(change_adaptor()));
        connect(lbY, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_bb()));
+               this, SLOT(changeBB()));
        connect(lbYunit, SIGNAL(activated(int)),
-               this, SLOT(change_bb()));
+               this, SLOT(changeBB()));
        connect(rtY, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_bb()));
+               this, SLOT(changeBB()));
        connect(rtYunit, SIGNAL(activated(int)),
-               this, SLOT(change_bb()));
+               this, SLOT(changeBB()));
        connect(lbX, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_bb()));
+               this, SLOT(changeBB()));
        connect(lbXunit, SIGNAL(activated(int)),
-               this, SLOT(change_bb()));
+               this, SLOT(changeBB()));
        connect(rtX, SIGNAL(textChanged(const QString&)),
-               this, SLOT(change_bb()));
+               this, SLOT(changeBB()));
        connect(rtXunit, SIGNAL(activated(int)),
-               this, SLOT(change_bb()));
+               this, SLOT(changeBB()));
        connect(getPB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
 
@@ -208,12 +201,12 @@ GuiGraphics::GuiGraphics(GuiView & lv)
        // setChecked(). Note, too, that clicked() would get called whenever it
        // is clicked, even right clicked (I think), not just whenever it is
        // toggled.
-       connect(displayGB, SIGNAL(toggled(bool)),
-               this, SLOT(change_adaptor()));
-       connect(showCB, SIGNAL(currentIndexChanged(int)),
-               this, SLOT(change_adaptor()));
+       connect(displayGB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
        connect(displayscale, SIGNAL(textChanged(const QString&)),
                this, SLOT(change_adaptor()));
+       connect(groupCO, SIGNAL(currentIndexChanged(int)),
+               this, SLOT(changeGroup(int)));
+
        displayscale->setValidator(new QIntValidator(displayscale));
 
        bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
@@ -258,7 +251,97 @@ void GuiGraphics::change_adaptor()
 }
 
 
-void GuiGraphics::change_bb()
+void GuiGraphics::changeGroup(int /* index */)
+{
+       QString const new_group = groupCO->itemData(
+               groupCO->currentIndex()).toString();
+       
+       // check if the old group consisted only of this member
+       if (current_group_ != fromqstr(new_group)
+           && graphics::countGroupMembers(buffer(), current_group_) == 1) {
+               if (!new_group.isEmpty()) {
+                       if (Alert::prompt(_("Dissolve previous group?"), 
+                               bformat(_("If you assign this graphic to group '%2$s',\n"
+                                         "the previously assigned group '%1$s' will be dissolved,\n"
+                                         "because this graphic was its only member.\n"
+                                         "How do you want to proceed?"),
+                                       from_utf8(current_group_), qstring_to_ucs4(new_group)),
+                                       0, 0,
+                                       bformat(_("Stick with group '%1$s'"),
+                                               from_utf8(current_group_)),
+                                       bformat(_("Assign to group '%1$s' anyway"),
+                                               qstring_to_ucs4(new_group))) == 0) {
+                               groupCO->setCurrentIndex(
+                                       groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
+                               return;
+                       }
+               } else {
+                       if (Alert::prompt(_("Dissolve previous group?"), 
+                       bformat(_("If you sign off this graphic from group '%1$s',\n"
+                                 "the group will be dissolved,\n"
+                                 "because this graphic was its only member.\n"
+                                 "How do you want to proceed?"),
+                               from_utf8(current_group_)),
+                               0, 0,
+                               bformat(_("Stick with group '%1$s'"),
+                               from_utf8(current_group_)),
+                               bformat(_("Sign off from group '%1$s'"),
+                               from_utf8(current_group_))) == 0) {
+                       groupCO->setCurrentIndex(
+                               groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
+                       return;
+                       }
+               }
+       } 
+
+       if (new_group.isEmpty()) {
+               changed();
+               return;
+       }
+
+       string grp = graphics::getGroupParams(buffer(), fromqstr(new_group));
+       if (grp.empty()) {
+               // group does not exist yet
+               changed();
+               return;
+       }
+       
+       // filename might have been changed
+       QString current_filename = filename->text();
+
+       // group exists: load params into the dialog
+       groupCO->blockSignals(true);
+       InsetGraphics::string2params(grp, buffer(), params_);
+       paramsToDialog(params_);
+       groupCO->blockSignals(false);
+       
+       // reset filename
+       filename->setText(current_filename);
+
+       changed();
+}
+
+
+void GuiGraphics::on_newGroupPB_clicked()
+{
+       docstring newgroup;
+       if (!Alert::askForText(newgroup, _("Enter unique group name:")))
+               return;
+       if (newgroup.empty())
+               return;
+       if (groupCO->findData(toqstr(newgroup), Qt::MatchExactly) != -1) {
+               Alert::warning(_("Group already defined!"), 
+                       bformat(_("A graphics group with the name '%1$s' already exists."),
+                               newgroup));
+               return;
+       }
+       groupCO->addItem(toqstr(newgroup), toqstr(newgroup));
+       groupCO->setCurrentIndex(
+               groupCO->findData(toqstr(newgroup), Qt::MatchExactly));
+}
+
+
+void GuiGraphics::changeBB()
 {
        bbChanged = true;
        LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
@@ -282,25 +365,12 @@ void GuiGraphics::on_getPB_clicked()
 }
 
 
-void GuiGraphics::on_editPB_clicked()
-{
-       editGraphics();
-}
-
-
-void GuiGraphics::on_filename_textChanged(const QString & filename)
-{
-       editPB->setDisabled(filename.isEmpty());
-       EmbeddedFile file = EmbeddedFile(fromqstr(filename), fromqstr(bufferFilepath()));
-}
-
-
 void GuiGraphics::setAutoText()
 {
        if (scaleCB->isChecked())
                return;
        if (!Scale->isEnabled() && Scale->text() != "100")
-               Scale->setText(QString("auto"));
+               Scale->setText(qt_(autostr));
 
        setAutoTextCB(WidthCB, Width, widthUnit);
        setAutoTextCB(HeightCB, Height, heightUnit);
@@ -399,58 +469,45 @@ void GuiGraphics::on_angle_textChanged(const QString & filename)
                                 (filename != "0"));
 }
 
-// returns the number of the string s in the vector v
-static int getItemNo(const vector<string> & v, string const & s)
-{
-       vector<string>::const_iterator cit =
-                   find(v.begin(), v.end(), s);
-       return (cit != v.end()) ? int(cit - v.begin()) : 0;
-}
-
 
-void GuiGraphics::updateContents()
+void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
 {
-       // clear and fill in the comboboxes
-       vector<string> const bb_units = frontend::getBBUnits();
+       static char const * const bb_units[] = { "bp", "cm", "mm", "in" };
+       static char const * const bb_units_gui[] = { N_("bp"), N_("cm"), N_("mm"), N_("in") };
+       size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
+
        lbXunit->clear();
        lbYunit->clear();
        rtXunit->clear();
        rtYunit->clear();
-       for (vector<string>::const_iterator it = bb_units.begin();
-           it != bb_units.end(); ++it) {
-               lbXunit->addItem(toqstr(*it));
-               lbYunit->addItem(toqstr(*it));
-               rtXunit->addItem(toqstr(*it));
-               rtYunit->addItem(toqstr(*it));
+       
+       for (size_t i = 0; i < bb_size; i++) {
+               lbXunit->addItem(qt_(bb_units_gui[i]),
+                       toqstr(bb_units[i]));
+               lbYunit->addItem(qt_(bb_units_gui[i]),
+                       toqstr(bb_units[i]));
+               rtXunit->addItem(qt_(bb_units_gui[i]),
+                       toqstr(bb_units[i]));
+               rtYunit->addItem(qt_(bb_units_gui[i]),
+                       toqstr(bb_units[i]));
        }
-
-       InsetGraphicsParams & igp = params_;
-
+       
        // set the right default unit
-       Length::UNIT unitDefault = Length::CM;
-       switch (lyxrc.default_papersize) {
-               case PAPER_USLETTER:
-               case PAPER_USLEGAL:
-               case PAPER_USEXECUTIVE:
-                       unitDefault = Length::IN;
-                       break;
-               default:
-                       break;
-       }
+       Length::UNIT const defaultUnit = Length::defaultUnit();
 
+       //lyxerr << bufferFilepath();
        string const name =
                igp.filename.outputFilename(fromqstr(bufferFilepath()));
        filename->setText(toqstr(name));
-       embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked);
 
        // set the bounding box values
        if (igp.bb.empty()) {
-               string const bb = readBB(igp.filename.absFilename());
+               string const bb = readBoundingBox(igp.filename.absFilename());
                // the values from the file always have the bigpoint-unit bp
-               lbX->setText(toqstr(token(bb, ' ', 0)));
-               lbY->setText(toqstr(token(bb, ' ', 1)));
-               rtX->setText(toqstr(token(bb, ' ', 2)));
-               rtY->setText(toqstr(token(bb, ' ', 3)));
+               doubleToWidget(lbX, token(bb, ' ', 0));
+               doubleToWidget(lbY, token(bb, ' ', 1));
+               doubleToWidget(rtX, token(bb, ' ', 2));
+               doubleToWidget(rtY, token(bb, ' ', 3));
                lbXunit->setCurrentIndex(0);
                lbYunit->setCurrentIndex(0);
                rtXunit->setCurrentIndex(0);
@@ -464,30 +521,30 @@ void GuiGraphics::updateContents()
                string const xr = token(igp.bb, ' ', 2);
                string const yr = token(igp.bb, ' ', 3);
                if (isValidLength(xl, &anyLength)) {
-                       lbX->setText(toqstr(convert<string>(anyLength.value())));
-                       string const unit(unit_name[anyLength.unit()]);
-                       lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
+                       doubleToWidget(lbX, anyLength.value());
+                       string const unit = unit_name[anyLength.unit()];
+                       lbXunit->setCurrentIndex(lbXunit->findData(toqstr(unit)));
                } else {
                        lbX->setText(toqstr(xl));
                }
                if (isValidLength(yl, &anyLength)) {
-                       lbY->setText(toqstr(convert<string>(anyLength.value())));
-                       string const unit(unit_name[anyLength.unit()]);
-                       lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
+                       doubleToWidget(lbY, anyLength.value());
+                       string const unit = unit_name[anyLength.unit()];
+                       lbYunit->setCurrentIndex(lbYunit->findData(toqstr(unit)));
                } else {
                        lbY->setText(toqstr(xl));
                }
                if (isValidLength(xr, &anyLength)) {
-                       rtX->setText(toqstr(convert<string>(anyLength.value())));
-                       string const unit(unit_name[anyLength.unit()]);
-                       rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
+                       doubleToWidget(rtX, anyLength.value());
+                       string const unit = unit_name[anyLength.unit()];
+                       rtXunit->setCurrentIndex(rtXunit->findData(toqstr(unit)));
                } else {
                        rtX->setText(toqstr(xl));
                }
                if (isValidLength(yr, &anyLength)) {
-                       rtY->setText(toqstr(convert<string>(anyLength.value())));
-                       string const unit(unit_name[anyLength.unit()]);
-                       rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
+                       doubleToWidget(rtY, anyLength.value());
+                       string const unit = unit_name[anyLength.unit()];
+                       rtYunit->setCurrentIndex(rtYunit->findData(toqstr(unit)));
                } else {
                        rtY->setText(toqstr(xl));
                }
@@ -498,43 +555,56 @@ void GuiGraphics::updateContents()
        draftCB->setChecked(igp.draft);
        clip->setChecked(igp.clip);
        unzipCB->setChecked(igp.noUnzip);
-
-       int item = 0;
-       switch (igp.display) {
-               case graphics::DefaultDisplay: item = 0; break;
-               case graphics::MonochromeDisplay: item = 1; break;
-               case graphics::GrayscaleDisplay: item = 2; break;
-               case graphics::ColorDisplay: item = 3; break;
-               case graphics::NoDisplay: item = 0; break;
-       }
-       showCB->setCurrentIndex(item);
+       displayGB->setChecked(igp.display);
        displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
-       displayGB->setChecked(igp.display != graphics::NoDisplay);
 
        // the output section (width/height)
 
-       Scale->setText(toqstr(igp.scale));
+       doubleToWidget(Scale, igp.scale);
        //igp.scale defaults to 100, so we treat it as empty
        bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
        scaleCB->blockSignals(true);
        scaleCB->setChecked(scaleChecked);
        scaleCB->blockSignals(false);
        Scale->setEnabled(scaleChecked);
+       displayGB->setEnabled(lyxrc.display_graphics);
+
+       set<string> grp;
+       graphics::getGraphicsGroups(buffer(), grp);
+       set<string>::const_iterator it = grp.begin();
+       set<string>::const_iterator end = grp.end();
+       groupCO->blockSignals(true);
+       groupCO->clear();
+       for (; it != end; it++)
+               groupCO->addItem(toqstr(*it), toqstr(*it));
+       groupCO->insertItem(0, qt_("None"), QString());
+       if (igp.groupId.empty())
+               groupCO->setCurrentIndex(0);
+       else
+               groupCO->setCurrentIndex(
+                       groupCO->findData(toqstr(igp.groupId), Qt::MatchExactly));
+       groupCO->blockSignals(false);
+
+       if (igp.width.value() == 0)
+               lengthToWidgets(Width, widthUnit, _(autostr), defaultUnit);
+       else
+               lengthToWidgets(Width, widthUnit, igp.width, defaultUnit);
 
-       lengthAutoToWidgets(Width, widthUnit, igp.width,
-               unitDefault);
        bool const widthChecked = !Width->text().isEmpty() &&
-               Width->text() != "auto";
+               Width->text() != qt_(autostr);
        WidthCB->blockSignals(true);
        WidthCB->setChecked(widthChecked);
        WidthCB->blockSignals(false);
        Width->setEnabled(widthChecked);
        widthUnit->setEnabled(widthChecked);
 
-       lengthAutoToWidgets(Height, heightUnit, igp.height,
-               unitDefault);
+       if (igp.height.value() == 0)
+               lengthToWidgets(Height, heightUnit, _(autostr), defaultUnit);
+       else
+               lengthToWidgets(Height, heightUnit, igp.height, defaultUnit);
+
        bool const heightChecked = !Height->text().isEmpty()
-               && Height->text() != "auto";
+               && Height->text() != qt_(autostr);
        HeightCB->blockSignals(true);
        HeightCB->setChecked(heightChecked);
        HeightCB->blockSignals(false);
@@ -548,7 +618,7 @@ void GuiGraphics::updateContents()
 
        setAutoText();
 
-       angle->setText(toqstr(igp.rotateAngle));
+       doubleToWidget(angle, igp.rotateAngle);
        rotateOrderCB->setChecked(igp.scaleBeforeRotation);
 
        rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
@@ -556,25 +626,20 @@ void GuiGraphics::updateContents()
 
        origin->clear();
 
-       vector<RotationOriginPair> origindata = getRotationOriginData();
-       vector<docstring> const origin_lang = getFirst(origindata);
-       origin_ltx = getSecond(origindata);
-
-       for (vector<docstring>::const_iterator it = origin_lang.begin();
-           it != origin_lang.end(); ++it)
-               origin->addItem(toqstr(*it));
+       for (size_t i = 0; i < rorigin_size; i++) {
+               origin->addItem(qt_(rorigin_gui_strs[i]),
+                       toqstr(rorigin_lyx_strs[i]));
+       }
 
        if (!igp.rotateOrigin.empty())
-               origin->setCurrentIndex(
-                       getItemNo(origin_ltx, igp.rotateOrigin));
+               origin->setCurrentIndex(origin->findData(toqstr(igp.rotateOrigin)));
        else
                origin->setCurrentIndex(0);
 
-       // disable edit button when no filename is present
-       editPB->setDisabled(filename->text().isEmpty());
-
-       //// latex section
+       // latex section
        latexoptions->setText(toqstr(igp.special));
+       // cf bug #3852
+       filename->setFocus();
 }
 
 
@@ -583,28 +648,15 @@ void GuiGraphics::applyView()
        InsetGraphicsParams & igp = params_;
 
        igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilepath()));
-       try {
-               Buffer & buf = buffer();
-               EmbeddedFile file(fromqstr(filename->text()), buf.filePath());
-               file.setEmbed(embedCB->checkState() == Qt::Checked);
-               // move file around if needed, an exception may be raised.
-               file.enable(buf.embedded(), &buf, true);
-               // if things are OK..., embed igp.filename
-               igp.filename.setEmbed(file.embedded());
-       } catch (ExceptionMessage const & message) {
-               Alert::error(message.title_, message.details_);
-               // failed to embed
-               igp.filename.setEmbed(false);
-       }
 
        // the bb section
        igp.bb.erase();
        if (bbChanged) {
                string bb;
-               string lbXs = fromqstr(lbX->text());
-               string lbYs = fromqstr(lbY->text());
-               string rtXs = fromqstr(rtX->text());
-               string rtYs = fromqstr(rtY->text());
+               string lbXs = widgetToDoubleStr(lbX);
+               string lbYs = widgetToDoubleStr(lbY);
+               string rtXs = widgetToDoubleStr(rtX);
+               string rtYs = widgetToDoubleStr(rtY);
                int bb_sum =
                        convert<int>(lbXs) + convert<int>(lbYs) +
                        convert<int>(rtXs) + convert<int>(rtXs);
@@ -631,21 +683,11 @@ void GuiGraphics::applyView()
 
        igp.draft = draftCB->isChecked();
        igp.clip = clip->isChecked();
-
-       switch (showCB->currentIndex()) {
-               case 0: igp.display = graphics::DefaultDisplay; break;
-               case 1: igp.display = graphics::MonochromeDisplay; break;
-               case 2: igp.display = graphics::GrayscaleDisplay; break;
-               case 3: igp.display = graphics::ColorDisplay; break;
-               default:;
-       }
-
-       if (!displayGB->isChecked())
-               igp.display = graphics::NoDisplay;
+       igp.display = displayGB->isChecked();
 
        //the graphics section
        if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
-               igp.scale = fromqstr(Scale->text());
+               igp.scale = widgetToDoubleStr(Scale);
                igp.width = Length("0pt");
                igp.height = Length("0pt");
                igp.keepAspectRatio = false;
@@ -666,9 +708,9 @@ void GuiGraphics::applyView()
 
        igp.noUnzip = unzipCB->isChecked();
        igp.lyxscale = displayscale->text().toInt();
-       igp.rotateAngle = fromqstr(angle->text());
+       igp.rotateAngle = widgetToDoubleStr(angle);
 
-       double rotAngle = convert<double>(igp.rotateAngle);
+       double rotAngle = widgetToDouble(angle);
        if (abs(rotAngle) > 360.0) {
                rotAngle -= 360.0 * floor(rotAngle / 360.0);
                igp.rotateAngle = convert<string>(rotAngle);
@@ -676,11 +718,16 @@ void GuiGraphics::applyView()
 
        // save the latex name for the origin. If it is the default
        // then origin_ltx returns ""
-       igp.rotateOrigin = origin_ltx[origin->currentIndex()];
+       igp.rotateOrigin =
+               fromqstr(origin->itemData(origin->currentIndex()).toString());
        igp.scaleBeforeRotation = rotateOrderCB->isChecked();
 
        // more latex options
        igp.special = fromqstr(latexoptions->text());
+
+       igp.groupId = fromqstr(groupCO->itemData(
+               groupCO->currentIndex()).toString());
+       current_group_ = igp.groupId;
 }
 
 
@@ -689,14 +736,14 @@ void GuiGraphics::getBB()
        string const fn = fromqstr(filename->text());
        if (fn.empty())
                return;
-       string const bb = readBB(fn);
+       string const bb = readBoundingBox(fn);
        bbChanged = false;
        if (bb.empty())
                return;
-       lbX->setText(toqstr(token(bb, ' ', 0)));
-       lbY->setText(toqstr(token(bb, ' ', 1)));
-       rtX->setText(toqstr(token(bb, ' ', 2)));
-       rtY->setText(toqstr(token(bb, ' ', 3)));
+       doubleToWidget(lbX, token(bb, ' ', 0));
+       doubleToWidget(lbY, token(bb, ' ', 1));
+       doubleToWidget(rtX, token(bb, ' ', 2));
+       doubleToWidget(rtY, token(bb, ' ', 3));
        // the default units for the bb values when reading
        // it from the file
        lbXunit->setCurrentIndex(0);
@@ -714,7 +761,9 @@ bool GuiGraphics::isValid()
 
 bool GuiGraphics::initialiseParams(string const & data)
 {
-       InsetGraphicsMailer::string2params(data, buffer(), params_);
+       InsetGraphics::string2params(data, buffer(), params_);
+       paramsToDialog(params_);
+       current_group_ = params_.groupId;
        return true;
 }
 
@@ -728,8 +777,7 @@ void GuiGraphics::clearParams()
 void GuiGraphics::dispatchParams()
 {
        InsetGraphicsParams tmp_params(params_);
-       string const lfun =
-               InsetGraphicsMailer::params2string(tmp_params, buffer());
+       string const lfun = InsetGraphics::params2string(tmp_params, buffer());
        dispatch(FuncRequest(getLfun(), lfun));
 }
 
@@ -743,19 +791,19 @@ QString GuiGraphics::browse(QString const & in_name) const
        FileName clip(clipdir);
 
        // bail out to system clipart directory
-       if (!(clip.exists() && clip.isDirectory()))
+       if (!clip.isDirectory())
                clipdir = addName(package().system_support().absFilename(), "clipart");
 
        return browseRelFile(in_name, bufferFilepath(),
-               title, FileFilterList(), false, 
+               title, fileFilters(QString()), false, 
                qt_("Clipart|#C#c"), toqstr(clipdir),
                qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
 }
 
 
-string const GuiGraphics::readBB(string const & file)
+string GuiGraphics::readBoundingBox(string const & file)
 {
-       FileName const abs_file = makeAbsPath(file, fromqstr(bufferFilepath()));
+       FileName const abs_file = support::makeAbsPath(file, fromqstr(bufferFilepath()));
 
        // try to get it from the file, if possible. Zipped files are
        // unzipped in the readBB_from_PSFile-Function
@@ -781,69 +829,10 @@ string const GuiGraphics::readBB(string const & file)
 }
 
 
-bool GuiGraphics::isFilenameValid(string const & fname) const
+bool GuiGraphics::isFileNameValid(string const & fname) const
 {
        // It may be that the filename is relative.
-       return makeAbsPath(fname, fromqstr(bufferFilepath())).isReadableFile();
-}
-
-
-void GuiGraphics::editGraphics()
-{
-       applyView();
-       string const lfun =
-               InsetGraphicsMailer::params2string(params_, buffer());
-       dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
-}
-
-
-namespace {
-
-char const * const bb_units[] = { "bp", "cm", "mm", "in" };
-size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
-
-// These are the strings that are stored in the LyX file and which
-// correspond to the LaTeX identifiers shown in the comments at the
-// end of each line.
-char const * const rorigin_lyx_strs[] = {
-       // the LaTeX default is leftBaseline
-       "",
-       "leftTop",  "leftBottom", "leftBaseline", // lt lb lB
-       "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
-       "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
-
-// These are the strings, corresponding to the above, that the GUI should
-// use. Note that they can/should be translated.
-char const * const rorigin_gui_strs[] = {
-       N_("Default"),
-       N_("Top left"), N_("Bottom left"), N_("Baseline left"),
-       N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
-       N_("Top right"), N_("Bottom right"), N_("Baseline right") };
-
-size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
-
-} // namespace anon
-
-
-vector<string> const getBBUnits()
-{
-       return vector<string>(bb_units, bb_units + bb_size);
-}
-
-
-vector<RotationOriginPair> getRotationOriginData()
-{
-       static vector<RotationOriginPair> data;
-       if (!data.empty())
-               return data;
-
-       data.resize(rorigin_size);
-       for (size_type i = 0; i < rorigin_size; ++i) {
-               data[i] = make_pair(_(rorigin_gui_strs[i]),
-                                   rorigin_lyx_strs[i]);
-       }
-
-       return data;
+       return support::makeAbsPath(fname, fromqstr(bufferFilepath())).isReadableFile();
 }
 
 
@@ -853,4 +842,4 @@ Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
 } // namespace frontend
 } // namespace lyx
 
-#include "GuiGraphics_moc.cpp"
+#include "moc_GuiGraphics.cpp"