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
pull/31/head
Mavridis Philippe 2 years ago committed by TDE Gitea
parent 62f0e27456
commit 3168c39ef1

@ -8,8 +8,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>464</width> <width>487</width>
<height>280</height> <height>278</height>
</rect> </rect>
</property> </property>
<property name="caption"> <property name="caption">
@ -19,30 +19,18 @@
<property name="name"> <property name="name">
<cstring>unnamed</cstring> <cstring>unnamed</cstring>
</property> </property>
<widget class="TQComboBox" row="0" column="1"> <widget class="TQCheckBox" row="3" column="0" rowspan="1" colspan="2">
<item>
<property name="text">
<string>Horizontal</string>
</property>
</item>
<item>
<property name="text">
<string>Vertical</string>
</property>
</item>
<property name="name"> <property name="name">
<cstring>kcfg_Orientation</cstring> <cstring>kcfg_Menubar</cstring>
</property> </property>
<property name="sizePolicy"> <property name="text">
<sizepolicy> <string>Show &amp;menu bar</string>
<hsizetype>3</hsizetype> </property>
<vsizetype>0</vsizetype> <property name="checked">
<horstretch>0</horstretch> <bool>true</bool>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
</widget> </widget>
<widget class="TQLabel" row="1" column="0"> <widget class="TQLabel" row="2" column="0">
<property name="name"> <property name="name">
<cstring>lblValueStyle</cstring> <cstring>lblValueStyle</cstring>
</property> </property>
@ -50,20 +38,12 @@
<string>Volume values:</string> <string>Volume values:</string>
</property> </property>
</widget> </widget>
<widget class="TQLabel" row="0" column="0"> <widget class="TQCheckBox" row="5" column="0" rowspan="1" colspan="2">
<property name="name"> <property name="name">
<cstring>lblOrientation</cstring> <cstring>kcfg_Labels</cstring>
</property>
<property name="text">
<string>Sliders orientation:</string>
</property>
</widget>
<widget class="TQCheckBox" row="3" column="0" rowspan="1" colspan="2">
<property name="name">
<cstring>kcfg_Tickmarks</cstring>
</property> </property>
<property name="text"> <property name="text">
<string>Show &amp;tickmarks</string> <string>Show &amp;labels</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>true</bool>
@ -71,27 +51,44 @@
</widget> </widget>
<widget class="TQCheckBox" row="4" column="0" rowspan="1" colspan="2"> <widget class="TQCheckBox" row="4" column="0" rowspan="1" colspan="2">
<property name="name"> <property name="name">
<cstring>kcfg_Labels</cstring> <cstring>kcfg_Tickmarks</cstring>
</property> </property>
<property name="text"> <property name="text">
<string>Show &amp;labels</string> <string>Show &amp;tickmarks</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
<widget class="TQCheckBox" row="2" column="0" rowspan="1" colspan="2"> <widget class="TQComboBox" row="2" column="1">
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>Absolute</string>
</property>
</item>
<item>
<property name="text">
<string>Relative</string>
</property>
</item>
<property name="name"> <property name="name">
<cstring>kcfg_Menubar</cstring> <cstring>kcfg_ValueStyle</cstring>
</property>
<property name="text">
<string>Show &amp;menu bar</string>
</property> </property>
<property name="checked"> <property name="sizePolicy">
<bool>true</bool> <sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
</widget> </widget>
<spacer row="5" column="1"> <spacer row="6" column="1">
<property name="name"> <property name="name">
<cstring>spacer5</cstring> <cstring>spacer5</cstring>
</property> </property>
@ -108,24 +105,63 @@
</size> </size>
</property> </property>
</spacer> </spacer>
<widget class="TQLabel" row="1" column="0">
<property name="name">
<cstring>lblOrientation</cstring>
</property>
<property name="text">
<string>Sliders orientation:</string>
</property>
</widget>
<widget class="TQComboBox" row="1" column="1"> <widget class="TQComboBox" row="1" column="1">
<item> <item>
<property name="text"> <property name="text">
<string>None</string> <string>Horizontal</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>Absolute</string> <string>Vertical</string>
</property> </property>
</item> </item>
<property name="name">
<cstring>kcfg_Orientation</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
<widget class="TQLabel" row="0" column="0">
<property name="name">
<cstring>lblOrientation_2</cstring>
</property>
<property name="text">
<string>Icon theme:</string>
</property>
</widget>
<widget class="TQComboBox" row="0" column="1">
<item> <item>
<property name="text"> <property name="text">
<string>Relative</string> <string>Crystal</string>
</property>
</item>
<item>
<property name="text">
<string>Classic (Old Crystal)</string>
</property>
</item>
<item>
<property name="text">
<string>System</string>
</property> </property>
</item> </item>
<property name="name"> <property name="name">
<cstring>kcfg_ValueStyle</cstring> <cstring>kcfg_IconTheme</cstring>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy> <sizepolicy>

@ -99,4 +99,21 @@
<default></default> <default></default>
</entry> </entry>
</group> </group>
<group name="Appearance">
<entry key="IconTheme" type="Enum">
<choices>
<choice name="Crystal">
<label>Crystal</label>
</choice>
<choice name="OldCrystal">
<label>Classic (Old Crystal)</label>
</choice>
<choice name="System">
<label>System theme</label>
</choice>
</choices>
<default>Crystal</default>
<label>Icon Theme</label>
</entry>
</group>
</kcfg> </kcfg>

