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 #include "support/lstrings.h"
16 #include "qt_helpers.h"
18 #include "lengthcombo.h"
21 #include <qlineedit.h>
22 #include <qtextcodec.h>
27 string makeFontName(string const & family, string const & foundry)
32 return family + " [" + foundry + ']';
34 return foundry + '-' + family;
39 pair<string,string> parseFontName(string const & name)
42 string::size_type const idx = name.find('[');
43 if (idx == string::npos || idx == 0)
44 return make_pair(name, string());
45 return make_pair(name.substr(0, idx - 1),
46 name.substr(idx + 1, name.size() - idx - 2));
48 string::size_type const idx = name.find('-');
49 if (idx == string::npos || idx == 0)
50 return make_pair(name, string());
51 return make_pair(name.substr(idx + 1),
57 string widgetsToLength(QLineEdit const * input, LengthCombo const * combo)
59 QString length = input->text();
63 // don't return unit-from-choice if the input(field) contains a unit
64 if (isValidGlueLength(fromqstr(length)))
65 return fromqstr(length);
67 LyXLength::UNIT unit = combo->currentLengthItem();
69 return LyXLength(length.toDouble(), unit).asString();
73 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
74 string const & len, LyXLength::UNIT defaultUnit)
77 // no length (UNIT_NONE)
78 combo->setCurrentItem(defaultUnit);
81 combo->setCurrentItem(LyXLength(len).unit());
82 input->setText(toqstr(tostr(LyXLength(len).value())));
87 QString const toqstr(char const * str)
89 QTextCodec * codec = QTextCodec::codecForLocale();
91 return codec->toUnicode(str);
95 QString const toqstr(string const & str)
97 return toqstr(str.c_str());
101 QString const qt_(char const * str)
103 return toqstr(_(str));
107 QString const qt_(string const & str)
109 return toqstr(_(str));
113 string const fromqstr(QString const & str)
115 QTextCodec * codec = QTextCodec::codecForLocale();
116 QCString tmpstr = codec->fromUnicode(str);
117 char const * tmpcstr = tmpstr;