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.
17 #include "support/Length.h"
18 #include "support/qstring_helpers.h"
19 #include "support/filetools.h"
24 #include <QHeaderView>
31 template <class T> class QList;
35 namespace support { class FileName; }
43 /// method to get a Length from widgets (LengthCombo)
44 std::string widgetsToLength(QLineEdit const * input, LengthCombo const * combo);
45 /// method to get a Length from widgets (QComboBox)
46 Length widgetsToLength(QLineEdit const * input, QComboBox const * combo);
48 /// method to set widgets from a Length
49 //FIXME Remove default_unit argument for the first form. FIXME Change
50 // all the code to remove default_unit argument when equal to the
52 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
54 Length::UNIT default_unit = Length::defaultUnit());
55 /// method to set widgets from a string
56 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
57 std::string const & len,
58 Length::UNIT default_unit = Length::defaultUnit());
59 /// method to set widgets from a docstring
60 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
61 docstring const & len, Length::UNIT default_unit);
63 /// method to get a double value from a localized widget (QLineEdit)
64 double widgetToDouble(QLineEdit const * input);
65 /// method to get a double value from a localized widget (QLineEdit)
66 std::string widgetToDoubleStr(QLineEdit const * input);
67 /// method to set a (localized) double value in a widget (QLineEdit)
68 void doubleToWidget(QLineEdit * input, double const & value,
69 char f = 'g', int prec = 6);
70 /// method to set a (localized) double value in a widget (QLineEdit)
71 void doubleToWidget(QLineEdit * input, std::string const & value,
72 char f = 'g', int prec = 6);
74 * method to format localized floating point numbers without
75 * ever using scientific notation
77 QString formatLocFPNumber(double d);
79 /// Method to sort QStrings locale-aware (e.g. in combo widgets)
80 bool SortLocaleAware(QString const & lhs, QString const & rhs);
82 /// Method to sort colors by GUI name in combo widgets
83 bool ColorSorter(ColorCode lhs, ColorCode rhs);
85 /// colors a widget red if invalid
86 void setValid(QWidget * widget, bool valid);
88 // set focus and highlight the current item if there is no selection already
89 void focusAndHighlight(QAbstractItemView * w);
91 // Sets all widget in highlighted in highlighted colour, and their children in
92 // plain in standard colours.
93 void setMessageColour(std::list<QWidget *> highlighted,
94 std::list<QWidget *> plain);
96 /// Qt5 changed setSectionMode to setSectionResizeMode
97 /// These wrappers work for Qt4 and Qt5
98 void setSectionResizeMode(QHeaderView * view,
99 int logicalIndex, QHeaderView::ResizeMode mode);
100 void setSectionResizeMode(QHeaderView * view,
101 QHeaderView::ResizeMode mode);
102 /// Shows a directory in OSs file browser
103 void showDirectory(support::FileName const & directory);
105 } // namespace frontend
109 * qt_ - i18nize string and convert to QString
111 * Use this in qt/ instead of _()
113 QString const qt_(std::string const & str);
114 QString const qt_(QString const & qstr);
118 support::FileName libFileSearch(QString const & dir, QString const & name,
119 QString const & ext = QString(),
120 support::search_mode mode = support::must_exist);
123 support::FileName imageLibFileSearch(QString & dir, QString const & name,
124 QString const & ext = QString(),
125 support::search_mode mode = support::must_exist);
127 /** Wrappers around browseFile which try to provide a filename
130 \param title: title for dialog
132 \param filters: *.ps, etc
134 \param save: whether to save dialog info (current path, etc) for next use.
136 The \param labelN and \param dirN arguments provide for extra buttons
137 in the dialog (e.g., "Templates" and a path to that directory).
139 The difference between the functions concerns when we think we have a
142 In \c browseRelToParent, we return a relative path only if it IS NOT of
143 the form "../../foo.txt".
145 In \c browseRelToSub, we return a relative path only if it IS of the
146 form "../../foo.txt".
148 QString browseRelToParent(QString const & filename,
149 QString const & relpath,
150 QString const & title,
151 QStringList const & filters,
153 QString const & label1 = QString(),
154 QString const & dir1 = QString(),
155 QString const & label2 = QString(),
156 QString const & dir2 = QString());
158 QString browseRelToSub(QString const & filename,
159 QString const & relpath,
160 QString const & title,
161 QStringList const & filters,
163 QString const & label1 = QString(),
164 QString const & dir1 = QString(),
165 QString const & label2 = QString(),
166 QString const & dir2 = QString());
168 /** Build filelists of all available bst/cls/sty-files. Done through
169 * kpsewhich and an external script, saved in *Files.lst.
170 * \param arg: cls, sty, bst, or bib, as required by TeXFiles.py.
171 * Can be a list of these, too.
173 void rescanTexStyles(std::string const & arg = empty_string());
175 /** Fill \c contents from one of the three texfiles.
176 * Each entry in the file list is returned as a name_with_path
178 QStringList texFileList(QString const & filename);
180 /// Convert internal line endings to line endings as expected by the OS
181 QString const externalLineEnding(docstring const & str);
183 /// Convert line endings in any formnat to internal line endings
184 docstring const internalLineEnding(QString const & str);
186 // wrapper around the docstring versions
187 QString internalPath(QString const &);
188 QString onlyFileName(QString const & str);
189 QString onlyPath(QString const & str);
190 QStringList fileFilters(QString const & description);
192 QString changeExtension(QString const & oldname, QString const & extension);
194 /// Remove the extension from \p name
195 QString removeExtension(QString const & name);
197 /** Add the extension \p ext to \p name.
198 Use this instead of changeExtension if you know that \p name is without
199 extension, because changeExtension would wrongly interpret \p name if it
202 QString addExtension(QString const & name, QString const & extension);
204 /// Return the extension of the file (not including the .)
205 QString getExtension(QString const & name);
206 QString makeAbsPath(QString const & relpath, QString const & base);
207 QString changeExtension(QString const & oldname, QString const & ext);
209 /// Format \param text for display as a ToolTip, breaking at lines of \param
210 /// width ems. Note: this function is expensive. Better call it in a delayed
211 /// manner, i.e. not to fill in a model (see for instance the function
212 /// ToolTipFormatter::eventFilter).
214 /// When is it called automatically? Whenever the tooltip is not already rich
215 /// text beginning with <html>, and is defined by the following functions:
216 /// - QWidget::setToolTip(),
217 /// - QAbstractItemModel::setData(..., Qt::ToolTipRole),
218 /// - Inset::toolTip()
220 /// In other words, tooltips can use Qt html, and the tooltip will still be
221 /// correctly broken. Moreover, it is possible to specify an entirely custom
222 /// tooltip (not subject to automatic formatting) by giving it in its entirety,
223 /// i.e. starting with <html>.
224 QString formatToolTip(QString text, int width = 30);
227 #if QT_VERSION < 0x050300
228 // Very partial implementation of QSignalBlocker for archaic qt versions.
229 class QSignalBlocker {
231 explicit QSignalBlocker(QObject * o)
232 : obj(o), init_state(obj && obj->blockSignals(true)) {}
236 obj->blockSignals(init_state);
245 // Check if qstr is understood as rich text (Qt HTML) and if so, produce a
246 // rendering in plain text.
247 QString qtHtmlToPlainText(QString const & qstr);
252 #endif // QTHELPERS_H