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>
25 #include <qtextcodec.h>
30 string makeFontName(string const & family, string const & foundry)
35 return family + " [" + foundry + ']';
37 return foundry + '-' + family;
42 pair<string,string> parseFontName(string const & name)
45 string::size_type const idx = name.find('[');
46 if (idx == string::npos || idx == 0)
47 return make_pair(name, string());
48 return make_pair(name.substr(0, idx - 1),
49 name.substr(idx + 1, name.size() - idx - 2));
51 string::size_type const idx = name.find('-');
52 if (idx == string::npos || idx == 0)
53 return make_pair(name, string());
54 return make_pair(name.substr(idx + 1),
60 string widgetsToLength(QLineEdit const * input, LengthCombo const * combo)
62 QString length = input->text();
66 // don't return unit-from-choice if the input(field) contains a unit
67 if (isValidGlueLength(fromqstr(length)))
68 return fromqstr(length);
70 LyXLength::UNIT unit = combo->currentLengthItem();
72 return LyXLength(length.toDouble(), unit).asString();
76 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
77 string const & len, LyXLength::UNIT defaultUnit)
80 // no length (UNIT_NONE)
81 combo->setCurrentItem(defaultUnit);
84 combo->setCurrentItem(LyXLength(len).unit());
85 input->setText(toqstr(tostr(LyXLength(len).value())));
90 QString const toqstr(char const * str)
92 QTextCodec * codec = QTextCodec::codecForLocale();
94 return codec->toUnicode(str);
98 QString const toqstr(string const & str)
100 return toqstr(str.c_str());
104 QString const qt_(char const * str)
106 return toqstr(_(str));
110 QString const qt_(string const & str)
112 return toqstr(_(str));
116 string const fromqstr(QString const & str)
118 QTextCodec * codec = QTextCodec::codecForLocale();
119 QCString tmpstr = codec->fromUnicode(str);
120 char const * tmpcstr = tmpstr;