]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiExternal.cpp
Fix the tab ordering of GuiDocument components.
[lyx.git] / src / frontends / qt4 / GuiExternal.cpp
index d5c14b8d7dc2e215bb3bcf0f47f19e9156dcb148..94decc7b3b9978f3c69dc3c980c14f054fc17c08 100644 (file)
@@ -80,6 +80,8 @@ char const * const origin_gui_strs[] = {
 
 external::Template getTemplate(int i)
 {
+       if (external::TemplateManager::get().getTemplates().empty())
+               return Template();
        external::TemplateManager::Templates::const_iterator i1
                = external::TemplateManager::get().getTemplates().begin();
        advance(i1, i);
@@ -197,7 +199,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)
@@ -213,23 +215,25 @@ bool GuiExternal::activateAspectratio() const
        if (usingScale())
                return false;
 
-       string const wstr = fromqstr(widthED->text());
-       if (wstr.empty())
+       QString const wstr = widthED->text();
+       if (wstr.isEmpty())
                return false;
-       bool const wIsDbl = isStrDbl(wstr);
-       if (wIsDbl && float_equal(convert<double>(wstr), 0.0, 0.05))
+       bool wIsDbl;
+       double val = wstr.trimmed().toDouble(&wIsDbl);
+       if (wIsDbl && float_equal(val, 0.0, 0.05))
                return false;
        Length l;
-       if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
+       if (!wIsDbl && (!isValidLength(fromqstr(wstr), &l) || l.zero()))
                return false;
 
-       string const hstr = fromqstr(heightED->text());
-       if (hstr.empty())
+       QString const hstr = heightED->text();
+       if (hstr.isEmpty())
                return false;
-       bool const hIsDbl = isStrDbl(hstr);
-       if (hIsDbl && float_equal(convert<double>(hstr), 0.0, 0.05))
+       bool hIsDbl;
+       val = hstr.trimmed().toDouble(&hIsDbl);
+       if (hIsDbl && float_equal(val, 0.0, 0.05))
                return false;
-       if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
+       if (!hIsDbl && (!isValidLength(fromqstr(hstr), &l) || l.zero()))
                return false;
 
        return true;
@@ -292,7 +296,7 @@ void GuiExternal::getbbClicked()
        if (filename.empty())
                return;
 
-       FileName const abs_file(support::makeAbsPath(filename, fromqstr(bufferFilepath())));
+       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);
@@ -349,27 +353,11 @@ void GuiExternal::widthUnitChanged()
 }
 
 
-static Length::UNIT defaultUnit()
-{
-       Length::UNIT default_unit = Length::CM;
-       switch (lyxrc.default_papersize) {
-       case PAPER_USLETTER:
-       case PAPER_USLEGAL:
-       case PAPER_USEXECUTIVE:
-               default_unit = Length::IN;
-               break;
-       default:
-               break;
-       }
-       return default_unit;
-}
-
-
 static void setRotation(QLineEdit & angleED, QComboBox & originCO,
        external::RotationData const & data)
 {
        originCO.setCurrentIndex(int(data.origin()));
-       angleED.setText(toqstr(data.angle));
+       doubleToWidget(&angleED, data.angle);
 }
 
 
@@ -379,7 +367,7 @@ static void getRotation(external::RotationData & data,
        typedef external::RotationData::OriginType OriginType;
 
        data.origin(static_cast<OriginType>(originCO.currentIndex()));
-       data.angle = fromqstr(angleED.text());
+       data.angle = widgetToDoubleStr(&angleED);
 }
 
 
@@ -397,15 +385,15 @@ static void setSize(QLineEdit & widthED, LengthCombo & widthUnitCO,
        }
 
        if (using_scale) {
-               widthED.setText(toqstr(scale));
+               doubleToWidget(&widthED, scale);
                widthUnitCO.setCurrentItem("scale");
        } else
                lengthToWidgets(&widthED, &widthUnitCO,
-                       data.width.asString(), defaultUnit());
+                               data.width.asString(), Length::defaultUnit());
 
        string const h = data.height.zero() ? string() : data.height.asString();
