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