mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 01:20:06 +00:00 
			
		
		
		
	Split out map page into map provider and map layout, provider initial content
This commit is contained in:
		
							parent
							
								
									411d2a3832
								
							
						
					
					
						commit
						7aa5190476
					
				
					 7 changed files with 254 additions and 14 deletions
				
			
		|  | @ -227,11 +227,13 @@ set(UI_UI  source/scwx/qt/ui/about_dialog.ui | ||||||
|            source/scwx/qt/ui/settings_dialog.ui |            source/scwx/qt/ui/settings_dialog.ui | ||||||
|            source/scwx/qt/ui/update_dialog.ui) |            source/scwx/qt/ui/update_dialog.ui) | ||||||
| set(HDR_UI_SETUP source/scwx/qt/ui/setup/finish_page.hpp | set(HDR_UI_SETUP source/scwx/qt/ui/setup/finish_page.hpp | ||||||
|                  source/scwx/qt/ui/setup/map_page.hpp |                  source/scwx/qt/ui/setup/map_layout_page.hpp | ||||||
|  |                  source/scwx/qt/ui/setup/map_provider_page.hpp | ||||||
|                  source/scwx/qt/ui/setup/setup_wizard.hpp |                  source/scwx/qt/ui/setup/setup_wizard.hpp | ||||||
|                  source/scwx/qt/ui/setup/welcome_page.hpp) |                  source/scwx/qt/ui/setup/welcome_page.hpp) | ||||||
| set(SRC_UI_SETUP source/scwx/qt/ui/setup/finish_page.cpp | set(SRC_UI_SETUP source/scwx/qt/ui/setup/finish_page.cpp | ||||||
|                  source/scwx/qt/ui/setup/map_page.cpp |                  source/scwx/qt/ui/setup/map_layout_page.cpp | ||||||
|  |                  source/scwx/qt/ui/setup/map_provider_page.cpp | ||||||
|                  source/scwx/qt/ui/setup/setup_wizard.cpp |                  source/scwx/qt/ui/setup/setup_wizard.cpp | ||||||
|                  source/scwx/qt/ui/setup/welcome_page.cpp) |                  source/scwx/qt/ui/setup/welcome_page.cpp) | ||||||
| set(HDR_UTIL source/scwx/qt/util/color.hpp | set(HDR_UTIL source/scwx/qt/util/color.hpp | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| #include <scwx/qt/ui/setup/map_page.hpp> | #include <scwx/qt/ui/setup/map_layout_page.hpp> | ||||||
| 
 | 
 | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
|  | @ -9,21 +9,21 @@ namespace ui | ||||||
| namespace setup | namespace setup | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
| class MapPage::Impl | class MapLayoutPage::Impl | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit Impl() = default; |    explicit Impl() = default; | ||||||
|    ~Impl()         = default; |    ~Impl()         = default; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| MapPage::MapPage(QWidget* parent) : | MapLayoutPage::MapLayoutPage(QWidget* parent) : | ||||||
|     QWizardPage(parent), p {std::make_shared<Impl>()} |     QWizardPage(parent), p {std::make_shared<Impl>()} | ||||||
| { | { | ||||||
|    setTitle(tr("Map Configuration")); |    setTitle(tr("Map Layout")); | ||||||
|    setSubTitle(tr("Configure the Supercell Wx map provider and basic layout.")); |    setSubTitle(tr("Configure the Supercell Wx map layout.")); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| MapPage::~MapPage() = default; | MapLayoutPage::~MapLayoutPage() = default; | ||||||
| 
 | 
 | ||||||
| } // namespace setup
 | } // namespace setup
 | ||||||
| } // namespace ui
 | } // namespace ui
 | ||||||
|  | @ -11,11 +11,11 @@ namespace ui | ||||||
| namespace setup | namespace setup | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
| class MapPage : public QWizardPage | class MapLayoutPage : public QWizardPage | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit MapPage(QWidget* parent = nullptr); |    explicit MapLayoutPage(QWidget* parent = nullptr); | ||||||
|    ~MapPage(); |    ~MapLayoutPage(); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|    class Impl; |    class Impl; | ||||||
							
								
								
									
										207
									
								
								scwx-qt/source/scwx/qt/ui/setup/map_provider_page.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										207
									
								
								scwx-qt/source/scwx/qt/ui/setup/map_provider_page.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,207 @@ | ||||||
|  | #include <scwx/qt/ui/setup/map_provider_page.hpp> | ||||||
|  | #include <scwx/qt/map/map_provider.hpp> | ||||||
|  | #include <scwx/qt/settings/general_settings.hpp> | ||||||
|  | 
 | ||||||
