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