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);
50 * toqstr - convert a UTF8 encoded char * into a QString
52 * This should not be used, since all possibly non-ASCII stuff should be
53 * stored in a docstring.
55 inline QString const toqstr(char const * str)
57 return QString::fromUtf8(str);
62 * toqstr - convert a UTF8 encoded std::string into a QString
64 * This should not be used, since all possibly non-ASCII stuff should be
65 * stored in a docstring.
67 inline QString const toqstr(std::string const & str)
69 return toqstr(str.c_str());
74 * Convert a QChar into a UCS4 character.
75 * This is a hack (it does only make sense for the common part of the UCS4
76 * and UTF16 encodings) and should not be used.
77 * This does only exist because of performance reasons (a real conversion
78 * using iconv is too slow on windows).
80 inline char_type const qchar_to_ucs4(QChar const & qchar)
82 return static_cast<char_type>(qchar.unicode());
87 * Convert a UCS4 character into a QChar.
88 * This is a hack (it does only make sense for the common part of the UCS4
89 * and UTF16 encodings) and should not be used.
90 * This does only exist because of performance reasons (a real conversion
91 * using iconv is too slow on windows).
93 inline QChar const ucs4_to_qchar(char_type const ucs4)
95 // FIXME: The following cast is not a real conversion but it work
96 // for the ucs2 subrange of unicode. Instead of an assertion we should
97 // return some special characters that indicates that its display is
99 BOOST_ASSERT(ucs4 < 65536);
100 return QChar(static_cast<unsigned short>(ucs4));
105 * toqstr - convert a UCS4 encoded docstring into a QString
107 * This is the preferred method of converting anything that possibly
108 * contains non-ASCII stuff to QString.
110 #if QT_VERSION >= 0x040200
111 inline QString const toqstr(docstring const & ucs4)
113 // If possible we let qt do the work, since this version does not
114 // need to be superfast.
115 return QString::fromUcs4(reinterpret_cast<uint const *>(ucs4.data()), ucs4.length());
118 QString const toqstr(docstring const & ucs4);
123 * ucs4_to_qstring - convert a UCS4 encoded char_type * into a QString
125 * This is a hack for the painter and font metrics and should not be used
126 * elsewhere. Since it uses ucs4_to_qchar it has the same limitations.
128 inline void ucs4_to_qstring(char_type const * str, size_t ls, QString & s)
130 int i = static_cast<int>(ls);
133 s[i] = ucs4_to_qchar(str[i]);
138 * qstring_to_ucs4 - convert a QString into a UCS4 encoded docstring
140 * This is the preferred method of converting anything that possibly
141 * contains non-ASCII stuff to docstring.
143 docstring const qstring_to_ucs4(QString const & qstr);
147 * qt_ - i18nize string and convert to QString
149 * Use this in qt4/ instead of _()
151 QString const qt_(char const * str, const char * comment = 0);
155 * qt_ - i18nize string and convert to QString
157 * Use this in qt4/ instead of _()
159 QString const qt_(std::string const & str);
163 * fromqstr - convert a QString into a UTF8 encoded std::string
165 * This should not be used except for output to lyxerr, since all possibly
166 * non-ASCII stuff should be stored in a docstring.
168 std::string const fromqstr(QString const & str);
172 #endif // QTHELPERS_H