|  | #include <QComboBox> | ||||||
|  | #include <QDesktopServices> | ||||||
|  | #include <QFrame> | ||||||
|  | #include <QGridLayout> | ||||||
|  | #include <QHBoxLayout> | ||||||
|  | #include <QLabel> | ||||||
|  | #include <QLineEdit> | ||||||
|  | #include <QPushButton> | ||||||
|  | #include <QUrl> | ||||||
|  | #include <QVBoxLayout> | ||||||
|  | 
 | ||||||
|  | namespace scwx | ||||||
|  | { | ||||||
|  | namespace qt | ||||||
|  | { | ||||||
|  | namespace ui | ||||||
|  | { | ||||||
|  | namespace setup | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  | struct MapProviderGroup | ||||||
|  | { | ||||||
|  |    QLabel*    apiKeyLabel_ {}; | ||||||
|  |    QLineEdit* apiKeyEdit_ {}; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | class MapProviderPage::Impl | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |    explicit Impl() = default; | ||||||
|  |    ~Impl()         = default; | ||||||
|  | 
 | ||||||
|  |    void        SelectMapProvider(const QString& text); | ||||||
|  |    void        SelectMapProvider(map::MapProvider mapProvider); | ||||||
|  |    void        SetupMapProviderGroup(MapProviderPage*  parent, | ||||||
|  |                                      MapProviderGroup& group, | ||||||
|  |                                      int               row); | ||||||
|  |    static void SetGroupVisible(MapProviderGroup& group, bool visible); | ||||||
|  | 
 | ||||||
|  |    QLayout* layout_ {}; | ||||||
|  | 
 | ||||||
|  |    QFrame*      mapProviderFrame_ {}; | ||||||
|  |    QGridLayout* mapProviderLayout_ {}; | ||||||
|  |    QLabel*      mapProviderLabel_ {}; | ||||||
|  |    QComboBox*   mapProviderComboBox_ {}; | ||||||
|  |    QLabel*      descriptionLabel_ {}; | ||||||
|  |    QFrame*      buttonFrame_ {}; | ||||||
|  |    QHBoxLayout* buttonLayout_ {}; | ||||||
|  |    QPushButton* apiKeyButton_ {}; | ||||||
|  |    QSpacerItem* buttonSpacer_ {}; | ||||||
|  | 
 | ||||||
|  |    MapProviderGroup mapboxGroup_ {}; | ||||||
|  |    MapProviderGroup maptilerGroup_ {}; | ||||||
|  | 
 | ||||||
|  |    map::MapProvider currentMapProvider_ {}; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | MapProviderPage::MapProviderPage(QWidget* parent) : | ||||||
|  |     QWizardPage(parent), p {std::make_shared<Impl>()} | ||||||
|  | { | ||||||
|  |    setTitle(tr("Map Provider")); | ||||||
|  |    setSubTitle(tr("Configure the Supercell Wx map provider.")); | ||||||
|  | 
 | ||||||
|  |    p->mapProviderFrame_    = new QFrame(parent); | ||||||
|  |    p->mapProviderLayout_   = new QGridLayout(parent); | ||||||
|  |    p->mapProviderLabel_    = new QLabel(parent); | ||||||
|  |    p->mapProviderComboBox_ = new QComboBox(parent); | ||||||
|  |    p->descriptionLabel_    = new QLabel(parent); | ||||||
|  |    p->buttonFrame_         = new QFrame(parent); | ||||||
|  |    p->buttonLayout_        = new QHBoxLayout(parent); | ||||||
|  |    p->apiKeyButton_        = new QPushButton(parent); | ||||||
|  |    p->buttonSpacer_ = | ||||||
|  |       new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); | ||||||
|  | 
 | ||||||
|  |    // Map Provider
 | ||||||
|  |    p->mapProviderLabel_->setText(tr("Map Provider")); | ||||||
|  | 
 | ||||||
|  |    for (const auto& mapProvider : map::MapProviderIterator()) | ||||||
|  |    { | ||||||
|  |       p->mapProviderComboBox_->addItem( | ||||||
|  |          QString::fromStdString(map::GetMapProviderName(mapProvider))); | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    p->mapProviderLayout_->setContentsMargins(0, 0, 0, 0); | ||||||
|  |    p->mapProviderLayout_->addWidget(p->mapProviderLabel_, 0, 0, 1, 1); | ||||||
|  |    p->mapProviderLayout_->addWidget(p->mapProviderComboBox_, 0, 1, 1, 1); | ||||||
|  |    p->mapProviderFrame_->setLayout(p->mapProviderLayout_); | ||||||
|  | 
 | ||||||
|  |    // Description
 | ||||||
|  |    p->descriptionLabel_->setText( | ||||||
|  |       ("You must get an API key from the map provider. After creating an " | ||||||
|  |        "account and reviewing terms of service, create an API key (or public " | ||||||
|  |        "token) with default scopes (unless one is created for you). Enter " | ||||||
|  |        "this API key here.")); | ||||||
|  |    p->descriptionLabel_->setWordWrap(true); | ||||||
|  | 
 | ||||||
|  |    // API Key Button
 | ||||||
|  |    p->buttonLayout_->setContentsMargins(0, 0, 0, 0); | ||||||
|  |    p->buttonLayout_->addWidget(p->apiKeyButton_); | ||||||
|  |    p->buttonLayout_->addItem(p->buttonSpacer_); | ||||||
|  |    p->buttonFrame_->setLayout(p->buttonLayout_); | ||||||
|  | 
 | ||||||
|  |    p->SetupMapProviderGroup(this, p->mapboxGroup_, 1); | ||||||
|  |    p->SetupMapProviderGroup(this, p->maptilerGroup_, 2); | ||||||
|  | 
 | ||||||
|  |    connect(p->mapProviderComboBox_, | ||||||
|  |            &QComboBox::currentTextChanged, | ||||||
|  |            this, | ||||||
|  |            [this](const QString& text) { p->SelectMapProvider(text); }); | ||||||
|  | 
 | ||||||
|  |    connect(p->apiKeyButton_, | ||||||
|  |            &QAbstractButton::clicked, | ||||||
|  |            this, | ||||||
|  |            [this]() | ||||||
|  |            { | ||||||
|  |               switch (p->currentMapProvider_) | ||||||
|  |               { | ||||||
|  |               case map::MapProvider::Mapbox: | ||||||
|  |                  QDesktopServices::openUrl(QUrl {"https://www.mapbox.com/"}); | ||||||
|  |                  break; | ||||||
|  | 
 | ||||||
|  |               case map::MapProvider::MapTiler: | ||||||
|  |                  QDesktopServices::openUrl(QUrl {"https://www.maptiler.com/"}); | ||||||
|  |                  break; | ||||||
|  | 
 | ||||||
|  |               default: | ||||||
|  |                  break; | ||||||
|  |               } | ||||||
|  |            }); | ||||||
|  | 
 | ||||||
|  |    // Map provider value
 | ||||||
|  |    map::MapProvider defaultMapProvider = map::GetMapProvider( | ||||||
|  |       settings::GeneralSettings::Instance().map_provider().GetDefault()); | ||||||
|  |    std::string defaultMapProviderName = | ||||||
|  |       map::GetMapProviderName(defaultMapProvider); | ||||||
|  |    p->mapProviderComboBox_->setCurrentText( | ||||||
|  |       QString::fromStdString(defaultMapProviderName)); | ||||||
|  |    p->SelectMapProvider(defaultMapProvider); | ||||||
|  | 
 | ||||||
|  |    p->layout_ = new QVBoxLayout(this); | ||||||
|  |    p->layout_->addWidget(p->mapProviderFrame_); | ||||||
|  |    p->layout_->addWidget(p->descriptionLabel_); | ||||||
|  |    p->layout_->addWidget(p->buttonFrame_); | ||||||
|  |    setLayout(p->layout_); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | MapProviderPage::~MapProviderPage() = default; | ||||||
|  | 
 | ||||||
|  | void MapProviderPage::Impl::SetupMapProviderGroup(MapProviderPage*  parent, | ||||||
|  |                                                   MapProviderGroup& group, | ||||||
|  |                                                   int               row) | ||||||
|  | { | ||||||
|  |    group.apiKeyLabel_ = new QLabel(parent); | ||||||
|  |    group.apiKeyEdit_  = new QLineEdit(parent); | ||||||
|  | 
 | ||||||
|  |    group.apiKeyLabel_->setText("API Key"); | ||||||
|  | 
 | ||||||
|  |    mapProviderLayout_->addWidget(group.apiKeyLabel_, row, 0, 1, 1); | ||||||
|  |    mapProviderLayout_->addWidget(group.apiKeyEdit_, row, 1, 1, 1); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void MapProviderPage::Impl::SelectMapProvider(const QString& text) | ||||||
|  | { | ||||||
|  |    SelectMapProvider(map::GetMapProvider(text.toStdString())); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void MapProviderPage::Impl::SelectMapProvider(map::MapProvider mapProvider) | ||||||
|  | { | ||||||
|  |    std::string name = map::GetMapProviderName(mapProvider); | ||||||
|  | 
 | ||||||
|  |    switch (mapProvider) | ||||||
|  |    { | ||||||
|  |    case map::MapProvider::Mapbox: | ||||||
|  |       SetGroupVisible(mapboxGroup_, true); | ||||||
|  |       SetGroupVisible(maptilerGroup_, false); | ||||||
|  |       break; | ||||||
|  | 
 | ||||||
|  |    case map::MapProvider::MapTiler: | ||||||
|  |       SetGroupVisible(mapboxGroup_, false); | ||||||
|  |       SetGroupVisible(maptilerGroup_, true); | ||||||
|  |       break; | ||||||
|  | 
 | ||||||
|  |    default: | ||||||
|  |       break; | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|  |    apiKeyButton_->setText( | ||||||
|  |       tr("Get %1 API Key").arg(QString::fromStdString(name))); | ||||||
|  | 
 | ||||||
|  |    currentMapProvider_ = mapProvider; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void MapProviderPage::Impl::SetGroupVisible(MapProviderGroup& group, | ||||||
|  |                                             bool              visible) | ||||||
|  | { | ||||||
|  |    group.apiKeyLabel_->setVisible(visible); | ||||||
|  |    group.apiKeyEdit_->setVisible(visible); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | } // namespace setup
 | ||||||
|  | } // namespace ui
 | ||||||
|  | } // namespace qt
 | ||||||
|  | } // namespace scwx
 | ||||||
							
								
								
									
										28
									
								
								scwx-qt/source/scwx/qt/ui/setup/map_provider_page.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								scwx-qt/source/scwx/qt/ui/setup/map_provider_page.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,28 @@ | ||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include <QWizardPage> | ||||||
|  | 
 | ||||||
|  | namespace scwx | ||||||
|  | { | ||||||
|  | namespace qt | ||||||
|  | { | ||||||
|  | namespace ui | ||||||
|  | { | ||||||
|  | namespace setup | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  | class MapProviderPage : public QWizardPage | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |    explicit MapProviderPage(QWidget* parent = nullptr); | ||||||
|  |    ~MapProviderPage(); | ||||||
|  | 
 | ||||||
|  | private: | ||||||
|  |    class Impl; | ||||||
|  |    std::shared_ptr<Impl> p; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | } // namespace setup
 | ||||||
|  | } // namespace ui
 | ||||||
|  | } // namespace qt
 | ||||||
|  | } // namespace scwx
 | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| #include <scwx/qt/ui/setup/setup_wizard.hpp> | #include <scwx/qt/ui/setup/setup_wizard.hpp> | ||||||
| #include <scwx/qt/ui/setup/finish_page.hpp> | #include <scwx/qt/ui/setup/finish_page.hpp> | ||||||
| #include <scwx/qt/ui/setup/map_page.hpp> | #include <scwx/qt/ui/setup/map_layout_page.hpp> | ||||||
|  | #include <scwx/qt/ui/setup/map_provider_page.hpp> | ||||||
| #include <scwx/qt/ui/setup/welcome_page.hpp> | #include <scwx/qt/ui/setup/welcome_page.hpp> | ||||||
| #include <scwx/qt/settings/general_settings.hpp> | #include <scwx/qt/settings/general_settings.hpp> | ||||||
| 
 | 
 | ||||||
|  | @ -35,7 +36,8 @@ SetupWizard::SetupWizard(QWidget* parent) : | ||||||
|    setOption(QWizard::WizardOption::HaveHelpButton); |    setOption(QWizard::WizardOption::HaveHelpButton); | ||||||
| 
 | 
 | ||||||
|    setPage(static_cast<int>(Page::Welcome), new WelcomePage(this)); |    setPage(static_cast<int>(Page::Welcome), new WelcomePage(this)); | ||||||
|    setPage(static_cast<int>(Page::Map), new MapPage(this)); |    setPage(static_cast<int>(Page::MapProvider), new MapProviderPage(this)); | ||||||
|  |    setPage(static_cast<int>(Page::MapLayout), new MapLayoutPage(this)); | ||||||
|    setPage(static_cast<int>(Page::Finish), new FinishPage(this)); |    setPage(static_cast<int>(Page::Finish), new FinishPage(this)); | ||||||
| 
 | 
 | ||||||
| #if !defined(Q_OS_MAC) | #if !defined(Q_OS_MAC) | ||||||
|  |  | ||||||
|  | @ -17,7 +17,8 @@ public: | ||||||
|    enum class Page : int |    enum class Page : int | ||||||
|    { |    { | ||||||
|       Welcome = 0, |       Welcome = 0, | ||||||
|       Map, |       MapProvider, | ||||||
|  |       MapLayout, | ||||||
|       Finish |       Finish | ||||||
|    }; |    }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat