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