Merge branch 'master' of https://github.com/fluxer/kdelibs into devinfo

This commit is contained in:
Ivailo Monev 2021-07-16 15:04:55 +03:00
commit 6bd35f1a56
4 changed files with 30 additions and 38 deletions

View file

@ -40,6 +40,11 @@ KTemperaturePrivate::KTemperaturePrivate(const double number, const QString &uni
} else if (unit == QString::fromUtf8("°F") || unit == QLatin1String("F") || unit == QLatin1String("Fahrenheit")) {
m_tempunit = KTemperature::Fahrenheit;
m_unit = QString::fromUtf8("°F");
// kelvin and kelvins are for KUnitConversion compatibility
} else if (unit == QLatin1String("K") || unit == QLatin1String("Kelvin")
|| unit == QLatin1String("kelvin") || unit == QLatin1String("kelvins")) {
m_tempunit = KTemperature::Kelvin;
m_unit = QLatin1String("K");
} else {
kDebug() << "invalid unit" << unit;
m_unit = QLatin1String("Unknown");
@ -73,16 +78,29 @@ QString KTemperature::toString() const
double KTemperature::convertTo(const KTempUnit unit) const
{
static const double celsius_fahrenheit_ratio = 33.8;
if (unit == d->m_tempunit) {
return d->m_number;
}
if (d->m_tempunit == KTemperature::Fahrenheit && unit == KTemperature::Celsius) {
return (d->m_number / celsius_fahrenheit_ratio);
} else if (d->m_tempunit == KTemperature::Celsius && unit == KTemperature::Fahrenheit) {
return (d->m_number * celsius_fahrenheit_ratio);
// for reference:
// https://www.rapidtables.com/convert/temperature/celsius-to-fahrenheit.html
// https://www.rapidtables.com/convert/temperature/celsius-to-kelvin.html
// https://www.rapidtables.com/convert/temperature/fahrenheit-to-celsius.html
// https://www.rapidtables.com/convert/temperature/fahrenheit-to-kelvin.html
// https://www.rapidtables.com/convert/temperature/kelvin-to-celsius.html
// https://www.rapidtables.com/convert/temperature/kelvin-to-fahrenheit.html
if (d->m_tempunit == KTemperature::Celsius && unit == KTemperature::Fahrenheit) {
return (d->m_number * 1.8 + 32);
} else if (d->m_tempunit == KTemperature::Celsius && unit == KTemperature::Kelvin) {
return (d->m_number + 273.15);
} else if (d->m_tempunit == KTemperature::Fahrenheit && unit == KTemperature::Celsius) {
return ((d->m_number - 32) / 1.8);
} else if (d->m_tempunit == KTemperature::Fahrenheit && unit == KTemperature::Kelvin) {
return ((d->m_number + 459.67) * 0.5);
} else if (d->m_tempunit == KTemperature::Kelvin && unit == KTemperature::Celsius) {
return (d->m_number - 273.15);
} else if (d->m_tempunit == KTemperature::Kelvin && unit == KTemperature::Fahrenheit) {
return (d->m_number * 1.8 - 459.67);
}
return 0.0;
}

View file

@ -33,13 +33,14 @@ public:
enum KTempUnit {
Invalid,
Celsius,
Fahrenheit
Fahrenheit,
Kelvin
};
/*!
@brief Constructs convertor
@param number value of the unit
@param unit string representation of the unit one of: "°C", "C", "Celsius", "°F", "F" or "Fahrenheit"
@param unit string representation of the unit one of: "°C", "C", "Celsius", "°F", "F", "Fahrenheit", "Kelvin" or "K"
*/
KTemperature(const double number, const QString &unit);
~KTemperature();
@ -49,11 +50,11 @@ public:
*/
double number() const;
/*!
@return Short string representing the unit passed to the constructor, e.g. "°C" or "°F"
@return Short string representing the unit passed to the constructor, e.g. "°C", "°F" or "K"
*/
QString unit() const;
/*!
@return Combination of the number and unit as string, e.g. "12 °C" or "123 °F"
@return Combination of the number and unit as string, e.g. "12 °C", "123 °F" or "123 K"
*/
QString toString() const;
/*!

View file

@ -68,10 +68,6 @@ bool isEffectAvailable(Effect effect)
case BlurBehind:
effectName = "_KDE_NET_WM_BLUR_BEHIND_REGION";
break;
case Dashboard:
// TODO: Better namespacing for atoms
effectName = "_WM_EFFECT_KDE_DASHBOARD";
break;
default:
return false;
}
@ -323,18 +319,6 @@ void enableBlurBehind(WId window, bool enable, const QRegion &region)
#endif
}
void markAsDashboard(WId window)
{
#ifdef Q_WS_X11
// avoid cast warning
char dash[] = "dashboard";
XClassHint classHint;
classHint.res_name = dash;
classHint.res_class = dash;
XSetClassHint(QX11Info::display(), window, &classHint);
#endif
}
}
}

View file

@ -42,8 +42,7 @@ namespace WindowEffects
PresentWindowsGroup = 4,
HighlightWindows = 5,
OverrideShadow = 6,
BlurBehind = 7,
Dashboard = 8
BlurBehind = 7
};
/**
@ -151,16 +150,6 @@ namespace WindowEffects
* @since 4.5
*/
PLASMA_EXPORT void enableBlurBehind(WId window, bool enable = true, const QRegion &region = QRegion());
/**
* Instructs the window manager to handle the given window as dashboard window as
* Dashboard windows should be handled diffrently and may have special effects
* applied to them.
*
* @param window The window for which to enable the blur effect
* @since 4.6
*/
PLASMA_EXPORT void markAsDashboard(WId window);
}
} // namespace Plasma