]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/qt_helpers.h
Add a function to translate QStrings
[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  * \author Richard Heck
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef QTHELPERS_H
14 #define QTHELPERS_H
15
16 #include "Length.h"
17 #include "support/qstring_helpers.h"
18 #include "qt_i18n.h"
19
20 #include <QString>
21 #include <QHeaderView>
22
23 class QComboBox;
24 class QLineEdit;
25 class QCheckBox;
26 class QString;
27 class QWidget;
28 template <class T> class QList;
29
30 namespace lyx {
31
32 namespace support { class FileName; }
33
34 class BufferParams;
35
36 namespace frontend {
37
38 class LengthCombo;
39
40 /// method to get a Length from widgets (LengthCombo)
41 std::string widgetsToLength(QLineEdit const * input, LengthCombo const * combo);
42 /// method to get a Length from widgets (QComboBox)
43 Length widgetsToLength(QLineEdit const * input, QComboBox const * combo);
44
45 //FIXME It would be nice if defaultUnit were a default argument
46 /// method to set widgets from a Length
47 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
48 Length const & len, Length::UNIT default_unit);
49 /// method to set widgets from a string
50 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
51 std::string const & len, Length::UNIT default_unit);
52 /// method to set widgets from a docstring
53 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
54 docstring const & len, Length::UNIT default_unit);
55
56 /// method to get a double value from a localized widget (QLineEdit)
57 double widgetToDouble(QLineEdit const * input);
58 /// method to get a double value from a localized widget (QLineEdit)
59 std::string widgetToDoubleStr(QLineEdit const * input);
60 /// method to set a (localized) double value in a widget (QLineEdit)
61 void doubleToWidget(QLineEdit * input, double const & value,
62         char f = 'g', int prec = 6);
63 /// method to set a (localized) double value in a widget (QLineEdit)
64 void doubleToWidget(QLineEdit * input, std::string const & value,
65         char f = 'g', int prec = 6);
66
67 /// colors a widget red if invalid
68 void setValid(QWidget * widget, bool valid);
69
70 /// Qt5 changed setSectionMode to setSectionResizeMode
71 /// These wrappers work for Qt4 and Qt5
72 void setSectionResizeMode(QHeaderView * view,
73     int logicalIndex, QHeaderView::ResizeMode mode);
74 void setSectionResizeMode(QHeaderView * view,
75         QHeaderView::ResizeMode mode);
76
77 } // namespace frontend
78
79
80 /**
81  * qt_ - i18nize string and convert to QString
82  *
83  * Use this in qt4/ instead of _()
84  */
85 QString const qt_(std::string const & str);
86 QString const qt_(QString const & qstr);
87
88
89 ///
90 support::FileName libFileSearch(QString const & dir, QString const & name,
91                                 QString const & ext = QString());
92
93 ///
94 support::FileName imageLibFileSearch(QString & dir, QString const & name,
95                                      QString const & ext = QString());
96
97 /** Wrappers around browseFile which try to provide a filename
98         relative to relpath.
99
100 \param title: title for dialog
101         
102 \param filters: *.ps, etc
103
104 \param save: whether to save dialog info (current path, etc) for next use.
105
106 The \param labelN and \param dirN arguments provide for extra buttons 
107 in the dialog (e.g., "Templates" and a path to that directory).
108
109 The difference between the functions concerns when we think we have a 
110 relative path. 
111
112 In \c browseRelToParent, we return a relative path only if it IS NOT of 
113         the form "../../foo.txt".
114
115 In \c browseRelToSub, we return a relative path only if it IS of the
116  form "../../foo.txt".
117 */
118 QString browseRelToParent(QString const & filename,
119         QString const & relpath,
120         QString const & title,
121         QStringList const & filters,
122         bool save = false,
123         QString const & label1 = QString(),
124         QString const & dir1 = QString(),
125         QString const & label2 = QString(),
126         QString const & dir2 = QString());
127
128 QString browseRelToSub(QString const & filename,
129         QString const & relpath,
130         QString const & title,
131         QStringList const & filters,
132         bool save = false,
133         QString const & label1 = QString(),
134         QString const & dir1 = QString(),
135         QString const & label2 = QString(),
136         QString const & dir2 = QString());
137
138 /** Build filelists of all availabe bst/cls/sty-files. Done through
139 *  kpsewhich and an external script, saved in *Files.lst.
140 *  \param arg: cls, sty, bst, or bib, as required by TeXFiles.py.
141 *         Can be a list of these, too.
142 */
143 void rescanTexStyles(std::string const & arg = empty_string());
144
145 /** Fill \c contents from one of the three texfiles.
146  *  Each entry in the file list is returned as a name_with_path
147  */
148 QStringList texFileList(QString const & filename);
149
150 /// Convert internal line endings to line endings as expected by the OS
151 QString const externalLineEnding(docstring const & str);
152
153 /// Convert line endings in any formnat to internal line endings
154 docstring const internalLineEnding(QString const & str);
155
156 // wrapper around the docstring versions
157 QString internalPath(QString const &);
158 QString onlyFileName(QString const & str);
159 QString onlyPath(QString const & str);
160 QStringList fileFilters(QString const & description);
161
162 QString changeExtension(QString const & oldname, QString const & extension);
163
164 /// Remove the extension from \p name
165 QString removeExtension(QString const & name);
166
167 /** Add the extension \p ext to \p name.
168  Use this instead of changeExtension if you know that \p name is without
169  extension, because changeExtension would wrongly interpret \p name if it
170  contains a dot.
171  */
172 QString addExtension(QString const & name, QString const & extension);
173
174 /// Return the extension of the file (not including the .)
175 QString getExtension(QString const & name);
176 QString makeAbsPath(QString const & relpath, QString const & base);
177 QString changeExtension(QString const & oldname, QString const & ext);
178
179 /// \return the display string associated with given type and buffer
180 /// parameter.
181 QString guiName(std::string const & type, BufferParams const & bp);
182
183 } // namespace lyx
184
185 #endif // QTHELPERS_H