4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
15 #include "lyxlength.h"
16 #include "support/docstring.h"
23 #include <boost/assert.hpp>
32 std::string makeFontName(std::string const & family, std::string const & foundry);
34 std::pair<std::string,std::string> parseFontName(std::string const & name);
36 /// method to get a LyXLength from widgets (LengthCombo)
37 std::string widgetsToLength(QLineEdit const * input, LengthCombo const * combo);
38 /// method to get a LyXLength from widgets (QComboBox)
39 LyXLength widgetsToLength(QLineEdit const * input, QComboBox const * combo);
41 /// method to set widgets from a LyXLength
42 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
43 std::string const & len, LyXLength::UNIT default_unit);
45 /// format a string to the given width
46 docstring const formatted(docstring const & text, int w = 80);
49 * toqstr - convert char * into Qt's unicode (UTF16)
51 * Use this whenever there's a user-visible string that is encoded
52 * for the locale (menus, dialogs etc.)
54 inline QString const toqstr(char const * str)
56 return QString::fromUtf8(str);
61 * toqstr - convert string into unicode
63 * Use this whenever there's a user-visible string that is encoded
64 * for the locale (menus, dialogs etc.)
66 inline QString const toqstr(std::string const & str)
68 return toqstr(str.c_str());
73 * toqstr - convert ucs4 into QString
75 * QString uses utf16 internally.
77 inline char_type const qchar_to_ucs4(QChar const & qchar) {
78 return static_cast<char_type>(qchar.unicode());
81 inline QChar const ucs4_to_qchar(char_type const ucs4) {
82 // FIXME: The following cast is not a real conversion but it work
83 // for the ucs2 subrange of unicode. Instead of an assertion we should
84 // return some special characters that indicates that its display is
86 BOOST_ASSERT(ucs4 < 65536);
87 return QChar(static_cast<unsigned short>(ucs4));
90 QString const toqstr(docstring const & ucs4);
92 void ucs4_to_qstring(docstring const & str, QString & s);
94 inline void ucs4_to_qstring(char_type const * str, size_t ls, QString & s)
96 int i = static_cast<int>(ls);
99 s[i] = ucs4_to_qchar(str[i]);
103 docstring const qstring_to_ucs4(QString const & qstr);
107 * qt_ - i18nize string and convert to unicode
109 * Use this in qt4/ instead of _()
111 QString const qt_(char const * str, const char * comment);
115 * qt_ - i18nize string and convert to unicode
117 * Use this in qt4/ instead of _()
119 QString const qt_(std::string const & str);
123 * fromqstr - convert QString into std::string in locale
125 * Return the QString encoded in the locale
127 std::string const fromqstr(QString const & str);
132 #endif // QTHELPERS_H