]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/qt_helpers.h
* fix spelling in comments to please John.
[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 "Length.h"
17 #include "support/qstring_helpers.h"
18 #include "qt_i18n.h"
19
20 #include <QString>
21
22 class QComboBox;
23 class QLineEdit;
24 class QCheckBox;
25 class QString;
26 class QWidget;
27 template <class T> class QList;
28
29 class LengthCombo;
30
31 namespace lyx {
32
33 namespace support { class FileName; }
34
35 class BufferParams;
36
37 namespace frontend {
38
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);
43
44 //FIXME It would be nice if defaultUnit were a default argument
45 /// method to set widgets from a Length
46 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
47 Length const & len, Length::UNIT default_unit);
48 /// method to set widgets from a string
49 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
50 std::string const & len, Length::UNIT default_unit);
51 /// method to set widgets from a docstring
52 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
53 docstring const & len, Length::UNIT default_unit);
54
55 /// method to get a double value from a localized widget (QLineEdit)
56 double widgetToDouble(QLineEdit const * input);
57 /// method to get a double value from a localized widget (QLineEdit)
58 std::string widgetToDoubleStr(QLineEdit const * input);
59 /// method to set a (localized) double value in a widget (QLineEdit)
60 void doubleToWidget(QLineEdit * input, double const & value,
61         char f = 'g', int prec = 6);
62 /// method to set a (localized) double value in a widget (QLineEdit)
63 void doubleToWidget(QLineEdit * input, std::string const & value,
64         char f = 'g', int prec = 6);
65
66 /// colors a widget red if invalid
67 void setValid(QWidget * widget, bool valid);
68
69 } // namespace frontend
70
71
72 /**
73  * qt_ - i18nize string and convert to QString
74  *
75  * Use this in qt4/ instead of _()
76  */
77 QString const qt_(std::string const & str);
78
79 ///
80 support::FileName libFileSearch(QString const & dir, QString const & name,
81                                 QString const & ext = QString());
82
83 /** Wrapper around browseFile which tries to provide a filename
84         relative to relpath.  If the relative path is of the form "foo.txt"
85         or "bar/foo.txt", then it is returned as relative. OTOH, if it is
86         of the form "../baz/foo.txt", an absolute path is returned. This is
87         intended to be useful for insets which encapsulate files/
88 */
89 QString browseRelFile(QString const & filename,
90         QString const & refpath,
91         QString const & title,
92         QStringList const & filters,
93         bool save = false,
94         QString const & label1 = QString(),
95         QString const & dir1 = QString(),
96         QString const & label2 = QString(),
97         QString const & dir2 = QString());
98
99
100 /** Build filelists of all availabe bst/cls/sty-files. Done through
101 *  kpsewhich and an external script, saved in *Files.lst.
102 */
103 void rescanTexStyles();
104
105 /** Fill \c contents from one of the three texfiles.
106  *  Each entry in the file list is returned as a name_with_path
107  */
108 QStringList texFileList(QString const & filename);
109
110 /// Convert internal line endings to line endings as expected by the OS
111 QString const externalLineEnding(docstring const & str);
112
113 /// Convert line endings in any formnat to internal line endings
114 docstring const internalLineEnding(QString const & str);
115
116 // wrapper around the docstring versions
117 QString internalPath(QString const &);
118 QString onlyFilename(QString const & str);
119 QString onlyPath(QString const & str);
120 QStringList fileFilters(QString const & description);
121
122 QString changeExtension(QString const & oldname, QString const & extension);
123
124 /// Remove the extension from \p name
125 QString removeExtension(QString const & name);
126
127 /** Add the extension \p ext to \p name.
128  Use this instead of changeExtension if you know that \p name is without
129  extension, because changeExtension would wrongly interpret \p name if it
130  contains a dot.
131  */
132 QString addExtension(QString const & name, QString const & extension);
133
134 /// Return the extension of the file (not including the .)
135 QString getExtension(QString const & name);
136 QString makeAbsPath(QString const & relpath, QString const & base);
137 QString changeExtension(QString const & oldname, QString const & ext);
138
139 /// \return the display string associated with given type and buffer
140 /// parameter.
141 QString guiName(std::string const & type, BufferParams const & bp);
142
143 } // namespace lyx
144
145 #endif // QTHELPERS_H