uitranslator.cpp

main 116 lines · 3.9 KB Raw
Alex Alex Commit Client Upload Part 2 19/10/2026 00:06
1/*
2 * Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#include "uitranslator.h"
24#include <framework/stdext/string.h>
25#include <boost/algorithm/string.hpp>
26
27Fw::AlignmentFlag Fw::translateAlignment(std::string aligment)
28{
29 boost::to_lower(aligment);
30 boost::erase_all(aligment, " ");
31 if(aligment == "topleft")
32 return Fw::AlignTopLeft;
33 else if(aligment == "topright")
34 return Fw::AlignTopRight;
35 else if(aligment == "bottomleft")
36 return Fw::AlignBottomLeft;
37 else if(aligment == "bottomright")
38 return Fw::AlignBottomRight;
39 else if(aligment == "left")
40 return Fw::AlignLeftCenter;
41 else if(aligment == "right")
42 return Fw::AlignRightCenter;
43 else if(aligment == "top")
44 return Fw::AlignTopCenter;
45 else if(aligment == "bottom")
46 return Fw::AlignBottomCenter;
47 else if(aligment == "center")
48 return Fw::AlignCenter;
49 return Fw::AlignNone;
50}
51
52Fw::AnchorEdge Fw::translateAnchorEdge(std::string anchorEdge)
53{
54 boost::to_lower(anchorEdge);
55 boost::erase_all(anchorEdge, " ");
56 if(anchorEdge == "left")
57 return Fw::AnchorLeft;
58 else if(anchorEdge == "right")
59 return Fw::AnchorRight;
60 else if(anchorEdge == "top")
61 return Fw::AnchorTop;
62 else if(anchorEdge == "bottom")
63 return Fw::AnchorBottom;
64 else if(anchorEdge == "horizontalcenter")
65 return Fw::AnchorHorizontalCenter;
66 else if(anchorEdge == "verticalcenter")
67 return Fw::AnchorVerticalCenter;
68 return Fw::AnchorNone;
69}
70
71Fw::WidgetState Fw::translateState(std::string state)
72{
73 boost::to_lower(state);
74 boost::trim(state);
75 if(state == "active")
76 return Fw::ActiveState;
77 else if(state == "focus")
78 return Fw::FocusState;
79 else if(state == "hover")
80 return Fw::HoverState;
81 else if(state == "pressed")
82 return Fw::PressedState;
83 else if(state == "checked")
84 return Fw::CheckedState;
85 else if(state == "disabled")
86 return Fw::DisabledState;
87 else if(state == "on")
88 return Fw::OnState;
89 else if(state == "first")
90 return Fw::FirstState;
91 else if(state == "middle")
92 return Fw::MiddleState;
93 else if(state == "last")
94 return Fw::LastState;
95 else if(state == "alternate")
96 return Fw::AlternateState;
97 else if(state == "dragging")
98 return Fw::DraggingState;
99 else if (state == "hidden")
100 return Fw::HiddenState;
101 else if (state == "mobile")
102 return Fw::MobileState;
103 return Fw::InvalidState;
104}
105
106Fw::AutoFocusPolicy Fw::translateAutoFocusPolicy(std::string policy)
107{
108 boost::to_lower(policy);
109 boost::trim(policy);
110 if(policy == "first")
111 return Fw::AutoFocusFirst;
112 else if(policy == "last")
113 return Fw::AutoFocusLast;
114 return Fw::AutoFocusNone;
115}
116
Top