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