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
13 #include "support/tostr.h"
15 #include "qt_helpers.h"
17 #include "lengthcombo.h"
20 #include <qlineedit.h>
21 #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;
122 string const formatted(string const & text, int w)
129 string::size_type curpos = 0;
133 string::size_type const nxtpos1 = text.find(' ', curpos);
134 string::size_type const nxtpos2 = text.find('\n', curpos);
135 string::size_type const nxtpos = std::min(nxtpos1, nxtpos2);
137 string const word = nxtpos == string::npos ?
138 text.substr(curpos) : text.substr(curpos, nxtpos-curpos);
140 bool const newline = (nxtpos2 != string::npos &&
143 string const line_plus_word =
144 line.empty() ? word : line + ' ' + word;
146 // FIXME: make w be size_t
147 if (line_plus_word.length() >= w) {
156 } else if (newline) {
157 sout += line_plus_word + '\n';
166 if (nxtpos == string::npos) {