mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 04:40:06 +00:00 
			
		
		
		
	Add theme editor dialog
This commit is contained in:
		
							parent
							
								
									bdb73b645c
								
							
						
					
					
						commit
						c29c0e82dd
					
				
					 3 changed files with 53 additions and 20 deletions
				
			
		|  | @ -48,6 +48,11 @@ | |||
| #include <QToolButton> | ||||
| #include <utility> | ||||
| 
 | ||||
| #define QT6CT_LIBRARY | ||||
| #include <qt6ct-common/qt6ct.h> | ||||
| #include <qt6ct/paletteeditdialog.h> | ||||
| #undef QT6CT_LIBRARY | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
|  | @ -578,31 +583,39 @@ void SettingsDialogImpl::SetupGeneralTab() | |||
|       self_, | ||||
|       [this]() | ||||
|       { | ||||
|          static const std::string themeFilter = "Qt6Ct Theme File (*.conf)"; | ||||
|          static const std::string allFilter   = "All Files (*)"; | ||||
|          const settings::GeneralSettings& generalSettings = | ||||
|             settings::GeneralSettings::Instance(); | ||||
|          const QString file = | ||||
|             generalSettings.theme_file().GetStagedOrValue().c_str(); | ||||
|          const QPalette palette = | ||||
|             Qt6CT::loadColorScheme(file, QApplication::palette()); | ||||
|          QStyle* style = QApplication::style(); | ||||
| 
 | ||||
|          QFileDialog* dialog = new QFileDialog(self_); | ||||
| 
 | ||||
|          dialog->setFileMode(QFileDialog::ExistingFile); | ||||
| 
 | ||||
|          dialog->setNameFilters( | ||||
|             {QObject::tr(themeFilter.c_str()), QObject::tr(allFilter.c_str())}); | ||||
|          // WA_DeleteOnClose manages memory
 | ||||
|          // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
 | ||||
|          auto* dialog = new PaletteEditDialog(palette, style, self_); | ||||
|          dialog->setAttribute(Qt::WA_DeleteOnClose); | ||||
| 
 | ||||
|          QObject::connect( | ||||
|             dialog, | ||||
|             &QFileDialog::fileSelected, | ||||
|             &QDialog::accepted, | ||||
|             self_, | ||||
|             [this](const QString& file) | ||||
|             [dialog]() | ||||
|             { | ||||
|                QString path = QDir::toNativeSeparators(file); | ||||
|                logger_->info("Selected theme file: {}", path.toStdString()); | ||||
|                self_->ui->themeFileLineEdit->setText(path); | ||||
|                const QPalette palette = dialog->selectedPalette(); | ||||
|                const settings::GeneralSettings& generalSettings = | ||||
|                   settings::GeneralSettings::Instance(); | ||||
|                const QString file = | ||||
|                   generalSettings.theme_file().GetStagedOrValue().c_str(); | ||||
|                Qt6CT::createColorScheme(file, palette); | ||||
| 
 | ||||
|                // setText does not emit the textEdited signal
 | ||||
|                Q_EMIT self_->ui->themeFileLineEdit->textEdited(path); | ||||
|                auto uiStyle = scwx::qt::types::GetUiStyle( | ||||
|                   generalSettings.theme().GetValue()); | ||||
|                if (uiStyle == scwx::qt::types::UiStyle::FusionCustom) | ||||
|                { | ||||
|                   QApplication::setPalette(palette); | ||||
|                } | ||||
|             }); | ||||
| 
 | ||||
|          dialog->open(); | ||||
|       }); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 AdenKoperczak
						AdenKoperczak