X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2Fqt_helpers.h;h=82a14383f396f51389a9b6e5a3da5272aaa548ee;hb=591d47a64b8ba894be5c793472397374d0496984;hp=fa96925da49d6303ec276266875a3b54cc3b59fc;hpb=6c300f72a217722652dc27db9108e1050028979c;p=lyx.git diff --git a/src/frontends/qt4/qt_helpers.h b/src/frontends/qt4/qt_helpers.h index fa96925da4..82a14383f3 100644 --- a/src/frontends/qt4/qt_helpers.h +++ b/src/frontends/qt4/qt_helpers.h @@ -16,13 +16,13 @@ #include "support/docstring.h" #include +#include #include #include class QComboBox; class QLineEdit; -class QString; class LengthCombo; @@ -45,12 +45,15 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo, docstring const formatted(docstring const & text, int w = 80); /** - * toqstr - convert char * into unicode + * toqstr - convert char * into Qt's unicode (UTF16) * * Use this whenever there's a user-visible string that is encoded * for the locale (menus, dialogs etc.) */ -QString const toqstr(char const * str); +inline QString const toqstr(char const * str) +{ + return QString::fromUtf8(str); +} /** @@ -59,7 +62,10 @@ QString const toqstr(char const * str); * Use this whenever there's a user-visible string that is encoded * for the locale (menus, dialogs etc.) */ -QString const toqstr(std::string const & str); +inline QString const toqstr(std::string const & str) +{ + return toqstr(str.c_str()); +} /** @@ -67,32 +73,44 @@ QString const toqstr(std::string const & str); * * QString uses utf16 internally. */ -QString const toqstr(docstring const & ucs4); +inline char_type const qchar_to_ucs4(QChar const & qchar) { + return static_cast(qchar.unicode()); +} -void ucs4_to_qstring(char_type const * str, size_t ls, QString & s); +inline QChar const ucs4_to_qchar(char_type const ucs4) { + // FIXME: The following cast is not a real conversion but it work + // for the ucs2 subrange of unicode. Instead of an assertion we should + // return some special characters that indicates that its display is + // not supported. + BOOST_ASSERT(ucs4 < 65536); + return QChar(static_cast(ucs4)); +} + +QString const toqstr(docstring const & ucs4); void ucs4_to_qstring(docstring const & str, QString & s); +inline void ucs4_to_qstring(char_type const * str, size_t ls, QString & s) +{ + int i = static_cast(ls); + s.resize(i); + for (i ; --i >= 0; ) + s[i] = ucs4_to_qchar(str[i]); +} + + QString ucs4_to_qstring(docstring const & str); docstring const qstring_to_ucs4(QString const & qstr); void qstring_to_ucs4(QString const & qstr, std::vector & ucs4); -inline char_type const qchar_to_ucs4(QChar const & qchar) { - return static_cast(qchar.unicode()); -} - -inline QChar const ucs4_to_qchar(char_type const ucs4) { - return QChar(static_cast(ucs4)); -} - /** * qt_ - i18nize string and convert to unicode * * Use this in qt4/ instead of qt_() */ -QString const qt_(char const * str); +QString const qt_(char const * str, const char * comment); /**