Process user-visible strings in TimezoneWidget and LocalePage.

This commit is contained in:
Teo Mrnjavac 2015-02-20 16:09:43 +01:00
parent 0abd902090
commit 71851ed274
4 changed files with 41 additions and 18 deletions

View File

@ -1,6 +1,6 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
*
* 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,

View File

@ -22,6 +22,7 @@
#include "localeglobal.h"
#include <QTimeZone>
//###
//### Private variables
@ -36,6 +37,23 @@ QHash<QString, QList<LocaleGlobal::Location> > 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;
}

View File

@ -1,6 +1,6 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
*
* Originally from the Manjaro Installation Framework
* by Roland Singer <roland@manjaro.org>
@ -45,6 +45,8 @@ public:
struct Location {
QString region, zone;
double latitude, longitude;
static QString pretty( const QString& s );
QString comment();
};
static void init();

View File

@ -1,6 +1,6 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
*
* Originally from the Manjaro Installation Framework
* by Roland Singer <roland@manjaro.org>
@ -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();
}