]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/qt_helpers.h
move everything into namespace lyx
[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 "lyxlength.h"
16 #include "support/docstring.h"
17
18 #include <QChar>
19
20 #include <vector>
21 #include <utility>
22
23 class QComboBox;
24 class QLineEdit;
25 class QString;
26
27 class LengthCombo;
28
29 namespace lyx {
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 docstring const formatted(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 utf16 internally.
69  */
70 QString const toqstr(docstring const & ucs4);
71
72 void ucs4_to_qstring(char_type const * str, size_t ls, QString & s);
73
74 void ucs4_to_qstring(docstring const & str, QString & s);
75
76 QString ucs4_to_qstring(docstring const & str);
77
78 docstring const qstring_to_ucs4(QString const & qstr);
79
80 void qstring_to_ucs4(QString const & qstr, std::vector<char_type> & ucs4);
81
82 inline char_type const qchar_to_ucs4(QChar const & qchar) {
83         return static_cast<char_type>(qchar.unicode());
84 }
85
86 inline QChar const ucs4_to_qchar(char_type const ucs4) {
87         return QChar(static_cast<unsigned short>(ucs4));
88 }
89
90 /**
91  * qt_ - i18nize string and convert to unicode
92  *
93  * Use this in qt4/ instead of qt_()
94  */
95 QString const qt_(char const * str);
96
97
98 /**
99  * qt_ - i18nize string and convert to unicode
100  *
101  * Use this in qt4/ instead of qt_()
102  */
103 QString const qt_(std::string const & str);
104
105
106 /**
107  * fromqstr - convert QString into std::string in locale
108  *
109  * Return the QString encoded in the locale
110  */
111 std::string const fromqstr(QString const & str);
112
113
114 } // namespace lyx
115
116 #endif // QTHELPERS_H