diff --git a/settings.conf b/settings.conf index fbfbb5c20..316a43dce 100644 --- a/settings.conf +++ b/settings.conf @@ -11,5 +11,5 @@ modules-search: [ local, /path/to/dir/with/more/modules ] # TBD: do we want to allow non-page modules (core-modules) to be set as immediate or # delayed? Is this an intrinsic property of a module? Does it depend on whether it's # a QProcess, a Python script or a plugin? More research is required. --teo -modules-prepare : [ greeting, partition ] +modules-prepare : [ greeting, locale, partition ] modules-postinstall : [ finished ] diff --git a/src/modules/locale/CMakeLists.txt b/src/modules/locale/CMakeLists.txt new file mode 100644 index 000000000..7e7fd359f --- /dev/null +++ b/src/modules/locale/CMakeLists.txt @@ -0,0 +1,15 @@ +include_directories( ${PROJECT_BINARY_DIR}/src/calamares ) +calamares_add_plugin( locale + TYPE viewmodule + EXPORT_MACRO PLUGINDLLEXPORT_PRO + CONFIG_FILE module.conf + SOURCES + LocaleViewStep.cpp + LocalePage.cpp + timezonewidget/timezonewidget.cpp + timezonewidget/localeglobal.cpp + UI + LINK_LIBRARIES + ${CALAMARES_LIBRARIES} + SHARED_LIB +) diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp new file mode 100644 index 000000000..00f27f9dc --- /dev/null +++ b/src/modules/locale/LocalePage.cpp @@ -0,0 +1,141 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "LocalePage.h" + +#include "timezonewidget/timezonewidget.h" + +#include +#include +#include + + +LocalePage::LocalePage( QWidget* parent ) + : QWidget() + , m_blockTzWidgetSet( false ) +{ + QBoxLayout *mainLayout = new QVBoxLayout; + + m_tzWidget = new TimeZoneWidget( this ); + mainLayout->addWidget( m_tzWidget ); + + QBoxLayout *bottomLayout = new QHBoxLayout; + mainLayout->addLayout( bottomLayout ); + + QLabel* cityLabel = new QLabel( tr( "Region:" ), this ); + bottomLayout->addWidget( cityLabel ); + + m_regionCombo = new QComboBox( this ); + bottomLayout->addWidget( m_regionCombo ); + m_regionCombo->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ); + cityLabel->setBuddy( m_regionCombo ); + + bottomLayout->addSpacing( 20 ); + + QLabel* timezoneLabel = new QLabel( tr( "Zone:" ), this ); + bottomLayout->addWidget( timezoneLabel ); + + m_timezoneCombo = new QComboBox( this ); + m_timezoneCombo->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ); + bottomLayout->addWidget( m_timezoneCombo ); + timezoneLabel->setBuddy( m_timezoneCombo ); + + mainLayout->addStretch(); + + setLayout( mainLayout ); + + connect( m_regionCombo, + static_cast< void ( QComboBox::* )( const QString& ) >( &QComboBox::currentIndexChanged ), + [this]( const QString& current ) + { + QHash< QString, QList< LocaleGlobal::Location > > regions = LocaleGlobal::getLocations(); + if ( !regions.contains( current ) ) + return; + + m_timezoneCombo->blockSignals( true ); + + m_timezoneCombo->clear(); + + QList< LocaleGlobal::Location > zones = regions.value( current ); + foreach ( const LocaleGlobal::Location& zone, zones ) + { + m_timezoneCombo->addItem( zone.zone ); + } + + m_timezoneCombo->model()->sort( 0 ); + + m_timezoneCombo->blockSignals( false ); + + m_timezoneCombo->currentIndexChanged( m_timezoneCombo->currentText() ); + }); + + connect( m_timezoneCombo, + static_cast< void ( QComboBox::* )( const QString& ) >( &QComboBox::currentIndexChanged ), + [this]( const QString& current ) + { + if ( !m_blockTzWidgetSet ) + m_tzWidget->setCurrentLocation( m_regionCombo->currentText(), current ); + }); + + connect( m_tzWidget, &TimeZoneWidget::locationChanged, + [this]( LocaleGlobal::Location location ) + { + m_blockTzWidgetSet = true; + + // Set region index + int index = m_regionCombo->findText( location.region ); + if ( index < 0 ) + return; + + m_regionCombo->setCurrentIndex( index ); + + // Set zone index + index = m_timezoneCombo->findText( location.zone ); + if ( index < 0 ) + return; + + m_timezoneCombo->setCurrentIndex( index ); + + m_blockTzWidgetSet = false; + }); +} + + +void +LocalePage::init() +{ + m_regionCombo->blockSignals( true ); + m_timezoneCombo->blockSignals( true ); + + // Setup locations + QHash< QString, QList< LocaleGlobal::Location > > regions = LocaleGlobal::getLocations(); + + QStringList keys = regions.keys(); + keys.sort(); + + foreach ( const QString& key, keys ) + { + m_regionCombo->addItem( key ); + } + + m_regionCombo->blockSignals( false ); + m_timezoneCombo->blockSignals( false ); + + m_regionCombo->currentIndexChanged( m_regionCombo->currentText() ); +} + diff --git a/src/modules/locale/LocalePage.h b/src/modules/locale/LocalePage.h new file mode 100644 index 000000000..67a5205f4 --- /dev/null +++ b/src/modules/locale/LocalePage.h @@ -0,0 +1,43 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef LOCALEPAGE_H +#define LOCALEPAGE_H + +#include + +class QComboBox; +class TimeZoneWidget; + +class LocalePage : public QWidget +{ + Q_OBJECT +public: + explicit LocalePage( QWidget* parent = nullptr ); + + void init(); + +private: + TimeZoneWidget* m_tzWidget; + QComboBox* m_regionCombo; + QComboBox* m_timezoneCombo; + + bool m_blockTzWidgetSet; +}; + +#endif // LOCALEPAGE_H diff --git a/src/modules/locale/LocaleViewStep.cpp b/src/modules/locale/LocaleViewStep.cpp new file mode 100644 index 000000000..f5ae872af --- /dev/null +++ b/src/modules/locale/LocaleViewStep.cpp @@ -0,0 +1,88 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "LocaleViewStep.h" + +#include "LocalePage.h" + +#include "timezonewidget/localeglobal.h" + +LocaleViewStep::LocaleViewStep( QObject* parent ) + : Calamares::ViewStep( parent ) + , m_widget( new LocalePage() ) +{ + LocaleGlobal::init(); //this takes a long time + m_widget->init(); + emit nextStatusChanged( true ); +} + + +LocaleViewStep::~LocaleViewStep() +{ + if ( m_widget && m_widget->parent() == nullptr ) + m_widget->deleteLater(); +} + + +QString +LocaleViewStep::prettyName() const +{ + return tr( "Location" ); +} + + +QWidget* +LocaleViewStep::widget() +{ + return m_widget; +} + + +void +LocaleViewStep::next() +{ + //TODO: actually save those settings somewhere + emit done(); +} + + +void +LocaleViewStep::back() +{} + + +bool +LocaleViewStep::isNextEnabled() const +{ + return true; +} + + +bool +LocaleViewStep::isAtBeginning() const +{ + return true; +} + + +bool +LocaleViewStep::isAtEnd() const +{ + return true; +} + diff --git a/src/modules/locale/LocaleViewStep.h b/src/modules/locale/LocaleViewStep.h new file mode 100644 index 000000000..57c5f44b3 --- /dev/null +++ b/src/modules/locale/LocaleViewStep.h @@ -0,0 +1,56 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef LOCALEVIEWSTEP_H +#define LOCALEVIEWSTEP_H + +#include + +#include "viewpages/ViewStep.h" +#include "PluginDllMacro.h" + +class LocalePage; + +class PLUGINDLLEXPORT LocaleViewStep : public Calamares::ViewStep +{ + Q_OBJECT + Q_PLUGIN_METADATA( IID "calamares.ViewModule/1.0" ) + + Q_INTERFACES( Calamares::ViewStep ) + +public: + explicit LocaleViewStep( QObject* parent = nullptr ); + virtual ~LocaleViewStep(); + + QString prettyName() const override; + + QWidget* widget() override; + + void next() override; + void back() override; + + bool isNextEnabled() const override; + + bool isAtBeginning() const override; + bool isAtEnd() const override; + +private: + LocalePage* m_widget; +}; + +#endif // LOCALEVIEWSTEP_H diff --git a/src/modules/locale/images/bg.png b/src/modules/locale/images/bg.png new file mode 100644 index 000000000..4bf391ae6 Binary files /dev/null and b/src/modules/locale/images/bg.png differ diff --git a/src/modules/locale/images/orig/bg.png b/src/modules/locale/images/orig/bg.png new file mode 100644 index 000000000..d7479bf96 Binary files /dev/null and b/src/modules/locale/images/orig/bg.png differ diff --git a/src/modules/locale/images/orig/timezone_-1.0.png b/src/modules/locale/images/orig/timezone_-1.0.png new file mode 100644 index 000000000..fb00d83c5 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_-1.0.png differ diff --git a/src/modules/locale/images/orig/timezone_-10.0.png b/src/modules/locale/images/orig/timezone_-10.0.png new file mode 100644 index 000000000..472eb888a Binary files /dev/null and b/src/modules/locale/images/orig/timezone_-10.0.png differ diff --git a/src/modules/locale/images/orig/timezone_-11.0.png b/src/modules/locale/images/orig/timezone_-11.0.png new file mode 100644 index 000000000..5f8c5d6f9 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_-11.0.png differ diff --git a/src/modules/locale/images/orig/timezone_-2.0.png b/src/modules/locale/images/orig/timezone_-2.0.png new file mode 100644 index 000000000..30a1ec738 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_-2.0.png differ diff --git a/src/modules/locale/images/orig/timezone_-3.0.png b/src/modules/locale/images/orig/timezone_-3.0.png new file mode 100644 index 000000000..c22dbb64a Binary files /dev/null and b/src/modules/locale/images/orig/timezone_-3.0.png differ diff --git a/src/modules/locale/images/orig/timezone_-3.5.png b/src/modules/locale/images/orig/timezone_-3.5.png new file mode 100644 index 000000000..c1df00b9b Binary files /dev/null and b/src/modules/locale/images/orig/timezone_-3.5.png differ diff --git a/src/modules/locale/images/orig/timezone_-4.0.png b/src/modules/locale/images/orig/timezone_-4.0.png new file mode 100644 index 000000000..4b5a4318c Binary files /dev/null and b/src/modules/locale/images/orig/timezone_-4.0.png differ diff --git a/src/modules/locale/images/orig/timezone_-4.5.png b/src/modules/locale/images/orig/timezone_-4.5.png new file mode 100644 index 000000000..9e3c13459 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_-4.5.png differ diff --git a/src/modules/locale/images/orig/timezone_-5.0.png b/src/modules/locale/images/orig/timezone_-5.0.png new file mode 100644 index 000000000..06c15e697 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_-5.0.png differ diff --git a/src/modules/locale/images/orig/timezone_-5.5.png b/src/modules/locale/images/orig/timezone_-5.5.png new file mode 100644 index 000000000..b1c788dc8 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_-5.5.png differ diff --git a/src/modules/locale/images/orig/timezone_-6.0.png b/src/modules/locale/images/orig/timezone_-6.0.png new file mode 100644 index 000000000..8505fb1f7 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_-6.0.png differ diff --git a/src/modules/locale/images/orig/timezone_-7.0.png b/src/modules/locale/images/orig/timezone_-7.0.png new file mode 100644 index 000000000..fec235da4 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_-7.0.png differ diff --git a/src/modules/locale/images/orig/timezone_-8.0.png b/src/modules/locale/images/orig/timezone_-8.0.png new file mode 100644 index 000000000..bdad7bf50 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_-8.0.png differ diff --git a/src/modules/locale/images/orig/timezone_-9.0.png b/src/modules/locale/images/orig/timezone_-9.0.png new file mode 100644 index 000000000..04cb3cb8b Binary files /dev/null and b/src/modules/locale/images/orig/timezone_-9.0.png differ diff --git a/src/modules/locale/images/orig/timezone_-9.5.png b/src/modules/locale/images/orig/timezone_-9.5.png new file mode 100644 index 000000000..b1c788dc8 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_-9.5.png differ diff --git a/src/modules/locale/images/orig/timezone_0.0.png b/src/modules/locale/images/orig/timezone_0.0.png new file mode 100644 index 000000000..e59b773ca Binary files /dev/null and b/src/modules/locale/images/orig/timezone_0.0.png differ diff --git a/src/modules/locale/images/orig/timezone_1.0.png b/src/modules/locale/images/orig/timezone_1.0.png new file mode 100644 index 000000000..2053b7e2e Binary files /dev/null and b/src/modules/locale/images/orig/timezone_1.0.png differ diff --git a/src/modules/locale/images/orig/timezone_10.0.png b/src/modules/locale/images/orig/timezone_10.0.png new file mode 100644 index 000000000..475dcf43a Binary files /dev/null and b/src/modules/locale/images/orig/timezone_10.0.png differ diff --git a/src/modules/locale/images/orig/timezone_10.5.png b/src/modules/locale/images/orig/timezone_10.5.png new file mode 100644 index 000000000..6ec7f9fa9 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_10.5.png differ diff --git a/src/modules/locale/images/orig/timezone_11.0.png b/src/modules/locale/images/orig/timezone_11.0.png new file mode 100644 index 000000000..6168aa2ba Binary files /dev/null and b/src/modules/locale/images/orig/timezone_11.0.png differ diff --git a/src/modules/locale/images/orig/timezone_11.5.png b/src/modules/locale/images/orig/timezone_11.5.png new file mode 100644 index 000000000..afdedd7e0 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_11.5.png differ diff --git a/src/modules/locale/images/orig/timezone_12.0.png b/src/modules/locale/images/orig/timezone_12.0.png new file mode 100644 index 000000000..d0b35317e Binary files /dev/null and b/src/modules/locale/images/orig/timezone_12.0.png differ diff --git a/src/modules/locale/images/orig/timezone_12.75.png b/src/modules/locale/images/orig/timezone_12.75.png new file mode 100644 index 000000000..4f74a8582 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_12.75.png differ diff --git a/src/modules/locale/images/orig/timezone_13.0.png b/src/modules/locale/images/orig/timezone_13.0.png new file mode 100644 index 000000000..fe2f134cd Binary files /dev/null and b/src/modules/locale/images/orig/timezone_13.0.png differ diff --git a/src/modules/locale/images/orig/timezone_2.0.png b/src/modules/locale/images/orig/timezone_2.0.png new file mode 100644 index 000000000..ec1e87401 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_2.0.png differ diff --git a/src/modules/locale/images/orig/timezone_3.0.png b/src/modules/locale/images/orig/timezone_3.0.png new file mode 100644 index 000000000..eda59dce1 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_3.0.png differ diff --git a/src/modules/locale/images/orig/timezone_3.5.png b/src/modules/locale/images/orig/timezone_3.5.png new file mode 100644 index 000000000..2dc7399a8 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_3.5.png differ diff --git a/src/modules/locale/images/orig/timezone_4.0.png b/src/modules/locale/images/orig/timezone_4.0.png new file mode 100644 index 000000000..483dc5342 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_4.0.png differ diff --git a/src/modules/locale/images/orig/timezone_4.5.png b/src/modules/locale/images/orig/timezone_4.5.png new file mode 100644 index 000000000..e09ed90bb Binary files /dev/null and b/src/modules/locale/images/orig/timezone_4.5.png differ diff --git a/src/modules/locale/images/orig/timezone_5.0.png b/src/modules/locale/images/orig/timezone_5.0.png new file mode 100644 index 000000000..1bb6d20f3 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_5.0.png differ diff --git a/src/modules/locale/images/orig/timezone_5.5.png b/src/modules/locale/images/orig/timezone_5.5.png new file mode 100644 index 000000000..f904cc298 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_5.5.png differ diff --git a/src/modules/locale/images/orig/timezone_5.75.png b/src/modules/locale/images/orig/timezone_5.75.png new file mode 100644 index 000000000..827ce1a45 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_5.75.png differ diff --git a/src/modules/locale/images/orig/timezone_6.0.png b/src/modules/locale/images/orig/timezone_6.0.png new file mode 100644 index 000000000..460f9cf11 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_6.0.png differ diff --git a/src/modules/locale/images/orig/timezone_6.5.png b/src/modules/locale/images/orig/timezone_6.5.png new file mode 100644 index 000000000..d307bf310 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_6.5.png differ diff --git a/src/modules/locale/images/orig/timezone_7.0.png b/src/modules/locale/images/orig/timezone_7.0.png new file mode 100644 index 000000000..239115af9 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_7.0.png differ diff --git a/src/modules/locale/images/orig/timezone_8.0.png b/src/modules/locale/images/orig/timezone_8.0.png new file mode 100644 index 000000000..3627686fd Binary files /dev/null and b/src/modules/locale/images/orig/timezone_8.0.png differ diff --git a/src/modules/locale/images/orig/timezone_9.0.png b/src/modules/locale/images/orig/timezone_9.0.png new file mode 100644 index 000000000..65d2e46dd Binary files /dev/null and b/src/modules/locale/images/orig/timezone_9.0.png differ diff --git a/src/modules/locale/images/orig/timezone_9.5.png b/src/modules/locale/images/orig/timezone_9.5.png new file mode 100644 index 000000000..1c3290c08 Binary files /dev/null and b/src/modules/locale/images/orig/timezone_9.5.png differ diff --git a/src/modules/locale/images/pin.png b/src/modules/locale/images/pin.png new file mode 100644 index 000000000..d4b32ed22 Binary files /dev/null and b/src/modules/locale/images/pin.png differ diff --git a/src/modules/locale/images/timezone_-1.0.png b/src/modules/locale/images/timezone_-1.0.png new file mode 100644 index 000000000..f76e008c6 Binary files /dev/null and b/src/modules/locale/images/timezone_-1.0.png differ diff --git a/src/modules/locale/images/timezone_-10.0.png b/src/modules/locale/images/timezone_-10.0.png new file mode 100644 index 000000000..2a04bf251 Binary files /dev/null and b/src/modules/locale/images/timezone_-10.0.png differ diff --git a/src/modules/locale/images/timezone_-11.0.png b/src/modules/locale/images/timezone_-11.0.png new file mode 100644 index 000000000..e2cca1485 Binary files /dev/null and b/src/modules/locale/images/timezone_-11.0.png differ diff --git a/src/modules/locale/images/timezone_-2.0.png b/src/modules/locale/images/timezone_-2.0.png new file mode 100644 index 000000000..439ce31eb Binary files /dev/null and b/src/modules/locale/images/timezone_-2.0.png differ diff --git a/src/modules/locale/images/timezone_-3.0.png b/src/modules/locale/images/timezone_-3.0.png new file mode 100644 index 000000000..0c5246e10 Binary files /dev/null and b/src/modules/locale/images/timezone_-3.0.png differ diff --git a/src/modules/locale/images/timezone_-3.5.png b/src/modules/locale/images/timezone_-3.5.png new file mode 100644 index 000000000..327ad65aa Binary files /dev/null and b/src/modules/locale/images/timezone_-3.5.png differ diff --git a/src/modules/locale/images/timezone_-4.0.png b/src/modules/locale/images/timezone_-4.0.png new file mode 100644 index 000000000..d556e93f4 Binary files /dev/null and b/src/modules/locale/images/timezone_-4.0.png differ diff --git a/src/modules/locale/images/timezone_-4.5.png b/src/modules/locale/images/timezone_-4.5.png new file mode 100644 index 000000000..8a86b67a8 Binary files /dev/null and b/src/modules/locale/images/timezone_-4.5.png differ diff --git a/src/modules/locale/images/timezone_-5.0.png b/src/modules/locale/images/timezone_-5.0.png new file mode 100644 index 000000000..8facd09f8 Binary files /dev/null and b/src/modules/locale/images/timezone_-5.0.png differ diff --git a/src/modules/locale/images/timezone_-5.5.png b/src/modules/locale/images/timezone_-5.5.png new file mode 100644 index 000000000..72ec45311 Binary files /dev/null and b/src/modules/locale/images/timezone_-5.5.png differ diff --git a/src/modules/locale/images/timezone_-6.0.png b/src/modules/locale/images/timezone_-6.0.png new file mode 100644 index 000000000..78d8dd7b5 Binary files /dev/null and b/src/modules/locale/images/timezone_-6.0.png differ diff --git a/src/modules/locale/images/timezone_-7.0.png b/src/modules/locale/images/timezone_-7.0.png new file mode 100644 index 000000000..a4a12b9ae Binary files /dev/null and b/src/modules/locale/images/timezone_-7.0.png differ diff --git a/src/modules/locale/images/timezone_-8.0.png b/src/modules/locale/images/timezone_-8.0.png new file mode 100644 index 000000000..81b518e30 Binary files /dev/null and b/src/modules/locale/images/timezone_-8.0.png differ diff --git a/src/modules/locale/images/timezone_-9.0.png b/src/modules/locale/images/timezone_-9.0.png new file mode 100644 index 000000000..ac2ee7874 Binary files /dev/null and b/src/modules/locale/images/timezone_-9.0.png differ diff --git a/src/modules/locale/images/timezone_-9.5.png b/src/modules/locale/images/timezone_-9.5.png new file mode 100644 index 000000000..72ec45311 Binary files /dev/null and b/src/modules/locale/images/timezone_-9.5.png differ diff --git a/src/modules/locale/images/timezone_0.0.png b/src/modules/locale/images/timezone_0.0.png new file mode 100644 index 000000000..987f6caa3 Binary files /dev/null and b/src/modules/locale/images/timezone_0.0.png differ diff --git a/src/modules/locale/images/timezone_1.0.png b/src/modules/locale/images/timezone_1.0.png new file mode 100644 index 000000000..0840db048 Binary files /dev/null and b/src/modules/locale/images/timezone_1.0.png differ diff --git a/src/modules/locale/images/timezone_10.0.png b/src/modules/locale/images/timezone_10.0.png new file mode 100644 index 000000000..9dfbd31f6 Binary files /dev/null and b/src/modules/locale/images/timezone_10.0.png differ diff --git a/src/modules/locale/images/timezone_10.5.png b/src/modules/locale/images/timezone_10.5.png new file mode 100644 index 000000000..8d560bc7e Binary files /dev/null and b/src/modules/locale/images/timezone_10.5.png differ diff --git a/src/modules/locale/images/timezone_11.0.png b/src/modules/locale/images/timezone_11.0.png new file mode 100644 index 000000000..71e62ee0c Binary files /dev/null and b/src/modules/locale/images/timezone_11.0.png differ diff --git a/src/modules/locale/images/timezone_11.5.png b/src/modules/locale/images/timezone_11.5.png new file mode 100644 index 000000000..442cabfeb Binary files /dev/null and b/src/modules/locale/images/timezone_11.5.png differ diff --git a/src/modules/locale/images/timezone_12.0.png b/src/modules/locale/images/timezone_12.0.png new file mode 100644 index 000000000..9d4b458e7 Binary files /dev/null and b/src/modules/locale/images/timezone_12.0.png differ diff --git a/src/modules/locale/images/timezone_12.75.png b/src/modules/locale/images/timezone_12.75.png new file mode 100644 index 000000000..921d59033 Binary files /dev/null and b/src/modules/locale/images/timezone_12.75.png differ diff --git a/src/modules/locale/images/timezone_13.0.png b/src/modules/locale/images/timezone_13.0.png new file mode 100644 index 000000000..87e0e4353 Binary files /dev/null and b/src/modules/locale/images/timezone_13.0.png differ diff --git a/src/modules/locale/images/timezone_2.0.png b/src/modules/locale/images/timezone_2.0.png new file mode 100644 index 000000000..d037c3f79 Binary files /dev/null and b/src/modules/locale/images/timezone_2.0.png differ diff --git a/src/modules/locale/images/timezone_3.0.png b/src/modules/locale/images/timezone_3.0.png new file mode 100644 index 000000000..dc930b78c Binary files /dev/null and b/src/modules/locale/images/timezone_3.0.png differ diff --git a/src/modules/locale/images/timezone_3.5.png b/src/modules/locale/images/timezone_3.5.png new file mode 100644 index 000000000..f803c691f Binary files /dev/null and b/src/modules/locale/images/timezone_3.5.png differ diff --git a/src/modules/locale/images/timezone_4.0.png b/src/modules/locale/images/timezone_4.0.png new file mode 100644 index 000000000..674ce4e6e Binary files /dev/null and b/src/modules/locale/images/timezone_4.0.png differ diff --git a/src/modules/locale/images/timezone_4.5.png b/src/modules/locale/images/timezone_4.5.png new file mode 100644 index 000000000..391c14a0a Binary files /dev/null and b/src/modules/locale/images/timezone_4.5.png differ diff --git a/src/modules/locale/images/timezone_5.0.png b/src/modules/locale/images/timezone_5.0.png new file mode 100644 index 000000000..e8ea14466 Binary files /dev/null and b/src/modules/locale/images/timezone_5.0.png differ diff --git a/src/modules/locale/images/timezone_5.5.png b/src/modules/locale/images/timezone_5.5.png new file mode 100644 index 000000000..78c972fab Binary files /dev/null and b/src/modules/locale/images/timezone_5.5.png differ diff --git a/src/modules/locale/images/timezone_5.75.png b/src/modules/locale/images/timezone_5.75.png new file mode 100644 index 000000000..1bc2c7050 Binary files /dev/null and b/src/modules/locale/images/timezone_5.75.png differ diff --git a/src/modules/locale/images/timezone_6.0.png b/src/modules/locale/images/timezone_6.0.png new file mode 100644 index 000000000..aa149a502 Binary files /dev/null and b/src/modules/locale/images/timezone_6.0.png differ diff --git a/src/modules/locale/images/timezone_6.5.png b/src/modules/locale/images/timezone_6.5.png new file mode 100644 index 000000000..878659506 Binary files /dev/null and b/src/modules/locale/images/timezone_6.5.png differ diff --git a/src/modules/locale/images/timezone_7.0.png b/src/modules/locale/images/timezone_7.0.png new file mode 100644 index 000000000..bc2c8f1ce Binary files /dev/null and b/src/modules/locale/images/timezone_7.0.png differ diff --git a/src/modules/locale/images/timezone_8.0.png b/src/modules/locale/images/timezone_8.0.png new file mode 100644 index 000000000..ee5095a26 Binary files /dev/null and b/src/modules/locale/images/timezone_8.0.png differ diff --git a/src/modules/locale/images/timezone_9.0.png b/src/modules/locale/images/timezone_9.0.png new file mode 100644 index 000000000..f104d2ba6 Binary files /dev/null and b/src/modules/locale/images/timezone_9.0.png differ diff --git a/src/modules/locale/images/timezone_9.5.png b/src/modules/locale/images/timezone_9.5.png new file mode 100644 index 000000000..bfc9637ac Binary files /dev/null and b/src/modules/locale/images/timezone_9.5.png differ diff --git a/src/modules/locale/module.conf b/src/modules/locale/module.conf new file mode 100644 index 000000000..ff129a9e3 --- /dev/null +++ b/src/modules/locale/module.conf @@ -0,0 +1,8 @@ +# Module metadata file for locale viewmodule +# Syntax is YAML 1.2 +--- +type: "view" +name: "locale" +interface: "qtplugin" +requires: [] +load: "libcalamares_viewmodule_locale.so" diff --git a/src/modules/locale/resources.qrc b/src/modules/locale/resources.qrc new file mode 100644 index 000000000..b6b0d0cf7 --- /dev/null +++ b/src/modules/locale/resources.qrc @@ -0,0 +1,44 @@ + + + images/bg.png + images/pin.png + images/timezone_0.0.png + images/timezone_1.0.png + images/timezone_2.0.png + images/timezone_3.0.png + images/timezone_3.5.png + images/timezone_4.0.png + images/timezone_4.5.png + images/timezone_5.0.png + images/timezone_5.5.png + images/timezone_5.75.png + images/timezone_6.0.png + images/timezone_6.5.png + images/timezone_7.0.png + images/timezone_8.0.png + images/timezone_9.0.png + images/timezone_9.5.png + images/timezone_10.0.png + images/timezone_10.5.png + images/timezone_11.0.png + images/timezone_11.5.png + images/timezone_12.0.png + images/timezone_12.75.png + images/timezone_13.0.png + images/timezone_-1.0.png + images/timezone_-2.0.png + images/timezone_-3.0.png + images/timezone_-3.5.png + images/timezone_-4.0.png + images/timezone_-4.5.png + images/timezone_-5.0.png + images/timezone_-5.5.png + images/timezone_-6.0.png + images/timezone_-7.0.png + images/timezone_-8.0.png + images/timezone_-9.0.png + images/timezone_-9.5.png + images/timezone_-10.0.png + images/timezone_-11.0.png + + diff --git a/src/modules/locale/timezonewidget/localeconst.h b/src/modules/locale/timezonewidget/localeconst.h new file mode 100644 index 000000000..bca6f23cc --- /dev/null +++ b/src/modules/locale/timezonewidget/localeconst.h @@ -0,0 +1,33 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Originally from the Manjaro Installation Framework + * by Roland Singer + * Copyright (C) 2007 Free Software Foundation, Inc. + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef LOCALECONST_H +#define LOCALECONST_H + + +#define LOCALESDIR "/usr/share/i18n/locales" +#define TZ_DATA_FILE "/usr/share/zoneinfo/zone.tab" +#define XKB_FILE "/usr/share/X11/xkb/rules/base.lst" +#define USER_IMAGES_PATH "/usr/share/pixmaps/faces" + + +#endif // LOCALECONST_H diff --git a/src/modules/locale/timezonewidget/localeglobal.cpp b/src/modules/locale/timezonewidget/localeglobal.cpp new file mode 100644 index 000000000..da7b47cde --- /dev/null +++ b/src/modules/locale/timezonewidget/localeglobal.cpp @@ -0,0 +1,305 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Originally from the Manjaro Installation Framework + * by Roland Singer + * Copyright (C) 2007 Free Software Foundation, Inc. + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "localeglobal.h" + + +//### +//### Private variables +//### + +QHash > > LocaleGlobal::locales; +QHash > LocaleGlobal::locations; + + +//### +//### Public methods +//### + + +void LocaleGlobal::init() { + // TODO: Error handling + initLocales(); + initLocations(); +} + + + +QHash > > LocaleGlobal::getLocales() { + return locales; +} + + + +QHash > LocaleGlobal::getLocations() { + return locations; +} + + + +QMap LocaleGlobal::getKeyboardLayouts() { + return parseKeyboardLayouts(XKB_FILE); +} + + +QMap LocaleGlobal::getKeyboardModels() { + return parseKeyboardModels(XKB_FILE); +} + + + +//### +//### Private methods +//### + + +void LocaleGlobal::initLocales() { + locales.clear(); + + QStringList files = QDir(LOCALESDIR).entryList(QDir::Files, QDir::Name); + + for (int i = 0; i < files.size(); ++i) { + QString filename = files.at(i); + QFile file(QString(LOCALESDIR) + "/" + filename); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + continue; + + QTextStream in(&file); + QString commentChar = "%"; + Locale locale; + QString lang, territory; + + locale.locale = filename; + + while (!in.atEnd()) { + QString line = in.readLine().trimmed(); + QStringList split = line.split(commentChar, QString::KeepEmptyParts).first().split(QRegExp(" (?=[^\"]*(\"[^\"]*\"[^\"]*)*$)"), QString::SkipEmptyParts); + + if (split.size() < 2) + continue; + + QString sub1 = QString(split.at(0)).remove("\""); + QString sub2 = QString(split.at(1)).remove("\""); + + if (sub1 == "comment_char") + commentChar = sub2; + else if (sub1 == "title") + locale.description = sub2; + else if (sub1 == "territory") + territory= sub2; + else if (sub1 == "language") + lang = sub2; + } + + if (lang.isEmpty() || territory.isEmpty()) + continue; + + locales[lang][territory].append(locale); + } +} + + + +void LocaleGlobal::initLocations() { + locations.clear(); + + QFile file(TZ_DATA_FILE); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + + QTextStream in(&file); + while (!in.atEnd()) { + QString line = in.readLine().trimmed().split('#', QString::KeepEmptyParts).first().trimmed(); + if (line.isEmpty()) + continue; + + QStringList list = line.split(QRegExp("[\t ]"), QString::SkipEmptyParts); + if (list.size() < 3) + continue; + + Location location; + QStringList timezone = list.at(2).split('/', QString::SkipEmptyParts); + int cooSplitPos = QString(list.at(1)).remove(0, 1).indexOf(QRegExp("[-+]")) + 1; + + if (timezone.size() < 2) + continue; + + location.region = timezone.first(); + location.zone = timezone.last(); + location.latitude = getRightGeoLocation(list.at(1).mid(0, cooSplitPos)); + location.longitude = getRightGeoLocation(list.at(1).mid(cooSplitPos)); + + locations[location.region].append(location); + } +} + + + +double LocaleGlobal::getRightGeoLocation(QString str) { + double sign = 1, num = 0.00; + + // Determind sign + if (str.startsWith('-')) { + sign = -1; + str.remove(0, 1); + } + else if (str.startsWith('+')) { + str.remove(0, 1); + } + + + if (str.length() == 4 || str.length() == 6) + num = str.mid(0, 2).toDouble() + str.mid(2, 2).toDouble() / 60; + else if (str.length() == 5 || str.length() == 7) + num = str.mid(0, 3).toDouble() + str.mid(3, 2).toDouble() / 60; + + return sign * num; +} + + + +//### Source by Georg Grabler ###// +QMap LocaleGlobal::parseKeyboardModels(QString filepath) +{ + QMap models; + + QFile fh(filepath); + fh.open(QIODevice::ReadOnly); + + if (!fh.isOpen()) { + qDebug() << "X11 Keyboard model definitions not found!"; + return models; + } + + bool modelsFound = false; + // read the file until the end or until we break the loop + while (!fh.atEnd()) { + QByteArray line = fh.readLine(); + + // check if we start with the model section in the file + if (!modelsFound && line.startsWith("! model")) + modelsFound = true; + else if (modelsFound && line.startsWith ("!")) + break; + else if (!modelsFound) + continue; + + // here we are in the model section, otherwhise we would continue or break + QRegExp rx; + rx.setPattern("^\\s+(\\S+)\\s+(\\w.*)\n$"); + + // insert into the model map + if (rx.indexIn(line) != -1) { + QString modelDesc = rx.cap(2); + QString model = rx.cap(1); + + if (model == "pc105") + modelDesc += " - " + QObject::tr("Default Keyboard Model"); + + models.insert(modelDesc, model); + } + } + + return models; +} + + + +QMap< QString, LocaleGlobal::KeyboardInfo > LocaleGlobal::parseKeyboardLayouts(QString filepath) +{ + QMap< QString, KeyboardInfo > layouts; + + //### Get Layouts ###// + + QFile fh(filepath); + fh.open(QIODevice::ReadOnly); + + if (!fh.isOpen()) { + qDebug() << "X11 Keyboard layout definitions not found!"; + return layouts; + } + + bool layoutsFound = false; + // read the file until the end or we break the loop + while (!fh.atEnd()) { + QByteArray line = fh.readLine(); + + // find the layout section otherwhise continue. If the layout section is at it's end, break the loop + if (!layoutsFound && line.startsWith("! layout")) + layoutsFound = true; + else if (layoutsFound && line.startsWith ("!")) + break; + else if (!layoutsFound) + continue; + + QRegExp rx; + rx.setPattern("^\\s+(\\S+)\\s+(\\w.*)\n$"); + + // insert into the layout map + if (rx.indexIn(line) != -1) { + KeyboardInfo info; + info.description = rx.cap(2); + info.variants.insert(QObject::tr("Default"), ""); + layouts.insert(rx.cap(1), info); + } + } + + fh.reset(); + + + //### Get Variants ###// + + bool variantsFound = false; + // read the file until the end or until we break + while (!fh.atEnd()) { + QByteArray line = fh.readLine(); + + // continue until we found the variant section. If found, read until the next section is found + if (!variantsFound && line.startsWith("! variant")) { + variantsFound = true; + continue; + } else if (variantsFound && line.startsWith ("!")) + break; + else if (!variantsFound) + continue; + + QRegExp rx; + rx.setPattern("^\\s+(\\S+)\\s+(\\S+): (\\w.*)\n$"); + + // insert into the variants multimap, if the pattern matches + if (rx.indexIn(line) != -1) { + if (layouts.find(rx.cap(2)) != layouts.end()) { + // in this case we found an entry in the multimap, and add the values to the multimap + layouts.find(rx.cap(2)).value().variants.insert(rx.cap(3), rx.cap(1)); + } else { + // create a new map in the multimap - the value was not found. + KeyboardInfo info; + info.description = rx.cap(2); + info.variants.insert(QObject::tr("Default"), ""); + info.variants.insert(rx.cap(3), rx.cap(1)); + layouts.insert(rx.cap(2), info); + } + } + } + + return layouts; +} diff --git a/src/modules/locale/timezonewidget/localeglobal.h b/src/modules/locale/timezonewidget/localeglobal.h new file mode 100644 index 000000000..1aee39bbf --- /dev/null +++ b/src/modules/locale/timezonewidget/localeglobal.h @@ -0,0 +1,74 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Originally from the Manjaro Installation Framework + * by Roland Singer + * Copyright (C) 2007 Free Software Foundation, Inc. + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef LOCALEGLOBAL_H +#define LOCALEGLOBAL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "localeconst.h" + +class LocaleGlobal +{ +public: + struct Locale { + QString description, locale; + }; + + struct Location { + QString region, zone; + double latitude, longitude; + }; + + struct KeyboardInfo { + QString description; + QMap< QString, QString > variants; + }; + + + static void init(); + static QHash > > getLocales(); + static QHash > getLocations(); + static QMap< QString, KeyboardInfo > getKeyboardLayouts(); + static QMap getKeyboardModels(); + +private: + static QHash > > locales; + static QHash > locations; + + static void initLocales(); + static void initLocations(); + static double getRightGeoLocation(QString str); + + static QMap parseKeyboardModels(QString filepath); + static QMap< QString, KeyboardInfo > parseKeyboardLayouts(QString filepath); +}; + +#endif // LOCALEGLOBAL_H diff --git a/src/modules/locale/timezonewidget/timezonewidget.cpp b/src/modules/locale/timezonewidget/timezonewidget.cpp new file mode 100644 index 000000000..8719b94a3 --- /dev/null +++ b/src/modules/locale/timezonewidget/timezonewidget.cpp @@ -0,0 +1,193 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Originally from the Manjaro Installation Framework + * by Roland Singer + * Copyright (C) 2007 Free Software Foundation, Inc. + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "timezonewidget.h" + +TimeZoneWidget::TimeZoneWidget(QWidget *parent) : + QWidget(parent) +{ + setMouseTracking(false); + setCursor(Qt::PointingHandCursor); + + // Font + font.setFamily("Cantarell"); + font.setPointSize(12); + font.setBold(false); + + // Images + background = QImage(":/images/bg.png").scaled(X_SIZE, Y_SIZE, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + pin = QImage(":/images/pin.png"); + + // Set size + setMinimumSize(background.size()); + setMaximumSize(background.size()); + + // Zone images + QStringList zones = QString(ZONES).split(" ", QString::SkipEmptyParts); + 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)); +} + + +void TimeZoneWidget::setCurrentLocation(QString region, QString zone) { + QHash > hash = LocaleGlobal::getLocations(); + + if (!hash.contains(region)) + return; + + QList locations = hash.value(region); + for (int i = 0; i < locations.size(); ++i) { + if (locations.at(i).zone == zone) { + setCurrentLocation(locations.at(i)); + break; + } + } +} + + + +void TimeZoneWidget::setCurrentLocation(LocaleGlobal::Location location) { + currentLocation = location; + + // Set zone + QPoint pos = getLocationPosition(currentLocation.longitude, currentLocation.latitude); + + for (int i = 0; i < timeZoneImages.size(); ++i) { + QImage zone = timeZoneImages[i]; + + // If not transparent set as current + if (zone.pixel(pos) != RGB_TRANSPARENT) { + currentZoneImage = zone; + break; + } + } + + // Repaint widget + repaint(); +} + + + +//### +//### Private +//### + + +QPoint TimeZoneWidget::getLocationPosition(double longitude, double latitude) { + const int width = this->width(); + const int height = this->height(); + + 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; + + if (x < 0) + x = width+x; + if (x >= width) + x -= width; + if (y < 0) + y = height+y; + if (y >= height) + y -= height; + + return QPoint((int)x, (int)y); +} + + + +void TimeZoneWidget::paintEvent(QPaintEvent*) { + const int width = this->width(); + const int height = this->height(); + QFontMetrics fontMetrics(font); + QPainter painter(this); + + painter.setRenderHint(QPainter::Antialiasing); + painter.setFont(font); + + // Draw background + painter.drawImage(0, 0, background); + + // Draw zone image + painter.drawImage(0, 0, currentZoneImage); + + // Draw pin + QPoint point = getLocationPosition(currentLocation.longitude, currentLocation.latitude); + 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 textHeight = fontMetrics.height(); + + QRect rect = QRect(point.x() - textWidth/2 - 5, point.y() - textHeight - 8, textWidth + 10, textHeight - 2); + + if (rect.x() <= 5) + rect.moveLeft(5); + if (rect.right() >= width-5) + rect.moveRight(width - 5); + if (rect.y() <= 5) + rect.moveTop(5); + if (rect.y() >= height-5) + rect.moveBottom(height-5); + + painter.setPen(QPen()); // no pen + 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.end(); +} + + + +void TimeZoneWidget::mousePressEvent(QMouseEvent *event) { + if (event->button() != Qt::LeftButton) + return; + + // Set nearest location + int nX = 999999, mX = event->pos().x(); + int nY = 999999, mY = event->pos().y(); + QHash > hash = LocaleGlobal::getLocations(); + QHash >::iterator iter = hash.begin(); + + while (iter != hash.end()) { + QList locations = iter.value(); + + for (int i = 0; i < locations.size(); ++i) { + LocaleGlobal::Location loc = locations[i]; + QPoint locPos = getLocationPosition(loc.longitude, loc.latitude); + + if ((abs(mX - locPos.x()) + abs(mY - locPos.y()) < abs(mX - nX) + abs(mY - nY))) { + currentLocation = loc; + nX = locPos.x(); + nY = locPos.y(); + } + } + + ++iter; + } + + // Set zone image and repaint widget + setCurrentLocation(currentLocation); + + // Emit signal + emit locationChanged(currentLocation); +} diff --git a/src/modules/locale/timezonewidget/timezonewidget.h b/src/modules/locale/timezonewidget/timezonewidget.h new file mode 100644 index 000000000..86b0b0872 --- /dev/null +++ b/src/modules/locale/timezonewidget/timezonewidget.h @@ -0,0 +1,72 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * Originally from the Manjaro Installation Framework + * by Roland Singer + * Copyright (C) 2007 Free Software Foundation, Inc. + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef TIMEZONEWIDGET_H +#define TIMEZONEWIDGET_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "localeglobal.h" + + +#define MAP_Y_OFFSET 0.125 +#define MAP_X_OFFSET -0.0370 +#define RGB_TRANSPARENT 0 +#define ZONES "0.0 1.0 2.0 3.0 3.5 4.0 4.5 5.0 5.5 5.75 6.0 6.5 7.0 8.0 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.75 13.0 -1.0 -2.0 -3.0 -3.5 -4.0 -4.5 -5.0 -5.5 -6.0 -7.0 -8.0 -9.0 -9.5 -10.0 -11.0" +#define X_SIZE 780 +#define Y_SIZE 340 + + +class TimeZoneWidget : public QWidget +{ + Q_OBJECT +public: + explicit TimeZoneWidget(QWidget *parent = 0); + + LocaleGlobal::Location getCurrentLocation() { return currentLocation; } + void setCurrentLocation(QString region, QString zone); + void setCurrentLocation(LocaleGlobal::Location location); + +signals: + void locationChanged(LocaleGlobal::Location location); + +private: + QFont font; + QImage background, pin, currentZoneImage; + QList timeZoneImages; + LocaleGlobal::Location currentLocation; + + QPoint getLocationPosition(double longitude, double latitude); + + void paintEvent(QPaintEvent *event); + void mousePressEvent(QMouseEvent *event); +}; + +#endif // TIMEZONEWIDGET_H