From 9a70c37ccda960e9b870a62da4b644b00b37f3e7 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Thu, 9 Nov 2023 06:23:41 -0600 Subject: [PATCH] Map layout page contents --- .../scwx/qt/ui/setup/map_layout_page.cpp | 154 ++++++++++++++++++ .../scwx/qt/ui/setup/map_layout_page.hpp | 2 + .../scwx/qt/ui/setup/map_provider_page.cpp | 10 +- 3 files changed, 161 insertions(+), 5 deletions(-) diff --git a/scwx-qt/source/scwx/qt/ui/setup/map_layout_page.cpp b/scwx-qt/source/scwx/qt/ui/setup/map_layout_page.cpp index e19e920b..787248bd 100644 --- a/scwx-qt/source/scwx/qt/ui/setup/map_layout_page.cpp +++ b/scwx-qt/source/scwx/qt/ui/setup/map_layout_page.cpp @@ -1,4 +1,14 @@ #include +#include +#include +#include + +#include +#include +#include +#include +#include +#include namespace scwx { @@ -9,11 +19,38 @@ namespace ui namespace setup { +static constexpr std::size_t kGridWidth_ {2u}; +static constexpr std::size_t kGridHeight_ {2u}; + class MapLayoutPage::Impl { public: explicit Impl() = default; ~Impl() = default; + + void SetupSettingsInterface(); + void UpdateGridDisplay(); + + QLayout* layout_ {}; + + QLabel* descriptionLabel_ {}; + QFrame* settingsFrame_ {}; + QGridLayout* settingsLayout_ {}; + QSpacerItem* settingsSpacer_ {}; + QLabel* gridWidthLabel_ {}; + QSpinBox* gridWidthSpinBox_ {}; + QLabel* gridHeightLabel_ {}; + QSpinBox* gridHeightSpinBox_ {}; + + QSpacerItem* leftGridSpacer_ {}; + QSpacerItem* rightGridSpacer_ {}; + QFrame* gridFrame_ {}; + QGridLayout* gridLayout_ {}; + boost::multi_array gridPanes_ { + boost::extents[kGridWidth_][kGridHeight_]}; + + settings::SettingsInterface gridWidth_ {}; + settings::SettingsInterface gridHeight_ {}; }; MapLayoutPage::MapLayoutPage(QWidget* parent) : @@ -21,10 +58,127 @@ MapLayoutPage::MapLayoutPage(QWidget* parent) : { setTitle(tr("Map Layout")); setSubTitle(tr("Configure the Supercell Wx map layout.")); + + p->descriptionLabel_ = new QLabel(this); + p->settingsFrame_ = new QFrame(this); + p->settingsLayout_ = new QGridLayout(p->settingsFrame_); + p->gridWidthLabel_ = new QLabel(this); + p->gridWidthSpinBox_ = new QSpinBox(this); + p->gridHeightLabel_ = new QLabel(this); + p->gridHeightSpinBox_ = new QSpinBox(this); + + p->settingsSpacer_ = + new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); + p->leftGridSpacer_ = + new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); + p->rightGridSpacer_ = + new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); + p->gridFrame_ = new QFrame(this); + p->gridLayout_ = new QGridLayout(p->gridFrame_); + + // Description + p->descriptionLabel_->setText( + tr("Grid Width and Grid Height settings allow multiple radar products to " + "be viewed simultaneously. Changing Grid Width will create panes " + "side by side, while Grid Height will create panes over and under.")); + p->descriptionLabel_->setWordWrap(true); + + // Settings + p->gridWidthLabel_->setText(tr("Grid Width")); + p->gridHeightLabel_->setText(tr("Grid Height")); + p->gridWidthSpinBox_->setMinimumWidth(100); + p->gridHeightSpinBox_->setMinimumWidth(100); + p->settingsLayout_->setContentsMargins(0, 0, 0, 0); + p->settingsLayout_->addWidget(p->gridWidthLabel_, 0, 0); + p->settingsLayout_->addWidget(p->gridWidthSpinBox_, 0, 1); + p->settingsLayout_->addWidget(p->gridHeightLabel_, 1, 0); + p->settingsLayout_->addWidget(p->gridHeightSpinBox_, 1, 1); + p->settingsLayout_->addItem(p->settingsSpacer_, 0, 2); + p->settingsFrame_->setLayout(p->settingsLayout_); + + // Grid + p->gridLayout_->setContentsMargins(0, 0, 0, 0); + p->gridLayout_->setSpacing(1); + p->gridLayout_->addItem(p->leftGridSpacer_, 0, 0); + p->gridLayout_->addItem(p->rightGridSpacer_, 0, kGridWidth_ + 1); + for (std::size_t i = 0; i < kGridWidth_; ++i) + { + for (std::size_t j = 0; j < kGridHeight_; ++j) + { + auto& pane = p->gridPanes_[i][j]; + pane = new QFrame(this); + pane->setStyleSheet("background-color:black;"); + pane->setFixedSize(75, 50); + p->gridLayout_->addWidget( + pane, static_cast(j), static_cast(i + 1)); + } + } + + // Overall layout + p->layout_ = new QVBoxLayout(this); + p->layout_->addWidget(p->descriptionLabel_); + p->layout_->addWidget(p->settingsFrame_); + p->layout_->addWidget(p->gridFrame_); + setLayout(p->layout_); + + // Configure settings interface + p->SetupSettingsInterface(); + + // Connect signals + connect(p->gridWidthSpinBox_, + &QSpinBox::valueChanged, + this, + [this]() { p->UpdateGridDisplay(); }); + connect(p->gridHeightSpinBox_, + &QSpinBox::valueChanged, + this, + [this]() { p->UpdateGridDisplay(); }); + + // Update grid display + p->UpdateGridDisplay(); } MapLayoutPage::~MapLayoutPage() = default; +void MapLayoutPage::Impl::SetupSettingsInterface() +{ + auto& generalSettings = settings::GeneralSettings::Instance(); + + gridWidth_.SetSettingsVariable(generalSettings.grid_width()); + gridWidth_.SetEditWidget(gridWidthSpinBox_); + + gridHeight_.SetSettingsVariable(generalSettings.grid_height()); + gridHeight_.SetEditWidget(gridHeightSpinBox_); +} + +void MapLayoutPage::Impl::UpdateGridDisplay() +{ + for (std::size_t i = 0; i < kGridWidth_; ++i) + { + for (std::size_t j = 0; j < kGridHeight_; ++j) + { + gridPanes_[i][j]->setVisible( + static_cast(i) < gridWidthSpinBox_->value() && + static_cast(j) < gridHeightSpinBox_->value()); + } + } +} + +bool MapLayoutPage::validatePage() +{ + bool committed = false; + + committed |= p->gridWidth_.Commit(); + committed |= p->gridHeight_.Commit(); + + if (committed) + { + manager::SettingsManager::Instance().SaveSettings(); + } + + return true; +} + } // namespace setup } // namespace ui } // namespace qt diff --git a/scwx-qt/source/scwx/qt/ui/setup/map_layout_page.hpp b/scwx-qt/source/scwx/qt/ui/setup/map_layout_page.hpp index 7e19f6d2..fb75a2d0 100644 --- a/scwx-qt/source/scwx/qt/ui/setup/map_layout_page.hpp +++ b/scwx-qt/source/scwx/qt/ui/setup/map_layout_page.hpp @@ -17,6 +17,8 @@ public: explicit MapLayoutPage(QWidget* parent = nullptr); ~MapLayoutPage(); + bool validatePage() override; + private: class Impl; std::shared_ptr p; diff --git a/scwx-qt/source/scwx/qt/ui/setup/map_provider_page.cpp b/scwx-qt/source/scwx/qt/ui/setup/map_provider_page.cpp index 22ad58e7..6cecf076 100644 --- a/scwx-qt/source/scwx/qt/ui/setup/map_provider_page.cpp +++ b/scwx-qt/source/scwx/qt/ui/setup/map_provider_page.cpp @@ -110,10 +110,10 @@ MapProviderPage::MapProviderPage(QWidget* parent) : // 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.")); + tr("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 @@ -165,7 +165,7 @@ void MapProviderPage::Impl::SetupMapProviderGroup(MapProviderGroup& group, group.apiKeyLabel_ = new QLabel(self_); group.apiKeyEdit_ = new QLineEdit(self_); - group.apiKeyLabel_->setText("API Key"); + group.apiKeyLabel_->setText(tr("API Key")); mapProviderLayout_->addWidget(group.apiKeyLabel_, row, 0, 1, 1); mapProviderLayout_->addWidget(group.apiKeyEdit_, row, 1, 1, 1);