mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 00:30:05 +00:00 
			
		
		
		
	Add hotkey settings page
This commit is contained in:
		
							parent
							
								
									589eff9882
								
							
						
					
					
						commit
						81f44add42
					
				
					 6 changed files with 299 additions and 35 deletions
				
			
		|  | @ -0,0 +1,90 @@ | |||
| #include <scwx/qt/ui/settings/hotkey_settings_widget.hpp> | ||||
| #include <scwx/qt/ui/hotkey_edit.hpp> | ||||
| #include <scwx/qt/settings/hotkey_settings.hpp> | ||||
| #include <scwx/qt/settings/settings_interface.hpp> | ||||
| #include <scwx/qt/types/hotkey_types.hpp> | ||||
| 
 | ||||
| #include <boost/unordered/unordered_flat_map.hpp> | ||||
| #include <QGridLayout> | ||||
| #include <QLabel> | ||||
| #include <QToolButton> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace ui | ||||
| { | ||||
| 
 | ||||
| static const std::string logPrefix_ = | ||||
|    "scwx::qt::ui::settings::hotkey_settings_widget"; | ||||
| 
 | ||||
| class HotkeySettingsWidget::Impl | ||||
| { | ||||
| public: | ||||
|    explicit Impl(HotkeySettingsWidget* self) : | ||||
|        self_ {self}, layout_ {new QGridLayout(self)} | ||||
|    { | ||||
|       auto& hotkeySettings = settings::HotkeySettings::Instance(); | ||||
| 
 | ||||
|       layout_->setContentsMargins(0, 0, 0, 0); | ||||
| 
 | ||||
|       int row = 0; | ||||
| 
 | ||||
|       for (types::Hotkey hotkey : types::HotkeyIterator()) | ||||
|       { | ||||
|          const std::string& labelText = types::GetHotkeyLongName(hotkey); | ||||
| 
 | ||||
|          QLabel*      label = new QLabel(QObject::tr(labelText.c_str()), self); | ||||
|          HotkeyEdit*  hotkeyEdit  = new HotkeyEdit(self); | ||||
|          QToolButton* resetButton = new QToolButton(self_); | ||||
| 
 | ||||
|          resetButton->setIcon( | ||||
|             QIcon {":/res/icons/font-awesome-6/rotate-left-solid.svg"}); | ||||
|          resetButton->setVisible(false); | ||||
| 
 | ||||
|          layout_->addWidget(label, row, 0); | ||||
|          layout_->addWidget(hotkeyEdit, row, 1); | ||||
|          layout_->addWidget(resetButton, row, 2); | ||||
| 
 | ||||
|          // Create settings interface
 | ||||
|          auto result = hotkeys_.emplace( | ||||
|             hotkey, settings::SettingsInterface<std::string> {}); | ||||
|          auto& pair      = *result.first; | ||||
|          auto& interface = pair.second; | ||||
| 
 | ||||
|          // Add to settings list
 | ||||
|          self_->AddSettingsInterface(&interface); | ||||
| 
 | ||||
|          auto& hotkeyVariable = hotkeySettings.hotkey(hotkey); | ||||
|          interface.SetSettingsVariable(hotkeyVariable); | ||||
|          interface.SetEditWidget(hotkeyEdit); | ||||
|          interface.SetResetButton(resetButton); | ||||
| 
 | ||||
|          ++row; | ||||
|       } | ||||
| 
 | ||||
|       QSpacerItem* spacer = | ||||
|          new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); | ||||
|       layout_->addItem(spacer, row, 0); | ||||
|    } | ||||
|    ~Impl() = default; | ||||
| 
 | ||||
|    HotkeySettingsWidget* self_; | ||||
|    QGridLayout*          layout_; | ||||
| 
 | ||||
|    boost::unordered_flat_map<types::Hotkey, | ||||
|                              settings::SettingsInterface<std::string>> | ||||
|       hotkeys_ {}; | ||||
| }; | ||||
| 
 | ||||
| HotkeySettingsWidget::HotkeySettingsWidget(QWidget* parent) : | ||||
|     SettingsPageWidget(parent), p {std::make_shared<Impl>(this)} | ||||
| { | ||||
| } | ||||
| 
 | ||||
