diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index 170ddc5ff..b5de92b64 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -1,6 +1,6 @@ /* === This file is part of Calamares - === * - * Copyright 2014, Teo Mrnjavac + * Copyright 2014-2015, Teo Mrnjavac * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -84,36 +84,38 @@ LocalePage::LocalePage( QWidget* parent ) setLayout( mainLayout ); connect( m_regionCombo, - static_cast< void ( QComboBox::* )( const QString& ) >( &QComboBox::currentIndexChanged ), - [this]( const QString& current ) + static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ), + [this]( int currentIndex ) { + Q_UNUSED( currentIndex ); QHash< QString, QList< LocaleGlobal::Location > > regions = LocaleGlobal::getLocations(); - if ( !regions.contains( current ) ) + if ( !regions.contains( m_regionCombo->currentData().toString() ) ) return; m_zoneCombo->blockSignals( true ); m_zoneCombo->clear(); - QList< LocaleGlobal::Location > zones = regions.value( current ); + QList< LocaleGlobal::Location > zones = regions.value( m_regionCombo->currentData().toString() ); foreach ( const LocaleGlobal::Location& zone, zones ) { - m_zoneCombo->addItem( zone.zone ); + m_zoneCombo->addItem( LocaleGlobal::Location::pretty( zone.zone ), zone.zone ); } m_zoneCombo->model()->sort( 0 ); m_zoneCombo->blockSignals( false ); - m_zoneCombo->currentIndexChanged( m_zoneCombo->currentText() ); + m_zoneCombo->currentIndexChanged( m_zoneCombo->currentIndex() ); } ); connect( m_zoneCombo, - static_cast< void ( QComboBox::* )( const QString& ) >( &QComboBox::currentIndexChanged ), - [this]( const QString& current ) + static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ), + [this]( int currentIndex ) { if ( !m_blockTzWidgetSet ) - m_tzWidget->setCurrentLocation( m_regionCombo->currentText(), current ); + m_tzWidget->setCurrentLocation( m_regionCombo->currentData().toString(), + m_zoneCombo->currentData().toString() ); } ); connect( m_tzWidget, &TimeZoneWidget::locationChanged, @@ -122,14 +124,14 @@ LocalePage::LocalePage( QWidget* parent ) m_blockTzWidgetSet = true; // Set region index - int index = m_regionCombo->findText( location.region ); + int index = m_regionCombo->findData( location.region ); if ( index < 0 ) return; m_regionCombo->setCurrentIndex( index ); // Set zone index - index = m_zoneCombo->findText( location.zone ); + index = m_zoneCombo->findData( location.zone ); if ( index < 0 ) return; @@ -193,13 +195,13 @@ LocalePage::init( const QString& initialRegion, foreach ( const QString& key, keys ) { - m_regionCombo->addItem( key ); + m_regionCombo->addItem( LocaleGlobal::Location::pretty( key ), key ); } m_regionCombo->blockSignals( false ); m_zoneCombo->blockSignals( false ); - m_regionCombo->currentIndexChanged( m_regionCombo->currentText() ); + m_regionCombo->currentIndexChanged( m_regionCombo->currentIndex() ); // Default location auto containsLocation = []( const QList< LocaleGlobal::Location >& locations, diff --git a/src/modules/locale/timezonewidget/localeglobal.cpp b/src/modules/locale/timezonewidget/localeglobal.cpp index 1e32c5a0b..290dab6a2 100644 --- a/src/modules/locale/timezonewidget/localeglobal.cpp +++ b/src/modules/locale/timezonewidget/localeglobal.cpp @@ -22,6 +22,7 @@ #include "localeglobal.h" +#include //### //### Private variables @@ -36,6 +37,23 @@ QHash > LocaleGlobal::locations; //### +QString +LocaleGlobal::Location::pretty( const QString& s ) +{ + return QString( s ).replace( '_', ' ' ).simplified(); +} + + +QString +LocaleGlobal::Location::comment() +{ + QTimeZone qtz = QTimeZone( QString( "%1/%2" ) + .arg( region ) + .arg( zone ).toLatin1() ); + return qtz.comment(); +} + + void LocaleGlobal::init() { // TODO: Error handling initLocales(); @@ -162,3 +180,4 @@ double LocaleGlobal::getRightGeoLocation(QString str) { return sign * num; } + diff --git a/src/modules/locale/timezonewidget/localeglobal.h b/src/modules/locale/timezonewidget/localeglobal.h index edf2da335..b55683006 100644 --- a/src/modules/locale/timezonewidget/localeglobal.h +++ b/src/modules/locale/timezonewidget/localeglobal.h @@ -1,6 +1,6 @@ /* === This file is part of Calamares - === * - * Copyright 2014, Teo Mrnjavac + * Copyright 2014-2015, Teo Mrnjavac * * Originally from the Manjaro Installation Framework * by Roland Singer @@ -45,6 +45,8 @@ public: struct Location { QString region, zone; double latitude, longitude; + static QString pretty( const QString& s ); + QString comment(); }; static void init(); diff --git a/src/modules/locale/timezonewidget/timezonewidget.cpp b/src/modules/locale/timezonewidget/timezonewidget.cpp index 0513a85b2..af4ac1a17 100644 --- a/src/modules/locale/timezonewidget/timezonewidget.cpp +++ b/src/modules/locale/timezonewidget/timezonewidget.cpp @@ -1,6 +1,6 @@ /* === This file is part of Calamares - === * - * Copyright 2014, Teo Mrnjavac + * Copyright 2014-2015, Teo Mrnjavac * * Originally from the Manjaro Installation Framework * by Roland Singer @@ -132,7 +132,7 @@ void TimeZoneWidget::paintEvent(QPaintEvent*) { painter.drawImage(point.x() - pin.width()/2, point.y() - pin.height()/2, pin); // Draw text and box - const int textWidth = fontMetrics.width(currentLocation.zone); + const int textWidth = fontMetrics.width(LocaleGlobal::Location::pretty(currentLocation.zone)); const int textHeight = fontMetrics.height(); QRect rect = QRect(point.x() - textWidth/2 - 5, point.y() - textHeight - 8, textWidth + 10, textHeight - 2); @@ -150,7 +150,7 @@ void TimeZoneWidget::paintEvent(QPaintEvent*) { painter.setBrush(QColor(40, 40, 40)); painter.drawRoundedRect(rect, 3, 3); painter.setPen(Qt::white); - painter.drawText(rect.x() + 5, rect.bottom() - 4, currentLocation.zone); + painter.drawText(rect.x() + 5, rect.bottom() - 4, LocaleGlobal::Location::pretty(currentLocation.zone)); painter.end(); }