]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiExternal.cpp
Docstringify getLongString in general and preamble snippets in particular
[lyx.git] / src / frontends / qt4 / GuiExternal.cpp
index b3d9e44ec00de963541cba2e01bf39974648b4b7..2e7b6f633c91f3b73d030b3efa6594cbb24ed54e 100644 (file)
@@ -23,6 +23,7 @@
 #include "insets/ExternalTemplate.h"
 #include "insets/InsetExternal.h"
 
+#include "graphics/epstools.h"
 #include "graphics/GraphicsCache.h"
 #include "graphics/GraphicsCacheItem.h"
 #include "graphics/GraphicsImage.h"
@@ -139,6 +140,14 @@ GuiExternal::GuiExternal(GuiView & lv)
        connect(ytED, SIGNAL(textChanged(QString)), this, SLOT(bbChanged()));
        connect(xlED, SIGNAL(textChanged(QString)), this, SLOT(bbChanged()));
        connect(ybED, SIGNAL(textChanged(QString)), this, SLOT(bbChanged()));
+       connect(xrUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+               this, SLOT(bbChanged()));
+       connect(ytUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+               this, SLOT(bbChanged()));
+       connect(xlUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+               this, SLOT(bbChanged()));
+       connect(ybUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+               this, SLOT(bbChanged()));
        connect(draftCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
 
        QIntValidator * validator = new QIntValidator(displayscaleED);
@@ -147,10 +156,10 @@ GuiExternal::GuiExternal(GuiView & lv)
 
        angleED->setValidator(new QDoubleValidator(-360, 360, 2, angleED));
 
-       xlED->setValidator(new QIntValidator(xlED));
-       ybED->setValidator(new QIntValidator(ybED));
-       xrED->setValidator(new QIntValidator(xrED));
-       ytED->setValidator(new QIntValidator(ytED));
+       xlED->setValidator(unsignedLengthValidator(xlED));
+       ybED->setValidator(unsignedLengthValidator(ybED));
+       xrED->setValidator(unsignedLengthValidator(xrED));
+       ytED->setValidator(unsignedLengthValidator(ytED));
 
        widthED->setValidator(unsignedLengthValidator(widthED));
        heightED->setValidator(unsignedLengthValidator(heightED));
@@ -182,6 +191,10 @@ GuiExternal::GuiExternal(GuiView & lv)
        bc().addReadOnly(xlED);
        bc().addReadOnly(xrED);
        bc().addReadOnly(ybED);
+       bc().addReadOnly(ytUnitCO);
+       bc().addReadOnly(xlUnitCO);
+       bc().addReadOnly(xrUnitCO);
+       bc().addReadOnly(ybUnitCO);
        bc().addReadOnly(extraFormatCO);
        bc().addReadOnly(extraED);
 
@@ -199,7 +212,7 @@ GuiExternal::GuiExternal(GuiView & lv)
        i1 = external::TemplateManager::get().getTemplates().begin();
        i2 = external::TemplateManager::get().getTemplates().end();
        for (; i1 != i2; ++i1)
-               externalCO->addItem(qt_(i1->second.lyxName));
+               externalCO->addItem(qt_(i1->second.guiName));
 
        // Fill the origins combo
        for (size_t i = 0; i != sizeof(origins) / sizeof(origins[0]); ++i)
@@ -207,6 +220,18 @@ GuiExternal::GuiExternal(GuiView & lv)
 
        // add scale item
        widthUnitCO->insertItem(0, qt_("Scale%"), "scale");
+
+       // remove all units from bb that depend on font or other dimensions
+       // we cannot use these, since we need to compare against absolute
+       // values from the image file.
+       xlUnitCO->noPercents();
+       xlUnitCO->removeFontDependent();
+       xrUnitCO->noPercents();
+       xrUnitCO->removeFontDependent();
+       ytUnitCO->noPercents();
+       ytUnitCO->removeFontDependent();
+       ybUnitCO->noPercents();
+       ybUnitCO->removeFontDependent();
 }
 
 
@@ -299,7 +324,7 @@ void GuiExternal::getbbClicked()
        FileName const abs_file(support::makeAbsPath(filename, fromqstr(bufferFilePath())));
 
        // try to get it from the file, if possible
-       string bb = readBB_from_PSFile(abs_file);
+       string bb = graphics::readBB_from_PSFile(abs_file);
        if (bb.empty()) {
                // we don't, so ask the Graphics Cache if it has loaded the file
                int width = 0;
@@ -317,10 +342,15 @@ void GuiExternal::getbbClicked()
                bb = "0 0 " + convert<string>(width) + ' ' + convert<string>(height);
        }
 
-       xlED->setText(toqstr(token(bb, ' ', 0)));
-       ybED->setText(toqstr(token(bb, ' ', 1)));
-       xrED->setText(toqstr(token(bb, ' ', 2)));
-       ytED->setText(toqstr(token(bb, ' ', 3)));
+       doubleToWidget(xlED, token(bb, ' ', 0));
+       doubleToWidget(ybED, token(bb, ' ', 1));
+       doubleToWidget(xrED, token(bb, ' ', 2));
+       doubleToWidget(ytED, token(bb, ' ', 3));
+       // the values from the file always have the bigpoint-unit bp
+       xlUnitCO->setCurrentIndex(0);
+       ybUnitCO->setCurrentIndex(0);
+       xrUnitCO->setCurrentIndex(0);
+       ytUnitCO->setCurrentIndex(0);
 
        bbChanged_ = false;
 }
