[locale] Move the find-a-zone-image-for position to the image list
This commit is contained in:
parent
6173f9337a
commit
1d5c4f13aa
@ -29,6 +29,8 @@ static const char* zoneNames[]
|
|||||||
static_assert( TimeZoneImageList::zoneCount == ( sizeof( zoneNames ) / sizeof( zoneNames[ 0 ] ) ),
|
static_assert( TimeZoneImageList::zoneCount == ( sizeof( zoneNames ) / sizeof( zoneNames[ 0 ] ) ),
|
||||||
"Incorrect number of zones" );
|
"Incorrect number of zones" );
|
||||||
|
|
||||||
|
#define ZONE_NAME QStringLiteral( "zone" )
|
||||||
|
|
||||||
TimeZoneImageList::TimeZoneImageList() {}
|
TimeZoneImageList::TimeZoneImageList() {}
|
||||||
|
|
||||||
TimeZoneImageList
|
TimeZoneImageList
|
||||||
@ -38,7 +40,7 @@ TimeZoneImageList::fromQRC()
|
|||||||
for ( const auto* zoneName : zoneNames )
|
for ( const auto* zoneName : zoneNames )
|
||||||
{
|
{
|
||||||
l.append( QImage( QStringLiteral( ":/images/timezone_" ) + zoneName + ".png" ) );
|
l.append( QImage( QStringLiteral( ":/images/timezone_" ) + zoneName + ".png" ) );
|
||||||
l.last().setText( QStringLiteral( "zone" ), zoneName );
|
l.last().setText( ZONE_NAME, zoneName );
|
||||||
}
|
}
|
||||||
|
|
||||||
return l;
|
return l;
|
||||||
@ -58,7 +60,7 @@ TimeZoneImageList::fromDirectory( const QString& dirName )
|
|||||||
for ( const auto* zoneName : zoneNames )
|
for ( const auto* zoneName : zoneNames )
|
||||||
{
|
{
|
||||||
l.append( QImage( dir.filePath( QStringLiteral( "timezone_" ) + zoneName + ".png" ) ) );
|
l.append( QImage( dir.filePath( QStringLiteral( "timezone_" ) + zoneName + ".png" ) ) );
|
||||||
l.last().setText( QStringLiteral( "zone" ), zoneName );
|
l.last().setText( ZONE_NAME, zoneName );
|
||||||
}
|
}
|
||||||
|
|
||||||
return l;
|
return l;
|
||||||
@ -137,3 +139,69 @@ TimeZoneImageList::getLocationPosition( double longitude, double latitude )
|
|||||||
|
|
||||||
return QPoint( int( x ), int( y ) );
|
return QPoint( int( x ), int( y ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pixel value indicating that a spot is outside of a zone
|
||||||
|
static constexpr const int RGB_TRANSPARENT = 0;
|
||||||
|
|
||||||
|
int
|
||||||
|
TimeZoneImageList::index( QPoint pos, int& overlap ) const
|
||||||
|
{
|
||||||
|
overlap = 0;
|
||||||
|
|
||||||
|
#ifdef DEBUG_TIMEZONES
|
||||||
|
bool found = false;
|
||||||
|
for ( int i = 0; i < size(); ++i )
|
||||||
|
{
|
||||||
|
const QImage& zone = at( i );
|
||||||
|
|
||||||
|
// If not transparent set as current
|
||||||
|
if ( zone.pixel( pos ) != RGB_TRANSPARENT )
|
||||||
|
{
|
||||||
|
// Log *all* the zones that contain this point,
|
||||||
|
// but only pick the first.
|
||||||
|
if ( !found )
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
cDebug() << Logger::SubEntry << "First zone found" << i << zone.text( ZONE_NAME );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cDebug() << Logger::SubEntry << "Also in zone" << i << zone.text( ZONE_NAME );
|
||||||
|
overlap++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( !found )
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return index( pos );
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
TimeZoneImageList::index( QPoint pos ) const
|
||||||
|
{
|
||||||
|
for ( int i = 0; i < size(); ++i )
|
||||||
|
{
|
||||||
|
const QImage& zone = at( i );
|
||||||
|
|
||||||
|
// If not transparent set as current
|
||||||
|
if ( zone.pixel( pos ) != RGB_TRANSPARENT )
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage
|
||||||
|
TimeZoneImageList::find( QPoint p ) const
|
||||||
|
{
|
||||||
|
int i = index( p );
|
||||||
|
if ( i < 0 || size() <= i )
|
||||||
|
{
|
||||||
|
return QImage();
|
||||||
|
}
|
||||||
|
return at( i );
|
||||||
|
}
|
||||||
|
@ -56,6 +56,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
static QPoint getLocationPosition( double longitude, double latitude );
|
static QPoint getLocationPosition( double longitude, double latitude );
|
||||||
|
|
||||||
|
int index( QPoint p ) const;
|
||||||
|
int index( QPoint p, int& overlap ) const;
|
||||||
|
QImage find( QPoint p ) const;
|
||||||
|
|
||||||
/// @brief The **expected** number of zones in the list.
|
/// @brief The **expected** number of zones in the list.
|
||||||
static constexpr const int zoneCount = 38;
|
static constexpr const int zoneCount = 38;
|
||||||
/// @brief The expected size of each zone image.
|
/// @brief The expected size of each zone image.
|
||||||
|
@ -28,9 +28,6 @@
|
|||||||
|
|
||||||
#include "timezonewidget.h"
|
#include "timezonewidget.h"
|
||||||
|
|
||||||
// Pixel value indicating that a spot is outside of a zone
|
|
||||||
#define RGB_TRANSPARENT 0
|
|
||||||
|
|
||||||
#ifdef DEBUG_TIMEZONES
|
#ifdef DEBUG_TIMEZONES
|
||||||
// Adds a label to the timezone with this name
|
// Adds a label to the timezone with this name
|
||||||
#define ZONE_NAME QStringLiteral( "zone" )
|
#define ZONE_NAME QStringLiteral( "zone" )
|
||||||
@ -88,37 +85,9 @@ TimeZoneWidget::setCurrentLocation( const CalamaresUtils::Locale::TZZone* locati
|
|||||||
cDebug() << "Setting location" << location->region() << location->zone() << '(' << location->country() << '@'
|
cDebug() << "Setting location" << location->region() << location->zone() << '(' << location->country() << '@'
|
||||||
<< location->latitude() << 'N' << location->longitude() << 'E' << ')';
|
<< location->latitude() << 'N' << location->longitude() << 'E' << ')';
|
||||||
cDebug() << Logger::SubEntry << "pixel x" << pos.x() << "pixel y" << pos.y();
|
cDebug() << Logger::SubEntry << "pixel x" << pos.x() << "pixel y" << pos.y();
|
||||||
|
|
||||||
bool found = false;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
currentZoneImage = timeZoneImages.find( pos );
|
||||||
for ( int i = 0; i < timeZoneImages.size(); ++i )
|
|
||||||
{
|
|
||||||
QImage zone = timeZoneImages[ i ];
|
|
||||||
|
|
||||||
// If not transparent set as current
|
|
||||||
if ( zone.pixel( pos ) != RGB_TRANSPARENT )
|
|
||||||
{
|
|
||||||
#ifdef DEBUG_TIMEZONES
|
|
||||||
// Log *all* the zones that contain this point,
|
|
||||||
// but only pick the first.
|
|
||||||
if ( !found )
|
|
||||||
{
|
|
||||||
currentZoneImage = zone;
|
|
||||||
found = true;
|
|
||||||
cDebug() << Logger::SubEntry << "First zone found" << i << zone.text( ZONE_NAME );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cDebug() << Logger::SubEntry << "Also in zone" << i << zone.text( ZONE_NAME );
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
currentZoneImage = zone;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Repaint widget
|
// Repaint widget
|
||||||
repaint();
|
repaint();
|
||||||
|
Loading…
Reference in New Issue
Block a user