summaryrefslogtreecommitdiffstats
path: root/kmix/kmixdockwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kmix/kmixdockwidget.cpp')
-rw-r--r--kmix/kmixdockwidget.cpp132
1 files changed, 111 insertions, 21 deletions
diff --git a/kmix/kmixdockwidget.cpp b/kmix/kmixdockwidget.cpp
index 7e08f71e..fba30421 100644
--- a/kmix/kmixdockwidget.cpp
+++ b/kmix/kmixdockwidget.cpp
@@ -34,6 +34,8 @@
#include <tdelocale.h>
#include <tdepopupmenu.h>
#include <tdeglobalsettings.h>
+#include <kstandarddirs.h>
+#include <tdemainwindow.h>
#include <tqapplication.h>
#include <tqcursor.h>
@@ -46,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 )
@@ -70,7 +73,10 @@ KMixDockWidget::KMixDockWidget( Mixer *mixer, TQWidget *parent, const char *name
}
createActions();
createMasterVolWidget();
- connect(this, TQT_SIGNAL(quitSelected()), kapp, TQT_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()
@@ -88,7 +94,7 @@ void KMixDockWidget::createActions()
TDEPopupMenu *popupMenu = contextMenu();
// Put "Mute" selector in context menu
- (void)new TDEToggleAction(i18n("M&ute"), 0, TQT_TQOBJECT(this), TQT_SLOT(dockMute()),
+ (void)new TDEToggleAction(i18n("M&ute"), 0, this, TQ_SLOT(dockMute()),
actionCollection(), "dock_mute");
TDEAction *a = actionCollection()->action("dock_mute");
if (a)
@@ -99,7 +105,7 @@ void KMixDockWidget::createActions()
// Put "Select Master Channel" dialog in context menu
if (m_mixer)
{
- (void)new TDEAction(i18n("Select Master Channel..."), 0, TQT_TQOBJECT(this), TQT_SLOT(selectMaster()),
+ (void)new TDEAction(i18n("Select Master Channel..."), 0, this, TQ_SLOT(selectMaster()),
actionCollection(), "select_master");
a = actionCollection()->action("select_master");
if (a)
@@ -114,8 +120,18 @@ void KMixDockWidget::createActions()
a->plug(popupMenu);
}
- // Help and quit
popupMenu->insertSeparator();
+
+ // KMix Options
+ TDEMainWindow *toplevel = static_cast<TDEMainWindow*>(parent());
+ a = toplevel->actionCollection()->action(KStdAction::name(KStdAction::Preferences));
+
+ if (a)
+ {
+ a->plug(popupMenu);
+ }
+
+ // Help and quit
popupMenu->insertItem(SmallIcon("help"), KStdGuiItem::help().text(), (new KHelpMenu(this, TDEGlobal::instance()->aboutData(), false))->menu(), false);
popupMenu->insertSeparator();
a = actionCollection()->action(KStdAction::name(KStdAction::Quit));
@@ -167,8 +183,8 @@ void KMixDockWidget::createMasterVolWidget()
* Refreshing the Icon
*
*/
- connect(m_mixer, TQT_SIGNAL(newVolumeLevels()), TQT_TQOBJECT(this), TQT_SLOT(setVolumeTip()));
- connect(m_mixer, TQT_SIGNAL(newVolumeLevels()), TQT_TQOBJECT(this), TQT_SLOT(slotUpdatePixmap()));
+ connect(m_mixer, TQ_SIGNAL(newVolumeLevels()), this, TQ_SLOT(setVolumeTip()));
+ connect(m_mixer, TQ_SIGNAL(newVolumeLevels()), this, TQ_SLOT(slotUpdatePixmap()));
}
void KMixDockWidget::deleteMasterVolWidget()
@@ -180,8 +196,8 @@ void KMixDockWidget::deleteMasterVolWidget()
}
if (m_mixer)
{
- disconnect(m_mixer, TQT_SIGNAL(newVolumeLevels()), TQT_TQOBJECT(this), TQT_SLOT(setVolumeTip()));
- disconnect(m_mixer, TQT_SIGNAL(newVolumeLevels()), TQT_TQOBJECT(this), TQT_SLOT(slotUpdatePixmap()));
+ disconnect(m_mixer, TQ_SIGNAL(newVolumeLevels()), this, TQ_SLOT(setVolumeTip()));
+ disconnect(m_mixer, TQ_SIGNAL(newVolumeLevels()), this, TQ_SLOT(slotUpdatePixmap()));
}
}
@@ -195,7 +211,7 @@ void KMixDockWidget::selectMaster()
if (!_dsm)
{
_dsm = new DialogSelectMaster(m_mixer);
- connect(_dsm, TQT_SIGNAL(newMasterSelected(bool, int, const TQString&)), TQT_SLOT( handleNewMaster(bool, int, const TQString&)));
+ connect(_dsm, TQ_SIGNAL(newMasterSelected(bool, int, const TQString&)), TQ_SLOT( handleNewMaster(bool, int, const TQString&)));
}
_dsm->show(m_mixer);
}
@@ -243,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()
{
@@ -250,6 +280,7 @@ KMixDockWidget::setVolumeTip()
if ( _dockAreaPopup != 0 ) {
md = _dockAreaPopup->dockDevice();
}
+
TQString tip = "";
int newToolTipValue = 0;
@@ -260,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 );
@@ -305,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)) {
@@ -314,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());
}
@@ -330,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);
@@ -349,7 +439,7 @@ KMixDockWidget::mousePressEvent(TQMouseEvent *me)
// esken: Due to overwhelming request, LeftButton shows the ViewDockAreaPopup, if configured
// to do so. Otherwise the main window will be shown.
- if ( me->button() == Qt::LeftButton )
+ if ( me->button() == TQt::LeftButton )
{
if ( ! _volumePopup ) {
// Case 1: User wants to show main window => This is the KSystemTray default action
@@ -393,7 +483,7 @@ KMixDockWidget::mousePressEvent(TQMouseEvent *me)
TQWidget::mousePressEvent(me); // KSystemTray's shouldn't do the default action for this
return;
} // LeftMouseButton pressed
- else if ( me->button() == Qt::MidButton ) {
+ else if ( me->button() == TQt::MidButton ) {
if ( ! _dockIconMuting ) {
toggleActive();
} else {
@@ -443,7 +533,7 @@ KMixDockWidget::wheelEvent(TQWheelEvent *e)
// Mhhh, it doesn't work. TQt does not show it again.
setVolumeTip();
// Simulate a mouse move to make TQt show the tooltip again
- TQApplication::postEvent( this, new TQMouseEvent( TQEvent::MouseMove, TQCursor::pos(), Qt::NoButton, Qt::NoButton ) );
+ TQApplication::postEvent( this, new TQMouseEvent( TQEvent::MouseMove, TQCursor::pos(), TQt::NoButton, TQt::NoButton ) );
}
}