1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
/*
* Qt UI
*
* Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact:
* GiWoong Kim <giwoong.kim@samsung.com>
* Sangho Park <sangho1206.park@samsung.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
* Contributors:
* - S-Core Co., Ltd
*
*/
#include "uiinformation.h"
#include "resource/ui_strings.h"
UiInformation::UiInformation() :
basePort(0)
{
this->resolution = QSize(0, 0);
this->vmDataPath = "./";
this->skinPath = "./";
}
void UiInformation::setVmName(QString name) { vmName = name; }
QString UiInformation::getVmName() { return vmName; }
void UiInformation::setResolution(QSize size) { resolution = size; }
QSize UiInformation::getResolution() { return resolution; }
void UiInformation::setBasePort(int port) { basePort = port; }
int UiInformation::getBasePort() { return basePort; }
void UiInformation::setVmDataPath(QString path) { vmDataPath = path; }
QString UiInformation::getVmDataPath() { return vmDataPath; }
void UiInformation::setSkinPath(QString path) { skinPath = path; }
QString UiInformation::getSkinPath() { return skinPath; }
void UiInformation::setSkinName(QString name) { skinName = name; }
QString UiInformation::getSkinName() { return skinName; }
QList<MainForm *> &UiInformation::getMainFormList()
{
return mainFormList;
}
QList<ControllerForm *> &UiInformation::getConFormList()
{
return conFormList;
}
QList<MenuItem *> &UiInformation::getMenuList()
{
return menuList;
}
UIState *UiInformation::getUiState()
{
return &uiState;
}
QColor UiInformation::getVMColor()
{
if (basePort <= 0) {
qWarning() << "invalid base port:" << basePort;
return QColor(255, 0, 0);
}
switch((basePort / 10) % 10) {
case 0:
break;
case 1:
return QColor(246, 226, 0);
case 2:
return QColor(0, 246, 12);
case 3:
return QColor(168, 43, 255);
case 4:
return QColor(246, 110, 0);
case 5:
return QColor(245, 48, 233);
case 6:
return QColor(94, 73, 255);
case 7:
return QColor(179, 246, 0);
case 8:
return QColor(245, 48, 48);
case 9:
return QColor(29, 223, 221);
}
return QColor(0, 174, 239);
}
/* form */
MainForm *UiInformation::getMainForm()
{
int index = uiState.getMainFormIndex();
if (index > (mainFormList.count() - 1) || index < 0) {
qWarning("invalid form found");
uiState.setMainFormIndex(0);
index = uiState.getMainFormIndex();
}
MainForm *mainForm = mainFormList.at(index);
if (mainForm == NULL) {
qFatal(MSG_INVALID_MAIN_FORM);
}
return mainForm;
}
DisplayType *UiInformation::getMainFormDpyType()
{
return getMainForm()->getDpyType();
}
ControllerForm *UiInformation::getConForm()
{
int index = uiState.getConState()->getConFormIndex();
if (index > (conFormList.count() - 1) || index < 0) {
qWarning("invalid form found");
return NULL;
}
return conFormList.at(index);
}
/* size */
QSize UiInformation::getMainSize()
{
return getMainForm()->
skinImg[LayoutForm::normal].size() * uiState.getScaleFactor();
}
QSize UiInformation::getConSize()
{
ControllerForm *conForm = getConForm();
if (conForm == NULL) {
qWarning("controller form is null");
return QSize(0, 0);
}
return conForm->skinImg[LayoutForm::normal].size();
}
QSize UiInformation::getUiSize()
{
QSize uiSize = getMainSize();
/* docking controller */
if (uiState.getConState()->getDockingCon() != NULL) {
QSize conSize = getConSize();
uiSize.setWidth(uiSize.width() + conSize.width());
uiSize.setHeight(qMax(uiSize.height(), conSize.height()));
}
return uiSize;
}
/* region */
QRegion UiInformation::getMainRegion()
{
QImage *mainImage = &(getMainForm()->skinImg[LayoutForm::normal]);
QImage regionImage = mainImage->scaled(
mainImage->width() * uiState.getScaleFactor(),
mainImage->height() * uiState.getScaleFactor()).createAlphaMask();
return QRegion(QBitmap::fromImage(regionImage));
}
QRegion UiInformation::getConRegion()
{
ControllerForm *conForm = getConForm();
if (conForm == NULL) {
qWarning("controller form is null");
return QRegion(0, 0, 0, 0);
}
QImage *conImage = &(conForm->skinImg[LayoutForm::normal]);
return QRegion(QBitmap::fromImage(conImage->createAlphaMask()));
}
QRegion UiInformation::getUiRegion()
{
QRegion uiRegion = getMainRegion();
/* docking controller */
DockingController *con = uiState.getConState()->getDockingCon();
if (con != NULL) {
QRegion conRegion = getConRegion();
int vShift = 0;
if (getMainSize().height() > getConSize().height()) {
if (con->getDockPos() & Qt::AlignCenter) {
vShift = (getMainSize().height() - getConSize().height()) / 2;
} else if (con->getDockPos() & Qt::AlignBottom) {
vShift = getMainSize().height() - getConSize().height();
}
}
conRegion.translate(getMainSize().width() + 1, vShift);
uiRegion = uiRegion.united(conRegion);
}
return uiRegion;
}
QRegion UiInformation::getMainKeyRegion(
QWidget *base, QRect &keyRect, LayoutForm::SkinImgType type)
{
QRegion baseRegion = base->mask().subtracted(QRect(
keyRect.topLeft() * uiState.getScaleFactor(),
keyRect.size() * uiState.getScaleFactor()));
// FIXME: clear key rectangle region
base->setMask(baseRegion);
QImage keyImage = getMainForm()->skinImg[type].copy(keyRect);
QImage regionImage = keyImage.scaled(
keyImage.width() * uiState.getScaleFactor(),
keyImage.height() * uiState.getScaleFactor()).createAlphaMask();
QRegion keyRegion(QBitmap::fromImage(regionImage));
keyRegion.translate(keyRect.topLeft() * uiState.getScaleFactor());
return baseRegion.united(keyRegion);
}
QRegion UiInformation::getConKeyRegion(
QWidget *base, QRect &keyRect, LayoutForm::SkinImgType type)
{
if (getConForm() == NULL) {
qWarning("controller form is null");
return QRegion();
}
if (getConForm()->skinImg[type].size() == QSize(0, 0)) {
qWarning("invalid controller image");
return QRegion();
}
QRegion baseRegion;
QRegion keyRegion;
if (uiState.getConState()->getDockingCon() != NULL) {
/* docking controller */
const int shiftW = getMainSize().width();
baseRegion = getUiRegion().subtracted(QRect(
keyRect.x() + shiftW, keyRect.y(),
keyRect.width(), keyRect.height()));
QImage keyImage = getConForm()->skinImg[type].copy(keyRect);
keyRegion = QRegion(QBitmap::fromImage(keyImage.createAlphaMask()));
keyRegion.translate(keyRect.left() + shiftW, keyRect.top());
} else {
baseRegion = base->mask().subtracted(QRect(
keyRect.x(), keyRect.y(), keyRect.width(), keyRect.height()));
QImage keyImage = getConForm()->skinImg[type].copy(keyRect);
keyRegion = QRegion(QBitmap::fromImage(keyImage.createAlphaMask()));
keyRegion.translate(keyRect.left(), keyRect.top());
}
return baseRegion.united(keyRegion);
}
UiInformation::~UiInformation()
{
qDebug("destroy UI info");
for (int i = 0; i < mainFormList.count(); i++) {
delete mainFormList.at(i);
}
mainFormList.clear();
for (int i = 0; i < conFormList.count(); i++) {
delete conFormList.at(i);
}
conFormList.clear();
for (int i = 0; i < menuList.count(); i++) {
delete menuList.at(i);
}
menuList.clear();
}
|