The newly added class abstracts away icon names from the main code and has the ability to fall back to "safer" icon choices so as to ensure (if possible) icon theme consistency. Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>pull/18/head
parent
5fea80f569
commit
0e7033dd09
@ -0,0 +1,171 @@
|
||||
#include <kiconloader.h>
|
||||
|
||||
#include "weather_icon.h"
|
||||
|
||||
WeatherIcon::WeatherIcon( int condition, bool night )
|
||||
: iconLoader()
|
||||
{
|
||||
TQString name;
|
||||
|
||||
switch( condition )
|
||||
{
|
||||
|
||||
case Sunny:
|
||||
{
|
||||
name = "weather-clear";
|
||||
iconName = ( night ? name.append("-night") : name );
|
||||
return;
|
||||
}
|
||||
|
||||
case Fog:
|
||||
{
|
||||
name = "weather-fog";
|
||||
if( night && iconExists( TQString(name.latin1()).append("-night")) )
|
||||
{
|
||||
name.append("-night");
|
||||
}
|
||||
iconName = name;
|
||||
return;
|
||||
}
|
||||
|
||||
case Mist:
|
||||
{
|
||||
name = "weather-mist";
|
||||
if( night && iconExists( TQString(name.latin1()).append("-night")) )
|
||||
{
|
||||
name.append("-night");
|
||||
}
|
||||
iconName = name;
|
||||
return;
|
||||
}
|
||||
|
||||
case Overcast: { iconName = "weather-overcast"; return; }
|
||||
case Hail: { iconName = "weather-freezing-rain"; return; }
|
||||
case LightRain: { iconName = "weather-showers-scattered"; return; }
|
||||
case Sleet: { iconName = "weather-snow-rain"; return; }
|
||||
}
|
||||
}
|
||||
|
||||
WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
|
||||
: iconLoader()
|
||||
{
|
||||
TQString name;
|
||||
|
||||
switch ( condition )
|
||||
{
|
||||
case Cloudy:
|
||||
{
|
||||
switch ( strength )
|
||||
{
|
||||
case 1: { name = "weather-few-clouds"; break; }
|
||||
|
||||
case 2:
|
||||
{
|
||||
name = "weather-moderate-clouds";
|
||||
if (! iconExists(name) )
|
||||
{
|
||||
name = "weather-few-clouds";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 3: { name = "weather-clouds"; break; }
|
||||
|
||||
case 4:
|
||||
{
|
||||
name = "weather-ample-clouds";
|
||||
if (! iconExists(name) )
|
||||
{
|
||||
name = "weather-clouds";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 5: { iconName = "weather-many-clouds"; return; }
|
||||
default: { iconName = "weather-clouds"; return; }
|
||||
}
|
||||
|
||||
iconName = name.append( night ? "-night" : "" );
|
||||
return;
|
||||
}
|
||||
|
||||
case Showers:
|
||||
{
|
||||
switch ( strength )
|
||||
{
|
||||
case 1: { name = "weather-showers-scattered"; break; }
|
||||
case 2: { name = "weather-showers"; break; }
|
||||
case 3:
|
||||
default: { iconName = "weather-showers"; return; }
|
||||
}
|
||||
|
||||
iconName = name.append( night ? "-night" : "-day" );
|
||||
return;
|
||||
}
|
||||
|
||||
case Snow:
|
||||
{
|
||||
switch( strength )
|
||||
{
|
||||
case 1: { name = "weather-snow-scattered"; break; }
|
||||
case 2:
|
||||
{
|
||||
name = "weather-snow-moderate";
|
||||
if (! iconExists( TQString(name.latin1()).append("-day")) )
|
||||
{
|
||||
name = "weather-snow-scattered";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
name = "weather-snow-ample";
|
||||
if ( iconExists( TQString(name.latin1()).append("-day") ) )
|
||||
break;
|
||||
}
|
||||
case 4: { iconName = "weather-snow-scattered"; return; }
|
||||
case 5:
|
||||
default: { iconName = "weather-snow"; return; }
|
||||
}
|
||||
|
||||
iconName = name.append( night ? "-night" : "-day" );
|
||||
return;
|
||||
}
|
||||
|
||||
case Thunderstorm:
|
||||
switch ( strength )
|
||||
{
|
||||
case 1: { name = "weather-storm"; break; }
|
||||
case 2:
|
||||
{
|
||||
name = "weather-storm-moderate";
|
||||
if (! iconExists( TQString(name.latin1()).append("-day")) )
|
||||
{
|
||||
name = "weather-storm";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
default: { iconName = "weather-storm"; return; }
|
||||
}
|
||||
|
||||
iconName = name.append( night ? "-night" : "-day" );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
WeatherIcon::~WeatherIcon()
|
||||
{}
|
||||
|
||||
|
||||
bool WeatherIcon::iconExists( TQString& icon, bool inTheme )
|
||||
{
|
||||
if ( inTheme )
|
||||
{
|
||||
return iconLoader->theme()->iconPath(icon, TDEIcon::SizeMedium, TDEIcon::MatchExact).isValid();
|
||||
}
|
||||
else
|
||||
{
|
||||
return !(iconLoader->iconPath(icon, TDEIcon::SizeMedium, true).isNull());
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
class TDEIconLoader;
|
||||
|
||||
class WeatherIcon {
|
||||
public:
|
||||
enum SimpleCondition { Sunny, Fog, Mist, Overcast, Hail, LightRain, Sleet };
|
||||
enum RangedCondition { Cloudy, Showers, Snow, Thunderstorm };
|
||||
|
||||
WeatherIcon( int condition /* SimpleCondition */, bool night );
|
||||
WeatherIcon( int condition /* RangedCondition */, bool night, unsigned int strength );
|
||||
~WeatherIcon();
|
||||
|
||||
static TQString unknown() { return "weather-none-available"; };
|
||||
TQString& name() { return iconName; }
|
||||
|
||||
private:
|
||||
bool iconExists( TQString& icon, bool inTheme = true );
|
||||
|
||||
TDEIconLoader* iconLoader;
|
||||
TQString iconName = unknown();
|
||||
};
|
Loading…
Reference in new issue