Debian Codegraph @

config-tool/skin/skinfcitx.cpp

raw
1 /*
2 * Copyright (C) 2013 National University of Defense Technology(NUDT) & Kylin Ltd.
3 *
4 * Authors:
5 * lenky gao [email protected]/[email protected]
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <QDebug>
21 #include <QBitmap>
22 #include <QColor>
23 #include <QDir>
24 #include <QFile>
25 #include <QFontMetrics>
26 #include <QPainter>
27 #include <QPixmap>
28 #include <QString>
29 #include <QTextStream>
30
31 #include "skinfcitx.h"
32
33 SkinFcitx::SkinFcitx() : SkinBase()
34 {
35
36 }
37
38 SkinFcitx::~SkinFcitx()
39 {
40
41 }
42
43 bool SkinFcitx::loadSkin(const QString skinPath)
44 {
45 init();
46 QFile fcitxSkinConfFile(skinPath + "fcitx_skin.conf");
47 if (!fcitxSkinConfFile.exists())
48 return false;
49 if (!fcitxSkinConfFile.open(QIODevice::ReadOnly))
50 return false;
51 QString line;
52 QString key, value;
53
54 bool skinFont = false;
55 bool skinInputBar = false;
56 bool skinFontVertical = false;
57 bool skinInputBarVertical = false;
58
59
60 QTextStream textStream(fcitxSkinConfFile.readAll());
61 do {
62 line = textStream.readLine(); //文件流指控制换行
63
64 if (line.isEmpty() || line.at(0) == '#')
65 continue;
66
67 if (line.at(0) == '[') {
68 skinFont = (line == "[SkinFont]");
69 skinInputBar = (line == "[SkinInputBar]");
70 skinFontVertical = (line == "[SkinFontVertical]");
71 skinInputBarVertical = (line == "[SkinInputBarVertical]");
72 continue;
73 }
74
75 if (!line.contains('='))
76 continue;
77
78 key = line.split('=').at(0);
79 value = line.split('=').at(1);
80 if (value.isEmpty())
81 continue;
82 if (skinFont) {
83 if (key == "FontSize") {
84 setFontSize(value.toInt());
85
86 } else if (key == "CandFontSize") {
87 setCandFontSize(value.toInt());
88
89 } else if (key == "InputColor") {
90 setInputColor(value2color(value));
91
92 } else if (key == "IndexColor") {
93 setIndexColor(value2color(value));
94
95 } else if (key == "FirstCandColor") {
96 setFirstCandColor(value2color(value));
97
98 } else if (key == "OtherColor") {
99 setOtherColor(value2color(value));
100
101 }
102 } else if (skinInputBar) {
103 if (key == "BackImg") {
104 setInputBackImg("file:/" + skinPath + value);
105
106 } else if (key == "TipsImg") {
107 setTipsImg("file:/" + skinPath + value);
108
109 } else if (key == "AdjustWidth") {
110 setAdjustWidth(value.toInt());
111
112 } else if (key == "AdjustHeight") {
113 setAdjustHeight(value.toInt());
114
115 } else if (key == "MarginLeft") {
116 setMarginLeft(value.toInt());
117
118 } else if (key == "MarginTop") {
119 setMarginTop(value.toInt());
120
121 } else if (key == "MarginRight") {
122 setMarginRight(value.toInt());
123
124 } else if (key == "MarginBottom") {
125 setMarginBottom(value.toInt());
126
127 } else if (key == "horizontalTileMode") {
128 setHorizontalTileMode(value);
129
130 } else if (key == "verticalTileMode") {
131 setVerticalTileMode(value);
132
133 } else if (key == "InputStringPosX") {
134 setInputStringPosX(value.toInt());
135
136 } else if (key == "InputStringPosY") {
137 setInputStringPosY(value.toInt());
138
139 } else if (key == "OutputCandPosX") {
140 setOutputCandPosX(value.toInt());
141
142 } else if (key == "OutputCandPosY") {
143 setOutputCandPosY(value.toInt());
144
145 } else if (key == "BackArrowPosX") {
146 setBackArrowPosX(value.toInt());
147
148 } else if (key == "BackArrowPosY") {
149 setBackArrowPosY(value.toInt());
150
151 } else if (key == "ForwardArrowPosX") {
152 setForwardArrowPosX(value.toInt());
153
154 } else if (key == "ForwardArrowPosY") {
155 setForwardArrowPosY(value.toInt());
156
157 } else if (key == "BackArrow") {
158 setBackArrowImg("file:/" + skinPath + value);
159
160 } else if (key == "ForwardArrow") {
161 setForwardArrowImg("file:/" + skinPath + value);
162
163 }
164 } else if (skinFontVertical) {
165 if (key == "FontSize") {
166 setFontSizeVertical(value.toInt());
167
168 } else if (key == "CandFontSize") {
169 setCandFontSizeVertical(value.toInt());
170
171 } else if (key == "InputColor") {
172 setInputColorVertical(value2color(value));
173
174 } else if (key == "IndexColor") {
175 setIndexColorVertical(value2color(value));
176
177 } else if (key == "FirstCandColor") {
178 setFirstCandColorVertical(value2color(value));
179
180 } else if (key == "OtherColor") {
181 setOtherColorVertical(value2color(value));
182 }
183 } else if (skinInputBarVertical) {
184 if (key == "BackImg") {
185 setInputBackImgVertical("file:/" + skinPath + value);
186
187 } else if (key == "TipsImg") {
188 setTipsImgVertical("file:/" + skinPath + value);
189
190 } else if (key == "AdjustWidth") {
191 setAdjustWidthVertical(value.toInt());
192
193 } else if (key == "AdjustHeight") {
194 setAdjustHeightVertical(value.toInt());
195
196 } else if (key == "MarginLeft") {
197 setMarginLeftVertical(value.toInt());
198
199 } else if (key == "MarginTop") {
200 setMarginTopVertical(value.toInt());
201
202 } else if (key == "MarginRight") {
203 setMarginRightVertical(value.toInt());
204
205 } else if (key == "MarginBottom") {
206 setMarginBottomVertical(value.toInt());
207
208 } else if (key == "horizontalTileMode") {
209 setHorizontalTileModeVertical(value);
210
211 } else if (key == "verticalTileMode") {
212 setVerticalTileModeVertical(value);
213
214 } else if (key == "InputStringPosX") {
215 setInputStringPosXVertical(value.toInt());
216
217 } else if (key == "InputStringPosY") {
218 setInputStringPosYVertical(value.toInt());
219
220 } else if (key == "OutputCandPosX") {
221 setOutputCandPosXVertical(value.toInt());
222
223 } else if (key == "OutputCandPosY") {
224 setOutputCandPosYVertical(value.toInt());
225
226 } else if (key == "BackArrowPosX") {
227 setBackArrowPosXVertical(value.toInt());
228
229 } else if (key == "BackArrowPosY") {
230 setBackArrowPosYVertical(value.toInt());
231
232 } else if (key == "ForwardArrowPosX") {
233 setForwardArrowPosXVertical(value.toInt());
234
235 } else if (key == "ForwardArrowPosY") {
236 setForwardArrowPosYVertical(value.toInt());
237
238 } else if (key == "BackArrow") {
239 setBackArrowImgVertical("file:/" + skinPath + value);
240
241 } else if (key == "ForwardArrow") {
242 setForwardArrowImgVertical("file:/" + skinPath + value);
243
244 }
245 }
246 } while (!line.isNull());
247
248 fcitxSkinConfFile.close();
249 return true;
250 }
251