X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt2%2Fqt_helpers.C;h=864955d25f86fdc33b9623707c4089378dd94b57;hb=4c6e0fe4226ce3b55d13726977f1e579f17c2ad1;hp=76a56b50f8d9db3d78f1e18960636edc63a9a2e8;hpb=9c8cc9a3050cdf3b5eaed7866b4bba0a6f9de7e5;p=lyx.git diff --git a/src/frontends/qt2/qt_helpers.C b/src/frontends/qt2/qt_helpers.C index 76a56b50f8..864955d25f 100644 --- a/src/frontends/qt2/qt_helpers.C +++ b/src/frontends/qt2/qt_helpers.C @@ -5,27 +5,25 @@ * * \author Dekel Tsur * - * Full author contact details are available in file CREDITS + * Full author contact details are available in file CREDITS. */ #include -#ifdef __GNUG__ -#pragma implementation -#endif - -#include "support/lstrings.h" - +#include "support/tostr.h" +#include "gettext.h" #include "qt_helpers.h" #include "lengthcombo.h" - -#include + #include +#include -using std::pair; using std::make_pair; +using std::pair; + + string makeFontName(string const & family, string const & foundry) { if (foundry.empty()) @@ -55,7 +53,7 @@ pair parseFontName(string const & name) #endif } - + string widgetsToLength(QLineEdit const * input, LengthCombo const * combo) { QString length = input->text(); @@ -63,8 +61,8 @@ string widgetsToLength(QLineEdit const * input, LengthCombo const * combo) return string(); // don't return unit-from-choice if the input(field) contains a unit - if (isValidGlueLength(length.latin1())) - return length.latin1(); + if (isValidGlueLength(fromqstr(length))) + return fromqstr(length); LyXLength::UNIT unit = combo->currentLengthItem(); @@ -81,6 +79,98 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo, input->setText(""); } else { combo->setCurrentItem(LyXLength(len).unit()); - input->setText(tostr(LyXLength(len).value()).c_str()); + input->setText(toqstr(tostr(LyXLength(len).value()))); + } +} + + +QString const toqstr(char const * str) +{ + QTextCodec * codec = QTextCodec::codecForLocale(); + + return codec->toUnicode(str); +} + + +QString const toqstr(string const & str) +{ + return toqstr(str.c_str()); +} + + +QString const qt_(char const * str) +{ + return toqstr(_(str)); +} + + +QString const qt_(string const & str) +{ + return toqstr(_(str)); +} + + +string const fromqstr(QString const & str) +{ + QTextCodec * codec = QTextCodec::codecForLocale(); + QCString tmpstr = codec->fromUnicode(str); + char const * tmpcstr = tmpstr; + return tmpcstr; +} + + +string const formatted(string const & text, int w) +{ + string sout; + + if (text.empty()) + return sout; + + string::size_type curpos = 0; + string line; + + for (;;) { + string::size_type const nxtpos1 = text.find(' ', curpos); + string::size_type const nxtpos2 = text.find('\n', curpos); + string::size_type const nxtpos = std::min(nxtpos1, nxtpos2); + + string const word = nxtpos == string::npos ? + text.substr(curpos) : text.substr(curpos, nxtpos-curpos); + + bool const newline = (nxtpos2 != string::npos && + nxtpos2 < nxtpos1); + + string const line_plus_word = + line.empty() ? word : line + ' ' + word; + + // FIXME: make w be size_t + if (line_plus_word.length() >= w) { + sout += line + '\n'; + if (newline) { + sout += word + '\n'; + line.erase(); + } else { + line = word; + } + + } else if (newline) { + sout += line_plus_word + '\n'; + line.erase(); + + } else { + if (!line.empty()) + line += ' '; + line += word; + } + + if (nxtpos == string::npos) { + if (!line.empty()) + sout += line; + break; + } + + curpos = nxtpos + 1; } + + return sout; }