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>
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(fromqstr(length)))
67 return fromqstr(length);
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(toqstr(tostr(LyXLength(len).value())));
89 QString const toqstr(char const * str)
91 QTextCodec * codec = QTextCodec::codecForLocale();
93 return codec->toUnicode(str);
97 QString const toqstr(string const & str)
99 return toqstr(str.c_str());
103 QString const qt_(char const * str)
105 return toqstr(_(str));
109 QString const qt_(string const & str)
111 return toqstr(_(str));
115 string const fromqstr(QString const & str)
117 QTextCodec * codec = QTextCodec::codecForLocale();
118 QCString tmpstr = codec->fromUnicode(str);
119 char const * tmpcstr = tmpstr;
124 string const formatted(string const & text, int w)
131 string::size_type curpos = 0;
135 string::size_type const nxtpos1 = text.find(' ', curpos);
136 string::size_type const nxtpos2 = text.find('\n', curpos);
137 string::size_type const nxtpos = std::min(nxtpos1, nxtpos2);
139 string const word = nxtpos == string::npos ?
140 text.substr(curpos) : text.substr(curpos, nxtpos-curpos);
142 bool const newline = (nxtpos2 != string::npos &&
145 string const line_plus_word =
146 line.empty() ? word : line + ' ' + word;
148 // FIXME: make w be size_t
149 if (line_plus_word.length() >= w) {
158 } else if (newline) {
159 sout += line_plus_word + '\n';
168 if (nxtpos == string::npos) {