@ -34,6 +34,7 @@
#include <tdelocale.h> #include <tdelocale.h>
#include <tdepopupmenu.h> #include <tdepopupmenu.h>
#include <tdeglobalsettings.h> #include <tdeglobalsettings.h>
#include <kstandarddirs.h>
#include <tdemainwindow.h> #include <tdemainwindow.h>
#include <tqapplication.h> #include <tqapplication.h>
@ -47,6 +48,7 @@
#include "mixer.h" #include "mixer.h"
#include "mixdevicewidget.h" #include "mixdevicewidget.h"
#include "kmixdockwidget.h" #include "kmixdockwidget.h"
#include "kmixsettings.h"
#include "viewdockareapopup.h" #include "viewdockareapopup.h"
KMixDockWidget::KMixDockWidget( Mixer *mixer, TQWidget *parent, const char *name, bool volumePopup, bool dockIconMuting ) 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(); createActions();
createMasterVolWidget(); createMasterVolWidget();
connect(this, TQ_SIGNAL(quitSelected()), kapp, TQ_SLOT(quitExtended())); 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() 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 void
KMixDockWidget::setVolumeTip() KMixDockWidget::setVolumeTip()
{ {
@ -261,6 +280,7 @@ KMixDockWidget::setVolumeTip()
if ( _dockAreaPopup != 0 ) { if ( _dockAreaPopup != 0 ) {
md = _dockAreaPopup->dockDevice(); md = _dockAreaPopup->dockDevice();
} }
TQString tip = ""; TQString tip = "";
int newToolTipValue = 0; int newToolTipValue = 0;
@ -271,10 +291,7 @@ KMixDockWidget::setVolumeTip()
} }
else else
{ {
long val = -1; long val = getAvgVolume();
if ( md->maxVolume() != 0 ) {
val = (md->getVolume().getAvgVolume(Volume::MMAIN)*100 )/( md->maxVolume() );
}
newToolTipValue = val + 10000*md->isMuted(); newToolTipValue = val + 10000*md->isMuted();
if ( _oldToolTipValue != newToolTipValue ) { if ( _oldToolTipValue != newToolTipValue ) {
tip = i18n( "Volume at %1%" ).arg( val ); tip = i18n( "Volume at %1%" ).arg( val );
@ -316,7 +333,13 @@ KMixDockWidget::updatePixmap(bool force)
} }
else 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)) { if (( newPixmapType != _oldPixmapType ) || (force == true)) {
@ -325,12 +348,23 @@ KMixDockWidget::updatePixmap(bool force)
TQPixmap origpixmap; TQPixmap origpixmap;
TQPixmap scaledpixmap; TQPixmap scaledpixmap;
TQImage newIcon; TQImage newIcon;
TQStringList fallback;
switch ( newPixmapType ) { switch ( newPixmapType ) {
case 'e': origpixmap = isShown() ? loadSizedIcon( "kmixdocked_error", width() ) : loadIcon( "kmixdocked_error"); break; case 'm': fallback << "audio-volume-muted" << "kmixdocked_mute"; break;
case 'm': origpixmap = isShown() ? loadSizedIcon( "kmixdocked_mute" , width() ) : loadIcon( "kmixdocked_mute"); break; case 'L': fallback << "audio-volume-low" << "kmixdocked"; break;
case 'd': origpixmap = isShown() ? loadSizedIcon( "kmixdocked" , width() ) : loadIcon( "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()) { if (isShown()) {
newIcon = newIcon.smoothScale(width(), height()); 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 * ) void KMixDockWidget::resizeEvent ( TQResizeEvent * )
{ {
updatePixmap(true); updatePixmap(true);

@ -70,6 +70,8 @@ class KMixDockWidget : public KSystemTray {
void toggleMinimizeRestore(); void toggleMinimizeRestore();
void resizeEvent(TQResizeEvent *); void resizeEvent(TQResizeEvent *);
void showEvent(TQShowEvent *); void showEvent(TQShowEvent *);
long getAvgVolume();
TQString getIconPath(TQStringList fallback);
private: private:
bool _playBeepOnVolumeChange; bool _playBeepOnVolumeChange;

@ -16,8 +16,10 @@ install( FILES
mix_microphone.png mix_midi.png mix_recmon.png mix_microphone.png mix_midi.png mix_recmon.png
mix_treble.png mix_unknown.png mix_volume.png mix_treble.png mix_unknown.png mix_volume.png
mix_surround.png mix_video.png mix_headphone.png mix_surround.png mix_video.png mix_headphone.png
mix_digital.png mix_ac97.png kmixdocked.png mix_digital.png mix_ac97.png mix_record.png
kmixdocked_mute.png kmixdocked_error.png mix_record.png
SpeakerFrontLeft.png SpeakerRearLeft.png SpeakerFrontRight.png SpeakerFrontLeft.png SpeakerRearLeft.png SpeakerFrontRight.png
SpeakerRearRight.png Listener.png SpeakerRearRight.png Listener.png
DESTINATION ${DATA_INSTALL_DIR}/kmix/pics ) DESTINATION ${DATA_INSTALL_DIR}/kmix/pics )
add_subdirectory(oldcrystal)
add_subdirectory(crystal)

@ -0,0 +1,13 @@
################################################################################
# Copyright © 2024 Mavridis Philippe <mavridisf@gmail.com> #
# #
# 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})

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

@ -0,0 +1,13 @@
################################################################################
# Copyright © 2024 Mavridis Philippe <mavridisf@gmail.com> #
# #
# 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})

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 607 B

After

Width:  |  Height:  |  Size: 607 B

Loading…
Cancel
Save