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
|
// Copyright 2010-2021 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
#include "OverlayUser.h"
#include "Channel.h"
#include "ClientUser.h"
#include "Database.h"
#include "MainWindow.h"
#include "Message.h"
#include "NetworkConfig.h"
#include "OverlayText.h"
#include "ServerHandler.h"
#include "User.h"
#include "Utils.h"
#include "GlobalShortcut.h"
#include "Global.h"
#include <QtGui/QImageReader>
OverlayUser::OverlayUser(ClientUser *cu, unsigned int height, OverlaySettings *osptr)
: OverlayGroup(), os(osptr), uiSize(height), cuUser(cu), tsColor(Settings::Passive) {
setup();
updateLayout();
}
OverlayUser::OverlayUser(Settings::TalkState ts, unsigned int height, OverlaySettings *osptr)
: OverlayGroup(), os(osptr), uiSize(height), cuUser(nullptr), tsColor(ts) {
qsChannelName = Overlay::tr("Channel");
setup();
updateLayout();
}
int OverlayUser::type() const {
return Type;
}
void OverlayUser::setup() {
qgpiMuted = new QGraphicsPixmapItem(this);
qgpiMuted->hide();
qgpiDeafened = new QGraphicsPixmapItem(this);
qgpiDeafened->hide();
qgpiAvatar = new QGraphicsPixmapItem(this);
for (int i = 0; i < 4; ++i) {
qgpiName[i] = new QGraphicsPixmapItem(this);
qgpiName[i]->hide();
}
qgpiChannel = new QGraphicsPixmapItem(this);
qgpiChannel->hide();
qgpiBox = new QGraphicsPathItem(this);
qgpiBox->hide();
}
#undef SCALESIZE
#define SCALESIZE(var) \
iroundf(uiSize * os->fZoom * os->qrf##var.width() + 0.5f), \
iroundf(uiSize * os->fZoom * os->qrf##var.height() + 0.5f)
void OverlayUser::updateLayout() {
QPixmap pm;
if (scene())
uiSize = iroundf(scene()->sceneRect().height() + 0.5);
prepareGeometryChange();
for (int i = 0; i < 4; ++i)
qgpiName[i]->setPixmap(pm);
qgpiAvatar->setPixmap(pm);
qgpiChannel->setPixmap(pm);
{
QImageReader qir(QLatin1String("skin:muted_self.svg"));
QSize sz = qir.size();
sz.scale(SCALESIZE(MutedDeafened), Qt::KeepAspectRatio);
qir.setScaledSize(sz);
qgpiMuted->setPixmap(QPixmap::fromImage(qir.read()));
}
{
QImageReader qir(QLatin1String("skin:deafened_self.svg"));
QSize sz = qir.size();
sz.scale(SCALESIZE(MutedDeafened), Qt::KeepAspectRatio);
qir.setScaledSize(sz);
qgpiDeafened->setPixmap(QPixmap::fromImage(qir.read()));
}
qgpiMuted->setPos(alignedPosition(scaledRect(os->qrfMutedDeafened, uiSize * os->fZoom), qgpiMuted->boundingRect(),
os->qaMutedDeafened));
qgpiMuted->setZValue(1.0f);
qgpiMuted->setOpacity(os->fMutedDeafened);
qgpiDeafened->setPos(alignedPosition(scaledRect(os->qrfMutedDeafened, uiSize * os->fZoom),
qgpiDeafened->boundingRect(), os->qaMutedDeafened));
qgpiDeafened->setZValue(1.0f);
qgpiDeafened->setOpacity(os->fMutedDeafened);
qgpiAvatar->setPos(0.0f, 0.0f);
qgpiAvatar->setOpacity(os->fAvatar);
for (int i = 0; i < 4; ++i) {
qgpiName[i]->setPos(0.0f, 0.0f);
qgpiName[i]->setZValue(2.0f);
qgpiName[i]->setOpacity(os->fUserName);
}
qgpiChannel->setPos(0.0f, 0.0f);
qgpiChannel->setZValue(3.0f);
qgpiChannel->setOpacity(os->fChannel);
QRectF childrenBounds = os->qrfAvatar | os->qrfChannel | os->qrfMutedDeafened | os->qrfUserName;
bool haspen =
(os->qcBoxPen != os->qcBoxFill) && (!qFuzzyCompare(os->qcBoxPen.alphaF(), static_cast< qreal >(0.0f)));
qreal pw = haspen ? qMax< qreal >(1.0f, os->fBoxPenWidth * uiSize * os->fZoom) : 0.0f;
qreal pad = os->fBoxPad * uiSize * os->fZoom;
QPainterPath pp;
pp.addRoundedRect(childrenBounds.x() * uiSize * os->fZoom + -pw / 2.0f - pad,
childrenBounds.y() * uiSize * os->fZoom + -pw / 2.0f - pad,
childrenBounds.width() * uiSize * os->fZoom + pw + 2.0f * pad,
childrenBounds.height() * uiSize * os->fZoom + pw + 2.0f * pad, 2.0f * pw, 2.0f * pw);
qgpiBox->setPath(pp);
qgpiBox->setPos(0.0f, 0.0f);
qgpiBox->setZValue(-1.0f);
qgpiBox->setPen(haspen ? QPen(os->qcBoxPen, pw) : Qt::NoPen);
qgpiBox->setBrush(qFuzzyCompare(os->qcBoxFill.alphaF(), static_cast< qreal >(0.0f)) ? Qt::NoBrush : os->qcBoxFill);
qgpiBox->setOpacity(1.0f);
if (!cuUser) {
switch (tsColor) {
case Settings::Passive:
qsName = Overlay::tr("Silent");
break;
case Settings::Talking:
qsName = Overlay::tr("Talking");
break;
case Settings::MutedTalking:
qsName = QObject::tr("Talking (muted)");
break;
case Settings::Whispering:
qsName = Overlay::tr("Whisper");
break;
case Settings::Shouting:
qsName = Overlay::tr("Shout");
break;
}
}
}
void OverlayUser::updateUser() {
if (os->bUserName && (qgpiName[0]->pixmap().isNull() || (cuUser && (qsName != cuUser->qsName)))) {
if (cuUser)
qsName = cuUser->qsName;
OverlayTextLine tl(qsName, os->qfUserName);
for (int i = 0; i < 4; ++i) {
const QPixmap &pm = tl.createPixmap(SCALESIZE(UserName), os->qcUserName[i]);
qgpiName[i]->setPixmap(pm);
if (i == 0)
qgpiName[0]->setPos(alignedPosition(scaledRect(os->qrfUserName, uiSize * os->fZoom),
qgpiName[0]->boundingRect(), os->qaUserName));
else
qgpiName[i]->setPos(qgpiName[0]->pos());
}
}
if (os->bChannel && (qgpiChannel->pixmap().isNull() || (cuUser && (qsChannelName != cuUser->cChannel->qsName)))) {
if (cuUser)
qsChannelName = cuUser->cChannel->qsName;
const QPixmap &pm =
OverlayTextLine(qsChannelName, os->qfChannel).createPixmap(SCALESIZE(Channel), os->qcChannel);
qgpiChannel->setPixmap(pm);
qgpiChannel->setPos(alignedPosition(scaledRect(os->qrfChannel, uiSize * os->fZoom), qgpiChannel->boundingRect(),
os->qaChannel));
}
if (os->bAvatar && (qgpiAvatar->pixmap().isNull() || (cuUser && (qbaAvatar != cuUser->qbaTextureHash)))) {
if (cuUser)
qbaAvatar = cuUser->qbaTextureHash;
QImage img;
if (!qbaAvatar.isNull() && cuUser->qbaTexture.isEmpty()) {
Global::get().o->requestTexture(cuUser);
} else if (qbaAvatar.isNull()) {
QImageReader qir(QLatin1String("skin:default_avatar.svg"));
QSize sz = qir.size();
sz.scale(SCALESIZE(Avatar), Qt::KeepAspectRatio);
qir.setScaledSize(sz);
img = qir.read();
} else {
QBuffer qb(&cuUser->qbaTexture);
qb.open(QIODevice::ReadOnly);
QImageReader qir(&qb, cuUser->qbaTextureFormat);
QSize sz = qir.size();
sz.scale(SCALESIZE(Avatar), Qt::KeepAspectRatio);
qir.setScaledSize(sz);
img = qir.read();
}
qgpiAvatar->setPixmap(QPixmap::fromImage(img));
qgpiAvatar->setPos(
alignedPosition(scaledRect(os->qrfAvatar, uiSize * os->fZoom), qgpiAvatar->boundingRect(), os->qaAvatar));
}
qgpiAvatar->setVisible(os->bAvatar);
if (cuUser) {
ClientUser *self = ClientUser::get(Global::get().uiSession);
if (os->bMutedDeafened) {
if (cuUser->bDeaf || cuUser->bSelfDeaf) {
qgpiMuted->hide();
qgpiDeafened->show();
} else if (cuUser->bMute || cuUser->bSelfMute || cuUser->bLocalMute || cuUser->bSuppress) {
qgpiMuted->show();
qgpiDeafened->hide();
} else {
qgpiMuted->hide();
qgpiDeafened->hide();
}
} else {
qgpiMuted->hide();
qgpiDeafened->hide();
}
bool samechannel = self && (self->cChannel == cuUser->cChannel);
qgpiChannel->setVisible(os->bChannel && !samechannel);
tsColor = cuUser->tsState;
} else {
qgpiChannel->setVisible(os->bChannel && (tsColor != Settings::Passive) && (tsColor != Settings::Talking));
qgpiMuted->setVisible(os->bChannel);
qgpiDeafened->hide();
}
if (os->bUserName)
for (int i = 0; i < 4; ++i)
qgpiName[i]->setVisible(i == tsColor);
else
for (int i = 0; i < 4; ++i)
qgpiName[i]->setVisible(false);
qgpiBox->setVisible(os->bBox);
setOpacity(os->fUser[tsColor]);
}
QRectF OverlayUser::scaledRect(const QRectF &qr, qreal scale) {
return QRectF(qr.x() * scale, qr.y() * scale, qr.width() * scale, qr.height() * scale);
}
QPointF OverlayUser::alignedPosition(const QRectF &box, const QRectF &item, Qt::Alignment a) {
qreal boxw = box.width();
qreal boxh = box.height();
qreal itemw = item.width();
qreal itemh = item.height();
qreal wdiff = boxw - itemw;
qreal hdiff = boxh - itemh;
qreal xofs = box.x() - item.x();
qreal yofs = box.y() - item.y();
if (a & Qt::AlignRight)
xofs += wdiff;
else if (a & Qt::AlignHCenter)
xofs += wdiff * 0.5f;
if (a & Qt::AlignBottom)
yofs += hdiff;
else if (a & Qt::AlignVCenter)
yofs += hdiff * 0.5f;
return QPointF(iroundf(xofs + 0.5f), iroundf(yofs + 0.5f));
}
|