make GUI theme global preference, load it ASAP

This commit is contained in:
Garux
2025-09-29 00:12:13 +05:00
parent 76c423fa63
commit b19fd006c7
8 changed files with 25 additions and 27 deletions
+1 -1
View File
@@ -211,7 +211,7 @@ NodeSmartReference Entity_parseTokens( Tokeniser& tokeniser, EntityCreator& enti
void Map_Read( scene::Node& root, Tokeniser& tokeniser, EntityCreator& entityTable, const PrimitiveParser& parser ){
LayersParser layersParser( root );
if( !layersParser.read_layers( tokeniser ) ){
layersParser.construct_tree(); // contruct anytime to have at least one layer, e.g. when empty .map
layersParser.construct_tree(); // construct anytime to have at least one layer, e.g. when empty .map
return;
}
layersParser.construct_tree();
+2 -2
View File
@@ -208,7 +208,7 @@ static void load_colors_theme( const char *filepath ){
}
void create_colours_menu( QMenu *menu ){
menu = menu->addMenu( "Colors" );
menu = menu->addMenu( "Theming" );
menu->setTearOffEnabled( g_Layout_enableDetachableMenus.m_value );
@@ -227,7 +227,7 @@ void create_colours_menu( QMenu *menu ){
}
theme_contruct_menu( menu );
theme_construct_menu( menu );
create_menu_item_with_mnemonic( menu, "OpenGL Font...", "OpenGLFont" );
+1
View File
@@ -61,6 +61,7 @@
? undo
button to add a layer
buttons to hide/show all layers
? tree item highlight is torn with 'default' theme in windows
*/
class LayerAssignVisitor : public SelectionSystem::Visitor
-2
View File
@@ -115,7 +115,6 @@
#include "referencecache.h"
#include "colors.h"
#include "theme.h"
#include "tools.h"
#include "filterbar.h"
@@ -1870,7 +1869,6 @@ void MainFrame::Create(){
PreferencesDialog_constructWindow( window );
FindTextureDialog_constructWindow( window );
SurfaceInspector_constructWindow( window );
theme_contruct();
SetActiveXY( m_pXYWnd );
+5 -9
View File
@@ -44,6 +44,7 @@
#include "xywindow.h"
#include "mainframe.h"
#include "gtkdlgs.h"
#include "theme.h"
#include <QCoreApplication>
#include <QGridLayout>
@@ -181,6 +182,7 @@ bool Preferences_Save_Safe( PreferenceDictionary& preferences, const char* filen
void RegisterGlobalPreferences( PreferenceSystem& preferences ){
preferences.registerPreference( "gamefile", makeCopiedStringStringImportCallback( LatchedAssignCaller( g_GamesDialog.m_sGameFile ) ), CopiedStringExportStringCaller( g_GamesDialog.m_sGameFile.m_latched ) );
preferences.registerPreference( "gamePrompt", BoolImportStringCaller( g_GamesDialog.m_bGamePrompt ), BoolExportStringCaller( g_GamesDialog.m_bGamePrompt ) );
theme_registerGlobalPreference( preferences );
}
@@ -241,15 +243,8 @@ void CGameDialog::GameFileImport( int value ){
void CGameDialog::GameFileExport( const IntImportCallback& importCallback ) const {
// use m_sGameFile to set value
int i = 0;
for ( const auto *game : mGames )
{
if ( game->mGameFile == m_sGameFile.m_latched ) {
m_nComboSelect = i;
break;
}
i++;
}
if( const auto found = std::ranges::find( mGames, m_sGameFile.m_latched, &CGameDescription::mGameFile ); found != mGames.cend() )
m_nComboSelect = std::distance( mGames.cbegin(), found );
importCallback( m_nComboSelect );
}
@@ -342,6 +337,7 @@ void CGameDialog::Reset(){
void CGameDialog::Init(){
InitGlobalPrefPath();
LoadPrefs();
theme_construct(); // after global prefs, b4 any normal windows
ScanForGames();
if ( mGames.empty() ) {
Error( "Didn't find any valid game file descriptions, aborting\n" );
+12 -10
View File
@@ -38,7 +38,6 @@ enum class ETheme{
Darker,
};
static QActionGroup *s_theme_group;
static ETheme s_theme = ETheme::Dark;
QString load_qss( const char *filename ){
@@ -139,10 +138,10 @@ void theme_set( ETheme theme ){
defaults.is1stThemeApplication = false;
}
void theme_contruct_menu( class QMenu *menu ){
void theme_construct_menu( class QMenu *menu ){
auto *m = menu->addMenu( "GUI Theme" );
m->setTearOffEnabled( g_Layout_enableDetachableMenus.m_value );
auto *group = s_theme_group = new QActionGroup( m );
auto *group = new QActionGroup( m );
for( const auto *name : { "Default", "Fusion", "Dark", "Darker" } )
{
@@ -150,17 +149,17 @@ void theme_contruct_menu( class QMenu *menu ){
a->setCheckable( true );
group->addAction( a );
}
// init radio
if( const int value = static_cast<int>( s_theme ); 0 <= value && value < group->actions().size() )
group->actions().at( value )->setChecked( true );
QObject::connect( s_theme_group, &QActionGroup::triggered, []( QAction *action ){
theme_set( static_cast<ETheme>( s_theme_group->actions().indexOf( action ) ) );
QObject::connect( group, &QActionGroup::triggered, []( QAction *action ){
theme_set( static_cast<ETheme>( action->actionGroup()->actions().indexOf( action ) ) );
} );
}
void ThemeImport( int value ){
s_theme = static_cast<ETheme>( value );
if( s_theme_group != nullptr && 0 <= value && value < s_theme_group->actions().size() ){
s_theme_group->actions().at( value )->setChecked( true );
}
}
typedef FreeCaller<void(int), ThemeImport> ThemeImportCaller;
@@ -170,7 +169,10 @@ void ThemeExport( const IntImportCallback& importer ){
typedef FreeCaller<void(const IntImportCallback&), ThemeExport> ThemeExportCaller;
void theme_contruct(){
GlobalPreferenceSystem().registerPreference( "GUIThemeV2", makeIntStringImportCallback( ThemeImportCaller() ), makeIntStringExportCallback( ThemeExportCaller() ) );
void theme_construct(){
theme_set( s_theme ); // set theme here, not in importer, so it's set on the very 1st start too (when there is no preference to load)
}
void theme_registerGlobalPreference( class PreferenceSystem& preferences ){
preferences.registerPreference( "GUITheme", makeIntStringImportCallback( ThemeImportCaller() ), makeIntStringExportCallback( ThemeExportCaller() ) );
}
+3 -2
View File
@@ -21,5 +21,6 @@
#pragma once
void theme_contruct_menu( class QMenu *menu );
void theme_contruct();
void theme_construct_menu( class QMenu *menu );
void theme_construct();
void theme_registerGlobalPreference( class PreferenceSystem& preferences );
+1 -1
View File
@@ -30,7 +30,7 @@ void OpenURL( const char *url ){
// let's put a little comment
globalOutputStream() << "OpenURL: " << url << '\n';
// QUrl::fromUserInput appears to work well for urls and local paths with spaces
// alternatively can prepend file:/// to the latter and use default QUrl contructor
// alternatively can prepend file:/// to the latter and use default QUrl constructor
if ( !QDesktopServices::openUrl( QUrl::fromUserInput( url ) ) ) {
qt_MessageBox( MainFrame_getWindow(), "Failed to launch browser!" );
}