|
|
@ -23,8 +23,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
|
|
|
|
#include "locale/TimeZone.h"
|
|
|
|
#include "locale/TimeZone.h"
|
|
|
|
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "timezonewidget.h"
|
|
|
|
#include "timezonewidget.h"
|
|
|
|
|
|
|
|
|
|
|
@ -38,8 +38,8 @@ constexpr static double MATH_PI = 3.14159265;
|
|
|
|
constexpr static QLatin1String ZONE_NAME( "zone" );
|
|
|
|
constexpr static QLatin1String ZONE_NAME( "zone" );
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
TimeZoneWidget::TimeZoneWidget( QWidget* parent ) :
|
|
|
|
TimeZoneWidget::TimeZoneWidget( QWidget* parent )
|
|
|
|
QWidget( parent )
|
|
|
|
: QWidget( parent )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
setMouseTracking( false );
|
|
|
|
setMouseTracking( false );
|
|
|
|
setCursor( Qt::PointingHandCursor );
|
|
|
|
setCursor( Qt::PointingHandCursor );
|
|
|
@ -60,7 +60,8 @@ TimeZoneWidget::TimeZoneWidget( QWidget* parent ) :
|
|
|
|
QStringList zones = QString( ZONES ).split( " ", QString::SkipEmptyParts );
|
|
|
|
QStringList zones = QString( ZONES ).split( " ", QString::SkipEmptyParts );
|
|
|
|
for ( int i = 0; i < zones.size(); ++i )
|
|
|
|
for ( int i = 0; i < zones.size(); ++i )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
timeZoneImages.append( QImage( ":/images/timezone_" + zones.at( i ) + ".png" ).scaled( X_SIZE, Y_SIZE, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
|
|
|
|
timeZoneImages.append( QImage( ":/images/timezone_" + zones.at( i ) + ".png" )
|
|
|
|
|
|
|
|
.scaled( X_SIZE, Y_SIZE, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
|
|
|
|
#ifdef DEBUG_TIMEZONES
|
|
|
|
#ifdef DEBUG_TIMEZONES
|
|
|
|
timeZoneImages.last().setText( ZONE_NAME, zones.at( i ) );
|
|
|
|
timeZoneImages.last().setText( ZONE_NAME, zones.at( i ) );
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -68,7 +69,8 @@ TimeZoneWidget::TimeZoneWidget( QWidget* parent ) :
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TimeZoneWidget::setCurrentLocation( QString regionName, QString zoneName )
|
|
|
|
void
|
|
|
|
|
|
|
|
TimeZoneWidget::setCurrentLocation( QString regionName, QString zoneName )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using namespace CalamaresUtils::Locale;
|
|
|
|
using namespace CalamaresUtils::Locale;
|
|
|
|
const auto& regions = TZRegion::fromZoneTab();
|
|
|
|
const auto& regions = TZRegion::fromZoneTab();
|
|
|
@ -86,7 +88,8 @@ void TimeZoneWidget::setCurrentLocation( QString regionName, QString zoneName )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TimeZoneWidget::setCurrentLocation( const CalamaresUtils::Locale::TZZone *location )
|
|
|
|
void
|
|
|
|
|
|
|
|
TimeZoneWidget::setCurrentLocation( const CalamaresUtils::Locale::TZZone* location )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
currentLocation = *location;
|
|
|
|
currentLocation = *location;
|
|
|
|
|
|
|
|
|
|
|
@ -119,7 +122,9 @@ void TimeZoneWidget::setCurrentLocation( const CalamaresUtils::Locale::TZZone *l
|
|
|
|
cDebug() << Logger::SubEntry << "First zone found" << i << zone.text( ZONE_NAME );
|
|
|
|
cDebug() << Logger::SubEntry << "First zone found" << i << zone.text( ZONE_NAME );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
cDebug() << Logger::SubEntry << "Also in zone" << i << zone.text( ZONE_NAME );
|
|
|
|
cDebug() << Logger::SubEntry << "Also in zone" << i << zone.text( ZONE_NAME );
|
|
|
|
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
currentZoneImage = zone;
|
|
|
|
currentZoneImage = zone;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -132,13 +137,13 @@ void TimeZoneWidget::setCurrentLocation( const CalamaresUtils::Locale::TZZone *l
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//###
|
|
|
|
//###
|
|
|
|
//### Private
|
|
|
|
//### Private
|
|
|
|
//###
|
|
|
|
//###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPoint TimeZoneWidget::getLocationPosition( double longitude, double latitude )
|
|
|
|
QPoint
|
|
|
|
|
|
|
|
TimeZoneWidget::getLocationPosition( double longitude, double latitude )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const int width = this->width();
|
|
|
|
const int width = this->width();
|
|
|
|
const int height = this->height();
|
|
|
|
const int height = this->height();
|
|
|
@ -152,39 +157,64 @@ QPoint TimeZoneWidget::getLocationPosition( double longitude, double latitude )
|
|
|
|
// of the different cities / regions looks ok -- at least Thule ends up in the right
|
|
|
|
// of the different cities / regions looks ok -- at least Thule ends up in the right
|
|
|
|
// country, and Inuvik isn't in the ocean.
|
|
|
|
// country, and Inuvik isn't in the ocean.
|
|
|
|
if ( latitude > 70.0 )
|
|
|
|
if ( latitude > 70.0 )
|
|
|
|
|
|
|
|
{
|
|
|
|
y -= sin( MATH_PI * ( latitude - 70.0 ) / 56.0 ) * MAP_Y_OFFSET * height * 0.8;
|
|
|
|
y -= sin( MATH_PI * ( latitude - 70.0 ) / 56.0 ) * MAP_Y_OFFSET * height * 0.8;
|
|
|
|
|
|
|
|
}
|
|
|
|
if ( latitude > 74.0 )
|
|
|
|
if ( latitude > 74.0 )
|
|
|
|
|
|
|
|
{
|
|
|
|
y += 4;
|
|
|
|
y += 4;
|
|
|
|
|
|
|
|
}
|
|
|
|
if ( latitude > 69.0 )
|
|
|
|
if ( latitude > 69.0 )
|
|
|
|
|
|
|
|
{
|
|
|
|
y -= 2;
|
|
|
|
y -= 2;
|
|
|
|
|
|
|
|
}
|
|
|
|
if ( latitude > 59.0 )
|
|
|
|
if ( latitude > 59.0 )
|
|
|
|
|
|
|
|
{
|
|
|
|
y -= 4 * int( ( latitude - 54.0 ) / 5.0 );
|
|
|
|
y -= 4 * int( ( latitude - 54.0 ) / 5.0 );
|
|
|
|
|
|
|
|
}
|
|
|
|
if ( latitude > 54.0 )
|
|
|
|
if ( latitude > 54.0 )
|
|
|
|
|
|
|
|
{
|
|
|
|
y -= 2;
|
|
|
|
y -= 2;
|
|
|
|
|
|
|
|
}
|
|
|
|
if ( latitude > 49.0 )
|
|
|
|
if ( latitude > 49.0 )
|
|
|
|
|
|
|
|
{
|
|
|
|
y -= int( ( latitude - 44.0 ) / 5.0 );
|
|
|
|
y -= int( ( latitude - 44.0 ) / 5.0 );
|
|
|
|
|
|
|
|
}
|
|
|
|
// Far south, some stretching occurs as well, but it is less pronounced.
|
|
|
|
// Far south, some stretching occurs as well, but it is less pronounced.
|
|
|
|
// Move down by 1 pixel per 5 degrees past 10 south
|
|
|
|
// Move down by 1 pixel per 5 degrees past 10 south
|
|
|
|
if ( latitude < 0 )
|
|
|
|
if ( latitude < 0 )
|
|
|
|
|
|
|
|
{
|
|
|
|
y += int( ( -latitude ) / 5.0 );
|
|
|
|
y += int( ( -latitude ) / 5.0 );
|
|
|
|
|
|
|
|
}
|
|
|
|
// Antarctica isn't shown on the map, but you could try clicking there
|
|
|
|
// Antarctica isn't shown on the map, but you could try clicking there
|
|
|
|
if ( latitude < -60 )
|
|
|
|
if ( latitude < -60 )
|
|
|
|
|
|
|
|
{
|
|
|
|
y = height - 1;
|
|
|
|
y = height - 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( x < 0 )
|
|
|
|
if ( x < 0 )
|
|
|
|
|
|
|
|
{
|
|
|
|
x = width + x;
|
|
|
|
x = width + x;
|
|
|
|
|
|
|
|
}
|
|
|
|
if ( x >= width )
|
|
|
|
if ( x >= width )
|
|
|
|
|
|
|
|
{
|
|
|
|
x -= width;
|
|
|
|
x -= width;
|
|
|
|
|
|
|
|
}
|
|
|
|
if ( y < 0 )
|
|
|
|
if ( y < 0 )
|
|
|
|
|
|
|
|
{
|
|
|
|
y = height + y;
|
|
|
|
y = height + y;
|
|
|
|
|
|
|
|
}
|
|
|
|
if ( y >= height )
|
|
|
|
if ( y >= height )
|
|
|
|
|
|
|
|
{
|
|
|
|
y -= height;
|
|
|
|
y -= height;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return QPoint( int( x ), int( y ) );
|
|
|
|
return QPoint( int( x ), int( y ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TimeZoneWidget::paintEvent( QPaintEvent* )
|
|
|
|
void
|
|
|
|
|
|
|
|
TimeZoneWidget::paintEvent( QPaintEvent* )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const int width = this->width();
|
|
|
|
const int width = this->width();
|
|
|
|
const int height = this->height();
|
|
|
|
const int height = this->height();
|
|
|
@ -213,8 +243,10 @@ void TimeZoneWidget::paintEvent( QPaintEvent* )
|
|
|
|
int lly = latLine0.y();
|
|
|
|
int lly = latLine0.y();
|
|
|
|
|
|
|
|
|
|
|
|
for ( int c = 0; c < width; ++c )
|
|
|
|
for ( int c = 0; c < width; ++c )
|
|
|
|
|
|
|
|
{
|
|
|
|
painter.drawPoint( c, lly );
|
|
|
|
painter.drawPoint( c, lly );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// Just a dot in the selected location, no label
|
|
|
|
// Just a dot in the selected location, no label
|
|
|
|
painter.setPen( Qt::red );
|
|
|
|
painter.setPen( Qt::red );
|
|
|
|
painter.drawPoint( point );
|
|
|
|
painter.drawPoint( point );
|
|
|
@ -231,13 +263,21 @@ void TimeZoneWidget::paintEvent( QPaintEvent* )
|
|
|
|
QRect rect = QRect( point.x() - textWidth / 2 - 5, point.y() - textHeight - 8, textWidth + 10, textHeight - 2 );
|
|
|
|
QRect rect = QRect( point.x() - textWidth / 2 - 5, point.y() - textHeight - 8, textWidth + 10, textHeight - 2 );
|
|
|
|
|
|
|
|
|
|
|
|
if ( rect.x() <= 5 )
|
|
|
|
if ( rect.x() <= 5 )
|
|
|
|
|
|
|
|
{
|
|
|
|
rect.moveLeft( 5 );
|
|
|
|
rect.moveLeft( 5 );
|
|
|
|
|
|
|
|
}
|
|
|
|
if ( rect.right() >= width - 5 )
|
|
|
|
if ( rect.right() >= width - 5 )
|
|
|
|
|
|
|
|
{
|
|
|
|
rect.moveRight( width - 5 );
|
|
|
|
rect.moveRight( width - 5 );
|
|
|
|
|
|
|
|
}
|
|
|
|
if ( rect.y() <= 5 )
|
|
|
|
if ( rect.y() <= 5 )
|
|
|
|
|
|
|
|
{
|
|
|
|
rect.moveTop( 5 );
|
|
|
|
rect.moveTop( 5 );
|
|
|
|
|
|
|
|
}
|
|
|
|
if ( rect.y() >= height - 5 )
|
|
|
|
if ( rect.y() >= height - 5 )
|
|
|
|
|
|
|
|
{
|
|
|
|
rect.moveBottom( height - 5 );
|
|
|
|
rect.moveBottom( height - 5 );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
painter.setPen( QPen() ); // no pen
|
|
|
|
painter.setPen( QPen() ); // no pen
|
|
|
|
painter.setBrush( QColor( 40, 40, 40 ) );
|
|
|
|
painter.setBrush( QColor( 40, 40, 40 ) );
|
|
|
@ -250,11 +290,13 @@ void TimeZoneWidget::paintEvent( QPaintEvent* )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void TimeZoneWidget::mousePressEvent( QMouseEvent* event )
|
|
|
|
TimeZoneWidget::mousePressEvent( QMouseEvent* event )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ( event->button() != Qt::LeftButton )
|
|
|
|
if ( event->button() != Qt::LeftButton )
|
|
|
|
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set nearest location
|
|
|
|
// Set nearest location
|
|
|
|
int nX = 999999, mX = event->pos().x();
|
|
|
|
int nX = 999999, mX = event->pos().x();
|
|
|
|