summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormio <stigma@disroot.org>2025-04-18 18:44:03 +1000
committermio <stigma@disroot.org>2025-05-11 16:46:23 +1000
commitd9afd6ce2b504f61945b021a427ea469285d19f9 (patch)
tree6bdfb379519e71ab9bb88c50ba717a1bbf463601
parent6a71a1b4140d02f36e054ac3a57a832f8d9103ea (diff)
downloadcodeine-d9afd6ce2b504f61945b021a427ea469285d19f9.tar.gz
codeine-d9afd6ce2b504f61945b021a427ea469285d19f9.zip
Add mute checkbox to volume slider
Part of https://mirror.git.trinitydesktop.org/gitea/TDE/codeine/issues/5 Signed-off-by: mio <stigma@disroot.org>
-rw-r--r--src/app/stateChange.cpp1
-rw-r--r--src/app/volumeAction.cpp60
-rw-r--r--src/app/volumeAction.h1
-rw-r--r--src/app/xineEngine.cpp12
-rw-r--r--src/app/xineEngine.h2
5 files changed, 67 insertions, 9 deletions
diff --git a/src/app/stateChange.cpp b/src/app/stateChange.cpp
index 2418209..ab671dd 100644
--- a/src/app/stateChange.cpp
+++ b/src/app/stateChange.cpp
@@ -66,6 +66,7 @@ MainWindow::engineStateChanged( Engine::State state )
//FIXME bad design to do this way
m_volumeAction->setVolume(engine()->volume());
+ m_volumeAction->setMuted(engine()->isMuted());
}
diff --git a/src/app/volumeAction.cpp b/src/app/volumeAction.cpp
index b628ba1..ed8924d 100644
--- a/src/app/volumeAction.cpp
+++ b/src/app/volumeAction.cpp
@@ -1,12 +1,15 @@
// (C) 2005 Max Howell (max.howell@methylblue.com)
// See COPYING file for licensing information
+#include <kiconloader.h>
#include <tdelocale.h>
#include <tdetoolbar.h>
#include <tqevent.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqslider.h>
+#include <tqtoolbutton.h>
+#include <tqtooltip.h>
#include "../debug.h"
#include "volumeAction.h"
@@ -20,19 +23,45 @@ public:
VolumeSlider( TQWidget *parent )
: TQFrame( parent )
{
- slider = new TQSlider( TQt::Vertical, this, "volume" );
- label = new TQLabel( this );
+ slider = new TQSlider(TQt::Vertical, this, "volume");
+ label = new TQLabel(this);
- TQBoxLayout *lay = new TQVBoxLayout( this );
- lay->addWidget( slider, 0, TQt::AlignHCenter );
- lay->addWidget( label, 0, TQt::AlignHCenter );
- lay->setMargin( 4 );
+ mute = new TQToolButton(this, "volume_slider_mute");
+ mute->setAutoRaise(true);
+ mute->setToggleButton(true);
+ TQToolTip::add(mute, i18n("Toggle Mute"));
+
+ TQBoxLayout *lay = new TQVBoxLayout(this);
+ lay->addWidget(slider, 0, TQt::AlignHCenter);
+ lay->addWidget(label, 0, TQt::AlignHCenter);
+ lay->addWidget(mute, 0, TQt::AlignHCenter);
+ lay->setMargin(4);
slider->setRange( 0, 100 );
setFrameStyle( TQFrame::Plain | TQFrame::Box );
setSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Preferred );
+ // Test for icon support
+ const char* mutedIcons[] = { "audio-volume-muted", "player_mute", "mute" };
+ bool iconFound = false;
+
+ for (size_t i = 0; i < (sizeof(mutedIcons) / sizeof(*mutedIcons)); ++i)
+ {
+ if (!TDEGlobal::iconLoader()->iconPath(mutedIcons[i], TDEIcon::Toolbar, true).isNull())
+ {
+ mute->setIconSet(TDEGlobal::iconLoader()->loadIconSet(mutedIcons[i], TDEIcon::Toolbar));
+ iconFound = true;
+ break;
+ }
+ }
+
+ if (!iconFound)
+ {
+ mute->setAutoRaise(false);
+ mute->setText(i18n("Mute"));
+ }
+
// Calculate width required for max label size
label->setText( "100%" );
adjustSize();
@@ -41,9 +70,16 @@ public:
hide();
}
+ TQToolButton *mute;
TQLabel *label;
TQSlider *slider;
int requiredWidth;
+
+ void setMuted(bool muted)
+ {
+ // Behave correctly when VolumeAction's "setMuted" slot is invoked.
+ mute->setDown(muted);
+ }
};
@@ -53,7 +89,9 @@ VolumeAction::VolumeAction( TDEToolBar *bar, TDEActionCollection *ac )
{
m_widget = new VolumeSlider( bar->topLevelWidget() );
- connect( this, TQ_SIGNAL(toggled( bool )), TQ_SLOT(toggled( bool )) );
+ connect(this, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggled(bool)));
+ connect(m_widget->mute, TQ_SIGNAL(toggled(bool)), Codeine::engine(), TQ_SLOT(setMuted(bool)));
+ connect(m_widget->mute, TQ_SIGNAL(toggled(bool)), TQ_SLOT(setMuted(bool)));
connect(m_widget->slider, TQ_SIGNAL(valueChanged(int)), Codeine::engine(), TQ_SLOT(setStreamParameter(int)));
connect(m_widget->slider, TQ_SIGNAL(valueChanged(int)), TQ_SLOT(sliderMoved(int)));
}
@@ -90,10 +128,14 @@ VolumeAction::sliderMoved(int v)
}
void
-VolumeAction::setVolume(int volume)
+VolumeAction::setMuted(bool mute)
{
- TQString vol = TQString("%1%").arg(volume);
+ m_widget->setMuted(mute);
+}
+void
+VolumeAction::setVolume(int volume)
+{
// TQt sliders are the wrong way round when vertical.
m_widget->slider->setValue(100 - volume);
}
diff --git a/src/app/volumeAction.h b/src/app/volumeAction.h
index 2645355..4012f85 100644
--- a/src/app/volumeAction.h
+++ b/src/app/volumeAction.h
@@ -18,6 +18,7 @@ class VolumeAction : public TDEToggleAction
virtual int plug( TQWidget*, int );
public slots:
+ void setMuted(bool mute);
// Update Slider and Label to \a volume
void setVolume(int volume);
diff --git a/src/app/xineEngine.cpp b/src/app/xineEngine.cpp
index 346af68..8a23f82 100644
--- a/src/app/xineEngine.cpp
+++ b/src/app/xineEngine.cpp
@@ -455,6 +455,12 @@ VideoWindow::posTimeLength( PosTimeLength type ) const
return 0; //--warning
}
+bool
+VideoWindow::isMuted() const
+{
+ return xine_get_param(m_stream, XINE_PARAM_AUDIO_AMP_MUTE);
+}
+
uint
VideoWindow::volume() const
{
@@ -595,6 +601,12 @@ VideoWindow::setStreamParameter( int value )
xine_set_param( m_stream, parameter, value );
}
+void
+VideoWindow::setMuted(bool mute)
+{
+ xine_set_param(m_stream, XINE_PARAM_AUDIO_AMP_MUTE, mute);
+}
+
const Engine::Scope&
VideoWindow::scope()
{
diff --git a/src/app/xineEngine.h b/src/app/xineEngine.h
index 168080d..d934acc 100644
--- a/src/app/xineEngine.h
+++ b/src/app/xineEngine.h
@@ -62,6 +62,7 @@ namespace Codeine
uint time() const { return posTimeLength( Time ); }
uint length() const { return posTimeLength( Length ); }
+ bool isMuted() const;
uint volume() const;
const Engine::Scope &scope();
@@ -78,6 +79,7 @@ namespace Codeine
///special slot, see implementation to facilitate understanding
void setStreamParameter( int );
+ void setMuted(bool);
signals:
void stateChanged( Engine::State );