[locale] Port TZ widget lookup to new find() method
- The TZ widget uses a different coordinate system (mapping lat and lon to pixel locations, and then calculating Manhattan distance from that), so needs a different distance function. - Simplify code: there's just one "closest TZ" function.
This commit is contained in:
parent
2f871acbfd
commit
0948963d86
@ -190,28 +190,15 @@ TimeZoneWidget::mousePressEvent( QMouseEvent* event )
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Set nearest location
|
|
||||||
int nX = 999999, mX = event->pos().x();
|
|
||||||
int nY = 999999, mY = event->pos().y();
|
|
||||||
|
|
||||||
using namespace CalamaresUtils::Locale;
|
int mX = event->pos().x();
|
||||||
const TimeZoneData* closest = nullptr;
|
int mY = event->pos().y();
|
||||||
for ( auto it = m_zonesData->begin(); it; ++it )
|
auto distance = [&]( const CalamaresUtils::Locale::TimeZoneData* zone ) {
|
||||||
{
|
|
||||||
const auto* zone = *it;
|
|
||||||
if ( zone )
|
|
||||||
{
|
|
||||||
QPoint locPos = TimeZoneImageList::getLocationPosition( zone->longitude(), zone->latitude() );
|
QPoint locPos = TimeZoneImageList::getLocationPosition( zone->longitude(), zone->latitude() );
|
||||||
|
return double( abs( mX - locPos.x() ) + abs( mY - locPos.y() ) );
|
||||||
|
};
|
||||||
|
|
||||||
if ( ( abs( mX - locPos.x() ) + abs( mY - locPos.y() ) < abs( mX - nX ) + abs( mY - nY ) ) )
|
const auto* closest = m_zonesData->find( distance );
|
||||||
{
|
|
||||||
closest = zone;
|
|
||||||
nX = locPos.x();
|
|
||||||
nY = locPos.y();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( closest )
|
if ( closest )
|
||||||
{
|
{
|
||||||
// Set zone image and repaint widget
|
// Set zone image and repaint widget
|
||||||
|
Loading…
Reference in New Issue
Block a user