]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/qt_helpers.h
more unicode work.
[lyx.git] / src / frontends / qt4 / qt_helpers.h
1 // -*- C++ -*-
2 /**
3  * \file qt_helpers.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Dekel Tsur
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef QTHELPERS_H
13 #define QTHELPERS_H
14
15 #include <utility>
16
17 #include "lyxlength.h"
18 //#include "lengthcombo.h"
19
20 #include "support/docstring.h"
21
22 #include <QChar>
23
24 #include <vector>
25
26 class LengthCombo;
27 class QComboBox;
28 class QLineEdit;
29 class QString;
30
31 std::string makeFontName(std::string const & family, std::string const & foundry);
32
33 std::pair<std::string,std::string> parseFontName(std::string const & name);
34
35 /// method to get a LyXLength from widgets (LengthCombo)
36 std::string widgetsToLength(QLineEdit const * input, LengthCombo const * combo);
37 /// method to get a LyXLength from widgets (QComboBox)
38 LyXLength widgetsToLength(QLineEdit const * input, QComboBox const * combo);
39
40 /// method to set widgets from a LyXLength
41 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
42         std::string const & len, LyXLength::UNIT default_unit);
43
44 /// format a string to the given width
45 lyx::docstring const formatted(lyx::docstring const & text, int w = 80);
46
47 /**
48  * toqstr - convert char * into unicode
49  *
50  * Use this whenever there's a user-visible string that is encoded
51  * for the locale (menus, dialogs etc.)
52  */
53 QString const toqstr(char const * str);
54
55
56 /**
57  * toqstr - convert string into unicode
58  *
59  * Use this whenever there's a user-visible string that is encoded
60  * for the locale (menus, dialogs etc.)
61  */
62 QString const toqstr(std::string const & str);
63
64
65 /**
66  * toqstr - convert ucs4 into QString
67  *
68  * QString uses ucs2 (a.k.a utf16) internally.
69  */
70 QString const toqstr(lyx::docstring const & ucs4);
71
72 void ucs4_to_qstring(lyx::char_type const * str, size_t ls, QString & s);
73
74 void ucs4_to_qstring(lyx::docstring const & str, QString & s);
75
76 lyx::docstring const qstring_to_ucs4(QString const & qstr);
77
78 void qstring_to_ucs4(QString const & qstr, std::vector<lyx::char_type> & ucs4);
79
80 inline lyx::char_type const qchar_to_ucs4(QChar const & qchar) {
81         return static_cast<lyx::char_type>(qchar.unicode());
82 }
83
84 inline QChar const ucs4_to_qchar(lyx::char_type const ucs4) {
85         return QChar(static_cast<unsigned short>(ucs4));
86 }
87
88 /**
89  * qt_ - i18nize string and convert to unicode
90  *
91  * Use this in qt4/ instead of qt_()
92  */
93 QString const qt_(char const * str);
94
95
96 /**
97  * qt_ - i18nize string and convert to unicode
98  *
99  * Use this in qt4/ instead of qt_()
100  */
101 QString const qt_(std::string const & str);
102
103
104 /**
105  * fromqstr - convert QString into std::string in locale
106  *
107  * Return the QString encoded in the locale
108  */
109 std::string const fromqstr(QString const & str);
110
111 #endif // QTHELPERS_H