3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
17 #include "support/lstrings.h"
19 #include "qt_helpers.h"
21 #include "lengthcombo.h"
24 #include <qlineedit.h>
29 string makeFontName(string const & family, string const & foundry)
34 return family + " [" + foundry + ']';
36 return foundry + '-' + family;
41 pair<string,string> parseFontName(string const & name)
44 string::size_type const idx = name.find('[');
45 if (idx == string::npos || idx == 0)
46 return make_pair(name, string());
47 return make_pair(name.substr(0, idx - 1),
48 name.substr(idx + 1, name.size() - idx - 2));
50 string::size_type const idx = name.find('-');
51 if (idx == string::npos || idx == 0)
52 return make_pair(name, string());
53 return make_pair(name.substr(idx + 1),
59 string widgetsToLength(QLineEdit const * input, LengthCombo const * combo)
61 QString length = input->text();
65 // don't return unit-from-choice if the input(field) contains a unit
66 if (isValidGlueLength(length.latin1()))
67 return length.latin1();
69 LyXLength::UNIT unit = combo->currentLengthItem();
71 return LyXLength(length.toDouble(), unit).asString();
75 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
76 string const & len, LyXLength::UNIT defaultUnit)
79 // no length (UNIT_NONE)
80 combo->setCurrentItem(defaultUnit);
83 combo->setCurrentItem(LyXLength(len).unit());
84 input->setText(tostr(LyXLength(len).value()).c_str());