]> git.lyx.org Git - lyx.git/blob - src/Floating.cpp
Replace obsoleted signal QComboBox::activated(QString)
[lyx.git] / src / Floating.cpp
1 /**
2  * \file Floating.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jean-Marc Lasgouttes
8  * \author Angus Leeming
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14 #include <set>
15
16 #include "Floating.h"
17
18 #include "support/debug.h"
19 #include "support/lstrings.h"
20 #include "support/textutils.h"
21
22 using namespace std;
23
24
25 namespace lyx {
26
27
28 Floating::Floating(string const & type, string const & placement,
29                    string const & ext, string const & within,
30                    string const & style, string const & name,
31                    string const & listName, std::string const & listCmd,
32                    string const & refPrefix, std::string const & allowedplacement,
33                    string const & htmlTag, string const & htmlAttrib,
34                    docstring const & htmlStyle,
35                    string const & docbookAttr, string const & docbookTagType,
36            string const & required, bool usesfloat, bool ispredefined,
37                    bool allowswide, bool allowssideways)
38         : floattype_(type), placement_(placement), ext_(ext), within_(within),
39           style_(style), name_(name), listname_(listName), listcommand_(listCmd),
40           refprefix_(refPrefix), allowedplacement_(allowedplacement), required_(required),
41           usesfloatpkg_(usesfloat), ispredefined_(ispredefined),
42           allowswide_(allowswide), allowssideways_(allowssideways),
43           html_tag_(htmlTag), html_attrib_(htmlAttrib), html_style_(htmlStyle),
44           docbook_attr_(docbookAttr), docbook_tag_type_(docbookTagType)
45 {}
46
47
48 std::string Floating::docbookFloatType() const
49 {
50         // TODO: configure this in the layouts?
51         if (floattype_ == "figure" || floattype_ == "graph" ||
52                         floattype_ == "chart" || floattype_ == "scheme")  {
53                 return "figure";
54         } else if (floattype_ == "table" || floattype_ == "tableau") {
55                 return "table";
56         } else if (floattype_ == "algorithm") {
57                 return "algorithm";
58         } else if (floattype_ == "video") {
59                 return "video";
60         } else {
61                 // If nothing matches, return something that will not be valid.
62                 LYXERR0("Unrecognised float type: " + floattype_);
63                 return "unknown";
64         }
65 }
66
67
68 string const & Floating::htmlAttrib() const
69 {
70         if (html_attrib_.empty())
71                 html_attrib_ = "class='" + defaultCSSClass() + "'";
72         return html_attrib_;
73 }
74
75
76 string const & Floating::htmlTag() const
77 {
78         if (html_tag_.empty())
79                 html_tag_ = "div";
80         return html_tag_;
81 }
82
83
84 string Floating::defaultCSSClass() const
85 {
86         if (!defaultcssclass_.empty())
87                 return defaultcssclass_;
88         string d;
89         string n = floattype_;
90         string::const_iterator it = n.begin();
91         string::const_iterator en = n.end();
92         for (; it != en; ++it) {
93                 if (!isAlphaASCII(*it))
94                         d += "_";
95                 else if (isLower(*it))
96                         d += *it;
97                 else
98                         d += support::lowercase(*it);
99         }
100         // are there other characters we need to remove?
101         defaultcssclass_ = "float-" + d;
102         return defaultcssclass_;
103 }
104
105
106 string Floating::docbookAttr() const
107 {
108         std::set<std::string> achemso = { "chart", "graph", "scheme" };
109         // For algorithms, a type attribute must be mentioned, if not already present in docbook_attr_.
110         if (docbookFloatType() == "algorithm" && docbook_attr_.find("type=") != std::string::npos)
111                 return docbook_attr_ + " type='algorithm'";
112         // Specific floats for achemso.
113         else if (docbookFloatType() == "figure" && achemso.find(floattype_) != achemso.end())
114                 return docbook_attr_ + " type='" + floattype_ + "'";
115         else
116                 return docbook_attr_;
117 }
118
119
120 string Floating::docbookTag(bool hasTitle) const
121 {
122         // TODO: configure this in the layouts?
123         if (docbookFloatType() == "figure" || docbookFloatType() == "algorithm" || docbookFloatType() == "video") {
124                 return hasTitle ? "figure" : "informalfigure";
125         } else if (docbookFloatType() == "table") {
126                 return hasTitle ? "table" : "informaltable";
127         } else {
128                 // If nothing matches, return something that will not be valid.
129                 LYXERR0("Unrecognised float type: " + floattype());
130                 return "float";
131         }
132 }
133
134
135 string const & Floating::docbookTagType() const
136 {
137         if (docbook_tag_type_ != "block" && docbook_tag_type_ != "paragraph" && docbook_tag_type_ != "inline")
138                 docbook_tag_type_ = "block";
139         return docbook_tag_type_;
140 }
141
142
143 string const & Floating::docbookCaption() const
144 {
145         docbook_caption_ = "";
146         if (floattype_ == "figure" || floattype_ == "algorithm")
147                 docbook_caption_ = "title";
148         else if (floattype_ == "table" || floattype_ == "tableau")
149                 docbook_caption_ = "caption";
150         return docbook_caption_;
151 }
152
153
154 } // namespace lyx