]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/qt_helpers.h
* qt_helpers:
[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 lyx::docstring const qstring_to_ucs4(QString const & qstr);
75
76 void qstring_to_ucs4(QString const & qstr, std::vector<lyx::char_type> & ucs4);
77
78 inline lyx::char_type const qchar_to_ucs4(QChar const & qchar) {
79         return static_cast<lyx::char_type>(qchar.unicode());
80 }
81
82 inline QChar const ucs4_to_qchar(lyx::char_type const ucs4) {
83         return QChar(static_cast<unsigned short>(ucs4));
84 }
85
86 /**
87  * qt_ - i18nize string and convert to unicode
88  *
89  * Use this in qt4/ instead of qt_()
90  */
91 QString const qt_(char const * str);
92
93
94 /**
95  * qt_ - i18nize string and convert to unicode
96  *
97  * Use this in qt4/ instead of qt_()
98  */
99 QString const qt_(std::string const & str);
100
101
102 /**
103  * fromqstr - convert QString into std::string in locale
104  *
105  * Return the QString encoded in the locale
106  */
107 std::string const fromqstr(QString const & str);
108
109 #endif // QTHELPERS_H