Skip to content
Permalink
Browse files

Fix overlay code related warnings in mumble

Apart from the usual shadow warnings and other spurious warnings
this code contained a lot of floating point conversions the compiler
was complaining about.

These are now either explicit or operate on double (whatever was
more convenient).

Even found a minor bug in OverlayClient::setupScene where the warning
indicated a typo in the rounding code.
  • Loading branch information...
hacst committed Oct 25, 2015
1 parent f9b2db4 commit e0cb6e0196303faf8c843cab53f03603cf2eabc7
@@ -47,7 +47,7 @@

OverlayClient::OverlayClient(QLocalSocket *socket, QObject *p)
: QObject(p)
, fFps(0)
, framesPerSecond(0)
, ougUsers(&g.s.os)
, iMouseX(0)
, iMouseY(0) {
@@ -125,7 +125,9 @@ bool OverlayClient::eventFilter(QObject *o, QEvent *e) {

void OverlayClient::updateFPS() {
if (g.s.os.bFps) {
const BasepointPixmap &pm = OverlayTextLine(QString(QLatin1String("%1")).arg(iroundf(fFps + 0.5f)), g.s.os.qfFps).createPixmap(g.s.os.qcFps);
const BasepointPixmap &pm = OverlayTextLine(
QString(QLatin1String("%1")).arg(iroundf(framesPerSecond + 0.5f)),
g.s.os.qfFps).createPixmap(g.s.os.qcFps);
qgpiFPS->setPixmap(pm);
// offset to use basepoint
//TODO: settings are providing a top left anchor, so shift down by ascent
@@ -280,8 +282,8 @@ void OverlayClient::showGui() {
}
}

QEvent event(QEvent::WindowActivate);
qApp->sendEvent(&qgs, &event);
QEvent activateEvent(QEvent::WindowActivate);
qApp->sendEvent(&qgs, &activateEvent);

QPoint p = QCursor::pos();
iMouseX = qBound<int>(0, p.x(), uiWidth-1);
@@ -444,7 +446,7 @@ void OverlayClient::readyReadMsgInit(unsigned int length) {

void OverlayClient::readyRead() {
while (true) {
unsigned int ready = qlsSocket->bytesAvailable();
quint64 ready = static_cast<quint64>(qlsSocket->bytesAvailable());

if (omMsg.omh.iLength == -1) {
if (ready < sizeof(OverlayMsgHeader)) {
@@ -460,7 +462,7 @@ void OverlayClient::readyRead() {
}

if (ready >= static_cast<unsigned int>(omMsg.omh.iLength)) {
int length = qlsSocket->read(omMsg.msgbuffer, omMsg.omh.iLength);
qint64 length = qlsSocket->read(omMsg.msgbuffer, omMsg.omh.iLength);

if (length != omMsg.omh.iLength) {
disconnect();
@@ -469,7 +471,7 @@ void OverlayClient::readyRead() {

switch (omMsg.omh.uiType) {
case OVERLAY_MSGTYPE_INIT: {
readyReadMsgInit(length);
readyReadMsgInit(static_cast<unsigned int>(length));
}
break;
case OVERLAY_MSGTYPE_SHMEM: {
@@ -478,7 +480,7 @@ void OverlayClient::readyRead() {
}
break;
case OVERLAY_MSGTYPE_PID: {
if (length != sizeof(OverlayMsgPid))
if (length != static_cast<qint64>(sizeof(OverlayMsgPid)))
break;

OverlayMsgPid *omp = & omMsg.omp;
@@ -502,7 +504,7 @@ void OverlayClient::readyRead() {
break;

OverlayMsgFps *omf = & omMsg.omf;
fFps = omf->fps;
framesPerSecond = omf->fps;
//qWarning() << "FPS: " << omf->fps;

Overlay *o = static_cast<Overlay *>(parent());
@@ -550,7 +552,7 @@ void OverlayClient::setupScene(bool show) {
qgpiLogo->setPixmap(QPixmap::fromImage(qir.read()));

QRectF qrf = qgpiLogo->boundingRect();
qgpiLogo->setPos(iroundf((uiWidth - qrf.width()) / 2.0f + 0.5f), iroundf((uiHeight - qrf.height()) / 2.0f) + 0.5f);
qgpiLogo->setPos(iroundf((uiWidth - qrf.width()) / 2.0f + 0.5f), iroundf((uiHeight - qrf.height()) / 2.0f + 0.5f));

}

@@ -57,7 +57,7 @@ class OverlayClient : public QObject {
QRect qrLast;
Timer t;

unsigned int fFps;
float framesPerSecond;
int iOffsetX, iOffsetY;
QGraphicsPixmapItem *qgpiCursor;
QGraphicsPixmapItem *qgpiLogo;
@@ -59,8 +59,10 @@ OverlayEditor::OverlayEditor(QWidget *p, QGraphicsItem *qgi, OverlaySettings *os
if (qgpw) {
qgpw->setFlag(QGraphicsItem::ItemIgnoresParentOpacity);
if (g.ocIntercept) {
qgpw->setPos(iroundf(g.ocIntercept->uiWidth / 16.0f + 0.5f), iroundf(g.ocIntercept->uiHeight / 16.0f + 0.5f));
qgpw->resize(iroundf(g.ocIntercept->uiWidth * 14.0f / 16.0f + 0.5f), iroundf(g.ocIntercept->uiHeight * 14.0f / 16.0f + 0.5f));
qgpw->setPos(iroundf(static_cast<float>(g.ocIntercept->uiWidth) / 16.0f + 0.5f),
iroundf(static_cast<float>(g.ocIntercept->uiHeight) / 16.0f + 0.5f));
qgpw->resize(iroundf(static_cast<float>(g.ocIntercept->uiWidth) * 14.0f / 16.0f + 0.5f),
iroundf(static_cast<float>(g.ocIntercept->uiHeight) * 14.0f / 16.0f + 0.5f));
}
}

@@ -77,7 +79,7 @@ OverlayEditor::~OverlayEditor() {
qgiPromote->setZValue(-1.0f);
}

void OverlayEditor::enterEvent(QEvent *event) {
void OverlayEditor::enterEvent(QEvent *e) {
QGraphicsProxyWidget *qgpw = g.mw->graphicsProxyWidget();
if (qgpw)
qgpw->setOpacity(0.9f);
@@ -89,10 +91,10 @@ void OverlayEditor::enterEvent(QEvent *event) {
if (qgiPromote)
qgiPromote->setZValue(-1.0f);

QDialog::enterEvent(event);
QDialog::enterEvent(e);
}

void OverlayEditor::leaveEvent(QEvent *event) {
void OverlayEditor::leaveEvent(QEvent *e) {
QGraphicsProxyWidget *qgpw = g.mw->graphicsProxyWidget();
if (qgpw)
qgpw->setOpacity(0.3f);
@@ -104,7 +106,7 @@ void OverlayEditor::leaveEvent(QEvent *event) {
if (qgiPromote)
qgiPromote->setZValue(1.0f);

QDialog::leaveEvent(event);
QDialog::leaveEvent(e);
}

void OverlayEditor::reset() {
@@ -45,8 +45,8 @@ class OverlayEditor : public QDialog, public Ui::OverlayEditor {
OverlayEditorScene oes;
OverlaySettings *os;

void enterEvent(QEvent *) Q_DECL_OVERRIDE;
void leaveEvent(QEvent *) Q_DECL_OVERRIDE;
void enterEvent(QEvent *e) Q_DECL_OVERRIDE;
void leaveEvent(QEvent *e) Q_DECL_OVERRIDE;
public:
OverlayEditor(QWidget *p = NULL, QGraphicsItem *qgi = NULL, OverlaySettings *osptr = NULL);
~OverlayEditor() Q_DECL_OVERRIDE;
@@ -176,14 +176,14 @@ void OverlayEditorScene::moveAvatar() {
}

void OverlayEditorScene::moveBox() {
QRectF children = os.qrfAvatar | os.qrfChannel | os.qrfMutedDeafened | os.qrfUserName;
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 * uiZoom) : 0.0f;
qreal pad = os.fBoxPad * uiSize * uiZoom;

QPainterPath pp;
pp.addRoundedRect(children.x() * uiSize * uiZoom + -pw / 2.0f - pad, children.y() * uiSize * uiZoom + -pw / 2.0f - pad, children.width() * uiSize * uiZoom + pw + 2.0f * pad, children.height() * uiSize * uiZoom + pw + 2.0f * pad, 2.0f * pw, 2.0f * pw);
pp.addRoundedRect(childrenBounds.x() * uiSize * uiZoom + -pw / 2.0f - pad, childrenBounds.y() * uiSize * uiZoom + -pw / 2.0f - pad, childrenBounds.width() * uiSize * uiZoom + pw + 2.0f * pad, childrenBounds.height() * uiSize * uiZoom + pw + 2.0f * pad, 2.0f * pw, 2.0f * pw);
qgpiBox->setPath(pp);
qgpiBox->setPos(0.0f, 0.0f);
qgpiBox->setPen(haspen ? QPen(os.qcBoxPen, pw) : Qt::NoPen);
@@ -235,14 +235,14 @@ void OverlayEditorScene::drawBackground(QPainter *p, const QRectF &rect) {
p->setBrushOrigin(0, 0);
p->fillRect(rect, backgroundBrush());

QRectF upscaled = OverlayUser::scaledRect(rect, 128.f / (uiSize * uiZoom));
QRectF upscaled = OverlayUser::scaledRect(rect, 128.f / static_cast<float>(uiSize * uiZoom));

{
int min = iroundf(upscaled.left());
int max = iroundf(ceil(upscaled.right()));

for (int i=min;i<=max;++i) {
qreal v = (i / 128.f) * uiSize * uiZoom;
qreal v = (i / 128) * static_cast<qreal>(uiSize * uiZoom);

if (i != 0)
p->setPen(QPen(QColor(128, 128, 128, 255), 0.0f));
@@ -258,7 +258,7 @@ void OverlayEditorScene::drawBackground(QPainter *p, const QRectF &rect) {
int max = iroundf(ceil(upscaled.bottom()));

for (int i=min;i<=max;++i) {
qreal v = (i / 128.f) * uiSize * uiZoom;
qreal v = (i / 128) * static_cast<qreal>(uiSize * uiZoom);

if (i != 0)
p->setPen(QPen(QColor(128, 128, 128, 255), 0.0f));
@@ -310,17 +310,17 @@ QRectF OverlayEditorScene::selectedRect() const {
}


void OverlayEditorScene::mousePressEvent(QGraphicsSceneMouseEvent *event) {
QGraphicsScene::mousePressEvent(event);
void OverlayEditorScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
QGraphicsScene::mousePressEvent(e);

if (event->isAccepted())
if (e->isAccepted())
return;

if (event->button() == Qt::LeftButton) {
event->accept();
if (e->button() == Qt::LeftButton) {
e->accept();

if (wfsHover == Qt::NoSection) {
qgpiSelected = childAt(event->scenePos());
qgpiSelected = childAt(e->scenePos());
if (qgpiSelected) {
qgriSelected->setRect(selectedRect());
qgriSelected->show();
@@ -329,18 +329,18 @@ void OverlayEditorScene::mousePressEvent(QGraphicsSceneMouseEvent *event) {
}
}

updateCursorShape(event->scenePos());
updateCursorShape(e->scenePos());
}
}

void OverlayEditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
QGraphicsScene::mouseReleaseEvent(event);
void OverlayEditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
QGraphicsScene::mouseReleaseEvent(e);

if (event->isAccepted())
if (e->isAccepted())
return;

if (event->button() == Qt::LeftButton) {
event->accept();
if (e->button() == Qt::LeftButton) {
e->accept();

QRectF rect = qgriSelected->rect();

@@ -368,21 +368,21 @@ void OverlayEditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
}
}

void OverlayEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
QGraphicsScene::mouseMoveEvent(event);
void OverlayEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
QGraphicsScene::mouseMoveEvent(e);

if (event->isAccepted())
if (e->isAccepted())
return;

if (qgpiSelected && (event->buttons() & Qt::LeftButton)) {
event->accept();
if (qgpiSelected && (e->buttons() & Qt::LeftButton)) {
e->accept();

if (wfsHover == Qt::NoSection)
return;

QPointF delta = event->scenePos() - event->buttonDownScenePos(Qt::LeftButton);
QPointF delta = e->scenePos() - e->buttonDownScenePos(Qt::LeftButton);

bool square = event->modifiers() & Qt::ShiftModifier;
bool square = e->modifiers() & Qt::ShiftModifier;

QRectF orig = selectedRect();
switch (wfsHover) {
@@ -472,7 +472,7 @@ void OverlayEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {

qgriSelected->setRect(orig);
} else {
updateCursorShape(event->scenePos());
updateCursorShape(e->scenePos());
}
}

@@ -529,18 +529,18 @@ void OverlayEditorScene::updateCursorShape(const QPointF &point) {
}
}

void OverlayEditorScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
QGraphicsScene::contextMenuEvent(event);
void OverlayEditorScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *e) {
QGraphicsScene::contextMenuEvent(e);

if (event->isAccepted())
if (e->isAccepted())
return;

if (! event->widget())
if (! e->widget())
return;

QGraphicsPixmapItem *item = childAt(event->scenePos());
QGraphicsPixmapItem *item = childAt(e->scenePos());

QMenu qm(event->widget());
QMenu qm(e->widget());

QMenu *qmLayout = qm.addMenu(tr("Layout preset"));
QAction *qaLayoutLargeAvatar = qmLayout->addAction(tr("Large square avatar"));
@@ -550,7 +550,7 @@ void OverlayEditorScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
QActionGroup *qagUser = new QActionGroup(&qm);
QAction *userOpacity[8];
for (int i=0;i<8;++i) {
qreal o = (i + 1) / 8.0f;
qreal o = (i + 1) / 8.0;

userOpacity[i] = new QAction(tr("%1%").arg(o * 100.0f, 0, 'f', 1), qagUser);
userOpacity[i]->setCheckable(true);
@@ -563,7 +563,7 @@ void OverlayEditorScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
}

QAction *color = NULL;
QAction *font = NULL;
QAction *fontAction = NULL;
QAction *objectOpacity[8];
for (int i=0;i<8;++i)
objectOpacity[i] = NULL;
@@ -581,7 +581,7 @@ void OverlayEditorScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
QMenu *qmObjTrans = qm.addMenu(tr("Object Opacity"));
QActionGroup *qagObject = new QActionGroup(&qm);
for (int i=0;i<8;++i) {
qreal o = (i + 1) / 8.0f;
qreal o = i + 1 / 8.0;

objectOpacity[i] = new QAction(tr("%1%").arg(o * 100.0f, 0, 'f', 1), qagObject);
objectOpacity[i]->setCheckable(true);
@@ -638,7 +638,7 @@ void OverlayEditorScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)

if ((item != qgpiAvatar) && (item != qgpiMuted)) {
color = qm.addAction(tr("Color..."));
font = qm.addAction(tr("Font..."));
fontAction = qm.addAction(tr("Font..."));
}
}

@@ -653,7 +653,7 @@ void OverlayEditorScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
QActionGroup *qagPen = new QActionGroup(qmPen);
QActionGroup *qagPad = new QActionGroup(qmPad);
for (int i=0;i<4;++i) {
qreal v = (i) ? powf(2.0f, -10 + i) : 0.0f;
qreal v = (i) ? powf(2.0f, static_cast<float>(-10 + i)) : 0.0f;
boxpen[i] = new QAction(QString::number(i), qagPen);
boxpen[i]->setData(v);
boxpen[i]->setCheckable(true);
@@ -670,14 +670,14 @@ void OverlayEditorScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
}
}

QAction *act = qm.exec(event->screenPos());
QAction *act = qm.exec(e->screenPos());

if (! act)
return;

for (int i=0;i<8;++i) {
if (userOpacity[i] == act) {
float o = act->data().toReal();
float o = static_cast<float>(act->data().toReal());
os.fUser[tsColor] = o;

qgiGroup->setOpacity(o);
@@ -735,13 +735,13 @@ void OverlayEditorScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
}

if (act == boxpencolor) {
QColor qc = QColorDialog::getColor(os.qcBoxPen, event->widget(), tr("Pick pen color"), QColorDialog::DontUseNativeDialog | QColorDialog::ShowAlphaChannel);
QColor qc = QColorDialog::getColor(os.qcBoxPen, e->widget(), tr("Pick pen color"), QColorDialog::DontUseNativeDialog | QColorDialog::ShowAlphaChannel);
if (! qc.isValid())
return;
os.qcBoxPen = qc;
moveBox();
} else if (act == boxfillcolor) {
QColor qc = QColorDialog::getColor(os.qcBoxFill, event->widget(), tr("Pick fill color"), QColorDialog::DontUseNativeDialog | QColorDialog::ShowAlphaChannel);
QColor qc = QColorDialog::getColor(os.qcBoxFill, e->widget(), tr("Pick fill color"), QColorDialog::DontUseNativeDialog | QColorDialog::ShowAlphaChannel);
if (! qc.isValid())
return;
os.qcBoxFill = qc;
@@ -755,7 +755,7 @@ void OverlayEditorScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
if (! col)
return;

QColor qc = QColorDialog::getColor(*col, event->widget(), tr("Pick color"), QColorDialog::DontUseNativeDialog);
QColor qc = QColorDialog::getColor(*col, e->widget(), tr("Pick color"), QColorDialog::DontUseNativeDialog);
if (! qc.isValid())
return;
qc.setAlpha(255);
@@ -765,7 +765,7 @@ void OverlayEditorScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)

*col = qc;
updateSelected();
} else if (act == font) {
} else if (act == fontAction) {
QFont *fontptr = (item == qgpiChannel) ? &os.qfChannel : &os.qfUserName;

qgpiSelected = NULL;

0 comments on commit e0cb6e0

Please sign in to comment.
You can’t perform that action at this time.