mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 14:10:19 +00:00
cleanup: prevent distracing conversion warnings
We do want the -Wfloat-conversion warnings where they point out potential bugs. But they are very distracting when they are triggered by floating point literals (which the standard defines as double) passed to a function expecting float arguments. The fact that Qt6 changes the arguments to all these functions from double to float is... hard to explain, but it is what it is. With these changes, for the majority of cases we create inlined helpers that conditionally compile to do the right thing. And in a handful of other cases we simply cast to float (and accept that on Qt5 this then gets cast back to double... for none of these cases the potential loss in precision makes any difference, anyway - which likely is why the Qt community made the decision to change the type of the arguments in the first place). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
81ed23583e
commit
59fe2f3d7e
6 changed files with 84 additions and 66 deletions
105
core/color.h
105
core/color.h
|
@ -7,65 +7,74 @@
|
|||
|
||||
#include <QColor>
|
||||
|
||||
static inline QColor makeColor(double r, double g, double b, double a = 1.0)
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) // they are just trolling us with these changes
|
||||
return QColor::fromRgbF((float)r, (float)g, (float)b, (float)a);
|
||||
#else
|
||||
return QColor::fromRgbF(r, g, b, a);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Greens
|
||||
#define CAMARONE1 QColor::fromRgbF(0.0, 0.4, 0.0, 1)
|
||||
#define FUNGREEN1 QColor::fromRgbF(0.0, 0.4, 0.2, 1)
|
||||
#define FUNGREEN1_HIGH_TRANS QColor::fromRgbF(0.0, 0.4, 0.2, 0.25)
|
||||
#define KILLARNEY1 QColor::fromRgbF(0.2, 0.4, 0.2, 1)
|
||||
#define APPLE1 QColor::fromRgbF(0.2, 0.6, 0.2, 1)
|
||||
#define APPLE1_MED_TRANS QColor::fromRgbF(0.2, 0.6, 0.2, 0.5)
|
||||
#define APPLE1_HIGH_TRANS QColor::fromRgbF(0.2, 0.6, 0.2, 0.25)
|
||||
#define LIMENADE1 QColor::fromRgbF(0.4, 0.8, 0.0, 1)
|
||||
#define ATLANTIS1 QColor::fromRgbF(0.4, 0.8, 0.2, 1)
|
||||
#define ATLANTIS2 QColor::fromRgbF(0.6, 0.8, 0.2, 1)
|
||||
#define RIOGRANDE1 QColor::fromRgbF(0.8, 0.8, 0.0, 1)
|
||||
#define EARLSGREEN1 QColor::fromRgbF(0.8, 0.8, 0.2, 1)
|
||||
#define FORESTGREEN1 QColor::fromRgbF(0.1, 0.5, 0.1, 1)
|
||||
#define NITROX_GREEN QColor::fromRgbF(0, 0.54, 0.375, 1)
|
||||
#define CAMARONE1 makeColor(0.0, 0.4, 0.0)
|
||||
#define FUNGREEN1 makeColor(0.0, 0.4, 0.2)
|
||||
#define FUNGREEN1_HIGH_TRANS makeColor(0.0, 0.4, 0.2, 0.25)
|
||||
#define KILLARNEY1 makeColor(0.2, 0.4, 0.2)
|
||||
#define APPLE1 makeColor(0.2, 0.6, 0.2)
|
||||
#define APPLE1_MED_TRANS makeColor(0.2, 0.6, 0.2, 0.5)
|
||||
#define APPLE1_HIGH_TRANS makeColor(0.2, 0.6, 0.2, 0.25)
|
||||
#define LIMENADE1 makeColor(0.4, 0.8, 0.0)
|
||||
#define ATLANTIS1 makeColor(0.4, 0.8, 0.2)
|
||||
#define ATLANTIS2 makeColor(0.6, 0.8, 0.2)
|
||||
#define RIOGRANDE1 makeColor(0.8, 0.8, 0.0)
|
||||
#define EARLSGREEN1 makeColor(0.8, 0.8, 0.2)
|
||||
#define FORESTGREEN1 makeColor(0.1, 0.5, 0.1)
|
||||
#define NITROX_GREEN makeColor(0, 0.54, 0.375)
|
||||
|
||||
// Reds
|
||||
#define PERSIANRED1 QColor::fromRgbF(0.8, 0.2, 0.2, 1)
|
||||
#define TUSCANY1 QColor::fromRgbF(0.8, 0.4, 0.2, 1)
|
||||
#define PIRATEGOLD1 QColor::fromRgbF(0.8, 0.5, 0.0, 1)
|
||||
#define PIRATEGOLD1_MED_TRANS QColor::fromRgbF(0.8, 0.5, 0.0, 0.75)
|
||||
#define HOKEYPOKEY1 QColor::fromRgbF(0.8, 0.6, 0.2, 1)
|
||||
#define CINNABAR1 QColor::fromRgbF(0.9, 0.3, 0.2, 1)
|
||||
#define REDORANGE1 QColor::fromRgbF(1.0, 0.2, 0.2, 1)
|
||||
#define REDORANGE1_HIGH_TRANS QColor::fromRgbF(1.0, 0.2, 0.2, 0.25)
|
||||
#define REDORANGE1_MED_TRANS QColor::fromRgbF(1.0, 0.2, 0.2, 0.5)
|
||||
#define RED1_MED_TRANS QColor::fromRgbF(1.0, 0.0, 0.0, 0.5)
|
||||
#define RED1 QColor::fromRgbF(1.0, 0.0, 0.0, 1)
|
||||
#define PERSIANRED1 makeColor(0.8, 0.2, 0.2)
|
||||
#define TUSCANY1 makeColor(0.8, 0.4, 0.2)
|
||||
#define PIRATEGOLD1 makeColor(0.8, 0.5, 0.0)
|
||||
#define PIRATEGOLD1_MED_TRANS makeColor(0.8, 0.5, 0.0, 0.75)
|
||||
#define HOKEYPOKEY1 makeColor(0.8, 0.6, 0.2)
|
||||
#define CINNABAR1 makeColor(0.9, 0.3, 0.2)
|
||||
#define REDORANGE1 makeColor(1.0, 0.2, 0.2)
|
||||
#define REDORANGE1_HIGH_TRANS makeColor(1.0, 0.2, 0.2, 0.25)
|
||||
#define REDORANGE1_MED_TRANS makeColor(1.0, 0.2, 0.2, 0.5)
|
||||
#define RED1_MED_TRANS makeColor(1.0, 0.0, 0.0, 0.5)
|
||||
#define RED1 makeColor(1.0, 0.0, 0.0)
|
||||
|
||||
// Monochromes
|
||||
#define BLACK1 QColor::fromRgbF(0.0, 0.0, 0.0, 1)
|
||||
#define BLACK1_LOW_TRANS QColor::fromRgbF(0.0, 0.0, 0.0, 0.75)
|
||||
#define BLACK1_HIGH_TRANS QColor::fromRgbF(0.0, 0.0, 0.0, 0.25)
|
||||
#define TUNDORA1_MED_TRANS QColor::fromRgbF(0.3, 0.3, 0.3, 0.5)
|
||||
#define MED_GRAY_HIGH_TRANS QColor::fromRgbF(0.5, 0.5, 0.5, 0.25)
|
||||
#define MERCURY1_MED_TRANS QColor::fromRgbF(0.9, 0.9, 0.9, 0.5)
|
||||
#define CONCRETE1_LOWER_TRANS QColor::fromRgbF(0.95, 0.95, 0.95, 0.9)
|
||||
#define WHITE1_MED_TRANS QColor::fromRgbF(1.0, 1.0, 1.0, 0.5)
|
||||
#define WHITE1 QColor::fromRgbF(1.0, 1.0, 1.0, 1)
|
||||
#define BLACK1 makeColor(0.0, 0.0, 0.0)
|
||||
#define BLACK1_LOW_TRANS makeColor(0.0, 0.0, 0.0, 0.75)
|
||||
#define BLACK1_HIGH_TRANS makeColor(0.0, 0.0, 0.0, 0.25)
|
||||
#define TUNDORA1_MED_TRANS makeColor(0.3, 0.3, 0.3, 0.5)
|
||||
#define MED_GRAY_HIGH_TRANS makeColor(0.5, 0.5, 0.5, 0.25)
|
||||
#define MERCURY1_MED_TRANS makeColor(0.9, 0.9, 0.9, 0.5)
|
||||
#define CONCRETE1_LOWER_TRANS makeColor(0.95, 0.95, 0.95, 0.9)
|
||||
#define WHITE1_MED_TRANS makeColor(1.0, 1.0, 1.0, 0.5)
|
||||
#define WHITE1 makeColor(1.0, 1.0, 1.0)
|
||||
|
||||
// Blues
|
||||
#define GOVERNORBAY2 QColor::fromRgbF(0.2, 0.2, 0.7, 1)
|
||||
#define GOVERNORBAY1_MED_TRANS QColor::fromRgbF(0.2, 0.2, 0.8, 0.5)
|
||||
#define ROYALBLUE2 QColor::fromRgbF(0.2, 0.2, 0.9, 1)
|
||||
#define ROYALBLUE2_LOW_TRANS QColor::fromRgbF(0.2, 0.2, 0.9, 0.75)
|
||||
#define AIR_BLUE QColor::fromRgbF(0.25, 0.75, 1.0, 1)
|
||||
#define AIR_BLUE_TRANS QColor::fromRgbF(0.25, 0.75, 1.0, 0.5)
|
||||
#define GOVERNORBAY2 makeColor(0.2, 0.2, 0.7)
|
||||
#define GOVERNORBAY1_MED_TRANS makeColor(0.2, 0.2, 0.8, 0.5)
|
||||
#define ROYALBLUE2 makeColor(0.2, 0.2, 0.9)
|
||||
#define ROYALBLUE2_LOW_TRANS makeColor(0.2, 0.2, 0.9, 0.75)
|
||||
#define AIR_BLUE makeColor(0.25, 0.75, 1.0)
|
||||
#define AIR_BLUE_TRANS makeColor(0.25, 0.75, 1.0, 0.5)
|
||||
|
||||
// Yellows / BROWNS
|
||||
#define SPRINGWOOD1 QColor::fromRgbF(0.95, 0.95, 0.9, 1)
|
||||
#define SPRINGWOOD1_MED_TRANS QColor::fromRgbF(0.95, 0.95, 0.9, 0.5)
|
||||
#define BROOM1_LOWER_TRANS QColor::fromRgbF(1.0, 1.0, 0.1, 0.9)
|
||||
#define PEANUT QColor::fromRgbF(0.5, 0.2, 0.1, 1.0)
|
||||
#define PEANUT_MED_TRANS QColor::fromRgbF(0.5, 0.2, 0.1, 0.5)
|
||||
#define NITROX_YELLOW QColor::fromRgbF(0.98, 0.89, 0.07, 1.0)
|
||||
#define SPRINGWOOD1 makeColor(0.95, 0.95, 0.9)
|
||||
#define SPRINGWOOD1_MED_TRANS makeColor(0.95, 0.95, 0.9, 0.5)
|
||||
#define BROOM1_LOWER_TRANS makeColor(1.0, 1.0, 0.1, 0.9)
|
||||
#define PEANUT makeColor(0.5, 0.2, 0.1)
|
||||
#define PEANUT_MED_TRANS makeColor(0.5, 0.2, 0.1, 0.5)
|
||||
#define NITROX_YELLOW makeColor(0.98, 0.89, 0.07)
|
||||
|
||||
// Magentas
|
||||
#define MEDIUMREDVIOLET1_HIGHER_TRANS QColor::fromRgbF(0.7, 0.2, 0.7, 0.1)
|
||||
#define MAGENTA QColor::fromRgbF(1.0, 0.0, 1.0, 1.0)
|
||||
#define MEDIUMREDVIOLET1_HIGHER_TRANS makeColor(0.7, 0.2, 0.7, 0.1)
|
||||
#define MAGENTA makeColor(1.0, 0.0, 1.0)
|
||||
|
||||
#define SAC_COLORS_START_IDX SAC_1
|
||||
#define SAC_COLORS 9
|
||||
|
|
|
@ -250,9 +250,9 @@ KMessageWidget::MessageType KMessageWidget::messageType() const
|
|||
|
||||
static QColor darkShade(QColor c)
|
||||
{
|
||||
qreal contrast = 0.7; // taken from kcolorscheme for the dark shade
|
||||
double contrast = 0.7; // taken from kcolorscheme for the dark shade
|
||||
|
||||
qreal darkAmount;
|
||||
double darkAmount;
|
||||
if (c.lightnessF() < 0.006) { /* too dark */
|
||||
darkAmount = 0.02 + 0.40 * contrast;
|
||||
} else if (c.lightnessF() > 0.93) { /* too bright */
|
||||
|
@ -261,9 +261,9 @@ static QColor darkShade(QColor c)
|
|||
darkAmount = (-c.lightnessF()) * (0.55 + contrast * 0.35);
|
||||
}
|
||||
|
||||
qreal v = c.lightnessF() + darkAmount;
|
||||
double v = c.lightnessF() + darkAmount;
|
||||
v = v > 0.0 ? (v < 1.0 ? v : 1.0) : 0.0;
|
||||
c.setHsvF(c.hslHueF(), c.hslSaturationF(), v);
|
||||
c.setHsvF(c.hslHueF(), c.hslSaturationF(), (float)v);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
|
|
@ -272,7 +272,7 @@ QColor QtWaitingSpinner::currentLineColor(int countDistance, int totalNrOfLines,
|
|||
int distanceThreshold =
|
||||
static_cast<int>(ceil((totalNrOfLines - 1) * trailFadePerc / 100.0));
|
||||
if (countDistance > distanceThreshold) {
|
||||
color.setAlphaF(minAlphaF);
|
||||
color.setAlphaF((float)minAlphaF);
|
||||
} else {
|
||||
qreal alphaDiff = color.alphaF() - minAlphaF;
|
||||
qreal gradient = alphaDiff / static_cast<qreal>(distanceThreshold + 1);
|
||||
|
@ -280,7 +280,7 @@ QColor QtWaitingSpinner::currentLineColor(int countDistance, int totalNrOfLines,
|
|||
|
||||
// If alpha is out of bounds, clip it.
|
||||
resultAlpha = std::min(1.0, std::max(0.0, resultAlpha));
|
||||
color.setAlphaF(resultAlpha);
|
||||
color.setAlphaF((float)resultAlpha);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
|
|
@ -52,27 +52,35 @@ static std::array<int, num_tissues> calcLinesPerTissue(int size)
|
|||
return res;
|
||||
}
|
||||
|
||||
static inline QRgb hsv2rgb(double h, double s, double v)
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) // they are just trolling us with these changes
|
||||
QColor c = QColor::fromHslF((float)h, (float)s, (float)v);
|
||||
#else
|
||||
QColor c = QColor::fromHslF(h, s, v);
|
||||
#endif
|
||||
return c.rgba();
|
||||
}
|
||||
|
||||
static QRgb colorScale(double value, int inert)
|
||||
{
|
||||
QColor color;
|
||||
double scaledValue = value / (AMB_PERCENTAGE * inert) * 1000.0;
|
||||
if (scaledValue < 0.8) // grade from cyan to blue to purple
|
||||
color.setHsvF(0.5 + 0.25 * scaledValue / 0.8, 1.0, 1.0);
|
||||
return hsv2rgb(0.5 + 0.25 * scaledValue / 0.8, 1.0, 1.0);
|
||||
else if (scaledValue < 1.0) // grade from magenta to black
|
||||
color.setHsvF(0.75, 1.0, (1.0 - scaledValue) / 0.2);
|
||||
return hsv2rgb(0.75, 1.0, (1.0 - scaledValue) / 0.2);
|
||||
else if (value < AMB_PERCENTAGE) // grade from black to bright green
|
||||
color.setHsvF(0.333, 1.0, (value - AMB_PERCENTAGE * inert / 1000.0) / (AMB_PERCENTAGE - AMB_PERCENTAGE * inert / 1000.0));
|
||||
return hsv2rgb(0.333, 1.0, (value - AMB_PERCENTAGE * inert / 1000.0) / (AMB_PERCENTAGE - AMB_PERCENTAGE * inert / 1000.0));
|
||||
else if (value < 65) // grade from bright green (0% M) to yellow-green (30% M)
|
||||
color.setHsvF(0.333 - 0.133 * (value - AMB_PERCENTAGE) / (65.0 - AMB_PERCENTAGE), 1.0, 1.0);
|
||||
return hsv2rgb(0.333 - 0.133 * (value - AMB_PERCENTAGE) / (65.0 - AMB_PERCENTAGE), 1.0, 1.0);
|
||||
else if (value < 85) // grade from yellow-green (30% M) to orange (70% M)
|
||||
color.setHsvF(0.2 - 0.1 * (value - 65.0) / 20.0, 1.0, 1.0);
|
||||
return hsv2rgb(0.2 - 0.1 * (value - 65.0) / 20.0, 1.0, 1.0);
|
||||
else if (value < 100) // grade from orange (70% M) to red (100% M)
|
||||
color.setHsvF(0.1 * (100.0 - value) / 15.0, 1.0, 1.0);
|
||||
return hsv2rgb(0.1 * (100.0 - value) / 15.0, 1.0, 1.0);
|
||||
else if (value < 120) // M value exceeded - grade from red to white
|
||||
color.setHsvF(0.0, 1 - (value - 100.0) / 20.0, 1.0);
|
||||
return hsv2rgb(0.0, 1 - (value - 100.0) / 20.0, 1.0);
|
||||
else // white
|
||||
color.setHsvF(0.0, 0.0, 1.0);
|
||||
return color.rgba();
|
||||
return hsv2rgb(0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
void DivePercentageItem::replot(const dive *d, const struct divecomputer *dc, const plot_info &pi)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "divepixmapcache.h"
|
||||
#include "core/metrics.h"
|
||||
#include "core/qthelper.h" // for renderSVGIconWidth
|
||||
#include "core/color.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
@ -49,7 +50,7 @@ DivePixmaps::DivePixmaps(int dpr) : dpr(dpr)
|
|||
// The transparen pixmap is a very obscure feature to enable tooltips without showing a pixmap.
|
||||
// See code in diveeventitem.cpp. This should probably be replaced by a different mechanism.
|
||||
QPixmap transparentPixmap(lrint(4 * dprf), lrint(20 * dprf));
|
||||
transparentPixmap.fill(QColor::fromRgbF(1.0, 1.0, 1.0, 0.01));
|
||||
transparentPixmap.fill(makeColor(1.0, 1.0, 1.0, 0.01));
|
||||
}
|
||||
|
||||
static std::vector<std::shared_ptr<const DivePixmaps>> cache;
|
||||
|
|
|
@ -87,7 +87,7 @@ void RegressionItem::updatePosition()
|
|||
img->fill(Qt::transparent);
|
||||
if (confidence) {
|
||||
QColor col(regressionItemColor);
|
||||
col.setAlphaF(reg.r2);
|
||||
col.setAlphaF((float)reg.r2);
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(QBrush(col));
|
||||
painter->drawPolygon(poly);
|
||||
|
|
Loading…
Reference in a new issue