4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
8 * \author Richard Kimberly Heck
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>
33 namespace support { class FileName; }
39 /// method to get a Length from widgets (LengthCombo)
40 std::string widgetsToLength(QLineEdit const * input, LengthCombo const * combo);
41 /// method to get a Length from widgets (QComboBox)
42 Length widgetsToLength(QLineEdit const * input, QComboBox const * combo);
44 /// method to set widgets from a Length
45 //FIXME Remove default_unit argument for the first form. FIXME Change
46 // all the code to remove default_unit argument when equal to the
48 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
50 Length::UNIT default_unit = Length::defaultUnit());
51 /// method to set widgets from a string
52 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
53 std::string const & len,
54 Length::UNIT default_unit = Length::defaultUnit());
55 /// method to set widgets from a docstring
56 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
57 docstring const & len, Length::UNIT default_unit);
59 /// method to get a double value from a localized widget (QLineEdit)
60 double widgetToDouble(QLineEdit const * input);
61 /// method to get a double value from a localized widget (QLineEdit)
62 std::string widgetToDoubleStr(QLineEdit const * input);
63 /// method to set a (localized) double value in a widget (QLineEdit)
64 void doubleToWidget(QLineEdit * input, double value,
65 char f = 'g', int prec = 6);
66 /// method to set a (localized) double value in a widget (QLineEdit)
67 void doubleToWidget(QLineEdit * input, std::string const & value,
68 char f = 'g', int prec = 6);
70 * method to format localized floating point numbers without
71 * ever using scientific notation
73 QString formatLocFPNumber(double d);
75 /// Method to sort QStrings locale-aware (e.g. in combo widgets)
76 bool SortLocaleAware(QString const & lhs, QString const & rhs);
78 /// Method to sort colors by GUI name in combo widgets
79 bool ColorSorter(ColorCode lhs, ColorCode rhs);
81 /// colors a widget red if invalid
82 void setValid(QWidget * widget, bool valid);
84 // set focus and highlight the current item if there is no selection already
85 void focusAndHighlight(QAbstractItemView * w);
87 // Sets all widget in highlighted in highlighted colour, and their children in
88 // plain in standard colours.
89 void setMessageColour(std::list<QWidget *> highlighted,
90 std::list<QWidget *> plain);
92 /// Qt5 changed setSectionMode to setSectionResizeMode
93 /// These wrappers work for Qt4 and Qt5
94 void setSectionResizeMode(QHeaderView * view,
95 int logicalIndex, QHeaderView::ResizeMode mode);
96 void setSectionResizeMode(QHeaderView * view,
97 QHeaderView::ResizeMode mode);
98 /// Shows a directory in OSs file browser
99 void showDirectory(support::FileName const & directory);
100 /// handle request for showing citation content - shows pdf/ps or
101 /// web page in target; external script can be used for pdf/ps view
102 /// \p pdfv takes a pad viewer, \p psv a ps viewer
103 void showTarget(std::string const & target,
104 std::string const & pdfv,
105 std::string const & psv);
107 } // namespace frontend
111 * qt_ - i18nize string and convert to QString
113 * Use this in qt/ instead of _()
115 QString const qt_(std::string const & str);
116 QString const qt_(QString const & qstr);
120 support::FileName libFileSearch(QString const & dir, QString const & name,
121 QString const & ext = QString(),
122 support::search_mode mode = support::must_exist);
125 support::FileName imageLibFileSearch(QString & dir, QString const & name,
126 QString const & ext = QString(),
127 support::search_mode mode = support::must_exist);
129 /** Wrappers around browseFile which try to provide a filename
132 \param title: title for dialog
134 \param filters: *.ps, etc
136 \param save: whether to save dialog info (current path, etc) for next use.
138 The \param labelN and \param dirN arguments provide for extra buttons
139 in the dialog (e.g., "Templates" and a path to that directory).
141 The difference between the functions concerns when we think we have a
144 In \c browseRelToParent, we return a relative path only if it IS NOT of
145 the form "../../foo.txt".
147 In \c browseRelToSub, we return a relative path only if it IS of the
148 form "../../foo.txt".
150 QString browseRelToParent(QString const & filename,
151 QString const & relpath,
152 QString const & title,
153 QStringList const & filters,
155 QString const & label1 = QString(),
156 QString const & dir1 = QString(),
157 QString const & label2 = QString(),
158 QString const & dir2 = QString());
160 QString browseRelToSub(QString const & filename,
161 QString const & relpath,
162 QString const & title,
163 QStringList const & filters,
165 QString const & label1 = QString(),
166 QString const & dir1 = QString(),
167 QString const & label2 = QString(),
168 QString const & dir2 = QString());
170 /** Build filelists of all available bst/cls/sty-files. Done through
171 * kpsewhich and an external script, saved in *Files.lst.
172 * \param arg: cls, sty, bst, or bib, as required by TeXFiles.py.
173 * Can be a list of these, too.
175 void rescanTexStyles(std::string const & arg = empty_string());
177 /** Fill \c contents from one of the three texfiles.
178 * Each entry in the file list is returned as a name_with_path
180 QStringList texFileList(QString const & filename);
182 /// Convert internal line endings to line endings as expected by the OS
183 QString const externalLineEnding(docstring const & str);
185 /// Convert line endings in any formnat to internal line endings
186 docstring const internalLineEnding(QString const & str);
188 // wrapper around the docstring versions
189 QString internalPath(QString const &);
190 QString onlyFileName(QString const & str);
191 QString onlyPath(QString const & str);
192 QStringList fileFilters(QString const & description);
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 text is understood as rich text (Qt HTML) and if so, produce a
246 // rendering in plain text.
247 QString qtHtmlToPlainText(QString const & text);
252 #endif // QTHELPERS_H