From 3168c39ef1e445db1a6e22a7ba63e8cb4714e6e8 Mon Sep 17 00:00:00 2001 From: Mavridis Philippe Date: Sun, 12 Dec 2021 16:24:28 +0200 Subject: KMix: system tray icon enhancements * XDG-compliant icon names with volume level specification (low, medium, high) Low-Medium threshold: 33% Medium-High threshold: 67% * Improved built-in icon theme with distinct volume levels (according to above) * Choice between classic KMix icon theme, imrpoved KMix icon theme and system theme. * New KMixDockWidget::getAvgVolume() method Gets average volume in %. Code actually comes from KMixDockWidget::setVolumeTip(), but was put into a separate method to be reused for determination of icon according to the volume level --- kmix/appearanceconfig.ui | 130 +++++++++++++++++---------- kmix/kmix.kcfg | 17 ++++ kmix/kmixdockwidget.cpp | 97 ++++++++++++++++++-- kmix/kmixdockwidget.h | 2 + kmix/pics/CMakeLists.txt | 6 +- kmix/pics/crystal/CMakeLists.txt | 13 +++ kmix/pics/crystal/audio-volume-error.png | Bin 0 -> 1176 bytes kmix/pics/crystal/audio-volume-high.png | Bin 0 -> 1581 bytes kmix/pics/crystal/audio-volume-low.png | Bin 0 -> 1379 bytes kmix/pics/crystal/audio-volume-medium.png | Bin 0 -> 1423 bytes kmix/pics/crystal/audio-volume-muted.png | Bin 0 -> 809 bytes kmix/pics/kmixdocked.png | Bin 1215 -> 0 bytes kmix/pics/kmixdocked_error.png | Bin 1176 -> 0 bytes kmix/pics/kmixdocked_mute.png | Bin 607 -> 0 bytes kmix/pics/oldcrystal/CMakeLists.txt | 13 +++ kmix/pics/oldcrystal/audio-volume-error.png | Bin 0 -> 1176 bytes kmix/pics/oldcrystal/audio-volume-high.png | 1 + kmix/pics/oldcrystal/audio-volume-low.png | Bin 0 -> 1215 bytes kmix/pics/oldcrystal/audio-volume-medium.png | 1 + kmix/pics/oldcrystal/audio-volume-muted.png | Bin 0 -> 607 bytes 20 files changed, 222 insertions(+), 58 deletions(-) create mode 100644 kmix/pics/crystal/CMakeLists.txt create mode 100644 kmix/pics/crystal/audio-volume-error.png create mode 100644 kmix/pics/crystal/audio-volume-high.png create mode 100644 kmix/pics/crystal/audio-volume-low.png create mode 100644 kmix/pics/crystal/audio-volume-medium.png create mode 100644 kmix/pics/crystal/audio-volume-muted.png delete mode 100644 kmix/pics/kmixdocked.png delete mode 100644 kmix/pics/kmixdocked_error.png delete mode 100644 kmix/pics/kmixdocked_mute.png create mode 100644 kmix/pics/oldcrystal/CMakeLists.txt create mode 100644 kmix/pics/oldcrystal/audio-volume-error.png create mode 120000 kmix/pics/oldcrystal/audio-volume-high.png create mode 100644 kmix/pics/oldcrystal/audio-volume-low.png create mode 120000 kmix/pics/oldcrystal/audio-volume-medium.png create mode 100644 kmix/pics/oldcrystal/audio-volume-muted.png diff --git a/kmix/appearanceconfig.ui b/kmix/appearanceconfig.ui index a55f5a11..294b00fb 100644 --- a/kmix/appearanceconfig.ui +++ b/kmix/appearanceconfig.ui @@ -8,8 +8,8 @@ 0 0 - 464 - 280 + 487 + 278 @@ -19,30 +19,18 @@ unnamed - - - - Horizontal - - - - - Vertical - - + - kcfg_Orientation + kcfg_Menubar - - - 3 - 0 - 0 - 0 - + + Show &menu bar + + + true - + lblValueStyle @@ -50,20 +38,12 @@ Volume values: - + - lblOrientation - - - Sliders orientation: - - - - - kcfg_Tickmarks + kcfg_Labels - Show &tickmarks + Show &labels true @@ -71,27 +51,44 @@ - kcfg_Labels + kcfg_Tickmarks - Show &labels + Show &tickmarks true - + + + + None + + + + + Absolute + + + + + Relative + + - kcfg_Menubar - - - Show &menu bar + kcfg_ValueStyle - - true + + + 3 + 0 + 0 + 0 + - + spacer5 @@ -108,24 +105,63 @@ + + + lblOrientation + + + Sliders orientation: + + - None + Horizontal - Absolute + Vertical + + kcfg_Orientation + + + + 3 + 0 + 0 + 0 + + + + + + lblOrientation_2 + + + Icon theme: + + + - Relative + Crystal + + + + + Classic (Old Crystal) + + + + + System - kcfg_ValueStyle + kcfg_IconTheme diff --git a/kmix/kmix.kcfg b/kmix/kmix.kcfg index b6d595bd..d4ca0956 100644 --- a/kmix/kmix.kcfg +++ b/kmix/kmix.kcfg @@ -99,4 +99,21 @@ + + + + + + + + + + + + + + Crystal + + + \ No newline at end of file diff --git a/kmix/kmixdockwidget.cpp b/kmix/kmixdockwidget.cpp index 574a996c..fba30421 100644 --- a/kmix/kmixdockwidget.cpp +++ b/kmix/kmixdockwidget.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -47,6 +48,7 @@ #include "mixer.h" #include "mixdevicewidget.h" #include "kmixdockwidget.h" +#include "kmixsettings.h" #include "viewdockareapopup.h" KMixDockWidget::KMixDockWidget( Mixer *mixer, TQWidget *parent, const char *name, bool volumePopup, bool dockIconMuting ) @@ -72,6 +74,9 @@ KMixDockWidget::KMixDockWidget( Mixer *mixer, TQWidget *parent, const char *name createActions(); createMasterVolWidget(); connect(this, TQ_SIGNAL(quitSelected()), kapp, TQ_SLOT(quitExtended())); + + TDEGlobal::dirs()->addResourceDir("icons_crystal", locate("appdata", "pics/crystal/")); + TDEGlobal::dirs()->addResourceDir("icons_oldcrystal", locate("appdata", "pics/oldcrystal/")); } KMixDockWidget::~KMixDockWidget() @@ -254,6 +259,20 @@ void KMixDockWidget::handleNewMaster(bool defaultMaster, int soundcard_id, const } +long +KMixDockWidget::getAvgVolume() +{ + MixDevice *md = 0; + if ( _dockAreaPopup != 0 ) { + md = _dockAreaPopup->dockDevice(); + } + + if ( md == 0 || md->maxVolume() == 0 ) + return -1; + + return (md->getVolume().getAvgVolume(Volume::MMAIN)*100 )/( md->maxVolume() ); +} + void KMixDockWidget::setVolumeTip() { @@ -261,6 +280,7 @@ KMixDockWidget::setVolumeTip() if ( _dockAreaPopup != 0 ) { md = _dockAreaPopup->dockDevice(); } + TQString tip = ""; int newToolTipValue = 0; @@ -271,10 +291,7 @@ KMixDockWidget::setVolumeTip() } else { - long val = -1; - if ( md->maxVolume() != 0 ) { - val = (md->getVolume().getAvgVolume(Volume::MMAIN)*100 )/( md->maxVolume() ); - } + long val = getAvgVolume(); newToolTipValue = val + 10000*md->isMuted(); if ( _oldToolTipValue != newToolTipValue ) { tip = i18n( "Volume at %1%" ).arg( val ); @@ -316,7 +333,13 @@ KMixDockWidget::updatePixmap(bool force) } else { - newPixmapType = 'd'; + long avgVol = getAvgVolume(); + if ( avgVol <= 33 ) + newPixmapType = 'L'; + else if ( avgVol <= 67 ) + newPixmapType = 'M'; + else + newPixmapType = 'H'; } if (( newPixmapType != _oldPixmapType ) || (force == true)) { @@ -325,12 +348,23 @@ KMixDockWidget::updatePixmap(bool force) TQPixmap origpixmap; TQPixmap scaledpixmap; TQImage newIcon; + + TQStringList fallback; switch ( newPixmapType ) { - case 'e': origpixmap = isShown() ? loadSizedIcon( "kmixdocked_error", width() ) : loadIcon( "kmixdocked_error"); break; - case 'm': origpixmap = isShown() ? loadSizedIcon( "kmixdocked_mute" , width() ) : loadIcon( "kmixdocked_mute"); break; - case 'd': origpixmap = isShown() ? loadSizedIcon( "kmixdocked" , width() ) : loadIcon( "kmixdocked "); break; + case 'm': fallback << "audio-volume-muted" << "kmixdocked_mute"; break; + case 'L': fallback << "audio-volume-low" << "kmixdocked"; break; + case 'M': fallback << "audio-volume-medium" << "kmixdocked"; break; + case 'H': fallback << "audio-volume-high" << "kmixdocked"; break; } - newIcon = origpixmap; + + TQString icon = getIconPath(fallback); + if (icon.isNull()) + { + icon = getIconPath("audio-volume-error"); + } + + origpixmap = isShown() ? loadSizedIcon(icon, width()) : loadIcon(icon); + newIcon = origpixmap; if (isShown()) { newIcon = newIcon.smoothScale(width(), height()); } @@ -341,6 +375,51 @@ KMixDockWidget::updatePixmap(bool force) } } +TQString KMixDockWidget::getIconPath(TQStringList fallback) +{ + auto iconTheme = KMixSettings::iconTheme(); + + TQCString iconThemeName; + if (iconTheme != KMixSettings::EnumIconTheme::System) + { + switch (iconTheme) + { + case KMixSettings::EnumIconTheme::OldCrystal: + iconThemeName = "oldcrystal"; + break; + + default: + case KMixSettings::EnumIconTheme::Crystal: + iconThemeName = "crystal"; + break; + } + } + + for (TQStringList::iterator it = fallback.begin(); it != fallback.end(); ++it) + { + if (iconTheme == KMixSettings::EnumIconTheme::System) + { + TQString iconPath = kapp->iconLoader()->iconPath((*it), TDEIcon::Panel, true); + if (!iconPath.isNull()) + { + return iconPath; + } + } + + else + { + TQCString type = "icons_" + iconThemeName; + + TQString iconPath = TDEGlobal::dirs()->findResource(type, TQString("%1.png").arg(*it)); + if (!iconPath.isNull()) return iconPath; + + iconPath = TDEGlobal::dirs()->findResource(type, TQString("%1.svg").arg(*it)); + if (!iconPath.isNull()) return iconPath; + } + } + return TQString::null; +} + void KMixDockWidget::resizeEvent ( TQResizeEvent * ) { updatePixmap(true); diff --git a/kmix/kmixdockwidget.h b/kmix/kmixdockwidget.h index a7b420a0..8f119ace 100644 --- a/kmix/kmixdockwidget.h +++ b/kmix/kmixdockwidget.h @@ -70,6 +70,8 @@ class KMixDockWidget : public KSystemTray { void toggleMinimizeRestore(); void resizeEvent(TQResizeEvent *); void showEvent(TQShowEvent *); + long getAvgVolume(); + TQString getIconPath(TQStringList fallback); private: bool _playBeepOnVolumeChange; diff --git a/kmix/pics/CMakeLists.txt b/kmix/pics/CMakeLists.txt index 35ea82c5..92af67f8 100644 --- a/kmix/pics/CMakeLists.txt +++ b/kmix/pics/CMakeLists.txt @@ -16,8 +16,10 @@ install( FILES mix_microphone.png mix_midi.png mix_recmon.png mix_treble.png mix_unknown.png mix_volume.png mix_surround.png mix_video.png mix_headphone.png - mix_digital.png mix_ac97.png kmixdocked.png - kmixdocked_mute.png kmixdocked_error.png mix_record.png + mix_digital.png mix_ac97.png mix_record.png SpeakerFrontLeft.png SpeakerRearLeft.png SpeakerFrontRight.png SpeakerRearRight.png Listener.png DESTINATION ${DATA_INSTALL_DIR}/kmix/pics ) + +add_subdirectory(oldcrystal) +add_subdirectory(crystal) \ No newline at end of file diff --git a/kmix/pics/crystal/CMakeLists.txt b/kmix/pics/crystal/CMakeLists.txt new file mode 100644 index 00000000..71f61d26 --- /dev/null +++ b/kmix/pics/crystal/CMakeLists.txt @@ -0,0 +1,13 @@ +################################################################################ +# Copyright © 2024 Mavridis Philippe # +# # +# This file is released under the GNU GPL version 3 or later. # +# Improvements and feedback are welcome! # +################################################################################ + +set(theme "crystal") + +install(FILES audio-volume-error.png audio-volume-muted.png + audio-volume-low.png audio-volume-medium.png + audio-volume-high.png + DESTINATION ${DATA_INSTALL_DIR}/kmix/pics/${theme}) \ No newline at end of file diff --git a/kmix/pics/crystal/audio-volume-error.png b/kmix/pics/crystal/audio-volume-error.png new file mode 100644 index 00000000..b0497662 Binary files /dev/null and b/kmix/pics/crystal/audio-volume-error.png differ diff --git a/kmix/pics/crystal/audio-volume-high.png b/kmix/pics/crystal/audio-volume-high.png new file mode 100644 index 00000000..bfa7234b Binary files /dev/null and b/kmix/pics/crystal/audio-volume-high.png differ diff --git a/kmix/pics/crystal/audio-volume-low.png b/kmix/pics/crystal/audio-volume-low.png new file mode 100644 index 00000000..e42f7c8b Binary files /dev/null and b/kmix/pics/crystal/audio-volume-low.png differ diff --git a/kmix/pics/crystal/audio-volume-medium.png b/kmix/pics/crystal/audio-volume-medium.png new file mode 100644 index 00000000..4be127eb Binary files /dev/null and b/kmix/pics/crystal/audio-volume-medium.png differ diff --git a/kmix/pics/crystal/audio-volume-muted.png b/kmix/pics/crystal/audio-volume-muted.png new file mode 100644 index 00000000..8ceb8690 Binary files /dev/null and b/kmix/pics/crystal/audio-volume-muted.png differ diff --git a/kmix/pics/kmixdocked.png b/kmix/pics/kmixdocked.png deleted file mode 100644 index 0c3f17d7..00000000 Binary files a/kmix/pics/kmixdocked.png and /dev/null differ diff --git a/kmix/pics/kmixdocked_error.png b/kmix/pics/kmixdocked_error.png deleted file mode 100644 index b0497662..00000000 Binary files a/kmix/pics/kmixdocked_error.png and /dev/null differ diff --git a/kmix/pics/kmixdocked_mute.png b/kmix/pics/kmixdocked_mute.png deleted file mode 100644 index 0dae0f15..00000000 Binary files a/kmix/pics/kmixdocked_mute.png and /dev/null differ diff --git a/kmix/pics/oldcrystal/CMakeLists.txt b/kmix/pics/oldcrystal/CMakeLists.txt new file mode 100644 index 00000000..47b37e11 --- /dev/null +++ b/kmix/pics/oldcrystal/CMakeLists.txt @@ -0,0 +1,13 @@ +################################################################################ +# Copyright © 2024 Mavridis Philippe # +# # +# This file is released under the GNU GPL version 3 or later. # +# Improvements and feedback are welcome! # +################################################################################ + +set(theme "oldcrystal") + +install(FILES audio-volume-error.png audio-volume-muted.png + audio-volume-low.png audio-volume-medium.png + audio-volume-high.png + DESTINATION ${DATA_INSTALL_DIR}/kmix/pics/${theme}) \ No newline at end of file diff --git a/kmix/pics/oldcrystal/audio-volume-error.png b/kmix/pics/oldcrystal/audio-volume-error.png new file mode 100644 index 00000000..b0497662 Binary files /dev/null and b/kmix/pics/oldcrystal/audio-volume-error.png differ diff --git a/kmix/pics/oldcrystal/audio-volume-high.png b/kmix/pics/oldcrystal/audio-volume-high.png new file mode 120000 index 00000000..dd3d1eea --- /dev/null +++ b/kmix/pics/oldcrystal/audio-volume-high.png @@ -0,0 +1 @@ +audio-volume-low.png \ No newline at end of file diff --git a/kmix/pics/oldcrystal/audio-volume-low.png b/kmix/pics/oldcrystal/audio-volume-low.png new file mode 100644 index 00000000..9e8997e5 Binary files /dev/null and b/kmix/pics/oldcrystal/audio-volume-low.png differ diff --git a/kmix/pics/oldcrystal/audio-volume-medium.png b/kmix/pics/oldcrystal/audio-volume-medium.png new file mode 120000 index 00000000..dd3d1eea --- /dev/null +++ b/kmix/pics/oldcrystal/audio-volume-medium.png @@ -0,0 +1 @@ +audio-volume-low.png \ No newline at end of file diff --git a/kmix/pics/oldcrystal/audio-volume-muted.png b/kmix/pics/oldcrystal/audio-volume-muted.png new file mode 100644 index 00000000..70764025 Binary files /dev/null and b/kmix/pics/oldcrystal/audio-volume-muted.png differ -- cgit v1.2.1