From 758db8358d3e54485d90c1a64bf8d248d582442a Mon Sep 17 00:00:00 2001 From: Garux Date: Fri, 10 Oct 2025 19:21:39 +0500 Subject: [PATCH] * adjust icons in light GUI themes for better visibility --- docs/changelog-custom.txt | 1 + libs/gtkutil/image.cpp | 32 ++++++++++++++++++++ libs/gtkutil/image.h | 1 + radiant/plugintoolbar.cpp | 5 +-- radiant/theme.cpp | 14 +++++++++ setup/data/tools/bitmaps/csgtool_extrude.svg | 14 ++++++--- setup/data/tools/bitmaps/csgtool_pull.svg | 13 +++++--- setup/data/tools/bitmaps/f-lights.svg | 2 +- setup/data/tools/bitmaps/index.theme | 16 ++++++++++ setup/data/tools/bitmaps_light/index.theme | 16 ++++++++++ 10 files changed, 101 insertions(+), 13 deletions(-) create mode 100644 setup/data/tools/bitmaps/index.theme create mode 100644 setup/data/tools/bitmaps_light/index.theme diff --git a/docs/changelog-custom.txt b/docs/changelog-custom.txt index 8ed2ccd8..62e1a199 100644 --- a/docs/changelog-custom.txt +++ b/docs/changelog-custom.txt @@ -1150,6 +1150,7 @@ misc... * do Run Engine After Compile also after unmonitored builds * support distinct lighting from different sky shaders in one map (by Tom Arrow) * -onesky: fallback to old behavior: any sky emits total of all suns/skylights in the map + * adjust icons in light GUI themes for better visibility diff --git a/libs/gtkutil/image.cpp b/libs/gtkutil/image.cpp index 1fa2af0f..139c68bc 100644 --- a/libs/gtkutil/image.cpp +++ b/libs/gtkutil/image.cpp @@ -25,6 +25,7 @@ #include "os/path.h" #include "string/string.h" #include "stream/stringstream.h" +#include namespace @@ -36,6 +37,34 @@ void BitmapsPath_set( const char* path ){ g_bitmapsPath = path; } +void Bitmaps_generateLight( const char *appPath ){ + for( const char *root : { "", "plugins/" } ) + { + QDir from( QString( appPath ) + root + "bitmaps/" ); + QDir to( QString( appPath ) + root + "bitmaps_light/" ); + for( auto *d : { &from, &to } ){ + d->setNameFilters( QStringList() << "*.svg" << "*.png" << "*.ico" ); + d->setFilter( QDir::Filter::Files ); + } + + if( to.count() < from.count() ){ + to.mkpath( to.absolutePath() ); + for( const QFileInfo& fileinfo : from.entryInfoList() ) + { + QFile file( fileinfo.absoluteFilePath() ); + if( file.open( QIODevice::OpenModeFlag::ReadOnly ) ){ + QByteArray data( file.readAll() ); + if( fileinfo.suffix() == "svg" ) + data.replace( "#C0C0C0", "#575757" ); + QFile outfile( to.absolutePath() + '/' + fileinfo.fileName() ); + if( outfile.open( QIODevice::OpenModeFlag::WriteOnly ) ) + outfile.write( data ); + } + } + } + } +} + QPixmap new_local_image( const char* filename ){ StringOutputStream fullpath( 256 ); @@ -47,6 +76,9 @@ QPixmap new_local_image( const char* filename ){ } QIcon new_local_icon( const char* filename ){ + if( QString name( CopiedString( PathExtensionless( filename ) ).c_str() ); QIcon::hasThemeIcon( name ) ) + return QIcon::fromTheme( name ); + StringOutputStream fullpath( 256 ); for( const auto *ext : { ".svg", ".png", ".ico" } ) diff --git a/libs/gtkutil/image.h b/libs/gtkutil/image.h index c70e0710..307a2a54 100644 --- a/libs/gtkutil/image.h +++ b/libs/gtkutil/image.h @@ -22,6 +22,7 @@ #pragma once void BitmapsPath_set( const char* path ); +void Bitmaps_generateLight( const char *appPath ); #include #include diff --git a/radiant/plugintoolbar.cpp b/radiant/plugintoolbar.cpp index 80e3d512..0c31d677 100644 --- a/radiant/plugintoolbar.cpp +++ b/radiant/plugintoolbar.cpp @@ -24,6 +24,7 @@ #include "itoolbar.h" #include "gtkmisc.h" +#include "gtkutil/image.h" #include "modulesystem.h" #include "stream/stringstream.h" @@ -55,7 +56,7 @@ void toolbar_insert( QToolBar *toolbar, const char* icon, const char* text, cons return; case IToolbarButton::eButton: { - toolbar_append_button( toolbar, tooltip, new_plugin_icon( icon ), plugin_construct_command_name( pluginName, text ).c_str() ); + toolbar_append_button( toolbar, tooltip, new_local_icon( icon ), plugin_construct_command_name( pluginName, text ).c_str() ); // QAction *button = toolbar->addAction( new_plugin_icon( icon ), text, [ibutton](){ ibutton->activate(); } ); // button->setToolTip( tooltip ); } @@ -65,7 +66,7 @@ void toolbar_insert( QToolBar *toolbar, const char* icon, const char* text, cons //. fixme need consistent plugin command names (same in menu and toolbar) for the current command system // now they are defined in 3 places, also must be used in menu to work in toolbar // also no defined toggle menu item support (->setCheckable( true ) is some workaround now) - toolbar_append_button( toolbar, tooltip, new_plugin_icon( icon ), plugin_construct_command_name( pluginName, text ).c_str() )->setCheckable( true ); + toolbar_append_button( toolbar, tooltip, new_local_icon( icon ), plugin_construct_command_name( pluginName, text ).c_str() )->setCheckable( true ); // toolbar_append_toggle_button( toolbar, tooltip, new_plugin_icon( icon ), plugin_construct_command_name( pluginName, text ).c_str() ); // QAction *button = toolbar->addAction( new_plugin_icon( icon ), text, [ibutton](){ ibutton->activate(); } ); // button->setToolTip( tooltip ); diff --git a/radiant/theme.cpp b/radiant/theme.cpp index bddded7c..5d5d47b9 100644 --- a/radiant/theme.cpp +++ b/radiant/theme.cpp @@ -29,6 +29,8 @@ #include "mainframe.h" #include "preferencesystem.h" #include "stringio.h" +#include "stream/stringstream.h" +#include "gtkutil/image.h" enum class ETheme{ @@ -46,6 +48,14 @@ QString load_qss( const char *filename ){ return {}; } +void set_icon_theme( bool light ){ + static auto init = ( Bitmaps_generateLight( AppPath_get() ), QIcon::setThemeSearchPaths( QIcon::themeSearchPaths() << AppPath_get() ), 1 ); + (void)init; + + BitmapsPath_set( StringStream( AppPath_get(), light? "bitmaps_light/" : "bitmaps/" ) ); + QIcon::setThemeName( light? "bitmaps_light" : "bitmaps" ); +} + void theme_set( ETheme theme ){ s_theme = theme; #ifdef WIN32 @@ -61,6 +71,7 @@ void theme_set( ETheme theme ){ defaults; if( theme == ETheme::Default ){ + set_icon_theme( true ); if( !defaults.is1stThemeApplication ){ qApp->setPalette( defaults.palette ); qApp->setStyleSheet( QString() ); @@ -68,11 +79,13 @@ void theme_set( ETheme theme ){ } } else if( theme == ETheme::Fusion ){ + set_icon_theme( true ); qApp->setPalette( defaults.palette ); qApp->setStyleSheet( load_qss( "fusion.qss" ) ); //missing, stub to load custom qss qApp->setStyle( "Fusion" ); } else if( theme == ETheme::Dark ){ + set_icon_theme( false ); qApp->setStyle( "Fusion" ); QPalette darkPalette; const QColor darkColor = QColor( 83, 84, 81 ); @@ -104,6 +117,7 @@ void theme_set( ETheme theme ){ qApp->setStyleSheet( load_qss( "dark.qss" ) ); } else if( theme == ETheme::Darker ){ + set_icon_theme( false ); qApp->setStyle( "Fusion" ); QPalette darkPalette; const QColor darkColor = QColor( 45, 45, 45 ); diff --git a/setup/data/tools/bitmaps/csgtool_extrude.svg b/setup/data/tools/bitmaps/csgtool_extrude.svg index e1d4a8b7..c0f5a4f8 100644 --- a/setup/data/tools/bitmaps/csgtool_extrude.svg +++ b/setup/data/tools/bitmaps/csgtool_extrude.svg @@ -1,9 +1,13 @@ - - - + viewBox="0 0 128 128" style="enable-background:new 0 0 128 128;" xml:space="preserve"> + + + + diff --git a/setup/data/tools/bitmaps/csgtool_pull.svg b/setup/data/tools/bitmaps/csgtool_pull.svg index 12e7a40c..bf4257a8 100644 --- a/setup/data/tools/bitmaps/csgtool_pull.svg +++ b/setup/data/tools/bitmaps/csgtool_pull.svg @@ -1,9 +1,12 @@ - - - + viewBox="0 0 128 128" style="enable-background:new 0 0 128 128;" xml:space="preserve"> + + + + diff --git a/setup/data/tools/bitmaps/f-lights.svg b/setup/data/tools/bitmaps/f-lights.svg index 97019ead..de37229d 100644 --- a/setup/data/tools/bitmaps/f-lights.svg +++ b/setup/data/tools/bitmaps/f-lights.svg @@ -4,7 +4,7 @@ viewBox="0 0 128 128" enable-background="new 0 0 128 128" xml:space="preserve"> - + diff --git a/setup/data/tools/bitmaps/index.theme b/setup/data/tools/bitmaps/index.theme new file mode 100644 index 00000000..5a9bb818 --- /dev/null +++ b/setup/data/tools/bitmaps/index.theme @@ -0,0 +1,16 @@ +[Icon Theme] +Name=DarkIcons +Comment=DarkIcons +Directories=.,../plugins/bitmaps + +[.] +Size=32 +Type=Scalable +MinSize=8 +MaxSize=256 + +[../plugins/bitmaps] +Size=32 +Type=Scalable +MinSize=8 +MaxSize=256 diff --git a/setup/data/tools/bitmaps_light/index.theme b/setup/data/tools/bitmaps_light/index.theme new file mode 100644 index 00000000..5e1e70e4 --- /dev/null +++ b/setup/data/tools/bitmaps_light/index.theme @@ -0,0 +1,16 @@ +[Icon Theme] +Name=LightIcons +Comment=LightIcons +Directories=.,../plugins/bitmaps + +[.] +Size=32 +Type=Scalable +MinSize=8 +MaxSize=256 + +[../plugins/bitmaps_light] +Size=32 +Type=Scalable +MinSize=8 +MaxSize=256