use qt round for better cross platform consistency (#4518)
* use qt round for better cross platform consistency * remove unnecessary casts
This commit is contained in:
parent
4d6c9ede8c
commit
6981cca2ae
7 changed files with 32 additions and 64 deletions
|
@ -1,19 +1,17 @@
|
|||
#include <QCursor>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#ifdef _WIN32
|
||||
#include "round.h"
|
||||
#endif /* _WIN32 */
|
||||
#include "abstractcarditem.h"
|
||||
|
||||
#include "carddatabase.h"
|
||||
#include "gamescene.h"
|
||||
#include "main.h"
|
||||
#include "pictureloader.h"
|
||||
#include "settingscache.h"
|
||||
|
||||
#include <QCursor>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <algorithm>
|
||||
|
||||
AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, int _id, QGraphicsItem *parent)
|
||||
: ArrowTarget(_owner, parent), id(_id), name(_name), tapped(false), facedown(false), tapAngle(0),
|
||||
bgColor(Qt::transparent), isHovered(false), realZValue(0)
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
#include "phasestoolbar.h"
|
||||
|
||||
#include "pb/command_draw_cards.pb.h"
|
||||
#include "pb/command_next_turn.pb.h"
|
||||
#include "pb/command_set_active_phase.pb.h"
|
||||
#include "pb/command_set_card_attr.pb.h"
|
||||
#include "pixmapgenerator.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
#include <QTimer>
|
||||
#include <cmath>
|
||||
#ifdef _WIN32
|
||||
#include "round.h"
|
||||
#endif /* _WIN32 */
|
||||
#include "pb/command_draw_cards.pb.h"
|
||||
#include "pb/command_next_turn.pb.h"
|
||||
#include "pb/command_set_active_phase.pb.h"
|
||||
#include "pb/command_set_card_attr.pb.h"
|
||||
#include "phasestoolbar.h"
|
||||
#include "pixmapgenerator.h"
|
||||
|
||||
PhaseButton::PhaseButton(const QString &_name, QGraphicsItem *parent, QAction *_doubleClickAction, bool _highlightable)
|
||||
: QObject(), QGraphicsItem(parent), name(_name), active(false), highlightable(_highlightable),
|
||||
|
@ -38,8 +36,7 @@ void PhaseButton::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*op
|
|||
QRectF iconRect = boundingRect().adjusted(3, 3, -3, -3);
|
||||
QRectF translatedIconRect = painter->combinedTransform().mapRect(iconRect);
|
||||
qreal scaleFactor = translatedIconRect.width() / iconRect.width();
|
||||
QPixmap iconPixmap =
|
||||
PhasePixmapGenerator::generatePixmap(static_cast<int>(round(translatedIconRect.height())), name);
|
||||
QPixmap iconPixmap = PhasePixmapGenerator::generatePixmap(qRound(translatedIconRect.height()), name);
|
||||
|
||||
painter->setBrush(QColor(static_cast<int>(220 * (activeAnimationCounter / 10.0)),
|
||||
static_cast<int>(220 * (activeAnimationCounter / 10.0)),
|
||||
|
@ -48,9 +45,8 @@ void PhaseButton::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*op
|
|||
painter->drawRect(0, 0, static_cast<int>(width - 1), static_cast<int>(width - 1));
|
||||
painter->save();
|
||||
resetPainterTransform(painter);
|
||||
painter->drawPixmap(iconPixmap.rect().translated(static_cast<int>(round(3 * scaleFactor)),
|
||||
static_cast<int>(round(3 * scaleFactor))),
|
||||
iconPixmap, iconPixmap.rect());
|
||||
painter->drawPixmap(iconPixmap.rect().translated(qRound(3 * scaleFactor), qRound(3 * scaleFactor)), iconPixmap,
|
||||
iconPixmap.rect());
|
||||
painter->restore();
|
||||
|
||||
painter->setBrush(QColor(0, 0, 0, static_cast<int>(255 * ((10 - activeAnimationCounter) / 15.0))));
|
||||
|
|
|
@ -3,13 +3,9 @@
|
|||
#include "pb/serverinfo_user.pb.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QPalette>
|
||||
#include <cmath>
|
||||
#ifdef _WIN32
|
||||
#include "round.h"
|
||||
#endif /* _WIN32 */
|
||||
#include <QDebug>
|
||||
|
||||
QMap<QString, QPixmap> PhasePixmapGenerator::pmCache;
|
||||
|
||||
|
|
|
@ -7,10 +7,7 @@
|
|||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QPixmapCache>
|
||||
#include <cmath>
|
||||
#ifdef _WIN32
|
||||
#include "round.h"
|
||||
#endif /* _WIN32 */
|
||||
#include <QtMath>
|
||||
|
||||
PlayerCounter::PlayerCounter(Player *_player,
|
||||
int _id,
|
||||
|
@ -49,7 +46,7 @@ void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*
|
|||
QSize translatedSize = translatedRect.size().toSize();
|
||||
QFont font("Serif");
|
||||
font.setWeight(QFont::Bold);
|
||||
font.setPixelSize(qMax((int)round(translatedSize.height() / 1.3), 9));
|
||||
font.setPixelSize(qMax(qRound(translatedSize.height() / 1.3), 9));
|
||||
painter->setFont(font);
|
||||
painter->setPen(Qt::white);
|
||||
painter->drawText(translatedRect, Qt::AlignCenter, QString::number(value));
|
||||
|
@ -96,9 +93,9 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o
|
|||
QPainter tempPainter(&cachedPixmap);
|
||||
// pow(foo, 0.5) equals to sqrt(foo), but using sqrt(foo) in this context will produce a compile error with
|
||||
// MSVC++
|
||||
QRadialGradient grad(translatedRect.center(), pow(translatedSize.width() * translatedSize.width() +
|
||||
translatedSize.height() * translatedSize.height(),
|
||||
0.5) /
|
||||
QRadialGradient grad(translatedRect.center(), qPow(translatedSize.width() * translatedSize.width() +
|
||||
translatedSize.height() * translatedSize.height(),
|
||||
0.5) /
|
||||
2);
|
||||
grad.setColorAt(1, Qt::black);
|
||||
grad.setColorAt(0, QColor(180, 180, 180));
|
||||
|
@ -135,7 +132,7 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o
|
|||
name = name.mid(0, 10) + "...";
|
||||
|
||||
QFont font;
|
||||
font.setPixelSize(qMax((int)round(translatedNameRect.height() / 1.5), 9));
|
||||
font.setPixelSize(qMax(qRound(translatedNameRect.height() / 1.5), 9));
|
||||
painter->setFont(font);
|
||||
painter->setPen(Qt::white);
|
||||
painter->drawText(translatedNameRect, Qt::AlignVCenter | Qt::AlignLeft, " " + name);
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include <QPainterPath>
|
||||
#include <QPalette>
|
||||
#include <QTimer>
|
||||
#include <cmath>
|
||||
#ifdef _WIN32
|
||||
#include "round.h"
|
||||
#endif /* _WIN32 */
|
||||
|
||||
ReplayTimelineWidget::ReplayTimelineWidget(QWidget *parent)
|
||||
: QWidget(parent), maxBinValue(1), maxTime(1), timeScaleFactor(1.0), currentTime(0), currentEvent(0)
|
||||
|
@ -54,7 +50,7 @@ void ReplayTimelineWidget::paintEvent(QPaintEvent * /* event */)
|
|||
QPainterPath path;
|
||||
path.moveTo(0, height() - 1);
|
||||
for (int i = 0; i < histogram.size(); ++i)
|
||||
path.lineTo(round(i * binWidth), (height() - 1) * (1.0 - (qreal)histogram[i] / maxBinValue));
|
||||
path.lineTo(qRound(i * binWidth), (height() - 1) * (1.0 - (qreal)histogram[i] / maxBinValue));
|
||||
path.lineTo(width() - 1, height() - 1);
|
||||
path.lineTo(0, height() - 1);
|
||||
painter.fillPath(path, Qt::black);
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
#ifndef MSVC_ROUND_FIX
|
||||
#define MSVC_ROUND_FIX
|
||||
/**
|
||||
* This helper function exists only because MS VC++ 2010 does not support round() in
|
||||
* <cmath>. round() works with g++ and clang++ but is formally a C++11 extension.
|
||||
* So this file exists for MS VC++ only.
|
||||
*/
|
||||
inline double round(double val)
|
||||
{
|
||||
return floor(val + 0.5);
|
||||
}
|
||||
|
||||
#endif /* MSVC_ROUND_FIX */
|
|
@ -1,10 +1,5 @@
|
|||
#include <QGraphicsScene>
|
||||
#include <QPainter>
|
||||
#include <QSet>
|
||||
#include <cmath>
|
||||
#ifdef _WIN32
|
||||
#include "round.h"
|
||||
#endif /* _WIN32 */
|
||||
#include "tablezone.h"
|
||||
|
||||
#include "arrowitem.h"
|
||||
#include "carddatabase.h"
|
||||
#include "carddragitem.h"
|
||||
|
@ -13,9 +8,12 @@
|
|||
#include "pb/command_set_card_attr.pb.h"
|
||||
#include "player.h"
|
||||
#include "settingscache.h"
|
||||
#include "tablezone.h"
|
||||
#include "thememanager.h"
|
||||
|
||||
#include <QGraphicsScene>
|
||||
#include <QPainter>
|
||||
#include <QSet>
|
||||
|
||||
const QColor TableZone::BACKGROUND_COLOR = QColor(100, 100, 100);
|
||||
const QColor TableZone::FADE_MASK = QColor(0, 0, 0, 80);
|
||||
const QColor TableZone::GRADIENT_COLOR = QColor(255, 255, 255, 150);
|
||||
|
|
Loading…
Reference in a new issue