4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
10 * Full author contact details are available in file CREDITS.
18 #include "support/lstrings.h"
19 #include "support/qstring_helpers.h"
20 #include "support/filetools.h"
23 #include <QHeaderView>
30 template <class T> class QList;
34 namespace support { class FileName; }
43 bool operator()(ColorCode lhs, ColorCode rhs) const {
44 return support::compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0;
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);
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
57 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
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);
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);
79 /// colors a widget red if invalid
80 void setValid(QWidget * widget, bool valid);
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);
89 } // namespace frontend
93 * qt_ - i18nize string and convert to QString
95 * Use this in qt4/ instead of _()
97 QString const qt_(std::string const & str);
98 QString const qt_(QString const & qstr);
102 support::FileName libFileSearch(QString const & dir, QString const & name,
103 QString const & ext = QString(),
104 support::search_mode mode = support::must_exist);
107 support::FileName imageLibFileSearch(QString & dir, QString const & name,
108 QString const & ext = QString(),
109 support::search_mode mode = support::must_exist);
111 /** Wrappers around browseFile which try to provide a filename
114 \param title: title for dialog
116 \param filters: *.ps, etc
118 \param save: whether to save dialog info (current path, etc) for next use.
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).
123 The difference between the functions concerns when we think we have a
126 In \c browseRelToParent, we return a relative path only if it IS NOT of
127 the form "../../foo.txt".
129 In \c browseRelToSub, we return a relative path only if it IS of the
130 form "../../foo.txt".
132 QString browseRelToParent(QString const & filename,
133 QString const & relpath,
134 QString const & title,
135 QStringList const & filters,
137 QString const & label1 = QString(),
138 QString const & dir1 = QString(),
139 QString const & label2 = QString(),
140 QString const & dir2 = QString());
142 QString browseRelToSub(QString const & filename,
143 QString const & relpath,
144 QString const & title,
145 QStringList const & filters,
147 QString const & label1 = QString(),
148 QString const & dir1 = QString(),
149 QString const & label2 = QString(),
150 QString const & dir2 = QString());
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.
157 void rescanTexStyles(std::string const & arg = empty_string());
159 /** Fill \c contents from one of the three texfiles.
160 * Each entry in the file list is returned as a name_with_path
162 QStringList texFileList(QString const & filename);
164 /// Convert internal line endings to line endings as expected by the OS
165 QString const externalLineEnding(docstring const & str);
167 /// Convert line endings in any formnat to internal line endings
168 docstring const internalLineEnding(QString const & str);
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);
176 QString changeExtension(QString const & oldname, QString const & extension);
178 /// Remove the extension from \p name
179 QString removeExtension(QString const & name);
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
186 QString addExtension(QString const & name, QString const & extension);
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);
193 /// \return the display string associated with given type and buffer
195 QString guiName(std::string const & type, BufferParams const & bp);
199 #endif // QTHELPERS_H