]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/qt_helpers.h
Factorize out some code between TocModel.cpp and Menus.cpp.
[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 class LyXErr;
37
38 LyXErr & operator<<(LyXErr &, QString const &);
39
40 namespace frontend {
41
42 /// method to get a Length from widgets (LengthCombo)
43 std::string widgetsToLength(QLineEdit const * input, LengthCombo const * combo);
44 /// method to get a Length from widgets (QComboBox)
45 Length widgetsToLength(QLineEdit const * input, QComboBox const * combo);
46
47 //FIXME It would be nice if defaultUnit were a default argument
48 /// method to set widgets from a Length
49 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
50 Length const & len, Length::UNIT default_unit);
51 /// method to set widgets from a string
52 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
53 std::string const & len, Length::UNIT default_unit);
54 /// method to set widgets from a Length with optional "auto" if zero
55 void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo,
56 Length const & len, Length::UNIT defaultUnit);
57
58 /// colors a widget red if invalid
59 void setValid(QWidget * widget, bool valid);
60
61 } // namespace frontend
62
63
64 /**
65  * qt_ - i18nize string and convert to QString
66  *
67  * Use this in qt4/ instead of _()
68  */
69 QString const qt_(std::string const & str);
70
71 ///
72 support::FileName libFileSearch(QString const & dir, QString const & name,
73                                 QString const & ext = QString());
74
75 /** Wrapper around browseFile which tries to provide a filename
76         relative to relpath.  If the relative path is of the form "foo.txt"
77         or "bar/foo.txt", then it is returned as relative. OTOH, if it is
78         of the form "../baz/foo.txt", an absolute path is returned. This is
79         intended to be useful for insets which encapsulate files/
80 */
81 QString browseRelFile(QString const & filename,
82         QString const & refpath,
83         QString const & title,
84         QStringList const & filters,
85         bool save = false,
86         QString const & label1 = QString(),
87         QString const & dir1 = QString(),
88         QString const & label2 = QString(),
89         QString const & dir2 = QString());
90
91
92 /** Build filelists of all availabe bst/cls/sty-files. Done through
93 *  kpsewhich and an external script, saved in *Files.lst.
94 */
95 void rescanTexStyles();
96
97 /** Fill \c contents from one of the three texfiles.
98  *  Each entry in the file list is returned as a name_with_path
99  */
100 QStringList texFileList(QString const & filename);
101
102 // wrapper around the docstring versions
103 QString internalPath(QString const &);
104 QString onlyFilename(QString const & str);
105 QString onlyPath(QString const & str);
106 QStringList fileFilters(QString const & description);
107
108 QString changeExtension(QString const & oldname, QString const & extension);
109
110 /// Remove the extension from \p name
111 QString removeExtension(QString const & name);
112
113 /** Add the extension \p ext to \p name.
114  Use this instead of changeExtension if you know that \p name is without
115  extension, because changeExtension would wrongly interpret \p name if it
116  contains a dot.
117  */
118 QString addExtension(QString const & name, QString const & extension);
119
120 /// Return the extension of the file (not including the .)
121 QString getExtension(QString const & name);
122 QString makeAbsPath(QString const & relpath, QString const & base);
123 QString changeExtension(QString const & oldname, QString const & ext);
124
125 /// \return the display string associated with given type and buffer
126 /// parameter.
127 QString guiName(std::string const & type, BufferParams const & bp);
128
129 } // namespace lyx
130
131 #endif // QTHELPERS_H