summaryrefslogtreecommitdiff
path: root/libsowatch/weathernotification.cpp
blob: 6d693b2562db98d1eb140d88ffa8cf01daf2d5ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "weathernotification.h"

using namespace sowatch;

WeatherNotification::WeatherNotification(QObject *parent) :
    Notification(parent)
{
}

qreal WeatherNotification::convertTemperature(qreal temp, Unit from, Unit to)
{
	if (from == to) {
		return temp;
	} else if (from == Celsius && to == Fahrenheit) {
		return temp * (9.0f/5.0f) + 32.0f;
	} else if (from == Fahrenheit && to == Celsius) {
		return (temp - 32.0f) * (5.0f/9.0f);
	} else {
		return 0.0f;
	}
}


int WeatherNotification::convertTemperature(int temp, Unit from, Unit to)
{
	if (from == to) {
		return temp;
	} else {
		return qRound(convertTemperature(static_cast<qreal>(temp), from, to));
	}
}