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