]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiGraphics.cpp
fix completion painting for RTL (inline completion and completion list)
[lyx.git] / src / frontends / qt4 / GuiGraphics.cpp
index a96e1a795f19d07e8c5c3c8efee06b6ee0aa91c8..1ceb9af9a557decb14e712820b5c3f15294e4f45 100644 (file)
@@ -16,7 +16,6 @@
 
 #include "GuiGraphics.h"
 
-#include "Buffer.h"
 #include "LengthCombo.h"
 #include "Length.h"
 #include "LyXRC.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 *);
+
+} // 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.
@@ -112,7 +131,21 @@ vector<typename Pair::second_type> getSecond(vector<Pair> const & pr)
 /// The (tranlated) GUI string and it's LaTeX equivalent.
 typedef pair<docstring, string> RotationOriginPair;
 ///
-vector<RotationOriginPair> getRotationOriginData();
+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;
+}
+
 
 
 GuiGraphics::GuiGraphics(GuiView & lv)
@@ -129,8 +162,6 @@ GuiGraphics::GuiGraphics(GuiView & lv)
        //graphics pane
        connect(filename, SIGNAL(textChanged(const QString &)),
                this, SLOT(change_adaptor()));
-       connect(embedCB, SIGNAL(toggled(bool)),
-               this, SLOT(change_adaptor()));
        connect(WidthCB, SIGNAL( clicked()),
                this, SLOT(change_adaptor()));
        connect(HeightCB, SIGNAL( clicked()),
@@ -214,6 +245,8 @@ GuiGraphics::GuiGraphics(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(displayscale, SIGNAL(textChanged(const QString&)),
                this, SLOT(change_adaptor()));
+       connect(groupId, SIGNAL(textChanged(const QString&)),
+               this, SLOT(change_adaptor()));
        displayscale->setValidator(new QIntValidator(displayscale));
 
        bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
@@ -282,12 +315,6 @@ void GuiGraphics::on_getPB_clicked()
 }
 
 
-void GuiGraphics::on_filename_textChanged(const QString & filename)
-{
-       EmbeddedFile file = EmbeddedFile(fromqstr(filename), fromqstr(bufferFilepath()));
-}
-
-
 void GuiGraphics::setAutoText()
 {
        if (scaleCB->isChecked())
@@ -393,7 +420,7 @@ void GuiGraphics::on_angle_textChanged(const QString & filename)
 }
 
 // returns the number of the string s in the vector v
-static int getItemNo(const vector<string> & v, string const & s)
+static int itemNumber(const vector<string> & v, string const & s)
 {
        vector<string>::const_iterator cit =
                    find(v.begin(), v.end(), s);
@@ -401,24 +428,24 @@ static int getItemNo(const vector<string> & v, string const & s)
 }
 
 
-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" };
+       size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
+
+       vector<string> const units = vector<string>(bb_units, bb_units + bb_size);
        lbXunit->clear();
        lbYunit->clear();
        rtXunit->clear();
        rtYunit->clear();
-       for (vector<string>::const_iterator it = bb_units.begin();
-           it != bb_units.end(); ++it) {
+       for (vector<string>::const_iterator it = units.begin();
+           it != units.end(); ++it) {
                lbXunit->addItem(toqstr(*it));
                lbYunit->addItem(toqstr(*it));
                rtXunit->addItem(toqstr(*it));
                rtYunit->addItem(toqstr(*it));
        }
 
-       InsetGraphicsParams & igp = params_;
-
        // set the right default unit
        Length::UNIT unitDefault = Length::CM;
        switch (lyxrc.default_papersize) {
@@ -431,14 +458,14 @@ void GuiGraphics::updateContents()
                        break;
        }
 
+       //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)));
@@ -458,29 +485,29 @@ void GuiGraphics::updateContents()
                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));
+                       string const unit = unit_name[anyLength.unit()];
+                       lbXunit->setCurrentIndex(itemNumber(units, 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));
+                       string const unit = unit_name[anyLength.unit()];
+                       lbYunit->setCurrentIndex(itemNumber(units, 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));
+                       string const unit = unit_name[anyLength.unit()];
+                       rtXunit->setCurrentIndex(itemNumber(units, 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));
+                       string const unit = unit_name[anyLength.unit()];
+                       rtYunit->setCurrentIndex(itemNumber(units, unit));
                } else {
                        rtY->setText(toqstr(xl));
                }
@@ -514,6 +541,8 @@ void GuiGraphics::updateContents()
        scaleCB->blockSignals(false);
        Scale->setEnabled(scaleChecked);
 
+       groupId->setText(toqstr(igp.groupId));
+
        lengthAutoToWidgets(Width, widthUnit, igp.width,
                unitDefault);
        bool const widthChecked = !Width->text().isEmpty() &&
@@ -558,12 +587,11 @@ void GuiGraphics::updateContents()
                origin->addItem(toqstr(*it));
 
        if (!igp.rotateOrigin.empty())
-               origin->setCurrentIndex(
-                       getItemNo(origin_ltx, igp.rotateOrigin));
+               origin->setCurrentIndex(itemNumber(origin_ltx, igp.rotateOrigin));
        else
                origin->setCurrentIndex(0);
 
-       //// latex section
+       // latex section
        latexoptions->setText(toqstr(igp.special));
 }
 
@@ -573,19 +601,6 @@ 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();
@@ -671,6 +686,8 @@ void GuiGraphics::applyView()
 
        // more latex options
        igp.special = fromqstr(latexoptions->text());
+
+       igp.groupId = fromqstr(groupId->text());
 }
 
 
@@ -679,7 +696,7 @@ 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;
@@ -705,6 +722,7 @@ bool GuiGraphics::isValid()
 bool GuiGraphics::initialiseParams(string const & data)
 {
        InsetGraphics::string2params(data, buffer(), params_);
+       paramsToDialog(params_);
        return true;
 }
 
@@ -720,6 +738,9 @@ void GuiGraphics::dispatchParams()
        InsetGraphicsParams tmp_params(params_);
        string const lfun = InsetGraphics::params2string(tmp_params, buffer());
        dispatch(FuncRequest(getLfun(), lfun));
+       if (!params_.groupId.empty())
+               dispatch(FuncRequest(LFUN_GRAPHICS_GROUPS_UNIFY,
+                               InsetGraphics::params2string(params_, buffer())));
 }
 
 
@@ -732,19 +753,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
@@ -770,60 +791,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();
-}
-
-
-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();
 }