mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 02:40:05 +00:00 
			
		
		
		
	added saving geometry
This commit is contained in:
		
							parent
							
								
									449912e655
								
							
						
					
					
						commit
						1b16b903a0
					
				
					 3 changed files with 27 additions and 5 deletions
				
			
		|  | @ -443,10 +443,15 @@ void MainWindow::keyReleaseEvent(QKeyEvent* ev) | |||
| void MainWindow::showEvent(QShowEvent* event) | ||||
| { | ||||
|    QMainWindow::showEvent(event); | ||||
|    auto& uiSettings = settings::UiSettings::Instance(); | ||||
| 
 | ||||
|    // restore the geometry state
 | ||||
|    std::string uiGeometry = uiSettings.main_ui_geometry().GetValue(); | ||||
|    restoreGeometry( | ||||
|       QByteArray::fromBase64(QByteArray::fromStdString(uiGeometry))); | ||||
| 
 | ||||
|    // restore the UI state
 | ||||
|    std::string uiState = | ||||
|       settings::UiSettings::Instance().main_ui_state().GetValue(); | ||||
|    std::string uiState = uiSettings.main_ui_state().GetValue(); | ||||
| 
 | ||||
|    bool restored = | ||||
|       restoreState(QByteArray::fromBase64(QByteArray::fromStdString(uiState))); | ||||
|  | @ -458,9 +463,15 @@ void MainWindow::showEvent(QShowEvent* event) | |||
| 
 | ||||
| void MainWindow::closeEvent(QCloseEvent* event) | ||||
| { | ||||
|    auto& uiSettings = settings::UiSettings::Instance(); | ||||
| 
 | ||||
|    // save the UI geometry
 | ||||
|    QByteArray uiGeometry = saveGeometry().toBase64(); | ||||
|    uiSettings.main_ui_geometry().StageValue(uiGeometry.data()); | ||||
| 
 | ||||
|    // save the UI state
 | ||||
|    QByteArray uiState = saveState().toBase64(); | ||||
|    settings::UiSettings::Instance().main_ui_state().StageValue(uiState.data()); | ||||
|    uiSettings.main_ui_state().StageValue(uiState.data()); | ||||
| 
 | ||||
|    QMainWindow::closeEvent(event); | ||||
| } | ||||
|  |  | |||
|  | @ -20,6 +20,7 @@ public: | |||
|       mapSettingsExpanded_.SetDefault(true); | ||||
|       timelineExpanded_.SetDefault(true); | ||||
|       mainUIState_.SetDefault(""); | ||||
|       mainUIGeometry_.SetDefault(""); | ||||
|    } | ||||
| 
 | ||||
|    ~UiSettingsImpl() {} | ||||
|  | @ -30,6 +31,7 @@ public: | |||
|    SettingsVariable<bool> mapSettingsExpanded_ {"map_settings_expanded"}; | ||||
|    SettingsVariable<bool> timelineExpanded_ {"timeline_expanded"}; | ||||
|    SettingsVariable<std::string> mainUIState_ {"main_ui_state"}; | ||||
|    SettingsVariable<std::string> mainUIGeometry_ {"main_ui_geometry"}; | ||||
| }; | ||||
| 
 | ||||
| UiSettings::UiSettings() : | ||||
|  | @ -40,7 +42,8 @@ UiSettings::UiSettings() : | |||
|                       &p->level3ProductsExpanded_, | ||||
|                       &p->mapSettingsExpanded_, | ||||
|                       &p->timelineExpanded_, | ||||
|                       &p->mainUIState_}); | ||||
|                       &p->mainUIState_, | ||||
|                       &p->mainUIGeometry_}); | ||||
|    SetDefaults(); | ||||
| } | ||||
| UiSettings::~UiSettings() = default; | ||||
|  | @ -78,6 +81,11 @@ SettingsVariable<std::string>& UiSettings::main_ui_state() const | |||
|    return p->mainUIState_; | ||||
| } | ||||
| 
 | ||||
| SettingsVariable<std::string>& UiSettings::main_ui_geometry() const | ||||
| { | ||||
|    return p->mainUIGeometry_; | ||||
| } | ||||
| 
 | ||||
| bool UiSettings::Shutdown() | ||||
| { | ||||
|    bool dataChanged = false; | ||||
|  | @ -89,6 +97,7 @@ bool UiSettings::Shutdown() | |||
|    dataChanged |= p->mapSettingsExpanded_.Commit(); | ||||
|    dataChanged |= p->timelineExpanded_.Commit(); | ||||
|    dataChanged |= p->mainUIState_.Commit(); | ||||
|    dataChanged |= p->mainUIGeometry_.Commit(); | ||||
| 
 | ||||
|    return dataChanged; | ||||
| } | ||||
|  | @ -106,7 +115,8 @@ bool operator==(const UiSettings& lhs, const UiSettings& rhs) | |||
|            lhs.p->level3ProductsExpanded_ == rhs.p->level3ProductsExpanded_ && | ||||
|            lhs.p->mapSettingsExpanded_ == rhs.p->mapSettingsExpanded_ && | ||||
|            lhs.p->timelineExpanded_ == rhs.p->timelineExpanded_ && | ||||
|            lhs.p->mainUIState_ == rhs.p->mainUIState_); | ||||
|            lhs.p->mainUIState_ == rhs.p->mainUIState_ && | ||||
|            lhs.p->mainUIGeometry_ == rhs.p->mainUIGeometry_); | ||||
| } | ||||
| 
 | ||||
| } // namespace settings
 | ||||
|  |  | |||
|  | @ -33,6 +33,7 @@ public: | |||
|    SettingsVariable<bool>& map_settings_expanded() const; | ||||
|    SettingsVariable<bool>& timeline_expanded() const; | ||||
|    SettingsVariable<std::string>& main_ui_state() const; | ||||
|    SettingsVariable<std::string>& main_ui_geometry() const; | ||||
| 
 | ||||
|    bool Shutdown(); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 AdenKoperczak
						AdenKoperczak