summaryrefslogtreecommitdiffstats
path: root/kweather/dockwidget.cpp
diff options
context:
space:
mode:
authorMavridis Philippe <mavridisf@gmail.com>2023-06-01 16:30:11 +0300
committerMavridis Philippe <mavridisf@gmail.com>2023-06-14 17:42:21 +0300
commitfe6de6f4bc8a0a7d86c2c3dc6413170214206cff (patch)
treed86bbc14c9c16c52b9d2b5b750de15ece38c7c5a /kweather/dockwidget.cpp
parent6b56a1befc9f510d4467cd5652cbb8fb49563070 (diff)
downloadtdetoys-fe6de6f4bc8a0a7d86c2c3dc6413170214206cff.tar.gz
tdetoys-fe6de6f4bc8a0a7d86c2c3dc6413170214206cff.zip
KWeather: improve icon loading and other fixes
- Fix pixelated icons (issue #19) - Fix "network offline" state - Add helper `bool weatherDataAvailable(TQString stationID)` DCOP function - Fix compatibility with old DCOP function signatures - Prevent double "Network is offline" strings in weather data. This commit introduces some new and renamed DCOP calls. Old function signatures are kept for compatibility, but are mraked as deprecated. Signed-off-by: Mavridis Philippe <mavridisf@gmail.com> (cherry picked from commit bc71670331e16b15fc30214cb85c409b8c91bb9c)
Diffstat (limited to 'kweather/dockwidget.cpp')
-rw-r--r--kweather/dockwidget.cpp47
1 files changed, 28 insertions, 19 deletions
diff --git a/kweather/dockwidget.cpp b/kweather/dockwidget.cpp
index 1d423a5..744ab91 100644
--- a/kweather/dockwidget.cpp
+++ b/kweather/dockwidget.cpp
@@ -29,6 +29,7 @@
#include <kdebug.h>
#include <tdeglobalsettings.h>
#include <tdelocale.h>
+#include <kiconloader.h>
dockwidget::dockwidget(const TQString &location, TQWidget *parent,
const char *name) : TQWidget(parent,name), m_locationCode( location ), m_orientation(Qt::Horizontal )
@@ -39,6 +40,7 @@ dockwidget::dockwidget(const TQString &location, TQWidget *parent,
connect(m_button, TQT_SIGNAL( clicked() ), TQT_SIGNAL( buttonClicked() ));
m_weatherService = new WeatherService_stub( "KWeatherService", "WeatherService" );
+ updateIcon();
}
dockwidget::~dockwidget()
@@ -101,7 +103,7 @@ void dockwidget::showWeather()
m_weatherService->stationName( m_locationCode ) + " (" +
m_weatherService->stationCountry( m_locationCode ) + ")</nobr></center></h3>";
- if ( m_weatherService->currentIconString( m_locationCode ) == "weather-none-available" ) // no data
+ if ( !m_weatherService->weatherDataAvailable(m_locationCode) ) // no data
tip += "<center><nobr>" + i18n("The network is currently offline...") + "</nobr></center>";
tip += TQString("<br><table>"
@@ -143,8 +145,7 @@ void dockwidget::showWeather()
tip += "</qt>";
- // On null or empty location code, or if the station needs maintenance, this will return the dunno icon.
- TQPixmap icon = m_weatherService->icon( m_locationCode );
+ updateIcon();
TQToolTip::remove(this);
TQToolTip::add(this, tip);
@@ -158,7 +159,6 @@ void dockwidget::showWeather()
m_lblWind->setText(wind);
m_lblPres->setText(pressure);
- m_button->setPixmap( icon );
}
void dockwidget::initDock()
@@ -204,13 +204,13 @@ void dockwidget::resizeView( const TQSize &size )
kdDebug(12004) << "Changing to size " << size << endl;
resize(size);
- if ( m_orientation ==Qt::Horizontal ) // Kicker in horizontal mode
+ if ( m_orientation == TQt::Horizontal ) // Kicker in horizontal mode
{
int h = size.height();
if ( m_mode == ShowAll )
{
- if ( h <= 128 ) // left to right layout
+ if ( h <= TDEIcon::SizeEnormous ) // left to right layout
{
static_cast<TQBoxLayout*>(layout())->setDirection(TQBoxLayout::LeftToRight);
m_lblTemp->setAlignment(TQt::AlignAuto | TQt::AlignVCenter);
@@ -221,7 +221,7 @@ void dockwidget::resizeView( const TQSize &size )
{
static_cast<TQBoxLayout*>(layout())->setDirection(TQBoxLayout::TopToBottom);
TQFontMetrics fm(m_font);
- h = 128 - (3 * fm.height()); // 3 lines of text below the button
+ h = TDEIcon::SizeEnormous - (3 * fm.height()); // 3 lines of text below the button
m_lblTemp->setAlignment(TQt::AlignCenter);
m_lblWind->setAlignment(TQt::AlignCenter);
m_lblPres->setAlignment(TQt::AlignCenter);
@@ -239,14 +239,14 @@ void dockwidget::resizeView( const TQSize &size )
{
static_cast<TQBoxLayout*>(layout())->setDirection(TQBoxLayout::TopToBottom);
TQFontMetrics fm(m_font);
- h = TQMIN(128, h) - fm.height();
+ h = TQMIN(TDEIcon::SizeEnormous, h) - fm.height();
m_lblTemp->setAlignment(TQt::AlignCenter);
}
m_button->setFixedSize(h, h);
}
else
{
- h = TQMIN(h, 128);
+ h = TQMIN(h, TDEIcon::SizeEnormous);
m_button->setFixedSize(h, h);
}
}
@@ -257,7 +257,7 @@ void dockwidget::resizeView( const TQSize &size )
if ( m_mode == ShowAll )
{
- if ( w <= 128 ) // top to bottom
+ if ( w <= TDEIcon::SizeEnormous ) // top to bottom
{
static_cast<TQBoxLayout*>(layout())->setDirection(TQBoxLayout::TopToBottom);
m_lblTemp->setAlignment(TQt::AlignCenter);
@@ -279,7 +279,7 @@ void dockwidget::resizeView( const TQSize &size )
}
else if ( m_mode == ShowTempOnly )
{
- if ( w <= 128 ) // top to bottom
+ if ( w <= TDEIcon::SizeEnormous ) // top to bottom
{
static_cast<TQBoxLayout*>(layout())->setDirection(TQBoxLayout::TopToBottom);
m_lblTemp->setAlignment(TQt::AlignCenter);
@@ -297,7 +297,7 @@ void dockwidget::resizeView( const TQSize &size )
}
else
{
- w = TQMIN(w, 128);
+ w = TQMIN(w, TDEIcon::SizeEnormous);
m_button->setFixedSize(w, w);
}
}
@@ -310,7 +310,7 @@ int dockwidget::widthForHeight(int h)
if ( m_mode == ShowAll )
{
- if ( h <= 128 ) // left to right layout
+ if ( h <= TDEIcon::SizeEnormous ) // left to right layout
{
int pixelSize = h/3 - 3;
pixelSize = TQMIN(pixelSize, fi.pixelSize()); // don't make it too large
@@ -330,7 +330,7 @@ int dockwidget::widthForHeight(int h)
}
TQFontMetrics fm(m_font);
// size of icon
- h = 128 - (3 * fm.height()); // 3 lines of text below the button
+ h = TDEIcon::SizeEnormous - (3 * fm.height()); // 3 lines of text below the button
w = TQMAX(fm.width(m_lblWind->text()), fm.width(m_lblPres->text())) + 1;
w = TQMAX(h, w); // at least width of square icon
}
@@ -357,17 +357,18 @@ int dockwidget::widthForHeight(int h)
}
TQFontMetrics fm(m_font);
// size of icon
- h = TQMIN(128, h) - fm.height();
+ h = TQMIN(TDEIcon::SizeEnormous, h) - fm.height();
w = fm.width(m_lblTemp->text()) + 1;
w = TQMAX(h, w); // at least width of square icon
}
}
else
{
- w = TQMIN(128, h); // don't make it too large
+ w = TQMIN(TDEIcon::SizeEnormous, h); // don't make it too large
}
updateFont();
+ updateIcon();
return w + 4;
}
@@ -380,7 +381,7 @@ int dockwidget::heightForWidth( int w )
TQFontMetrics fmg(TDEGlobalSettings::generalFont());
int maxWidth = fmg.width("888 km/h NNWW"); // a good approximation
- if ( w <= 128 ) // top to bottom
+ if ( w <= TDEIcon::SizeEnormous ) // top to bottom
{
if ( maxWidth <= w ) // enough space to use global font
{
@@ -415,7 +416,7 @@ int dockwidget::heightForWidth( int w )
TQFontMetrics fmg(TDEGlobalSettings::generalFont());
int maxWidth = fmg.width("888.88 CC"); // a good approximation
- if ( w <= 128 ) // top to bottom
+ if ( w <= TDEIcon::SizeEnormous ) // top to bottom
{
if ( maxWidth <= w ) // enough space to use global font
{
@@ -446,10 +447,11 @@ int dockwidget::heightForWidth( int w )
}
else
{
- h = TQMIN(128, w); // don't make it too large
+ h = TQMIN(TDEIcon::SizeEnormous, w); // don't make it too large
}
updateFont();
+ updateIcon();
return h;
}
@@ -462,4 +464,11 @@ void dockwidget::updateFont()
m_lblPres->setFont(m_font);
}
+void dockwidget::updateIcon()
+{
+ // On null or empty location code, or if the station needs maintenance, this will return the dunno icon.
+ TQPixmap icon = m_weatherService->icon( m_locationCode, m_button->height() );
+ m_button->setPixmap( icon );
+}
+
#include "dockwidget.moc"