Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2008 Emweb bv, Herent, Belgium. |
3 | | * |
4 | | * See the LICENSE file for terms of use. |
5 | | */ |
6 | | |
7 | | #include "Wt/WIcon.h" |
8 | | #include "Wt/WApplication.h" |
9 | | #include "Wt/WEnvironment.h" |
10 | | #include "Wt/WCssDecorationStyle.h" |
11 | | #include "Wt/WFont.h" |
12 | | |
13 | | #include "WebUtils.h" |
14 | | #include "DomElement.h" |
15 | | |
16 | | namespace Wt { |
17 | | |
18 | | WIcon::WIcon() |
19 | 0 | : iconChanged_(false) |
20 | 0 | { } |
21 | | |
22 | | WIcon::WIcon(const std::string& name) |
23 | 0 | : iconChanged_(false) |
24 | 0 | { |
25 | 0 | setName(name); |
26 | 0 | } |
27 | | |
28 | | void WIcon::setName(const std::string& name) |
29 | 0 | { |
30 | 0 | if (name_ != name) { |
31 | 0 | name_ = name; |
32 | 0 | iconChanged_ = true; |
33 | 0 | repaint(); |
34 | |
|
35 | 0 | if (!name_.empty()) |
36 | 0 | loadIconFont(); |
37 | 0 | } |
38 | 0 | } |
39 | | |
40 | | void WIcon::setSize(double factor) |
41 | 0 | { |
42 | 0 | decorationStyle().font().setSize(WLength(factor, LengthUnit::FontEm)); |
43 | 0 | } |
44 | | |
45 | | double WIcon::size() const |
46 | 0 | { |
47 | 0 | const WFont& f = decorationStyle().font(); |
48 | 0 | if (f.sizeLength().unit() == LengthUnit::FontEm) |
49 | 0 | return f.sizeLength().value(); |
50 | 0 | else |
51 | 0 | return 1; |
52 | 0 | } |
53 | | |
54 | | void WIcon::updateDom(DomElement& element, bool all) |
55 | 0 | { |
56 | 0 | if (iconChanged_ || all) { |
57 | 0 | std::string sc; |
58 | 0 | if (!all) |
59 | 0 | sc = styleClass().toUTF8(); |
60 | |
|
61 | 0 | if (!name_.empty()) |
62 | 0 | sc = Utils::addWord(sc, "fa fa-" + name_); |
63 | |
|
64 | 0 | element.setProperty(Property::Class, sc); |
65 | |
|
66 | 0 | iconChanged_ = false; |
67 | 0 | } |
68 | |
|
69 | 0 | WInteractWidget::updateDom(element, all); |
70 | 0 | } |
71 | | |
72 | | DomElementType WIcon::domElementType() const |
73 | 0 | { |
74 | 0 | return DomElementType::I; |
75 | 0 | } |
76 | | |
77 | | void WIcon::propagateRenderOk(bool deep) |
78 | 0 | { |
79 | 0 | iconChanged_ = false; |
80 | |
|
81 | 0 | WInteractWidget::propagateRenderOk(deep); |
82 | 0 | } |
83 | | |
84 | | void WIcon::loadIconFont() |
85 | 0 | { |
86 | 0 | WApplication *app = WApplication::instance(); |
87 | |
|
88 | 0 | std::string fontDir = WApplication::relativeResourcesUrl() |
89 | 0 | + "font-awesome/"; |
90 | |
|
91 | 0 | app->useStyleSheet(fontDir + "css/font-awesome.min.css"); |
92 | 0 | } |
93 | | |
94 | | } |