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