@@ -428,14 +458,17 @@ static void getSize(external::ResizeData & data,
 void setCrop(QCheckBox & clipCB,
        QLineEdit & xlED, QLineEdit & ybED,
        QLineEdit & xrED, QLineEdit & ytED,
+       LengthCombo & xlUnitCO, LengthCombo & ybUnitCO,
+       LengthCombo & xrUnitCO, LengthCombo & ytUnitCO,
        external::ClipData const & data)
 {
        clipCB.setChecked(data.clip);
-       graphics::BoundingBox const & bbox = data.bbox;
-       xlED.setText(QString::number(bbox.xl));
-       ybED.setText(QString::number(bbox.yb));
-       xrED.setText(QString::number(bbox.xr));
-       ytED.setText(QString::number(bbox.yt));
+       Length::UNIT const default_unit = data.bbox.xl.zero() ?
+               Length::defaultUnit() : data.bbox.xl.unit();
+       lengthToWidgets(&xlED, &xlUnitCO, data.bbox.xl, default_unit);
+       lengthToWidgets(&ybED, &ybUnitCO, data.bbox.yb, default_unit);
+       lengthToWidgets(&xrED, &xrUnitCO, data.bbox.xr, default_unit);
+       lengthToWidgets(&ytED, &ytUnitCO, data.bbox.yt, default_unit);
 }
 
 
@@ -443,6 +476,8 @@ static void getCrop(external::ClipData & data,
        QCheckBox const & clipCB,
        QLineEdit const & xlED, QLineEdit const & ybED,
        QLineEdit const & xrED, QLineEdit const & ytED,
+       LengthCombo const & xlUnitCO, LengthCombo const & ybUnitCO,
+       LengthCombo const & xrUnitCO, LengthCombo const & ytUnitCO,
        bool bb_changed)
 {
        data.clip = clipCB.isChecked();
@@ -450,10 +485,10 @@ static void getCrop(external::ClipData & data,
        if (!bb_changed)
                return;
 
-       data.bbox.xl = xlED.text().toInt();
-       data.bbox.yb = ybED.text().toInt();
-       data.bbox.xr = xrED.text().toInt();
-       data.bbox.yt = ytED.text().toInt();
+       data.bbox.xl = Length(widgetsToLength(&xlED, &xlUnitCO));
+       data.bbox.yb = Length(widgetsToLength(&ybED, &ybUnitCO));
+       data.bbox.xr = Length(widgetsToLength(&xrED, &xrUnitCO));
+       data.bbox.yt = Length(widgetsToLength(&ytED, &ytUnitCO));
 }
 
 
@@ -493,7 +528,8 @@ void GuiExternal::updateContents()
        setSize(*widthED, *widthUnitCO, *heightED, *heightUnitCO,
                *aspectratioCB, params_.resizedata);
 
-       setCrop(*clipCB, *xlED, *ybED, *xrED, *ytED, params_.clipdata);
+       setCrop(*clipCB, *xlED, *ybED, *xrED, *ytED,
+               *xlUnitCO, *ybUnitCO, *xrUnitCO, *ytUnitCO, params_.clipdata);
        bbChanged_ = !params_.clipdata.bbox.empty();
 
        isValid();
@@ -503,7 +539,7 @@ void GuiExternal::updateContents()
 void GuiExternal::updateTemplate()
 {
        external::Template templ = getTemplate(externalCO->currentIndex());
-       externalTB->setPlainText(qt_(templ.helpText));
+       externalTB->setPlainText(toqstr(translateIfPossible(templ.helpText)));
 
        // Ascertain which (if any) transformations the template supports
        // and disable tabs and Group Boxes hosting unsupported transforms.
@@ -583,8 +619,8 @@ void GuiExternal::applyView()
                        *heightED, *heightUnitCO, *aspectratioCB, usingScale());
 
        if (cropGB->isEnabled())
-               getCrop(params_.clipdata, *clipCB, *xlED, *ybED,
-                       *xrED, *ytED, bbChanged_);
+               getCrop(params_.clipdata, *clipCB, *xlED, *ybED, *xrED, *ytED,
+                       *xlUnitCO, *ybUnitCO, *xrUnitCO, *ytUnitCO, bbChanged_);
 
        if (optionsGB->isEnabled()) {
                MapType::const_iterator it = extra_.begin();
@@ -623,7 +659,14 @@ static QStringList templateFilters(QString const & template_name)
        external::Template const * const et_ptr =
                etm.getTemplateByName(fromqstr(template_name));
 
-       return fileFilters(et_ptr ? toqstr(et_ptr->fileRegExp) : QString());
+       string filter;
+       if (et_ptr && et_ptr->fileRegExp != "" && et_ptr->fileRegExp != "*") {
+               filter += et_ptr->guiName;
+               filter += " (";
+               filter += et_ptr->fileRegExp;
+               filter += ")";
+       }
+       return fileFilters(toqstr(filter));
 }