Code-formatting, add copyright notice

This commit is contained in:
Adriaan de Groot 2017-10-12 07:08:21 -07:00
parent c10d7470bb
commit 00fa7bff1c

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === This file is part of Calamares - <http://github.com/calamares> ===
* *
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org> * Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org>
* *
* Originally from the Manjaro Installation Framework * Originally from the Manjaro Installation Framework
* by Roland Singer <roland@manjaro.org> * by Roland Singer <roland@manjaro.org>
@ -26,59 +27,64 @@
constexpr double MATH_PI = 3.14159265; constexpr double MATH_PI = 3.14159265;
TimeZoneWidget::TimeZoneWidget(QWidget* parent) : TimeZoneWidget::TimeZoneWidget( QWidget* parent ) :
QWidget(parent) QWidget( parent )
{ {
setMouseTracking(false); setMouseTracking( false );
setCursor(Qt::PointingHandCursor); setCursor( Qt::PointingHandCursor );
// Font // Font
font.setPointSize(12); font.setPointSize( 12 );
font.setBold(false); font.setBold( false );
// Images // Images
background = QImage(":/images/bg.png").scaled(X_SIZE, Y_SIZE, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); background = QImage( ":/images/bg.png" ).scaled( X_SIZE, Y_SIZE, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
pin = QImage(":/images/pin.png"); pin = QImage( ":/images/pin.png" );
// Set size // Set size
setMinimumSize(background.size()); setMinimumSize( background.size() );
setMaximumSize(background.size()); setMaximumSize( background.size() );
// Zone images // Zone images
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 ) );
} }
void TimeZoneWidget::setCurrentLocation(QString region, QString zone) { void TimeZoneWidget::setCurrentLocation( QString region, QString zone )
{
QHash<QString, QList<LocaleGlobal::Location> > hash = LocaleGlobal::getLocations(); QHash<QString, QList<LocaleGlobal::Location> > hash = LocaleGlobal::getLocations();
if (!hash.contains(region)) if ( !hash.contains( region ) )
return; return;
QList<LocaleGlobal::Location> locations = hash.value(region); QList<LocaleGlobal::Location> locations = hash.value( region );
for (int i = 0; i < locations.size(); ++i) { for ( int i = 0; i < locations.size(); ++i )
if (locations.at(i).zone == zone) { {
setCurrentLocation(locations.at(i)); if ( locations.at( i ).zone == zone )
{
setCurrentLocation( locations.at( i ) );
break; break;
} }
} }
} }
void TimeZoneWidget::setCurrentLocation( LocaleGlobal::Location location )
void TimeZoneWidget::setCurrentLocation(LocaleGlobal::Location location) { {
currentLocation = location; currentLocation = location;
// Set zone // Set zone
QPoint pos = getLocationPosition(currentLocation.longitude, currentLocation.latitude); QPoint pos = getLocationPosition( currentLocation.longitude, currentLocation.latitude );
for (int i = 0; i < timeZoneImages.size(); ++i) { for ( int i = 0; i < timeZoneImages.size(); ++i )
{
QImage zone = timeZoneImages[i]; QImage zone = timeZoneImages[i];
// If not transparent set as current // If not transparent set as current
if (zone.pixel(pos) != RGB_TRANSPARENT) { if ( zone.pixel( pos ) != RGB_TRANSPARENT )
{
currentZoneImage = zone; currentZoneImage = zone;
break; break;
} }
@ -95,85 +101,87 @@ void TimeZoneWidget::setCurrentLocation(LocaleGlobal::Location location) {
//### //###
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();
double x = (width / 2.0 + (width / 2.0) * longitude / 180.0) + MAP_X_OFFSET * width; double x = ( width / 2.0 + ( width / 2.0 ) * longitude / 180.0 ) + MAP_X_OFFSET * width;
double y = (height / 2.0 - (height / 2.0) * latitude / 90.0) + MAP_Y_OFFSET * height; double y = ( height / 2.0 - ( height / 2.0 ) * latitude / 90.0 ) + MAP_Y_OFFSET * height;
//Far north, the MAP_Y_OFFSET no longer holds, cancel the Y offset; it's noticeable //Far north, the MAP_Y_OFFSET no longer holds, cancel the Y offset; it's noticeable
// from 62 degrees north, so scale those 28 degrees as if the world is flat south // from 62 degrees north, so scale those 28 degrees as if the world is flat south
// of there, and we have a funny "rounded" top of the world. In practice the locations // of there, and we have a funny "rounded" top of the world. In practice the locations
// 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 > 62.0) if ( latitude > 62.0 )
y -= sin(MATH_PI * (latitude - 62.0) / 56.0) * MAP_Y_OFFSET * height; y -= sin( MATH_PI * ( latitude - 62.0 ) / 56.0 ) * MAP_Y_OFFSET * height;
// 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();
QFontMetrics fontMetrics(font); QFontMetrics fontMetrics( font );
QPainter painter(this); QPainter painter( this );
painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint( QPainter::Antialiasing );
painter.setFont(font); painter.setFont( font );
// Draw background // Draw background
painter.drawImage(0, 0, background); painter.drawImage( 0, 0, background );
// Draw zone image // Draw zone image
painter.drawImage(0, 0, currentZoneImage); painter.drawImage( 0, 0, currentZoneImage );
// Draw pin // Draw pin
QPoint point = getLocationPosition(currentLocation.longitude, currentLocation.latitude); QPoint point = getLocationPosition( currentLocation.longitude, currentLocation.latitude );
painter.drawImage(point.x() - pin.width()/2, point.y() - pin.height()/2, pin); painter.drawImage( point.x() - pin.width()/2, point.y() - pin.height()/2, pin );
// Draw text and box // Draw text and box
const int textWidth = fontMetrics.width(LocaleGlobal::Location::pretty(currentLocation.zone)); const int textWidth = fontMetrics.width( LocaleGlobal::Location::pretty( currentLocation.zone ) );
const int textHeight = fontMetrics.height(); const int textHeight = fontMetrics.height();
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 ) );
painter.drawRoundedRect(rect, 3, 3); painter.drawRoundedRect( rect, 3, 3 );
painter.setPen(Qt::white); painter.setPen( Qt::white );
painter.drawText(rect.x() + 5, rect.bottom() - 4, LocaleGlobal::Location::pretty(currentLocation.zone)); painter.drawText( rect.x() + 5, rect.bottom() - 4, LocaleGlobal::Location::pretty( currentLocation.zone ) );
painter.end(); painter.end();
} }
void TimeZoneWidget::mousePressEvent(QMouseEvent* event) { void TimeZoneWidget::mousePressEvent( QMouseEvent* event )
if (event->button() != Qt::LeftButton) {
if ( event->button() != Qt::LeftButton )
return; return;
// Set nearest location // Set nearest location
@ -182,14 +190,17 @@ void TimeZoneWidget::mousePressEvent(QMouseEvent* event) {
QHash<QString, QList<LocaleGlobal::Location> > hash = LocaleGlobal::getLocations(); QHash<QString, QList<LocaleGlobal::Location> > hash = LocaleGlobal::getLocations();
QHash<QString, QList<LocaleGlobal::Location> >::iterator iter = hash.begin(); QHash<QString, QList<LocaleGlobal::Location> >::iterator iter = hash.begin();
while (iter != hash.end()) { while ( iter != hash.end() )
{
QList<LocaleGlobal::Location> locations = iter.value(); QList<LocaleGlobal::Location> locations = iter.value();
for (int i = 0; i < locations.size(); ++i) { for ( int i = 0; i < locations.size(); ++i )
{
LocaleGlobal::Location loc = locations[i]; LocaleGlobal::Location loc = locations[i];
QPoint locPos = getLocationPosition(loc.longitude, loc.latitude); QPoint locPos = getLocationPosition( loc.longitude, loc.latitude );
if ((abs(mX - locPos.x()) + abs(mY - locPos.y()) < abs(mX - nX) + abs(mY - nY))) { if ( ( abs( mX - locPos.x() ) + abs( mY - locPos.y() ) < abs( mX - nX ) + abs( mY - nY ) ) )
{
currentLocation = loc; currentLocation = loc;
nX = locPos.x(); nX = locPos.x();
nY = locPos.y(); nY = locPos.y();
@ -200,8 +211,8 @@ void TimeZoneWidget::mousePressEvent(QMouseEvent* event) {
} }
// Set zone image and repaint widget // Set zone image and repaint widget
setCurrentLocation(currentLocation); setCurrentLocation( currentLocation );
// Emit signal // Emit signal
emit locationChanged(currentLocation); emit locationChanged( currentLocation );
} }