-       Length::UNIT default_unit = data.width.zero() ?
-               defaultUnit() : data.width.unit();
+       Length::UNIT const default_unit = data.width.zero() ?
+               Length::defaultUnit() : data.width.unit();
        lengthToWidgets(&heightED, &heightUnitCO, h, default_unit);
 
        heightED.setEnabled(!using_scale);
@@ -424,11 +412,9 @@ static void getSize(external::ResizeData & data,
        QLineEdit const & heightED, LengthCombo const & heightUnitCO,
        QCheckBox const & aspectratioCB, bool const scaling)
 {
-       string const width = fromqstr(widthED.text());
-
        if (scaling) {
                // scaling instead of a width
-               data.scale = width;
+               data.scale = widgetToDoubleStr(&widthED);
                data.width = Length();
        } else {
                data.width = Length(widgetsToLength(&widthED, &widthUnitCO));
@@ -474,10 +460,10 @@ static void getCrop(external::ClipData & data,
 void GuiExternal::updateContents()
 {
        string const name =
-               params_.filename.outputFilename(fromqstr(bufferFilepath()));
+               params_.filename.outputFileName(fromqstr(bufferFilePath()));
        fileED->setText(toqstr(name));
 
-       int index = -1;
+       int index = 0;
        external::TemplateManager::Templates::const_iterator i1, i2;
        i1 = external::TemplateManager::get().getTemplates().begin();
        i2 = external::TemplateManager::get().getTemplates().end();
@@ -526,21 +512,19 @@ void GuiExternal::updateTemplate()
        TransformIDs::const_iterator tr_begin = transformIds.begin();
        TransformIDs::const_iterator const tr_end = transformIds.end();
 
-       bool found = std::find(tr_begin, tr_end, external::Rotate) != tr_end;
-       rotationGB->setEnabled(found);
+       bool rotate = std::find(tr_begin, tr_end, external::Rotate) != tr_end;
+       rotationGB->setEnabled(rotate);
 
-       found = std::find(tr_begin, tr_end, external::Resize) != tr_end;
-       scaleGB->setEnabled(found);
+       bool resize = std::find(tr_begin, tr_end, external::Resize) != tr_end;
+       scaleGB->setEnabled(resize);
 
-       found = std::find(tr_begin, tr_end, external::Clip) != tr_end;
-       cropGB->setEnabled(found);
+       bool clip = std::find(tr_begin, tr_end, external::Clip) != tr_end;
+       cropGB->setEnabled(clip);
 
-       tab->setTabEnabled(tab->indexOf(sizetab),
-               rotationGB->isEnabled()
-               || scaleGB->isEnabled()
-               || cropGB->isEnabled());
+       sizetab->setEnabled(rotate || resize || clip);
+       tab->setTabEnabled(tab->indexOf(sizetab), rotate || resize || clip);
 
-       found = std::find(tr_begin, tr_end, external::Extra) != tr_end;
+       bool found = std::find(tr_begin, tr_end, external::Extra) != tr_end;
        optionsGB->setEnabled(found);
 
        bool scaled = displayGB->isChecked() && displayGB->isEnabled() &&
@@ -584,7 +568,7 @@ void GuiExternal::updateTemplate()
 
 void GuiExternal::applyView()
 {
-       params_.filename.set(fromqstr(fileED->text()), fromqstr(bufferFilepath()));
+       params_.filename.set(fromqstr(fileED->text()), fromqstr(bufferFilePath()));
        params_.settemplate(getTemplate(externalCO->currentIndex()).lyxName);
 
        params_.draft = draftCB->isChecked();
@@ -639,7 +623,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));
 }
 
 
@@ -647,13 +638,13 @@ QString GuiExternal::browse(QString const & input,
                                     QString const & template_name) const
 {
        QString const title = qt_("Select external file");
-       QString const bufpath = bufferFilepath();
+       QString const bufpath = bufferFilePath();
        QStringList const filter = templateFilters(template_name);
 
        QString const label1 = qt_("Documents|#o#O");
        QString const dir1 = toqstr(lyxrc.document_path);
 
-       return browseRelFile(input, bufpath, title, filter, false, label1, dir1);
+       return browseRelToParent(input, bufpath, title, filter, false, label1, dir1);
 }