| HotkeySettingsWidget::~HotkeySettingsWidget() = default; | ||||
| 
 | ||||
| } // namespace ui
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
|  | @ -0,0 +1,29 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <scwx/qt/ui/settings/settings_page_widget.hpp> | ||||
| 
 | ||||
| #include <QWidget> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace ui | ||||
| { | ||||
| 
 | ||||
| class HotkeySettingsWidget : public SettingsPageWidget | ||||
| { | ||||
|    Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
|    explicit HotkeySettingsWidget(QWidget* parent = nullptr); | ||||
|    ~HotkeySettingsWidget(); | ||||
| 
 | ||||
| private: | ||||
|    class Impl; | ||||
|    std::shared_ptr<Impl> p; | ||||
| }; | ||||
| 
 | ||||
| } // namespace ui
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
							
								
								
									
										68
									
								
								scwx-qt/source/scwx/qt/ui/settings/settings_page_widget.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								scwx-qt/source/scwx/qt/ui/settings/settings_page_widget.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,68 @@ | |||
| #include <scwx/qt/ui/settings/settings_page_widget.hpp> | ||||
| #include <scwx/qt/settings/settings_interface_base.hpp> | ||||
| 
 | ||||
| #include <vector> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace ui | ||||
| { | ||||
| 
 | ||||
| static const std::string logPrefix_ = | ||||
|    "scwx::qt::ui::settings::settings_page_widget"; | ||||
| 
 | ||||
| class SettingsPageWidget::Impl | ||||
| { | ||||
| public: | ||||
|    explicit Impl() {} | ||||
|    ~Impl() = default; | ||||
| 
 | ||||
|    std::vector<settings::SettingsInterfaceBase*> settings_; | ||||
| }; | ||||
| 
 | ||||
| SettingsPageWidget::SettingsPageWidget(QWidget* parent) : | ||||
|     QWidget(parent), p {std::make_shared<Impl>()} | ||||
| { | ||||
| } | ||||
| 
 | ||||
| SettingsPageWidget::~SettingsPageWidget() = default; | ||||
| 
 | ||||
| void SettingsPageWidget::AddSettingsInterface( | ||||
|    settings::SettingsInterfaceBase* setting) | ||||
| { | ||||
|    p->settings_.push_back(setting); | ||||
| } | ||||
| 
 | ||||
| bool SettingsPageWidget::CommitChanges() | ||||
| { | ||||
|    bool committed = false; | ||||
| 
 | ||||
|    for (auto& setting : p->settings_) | ||||
|    { | ||||
|       committed |= setting->Commit(); | ||||
|    } | ||||
| 
 | ||||
|    return committed; | ||||
| } | ||||
| 
 | ||||
| void SettingsPageWidget::DiscardChanges() | ||||
| { | ||||
|    for (auto& setting : p->settings_) | ||||
|    { | ||||
|       setting->Reset(); | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| void SettingsPageWidget::ResetToDefault() | ||||
| { | ||||
|    for (auto& setting : p->settings_) | ||||
|    { | ||||
|       setting->StageDefault(); | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| } // namespace ui
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
							
								
								
									
										36
									
								
								scwx-qt/source/scwx/qt/ui/settings/settings_page_widget.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								scwx-qt/source/scwx/qt/ui/settings/settings_page_widget.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,36 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <scwx/qt/settings/settings_interface_base.hpp> | ||||
| 
 | ||||
| #include <QWidget> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace ui | ||||
| { | ||||
| 
 | ||||
| class SettingsPageWidget : public QWidget | ||||
| { | ||||
|    Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
|    explicit SettingsPageWidget(QWidget* parent = nullptr); | ||||
|    ~SettingsPageWidget(); | ||||
| 
 | ||||
|    bool CommitChanges(); | ||||
|    void DiscardChanges(); | ||||
|    void ResetToDefault(); | ||||
| 
 | ||||
| protected: | ||||
|    void AddSettingsInterface(settings::SettingsInterfaceBase* setting); | ||||
| 
 | ||||
| private: | ||||
|    class Impl; | ||||
|    std::shared_ptr<Impl> p; | ||||
| }; | ||||
| 
 | ||||
| } // namespace ui
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
|  | @ -22,6 +22,7 @@ | |||
| #include <scwx/qt/types/time_types.hpp> | ||||
| #include <scwx/qt/ui/county_dialog.hpp> | ||||
| #include <scwx/qt/ui/radar_site_dialog.hpp> | ||||
| #include <scwx/qt/ui/settings/hotkey_settings_widget.hpp> | ||||
| #include <scwx/qt/util/color.hpp> | ||||
| #include <scwx/qt/util/file.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
|  | @ -177,6 +178,7 @@ public: | |||
|    void SetupPalettesAlertsTab(); | ||||
|    void SetupAudioTab(); | ||||
|    void SetupTextTab(); | ||||
|    void SetupHotkeysTab(); | ||||
| 
 | ||||
|    void ShowColorDialog(QLineEdit* lineEdit, QFrame* frame = nullptr); | ||||
|    void UpdateRadarDialogLocation(const std::string& id); | ||||
|  | @ -216,6 +218,9 @@ public: | |||
|    std::shared_ptr<manager::PositionManager> positionManager_ { | ||||
|       manager::PositionManager::Instance()}; | ||||
| 
 | ||||
|    std::vector<SettingsPageWidget*> settingsPages_ {}; | ||||
|    HotkeySettingsWidget*            hotkeySettingsWidget_ {}; | ||||
| 
 | ||||
|    settings::SettingsInterface<std::string>  defaultRadarSite_ {}; | ||||
|    settings::SettingsInterface<std::int64_t> gridWidth_ {}; | ||||
|    settings::SettingsInterface<std::int64_t> gridHeight_ {}; | ||||
|  | @ -289,6 +294,9 @@ SettingsDialog::SettingsDialog(QWidget* parent) : | |||
|    // Text
 | ||||
|    p->SetupTextTab(); | ||||
| 
 | ||||
|    // Hotkeys
 | ||||
|    p->SetupHotkeysTab(); | ||||
| 
 | ||||
|    p->ConnectSignals(); | ||||
| } | ||||
| 
 | ||||
|  | @ -1171,6 +1179,16 @@ void SettingsDialogImpl::SetupTextTab() | |||
|       self_->ui->radarSiteHoverTextCheckBox); | ||||
| } | ||||
| 
 | ||||
| void SettingsDialogImpl::SetupHotkeysTab() | ||||
| { | ||||
|    QVBoxLayout* layout = new QVBoxLayout(self_->ui->hotkeys); | ||||
| 
 | ||||
|    hotkeySettingsWidget_ = new HotkeySettingsWidget(self_->ui->hotkeys); | ||||
|    layout->addWidget(hotkeySettingsWidget_); | ||||
| 
 | ||||
|    settingsPages_.push_back(hotkeySettingsWidget_); | ||||
| } | ||||
| 
 | ||||
| QImage SettingsDialogImpl::GenerateColorTableImage( | ||||
|    std::shared_ptr<common::ColorTable> colorTable, | ||||
|    std::uint16_t                       min, | ||||
|  | @ -1343,6 +1361,11 @@ void SettingsDialogImpl::ApplyChanges() | |||
|       committed |= setting->Commit(); | ||||
|    } | ||||
| 
 | ||||
|    for (auto& page : settingsPages_) | ||||
|    { | ||||
|       committed |= page->CommitChanges(); | ||||
|    } | ||||
| 
 | ||||
|    if (committed) | ||||
|    { | ||||
|       manager::SettingsManager::Instance().SaveSettings(); | ||||
|  | @ -1357,6 +1380,11 @@ void SettingsDialogImpl::DiscardChanges() | |||
|    { | ||||
|       setting->Reset(); | ||||
|    } | ||||
| 
 | ||||
|    for (auto& page : settingsPages_) | ||||
|    { | ||||
|       page->DiscardChanges(); | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| void SettingsDialogImpl::ResetToDefault() | ||||
|  | @ -1367,6 +1395,11 @@ void SettingsDialogImpl::ResetToDefault() | |||
|    { | ||||
|       setting->StageDefault(); | ||||
|    } | ||||
| 
 | ||||
|    for (auto& page : settingsPages_) | ||||
|    { | ||||
|       page->ResetToDefault(); | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| std::string SettingsDialogImpl::RadarSiteLabel( | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat