Process user-visible strings in TimezoneWidget and LocalePage.
This commit is contained in:
parent
0abd902090
commit
71851ed274
@ -1,6 +1,6 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/* === 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
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -84,36 +84,38 @@ LocalePage::LocalePage( QWidget* parent )
|
|||||||
setLayout( mainLayout );
|
setLayout( mainLayout );
|
||||||
|
|
||||||
connect( m_regionCombo,
|
connect( m_regionCombo,
|
||||||
static_cast< void ( QComboBox::* )( const QString& ) >( &QComboBox::currentIndexChanged ),
|
static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ),
|
||||||
[this]( const QString& current )
|
[this]( int currentIndex )
|
||||||
{
|
{
|
||||||
|
Q_UNUSED( currentIndex );
|
||||||
QHash< QString, QList< LocaleGlobal::Location > > regions = LocaleGlobal::getLocations();
|
QHash< QString, QList< LocaleGlobal::Location > > regions = LocaleGlobal::getLocations();
|
||||||
if ( !regions.contains( current ) )
|
if ( !regions.contains( m_regionCombo->currentData().toString() ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_zoneCombo->blockSignals( true );
|
m_zoneCombo->blockSignals( true );
|
||||||
|
|
||||||
m_zoneCombo->clear();
|
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 )
|
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->model()->sort( 0 );
|
||||||
|
|
||||||
m_zoneCombo->blockSignals( false );
|
m_zoneCombo->blockSignals( false );
|
||||||
|
|
||||||
m_zoneCombo->currentIndexChanged( m_zoneCombo->currentText() );
|
m_zoneCombo->currentIndexChanged( m_zoneCombo->currentIndex() );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
connect( m_zoneCombo,
|
connect( m_zoneCombo,
|
||||||
static_cast< void ( QComboBox::* )( const QString& ) >( &QComboBox::currentIndexChanged ),
|
static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ),
|
||||||
[this]( const QString& current )
|
[this]( int currentIndex )
|
||||||
{
|
{
|
||||||
if ( !m_blockTzWidgetSet )
|
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,
|
connect( m_tzWidget, &TimeZoneWidget::locationChanged,
|
||||||
@ -122,14 +124,14 @@ LocalePage::LocalePage( QWidget* parent )
|
|||||||
m_blockTzWidgetSet = true;
|
m_blockTzWidgetSet = true;
|
||||||
|
|
||||||
// Set region index
|
// Set region index
|
||||||
int index = m_regionCombo->findText( location.region );
|
int index = m_regionCombo->findData( location.region );
|
||||||
if ( index < 0 )
|
if ( index < 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_regionCombo->setCurrentIndex( index );
|
m_regionCombo->setCurrentIndex( index );
|
||||||
|
|
||||||
// Set zone index
|
// Set zone index
|
||||||
index = m_zoneCombo->findText( location.zone );
|
index = m_zoneCombo->findData( location.zone );
|
||||||
if ( index < 0 )
|
if ( index < 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -193,13 +195,13 @@ LocalePage::init( const QString& initialRegion,
|
|||||||
|
|
||||||
foreach ( const QString& key, keys )
|
foreach ( const QString& key, keys )
|
||||||
{
|
{
|
||||||
m_regionCombo->addItem( key );
|
m_regionCombo->addItem( LocaleGlobal::Location::pretty( key ), key );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_regionCombo->blockSignals( false );
|
m_regionCombo->blockSignals( false );
|
||||||
m_zoneCombo->blockSignals( false );
|
m_zoneCombo->blockSignals( false );
|
||||||
|
|
||||||
m_regionCombo->currentIndexChanged( m_regionCombo->currentText() );
|
m_regionCombo->currentIndexChanged( m_regionCombo->currentIndex() );
|
||||||
|
|
||||||
// Default location
|
// Default location
|
||||||
auto containsLocation = []( const QList< LocaleGlobal::Location >& locations,
|
auto containsLocation = []( const QList< LocaleGlobal::Location >& locations,
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "localeglobal.h"
|
#include "localeglobal.h"
|
||||||
|
|
||||||
|
#include <QTimeZone>
|
||||||
|
|
||||||
//###
|
//###
|
||||||
//### Private variables
|
//### 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() {
|
void LocaleGlobal::init() {
|
||||||
// TODO: Error handling
|
// TODO: Error handling
|
||||||
initLocales();
|
initLocales();
|
||||||
@ -162,3 +180,4 @@ double LocaleGlobal::getRightGeoLocation(QString str) {
|
|||||||
|
|
||||||
return sign * num;
|
return sign * num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/* === 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
|
* Originally from the Manjaro Installation Framework
|
||||||
* by Roland Singer <roland@manjaro.org>
|
* by Roland Singer <roland@manjaro.org>
|
||||||
@ -45,6 +45,8 @@ public:
|
|||||||
struct Location {
|
struct Location {
|
||||||
QString region, zone;
|
QString region, zone;
|
||||||
double latitude, longitude;
|
double latitude, longitude;
|
||||||
|
static QString pretty( const QString& s );
|
||||||
|
QString comment();
|
||||||
};
|
};
|
||||||
|
|
||||||
static void init();
|
static void init();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/* === 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
|
* Originally from the Manjaro Installation Framework
|
||||||
* by Roland Singer <roland@manjaro.org>
|
* 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);
|
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(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);
|
||||||
@ -150,7 +150,7 @@ void TimeZoneWidget::paintEvent(QPaintEvent*) {
|
|||||||
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, currentLocation.zone);
|
painter.drawText(rect.x() + 5, rect.bottom() - 4, LocaleGlobal::Location::pretty(currentLocation.zone));
|
||||||
|
|
||||||
painter.end();
|
painter.end();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user