From c327076817dad875bd057bf28eab36b1d4e732ef Mon Sep 17 00:00:00 2001 From: Aleksandar Sasha Babic Date: Tue, 10 Nov 2009 21:02:35 +0100 Subject: Revert "Check that we're not using double where qreal should be used" This reverts commit d9a275b3cc4a248da1f392fb5649b9fe7a93b12c. --- src/gui/styles/qs60style.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index f15a6a5..16a81b3 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -1723,7 +1723,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, optionMenuItem.palette.setColor(QPalette::Disabled, QPalette::Text, QS60StylePrivate::lighterColor( optionMenuItem.palette.color(QPalette::Disabled, QPalette::Text))); painter->save(); - painter->setOpacity(qreal(0.75)); + painter->setOpacity(0.5); } QCommonStyle::drawItemText(painter, textRect, text_flags, optionMenuItem.palette, enabled, @@ -1829,7 +1829,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, painter->save(); if (widget) painter->setBrush(widget->palette().button()); - painter->setOpacity(qreal(0.3)); + painter->setOpacity(0.3); painter->fillRect(toolBar->rect, painter->brush()); painter->restore(); } -- cgit v0.12 From 72c170b64056a59dce9f849a5789d2968071f7b9 Mon Sep 17 00:00:00 2001 From: Aleksandar Sasha Babic Date: Tue, 10 Nov 2009 21:04:41 +0100 Subject: Revert "Using qreal more consistently in code (prevent misuse of double)" This reverts commit 676780d515cedca85829ae962e4f501c5e5b6581. Conflicts: src/gui/painting/qblendfunctions.cpp --- mkspecs/common/symbian/symbian.conf | 2 +- src/3rdparty/easing/easing.cpp | 180 ++++++++++++------------ src/corelib/global/qglobal.h | 4 +- src/corelib/global/qnumeric_p.h | 6 - src/corelib/kernel/qmath.h | 45 ++---- src/corelib/tools/qdatetime.cpp | 2 +- src/corelib/tools/qeasingcurve.cpp | 20 +-- src/corelib/tools/qline.cpp | 12 +- src/gui/graphicsview/qgraphicsitem.cpp | 3 +- src/gui/graphicsview/qgraphicsitemanimation.cpp | 18 +-- src/gui/graphicsview/qgraphicsscene.cpp | 6 +- src/gui/graphicsview/qgraphicsview.cpp | 2 +- src/gui/graphicsview/qgraphicswidget_p.cpp | 6 +- src/gui/graphicsview/qgridlayoutengine.cpp | 88 ++++++------ src/gui/graphicsview/qsimplex_p.cpp | 4 +- src/gui/image/qimage.cpp | 30 ++-- src/gui/image/qpaintengine_pic.cpp | 4 +- src/gui/image/qpicture.cpp | 4 +- src/gui/image/qpixmap_raster.cpp | 4 +- src/gui/image/qpixmap_s60.cpp | 9 +- src/gui/image/qpnghandler.cpp | 4 +- src/gui/math3d/qmatrix4x4.cpp | 145 +++++++++---------- src/gui/math3d/qquaternion.cpp | 29 ++-- src/gui/math3d/qvector2d.cpp | 6 +- src/gui/math3d/qvector3d.cpp | 8 +- src/gui/math3d/qvector4d.cpp | 16 +-- src/gui/painting/qbezier.cpp | 104 +++++++------- src/gui/painting/qbezier_p.h | 45 +++--- src/gui/painting/qblendfunctions.cpp | 18 ++- src/gui/painting/qbrush.cpp | 2 +- src/gui/painting/qcolor.cpp | 89 ++++++------ src/gui/painting/qdrawhelper.cpp | 111 ++++++++------- src/gui/painting/qdrawutil.cpp | 70 +++++---- src/gui/painting/qmath_p.h | 5 +- src/gui/painting/qpaintbuffer.cpp | 2 +- src/gui/painting/qpaintengine_raster.cpp | 32 ++--- src/gui/painting/qpaintengineex.cpp | 13 +- src/gui/painting/qpainter.cpp | 27 ++-- src/gui/painting/qpainterpath.cpp | 27 ++-- src/gui/painting/qpainterpath_p.h | 2 +- src/gui/painting/qpathclipper.cpp | 18 +-- src/gui/painting/qrasterizer.cpp | 32 ++--- src/gui/painting/qstroker.cpp | 25 ++-- src/gui/painting/qstroker_p.h | 2 +- src/gui/painting/qtransform.cpp | 27 ++-- src/gui/styles/qcommonstyle.cpp | 17 ++- src/gui/styles/qs60style.cpp | 16 +-- src/gui/styles/qstyle.cpp | 2 +- src/gui/styles/qstylehelper.cpp | 26 ++-- src/gui/styles/qstylesheetstyle.cpp | 8 +- src/gui/text/qfont.cpp | 6 +- src/gui/text/qfontdatabase.cpp | 6 +- src/svg/qsvggenerator.cpp | 9 +- src/svg/qsvggraphics.cpp | 11 +- src/svg/qsvghandler.cpp | 73 +++++----- src/svg/qsvgtinydocument.cpp | 13 +- 56 files changed, 710 insertions(+), 785 deletions(-) diff --git a/mkspecs/common/symbian/symbian.conf b/mkspecs/common/symbian/symbian.conf index 0f06b92..79bac42 100644 --- a/mkspecs/common/symbian/symbian.conf +++ b/mkspecs/common/symbian/symbian.conf @@ -7,7 +7,7 @@ CONFIG += qt warn_on release incremental QT += core gui QMAKE_INCREMENTAL_STYLE = sublib -DEFINES += UNICODE QT_KEYPAD_NAVIGATION QT_SOFTKEYS_ENABLED QT_USE_MATH_H_FLOATS +DEFINES += UNICODE QT_KEYPAD_NAVIGATION QT_SOFTKEYS_ENABLED QMAKE_COMPILER_DEFINES += SYMBIAN QMAKE_EXT_OBJ = .o diff --git a/src/3rdparty/easing/easing.cpp b/src/3rdparty/easing/easing.cpp index 65e9f95..81af40f 100644 --- a/src/3rdparty/easing/easing.cpp +++ b/src/3rdparty/easing/easing.cpp @@ -18,7 +18,13 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */ #include -#include +#include +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif +#ifndef M_PI_2 +#define M_PI_2 (M_PI / 2) +#endif QT_USE_NAMESPACE @@ -63,12 +69,12 @@ static qreal easeOutQuad(qreal t) */ static qreal easeInOutQuad(qreal t) { - t*=qreal(2.0); + t*=2.0; if (t < 1) { - return t*t*qreal(0.5); + return t*t/qreal(2); } else { --t; - return qreal(-0.5) * (t*(t-2) - 1); + return -0.5 * (t*(t-2) - 1); } } @@ -80,8 +86,8 @@ static qreal easeInOutQuad(qreal t) */ static qreal easeOutInQuad(qreal t) { - if (t < qreal(0.5)) return easeOutQuad (t*2) * qreal(0.5); - return easeInQuad((2*t)-1) * qreal(0.5) + qreal(0.5); + if (t < 0.5) return easeOutQuad (t*2)/2; + return easeInQuad((2*t)-1)/2 + 0.5; } /** @@ -103,7 +109,7 @@ static qreal easeInCubic(qreal t) */ static qreal easeOutCubic(qreal t) { - t-=qreal(1.0); + t-=1.0; return t*t*t + 1; } @@ -115,12 +121,12 @@ static qreal easeOutCubic(qreal t) */ static qreal easeInOutCubic(qreal t) { - t*=qreal(2.0); + t*=2.0; if(t < 1) { - return qreal(0.5)*t*t*t; + return 0.5*t*t*t; } else { t -= qreal(2.0); - return qreal(0.5)*(t*t*t + 2); + return 0.5*(t*t*t + 2); } } @@ -132,8 +138,8 @@ static qreal easeInOutCubic(qreal t) */ static qreal easeOutInCubic(qreal t) { - if (t < qreal(0.5)) return easeOutCubic (2*t) * qreal(0.5); - return easeInCubic(2*t - 1) * qreal(0.5) + qreal(0.5); + if (t < 0.5) return easeOutCubic (2*t)/2; + return easeInCubic(2*t - 1)/2 + 0.5; } /** @@ -168,10 +174,10 @@ static qreal easeOutQuart(qreal t) static qreal easeInOutQuart(qreal t) { t*=2; - if (t < 1) return qreal(0.5)*t*t*t*t; + if (t < 1) return 0.5*t*t*t*t; else { t -= 2.0f; - return qreal(-0.5) * (t*t*t*t- 2); + return -0.5 * (t*t*t*t- 2); } } @@ -183,8 +189,8 @@ static qreal easeInOutQuart(qreal t) */ static qreal easeOutInQuart(qreal t) { - if (t < qreal(0.5)) return easeOutQuart (2*t) * qreal(0.5); - return easeInQuart(2*t-1) * qreal(0.5) + qreal(0.5); + if (t < 0.5) return easeOutQuart (2*t)/2; + return easeInQuart(2*t-1)/2 + 0.5; } /** @@ -206,7 +212,7 @@ static qreal easeInQuint(qreal t) */ static qreal easeOutQuint(qreal t) { - t-=qreal(1.0); + t-=1.0; return t*t*t*t*t + 1; } @@ -218,11 +224,11 @@ static qreal easeOutQuint(qreal t) */ static qreal easeInOutQuint(qreal t) { - t*=qreal(2.0); - if (t < 1) return qreal(0.5)*t*t*t*t*t; + t*=2.0; + if (t < 1) return 0.5*t*t*t*t*t; else { - t -= qreal(2.0); - return qreal(0.5)*(t*t*t*t*t + 2); + t -= 2.0; + return 0.5*(t*t*t*t*t + 2); } } @@ -234,8 +240,8 @@ static qreal easeInOutQuint(qreal t) */ static qreal easeOutInQuint(qreal t) { - if (t < qreal(0.5)) return easeOutQuint (2*t) * qreal(0.5); - return easeInQuint(2*t - 1) * qreal(0.5) + qreal(0.5); + if (t < 0.5) return easeOutQuint (2*t)/2; + return easeInQuint(2*t - 1)/2 + 0.5; } /** @@ -246,7 +252,7 @@ static qreal easeOutInQuint(qreal t) */ static qreal easeInSine(qreal t) { - return (t == qreal(1.0)) ? qreal(1.0) : -qCos(t * Q_PI2) + qreal(1.0); + return (t == 1.0) ? 1.0 : -::cos(t * M_PI_2) + 1.0; } /** @@ -257,7 +263,7 @@ static qreal easeInSine(qreal t) */ static qreal easeOutSine(qreal t) { - return qSin(t* Q_PI2); + return ::sin(t* M_PI_2); } /** @@ -268,7 +274,7 @@ static qreal easeOutSine(qreal t) */ static qreal easeInOutSine(qreal t) { - return qreal(-0.5) * (qCos(Q_PI*t) - 1); + return -0.5 * (::cos(M_PI*t) - 1); } /** @@ -279,8 +285,8 @@ static qreal easeInOutSine(qreal t) */ static qreal easeOutInSine(qreal t) { - if (t < qreal(0.5)) return easeOutSine (2*t) * qreal(0.5); - return easeInSine(2*t - 1) * qreal(0.5) + qreal(0.5); + if (t < 0.5) return easeOutSine (2*t)/2; + return easeInSine(2*t - 1)/2 + 0.5; } /** @@ -291,7 +297,7 @@ static qreal easeOutInSine(qreal t) */ static qreal easeInExpo(qreal t) { - return (t==0 || t == qreal(1.0)) ? t : ::qPow(qreal(2.0), 10 * (t - 1)) - qreal(0.001); + return (t==0 || t == 1.0) ? t : ::qPow(2.0, 10 * (t - 1)) - qreal(0.001); } /** @@ -302,7 +308,7 @@ static qreal easeInExpo(qreal t) */ static qreal easeOutExpo(qreal t) { - return (t==qreal(1.0)) ? qreal(1.0) : qreal(1.001) * (-::qPow(2.0f, -10 * t) + 1); + return (t==1.0) ? 1.0 : 1.001 * (-::qPow(2.0f, -10 * t) + 1); } /** @@ -313,11 +319,11 @@ static qreal easeOutExpo(qreal t) */ static qreal easeInOutExpo(qreal t) { - if (t==qreal(0.0)) return qreal(0.0); - if (t==qreal(1.0)) return qreal(1.0); - t*=qreal(2.0); - if (t < 1) return qreal(0.5) * ::qPow(qreal(2.0), 10 * (t - 1)) - qreal(0.0005); - return qreal(0.5) * qreal(1.0005) * (-::qPow(qreal(2.0), -10 * (t - 1)) + 2); + if (t==0.0) return qreal(0.0); + if (t==1.0) return qreal(1.0); + t*=2.0; + if (t < 1) return 0.5 * ::qPow(qreal(2.0), 10 * (t - 1)) - 0.0005; + return 0.5 * 1.0005 * (-::qPow(qreal(2.0), -10 * (t - 1)) + 2); } /** @@ -328,8 +334,8 @@ static qreal easeInOutExpo(qreal t) */ static qreal easeOutInExpo(qreal t) { - if (t < qreal(0.5)) return easeOutExpo (2*t) * qreal(0.5); - return easeInExpo(2*t - 1) * qreal(0.5) + qreal(0.5); + if (t < 0.5) return easeOutExpo (2*t)/2; + return easeInExpo(2*t - 1)/2 + 0.5; } /** @@ -340,7 +346,7 @@ static qreal easeOutInExpo(qreal t) */ static qreal easeInCirc(qreal t) { - return -(::qSqrt(1 - t*t) - 1); + return -(::sqrt(1 - t*t) - 1); } /** @@ -352,7 +358,7 @@ static qreal easeInCirc(qreal t) static qreal easeOutCirc(qreal t) { t-= qreal(1.0); - return ::qSqrt(1 - t* t); + return ::sqrt(1 - t* t); } /** @@ -365,10 +371,10 @@ static qreal easeInOutCirc(qreal t) { t*=qreal(2.0); if (t < 1) { - return qreal(-0.5) * (::qSqrt(1 - t*t) - 1); + return -0.5 * (::sqrt(1 - t*t) - 1); } else { t -= qreal(2.0); - return qreal(0.5) * (::qSqrt(1 - t*t) + 1); + return 0.5 * (::sqrt(1 - t*t) + 1); } } @@ -380,26 +386,26 @@ static qreal easeInOutCirc(qreal t) */ static qreal easeOutInCirc(qreal t) { - if (t < qreal(0.5)) return easeOutCirc (2*t)*qreal(0.5); - return easeInCirc(2*t - 1)*qreal(0.5) + qreal(0.5); + if (t < 0.5) return easeOutCirc (2*t)/2; + return easeInCirc(2*t - 1)/2 + 0.5; } static qreal easeInElastic_helper(qreal t, qreal b, qreal c, qreal d, qreal a, qreal p) { if (t==0) return b; - qreal t_adj = t / d; + qreal t_adj = (qreal)t / (qreal)d; if (t_adj==1) return b+c; qreal s; - if(a < ::qAbs(c)) { + if(a < ::fabs(c)) { a = c; - s = p * 0.25f; + s = p / 4.0f; } else { - s = p / (Q_2PI) * ::qAsin(c / a); + s = p / (2 * M_PI) * ::asin(c / a); } t_adj -= 1.0f; - return -(a*::qPow(2.0f,10*t_adj) * qSin( (t_adj*d-s)*(Q_2PI)/p )) + b; + return -(a*::qPow(2.0f,10*t_adj) * ::sin( (t_adj*d-s)*(2*M_PI)/p )) + b; } /** @@ -423,12 +429,12 @@ static qreal easeOutElastic_helper(qreal t, qreal /*b*/, qreal c, qreal /*d*/, q qreal s; if(a < c) { a = c; - s = p * 0.25f; + s = p / 4.0f; } else { - s = p / (Q_2PI) * ::qAsin(c / a); + s = p / (2 * M_PI) * ::asin(c / a); } - return (a*::qPow(2.0f,-10*t) * ::qSin( (t-s)*(Q_2PI)/p ) + c); + return (a*::qPow(2.0f,-10*t) * ::sin( (t-s)*(2*M_PI)/p ) + c); } /** @@ -454,20 +460,20 @@ static qreal easeOutElastic(qreal t, qreal a, qreal p) */ static qreal easeInOutElastic(qreal t, qreal a, qreal p) { - if (t==0) return qreal(0.0); - t*=qreal(2.0); - if (t==2) return qreal(1.0); + if (t==0) return 0.0; + t*=2.0; + if (t==2) return 1.0; qreal s; - if(a < qreal(1.0)) { - a = qreal(1.0); - s = p * 0.25f; + if(a < 1.0) { + a = 1.0; + s = p / 4.0f; } else { - s = p / (Q_2PI) * ::qAsin(qreal(1.0) / a); + s = p / (2 * M_PI) * ::asin(1.0 / a); } - if (t < 1) return qreal(-.5)*(a*::qPow(2.0f,10*(t-1)) * ::qSin( (t-1-s)*(Q_2PI)/p )); - return a*::qPow(2.0f,-10*(t-1)) * ::qSin( (t-1-s)*(Q_2PI)/p )*qreal(.5) + qreal(1.0); + if (t < 1) return -.5*(a*::qPow(2.0f,10*(t-1)) * ::sin( (t-1-s)*(2*M_PI)/p )); + return a*::qPow(2.0f,-10*(t-1)) * ::sin( (t-1-s)*(2*M_PI)/p )*.5 + 1.0; } /** @@ -480,8 +486,8 @@ static qreal easeInOutElastic(qreal t, qreal a, qreal p) */ static qreal easeOutInElastic(qreal t, qreal a, qreal p) { - if (t < qreal(0.5)) return easeOutElastic_helper(t*2, 0, qreal(0.5), qreal(1.0), a, p); - return easeInElastic_helper(2*t - qreal(1.0), qreal(0.5), qreal(0.5), qreal(1.0), a, p); + if (t < 0.5) return easeOutElastic_helper(t*2, 0, 0.5, 1.0, a, p); + return easeInElastic_helper(2*t - 1.0, 0.5, 0.5, 1.0, a, p); } /** @@ -518,14 +524,14 @@ static qreal easeOutBack(qreal t, qreal s) */ static qreal easeInOutBack(qreal t, qreal s) { - t *= qreal(2.0); + t *= 2.0; if (t < 1) { s *= 1.525f; - return qreal(0.5)*(t*t*((s+1)*t - s)); + return 0.5*(t*t*((s+1)*t - s)); } else { t -= 2; s *= 1.525f; - return qreal(0.5)*(t*t*((s+1)*t+ s) + 2); + return 0.5*(t*t*((s+1)*t+ s) + 2); } } @@ -538,26 +544,24 @@ static qreal easeInOutBack(qreal t, qreal s) */ static qreal easeOutInBack(qreal t, qreal s) { - if (t < qreal(0.5)) return easeOutBack (2*t, s) * qreal(0.5); - return easeInBack(2*t - 1, s) * qreal(0.5) + qreal(0.5); + if (t < 0.5) return easeOutBack (2*t, s)/2; + return easeInBack(2*t - 1, s)/2 + 0.5; } static qreal easeOutBounce_helper(qreal t, qreal c, qreal a) { - const qreal inv_22 = 1 / qreal(22.0); - const qreal inv_11 = 2 * inv_22; - if (t == qreal(1.0)) return c; - if (t < (4 * inv_11)) { - return c*(qreal(7.5625)*t*t); - } else if (t < (8 * inv_11)) { - t -= (6 * inv_11); - return -a * (qreal(1.) - (qreal(7.5625)*t*t + qreal(.75))) + c; - } else if (t < (10 * inv_11)) { - t -= (9 * inv_11); - return -a * (qreal(1.) - (qreal(7.5625)*t*t + qreal(.9375))) + c; + if (t == 1.0) return c; + if (t < (4/11.0)) { + return c*(7.5625*t*t); + } else if (t < (8/11.0)) { + t -= (6/11.0); + return -a * (1. - (7.5625*t*t + .75)) + c; + } else if (t < (10/11.0)) { + t -= (9/11.0); + return -a * (1. - (7.5625*t*t + .9375)) + c; } else { - t -= (21 * inv_22); - return -a * (qreal(1.) - (qreal(7.5625)*t*t + qreal(.984375))) + c; + t -= (21/22.0); + return -a * (1. - (7.5625*t*t + .984375)) + c; } } @@ -582,7 +586,7 @@ static qreal easeOutBounce(qreal t, qreal a) */ static qreal easeInBounce(qreal t, qreal a) { - return qreal(1.0) - easeOutBounce_helper(qreal(1.0)-t, qreal(1.0), a); + return 1.0 - easeOutBounce_helper(1.0-t, 1.0, a); } @@ -595,8 +599,8 @@ static qreal easeInBounce(qreal t, qreal a) */ static qreal easeInOutBounce(qreal t, qreal a) { - if (t < qreal(0.5)) return easeInBounce (2*t, a) * qreal(0.5); - else return (t == qreal(1.0)) ? qreal(1.0) : easeOutBounce (2*t - 1, a) * qreal(0.5) + qreal(0.5); + if (t < 0.5) return easeInBounce (2*t, a)/2; + else return (t == 1.0) ? 1.0 : easeOutBounce (2*t - 1, a)/2 + 0.5; } /** @@ -608,13 +612,13 @@ static qreal easeInOutBounce(qreal t, qreal a) */ static qreal easeOutInBounce(qreal t, qreal a) { - if (t < qreal(0.5)) return easeOutBounce_helper(t*2, qreal(0.5), a); - return qreal(1.0) - easeOutBounce_helper (qreal(2.0)-2*t, qreal(0.5), a); + if (t < 0.5) return easeOutBounce_helper(t*2, 0.5, a); + return 1.0 - easeOutBounce_helper (2.0-2*t, 0.5, a); } static inline qreal qt_sinProgress(qreal value) { - return qSin((value * Q_PI) - Q_PI2) * qreal(0.5) + qreal(0.5); + return qSin((value * M_PI) - M_PI_2) / 2 + qreal(0.5); } static inline qreal qt_smoothBeginEndMixFactor(qreal value) @@ -652,7 +656,7 @@ static qreal easeOutCurve(qreal t) */ static qreal easeSineCurve(qreal t) { - return (qSin(((t * Q_2PI)) - Q_PI2) + 1) * qreal(0.5); + return (qSin(((t * M_PI * 2)) - M_PI_2) + 1) / 2; } /** @@ -661,6 +665,6 @@ static qreal easeSineCurve(qreal t) */ static qreal easeCosineCurve(qreal t) { - return (qCos(((t * Q_2PI)) - Q_PI2) + 1) * qreal(0.5); + return (qCos(((t * M_PI * 2)) - M_PI_2) + 1) / 2; } diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 6befb33..9558256 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1081,14 +1081,14 @@ template inline T qAbs(const T &t) { return t >= 0 ? t : -t; } inline int qRound(qreal d) -{ return d >= qreal(0.0) ? int(d + qreal(0.5)) : int(d - int(d-1) + qreal(0.5)) + int(d-1); } +{ return d >= 0.0 ? int(d + 0.5) : int(d - int(d-1) + 0.5) + int(d-1); } #if defined(QT_NO_FPU) || defined(QT_ARCH_ARM) || defined(QT_ARCH_WINDOWSCE) || defined(QT_ARCH_SYMBIAN) inline qint64 qRound64(double d) { return d >= 0.0 ? qint64(d + 0.5) : qint64(d - qreal(qint64(d-1)) + 0.5) + qint64(d-1); } #else inline qint64 qRound64(qreal d) -{ return d >= 0.0 ? qint64(d + qreal(0.5)) : qint64(d - qreal(qint64(d-1)) + qreal(0.5)) + qint64(d-1); } +{ return d >= 0.0 ? qint64(d + 0.5) : qint64(d - qreal(qint64(d-1)) + 0.5) + qint64(d-1); } #endif template diff --git a/src/corelib/global/qnumeric_p.h b/src/corelib/global/qnumeric_p.h index 3f7b5b5..c8b5735 100644 --- a/src/corelib/global/qnumeric_p.h +++ b/src/corelib/global/qnumeric_p.h @@ -57,12 +57,6 @@ QT_BEGIN_NAMESPACE -static const qreal Q_PI = qreal(3.14159265358979323846); // pi -static const qreal Q_2PI = qreal(6.28318530717958647693); // 2*pi -static const qreal Q_PI2 = qreal(1.57079632679489661923); // pi/2 -static const qreal Q_PI180 = qreal(0.01745329251994329577); // pi/180 -static const qreal Q_180PI = qreal(57.29577951308232087685); // 180/pi - #if !defined(Q_CC_MIPS) static const union { unsigned char c[8]; double d; } qt_be_inf_bytes = { { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 } }; diff --git a/src/corelib/kernel/qmath.h b/src/corelib/kernel/qmath.h index ef3a4b0..a9e4378 100644 --- a/src/corelib/kernel/qmath.h +++ b/src/corelib/kernel/qmath.h @@ -45,7 +45,6 @@ #include #include -#include QT_BEGIN_HEADER @@ -107,16 +106,6 @@ inline qreal qAcos(qreal v) return acos(v); } -inline qreal qAsin(qreal v) -{ -#ifdef QT_USE_MATH_H_FLOATS - if (sizeof(qreal) == sizeof(float)) - return asinf(float(v)); - else -#endif - return asin(v); -} - inline qreal qSqrt(qreal v) { #ifdef QT_USE_MATH_H_FLOATS @@ -147,42 +136,28 @@ inline qreal qPow(qreal x, qreal y) return pow(x, y); } +#ifndef M_PI +#define M_PI (3.14159265358979323846) +#endif + inline qreal qFastSin(qreal x) { - int si = int(x * (qreal(0.5) * QT_SINE_TABLE_SIZE / Q_PI)); // Would be more accurate with qRound, but slower. - qreal d = x - si * (qreal(2.0) * Q_PI / QT_SINE_TABLE_SIZE); + int si = int(x * (0.5 * QT_SINE_TABLE_SIZE / M_PI)); // Would be more accurate with qRound, but slower. + qreal d = x - si * (2.0 * M_PI / QT_SINE_TABLE_SIZE); int ci = si + QT_SINE_TABLE_SIZE / 4; si &= QT_SINE_TABLE_SIZE - 1; ci &= QT_SINE_TABLE_SIZE - 1; - return qt_sine_table[si] + (qt_sine_table[ci] - qreal(0.5) * qt_sine_table[si] * d) * d; + return qt_sine_table[si] + (qt_sine_table[ci] - 0.5 * qt_sine_table[si] * d) * d; } inline qreal qFastCos(qreal x) { - int ci = int(x * (qreal(0.5) * QT_SINE_TABLE_SIZE / Q_PI)); // Would be more accurate with qRound, but slower. - qreal d = x - ci * (qreal(2.0) * Q_PI / QT_SINE_TABLE_SIZE); + int ci = int(x * (0.5 * QT_SINE_TABLE_SIZE / M_PI)); // Would be more accurate with qRound, but slower. + qreal d = x - ci * (2.0 * M_PI / QT_SINE_TABLE_SIZE); int si = ci + QT_SINE_TABLE_SIZE / 4; si &= QT_SINE_TABLE_SIZE - 1; ci &= QT_SINE_TABLE_SIZE - 1; - return qt_sine_table[si] - (qt_sine_table[ci] + qreal(0.5) * qt_sine_table[si] * d) * d; -} - -inline qreal qFabs(qreal x) -{ -#ifdef QT_USE_MATH_H_FLOATS - if(sizeof(qreal) == sizeof(float)) - return fabsf(x); -#endif - return fabs(x); -} - -inline qreal qAtan2(qreal x, qreal y) -{ -#ifdef QT_USE_MATH_H_FLOATS - if(sizeof(qreal) == sizeof(float)) - return atan2f(x, y); -#endif - return atan2(x, y); + return qt_sine_table[si] - (qt_sine_table[ci] + 0.5 * qt_sine_table[si] * d) * d; } QT_END_NAMESPACE diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 5ae2dde..db6435e 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -1915,7 +1915,7 @@ QTime QTime::fromString(const QString& s, Qt::DateFormat f) const float msec(msec_s.toFloat(&ok)); if (!ok) return QTime(); - return QTime(hour, minute, second, qMin(qRound(msec * qreal(1000.0)), 999)); + return QTime(hour, minute, second, qMin(qRound(msec * 1000.0), 999)); } } } diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp index a629ebc..3e1e1ee 100644 --- a/src/corelib/tools/qeasingcurve.cpp +++ b/src/corelib/tools/qeasingcurve.cpp @@ -317,7 +317,7 @@ class QEasingCurveFunction public: enum Type { In, Out, InOut, OutIn }; - QEasingCurveFunction(QEasingCurveFunction::Type type = In, qreal period = qreal(0.3), qreal amplitude = qreal(1.0), + QEasingCurveFunction(QEasingCurveFunction::Type type = In, qreal period = 0.3, qreal amplitude = 1.0, qreal overshoot = 1.70158f) : _t(type), _p(period), _a(amplitude), _o(overshoot) { } @@ -667,7 +667,7 @@ bool QEasingCurve::operator==(const QEasingCurve &other) const */ qreal QEasingCurve::amplitude() const { - return d_ptr->config ? d_ptr->config->_a : qreal(1.0); + return d_ptr->config ? d_ptr->config->_a : 1.0; } /*! @@ -691,7 +691,7 @@ void QEasingCurve::setAmplitude(qreal amplitude) */ qreal QEasingCurve::period() const { - return d_ptr->config ? d_ptr->config->_p : qreal(0.3); + return d_ptr->config ? d_ptr->config->_p : 0.3; } /*! @@ -742,9 +742,9 @@ QEasingCurve::Type QEasingCurve::type() const void QEasingCurvePrivate::setType_helper(QEasingCurve::Type newType) { - qreal amp = qreal(-1.0); - qreal period = qreal(-1.0); - qreal overshoot = qreal(-1.0); + qreal amp = -1.0; + qreal period = -1.0; + qreal overshoot = -1.0; if (config) { amp = config->_a; @@ -754,13 +754,13 @@ void QEasingCurvePrivate::setType_helper(QEasingCurve::Type newType) config = 0; } - if (isConfigFunction(newType) || (amp != qreal(-1.0)) || (period != qreal(-1.0)) || (overshoot != qreal(-1.0))) { + if (isConfigFunction(newType) || (amp != -1.0) || (period != -1.0) || (overshoot != -1.0)) { config = curveToFunctionObject(newType); - if (amp != qreal(-1.0)) + if (amp != -1.0) config->_a = amp; - if (period != qreal(-1.0)) + if (period != -1.0) config->_p = period; - if (overshoot != qreal(-1.0)) + if (overshoot != -1.0) config->_o = overshoot; func = 0; } else if (newType != QEasingCurve::Custom) { diff --git a/src/corelib/tools/qline.cpp b/src/corelib/tools/qline.cpp index 5b30c97..d0afb7a 100644 --- a/src/corelib/tools/qline.cpp +++ b/src/corelib/tools/qline.cpp @@ -574,7 +574,7 @@ qreal QLineF::angle() const const qreal dx = pt2.x() - pt1.x(); const qreal dy = pt2.y() - pt1.y(); - const qreal theta = qAtan2(-dy, dx) * qreal(360.0) / Q_2PI; + const qreal theta = atan2(-dy, dx) * 360.0 / M_2PI; const qreal theta_normalized = theta < 0 ? theta + 360 : theta; @@ -598,7 +598,7 @@ qreal QLineF::angle() const */ void QLineF::setAngle(qreal angle) { - const qreal angleR = angle * Q_2PI / qreal(360.0); + const qreal angleR = angle * M_2PI / 360.0; const qreal l = length(); const qreal dx = qCos(angleR) * l; @@ -620,7 +620,7 @@ void QLineF::setAngle(qreal angle) */ QLineF QLineF::fromPolar(qreal length, qreal angle) { - const qreal angleR = angle * Q_2PI / qreal(360.0); + const qreal angleR = angle * M_2PI / 360.0; return QLineF(0, 0, qCos(angleR) * length, -qSin(angleR) * length); } @@ -639,7 +639,7 @@ QLineF QLineF::unitVector() const QLineF f(p1(), QPointF(pt1.x() + x/len, pt1.y() + y/len)); #ifndef QT_NO_DEBUG - if (qAbs(f.length() - 1) >= qreal(0.001)) + if (qAbs(f.length() - 1) >= 0.001) qWarning("QLine::unitVector: New line does not have unit length"); #endif @@ -814,8 +814,8 @@ qreal QLineF::angle(const QLineF &l) const qreal cos_line = (dx()*l.dx() + dy()*l.dy()) / (length()*l.length()); qreal rad = 0; // only accept cos_line in the range [-1,1], if it is outside, use 0 (we return 0 rather than PI for those cases) - if (cos_line >= qreal(-1.0) && cos_line <= qreal(1.0)) rad = qAcos( cos_line ); - return rad * 360 / Q_2PI; + if (cos_line >= -1.0 && cos_line <= 1.0) rad = acos( cos_line ); + return rad * 360 / M_2PI; } diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index bcd060e..9d495e9 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -8460,9 +8460,8 @@ QPainterPath QGraphicsEllipseItem::shape() const if (d->rect.isNull()) return path; if (d->spanAngle != 360 * 16) { - const qreal inv_16 = 1 / qreal(16.0); path.moveTo(d->rect.center()); - path.arcTo(d->rect, d->startAngle * inv_16, d->spanAngle * inv_16); + path.arcTo(d->rect, d->startAngle / 16.0, d->spanAngle / 16.0); } else { path.addEllipse(d->rect); } diff --git a/src/gui/graphicsview/qgraphicsitemanimation.cpp b/src/gui/graphicsview/qgraphicsitemanimation.cpp index 1516e46..be2f300 100644 --- a/src/gui/graphicsview/qgraphicsitemanimation.cpp +++ b/src/gui/graphicsview/qgraphicsitemanimation.cpp @@ -165,7 +165,7 @@ qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, QList void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QList *binList, const char* method) { - if (step < qreal(0.0) || step > qreal(1.0)) { + if (step < 0.0 || step > 1.0) { qWarning("QGraphicsItemAnimation::%s: invalid step = %f", method, step); return; } @@ -255,7 +255,7 @@ void QGraphicsItemAnimation::setTimeLine(QTimeLine *timeLine) */ QPointF QGraphicsItemAnimation::posAt(qreal step) const { - if (step < qreal(0.0) || step > qreal(1.0)) + if (step < 0.0 || step > 1.0) qWarning("QGraphicsItemAnimation::posAt: invalid step = %f", step); return QPointF(d->linearValueForStep(step, &d->xPosition, d->startPos.x()), @@ -294,7 +294,7 @@ QList > QGraphicsItemAnimation::posList() const */ QMatrix QGraphicsItemAnimation::matrixAt(qreal step) const { - if (step < qreal(0.0) || step > qreal(1.0)) + if (step < 0.0 || step > 1.0) qWarning("QGraphicsItemAnimation::matrixAt: invalid step = %f", step); QMatrix matrix; @@ -316,7 +316,7 @@ QMatrix QGraphicsItemAnimation::matrixAt(qreal step) const */ qreal QGraphicsItemAnimation::rotationAt(qreal step) const { - if (step < qreal(0.0) || step > qreal(1.0)) + if (step < 0.0 || step > 1.0) qWarning("QGraphicsItemAnimation::rotationAt: invalid step = %f", step); return d->linearValueForStep(step, &d->rotation); @@ -405,7 +405,7 @@ QList > QGraphicsItemAnimation::translationList() const */ qreal QGraphicsItemAnimation::verticalScaleAt(qreal step) const { - if (step < qreal(0.0) || step > qreal(1.0)) + if (step < 0.0 || step > 1.0) qWarning("QGraphicsItemAnimation::verticalScaleAt: invalid step = %f", step); return d->linearValueForStep(step, &d->verticalScale, 1); @@ -418,7 +418,7 @@ qreal QGraphicsItemAnimation::verticalScaleAt(qreal step) const */ qreal QGraphicsItemAnimation::horizontalScaleAt(qreal step) const { - if (step < qreal(0.0) || step > qreal(1.0)) + if (step < 0.0 || step > 1.0) qWarning("QGraphicsItemAnimation::horizontalScaleAt: invalid step = %f", step); return d->linearValueForStep(step, &d->horizontalScale, 1); @@ -457,7 +457,7 @@ QList > QGraphicsItemAnimation::scaleList() const */ qreal QGraphicsItemAnimation::verticalShearAt(qreal step) const { - if (step < qreal(0.0) || step > qreal(1.0)) + if (step < 0.0 || step > 1.0) qWarning("QGraphicsItemAnimation::verticalShearAt: invalid step = %f", step); return d->linearValueForStep(step, &d->verticalShear, 0); @@ -470,7 +470,7 @@ qreal QGraphicsItemAnimation::verticalShearAt(qreal step) const */ qreal QGraphicsItemAnimation::horizontalShearAt(qreal step) const { - if (step < qreal(0.0) || step > qreal(1.0)) + if (step < 0.0 || step > 1.0) qWarning("QGraphicsItemAnimation::horizontalShearAt: invalid step = %f", step); return d->linearValueForStep(step, &d->horizontalShear, 0); @@ -527,7 +527,7 @@ void QGraphicsItemAnimation::clear() */ void QGraphicsItemAnimation::setStep(qreal x) { - if (x < qreal(0.0) || x > qreal(1.0)) { + if (x < 0.0 || x > 1.0) { qWarning("QGraphicsItemAnimation::setStep: invalid step = %f", x); return; } diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 917d3ae..13f31b8 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -4168,13 +4168,13 @@ static void _q_paintItem(QGraphicsItem *item, QPainter *painter, QGraphicsWidget *widgetItem = static_cast(item); QGraphicsProxyWidget *proxy = qobject_cast(widgetItem); const qreal windowOpacity = (proxy && proxy->widget() && useWindowOpacity) - ? proxy->widget()->windowOpacity() : qreal(1.0); + ? proxy->widget()->windowOpacity() : 1.0; const qreal oldPainterOpacity = painter->opacity(); if (qFuzzyIsNull(windowOpacity)) return; // Set new painter opacity. - if (windowOpacity < qreal(1.0)) + if (windowOpacity < 1.0) painter->setOpacity(oldPainterOpacity * windowOpacity); // set layoutdirection on the painter @@ -4268,7 +4268,7 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte QGraphicsProxyWidget *proxy = item->isWidget() ? qobject_cast(static_cast(item)) : 0; if (proxy && proxy->widget()) { const qreal windowOpacity = proxy->widget()->windowOpacity(); - if (windowOpacity < qreal(1.0)) + if (windowOpacity < 1.0) newPainterOpacity *= windowOpacity; } diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 61a3758..27fd09e 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -297,7 +297,7 @@ inline int q_round_bound(qreal d) //### (int)(qreal) INT_MAX != INT_MAX for sing return INT_MIN; else if (d >= (qreal) INT_MAX) return INT_MAX; - return d >= qreal(0.0) ? int(d + qreal(0.5)) : int(d - int(d-1) + qreal(0.5)) + int(d-1); + return d >= 0.0 ? int(d + 0.5) : int(d - int(d-1) + 0.5) + int(d-1); } void QGraphicsViewPrivate::translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent) diff --git a/src/gui/graphicsview/qgraphicswidget_p.cpp b/src/gui/graphicsview/qgraphicswidget_p.cpp index 7847635..b747a30 100644 --- a/src/gui/graphicsview/qgraphicswidget_p.cpp +++ b/src/gui/graphicsview/qgraphicswidget_p.cpp @@ -457,13 +457,13 @@ static QSizeF closestAcceptableSize(const QSizeF &proposed, min_hfw = minimumHeightForWidth(maxw, minh, maxh, widget); do { - if (maxw - minw < qreal(0.1)) { + if (maxw - minw < 0.1) { // we still havent found anything, cut off binary search minw = maxw; minh = maxh; } - middlew = minw + (maxw - minw) * qreal(0.5); - middleh = minh + (maxh - minh) * qreal(0.5); + middlew = minw + (maxw - minw)/2.0; + middleh = minh + (maxh - minh)/2.0; min_hfw = minimumHeightForWidth(middlew, minh, maxh, widget); diff --git a/src/gui/graphicsview/qgridlayoutengine.cpp b/src/gui/graphicsview/qgridlayoutengine.cpp index f6fa16b..f61360a 100644 --- a/src/gui/graphicsview/qgridlayoutengine.cpp +++ b/src/gui/graphicsview/qgridlayoutengine.cpp @@ -69,22 +69,21 @@ static void insertOrRemoveItems(QVector &items, int index, int delta) static qreal growthFactorBelowPreferredSize(qreal desired, qreal sumAvailable, qreal sumDesired) { - Q_ASSERT(sumDesired != qreal(0.0)); - const qreal inv_sumDesired = 1 / sumDesired; - return desired * ::pow(sumAvailable * inv_sumDesired, desired * inv_sumDesired); + Q_ASSERT(sumDesired != 0.0); + return desired * ::pow(sumAvailable / sumDesired, desired / sumDesired); } static qreal fixedDescent(qreal descent, qreal ascent, qreal targetSize) { - if (descent < qreal(0.0)) - return qreal(-1.0); + if (descent < 0.0) + return -1.0; - Q_ASSERT(descent >= qreal(0.0)); - Q_ASSERT(ascent >= qreal(0.0)); + Q_ASSERT(descent >= 0.0); + Q_ASSERT(ascent >= 0.0); Q_ASSERT(targetSize >= ascent + descent); qreal extra = targetSize - (ascent + descent); - return descent + (extra * qreal(0.5)); + return descent + (extra / 2.0); } static qreal compare(const QGridLayoutBox &box1, const QGridLayoutBox &box2, int which) @@ -101,7 +100,7 @@ static qreal compare(const QGridLayoutBox &box1, const QGridLayoutBox &box2, int void QGridLayoutBox::add(const QGridLayoutBox &other, int stretch, qreal spacing) { - Q_ASSERT(q_minimumDescent < qreal(0.0)); + Q_ASSERT(q_minimumDescent < 0.0); q_minimumSize += other.q_minimumSize + spacing; q_preferredSize += other.q_preferredSize + spacing; @@ -135,7 +134,7 @@ void QGridLayoutBox::normalize() q_preferredSize = qBound(q_minimumSize, q_preferredSize, q_maximumSize); q_minimumDescent = qMin(q_minimumDescent, q_minimumSize); - Q_ASSERT((q_minimumDescent < qreal(0.0)) == (q_minimumAscent < qreal(0.0))); + Q_ASSERT((q_minimumDescent < 0.0) == (q_minimumAscent < 0.0)); } #ifdef QT_DEBUG @@ -162,7 +161,7 @@ void QGridLayoutRowData::reset(int count) boxes.fill(QGridLayoutBox(), count); multiCellMap.clear(); stretches.fill(0, count); - spacings.fill(qreal(0.0), count); + spacings.fill(0.0, count); hasIgnoreFlag = false; } @@ -183,7 +182,7 @@ void QGridLayoutRowData::distributeMultiCells() for (int j = 0; j < NSizes; ++j) { qreal extra = compare(totalBox, box, j); - if (extra > qreal(0.0)) { + if (extra > 0.0) { calculateGeometries(start, end, totalBox.q_sizes(j), dummy.data(), newSizes.data(), 0, totalBox); @@ -211,7 +210,7 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz int n = end - start; QVarLengthArray newSizes(n); QVarLengthArray factors(n); - qreal sumFactors = qreal(0.0); + qreal sumFactors = 0.0; int sumStretches = 0; qreal sumAvailable; @@ -224,25 +223,24 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz stealBox(start, end, MinimumSize, positions, sizes); sumAvailable = targetSize - totalBox.q_minimumSize; - if (sumAvailable > qreal(0.0)) { - const qreal sumDesired = totalBox.q_preferredSize - totalBox.q_minimumSize; + if (sumAvailable > 0.0) { + qreal sumDesired = totalBox.q_preferredSize - totalBox.q_minimumSize; for (int i = 0; i < n; ++i) { if (ignore.testBit(start + i)) { - factors[i] = qreal(0.0); + factors[i] = 0.0; continue; } const QGridLayoutBox &box = boxes.at(start + i); - const qreal desired = box.q_preferredSize - box.q_minimumSize; + qreal desired = box.q_preferredSize - box.q_minimumSize; factors[i] = growthFactorBelowPreferredSize(desired, sumAvailable, sumDesired); sumFactors += factors[i]; } - const qreal inv_sumFactors = 1 / sumFactors; for (int i = 0; i < n; ++i) { - Q_ASSERT(sumFactors > qreal(0.0)); - const qreal delta = sumAvailable * factors[i] * inv_sumFactors; + Q_ASSERT(sumFactors > 0.0); + qreal delta = sumAvailable * factors[i] / sumFactors; newSizes[i] = sizes[i] + delta; } } @@ -250,46 +248,46 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz stealBox(start, end, PreferredSize, positions, sizes); sumAvailable = targetSize - totalBox.q_preferredSize; - if (sumAvailable > qreal(0.0)) { + if (sumAvailable > 0.0) { bool somethingHasAMaximumSize = false; - qreal sumPreferredSizes = qreal(0.0); + qreal sumPreferredSizes = 0.0; for (int i = 0; i < n; ++i) sumPreferredSizes += sizes[i]; for (int i = 0; i < n; ++i) { if (ignore.testBit(start + i)) { - newSizes[i] = qreal(0.0); - factors[i] = qreal(0.0); + newSizes[i] = 0.0; + factors[i] = 0.0; continue; } const QGridLayoutBox &box = boxes.at(start + i); - const qreal desired = box.q_maximumSize - box.q_preferredSize; - if (desired == qreal(0.0)) { + qreal desired = box.q_maximumSize - box.q_preferredSize; + if (desired == 0.0) { newSizes[i] = sizes[i]; - factors[i] = qreal(0.0); + factors[i] = 0.0; } else { - Q_ASSERT(desired > qreal(0.0)); + Q_ASSERT(desired > 0.0); int stretch = stretches[start + i]; if (sumStretches == 0) { if (hasIgnoreFlag) { - factors[i] = (stretch < 0) ? qreal(1.0) : qreal(0.0); + factors[i] = (stretch < 0) ? 1.0 : 0.0; } else { - factors[i] = (stretch < 0) ? sizes[i] : qreal(0.0); + factors[i] = (stretch < 0) ? sizes[i] : 0.0; } } else if (stretch == sumStretches) { - factors[i] = qreal(1.0); + factors[i] = 1.0; } else if (stretch <= 0) { - factors[i] = qreal(0.0); + factors[i] = 0.0; } else { qreal ultimatePreferredSize; qreal ultimateSumPreferredSizes; qreal x = ((stretch * sumPreferredSizes) - (sumStretches * box.q_preferredSize)) / (sumStretches - stretch); - if (x >= qreal(0.0)) { + if (x >= 0.0) { ultimatePreferredSize = box.q_preferredSize + x; ultimateSumPreferredSizes = sumPreferredSizes + x; } else { @@ -303,8 +301,8 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz (at the expense of the stretch factors, which are not fully respected during the transition). */ - ultimatePreferredSize = ultimatePreferredSize * qreal(1.5); - ultimateSumPreferredSizes = ultimateSumPreferredSizes * qreal(1.5); + ultimatePreferredSize = ultimatePreferredSize * 3 / 2; + ultimateSumPreferredSizes = ultimateSumPreferredSizes * 3 / 2; qreal ultimateFactor = (stretch * ultimateSumPreferredSizes / sumStretches) @@ -325,7 +323,7 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz if (desired < sumAvailable) somethingHasAMaximumSize = true; - newSizes[i] = qreal(-1.0); + newSizes[i] = -1.0; } } @@ -334,7 +332,7 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz keepGoing = false; for (int i = 0; i < n; ++i) { - if (newSizes[i] >= qreal(0.0)) + if (newSizes[i] >= 0.0) continue; const QGridLayoutBox &box = boxes.at(start + i); @@ -343,7 +341,7 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz newSizes[i] = box.q_maximumSize; sumAvailable -= box.q_maximumSize - sizes[i]; sumFactors -= factors[i]; - keepGoing = (sumAvailable > qreal(0.0)); + keepGoing = (sumAvailable > 0.0); if (!keepGoing) break; } @@ -351,8 +349,8 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz } for (int i = 0; i < n; ++i) { - if (newSizes[i] < qreal(0.0)) { - qreal delta = (sumFactors == qreal(0.0)) ? qreal(0.0) + if (newSizes[i] < 0.0) { + qreal delta = (sumFactors == 0.0) ? 0.0 : sumAvailable * factors[i] / sumFactors; newSizes[i] = sizes[i] + delta; } @@ -408,8 +406,8 @@ QGridLayoutBox QGridLayoutRowData::totalBox(int start, int end) const { QGridLayoutBox result; if (start < end) { - result.q_maximumSize = qreal(0.0); - qreal nextSpacing = qreal(0.0); + result.q_maximumSize = 0.0; + qreal nextSpacing = 0.0; for (int i = start; i < end; ++i) { result.add(boxes.at(i), stretches.at(i), nextSpacing); nextSpacing = spacings.at(i); @@ -420,11 +418,11 @@ QGridLayoutBox QGridLayoutRowData::totalBox(int start, int end) const void QGridLayoutRowData::stealBox(int start, int end, int which, qreal *positions, qreal *sizes) { - qreal offset = qreal(0.0); - qreal nextSpacing = qreal(0.0); + qreal offset = 0.0; + qreal nextSpacing = 0.0; for (int i = start; i < end; ++i) { - qreal avail = qreal(0.0); + qreal avail = 0.0; if (!ignore.testBit(i)) { const QGridLayoutBox &box = boxes.at(i); diff --git a/src/gui/graphicsview/qsimplex_p.cpp b/src/gui/graphicsview/qsimplex_p.cpp index 1b3eaf9..cd40f9e 100644 --- a/src/gui/graphicsview/qsimplex_p.cpp +++ b/src/gui/graphicsview/qsimplex_p.cpp @@ -485,8 +485,8 @@ bool QSimplex::iterate() // Normalize Pivot Row qreal pivot = valueAt(pivotRow, pivotColumn); - if (pivot != qreal(1.0)) - combineRows(pivotRow, pivotRow, (qreal(1.0) - pivot) / pivot); + if (pivot != 1.0) + combineRows(pivotRow, pivotRow, (1.0 - pivot) / pivot); // Update other rows for (int row=0; row < rows; ++row) { diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index ebad019..6d96d7a 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -5351,19 +5351,19 @@ int QImage::metric(PaintDeviceMetric metric) const break; case PdmDpiX: - return qRound(d->dpmx * qreal(0.0254)); + return qRound(d->dpmx * 0.0254); break; case PdmDpiY: - return qRound(d->dpmy * qreal(0.0254)); + return qRound(d->dpmy * 0.0254); break; case PdmPhysicalDpiX: - return qRound(d->dpmx * qreal(0.0254)); + return qRound(d->dpmx * 0.0254); break; case PdmPhysicalDpiY: - return qRound(d->dpmy * qreal(0.0254)); + return qRound(d->dpmy * 0.0254); break; default: @@ -5429,12 +5429,12 @@ bool qt_xForm_helper(const QTransform &trueMat, int xoffset, int type, int depth uchar *dptr, int dbpl, int p_inc, int dHeight, const uchar *sptr, int sbpl, int sWidth, int sHeight) { - int m11 = int(trueMat.m11()*qreal(4096.0)); - int m12 = int(trueMat.m12()*qreal(4096.0)); - int m21 = int(trueMat.m21()*qreal(4096.0)); - int m22 = int(trueMat.m22()*qreal(4096.0)); - int dx = qRound(trueMat.dx()*qreal(4096.0)); - int dy = qRound(trueMat.dy()*qreal(4096.0)); + int m11 = int(trueMat.m11()*4096.0); + int m12 = int(trueMat.m12()*4096.0); + int m21 = int(trueMat.m21()*4096.0); + int m22 = int(trueMat.m22()*4096.0); + int dx = qRound(trueMat.dx()*4096.0); + int dy = qRound(trueMat.dy()*4096.0); int m21ydx = dx + (xoffset<<16) + (m11 + m21) / 2; int m22ydy = dy + (m12 + m22) / 2; @@ -6018,22 +6018,22 @@ QImage QImage::transformed(const QTransform &matrix, Qt::TransformationMode mode if (mat.type() <= QTransform::TxScale) { if (mat.type() == QTransform::TxNone) // identity matrix return *this; - else if (mat.m11() == qreal(-1.) && mat.m22() == qreal(-1.)) + else if (mat.m11() == -1. && mat.m22() == -1.) return rotated180(*this); if (mode == Qt::FastTransformation) { hd = qRound(qAbs(mat.m22()) * hs); wd = qRound(qAbs(mat.m11()) * ws); } else { - hd = int(qAbs(mat.m22()) * hs + qreal(0.9999)); - wd = int(qAbs(mat.m11()) * ws + qreal(0.9999)); + hd = int(qAbs(mat.m22()) * hs + 0.9999); + wd = int(qAbs(mat.m11()) * ws + 0.9999); } scale_xform = true; } else { if (mat.type() <= QTransform::TxRotate && mat.m11() == 0 && mat.m22() == 0) { - if (mat.m12() == qreal(1.) && mat.m21() == qreal(-1.)) + if (mat.m12() == 1. && mat.m21() == -1.) return rotated90(*this); - else if (mat.m12() == qreal(-1.) && mat.m21() == qreal(1.)) + else if (mat.m12() == -1. && mat.m21() == 1.) return rotated270(*this); } diff --git a/src/gui/image/qpaintengine_pic.cpp b/src/gui/image/qpaintengine_pic.cpp index b6fea8b..80b16cf 100644 --- a/src/gui/image/qpaintengine_pic.cpp +++ b/src/gui/image/qpaintengine_pic.cpp @@ -342,7 +342,7 @@ void QPicturePaintEngine::writeCmdLength(int pos, const QRectF &r, bool corr) } d->pic_d->pictb.seek(newpos); // set to new position - if (br.width() > qreal(0.0) || br.height() > qreal(0.0)) { + if (br.width() > 0.0 || br.height() > 0.0) { if (corr) { // widen bounding rect int w2 = painter()->pen().width() / 2; br.setCoords(br.left() - w2, br.top() - w2, @@ -354,7 +354,7 @@ void QPicturePaintEngine::writeCmdLength(int pos, const QRectF &r, bool corr) br &= cr; } - if (br.width() > qreal(0.0) || br.height() > qreal(0.0)) { + if (br.width() > 0.0 || br.height() > 0.0) { int minx = qFloor(br.left()); int miny = qFloor(br.top()); int maxx = qCeil(br.right()); diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp index 39a4fcc..f502827 100644 --- a/src/gui/image/qpicture.cpp +++ b/src/gui/image/qpicture.cpp @@ -967,10 +967,10 @@ int QPicture::metric(PaintDeviceMetric m) const val = brect.height(); break; case PdmWidthMM: - val = int(qreal(25.4)/qt_defaultDpiX()*brect.width()); + val = int(25.4/qt_defaultDpiX()*brect.width()); break; case PdmHeightMM: - val = int(qreal(25.4)/qt_defaultDpiY()*brect.height()); + val = int(25.4/qt_defaultDpiY()*brect.height()); break; case PdmDpiX: case PdmPhysicalDpiX: diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp index 5ff3109..1b01e6f 100644 --- a/src/gui/image/qpixmap_raster.cpp +++ b/src/gui/image/qpixmap_raster.cpp @@ -373,9 +373,9 @@ int QRasterPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const case QPaintDevice::PdmHeight: return h; case QPaintDevice::PdmWidthMM: - return qRound(d->width * qreal(25.4) / qt_defaultDpiX()); + return qRound(d->width * 25.4 / qt_defaultDpiX()); case QPaintDevice::PdmHeightMM: - return qRound(d->width * qreal(25.4) / qt_defaultDpiY()); + return qRound(d->width * 25.4 / qt_defaultDpiY()); case QPaintDevice::PdmNumColors: return d->colortable.size(); case QPaintDevice::PdmDepth: diff --git a/src/gui/image/qpixmap_s60.cpp b/src/gui/image/qpixmap_s60.cpp index cc73e3e..f7a880c 100644 --- a/src/gui/image/qpixmap_s60.cpp +++ b/src/gui/image/qpixmap_s60.cpp @@ -568,7 +568,6 @@ int QS60PixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const if (!cfbsBitmap) return 0; - qreal div_by_KTwipsPerInch = 1 / (qreal)KTwipsPerInch; switch (metric) { case QPaintDevice::PdmWidth: return cfbsBitmap->SizeInPixels().iWidth; @@ -576,23 +575,23 @@ int QS60PixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const return cfbsBitmap->SizeInPixels().iHeight; case QPaintDevice::PdmWidthMM: { TInt twips = cfbsBitmap->SizeInTwips().iWidth; - return (int)(twips * (qreal(25.4) * div_by_KTwipsPerInch)); + return (int)(twips * (25.4/KTwipsPerInch)); } case QPaintDevice::PdmHeightMM: { TInt twips = cfbsBitmap->SizeInTwips().iHeight; - return (int)(twips * (qreal(25.4) * div_by_KTwipsPerInch)); + return (int)(twips * (25.4/KTwipsPerInch)); } case QPaintDevice::PdmNumColors: return TDisplayModeUtils::NumDisplayModeColors(cfbsBitmap->DisplayMode()); case QPaintDevice::PdmDpiX: case QPaintDevice::PdmPhysicalDpiX: { - qreal inches = cfbsBitmap->SizeInTwips().iWidth * div_by_KTwipsPerInch; + TReal inches = cfbsBitmap->SizeInTwips().iWidth / (TReal)KTwipsPerInch; TInt pixels = cfbsBitmap->SizeInPixels().iWidth; return pixels / inches; } case QPaintDevice::PdmDpiY: case QPaintDevice::PdmPhysicalDpiY: { - qreal inches = cfbsBitmap->SizeInTwips().iHeight * div_by_KTwipsPerInch; + TReal inches = cfbsBitmap->SizeInTwips().iHeight / (TReal)KTwipsPerInch; TInt pixels = cfbsBitmap->SizeInPixels().iHeight; return pixels / inches; } diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp index a52ba77..14c863b 100644 --- a/src/gui/image/qpnghandler.cpp +++ b/src/gui/image/qpnghandler.cpp @@ -732,8 +732,8 @@ bool Q_INTERNAL_WIN_NO_THROW QPNGImageWriter::writeImage(const QImage& image_in, png_set_compression_level(png_ptr, quality); } - if (gamma != qreal(0.0)) { - png_set_gAMA(png_ptr, info_ptr, qreal(1.0)/gamma); + if (gamma != 0.0) { + png_set_gAMA(png_ptr, info_ptr, 1.0/gamma); } png_set_write_fn(png_ptr, (void*)this, qpiw_write_fn, qpiw_flush_fn); diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index 031c5ef..2c3d616 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -40,7 +40,6 @@ ****************************************************************************/ #include "qmatrix4x4.h" -#include #include #include #include @@ -59,7 +58,7 @@ QT_BEGIN_NAMESPACE \sa QVector3D, QGenericMatrix */ -static const qreal inv_dist_to_plane = qreal(1.) / qreal(1024.); +static const qreal inv_dist_to_plane = 1. / 1024.; /*! \fn QMatrix4x4::QMatrix4x4() @@ -507,23 +506,22 @@ QMatrix4x4 QMatrix4x4::transposed() const */ QMatrix4x4& QMatrix4x4::operator/=(qreal divisor) { - const qreal inv_divisor = (1 / divisor); - m[0][0] *= inv_divisor; - m[0][1] *= inv_divisor; - m[0][2] *= inv_divisor; - m[0][3] *= inv_divisor; - m[1][0] *= inv_divisor; - m[1][1] *= inv_divisor; - m[1][2] *= inv_divisor; - m[1][3] *= inv_divisor; - m[2][0] *= inv_divisor; - m[2][1] *= inv_divisor; - m[2][2] *= inv_divisor; - m[2][3] *= inv_divisor; - m[3][0] *= inv_divisor; - m[3][1] *= inv_divisor; - m[3][2] *= inv_divisor; - m[3][3] *= inv_divisor; + m[0][0] /= divisor; + m[0][1] /= divisor; + m[0][2] /= divisor; + m[0][3] /= divisor; + m[1][0] /= divisor; + m[1][1] /= divisor; + m[1][2] /= divisor; + m[1][3] /= divisor; + m[2][0] /= divisor; + m[2][1] /= divisor; + m[2][2] /= divisor; + m[2][3] /= divisor; + m[3][0] /= divisor; + m[3][1] /= divisor; + m[3][2] /= divisor; + m[3][3] /= divisor; flagBits = General; return *this; } @@ -664,24 +662,23 @@ QMatrix4x4& QMatrix4x4::operator/=(qreal divisor) */ QMatrix4x4 operator/(const QMatrix4x4& matrix, qreal divisor) { - const qreal inv_divisor = (1 / divisor); QMatrix4x4 m(1); // The "1" says to not load the identity. - m.m[0][0] = matrix.m[0][0] * inv_divisor; - m.m[0][1] = matrix.m[0][1] * inv_divisor; - m.m[0][2] = matrix.m[0][2] * inv_divisor; - m.m[0][3] = matrix.m[0][3] * inv_divisor; - m.m[1][0] = matrix.m[1][0] * inv_divisor; - m.m[1][1] = matrix.m[1][1] * inv_divisor; - m.m[1][2] = matrix.m[1][2] * inv_divisor; - m.m[1][3] = matrix.m[1][3] * inv_divisor; - m.m[2][0] = matrix.m[2][0] * inv_divisor; - m.m[2][1] = matrix.m[2][1] * inv_divisor; - m.m[2][2] = matrix.m[2][2] * inv_divisor; - m.m[2][3] = matrix.m[2][3] * inv_divisor; - m.m[3][0] = matrix.m[3][0] * inv_divisor; - m.m[3][1] = matrix.m[3][1] * inv_divisor; - m.m[3][2] = matrix.m[3][2] * inv_divisor; - m.m[3][3] = matrix.m[3][3] * inv_divisor; + m.m[0][0] = matrix.m[0][0] / divisor; + m.m[0][1] = matrix.m[0][1] / divisor; + m.m[0][2] = matrix.m[0][2] / divisor; + m.m[0][3] = matrix.m[0][3] / divisor; + m.m[1][0] = matrix.m[1][0] / divisor; + m.m[1][1] = matrix.m[1][1] / divisor; + m.m[1][2] = matrix.m[1][2] / divisor; + m.m[1][3] = matrix.m[1][3] / divisor; + m.m[2][0] = matrix.m[2][0] / divisor; + m.m[2][1] = matrix.m[2][1] / divisor; + m.m[2][2] = matrix.m[2][2] / divisor; + m.m[2][3] = matrix.m[2][3] / divisor; + m.m[3][0] = matrix.m[3][0] / divisor; + m.m[3][1] = matrix.m[3][1] / divisor; + m.m[3][2] = matrix.m[3][2] / divisor; + m.m[3][3] = matrix.m[3][3] / divisor; return m; } @@ -1014,7 +1011,7 @@ void QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) s = 0.0f; c = -1.0f; } else { - qreal a = angle * Q_PI180; + qreal a = angle * M_PI / 180.0f; c = qCos(a); s = qSin(a); } @@ -1069,11 +1066,10 @@ void QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) if (!quick) { qreal len = x * x + y * y + z * z; if (!qFuzzyIsNull(len - 1.0f) && !qFuzzyIsNull(len)) { - const qreal inv_len = 1 / len; len = qSqrt(len); - x *= inv_len; - y *= inv_len; - z *= inv_len; + x /= len; + y /= len; + z /= len; } ic = 1.0f - c; m.m[0][0] = x * x * ic + c; @@ -1122,7 +1118,7 @@ void QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) s = 0.0f; c = -1.0f; } else { - qreal a = angle * Q_PI180; + qreal a = angle * M_PI / 180.0f; c = qCos(a); s = qSin(a); } @@ -1173,11 +1169,10 @@ void QMatrix4x4::projectedRotate(qreal angle, qreal x, qreal y, qreal z) if (!quick) { qreal len = x * x + y * y + z * z; if (!qFuzzyIsNull(len - 1.0f) && !qFuzzyIsNull(len)) { - const qreal inv_len = 1 / len; len = qSqrt(len); - x *= inv_len; - y *= inv_len; - z *= inv_len; + x /= len; + y /= len; + z /= len; } ic = 1.0f - c; m.m[0][0] = x * x * ic + c; @@ -1304,39 +1299,35 @@ void QMatrix4x4::ortho(qreal left, qreal right, qreal bottom, qreal top, qreal n qreal width = right - left; qreal invheight = top - bottom; qreal clip = farPlane - nearPlane; - qreal inv_width = 1 / width; - qreal inv_invheight = 1 / invheight; - qreal inv_clip = 1 / clip; #ifndef QT_NO_VECTOR3D if (clip == 2.0f && (nearPlane + farPlane) == 0.0f) { // We can express this projection as a translate and scale // which will be more efficient to modify with further // transformations than producing a "General" matrix. - translate(QVector3D - (-(left + right) * inv_width, - -(top + bottom) * inv_invheight, + (-(left + right) / width, + -(top + bottom) / invheight, 0.0f)); scale(QVector3D - (2.0f * inv_width, - 2.0f * inv_invheight, + (2.0f / width, + 2.0f / invheight, -1.0f)); return; } #endif QMatrix4x4 m(1); - m.m[0][0] = 2.0f * inv_width; + m.m[0][0] = 2.0f / width; m.m[1][0] = 0.0f; m.m[2][0] = 0.0f; - m.m[3][0] = -(left + right) * inv_width; + m.m[3][0] = -(left + right) / width; m.m[0][1] = 0.0f; - m.m[1][1] = 2.0f * inv_invheight; + m.m[1][1] = 2.0f / invheight; m.m[2][1] = 0.0f; - m.m[3][1] = -(top + bottom) * inv_invheight; + m.m[3][1] = -(top + bottom) / invheight; m.m[0][2] = 0.0f; m.m[1][2] = 0.0f; - m.m[2][2] = -2.0f * inv_clip; - m.m[3][2] = -(nearPlane + farPlane) * inv_clip; + m.m[2][2] = -2.0f / clip; + m.m[3][2] = -(nearPlane + farPlane) / clip; m.m[0][3] = 0.0f; m.m[1][3] = 0.0f; m.m[2][3] = 0.0f; @@ -1363,24 +1354,21 @@ void QMatrix4x4::frustum(qreal left, qreal right, qreal bottom, qreal top, qreal // Construct the projection. QMatrix4x4 m(1); - const qreal width = right - left; - const qreal invheight = top - bottom; - const qreal clip = farPlane - nearPlane; - const qreal inv_width = 1 / width; - const qreal inv_invheight = 1 / invheight; - const qreal inv_clip = 1 / clip; - m.m[0][0] = 2.0f * nearPlane * inv_width; + qreal width = right - left; + qreal invheight = top - bottom; + qreal clip = farPlane - nearPlane; + m.m[0][0] = 2.0f * nearPlane / width; m.m[1][0] = 0.0f; - m.m[2][0] = (left + right) * inv_width; + m.m[2][0] = (left + right) / width; m.m[3][0] = 0.0f; m.m[0][1] = 0.0f; - m.m[1][1] = 2.0f * nearPlane * inv_invheight; - m.m[2][1] = (top + bottom) * inv_invheight; + m.m[1][1] = 2.0f * nearPlane / invheight; + m.m[2][1] = (top + bottom) / invheight; m.m[3][1] = 0.0f; m.m[0][2] = 0.0f; m.m[1][2] = 0.0f; - m.m[2][2] = -(nearPlane + farPlane) * inv_clip; - m.m[3][2] = -2.0f * nearPlane * farPlane * inv_clip; + m.m[2][2] = -(nearPlane + farPlane) / clip; + m.m[3][2] = -2.0f * nearPlane * farPlane / clip; m.m[0][3] = 0.0f; m.m[1][3] = 0.0f; m.m[2][3] = -1.0f; @@ -1406,13 +1394,12 @@ void QMatrix4x4::perspective(qreal angle, qreal aspect, qreal nearPlane, qreal f // Construct the projection. QMatrix4x4 m(1); - const qreal radians = (angle * 0.5f) * Q_PI180; - const qreal sine = qSin(radians); + qreal radians = (angle / 2.0f) * M_PI / 180.0f; + qreal sine = qSin(radians); if (sine == 0.0f) return; - const qreal cotan = qCos(radians) / sine; - const qreal clip = farPlane - nearPlane; - const qreal inv_clip = 1 / clip; + qreal cotan = qCos(radians) / sine; + qreal clip = farPlane - nearPlane; m.m[0][0] = cotan / aspect; m.m[1][0] = 0.0f; m.m[2][0] = 0.0f; @@ -1423,8 +1410,8 @@ void QMatrix4x4::perspective(qreal angle, qreal aspect, qreal nearPlane, qreal f m.m[3][1] = 0.0f; m.m[0][2] = 0.0f; m.m[1][2] = 0.0f; - m.m[2][2] = -(nearPlane + farPlane) * inv_clip; - m.m[3][2] = -(2.0f * nearPlane * farPlane) * inv_clip; + m.m[2][2] = -(nearPlane + farPlane) / clip; + m.m[3][2] = -(2.0f * nearPlane * farPlane) / clip; m.m[0][3] = 0.0f; m.m[1][3] = 0.0f; m.m[2][3] = -1.0f; diff --git a/src/gui/math3d/qquaternion.cpp b/src/gui/math3d/qquaternion.cpp index da629e6..626cb3c 100644 --- a/src/gui/math3d/qquaternion.cpp +++ b/src/gui/math3d/qquaternion.cpp @@ -269,12 +269,11 @@ void QQuaternion::normalize() return; len = qSqrt(len); - const double inv_len = 1 / len; - xp *= inv_len; - yp *= inv_len; - zp *= inv_len; - wp *= inv_len; + xp /= len; + yp /= len; + zp /= len; + wp /= len; } /*! @@ -358,7 +357,7 @@ QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D& axis, qreal angle) // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q56 // We normalize the result just in case the values are close // to zero, as suggested in the above FAQ. - qreal a = (angle * 0.5f) * Q_PI180; + qreal a = (angle / 2.0f) * M_PI / 180.0f; qreal s = qSin(a); qreal c = qCos(a); QVector3D ax = axis.normalized(); @@ -376,12 +375,11 @@ QQuaternion QQuaternion::fromAxisAndAngle { qreal length = qSqrt(x * x + y * y + z * z); if (!qFuzzyIsNull(length - 1.0f) && !qFuzzyIsNull(length)) { - const qreal inv_length = 1 / length; - x *= inv_length; - y *= inv_length; - z *= inv_length; + x /= length; + y /= length; + z /= length; } - qreal a = (angle * 0.5f) * Q_PI180; + qreal a = (angle / 2.0f) * M_PI / 180.0f; qreal s = qSin(a); qreal c = qCos(a); return QQuaternion(c, x * s, y * s, z * s).normalized(); @@ -518,13 +516,12 @@ QQuaternion QQuaternion::slerp // then revert to simple linear interpolation. qreal factor1 = 1.0f - t; qreal factor2 = t; - if ((1.0f - dot) > qreal(0.0000001)) { + if ((1.0f - dot) > 0.0000001) { qreal angle = qreal(qAcos(dot)); qreal sinOfAngle = qreal(qSin(angle)); - if (sinOfAngle > qreal(0.0000001)) { - const qreal inv_sinOfAngle = 1 / sinOfAngle; - factor1 = qreal(qSin((1.0f - t) * angle)) * inv_sinOfAngle; - factor2 = qreal(qSin(t * angle)) * inv_sinOfAngle; + if (sinOfAngle > 0.0000001) { + factor1 = qreal(qSin((1.0f - t) * angle)) / sinOfAngle; + factor2 = qreal(qSin(t * angle)) / sinOfAngle; } } diff --git a/src/gui/math3d/qvector2d.cpp b/src/gui/math3d/qvector2d.cpp index a959979..2555a6f 100644 --- a/src/gui/math3d/qvector2d.cpp +++ b/src/gui/math3d/qvector2d.cpp @@ -216,9 +216,9 @@ void QVector2D::normalize() return; len = qSqrt(len); - const double inv_len = 1 / len; - xp *= inv_len; - yp *= inv_len; + + xp /= len; + yp /= len; } /*! diff --git a/src/gui/math3d/qvector3d.cpp b/src/gui/math3d/qvector3d.cpp index a8cc807..9552e3a 100644 --- a/src/gui/math3d/qvector3d.cpp +++ b/src/gui/math3d/qvector3d.cpp @@ -233,10 +233,10 @@ void QVector3D::normalize() return; len = qSqrt(len); - const double inv_len = 1 / len; - xp *= inv_len; - yp *= inv_len; - zp *= inv_len; + + xp /= len; + yp /= len; + zp /= len; } /*! diff --git a/src/gui/math3d/qvector4d.cpp b/src/gui/math3d/qvector4d.cpp index e4b2b82..1691a6d 100644 --- a/src/gui/math3d/qvector4d.cpp +++ b/src/gui/math3d/qvector4d.cpp @@ -285,11 +285,11 @@ void QVector4D::normalize() return; len = qSqrt(len); - const double inv_len = 1 / len; - xp *= inv_len; - yp *= inv_len; - zp *= inv_len; - wp *= inv_len; + + xp /= len; + yp /= len; + zp /= len; + wp /= len; } /*! @@ -459,8 +459,7 @@ QVector2D QVector4D::toVector2DAffine() const { if (qIsNull(wp)) return QVector2D(); - const qreal inv_wp = 1 / wp; - return QVector2D(xp * inv_wp, yp * inv_wp, 1); + return QVector2D(xp / wp, yp / wp, 1); } #endif @@ -487,8 +486,7 @@ QVector3D QVector4D::toVector3DAffine() const { if (qIsNull(wp)) return QVector3D(); - const qreal inv_wp = 1 / wp; - return QVector3D(xp * inv_wp, yp * inv_wp, zp * inv_wp, 1); + return QVector3D(xp / wp, yp / wp, zp / wp, 1); } #endif diff --git a/src/gui/painting/qbezier.cpp b/src/gui/painting/qbezier.cpp index c49086b..a6b4cef 100644 --- a/src/gui/painting/qbezier.cpp +++ b/src/gui/painting/qbezier.cpp @@ -62,10 +62,10 @@ QT_BEGIN_NAMESPACE #endif #ifndef M_SQRT2 -#define M_SQRT2 qreal(1.41421356237309504880) +#define M_SQRT2 1.41421356237309504880 #endif -#define log2(x) (qLn(qreal(x))/qLn(qreal(2.))) +#define log2(x) (qLn(x)/qLn(2.)) static inline qreal log4(qreal x) { @@ -132,7 +132,7 @@ static inline void flattenBezierWithoutInflections(QBezier &bez, qreal d = qAbs(dx * (bez.y3 - bez.y2) - dy * (bez.x3 - bez.x2)); - qreal t = qSqrt(qreal(4.) / qreal(3.) * normalized * flatness / d); + qreal t = qSqrt(4. / 3. * normalized * flatness / d); if (t > 1 || qFuzzyIsNull(t - (qreal)1.)) break; bez.parameterSplitLeft(t, &left); @@ -267,7 +267,7 @@ void QBezier::addToPolygonMixed(QPolygonF *polygon) const qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3); l = 1.; } - if (d < qreal(.5)*l || b == beziers + 31) { + if (d < .5*l || b == beziers + 31) { // good enough, we pop it off and add the endpoint polygon->append(QPointF(b->x4, b->y4)); --b; @@ -327,8 +327,8 @@ static ShiftResult good_offset(const QBezier *b1, const QBezier *b2, qreal offse const qreal o2 = offset*offset; const qreal max_dist_line = threshold*offset*offset; const qreal max_dist_normal = threshold*offset; - const qreal spacing = qreal(0.25); - for (qreal i = spacing; i < qreal(0.99); i += spacing) { + const qreal spacing = 0.25; + for (qreal i = spacing; i < 0.99; i += spacing) { QPointF p1 = b1->pointAt(i); QPointF p2 = b2->pointAt(i); qreal d = (p1.x() - p2.x())*(p1.x() - p2.x()) + (p1.y() - p2.y())*(p1.y() - p2.y()); @@ -337,7 +337,7 @@ static ShiftResult good_offset(const QBezier *b1, const QBezier *b2, qreal offse QPointF normalPoint = b1->normalVector(i); qreal l = qAbs(normalPoint.x()) + qAbs(normalPoint.y()); - if (l != qreal(0.)) { + if (l != 0.) { d = qAbs( normalPoint.x()*(p1.y() - p2.y()) - normalPoint.y()*(p1.x() - p2.x()) ) / l; if (d > max_dist_normal) return Split; @@ -418,14 +418,14 @@ static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qr } QRectF b = orig->bounds(); - if (np == 4 && b.width() < qreal(.1)*offset && b.height() < qreal(.1)*offset) { + if (np == 4 && b.width() < .1*offset && b.height() < .1*offset) { qreal l = (orig->x1 - orig->x2)*(orig->x1 - orig->x2) + (orig->y1 - orig->y2)*(orig->y1 - orig->y1) * (orig->x3 - orig->x4)*(orig->x3 - orig->x4) + (orig->y3 - orig->y4)*(orig->y3 - orig->y4); qreal dot = (orig->x1 - orig->x2)*(orig->x3 - orig->x4) + (orig->y1 - orig->y2)*(orig->y3 - orig->y4); - if (dot < 0 && dot*dot < qreal(0.8)*l) + if (dot < 0 && dot*dot < 0.8*l) // the points are close and reverse dirction. Approximate the whole // thing by a semi circle return Circle; @@ -444,7 +444,7 @@ static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qr QPointF normal_sum = prev_normal + next_normal; - qreal r = qreal(1.0) + prev_normal.x() * next_normal.x() + qreal r = 1.0 + prev_normal.x() * next_normal.x() + prev_normal.y() * next_normal.y(); if (qFuzzyIsNull(r)) { @@ -468,7 +468,7 @@ static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qr // This value is used to determine the length of control point vectors // when approximating arc segments as curves. The factor is multiplied // with the radius of the circle. -#define KAPPA qreal(0.5522847498) +#define KAPPA 0.5522847498 static bool addCircle(const QBezier *b, qreal offset, QBezier *o) @@ -490,32 +490,32 @@ static bool addCircle(const QBezier *b, qreal offset, QBezier *o) normals[1] /= -1*qSqrt(normals[1].x()*normals[1].x() + normals[1].y()*normals[1].y()); qreal angles[2]; - qreal sign = qreal(1.); + qreal sign = 1.; for (int i = 0; i < 2; ++i) { qreal cos_a = normals[i].x()*normals[i+1].x() + normals[i].y()*normals[i+1].y(); - if (cos_a > qreal(1.)) - cos_a = qreal(1.); - if (cos_a < qreal(-1.)) + if (cos_a > 1.) + cos_a = 1.; + if (cos_a < -1.) cos_a = -1; - angles[i] = qAcos(cos_a)/Q_PI; + angles[i] = acos(cos_a)/Q_PI; } - if (angles[0] + angles[1] > qreal(1.)) { + if (angles[0] + angles[1] > 1.) { // more than 180 degrees normals[1] = -normals[1]; - angles[0] = qreal(1.) - angles[0]; - angles[1] = qreal(1.) - angles[1]; - sign = qreal(-1.); + angles[0] = 1. - angles[0]; + angles[1] = 1. - angles[1]; + sign = -1.; } QPointF circle[3]; circle[0] = QPointF(b->x1, b->y1) + normals[0]*offset; - circle[1] = QPointF(qreal(0.5)*(b->x1 + b->x4), qreal(0.5)*(b->y1 + b->y4)) + normals[1]*offset; + circle[1] = QPointF(0.5*(b->x1 + b->x4), 0.5*(b->y1 + b->y4)) + normals[1]*offset; circle[2] = QPointF(b->x4, b->y4) + normals[2]*offset; for (int i = 0; i < 2; ++i) { - qreal kappa = qreal(2.)*KAPPA * sign * offset * angles[i]; + qreal kappa = 2.*KAPPA * sign * offset * angles[i]; o->x1 = circle[i].x(); o->y1 = circle[i].y(); @@ -695,7 +695,7 @@ static bool RecursivelyIntersect(const QBezier &a, qreal t0, qreal t1, int depth if (deptha > 0) { QBezier A[2]; a.split(&A[0], &A[1]); - qreal tmid = (t0+t1)*qreal(0.5); + qreal tmid = (t0+t1)*0.5; //qDebug()<<"\t1)"< 0) { QBezier B[2]; b.split(&B[0], &B[1]); - qreal umid = (u0 + u1)*qreal(0.5); + qreal umid = (u0 + u1)*0.5; depthb--; if (IntersectBB(a, B[0])) { //fprintf(stderr, "\t 7 from %d\n", currentD); @@ -783,13 +783,13 @@ static bool RecursivelyIntersect(const QBezier &a, qreal t0, qreal t1, int depth qreal xmk = b.x1 - a.x1; qreal ymk = b.y1 - a.y1; qreal det = xnm * ylk - ynm * xlk; - if (qreal(1.0) + det == qreal(1.0)) { + if (1.0 + det == 1.0) { return false; } else { qreal detinv = 1.0 / det; qreal rs = (xnm * ymk - ynm *xmk) * detinv; qreal rt = (xlk * ymk - ylk * xmk) * detinv; - if ((rs < qreal(0.0)) || (rs > qreal(1.0)) || (rt < qreal(0.0)) || (rt > qreal(1.0))) + if ((rs < 0.0) || (rs > 1.0) || (rt < 0.0) || (rt > 1.0)) return false; if (t) { @@ -816,17 +816,17 @@ bool QBezier::findIntersections(const QBezier &a, const QBezier &b, QVector > *t) { if (IntersectBB(a, b)) { - QPointF la1(qFabs((a.x3 - a.x2) - (a.x2 - a.x1)), - qFabs((a.y3 - a.y2) - (a.y2 - a.y1))); - QPointF la2(qFabs((a.x4 - a.x3) - (a.x3 - a.x2)), - qFabs((a.y4 - a.y3) - (a.y3 - a.y2))); + QPointF la1(fabs((a.x3 - a.x2) - (a.x2 - a.x1)), + fabs((a.y3 - a.y2) - (a.y2 - a.y1))); + QPointF la2(fabs((a.x4 - a.x3) - (a.x3 - a.x2)), + fabs((a.y4 - a.y3) - (a.y3 - a.y2))); QPointF la; if (la1.x() > la2.x()) la.setX(la1.x()); else la.setX(la2.x()); if (la1.y() > la2.y()) la.setY(la1.y()); else la.setY(la2.y()); - QPointF lb1(qFabs((b.x3 - b.x2) - (b.x2 - b.x1)), - qFabs((b.y3 - b.y2) - (b.y2 - b.y1))); - QPointF lb2(qFabs((b.x4 - b.x3) - (b.x3 - b.x2)), - qFabs((b.y4 - b.y3) - (b.y3 - b.y2))); + QPointF lb1(fabs((b.x3 - b.x2) - (b.x2 - b.x1)), + fabs((b.y3 - b.y2) - (b.y2 - b.y1))); + QPointF lb2(fabs((b.x4 - b.x3) - (b.x3 - b.x2)), + fabs((b.y4 - b.y3) - (b.y3 - b.y2))); QPointF lb; if (lb1.x() > lb2.x()) lb.setX(lb1.x()); else lb.setX(lb2.x()); if (lb1.y() > lb2.y()) lb.setY(lb1.y()); else lb.setY(lb2.y()); @@ -836,27 +836,27 @@ bool QBezier::findIntersections(const QBezier &a, const QBezier &b, else l0 = la.y(); int ra; - if (l0 * qreal(0.75) * M_SQRT2 + qreal(1.0) == qreal(1.0)) + if (l0 * 0.75 * M_SQRT2 + 1.0 == 1.0) ra = 0; else - ra = qCeil(log4(M_SQRT2 * qreal(6.0) / qreal(8.0) * INV_EPS * l0)); + ra = qCeil(log4(M_SQRT2 * 6.0 / 8.0 * INV_EPS * l0)); if (lb.x() > lb.y()) l0 = lb.x(); else l0 = lb.y(); int rb; - if (l0 * qreal(0.75) * M_SQRT2 + qreal(1.0) == qreal(1.0)) + if (l0 * 0.75 * M_SQRT2 + 1.0 == 1.0) rb = 0; else - rb = qCeil(log4(M_SQRT2 * qreal(6.0) / qreal(8.0) * INV_EPS * l0)); + rb = qCeil(log4(M_SQRT2 * 6.0 / 8.0 * INV_EPS * l0)); // if qreal is float then halve the number of subdivisions if (sizeof(qreal) == 4) { - ra *= qreal(0.5); - rb *= qreal(0.5); + ra /= 2; + rb /= 2; } - return RecursivelyIntersect(a, qreal(0.), qreal(1.), ra, b, qreal(0.), qreal(1.), rb, t); + return RecursivelyIntersect(a, 0., 1., ra, b, 0., 1., rb, t); } //Don't sort here because it breaks the orders of corresponding @@ -934,7 +934,7 @@ QVector< QList > QBezier::splitAtIntersections(QBezier &b) qreal QBezier::length(qreal error) const { - qreal length = qreal(0.0); + qreal length = 0.0; addIfClose(&length, error); @@ -945,7 +945,7 @@ void QBezier::addIfClose(qreal *length, qreal error) const { QBezier left, right; /* bez poly splits */ - qreal len = qreal(0.0); /* arc length */ + qreal len = 0.0; /* arc length */ qreal chord; /* chord length */ len = len + QLineF(QPointF(x1, y1),QPointF(x2, y2)).length(); @@ -988,7 +988,7 @@ qreal QBezier::tForY(qreal t0, qreal t1, qreal y) const qreal lt = t0; qreal dt; do { - qreal t = qreal(0.5) * (t0 + t1); + qreal t = 0.5 * (t0 + t1); qreal a, b, c, d; QBezier::coefficients(t, a, b, c, d); @@ -1054,15 +1054,15 @@ int QBezier::stationaryYPoints(qreal &t0, qreal &t1) const qreal QBezier::tAtLength(qreal l) const { qreal len = length(); - qreal t = qreal(1.0); - const qreal error = qreal(0.01); + qreal t = 1.0; + const qreal error = (qreal)0.01; if (l > len || qFuzzyCompare(l, len)) return t; - t *= qreal(0.5); + t *= 0.5; //int iters = 0; //qDebug()<<"LEN is "<x2 = (x1 + x2)*qreal(.5); - secondHalf->x3 = (x3 + x4)*qreal(.5); + qreal c = (x2 + x3)*.5; + firstHalf->x2 = (x1 + x2)*.5; + secondHalf->x3 = (x3 + x4)*.5; firstHalf->x1 = x1; secondHalf->x4 = x4; - firstHalf->x3 = (firstHalf->x2 + c)*qreal(.5); - secondHalf->x2 = (secondHalf->x3 + c)*qreal(.5); - firstHalf->x4 = secondHalf->x1 = (firstHalf->x3 + secondHalf->x2)*qreal(.5); + firstHalf->x3 = (firstHalf->x2 + c)*.5; + secondHalf->x2 = (secondHalf->x3 + c)*.5; + firstHalf->x4 = secondHalf->x1 = (firstHalf->x3 + secondHalf->x2)*.5; - c = (y2 + y3)*qreal(.5); - firstHalf->y2 = (y1 + y2)*qreal(.5); - secondHalf->y3 = (y3 + y4)*qreal(.5); + c = (y2 + y3)/2; + firstHalf->y2 = (y1 + y2)*.5; + secondHalf->y3 = (y3 + y4)*.5; firstHalf->y1 = y1; secondHalf->y4 = y4; - firstHalf->y3 = (firstHalf->y2 + c)*qreal(.5); - secondHalf->y2 = (secondHalf->y3 + c)*qreal(.5); - firstHalf->y4 = secondHalf->y1 = (firstHalf->y3 + secondHalf->y2)*qreal(.5); + firstHalf->y3 = (firstHalf->y2 + c)*.5; + secondHalf->y2 = (secondHalf->y3 + c)*.5; + firstHalf->y4 = secondHalf->y1 = (firstHalf->y3 + secondHalf->y2)*.5; } inline void QBezier::parameterSplitLeft(qreal t, QBezier *left) diff --git a/src/gui/painting/qblendfunctions.cpp b/src/gui/painting/qblendfunctions.cpp index 2d434d3..ba1b642 100644 --- a/src/gui/painting/qblendfunctions.cpp +++ b/src/gui/painting/qblendfunctions.cpp @@ -223,9 +223,13 @@ void qt_scale_image_16bit(uchar *destPixels, int dbpl, int h = ty2 - ty1; int w = tx2 - tx1; + quint32 basex; quint32 srcy; + const int dstx = qCeil((tx1 + 0.5 - qMin(targetRect.left(), targetRect.right())) * ix) - 1; + const int dsty = qCeil((ty1 + 0.5 - qMin(targetRect.top(), targetRect.bottom())) * iy) - 1; + if (sx < 0) { int dstx = qFloor((tx1 + qreal(0.5) - targetRect.right()) * ix) + 1; basex = quint32(srcRect.right() * 65536) + dstx; @@ -738,6 +742,10 @@ template void qt_scale_image_32bit(uchar *destPixels, int dbpl, quint32 basex; quint32 srcy; + const int dstx = qCeil((tx1 + 0.5 - qMin(targetRect.left(), targetRect.right())) * ix) - 1; + const int dsty = qCeil((ty1 + 0.5 - qMin(targetRect.top(), targetRect.bottom())) * iy) - 1; + + if (sx < 0) { int dstx = qFloor((tx1 + qreal(0.5) - targetRect.right()) * ix) + 1; basex = quint32(srcRect.right() * 65536) + dstx; @@ -842,8 +850,8 @@ void qt_transform_image_rasterize(DestT *destPixels, int dbpl, qreal rightSlope = (bottomRight.x - topRight.x) / (bottomRight.y - topRight.y); int dx_l = int(leftSlope * 0x10000); int dx_r = int(rightSlope * 0x10000); - int x_l = int((topLeft.x + (qreal(0.5) + fromY - topLeft.y) * leftSlope + qreal(0.5)) * 0x10000); - int x_r = int((topRight.x + (qreal(0.5) + fromY - topRight.y) * rightSlope + qreal(0.5)) * 0x10000); + int x_l = int((topLeft.x + (0.5 + fromY - topLeft.y) * leftSlope + 0.5) * 0x10000); + int x_r = int((topRight.x + (0.5 + fromY - topRight.y) * rightSlope + 0.5) * 0x10000); int fromX, toX, x1, x2, u, v, i, ii; DestT *line; @@ -1020,7 +1028,7 @@ void qt_transform_image(DestT *destPixels, int dbpl, if (det == 0) return; - qreal invDet = qreal(1.0) / det; + qreal invDet = 1.0 / det; qreal m11, m12, m21, m22, mdx, mdy; m11 = (u.u * w.y - u.y * w.u) * invDet; @@ -1034,8 +1042,8 @@ void qt_transform_image(DestT *destPixels, int dbpl, int dvdx = int(m21 * 0x10000); int dudy = int(m12 * 0x10000); int dvdy = int(m22 * 0x10000); - int u0 = qCeil((qreal(0.5) * m11 + qreal(0.5) * m12 + mdx) * 0x10000) - 1; - int v0 = qCeil((qreal(0.5) * m21 + qreal(0.5) * m22 + mdy) * 0x10000) - 1; + int u0 = qCeil((0.5 * m11 + 0.5 * m12 + mdx) * 0x10000) - 1; + int v0 = qCeil((0.5 * m21 + 0.5 * m22 + mdy) * 0x10000) - 1; int x1 = qFloor(sourceRect.left()); int y1 = qFloor(sourceRect.top()); diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index 9a8e09b..afe9986 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -1774,7 +1774,7 @@ static QPointF qt_radial_gradient_adapt_focal_point(const QPointF ¢er, // We have a one pixel buffer zone to avoid numerical instability on the // circle border //### this is hacky because technically we should adjust based on current matrix - const qreal compensated_radius = radius - radius * qreal(0.001); + const qreal compensated_radius = radius - radius * 0.001; QLineF line(center, focalPoint); if (line.length() > (compensated_radius)) line.setLength(compensated_radius); diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp index acbad3e..4da993b 100644 --- a/src/gui/painting/qcolor.cpp +++ b/src/gui/painting/qcolor.cpp @@ -604,13 +604,12 @@ void QColor::getHsvF(qreal *h, qreal *s, qreal *v, qreal *a) const return; } - const qreal inv_USHRT_MAX = 1 / qreal(USHRT_MAX); - *h = ct.ahsv.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsv.hue / qreal(36000.0); - *s = ct.ahsv.saturation * inv_USHRT_MAX; - *v = ct.ahsv.value * inv_USHRT_MAX; + *h = ct.ahsv.hue == USHRT_MAX ? -1.0 : ct.ahsv.hue / 36000.0; + *s = ct.ahsv.saturation / qreal(USHRT_MAX); + *v = ct.ahsv.value / qreal(USHRT_MAX); if (a) - *a = ct.ahsv.alpha * inv_USHRT_MAX; + *a = ct.ahsv.alpha / qreal(USHRT_MAX); } /*! @@ -716,13 +715,12 @@ void QColor::getHslF(qreal *h, qreal *s, qreal *l, qreal *a) const return; } - const qreal inv_USHRT_MAX = 1 / qreal(USHRT_MAX); - *h = ct.ahsl.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsl.hue / qreal(36000.0); - *s = ct.ahsl.saturation * inv_USHRT_MAX; - *l = ct.ahsl.lightness * inv_USHRT_MAX; + *h = ct.ahsl.hue == USHRT_MAX ? -1.0 : ct.ahsl.hue / 36000.0; + *s = ct.ahsl.saturation / qreal(USHRT_MAX); + *l = ct.ahsl.lightness / qreal(USHRT_MAX); if (a) - *a = ct.ahsl.alpha * inv_USHRT_MAX; + *a = ct.ahsl.alpha / qreal(USHRT_MAX); } /*! @@ -1302,7 +1300,7 @@ qreal QColor::hsvHueF() const { if (cspec != Invalid && cspec != Hsv) return toHsv().hueF(); - return ct.ahsv.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsv.hue / qreal(36000.0); + return ct.ahsv.hue == USHRT_MAX ? -1.0 : ct.ahsv.hue / 36000.0; } /*! @@ -1398,7 +1396,7 @@ qreal QColor::hslHueF() const { if (cspec != Invalid && cspec != Hsl) return toHsl().hslHueF(); - return ct.ahsl.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsl.hue / qreal(36000.0); + return ct.ahsl.hue == USHRT_MAX ? -1.0 : ct.ahsl.hue / 36000.0; } /*! @@ -1549,8 +1547,6 @@ QColor QColor::toRgb() const color.ct.argb.alpha = ct.argb.alpha; color.ct.argb.pad = 0; - const qreal inv_USHRT_MAX = 1 / qreal(USHRT_MAX); - switch (cspec) { case Hsv: { @@ -1561,15 +1557,15 @@ QColor QColor::toRgb() const } // chromatic case - const qreal h = ct.ahsv.hue == 36000 ? 0 : ct.ahsv.hue / qreal(6000.); - const qreal s = ct.ahsv.saturation * inv_USHRT_MAX; - const qreal v = ct.ahsv.value * inv_USHRT_MAX; + const qreal h = ct.ahsv.hue == 36000 ? 0 : ct.ahsv.hue / 6000.; + const qreal s = ct.ahsv.saturation / qreal(USHRT_MAX); + const qreal v = ct.ahsv.value / qreal(USHRT_MAX); const int i = int(h); const qreal f = h - i; - const qreal p = v * (qreal(1.0) - s); + const qreal p = v * (1.0 - s); if (i & 1) { - const qreal q = v * (qreal(1.0) - (s * f)); + const qreal q = v * (1.0 - (s * f)); switch (i) { case 1: @@ -1589,7 +1585,7 @@ QColor QColor::toRgb() const break; } } else { - const qreal t = v * (qreal(1.0) - (s * (qreal(1.0) - f))); + const qreal t = v * (1.0 - (s * (1.0 - f))); switch (i) { case 0: @@ -1621,9 +1617,9 @@ QColor QColor::toRgb() const color.ct.argb.red = color.ct.argb.green = color.ct.argb.blue = 0; } else { // chromatic case - const qreal h = ct.ahsl.hue == 36000 ? 0 : ct.ahsl.hue / qreal(36000.); - const qreal s = ct.ahsl.saturation * inv_USHRT_MAX; - const qreal l = ct.ahsl.lightness * inv_USHRT_MAX; + const qreal h = ct.ahsl.hue == 36000 ? 0 : ct.ahsl.hue / 36000.; + const qreal s = ct.ahsl.saturation / qreal(USHRT_MAX); + const qreal l = ct.ahsl.lightness / qreal(USHRT_MAX); qreal temp2; if (l < qreal(0.5)) @@ -1660,14 +1656,14 @@ QColor QColor::toRgb() const } case Cmyk: { - const qreal c = ct.acmyk.cyan * inv_USHRT_MAX; - const qreal m = ct.acmyk.magenta * inv_USHRT_MAX; - const qreal y = ct.acmyk.yellow * inv_USHRT_MAX; - const qreal k = ct.acmyk.black * inv_USHRT_MAX; - - color.ct.argb.red = qRound((qreal(1.0) - (c * (qreal(1.0) - k) + k)) * USHRT_MAX); - color.ct.argb.green = qRound((qreal(1.0) - (m * (qreal(1.0) - k) + k)) * USHRT_MAX); - color.ct.argb.blue = qRound((qreal(1.0) - (y * (qreal(1.0) - k) + k)) * USHRT_MAX); + const qreal c = ct.acmyk.cyan / qreal(USHRT_MAX); + const qreal m = ct.acmyk.magenta / qreal(USHRT_MAX); + const qreal y = ct.acmyk.yellow / qreal(USHRT_MAX); + const qreal k = ct.acmyk.black / qreal(USHRT_MAX); + + color.ct.argb.red = qRound((1.0 - (c * (1.0 - k) + k)) * USHRT_MAX); + color.ct.argb.green = qRound((1.0 - (m * (1.0 - k) + k)) * USHRT_MAX); + color.ct.argb.blue = qRound((1.0 - (y * (1.0 - k) + k)) * USHRT_MAX); break; } default: @@ -1701,10 +1697,9 @@ QColor QColor::toHsv() const color.ct.ahsv.alpha = ct.argb.alpha; color.ct.ahsv.pad = 0; - const qreal inv_USHRT_MAX = 1 / qreal(USHRT_MAX); - const qreal r = ct.argb.red * inv_USHRT_MAX; - const qreal g = ct.argb.green * inv_USHRT_MAX; - const qreal b = ct.argb.blue * inv_USHRT_MAX; + const qreal r = ct.argb.red / qreal(USHRT_MAX); + const qreal g = ct.argb.green / qreal(USHRT_MAX); + const qreal b = ct.argb.blue / qreal(USHRT_MAX); const qreal max = Q_MAX_3(r, g, b); const qreal min = Q_MIN_3(r, g, b); const qreal delta = max - min; @@ -1720,15 +1715,15 @@ QColor QColor::toHsv() const if (qFuzzyCompare(r, max)) { hue = ((g - b) /delta); } else if (qFuzzyCompare(g, max)) { - hue = (qreal(2.0) + (b - r) / delta); + hue = (2.0 + (b - r) / delta); } else if (qFuzzyCompare(b, max)) { - hue = (qreal(4.0) + (r - g) / delta); + hue = (4.0 + (r - g) / delta); } else { Q_ASSERT_X(false, "QColor::toHsv", "internal error"); } - hue *= qreal(60.0); - if (hue < qreal(0.0)) - hue += qreal(360.0); + hue *= 60.0; + if (hue < 0.0) + hue += 360.0; color.ct.ahsv.hue = qRound(hue * 100); } @@ -1809,10 +1804,9 @@ QColor QColor::toCmyk() const color.ct.acmyk.alpha = ct.argb.alpha; // rgb -> cmy - const qreal inv_USHRT_MAX = 1 / qreal(USHRT_MAX); - const qreal r = ct.argb.red * inv_USHRT_MAX; - const qreal g = ct.argb.green * inv_USHRT_MAX; - const qreal b = ct.argb.blue * inv_USHRT_MAX; + const qreal r = ct.argb.red / qreal(USHRT_MAX); + const qreal g = ct.argb.green / qreal(USHRT_MAX); + const qreal b = ct.argb.blue / qreal(USHRT_MAX); qreal c = 1.0 - r; qreal m = 1.0 - g; qreal y = 1.0 - b; @@ -1821,10 +1815,9 @@ QColor QColor::toCmyk() const const qreal k = qMin(c, qMin(m, y)); if (!qFuzzyIsNull(k - 1)) { - const qreal div_by_one_minus_k = 1 / (qreal(1.0) - k); - c = (c - k) * div_by_one_minus_k; - m = (m - k) * div_by_one_minus_k; - y = (y - k) * div_by_one_minus_k; + c = (c - k) / (1.0 - k); + m = (m - k) / (1.0 - k); + y = (y - k) / (1.0 - k); } color.ct.acmyk.cyan = qRound(c * USHRT_MAX); diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index 8d7a15d..4df7f8a 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -565,8 +565,8 @@ const uint * QT_FASTCALL fetchTransformed(uint *buffer, const Operator *, const int image_width = data->texture.width; int image_height = data->texture.height; - const qreal cx = x + qreal(0.5); - const qreal cy = y + qreal(0.5); + const qreal cx = x + 0.5; + const qreal cy = y + 0.5; const uint *end = buffer + length; uint *b = buffer; @@ -670,8 +670,8 @@ const uint * QT_FASTCALL fetchTransformedBilinear(uint *buffer, const Operator * int image_width = data->texture.width; int image_height = data->texture.height; - const qreal cx = x + qreal(0.5); - const qreal cy = y + qreal(0.5); + const qreal cx = x + 0.5; + const qreal cy = y + 0.5; const uint *end = buffer + length; uint *b = buffer; @@ -747,8 +747,8 @@ const uint * QT_FASTCALL fetchTransformedBilinear(uint *buffer, const Operator * while (b < end) { const qreal iw = fw == 0 ? 1 : 1 / fw; - const qreal px = fx * iw - qreal(0.5); - const qreal py = fy * iw - qreal(0.5); + const qreal px = fx * iw - 0.5; + const qreal py = fy * iw - 0.5; int x1 = int(px) - (px < 0); int x2 = x1 + 1; @@ -927,7 +927,7 @@ static const SourceFetchProc sourceFetch[NBlendTypes][QImage::NImageFormats] = { static inline uint qt_gradient_pixel(const QGradientData *data, qreal pos) { - int ipos = int(pos * (GRADIENT_STOPTABLE_SIZE - 1) + qreal(0.5)); + int ipos = int(pos * (GRADIENT_STOPTABLE_SIZE - 1) + 0.5); // calculate the actual offset. if (ipos < 0 || ipos >= GRADIENT_STOPTABLE_SIZE) { @@ -1008,8 +1008,8 @@ static const uint * QT_FASTCALL fetchLinearGradient(uint *buffer, const Operator if (op->linear.l == 0) { t = inc = 0; } else { - rx = data->m21 * (y + qreal(0.5)) + data->m11 * (x + qreal(0.5)) + data->dx; - ry = data->m22 * (y + qreal(0.5)) + data->m12 * (x + qreal(0.5)) + data->dy; + rx = data->m21 * (y + 0.5) + data->m11 * (x + 0.5) + data->dx; + ry = data->m22 * (y + 0.5) + data->m12 * (x + 0.5) + data->dy; t = op->linear.dx*rx + op->linear.dy*ry + op->linear.off; inc = op->linear.dx * data->m11 + op->linear.dy * data->m12; affine = !data->m13 && !data->m23; @@ -1045,7 +1045,7 @@ static const uint * QT_FASTCALL fetchLinearGradient(uint *buffer, const Operator } } } else { // fall back to float math here as well - qreal rw = data->m23 * (y + qreal(0.5)) + data->m13 * (x + qreal(0.5)) + data->m33; + qreal rw = data->m23 * (y + 0.5) + data->m13 * (x + 0.5) + data->m33; while (buffer < end) { qreal x = rx/rw; qreal y = ry/rw; @@ -1092,10 +1092,10 @@ static const uint * QT_FASTCALL fetchRadialGradient(uint *buffer, const Operator int y, int x, int length) { const uint *b = buffer; - qreal rx = data->m21 * (y + qreal(0.5)) - + data->dx + data->m11 * (x + qreal(0.5)); - qreal ry = data->m22 * (y + qreal(0.5)) - + data->dy + data->m12 * (x + qreal(0.5)); + qreal rx = data->m21 * (y + 0.5) + + data->dx + data->m11 * (x + 0.5); + qreal ry = data->m22 * (y + 0.5) + + data->dy + data->m12 * (x + 0.5); bool affine = !data->m13 && !data->m23; //qreal r = data->gradient.radial.radius; @@ -1141,8 +1141,8 @@ static const uint * QT_FASTCALL fetchRadialGradient(uint *buffer, const Operator ++buffer; } } else { - qreal rw = data->m23 * (y + qreal(0.5)) - + data->m33 + data->m13 * (x + qreal(0.5)); + qreal rw = data->m23 * (y + 0.5) + + data->m33 + data->m13 * (x + 0.5); if (!rw) rw = 1; while (buffer < end) { @@ -1171,10 +1171,10 @@ static const uint * QT_FASTCALL fetchConicalGradient(uint *buffer, const Operato int y, int x, int length) { const uint *b = buffer; - qreal rx = data->m21 * (y + qreal(0.5)) - + data->dx + data->m11 * (x + qreal(0.5)); - qreal ry = data->m22 * (y + qreal(0.5)) - + data->dy + data->m12 * (x + qreal(0.5)); + qreal rx = data->m21 * (y + 0.5) + + data->dx + data->m11 * (x + 0.5); + qreal ry = data->m22 * (y + 0.5) + + data->dy + data->m12 * (x + 0.5); bool affine = !data->m13 && !data->m23; const uint *end = buffer + length; @@ -1182,25 +1182,25 @@ static const uint * QT_FASTCALL fetchConicalGradient(uint *buffer, const Operato rx -= data->gradient.conical.center.x; ry -= data->gradient.conical.center.y; while (buffer < end) { - qreal angle = qAtan2(ry, rx) + data->gradient.conical.angle; + qreal angle = atan2(ry, rx) + data->gradient.conical.angle; - *buffer = qt_gradient_pixel(&data->gradient, 1 - angle / Q_2PI); + *buffer = qt_gradient_pixel(&data->gradient, 1 - angle / (2*Q_PI)); rx += data->m11; ry += data->m12; ++buffer; } } else { - qreal rw = data->m23 * (y + qreal(0.5)) - + data->m33 + data->m13 * (x + qreal(0.5)); + qreal rw = data->m23 * (y + 0.5) + + data->m33 + data->m13 * (x + 0.5); if (!rw) rw = 1; while (buffer < end) { - qreal angle = qAtan2(ry/rw - data->gradient.conical.center.x, + qreal angle = atan2(ry/rw - data->gradient.conical.center.x, rx/rw - data->gradient.conical.center.y) + data->gradient.conical.angle; - *buffer = qt_gradient_pixel(&data->gradient, qreal(1.) - angle / Q_2PI); + *buffer = qt_gradient_pixel(&data->gradient, 1. - angle / (2*Q_PI)); rx += data->m11; ry += data->m12; @@ -5166,8 +5166,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_argb(int count, const uint *target = ((uint *)t) + spans->x; uint *image_bits = (uint *)data->texture.imageData; - const qreal cx = spans->x + qreal(0.5); - const qreal cy = spans->y + qreal(0.5); + const qreal cx = spans->x + 0.5; + const qreal cy = spans->y + 0.5; int x = int((data->m21 * cy + data->m11 * cx + data->dx) * fixed_scale) - half_point; @@ -5241,8 +5241,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_argb(int count, const uint *target = ((uint *)t) + spans->x; uint *image_bits = (uint *)data->texture.imageData; - const qreal cx = spans->x + qreal(0.5); - const qreal cy = spans->y + qreal(0.5); + const qreal cx = spans->x + 0.5; + const qreal cy = spans->y + 0.5; qreal x = data->m21 * cy + data->m11 * cx + data->dx; qreal y = data->m22 * cy + data->m12 * cx + data->dy; @@ -5256,8 +5256,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_argb(int count, const uint *b = buffer; while (b < end) { const qreal iw = w == 0 ? 1 : 1 / w; - const qreal px = x * iw - qreal(0.5); - const qreal py = y * iw - qreal(0.5); + const qreal px = x * iw - 0.5; + const qreal py = y * iw - 0.5; int x1 = int(px) - (px < 0); int x2 = x1 + 1; @@ -5668,8 +5668,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_tiled_argb(int count, uint *target = ((uint *)t) + spans->x; uint *image_bits = (uint *)data->texture.imageData; - const qreal cx = spans->x + qreal(0.5); - const qreal cy = spans->y + qreal(0.5); + const qreal cx = spans->x + 0.5; + const qreal cy = spans->y + 0.5; int x = int((data->m21 * cy + data->m11 * cx + data->dx) * fixed_scale) - half_point; @@ -5751,8 +5751,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_tiled_argb(int count, uint *target = ((uint *)t) + spans->x; uint *image_bits = (uint *)data->texture.imageData; - const qreal cx = spans->x + qreal(0.5); - const qreal cy = spans->y + qreal(0.5); + const qreal cx = spans->x + 0.5; + const qreal cy = spans->y + 0.5; qreal x = data->m21 * cy + data->m11 * cx + data->dx; qreal y = data->m22 * cy + data->m12 * cx + data->dy; @@ -5766,8 +5766,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_tiled_argb(int count, uint *b = buffer; while (b < end) { const qreal iw = w == 0 ? 1 : 1 / w; - const qreal px = x * iw - qreal(0.5); - const qreal py = y * iw - qreal(0.5); + const qreal px = x * iw - 0.5; + const qreal py = y * iw - 0.5; int x1 = int(px) - (px < 0); int x2 = x1 + 1; @@ -5859,8 +5859,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_argb(int count, const QSpan *s uint *target = ((uint *)t) + spans->x; uint *image_bits = (uint *)data->texture.imageData; - const qreal cx = spans->x + qreal(0.5); - const qreal cy = spans->y + qreal(0.5); + const qreal cx = spans->x + 0.5; + const qreal cy = spans->y + 0.5; int x = int((data->m21 * cy + data->m11 * cx + data->dx) * fixed_scale); @@ -5907,8 +5907,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_argb(int count, const QSpan *s uint *target = ((uint *)t) + spans->x; uint *image_bits = (uint *)data->texture.imageData; - const qreal cx = spans->x + qreal(0.5); - const qreal cy = spans->y + qreal(0.5); + const qreal cx = spans->x + 0.5; + const qreal cy = spans->y + 0.5; qreal x = data->m21 * cy + data->m11 * cx + data->dx; qreal y = data->m22 * cy + data->m12 * cx + data->dy; @@ -6259,8 +6259,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_tiled_argb(int count, const QS uint *target = ((uint *)t) + spans->x; uint *image_bits = (uint *)data->texture.imageData; - const qreal cx = spans->x + qreal(0.5); - const qreal cy = spans->y + qreal(0.5); + const qreal cx = spans->x + 0.5; + const qreal cy = spans->y + 0.5; int x = int((data->m21 * cy + data->m11 * cx + data->dx) * fixed_scale); @@ -6311,8 +6311,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_tiled_argb(int count, const QS uint *target = ((uint *)t) + spans->x; uint *image_bits = (uint *)data->texture.imageData; - const qreal cx = spans->x + qreal(0.5); - const qreal cy = spans->y + qreal(0.5); + const qreal cx = spans->x + 0.5; + const qreal cy = spans->y + 0.5; qreal x = data->m21 * cy + data->m11 * cx + data->dx; qreal y = data->m22 * cy + data->m12 * cx + data->dy; @@ -6996,7 +6996,7 @@ static void qt_gradient_quint32(int count, const QSpan *spans, void *userData) */ const int gss = GRADIENT_STOPTABLE_SIZE - 1; int yinc = int((linear.dy * data->m22 * gss) * FIXPT_SIZE); - int off = int((((linear.dy * (data->m22 * qreal(0.5) + data->dy) + linear.off) * gss) * FIXPT_SIZE)); + int off = int((((linear.dy * (data->m22 * 0.5 + data->dy) + linear.off) * gss) * FIXPT_SIZE)); while (count--) { int y = spans->y; @@ -7044,7 +7044,7 @@ static void qt_gradient_quint16(int count, const QSpan *spans, void *userData) */ const int gss = GRADIENT_STOPTABLE_SIZE - 1; int yinc = int((linear.dy * data->m22 * gss) * FIXPT_SIZE); - int off = int((((linear.dy * (data->m22 * qreal(0.5) + data->dy) + linear.off) * gss) * FIXPT_SIZE)); + int off = int((((linear.dy * (data->m22 * 0.5 + data->dy) + linear.off) * gss) * FIXPT_SIZE)); uint oldColor = data->solid.color; while (count--) { @@ -7123,13 +7123,13 @@ void qt_build_pow_tables() { #ifdef Q_WS_MAC // decided by testing a few things on an iMac, should probably get this from the // system... - smoothing = qreal(2.0); + smoothing = 2.0; #endif #ifdef Q_WS_WIN int winSmooth; if (SystemParametersInfo(0x200C /* SPI_GETFONTSMOOTHINGCONTRAST */, 0, &winSmooth, 0)) - smoothing = winSmooth / qreal(1000.0); + smoothing = winSmooth / 1000.0; #endif #ifdef Q_WS_X11 @@ -7139,19 +7139,18 @@ void qt_build_pow_tables() { qt_pow_rgb_invgamma[i] = uchar(i); } #else - const qreal inv_255 = 1 / qreal(255.0); for (int i=0; i<256; ++i) { - qt_pow_rgb_gamma[i] = uchar(qRound(qPow(i * inv_255, smoothing) * 255)); - qt_pow_rgb_invgamma[i] = uchar(qRound(qPow(i * inv_255, 1 / smoothing) * 255)); + qt_pow_rgb_gamma[i] = uchar(qRound(pow(i / qreal(255.0), smoothing) * 255)); + qt_pow_rgb_invgamma[i] = uchar(qRound(pow(i / qreal(255.), 1 / smoothing) * 255)); } #endif #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) - const qreal gray_gamma = qreal(2.31); + const qreal gray_gamma = 2.31; for (int i=0; i<256; ++i) - qt_pow_gamma[i] = uint(qRound(qPow(i / qreal(255.), gray_gamma) * 2047)); + qt_pow_gamma[i] = uint(qRound(pow(i / qreal(255.), gray_gamma) * 2047)); for (int i=0; i<2048; ++i) - qt_pow_invgamma[i] = uchar(qRound(qPow(i / qreal(2047.0), 1 / gray_gamma) * 255)); + qt_pow_invgamma[i] = uchar(qRound(pow(i / 2047.0, 1 / gray_gamma) * 255)); #endif } diff --git a/src/gui/painting/qdrawutil.cpp b/src/gui/painting/qdrawutil.cpp index be9061f..1182b9a 100644 --- a/src/gui/painting/qdrawutil.cpp +++ b/src/gui/painting/qdrawutil.cpp @@ -1180,48 +1180,46 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin for (int i = 2; i < rows - 1; ++i) yTarget[i] = yTarget[i - 1] + dy; - const qreal inv_d_source_width = 1 / (qreal)d.source.width(); - const qreal inv_d_source_height = 1 / (qreal)d.source.height(); // corners if (targetMargins.top() > 0 && targetMargins.left() > 0 && sourceMargins.top() > 0 && sourceMargins.left() > 0) { // top left d.point.setX(0.5 * (xTarget[1] + xTarget[0])); d.point.setY(0.5 * (yTarget[1] + yTarget[0])); d.source = QRectF(sourceRect.left(), sourceRect.top(), sourceMargins.left(), sourceMargins.top()); - d.scaleX = qreal(xTarget[1] - xTarget[0]) * inv_d_source_width; - d.scaleY = qreal(yTarget[1] - yTarget[0]) * inv_d_source_height; + d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.source.width(); + d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.source.height(); if (hints & QDrawBorderPixmap::OpaqueTopLeft) opaqueData.append(d); else translucentData.append(d); } if (targetMargins.top() > 0 && targetMargins.right() > 0 && sourceMargins.top() > 0 && sourceMargins.right() > 0) { // top right - d.point.setX(qreal(0.5) * (xTarget[columns] + xTarget[columns - 1])); - d.point.setY(qreal(0.5) * (yTarget[1] + yTarget[0])); + d.point.setX(0.5 * (xTarget[columns] + xTarget[columns - 1])); + d.point.setY(0.5 * (yTarget[1] + yTarget[0])); d.source = QRectF(sourceCenterRight, sourceRect.top(), sourceMargins.right(), sourceMargins.top()); - d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) * inv_d_source_width; - d.scaleY = qreal(yTarget[1] - yTarget[0]) * inv_d_source_height; + d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.source.width(); + d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.source.height(); if (hints & QDrawBorderPixmap::OpaqueTopRight) opaqueData.append(d); else translucentData.append(d); } if (targetMargins.bottom() > 0 && targetMargins.left() > 0 && sourceMargins.bottom() > 0 && sourceMargins.left() > 0) { // bottom left - d.point.setX(qreal(0.5) * (xTarget[1] + xTarget[0])); - d.point.setY(qreal(0.5) * (yTarget[rows] + yTarget[rows - 1])); + d.point.setX(0.5 * (xTarget[1] + xTarget[0])); + d.point.setY(0.5 * (yTarget[rows] + yTarget[rows - 1])); d.source = QRectF(sourceRect.left(), sourceCenterBottom, sourceMargins.left(), sourceMargins.bottom()); - d.scaleX = qreal(xTarget[1] - xTarget[0]) * inv_d_source_width; - d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) * inv_d_source_height; + d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.source.width(); + d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.source.height(); if (hints & QDrawBorderPixmap::OpaqueBottomLeft) opaqueData.append(d); else translucentData.append(d); } if (targetMargins.bottom() > 0 && targetMargins.right() > 0 && sourceMargins.bottom() > 0 && sourceMargins.right() > 0) { // bottom right - d.point.setX(qreal(0.5) * (xTarget[columns] + xTarget[columns - 1])); - d.point.setY(qreal(0.5) * (yTarget[rows] + yTarget[rows - 1])); + d.point.setX(0.5 * (xTarget[columns] + xTarget[columns - 1])); + d.point.setY(0.5 * (yTarget[rows] + yTarget[rows - 1])); d.source = QRectF(sourceCenterRight, sourceCenterBottom, sourceMargins.right(), sourceMargins.bottom()); - d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) * inv_d_source_width; - d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) * inv_d_source_height; + d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.source.width(); + d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.source.height(); if (hints & QDrawBorderPixmap::OpaqueBottomRight) opaqueData.append(d); else @@ -1233,11 +1231,11 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin if (targetMargins.top() > 0 && sourceMargins.top() > 0) { // top QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueTop ? opaqueData : translucentData; d.source = QRectF(sourceCenterLeft, sourceRect.top(), sourceCenterWidth, sourceMargins.top()); - d.point.setY(qreal(0.5) * (yTarget[1] + yTarget[0])); - d.scaleX = dx * inv_d_source_width; - d.scaleY = qreal(yTarget[1] - yTarget[0]) * inv_d_source_height; + d.point.setY(0.5 * (yTarget[1] + yTarget[0])); + d.scaleX = dx / d.source.width(); + d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.source.height(); for (int i = 1; i < columns - 1; ++i) { - d.point.setX(qreal(0.5) * (xTarget[i + 1] + xTarget[i])); + d.point.setX(0.5 * (xTarget[i + 1] + xTarget[i])); data.append(d); } if (rules.horizontal == Qt::RepeatTile) @@ -1246,11 +1244,11 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin if (targetMargins.bottom() > 0 && sourceMargins.bottom() > 0) { // bottom QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueBottom ? opaqueData : translucentData; d.source = QRectF(sourceCenterLeft, sourceCenterBottom, sourceCenterWidth, sourceMargins.bottom());; - d.point.setY(qreal(0.5) * (yTarget[rows] + yTarget[rows - 1])); - d.scaleX = dx * inv_d_source_width; - d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) * inv_d_source_height; + d.point.setY(0.5 * (yTarget[rows] + yTarget[rows - 1])); + d.scaleX = dx / d.source.width(); + d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.source.height(); for (int i = 1; i < columns - 1; ++i) { - d.point.setX(qreal(0.5) * (xTarget[i + 1] + xTarget[i])); + d.point.setX(0.5 * (xTarget[i + 1] + xTarget[i])); data.append(d); } if (rules.horizontal == Qt::RepeatTile) @@ -1263,11 +1261,11 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin if (targetMargins.left() > 0 && sourceMargins.left() > 0) { // left QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueLeft ? opaqueData : translucentData; d.source = QRectF(sourceRect.left(), sourceCenterTop, sourceMargins.left(), sourceCenterHeight); - d.point.setX(qreal(0.5) * (xTarget[1] + xTarget[0])); - d.scaleX = qreal(xTarget[1] - xTarget[0]) * inv_d_source_width; - d.scaleY = dy * inv_d_source_height; + d.point.setX(0.5 * (xTarget[1] + xTarget[0])); + d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.source.width(); + d.scaleY = dy / d.source.height(); for (int i = 1; i < rows - 1; ++i) { - d.point.setY(qreal(0.5) * (yTarget[i + 1] + yTarget[i])); + d.point.setY(0.5 * (yTarget[i + 1] + yTarget[i])); data.append(d); } if (rules.vertical == Qt::RepeatTile) @@ -1276,11 +1274,11 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin if (targetMargins.right() > 0 && sourceMargins.right() > 0) { // right QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueRight ? opaqueData : translucentData; d.source = QRectF(sourceCenterRight, sourceCenterTop, sourceMargins.right(), sourceCenterHeight); - d.point.setX(qreal(0.5) * (xTarget[columns] + xTarget[columns - 1])); - d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) * inv_d_source_width; - d.scaleY = dy * inv_d_source_height; + d.point.setX(0.5 * (xTarget[columns] + xTarget[columns - 1])); + d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.source.width(); + d.scaleY = dy / d.source.height(); for (int i = 1; i < rows - 1; ++i) { - d.point.setY(qreal(0.5) * (yTarget[i + 1] + yTarget[i])); + d.point.setY(0.5 * (yTarget[i + 1] + yTarget[i])); data.append(d); } if (rules.vertical == Qt::RepeatTile) @@ -1292,16 +1290,16 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin if (targetCenterWidth > 0 && targetCenterHeight > 0 && sourceCenterWidth > 0 && sourceCenterHeight > 0) { QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueCenter ? opaqueData : translucentData; d.source = QRectF(sourceCenterLeft, sourceCenterTop, sourceCenterWidth, sourceCenterHeight); - d.scaleX = dx * inv_d_source_width; - d.scaleY = dy * inv_d_source_height; + d.scaleX = dx / d.source.width(); + d.scaleY = dy / d.source.height(); qreal repeatWidth = (xTarget[columns - 1] - xTarget[columns - 2]) / d.scaleX; qreal repeatHeight = (yTarget[rows - 1] - yTarget[rows - 2]) / d.scaleY; for (int j = 1; j < rows - 1; ++j) { - d.point.setY(qreal(0.5) * (yTarget[j + 1] + yTarget[j])); + d.point.setY(0.5 * (yTarget[j + 1] + yTarget[j])); for (int i = 1; i < columns - 1; ++i) { - d.point.setX(qreal(0.5) * (xTarget[i + 1] + xTarget[i])); + d.point.setX(0.5 * (xTarget[i + 1] + xTarget[i])); data.append(d); } if (rules.horizontal == Qt::RepeatTile) diff --git a/src/gui/painting/qmath_p.h b/src/gui/painting/qmath_p.h index 53ed8ab..f4a3982 100644 --- a/src/gui/painting/qmath_p.h +++ b/src/gui/painting/qmath_p.h @@ -54,10 +54,13 @@ // #include -#include QT_BEGIN_NAMESPACE +static const qreal Q_PI = qreal(3.14159265358979323846); // pi +static const qreal Q_2PI = qreal(6.28318530717958647693); // 2*pi +static const qreal Q_PI2 = qreal(1.57079632679489661923); // pi/2 + QT_END_NAMESPACE #endif // QMATH_P_H diff --git a/src/gui/painting/qpaintbuffer.cpp b/src/gui/painting/qpaintbuffer.cpp index fc6726e..b8700c3 100644 --- a/src/gui/painting/qpaintbuffer.cpp +++ b/src/gui/painting/qpaintbuffer.cpp @@ -426,7 +426,7 @@ void QPaintBufferEngine::penChanged() QPointF transformedWidth(penWidth, penWidth); if (!pen.isCosmetic()) transformedWidth = painter()->transform().map(transformedWidth); - buffer->penWidthAdjustment = transformedWidth.x() * qreal(0.5); + buffer->penWidthAdjustment = transformedWidth.x() / 2.0; } } #ifdef QPAINTBUFFER_DEBUG_DRAW diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 22bb9d2..3f33319 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -126,7 +126,7 @@ void dumpClip(int width, int height, const QClipData *clip); #define int_dim(pos, dim) (int(pos+dim) - int(pos)) // use the same rounding as in qrasterizer.cpp (6 bit fixed point) -static const qreal aliasedCoordinateDelta = qreal(0.5) - qreal(0.015625); +static const qreal aliasedCoordinateDelta = 0.5 - 0.015625; #ifdef Q_WS_WIN extern bool qt_cleartype_enabled; @@ -1743,8 +1743,8 @@ void QRasterPaintEngine::stroke(const QVectorPath &path, const QPen &pen) if (lines[i].p1() == lines[i].p2()) { if (s->lastPen.capStyle() != Qt::FlatCap) { QPointF p = lines[i].p1(); - QLineF line = s->matrix.map(QLineF(QPointF(p.x() - width*qreal(0.5), p.y()), - QPointF(p.x() + width*qreal(0.5), p.y()))); + QLineF line = s->matrix.map(QLineF(QPointF(p.x() - width*0.5, p.y()), + QPointF(p.x() + width*0.5, p.y()))); d->rasterizer->rasterizeLine(line.p1(), line.p2(), 1); } continue; @@ -1958,9 +1958,8 @@ static bool splitPolygon(const QPointF *points, int pointCount, QVector QVector sorted; sorted.reserve(pointCount); - const qreal three_quarters = qreal(3) / qreal(4); - upper->reserve(pointCount * three_quarters); - lower->reserve(pointCount * three_quarters); + upper->reserve(pointCount * 3 / 4); + lower->reserve(pointCount * 3 / 4); for (int i = 0; i < pointCount; ++i) sorted << points + i; @@ -2337,13 +2336,13 @@ void QRasterPaintEngine::strokePolygonCosmetic(const QPoint *points, int pointCo int x1 = points[pointCount-1].x() * m11 + dx; int y1 = points[pointCount-1].y() * m22 + dy; - qreal w = m13*points[pointCount-1].x() + m23*points[pointCount-1].y() + qreal(1.); + qreal w = m13*points[pointCount-1].x() + m23*points[pointCount-1].y() + 1.; w = 1/w; x1 = int(x1*w); y1 = int(y1*w); int x2 = points[0].x() * m11 + dx; int y2 = points[0].y() * m22 + dy; - w = m13*points[0].x() + m23*points[0].y() + qreal(1.); + w = m13*points[0].x() + m23*points[0].y() + 1.; w = 1/w; x2 = int(x2 * w); y2 = int(y2 * w); @@ -4868,7 +4867,7 @@ void QGradientCache::generateGradientColorTable(const QGradient& gradient, uint uint next_color; qreal incr = 1 / qreal(size); // the double increment. - qreal dpos = qreal(1.5) * incr; // current position in gradient stop list (0 to 1) + qreal dpos = 1.5 * incr; // current position in gradient stop list (0 to 1) // Up to first point colorTable[pos++] = PREMUL(current_color); @@ -5042,7 +5041,7 @@ void QSpanData::setup(const QBrush &brush, int alpha, QPainter::CompositionMode QPointF center = g->center(); conicalData.center.x = center.x(); conicalData.center.y = center.y(); - conicalData.angle = g->angle() * Q_2PI / qreal(360.0); + conicalData.angle = g->angle() * 2 * Q_PI / 360.0; } break; @@ -5141,8 +5140,7 @@ void QSpanData::setupMatrix(const QTransform &matrix, int bilin) { QTransform delta; // make sure we round off correctly in qdrawhelper.cpp - const qreal inv_65536 = qreal(1.0) / 65536; - delta.translate(inv_65536, inv_65536); + delta.translate(1.0 / 65536, 1.0 / 65536); QTransform inv = (delta * matrix).inverted(); m11 = inv.m11(); @@ -6051,9 +6049,9 @@ static void drawEllipse_midpoint_i(const QRect &rect, const QRect &clip, const QFixed b = QFixed(rect.height()) >> 1; QFixed d = b*b - (a*a*b) + ((a*a) >> 2); #else - const qreal a = qreal(rect.width()) * qreal(0.5); - const qreal b = qreal(rect.height()) * qreal(0.5); - qreal d = b*b - (a*a*b) + qreal(0.25)*a*a; + const qreal a = qreal(rect.width()) / 2; + const qreal b = qreal(rect.height()) / 2; + qreal d = b*b - (a*a*b) + 0.25*a*a; #endif int x = 0; @@ -6081,7 +6079,7 @@ static void drawEllipse_midpoint_i(const QRect &rect, const QRect &clip, d = b*b*(x + (QFixed(1) >> 1))*(x + (QFixed(1) >> 1)) + a*a*((y - 1)*(y - 1) - b*b); #else - d = b*b*(x + qreal(0.5))*(x + qreal(0.5)) + a*a*(qreal(y - 1)*qreal(y - 1) - b*b); + d = b*b*(x + 0.5)*(x + 0.5) + a*a*((y - 1)*(y - 1) - b*b); #endif const int miny = rect.height() & 0x1; while (y > miny) { @@ -6152,4 +6150,4 @@ void dumpClip(int width, int height, const QClipData *clip) #endif -QT_END_NAMESPACE \ No newline at end of file +QT_END_NAMESPACE diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp index 225e593..7d1c109 100644 --- a/src/gui/painting/qpaintengineex.cpp +++ b/src/gui/painting/qpaintengineex.cpp @@ -731,9 +731,8 @@ void QPaintEngineEx::drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yR qreal y2 = rect.bottom(); if (mode == Qt::RelativeSize) { - const qreal inv_200 = 1 / qreal(200.); - xRadius = xRadius * rect.width() * inv_200; - yRadius = yRadius * rect.height() * inv_200; + xRadius = xRadius * rect.width() / 200.; + yRadius = yRadius * rect.height() / 200.; } xRadius = qMin(xRadius, rect.width() / 2); @@ -847,7 +846,7 @@ void QPaintEngineEx::drawPoints(const QPointF *points, int pointCount) for (int i=0; imatrix).boundingRect(); } else { - strokeOffsetX = qAbs(penWidth * state->matrix.m11() * qreal(0.5)); - strokeOffsetY = qAbs(penWidth * state->matrix.m22() * qreal(0.5)); + strokeOffsetX = qAbs(penWidth * state->matrix.m11() / 2.0); + strokeOffsetY = qAbs(penWidth * state->matrix.m22() / 2.0); } } } @@ -467,7 +467,7 @@ void QPainterPrivate::draw_helper(const QPainterPath &originalPath, DrawOperatio pt.end(); p.resetTransform(); p.setCompositionMode(QPainter::CompositionMode_SourceAtop); - p.setOpacity(qreal(0.5)); + p.setOpacity(0.5); p.fillRect(0, 0, image.width(), image.height(), QBrush(block)); } #endif @@ -3565,7 +3565,7 @@ void QPainter::drawPoints(const QPointF *points, int pointCount) QPainterPath path; for (int i=0; idraw_helper(path, QPainterPrivate::StrokeDraw); if (flat_pen) @@ -3627,7 +3627,7 @@ void QPainter::drawPoints(const QPoint *points, int pointCount) QPainterPath path; for (int i=0; idraw_helper(path, QPainterPrivate::StrokeDraw); if (flat_pen) @@ -4270,9 +4270,8 @@ void QPainter::drawArc(const QRectF &r, int a, int alen) QRectF rect = r.normalized(); QPainterPath path; - const qreal inv_16 = 1 / qreal(16.0); - path.arcMoveTo(rect, a * inv_16); - path.arcTo(rect, a * inv_16, alen * inv_16); + path.arcMoveTo(rect, a/16.0); + path.arcTo(rect, a/16.0, alen/16.0); strokePath(path, d->state->pen); } @@ -4341,9 +4340,8 @@ void QPainter::drawPie(const QRectF &r, int a, int alen) QRectF rect = r.normalized(); QPainterPath path; - const qreal inv_16 = 1 / qreal(16.0); path.moveTo(rect.center()); - path.arcTo(rect.x(), rect.y(), rect.width(), rect.height(), a * inv_16, alen * inv_16); + path.arcTo(rect.x(), rect.y(), rect.width(), rect.height(), a/16.0, alen/16.0); path.closeSubpath(); drawPath(path); @@ -4404,9 +4402,8 @@ void QPainter::drawChord(const QRectF &r, int a, int alen) QRectF rect = r.normalized(); QPainterPath path; - const qreal inv_16 = 1 / qreal(16.0); - path.arcMoveTo(rect, a * inv_16); - path.arcTo(rect, a * inv_16, alen * inv_16); + path.arcMoveTo(rect, a/16.0); + path.arcTo(rect, a/16.0, alen/16.0); path.closeSubpath(); drawPath(path); } @@ -5908,7 +5905,7 @@ static QPainterPath generateWavyPath(qreal minWidth, qreal maxRadius, QPaintDevi QPainterPath path; bool up = true; - const qreal radius = qMax(qreal(.5), qMin(qreal(1.25) * device->logicalDpiY() / qt_defaultDpi(), maxRadius)); + const qreal radius = qMax(qreal(.5), qMin(qreal(1.25 * device->logicalDpiY() / qt_defaultDpi()), maxRadius)); qreal xs, ys; int i = 0; path.moveTo(0, radius); @@ -5988,7 +5985,7 @@ static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const if (ti.flags & QTextItem::StrikeOut) { QLineF strikeOutLine = line; - strikeOutLine.translate(qreal(0.), - fe->ascent().toReal() / qreal(3.)); + strikeOutLine.translate(0., - fe->ascent().toReal() / 3.); painter->setPen(pen); painter->drawLine(strikeOutLine); } diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index 0f31cca..8133793 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -799,9 +799,8 @@ void QPainterPath::quadTo(const QPointF &c, const QPointF &e) if (prev == c && c == e) return; - const qreal inv_3 = 1 / qreal(3); - QPointF c1((prev.x() + 2*c.x()) * inv_3, (prev.y() + 2*c.y()) * inv_3); - QPointF c2((e.x() + 2*c.x()) * inv_3, (e.y() + 2*c.y()) * inv_3); + QPointF c1((prev.x() + 2*c.x()) / 3, (prev.y() + 2*c.y()) / 3); + QPointF c2((e.x() + 2*c.x()) / 3, (e.y() + 2*c.y()) / 3); cubicTo(c1, c2, e); } @@ -1805,24 +1804,22 @@ static bool qt_painterpath_isect_line_rect(qreal x1, qreal y1, qreal x2, qreal y return false; if (p1 | p2) { - const qreal dx = x2 - x1; - const qreal dy = y2 - y1; - const qreal dx_dy_ratio = dx / dy; - const qreal dy_dx_ratio = dy / dx; + qreal dx = x2 - x1; + qreal dy = y2 - y1; // clip x coordinates if (x1 < left) { - y1 += dy_dx_ratio * (left - x1); + y1 += dy/dx * (left - x1); x1 = left; } else if (x1 > right) { - y1 -= dy_dx_ratio * (x1 - right); + y1 -= dy/dx * (x1 - right); x1 = right; } if (x2 < left) { - y2 += dy_dx_ratio * (left - x2); + y2 += dy/dx * (left - x2); x2 = left; } else if (x2 > right) { - y2 -= dy_dx_ratio * (x2 - right); + y2 -= dy/dx * (x2 - right); x2 = right; } @@ -1836,17 +1833,17 @@ static bool qt_painterpath_isect_line_rect(qreal x1, qreal y1, qreal x2, qreal y // clip y coordinates if (y1 < top) { - x1 += dx_dy_ratio * (top - y1); + x1 += dx/dy * (top - y1); y1 = top; } else if (y1 > bottom) { - x1 -= dx_dy_ratio * (y1 - bottom); + x1 -= dx/dy * (y1 - bottom); y1 = bottom; } if (y2 < top) { - x2 += dx_dy_ratio * (top - y2); + x2 += dx/dy * (top - y2); y2 = top; } else if (y2 > bottom) { - x2 -= dx_dy_ratio * (y2 - bottom); + x2 -= dx/dy * (y2 - bottom); y2 = bottom; } diff --git a/src/gui/painting/qpainterpath_p.h b/src/gui/painting/qpainterpath_p.h index a2bc905..54b9392 100644 --- a/src/gui/painting/qpainterpath_p.h +++ b/src/gui/painting/qpainterpath_p.h @@ -258,7 +258,7 @@ inline void QPainterPathData::maybeMoveTo() } } -#define KAPPA qreal(0.5522847498) +#define KAPPA 0.5522847498 QT_END_NAMESPACE diff --git a/src/gui/painting/qpathclipper.cpp b/src/gui/painting/qpathclipper.cpp index 1568ad8..ab2dc33 100644 --- a/src/gui/painting/qpathclipper.cpp +++ b/src/gui/painting/qpathclipper.cpp @@ -321,11 +321,11 @@ void QIntersectionFinder::intersectLines(const QLineF &a, const QLineF &b, QData if (p1_equals_q1 || p1_equals_q2 || p2_equals_q1 || p2_equals_q2) return; - const qreal inv_par = 1 / qreal(par); + const qreal tp = (qDelta.y() * (q1.x() - p1.x()) - - qDelta.x() * (q1.y() - p1.y())) * inv_par; + qDelta.x() * (q1.y() - p1.y())) / par; const qreal tq = (pDelta.y() * (q1.x() - p1.x()) - - pDelta.x() * (q1.y() - p1.y())) * inv_par; + pDelta.x() * (q1.y() - p1.y())) / par; if (tp<0 || tp>1 || tq<0 || tq>1) return; @@ -1192,24 +1192,24 @@ static qreal computeAngle(const QPointF &v) { #if 1 if (v.x() == 0) { - return v.y() <= 0 ? 0 : qreal(64.); + return v.y() <= 0 ? 0 : 64.; } else if (v.y() == 0) { - return v.x() <= 0 ? qreal(32.) : qreal(96.); + return v.x() <= 0 ? 32. : 96.; } QPointF nv = normalize(v); if (nv.y() < 0) { if (nv.x() < 0) { // 0 - 32 - return qreal(-32.) * nv.x(); + return -32. * nv.x(); } else { // 96 - 128 - return qreal(128.) - qreal(32.) * nv.x(); + return 128. - 32. * nv.x(); } } else { // 32 - 96 - return qreal(64.) + 32 * nv.x(); + return 64. + 32 * nv.x(); } #else // doesn't seem to be robust enough - return qAtan2(v.x(), v.y()) + Q_PI; + return atan2(v.x(), v.y()) + Q_PI; #endif } diff --git a/src/gui/painting/qrasterizer.cpp b/src/gui/painting/qrasterizer.cpp index ba5eda6..b602690 100644 --- a/src/gui/painting/qrasterizer.cpp +++ b/src/gui/painting/qrasterizer.cpp @@ -44,7 +44,6 @@ #include #include -#include #include #include #include @@ -52,8 +51,8 @@ QT_BEGIN_NAMESPACE typedef int Q16Dot16; -#define Q16Dot16ToFloat(i) ((i)/qreal(65536.)) -#define FloatToQ16Dot16(i) (int)((i) * qreal(65536.)) +#define Q16Dot16ToFloat(i) ((i)/65536.) +#define FloatToQ16Dot16(i) (int)((i) * 65536.) #define IntToQ16Dot16(i) ((i) << 16) #define Q16Dot16ToInt(i) ((i) >> 16) #define Q16Dot16Factor 65536 @@ -708,12 +707,12 @@ void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width, if (a == b || width == 0 || d->clipRect.isEmpty()) return; - Q_ASSERT(width > qreal(0.0)); + Q_ASSERT(width > 0.0); QPointF pa = a; QPointF pb = b; - QPointF offs = QPointF(qAbs(b.y() - a.y()), qAbs(b.x() - a.x())) * width * qreal(0.5); + QPointF offs = QPointF(qAbs(b.y() - a.y()), qAbs(b.x() - a.x())) * width * 0.5; if (squareCap) offs += QPointF(offs.y(), offs.x()); const QRectF clip(d->clipRect.topLeft() - offs, d->clipRect.bottomRight() + QPoint(1, 1) + offs); @@ -751,12 +750,10 @@ void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width, } if (!d->antialiased) { - const qreal inv_64 = 1 / qreal(64.); - const qreal delta = (COORD_OFFSET - COORD_ROUNDING) * inv_64; - pa.rx() += delta; - pa.ry() += delta; - pb.rx() += delta; - pb.ry() += delta; + pa.rx() += (COORD_OFFSET - COORD_ROUNDING)/64.; + pa.ry() += (COORD_OFFSET - COORD_ROUNDING)/64.; + pb.rx() += (COORD_OFFSET - COORD_ROUNDING)/64.; + pb.ry() += (COORD_OFFSET - COORD_ROUNDING)/64.; } { @@ -781,7 +778,7 @@ void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width, return; // adjust width which is given relative to |b - a| - width *= qSqrt(w0 / w); + width *= sqrt(w0 / w); } QSpanBuffer buffer(d->blend, d->data, d->clipRect); @@ -796,11 +793,10 @@ void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width, pa = QPointF(x, y - dy); pb = QPointF(x, y + dy); - const qreal inv_width = 1 / width; if (squareCap) - width = inv_width + 1.0f; + width = 1 / width + 1.0f; else - width = inv_width; + width = 1 / width; squareCap = false; } @@ -1196,10 +1192,8 @@ void QRasterizer::rasterize(const QPainterPath &path, Qt::FillRule fillRule) QRectF bounds = path.controlPointRect(); - const qreal inv_64 = 1 / qreal(64.); - const qreal delta = (COORD_OFFSET - COORD_ROUNDING) * inv_64 ; - int iTopBound = qMax(d->clipRect.top(), int(bounds.top() + qreal(0.5) + delta)); - int iBottomBound = qMin(d->clipRect.bottom(), int(bounds.bottom() - qreal(0.5) + delta)); + int iTopBound = qMax(d->clipRect.top(), int(bounds.top() + 0.5 + (COORD_OFFSET - COORD_ROUNDING)/64.)); + int iBottomBound = qMin(d->clipRect.bottom(), int(bounds.bottom() - 0.5 + (COORD_OFFSET - COORD_ROUNDING)/64.)); if (iTopBound > iBottomBound) return; diff --git a/src/gui/painting/qstroker.cpp b/src/gui/painting/qstroker.cpp index b33d86b..228a6b1 100644 --- a/src/gui/painting/qstroker.cpp +++ b/src/gui/painting/qstroker.cpp @@ -788,12 +788,12 @@ qreal qt_t_for_arc_angle(qreal angle) if (qFuzzyCompare(angle, qreal(90))) return 1; - qreal radians = Q_PI180 * angle; + qreal radians = Q_PI * angle / 180; qreal cosAngle = qCos(radians); qreal sinAngle = qSin(radians); // initial guess - qreal tc = angle / qreal(90); + qreal tc = angle / 90; // do some iterations of newton's method to approximate cosAngle // finds the zero of the function b.pointAt(tc).x() - cosAngle tc -= ((((2-3*QT_PATH_KAPPA) * tc + 3*(QT_PATH_KAPPA-1)) * tc) * tc + 1 - cosAngle) // value @@ -812,7 +812,7 @@ qreal qt_t_for_arc_angle(qreal angle) // use the average of the t that best approximates cosAngle // and the t that best approximates sinAngle - qreal t = qreal(0.5) * (tc + ts); + qreal t = 0.5 * (tc + ts); #if 0 printf("angle: %f, t: %f\n", angle, t); @@ -861,11 +861,11 @@ QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLengt qreal y = rect.y(); qreal w = rect.width(); - qreal w2 = rect.width() * qreal(0.5); + qreal w2 = rect.width() / 2; qreal w2k = w2 * QT_PATH_KAPPA; qreal h = rect.height(); - qreal h2 = rect.height() * qreal(0.5); + qreal h2 = rect.height() / 2; qreal h2k = h2 * QT_PATH_KAPPA; QPointF points[16] = @@ -898,24 +898,23 @@ QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLengt else if (sweepLength < -360) sweepLength = -360; // Special case fast paths - if (startAngle == qreal(0.0)) { - if (sweepLength == qreal(360.0)) { + if (startAngle == 0.0) { + if (sweepLength == 360.0) { for (int i = 11; i >= 0; --i) curves[(*point_count)++] = points[i]; return points[12]; - } else if (sweepLength == qreal(-360.0)) { + } else if (sweepLength == -360.0) { for (int i = 1; i <= 12; ++i) curves[(*point_count)++] = points[i]; return points[0]; } } - qreal inv_90 = qreal(1) / qreal(90); - int startSegment = int(floor(startAngle * inv_90)); - int endSegment = int(floor((startAngle + sweepLength) * inv_90)); + int startSegment = int(floor(startAngle / 90)); + int endSegment = int(floor((startAngle + sweepLength) / 90)); - qreal startT = (startAngle - startSegment * 90) * inv_90; - qreal endT = (startAngle + sweepLength - endSegment * 90) * inv_90; + qreal startT = (startAngle - startSegment * 90) / 90; + qreal endT = (startAngle + sweepLength - endSegment * 90) / 90; int delta = sweepLength > 0 ? 1 : -1; if (delta < 0) { diff --git a/src/gui/painting/qstroker_p.h b/src/gui/painting/qstroker_p.h index 5ff9d87..a10ebd9 100644 --- a/src/gui/painting/qstroker_p.h +++ b/src/gui/painting/qstroker_p.h @@ -110,7 +110,7 @@ struct qfixed2d }; #endif -#define QT_PATH_KAPPA qreal(0.5522847498) +#define QT_PATH_KAPPA 0.5522847498 QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLength, QPointF *controlPoints, int *point_count); diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index 27a1503..45db80a 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE -#define Q_NEAR_CLIP (sizeof(qreal) == sizeof(double) ? qreal(0.000001) : qreal(0.0001)) +#define Q_NEAR_CLIP (sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001) #ifdef MAP # undef MAP @@ -82,7 +82,7 @@ QT_BEGIN_NAMESPACE if (t == TxProject) { \ qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); \ if (w < qreal(Q_NEAR_CLIP)) w = qreal(Q_NEAR_CLIP); \ - w = qreal(1.)/w; \ + w = 1./w; \ nx *= w; \ ny *= w; \ } \ @@ -369,8 +369,8 @@ QTransform QTransform::inverted(bool *invertible) const inv = !qFuzzyIsNull(affine._m11); inv &= !qFuzzyIsNull(affine._m22); if (inv) { - invert.affine._m11 = qreal(1.) / affine._m11; - invert.affine._m22 = qreal(1.) / affine._m22; + invert.affine._m11 = 1. / affine._m11; + invert.affine._m22 = 1. / affine._m22; invert.affine._dx = -affine._dx * invert.affine._m11; invert.affine._dy = -affine._dy * invert.affine._m22; } @@ -1087,7 +1087,7 @@ QPoint QTransform::map(const QPoint &p) const x = affine._m11 * fx + affine._m21 * fy + affine._dx; y = affine._m12 * fx + affine._m22 * fy + affine._dy; if (t == TxProject) { - qreal w = qreal(1.)/(m_13 * fx + m_23 * fy + m_33); + qreal w = 1./(m_13 * fx + m_23 * fy + m_33); x *= w; y *= w; } @@ -1138,7 +1138,7 @@ QPointF QTransform::map(const QPointF &p) const x = affine._m11 * fx + affine._m21 * fy + affine._dx; y = affine._m12 * fx + affine._m22 * fy + affine._dy; if (t == TxProject) { - qreal w = qreal(1.)/(m_13 * fx + m_23 * fy + m_33); + qreal w = 1./(m_13 * fx + m_23 * fy + m_33); x *= w; y *= w; } @@ -1217,10 +1217,10 @@ QLine QTransform::map(const QLine &l) const x2 = affine._m11 * fx2 + affine._m21 * fy2 + affine._dx; y2 = affine._m12 * fx2 + affine._m22 * fy2 + affine._dy; if (t == TxProject) { - qreal w = qreal(1.)/(m_13 * fx1 + m_23 * fy1 + m_33); + qreal w = 1./(m_13 * fx1 + m_23 * fy1 + m_33); x1 *= w; y1 *= w; - w = qreal(1.)/(m_13 * fx2 + m_23 * fy2 + m_33); + w = 1./(m_13 * fx2 + m_23 * fy2 + m_33); x2 *= w; y2 *= w; } @@ -1276,10 +1276,10 @@ QLineF QTransform::map(const QLineF &l) const x2 = affine._m11 * fx2 + affine._m21 * fy2 + affine._dx; y2 = affine._m12 * fx2 + affine._m22 * fy2 + affine._dy; if (t == TxProject) { - qreal w = qreal(1.)/(m_13 * fx1 + m_23 * fy1 + m_33); + qreal w = 1./(m_13 * fx1 + m_23 * fy1 + m_33); x1 *= w; y1 *= w; - w = qreal(1.)/(m_13 * fx2 + m_23 * fy2 + m_33); + w = 1./(m_13 * fx2 + m_23 * fy2 + m_33); x2 *= w; y2 *= w; } @@ -1438,7 +1438,7 @@ struct QHomogeneousCoordinate QHomogeneousCoordinate(qreal x_, qreal y_, qreal w_) : x(x_), y(y_), w(w_) {} const QPointF toPoint() const { - qreal iw = qreal(1.) / w; + qreal iw = 1. / w; return QPointF(x * iw, y * iw); } }; @@ -1695,9 +1695,8 @@ bool QTransform::squareToQuad(const QPolygonF &quad, QTransform &trans) if (!bottom) return false; - double inv_bottom = 1 / bottom; - g = gtop * inv_bottom; - h = htop * inv_bottom; + g = gtop/bottom; + h = htop/bottom; a = dx1 - dx0 + g * dx1; b = dx3 - dx0 + h * dx3; diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp index 4d3272c..4c9541b 100644 --- a/src/gui/styles/qcommonstyle.cpp +++ b/src/gui/styles/qcommonstyle.cpp @@ -3070,9 +3070,9 @@ static QPolygonF calcArrow(const QStyleOptionSlider *dial, qreal &a) int currentSliderPosition = dial->upsideDown ? dial->sliderPosition : (dial->maximum - dial->sliderPosition); if (dial->maximum == dial->minimum) - a = Q_PI2; + a = Q_PI / 2; else if (dial->dialWrapping) - a = Q_PI2 * 3 - (currentSliderPosition - dial->minimum) * Q_2PI + a = Q_PI * 3 / 2 - (currentSliderPosition - dial->minimum) * 2 * Q_PI / (dial->maximum - dial->minimum); else a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI @@ -3087,13 +3087,12 @@ static QPolygonF calcArrow(const QStyleOptionSlider *dial, qreal &a) int back = len / 2; QPolygonF arrow(3); - const qreal five_div_by_six = 5 / 6; - arrow[0] = QPointF(qreal(0.5) + xc + len * qCos(a), - qreal(0.5) + yc - len * qSin(a)); - arrow[1] = QPointF(qreal(0.5) + xc + back * qCos(a + Q_PI * five_div_by_six), - qreal(0.5) + yc - back * qSin(a + Q_PI * five_div_by_six)); - arrow[2] = QPointF(qreal(0.5) + xc + back * qCos(a - Q_PI * five_div_by_six), - qreal(0.5) + yc - back * qSin(a - Q_PI * five_div_by_six)); + arrow[0] = QPointF(0.5 + xc + len * qCos(a), + 0.5 + yc - len * qSin(a)); + arrow[1] = QPointF(0.5 + xc + back * qCos(a + Q_PI * 5 / 6), + 0.5 + yc - back * qSin(a + Q_PI * 5 / 6)); + arrow[2] = QPointF(0.5 + xc + back * qCos(a - Q_PI * 5 / 6), + 0.5 + yc - back * qSin(a - Q_PI * 5 / 6)); return arrow; } diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 16a81b3..a1dab86 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -553,7 +553,7 @@ void QS60StylePrivate::drawRow(QS60StyleEnums::SkinParts start, #if 0 painter->save(); - painter->setOpacity(qreal(.3)); + painter->setOpacity(.3); painter->fillRect(startRect, Qt::red); painter->fillRect(middleRect, Qt::green); painter->fillRect(endRect, Qt::blue); @@ -1598,7 +1598,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, QS60StylePrivate::SF_PointNorth : QS60StylePrivate::SF_PointWest; QS60StylePrivate::drawSkinPart(QS60StyleEnums::SP_QgnGrafBarWait, painter, progressRect, flags | orientationFlag); } else { - const qreal progressFactor = (optionProgressBar->minimum == optionProgressBar->maximum) ? qreal(1.0) + const qreal progressFactor = (optionProgressBar->minimum == optionProgressBar->maximum) ? 1.0 : (qreal)optionProgressBar->progress / optionProgressBar->maximum; if (optionProgressBar->orientation == Qt::Horizontal) { progressRect.setWidth(int(progressRect.width() * progressFactor)); @@ -1886,12 +1886,12 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, if (focusFrame->widget() && focusFrame->widget()->hasEditFocus()) editFocus = true; } - const qreal opacity = editFocus ? qreal(0.65) : qreal(0.45); // Trial and error factors. Feel free to improve. + const qreal opacity = editFocus ? 0.65 : 0.45; // Trial and error factors. Feel free to improve. #else - const qreal opacity = qreal(0.5); + const qreal opacity = 0.5; #endif // Because of Qts coordinate system, we need to tweak the rect by .5 pixels, otherwise it gets blurred. - const qreal rectAdjustment = (penWidth % 2) ? qreal(-.5) : 0; + const qreal rectAdjustment = (penWidth % 2) ? -.5 : 0; // Make sure that the pen stroke is inside the rect const QRectF adjustedRect = @@ -1915,7 +1915,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, case CE_Splitter: if (option->state & State_Sunken && option->state & State_Enabled) { painter->save(); - painter->setOpacity(qreal(0.5)); + painter->setOpacity(0.5); painter->setBrush(d->themePalette()->light()); painter->setRenderHint(QPainter::Antialiasing); const qreal roundRectRadius = 4 * goldenRatio; @@ -1993,8 +1993,8 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti case PE_IndicatorRadioButton: { QRect buttonRect = option->rect; //there is empty (a. 33%) space in svg graphics for radiobutton - const qreal reduceWidth = (qreal)buttonRect.width()/qreal(3.0); - const qreal rectWidth = (qreal)option->rect.width() != 0 ? option->rect.width() : qreal(1.0); + const qreal reduceWidth = (qreal)buttonRect.width()/3.0; + const qreal rectWidth = (qreal)option->rect.width() != 0 ? option->rect.width() : 1.0; // Try to occupy the full area const qreal scaler = 1 + (reduceWidth/rectWidth); buttonRect.setWidth((int)((buttonRect.width()-reduceWidth) * scaler)); diff --git a/src/gui/styles/qstyle.cpp b/src/gui/styles/qstyle.cpp index 6733209..ec238a9 100644 --- a/src/gui/styles/qstyle.cpp +++ b/src/gui/styles/qstyle.cpp @@ -2132,7 +2132,7 @@ int QStyle::sliderPositionFromValue(int min, int max, int logicalValue, int span uint p = upsideDown ? max - logicalValue : logicalValue - min; if (range > (uint)INT_MAX/4096) { - qreal dpos = (qreal(p))/(qreal(range)/span); + double dpos = (double(p))/(double(range)/span); return int(dpos); } else if (range > (uint)span) { return (2 * p * span + range) / (2*range); diff --git a/src/gui/styles/qstylehelper.cpp b/src/gui/styles/qstylehelper.cpp index 5b6f72f..af30f15 100644 --- a/src/gui/styles/qstylehelper.cpp +++ b/src/gui/styles/qstylehelper.cpp @@ -117,15 +117,15 @@ static QPointF calcRadialPos(const QStyleOptionSlider *dial, qreal offset) const int currentSliderPosition = dial->upsideDown ? dial->sliderPosition : (dial->maximum - dial->sliderPosition); qreal a = 0; if (dial->maximum == dial->minimum) - a = Q_PI2; + a = Q_PI / 2; else if (dial->dialWrapping) - a = Q_PI2 * 3 - (currentSliderPosition - dial->minimum) * Q_2PI + a = Q_PI * 3 / 2 - (currentSliderPosition - dial->minimum) * 2 * Q_PI / (dial->maximum - dial->minimum); else a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI / (dial->maximum - dial->minimum)) / 6; - const qreal xc = width * qreal(0.5); - const qreal yc = height * qreal(0.5); + qreal xc = width / 2.0; + qreal yc = height / 2.0; qreal len = r - QStyleHelper::calcBigLineSize(r) - 3; qreal back = offset * len; QPointF pos(QPointF(xc + back * qCos(a), yc - back * qSin(a))); @@ -134,7 +134,7 @@ static QPointF calcRadialPos(const QStyleOptionSlider *dial, qreal offset) qreal angle(const QPointF &p1, const QPointF &p2) { - static const qreal rad_factor = Q_PI180; + static const qreal rad_factor = 180 / Q_PI; qreal _angle = 0; if (p1.x() == p2.x()) { @@ -186,7 +186,7 @@ QPolygonF calcLines(const QStyleOptionSlider *dial) poly.resize(2 + 2 * notches); int smallLineSize = bigLineSize / 2; for (int i = 0; i <= notches; ++i) { - qreal angle = dial->dialWrapping ? Q_PI2 * 3 - i * Q_2PI / notches + qreal angle = dial->dialWrapping ? Q_PI * 3 / 2 - i * 2 * Q_PI / notches : (Q_PI * 8 - i * 10 * Q_PI / notches) / 6; qreal s = qSin(angle); qreal c = qCos(angle); @@ -215,7 +215,7 @@ void drawDial(const QStyleOptionSlider *option, QPainter *painter) const bool enabled = option->state & QStyle::State_Enabled; qreal r = qMin(width, height) / 2; r -= r/50; - const qreal penSize = r/qreal(20.0); + const qreal penSize = r/20.0; painter->save(); painter->setRenderHint(QPainter::Antialiasing); @@ -234,7 +234,7 @@ void drawDial(const QStyleOptionSlider *option, QPainter *painter) const qreal dx = option->rect.x() + d_ + (width - 2 * r) / 2 + 1; const qreal dy = option->rect.y() + d_ + (height - 2 * r) / 2 + 1; - QRectF br = QRectF(dx + qreal(0.5), dy + qreal(0.5), + QRectF br = QRectF(dx + 0.5, dy + 0.5, int(r * 2 - 2 * d_ - 2), int(r * 2 - 2 * d_ - 2)); buttonColor.setHsv(buttonColor .hue(), @@ -244,11 +244,11 @@ void drawDial(const QStyleOptionSlider *option, QPainter *painter) if (enabled) { // Drop shadow - const qreal shadowSize = qMax(qreal(1.0), penSize * qreal(0.5)); + qreal shadowSize = qMax(1.0, penSize/2.0); QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize, 2*shadowSize, 2*shadowSize); QRadialGradient shadowGradient(shadowRect.center().x(), - shadowRect.center().y(), shadowRect.width() * qreal(0.5), + shadowRect.center().y(), shadowRect.width()/2.0, shadowRect.center().x(), shadowRect.center().y()); shadowGradient.setColorAt(qreal(0.91), QColor(0, 0, 0, 40)); shadowGradient.setColorAt(qreal(1.0), Qt::transparent); @@ -260,7 +260,7 @@ void drawDial(const QStyleOptionSlider *option, QPainter *painter) // Main gradient QRadialGradient gradient(br.center().x() - br.width()/3, dy, - br.width()*qreal(1.3), br.center().x(), + br.width()*1.3, br.center().x(), br.center().y() - br.height()/2); gradient.setColorAt(0, buttonColor.lighter(110)); gradient.setColorAt(qreal(0.5), buttonColor); @@ -283,7 +283,7 @@ void drawDial(const QStyleOptionSlider *option, QPainter *painter) qMin(160, highlight.saturation()), qMax(230, highlight.value())); highlight.setAlpha(127); - p->setPen(QPen(highlight, qreal(2.0))); + p->setPen(QPen(highlight, 2.0)); p->setBrush(Qt::NoBrush); p->drawEllipse(br.adjusted(-1, -1, 1, 1)); } @@ -302,7 +302,7 @@ void drawDial(const QStyleOptionSlider *option, QPainter *painter) dialGradient.setColorAt(1, buttonColor.darker(140)); dialGradient.setColorAt(qreal(0.4), buttonColor.darker(120)); dialGradient.setColorAt(0, buttonColor.darker(110)); - if (penSize > qreal(3.0)) { + if (penSize > 3.0) { painter->setPen(QPen(QColor(0, 0, 0, 25), penSize)); painter->drawLine(calcRadialPos(option, qreal(0.90)), calcRadialPos(option, qreal(0.96))); } diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index 1c24a03..ce73fd8 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -1252,20 +1252,20 @@ QPainterPath QRenderRule::borderClip(QRect r) const QRectF rect(r); const int *borders = border()->borders; QPainterPath path; - qreal curY = rect.y() + borders[TopEdge]*qreal(0.5); + qreal curY = rect.y() + borders[TopEdge]/2.0; path.moveTo(rect.x() + tlr.width(), curY); path.lineTo(rect.right() - trr.width(), curY); - qreal curX = rect.right() - borders[RightEdge]*qreal(0.5); + qreal curX = rect.right() - borders[RightEdge]/2.0; path.arcTo(curX - 2*trr.width() + borders[RightEdge], curY, trr.width()*2 - borders[RightEdge], trr.height()*2 - borders[TopEdge], 90, -90); path.lineTo(curX, rect.bottom() - brr.height()); - curY = rect.bottom() - borders[BottomEdge]*qreal(0.5); + curY = rect.bottom() - borders[BottomEdge]/2.0; path.arcTo(curX - 2*brr.width() + borders[RightEdge], curY - 2*brr.height() + borders[BottomEdge], brr.width()*2 - borders[RightEdge], brr.height()*2 - borders[BottomEdge], 0, -90); path.lineTo(rect.x() + blr.width(), curY); - curX = rect.left() + borders[LeftEdge]*qreal(0.5); + curX = rect.left() + borders[LeftEdge]/2.0; path.arcTo(curX, rect.bottom() - 2*blr.height() + borders[BottomEdge]/2, blr.width()*2 - borders[LeftEdge], blr.height()*2 - borders[BottomEdge], 270, -90); diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 4511709..447087c 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -309,7 +309,7 @@ QFontPrivate *QFontPrivate::smallCapsFontPrivate() const QFont font(const_cast(this)); qreal pointSize = font.pointSizeF(); if (pointSize > 0) - font.setPointSizeF(pointSize * qreal(.7)); + font.setPointSizeF(pointSize * .7); else font.setPixelSize((font.pixelSize() * 7 + 5) / 10); scFont = font.d.data(); @@ -2143,7 +2143,7 @@ QDataStream &operator<<(QDataStream &s, const QFont &font) if (s.version() >= QDataStream::Qt_4_0) { // 4.0 - qreal pointSize = font.d->request.pointSize; + double pointSize = font.d->request.pointSize; qint32 pixelSize = font.d->request.pixelSize; s << pointSize; s << pixelSize; @@ -2205,7 +2205,7 @@ QDataStream &operator>>(QDataStream &s, QFont &font) if (s.version() >= QDataStream::Qt_4_0) { // 4.0 - qreal pointSize; + double pointSize; qint32 pixelSize; s >> pointSize; s >> pixelSize; diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index e8a0068..7e93aa0 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -1885,12 +1885,11 @@ QList QFontDatabase::pointSizes(const QString &family, smoothScalable = true; goto end; } - const qreal pointsize_factor = qreal(72.0) / dpi; for (int l = 0; l < style->count; l++) { const QtFontSize *size = style->pixelSizes + l; if (size->pixelSize != 0 && size->pixelSize != USHRT_MAX) { - const uint pointSize = qRound(size->pixelSize * pointsize_factor); + const uint pointSize = qRound(size->pixelSize * 72.0 / dpi); if (! sizes.contains(pointSize)) sizes.append(pointSize); } @@ -1993,12 +1992,11 @@ QList QFontDatabase::smoothSizes(const QString &family, smoothScalable = true; goto end; } - const qreal pointsize_factor = qreal(72.0) / dpi; for (int l = 0; l < style->count; l++) { const QtFontSize *size = style->pixelSizes + l; if (size->pixelSize != 0 && size->pixelSize != USHRT_MAX) { - const uint pointSize = qRound(size->pixelSize * pointsize_factor); + const uint pointSize = qRound(size->pixelSize * 72.0 / dpi); if (! sizes.contains(pointSize)) sizes.append(pointSize); } diff --git a/src/svg/qsvggenerator.cpp b/src/svg/qsvggenerator.cpp index 248bf55..2f80a92 100644 --- a/src/svg/qsvggenerator.cpp +++ b/src/svg/qsvggenerator.cpp @@ -796,9 +796,9 @@ int QSvgGenerator::metric(QPaintDevice::PaintDeviceMetric metric) const case QPaintDevice::PdmDpiY: return d->engine->resolution(); case QPaintDevice::PdmHeightMM: - return qRound(d->engine->size().height() * (d->engine->resolution() / qreal(25.4))); + return qRound(d->engine->size().height() * 25.4 / d->engine->resolution()); case QPaintDevice::PdmWidthMM: - return qRound(d->engine->size().width() * (d->engine->resolution() / qreal(25.4))); + return qRound(d->engine->size().width() * 25.4 / d->engine->resolution()); case QPaintDevice::PdmNumColors: return 0xffffffff; case QPaintDevice::PdmPhysicalDpiX: @@ -842,9 +842,8 @@ bool QSvgPaintEngine::begin(QPaintDevice *) *d->stream << "" << endl << "size.isValid()) { - const qreal mm_factor = d->resolution / qreal(25.4); - const qreal wmm = d->size.width() * mm_factor; - const qreal hmm = d->size.height() * mm_factor; + qreal wmm = d->size.width() * 25.4 / d->resolution; + qreal hmm = d->size.height() * 25.4 / d->resolution; *d->stream << " width=\"" << wmm << "mm\" height=\"" << hmm << "mm\"" << endl; } diff --git a/src/svg/qsvggraphics.cpp b/src/svg/qsvggraphics.cpp index cc3c170..6552b69 100644 --- a/src/svg/qsvggraphics.cpp +++ b/src/svg/qsvggraphics.cpp @@ -332,12 +332,11 @@ void QSvgText::draw(QPainter *p, QSvgExtraStates &states) // Force the font to have a size of 100 pixels to avoid truncation problems // when the font is very small. - const qreal scale = qreal(100.0) / p->font().pointSizeF(); - const qreal inv_scale = p->font().pointSizeF() / qreal(100.0); // like '1/scale' but with less rounding errors + qreal scale = 100.0 / p->font().pointSizeF(); Qt::Alignment alignment = states.textAnchor; QTransform oldTransform = p->worldTransform(); - p->scale(inv_scale, inv_scale); + p->scale(1 / scale, 1 / scale); qreal y = 0; bool initial = true; @@ -347,7 +346,7 @@ void QSvgText::draw(QPainter *p, QSvgExtraStates &states) if (m_type == TEXTAREA) { if (alignment == Qt::AlignHCenter) - px += scaledSize.width() * qreal(0.5); + px += scaledSize.width() / 2; else if (alignment == Qt::AlignRight) px += scaledSize.width(); } @@ -460,7 +459,7 @@ void QSvgText::draw(QPainter *p, QSvgExtraStates &states) qreal x = 0; if (alignment == Qt::AlignHCenter) - x -= qreal(0.5) * line.naturalTextWidth(); + x -= 0.5 * line.naturalTextWidth(); else if (alignment == Qt::AlignRight) x -= line.naturalTextWidth(); @@ -480,7 +479,7 @@ void QSvgText::draw(QPainter *p, QSvgExtraStates &states) break; } - y += qreal(1.1) * line.height(); + y += 1.1 * line.height(); } tl.draw(p, QPointF(px, py), QVector(), bounds); diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index a340c05..3ed918e 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -66,7 +66,6 @@ #include "qnumeric.h" #include "qvarlengtharray.h" #include "private/qmath_p.h" -#include "private/qnumeric_p.h" #include "float.h" @@ -909,7 +908,7 @@ static inline qreal convertToNumber(const QString &str, QSvgHandler *handler, bo QSvgHandler::LengthType type; qreal num = parseLength(str, type, handler, ok); if (type == QSvgHandler::LT_PERCENT) { - num = num * qreal(0.01); + num = num/100.0; } return num; } @@ -944,13 +943,13 @@ static qreal convertToPixels(qreal len, bool , QSvgHandler::LengthType type) case QSvgHandler::LT_PC: break; case QSvgHandler::LT_PT: - return len * qreal(1.25); + return len * 1.25; break; case QSvgHandler::LT_MM: - return len * qreal(3.543307); + return len * 3.543307; break; case QSvgHandler::LT_CM: - return len * qreal(35.43307); + return len * 35.43307; break; case QSvgHandler::LT_IN: return len * 90; @@ -1373,16 +1372,16 @@ static void pathArcSegment(QPainterPath &path, qreal t; qreal thHalf; - sinTh = qSin(xAxisRotation * Q_PI180); - cosTh = qCos(xAxisRotation * Q_PI180); + sinTh = qSin(xAxisRotation * (Q_PI / 180.0)); + cosTh = qCos(xAxisRotation * (Q_PI / 180.0)); a00 = cosTh * rx; a01 = -sinTh * ry; a10 = sinTh * rx; a11 = cosTh * ry; - thHalf = qreal(0.5) * (th1 - th0); - t = (qreal(8.0) / qreal(3.0)) * qSin(thHalf * qreal(0.5)) * qSin(thHalf * qreal(0.5)) / qSin(thHalf); + thHalf = 0.5 * (th1 - th0); + t = (8.0 / 3.0) * qSin(thHalf * 0.5) * qSin(thHalf * 0.5) / qSin(thHalf); x1 = xc + qCos(th0) - t * qSin(th0); y1 = yc + qSin(th0) + t * qCos(th0); x3 = xc + qCos(th1); @@ -1442,11 +1441,11 @@ static void pathArc(QPainterPath &path, rx = qAbs(rx); ry = qAbs(ry); - sin_th = qSin(x_axis_rotation * Q_PI180); - cos_th = qCos(x_axis_rotation * Q_PI180); + sin_th = qSin(x_axis_rotation * (Q_PI / 180.0)); + cos_th = qCos(x_axis_rotation * (Q_PI / 180.0)); - dx = (curx - x) * qreal(0.5); - dy = (cury - y) * qreal(0.5); + dx = (curx - x) / 2.0; + dy = (cury - y) / 2.0; dx1 = cos_th * dx + sin_th * dy; dy1 = -sin_th * dx + cos_th * dy; Pr1 = rx * rx; @@ -1460,12 +1459,10 @@ static void pathArc(QPainterPath &path, ry = ry * qSqrt(check); } - const qreal inv_rx = 1 / rx; - const qreal inv_ry = 1 / ry; - a00 = cos_th * inv_rx; - a01 = sin_th * inv_rx; - a10 = -sin_th * inv_ry; - a11 = cos_th * inv_ry; + a00 = cos_th / rx; + a01 = sin_th / rx; + a10 = -sin_th / ry; + a11 = cos_th / ry; x0 = a00 * curx + a01 * cury; y0 = a10 * curx + a11 * cury; x1 = a00 * x + a01 * y; @@ -1476,12 +1473,12 @@ static void pathArc(QPainterPath &path, The arc fits a unit-radius circle in this space. */ d = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0); - sfactor_sq = qreal(1.0) / d - qreal(0.25); + sfactor_sq = 1.0 / d - 0.25; if (sfactor_sq < 0) sfactor_sq = 0; sfactor = qSqrt(sfactor_sq); if (sweep_flag == large_arc_flag) sfactor = -sfactor; - xc = qreal(0.5) * (x0 + x1) - sfactor * (y1 - y0); - yc = qreal(0.5) * (y0 + y1) + sfactor * (x1 - x0); + xc = 0.5 * (x0 + x1) - sfactor * (y1 - y0); + yc = 0.5 * (y0 + y1) + sfactor * (x1 - x0); /* (xc, yc) is center of the circle. */ th0 = atan2(y0 - yc, x0 - xc); @@ -1489,18 +1486,16 @@ static void pathArc(QPainterPath &path, th_arc = th1 - th0; if (th_arc < 0 && sweep_flag) - th_arc += Q_2PI; + th_arc += 2 * Q_PI; else if (th_arc > 0 && !sweep_flag) - th_arc -= Q_2PI; + th_arc -= 2 * Q_PI; - n_segs = qCeil(qAbs(th_arc / (Q_PI2 + qreal(0.001)))); + n_segs = qCeil(qAbs(th_arc / (Q_PI * 0.5 + 0.001))); - const qreal th_arc_div_n_segs = th_arc / n_segs; for (i = 0; i < n_segs; i++) { - const qreal i_mul_th_arc_div_n_segs = i * th_arc_div_n_segs; pathArcSegment(path, xc, yc, - th0 + i_mul_th_arc_div_n_segs, - th0 + i_mul_th_arc_div_n_segs + th_arc_div_n_segs, + th0 + i * th_arc / n_segs, + th0 + (i + 1) * th_arc / n_segs, rx, ry, x_axis_rotation); } } @@ -2974,10 +2969,10 @@ static QSvgNode *createRectNode(QSvgNode *parent, //9.2 The 'rect' element clearly specifies it // but the case might in fact be handled because // we draw rounded rectangles differently - if (nrx > bounds.width()*qreal(0.5)) - nrx = bounds.width()*qreal(0.5); - if (nry > bounds.height()*qreal(0.5)) - nry = bounds.height()*qreal(0.5); + if (nrx > bounds.width()/2) + nrx = bounds.width()/2; + if (nry > bounds.height()/2) + nry = bounds.height()/2; if (nrx && !nry) nry = nrx; @@ -2987,8 +2982,8 @@ static QSvgNode *createRectNode(QSvgNode *parent, //we draw rounded rect from 0...99 //svg from 0...bounds.width()/2 so we're adjusting the //coordinates - nrx *= (200/bounds.width()); - nry *= (200/bounds.height()); + nrx *= (100/(bounds.width()/2)); + nry *= (100/(bounds.height()/2)); QSvgNode *rect = new QSvgRect(parent, bounds, int(nrx), @@ -3078,7 +3073,7 @@ static bool parseStopNode(QSvgStyleProperty *parent, bool ok = true; qreal offset = convertToNumber(offsetStr, handler, &ok); if (!ok) - offset = qreal(0.0); + offset = 0.0; QString black = QString::fromLatin1("#000000"); if (colorStr.isEmpty()) { colorStr = QStringRef(&black); @@ -3098,9 +3093,9 @@ static bool parseStopNode(QSvgStyleProperty *parent, } // If offset is greater than one, it must be clamped to one. - if (offset > qreal(1.0)) { - if ((stops.size() == 1) || (stops.at(stops.size() - 2).first < qreal(1.0) - FLT_EPSILON)) { - stops.back().first = qreal(1.0) - FLT_EPSILON; + if (offset > 1.0) { + if ((stops.size() == 1) || (stops.at(stops.size() - 2).first < 1.0 - FLT_EPSILON)) { + stops.back().first = 1.0 - FLT_EPSILON; grad->setStops(stops); } offset = 1.0; diff --git a/src/svg/qsvgtinydocument.cpp b/src/svg/qsvgtinydocument.cpp index 21e9e9f..e2cefeb 100644 --- a/src/svg/qsvgtinydocument.cpp +++ b/src/svg/qsvgtinydocument.cpp @@ -466,19 +466,20 @@ QMatrix QSvgTinyDocument::matrixForElement(const QString &id) const int QSvgTinyDocument::currentFrame() const { - const qreal runningPercentage = qMin(qreal(m_time.elapsed()) / qreal(m_animationDuration), qreal(1.)); + double runningPercentage = qMin(m_time.elapsed()/double(m_animationDuration), 1.); - const int totalFrames = m_fps * m_animationDuration; + int totalFrames = m_fps * m_animationDuration; return int(runningPercentage * totalFrames); } void QSvgTinyDocument::setCurrentFrame(int frame) { - const int totalFrames = m_fps * m_animationDuration; - const qreal framePercentage = frame / totalFrames; - const qreal timeForFrame = m_animationDuration * framePercentage * 1000; //in ms - const int timeToAdd = int(timeForFrame - m_time.elapsed()); + int totalFrames = m_fps * m_animationDuration; + double framePercentage = frame/double(totalFrames); + double timeForFrame = m_animationDuration * framePercentage; //in S + timeForFrame *= 1000; //in ms + int timeToAdd = int(timeForFrame - m_time.elapsed()); m_time = m_time.addMSecs(timeToAdd); } -- cgit v0.12 From 258e751b7f4c3ff5e44fdbd654ce45d0693934bf Mon Sep 17 00:00:00 2001 From: Janne Anttila Date: Wed, 11 Nov 2009 15:34:15 +0200 Subject: Fix for assertion failure in in QWidget::grabMouse for Symbian. Docs say: "Note that only visible widgets can grab mouse input. If isVisible() returns false for a widget, that widget cannot call grabMouse()." qwidget_x11.cpp uses the similar condition in grabMouse as symbian after this commit. Task-number: QTBUG-5658 Reviewed-by: Jason Barron --- src/gui/kernel/qwidget_s60.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp index 915d308..504a538 100644 --- a/src/gui/kernel/qwidget_s60.cpp +++ b/src/gui/kernel/qwidget_s60.cpp @@ -1236,7 +1236,7 @@ void QWidget::releaseKeyboard() void QWidget::grabMouse() { - if (!qt_nograb()) { + if (isVisible() && !qt_nograb()) { if (QWidgetPrivate::mouseGrabber && QWidgetPrivate::mouseGrabber != this) QWidgetPrivate::mouseGrabber->releaseMouse(); Q_ASSERT(testAttribute(Qt::WA_WState_Created)); @@ -1253,7 +1253,7 @@ void QWidget::grabMouse() #ifndef QT_NO_CURSOR void QWidget::grabMouse(const QCursor &cursor) { - if (!qt_nograb()) { + if (isVisible() && !qt_nograb()) { if (QWidgetPrivate::mouseGrabber && QWidgetPrivate::mouseGrabber != this) QWidgetPrivate::mouseGrabber->releaseMouse(); Q_ASSERT(testAttribute(Qt::WA_WState_Created)); -- cgit v0.12