diff --git a/core/color.h b/core/color.h index 37281045e..3e9999e4e 100644 --- a/core/color.h +++ b/core/color.h @@ -7,65 +7,74 @@ #include +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 diff --git a/desktop-widgets/kmessagewidget.cpp b/desktop-widgets/kmessagewidget.cpp index f293e7527..c64635220 100644 --- a/desktop-widgets/kmessagewidget.cpp +++ b/desktop-widgets/kmessagewidget.cpp @@ -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; } diff --git a/desktop-widgets/qtwaitingspinner.cpp b/desktop-widgets/qtwaitingspinner.cpp index 14e8669b0..bfe024b92 100644 --- a/desktop-widgets/qtwaitingspinner.cpp +++ b/desktop-widgets/qtwaitingspinner.cpp @@ -272,7 +272,7 @@ QColor QtWaitingSpinner::currentLineColor(int countDistance, int totalNrOfLines, int distanceThreshold = static_cast(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(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; } diff --git a/profile-widget/divepercentageitem.cpp b/profile-widget/divepercentageitem.cpp index 1e879406a..5b2d83474 100644 --- a/profile-widget/divepercentageitem.cpp +++ b/profile-widget/divepercentageitem.cpp @@ -52,27 +52,35 @@ static std::array 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) diff --git a/profile-widget/divepixmapcache.cpp b/profile-widget/divepixmapcache.cpp index 4f487a41b..37c6146ae 100644 --- a/profile-widget/divepixmapcache.cpp +++ b/profile-widget/divepixmapcache.cpp @@ -2,6 +2,7 @@ #include "divepixmapcache.h" #include "core/metrics.h" #include "core/qthelper.h" // for renderSVGIconWidth +#include "core/color.h" #include @@ -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> cache; diff --git a/stats/regressionitem.cpp b/stats/regressionitem.cpp index 9f176c6ae..3377ec419 100644 --- a/stats/regressionitem.cpp +++ b/stats/regressionitem.cpp @@ -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);