]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/qt_helpers.h
* qt_helpers.h:
[lyx.git] / src / frontends / qt4 / qt_helpers.h
index 01d1196540fadfefa33cd4331043ef607d6f3004..82a14383f396f51389a9b6e5a3da5272aaa548ee 100644 (file)
 #ifndef QTHELPERS_H
 #define QTHELPERS_H
 
-#include <utility>
-
 #include "lyxlength.h"
-//#include "lengthcombo.h"
+#include "support/docstring.h"
 
-#include "support/types.h"
+#include <QChar>
+#include <QString>
 
 #include <vector>
+#include <utility>
 
-class LengthCombo;
 class QComboBox;
 class QLineEdit;
-class QString;
-class QChar;
+
+class LengthCombo;
+
+namespace lyx {
 
 std::string makeFontName(std::string const & family, std::string const & foundry);
 
@@ -41,15 +42,18 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
        std::string const & len, LyXLength::UNIT default_unit);
 
 /// format a string to the given width
-std::string const formatted(std::string const & text, int w = 80);
+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);
+}
 
 
 /**
@@ -58,33 +62,55 @@ 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());
+}
 
 
 /**
  * toqstr - convert ucs4 into QString
  *
- * QString uses ucs2 (a.k.a utf16) internally.
+ * QString uses utf16 internally.
  */
-QString const toqstr(lyx::docstring const & ucs4);
+inline char_type const qchar_to_ucs4(QChar const & qchar) {
+       return static_cast<char_type>(qchar.unicode());
+}
+
+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<unsigned short>(ucs4));
+}
+
+QString const toqstr(docstring const & ucs4);
 
-QString const ucs4_to_qstring(lyx::char_type const * str, size_t ls);
+void ucs4_to_qstring(docstring const & str, QString & s);
 
-lyx::docstring const qstring_to_ucs4(QString const & qstr);
+inline void ucs4_to_qstring(char_type const * str, size_t ls, QString & s)
+{
+       int i = static_cast<int>(ls);
+       s.resize(i);
+       for (i ; --i >= 0; )
+               s[i] = ucs4_to_qchar(str[i]);
+}
 
-void qstring_to_ucs4(QString const & qstr, std::vector<lyx::char_type> & ucs4);
 
-lyx::char_type const qchar_to_ucs4(QChar const & qchar);
+QString ucs4_to_qstring(docstring const & str);
 
-QChar const ucs4_to_qchar(lyx::char_type const & ucs4);
+docstring const qstring_to_ucs4(QString const & qstr);
 
+void qstring_to_ucs4(QString const & qstr, std::vector<char_type> & 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);
 
 
 /**
@@ -102,4 +128,7 @@ QString const qt_(std::string const & str);
  */
 std::string const fromqstr(QString const & str);
 
+
+} // namespace lyx
+
 #endif // QTHELPERS_H