]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/qt_helpers.h
extract code that sets color of widget from ButtonController and move to qt_helpers
[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/docstring.h"
18 #include "support/qstring_helpers.h"
19
20 #include <QString>
21 #include <utility>
22
23 class QComboBox;
24 class QLineEdit;
25 class QCheckBox;
26 class QWidget;
27
28 class LengthCombo;
29
30 namespace lyx {
31
32 std::string makeFontName(std::string const & family, std::string const & foundry);
33
34 std::pair<std::string,std::string> parseFontName(std::string const & name);
35
36 /// method to get a Length from widgets (LengthCombo)
37 std::string widgetsToLength(QLineEdit const * input, LengthCombo const * combo);
38 /// method to get a Length from widgets (QComboBox)
39 Length widgetsToLength(QLineEdit const * input, QComboBox const * combo);
40
41 //FIXME It would be nice if defaultUnit were a default argument
42 /// method to set widgets from a Length
43 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
44         Length const & len, Length::UNIT default_unit);
45 /// method to set widgets from a string
46 void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
47         std::string const & len, Length::UNIT default_unit);
48 /// method to set widgets from a Length with optional "auto" if zero
49 void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo,
50         Length const & len, Length::UNIT defaultUnit);
51
52 //FIXME setAutoTextCB should really take an argument, as indicated, that
53 //determines what text is to be written for "auto". But making
54 //that work involves more extensive revisions than we now want
55 //to make, since "auto" also appears in updateContents() (see
56 //GuiGraphics.cpp).
57 //The right way to do this, I think, would be to define a class
58 //checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
59 //the checkbox, line edit, and length combo together, and then made e.g.
60 //lengthToWidgets, widgetsToLength, etc, all public methods of that class.
61 //Perhaps even the validator could be exposed through it.
62 /**
63  * sets a checkbox-line edit-length combo group, using "text" if the
64  * checkbox is unchecked and clearing the line edit if it previously
65  * said "text".
66 */
67 void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
68         LengthCombo * lengthCombo/*, string text = "auto"*/);
69
70 /// colors a widget red if invalid
71 void setValid(QWidget * widget, bool valid);
72
73 /// format a string to the given width
74 docstring const formatted(docstring const & text, int w = 80);
75
76
77 /**
78  * qt_ - i18nize string and convert to QString
79  *
80  * Use this in qt4/ instead of _()
81  */
82 QString const qt_(char const * str, const char * comment = 0);
83
84
85 /**
86  * qt_ - i18nize string and convert to QString
87  *
88  * Use this in qt4/ instead of _()
89  */
90 QString const qt_(std::string const & str);
91
92 } // namespace lyx
93
94 #endif // QTHELPERS_H