Volume bar does stuff now! It will stay in sync with the volume from your system.
This commit is contained in:
parent
4318215dbb
commit
c4b32b5692
4 changed files with 74 additions and 9 deletions
|
@ -1,3 +1,5 @@
|
|||
#include "XMMSHandler.h"
|
||||
|
||||
#include "VolumeSlider.h"
|
||||
#include <QMouseEvent>
|
||||
|
||||
|
@ -8,6 +10,8 @@
|
|||
|
||||
VolumeSlider::VolumeSlider (QWidget *parent) : PixWidget (parent)
|
||||
{
|
||||
XMMSHandler *xmmsh = XMMSHandler::getInstance ();
|
||||
|
||||
setMinimumSize (68, 13);
|
||||
setMaximumSize (68, 13);
|
||||
m_volume = 0;
|
||||
|
@ -16,6 +20,11 @@ VolumeSlider::VolumeSlider (QWidget *parent) : PixWidget (parent)
|
|||
m_volbtn = NULL;
|
||||
|
||||
m_pixmap = QPixmap (68, 13);
|
||||
|
||||
connect (xmmsh, SIGNAL(getVolume (uint)),
|
||||
this, SLOT(setVolume (uint)));
|
||||
|
||||
xmmsh->volumeGet ();
|
||||
}
|
||||
|
||||
VolumeSlider::~VolumeSlider ()
|
||||
|
@ -164,6 +173,9 @@ VolumeSlider::setVolume (uint volume_base100)
|
|||
if(m_volume > 27)
|
||||
m_volume = 27;
|
||||
|
||||
if(m_hasvolbtn)
|
||||
m_volbtn->setVolume (volume_base100);
|
||||
|
||||
changePixmap ();
|
||||
}
|
||||
|
||||
|
@ -188,9 +200,9 @@ void
|
|||
VolButton::mousePressEvent (QMouseEvent *event)
|
||||
{
|
||||
QPoint p (event->globalPos ());
|
||||
QPoint np = m_volslider->mapFromGlobal(p);
|
||||
QPoint np = m_volslider->mapFromGlobal (p);
|
||||
|
||||
move(np.x() - 7, 1);
|
||||
move (np.x() - 7, 1);
|
||||
|
||||
changePixmap (true);
|
||||
}
|
||||
|
@ -204,7 +216,7 @@ VolButton::mouseReleaseEvent (QMouseEvent *event)
|
|||
void
|
||||
VolButton::mouseMoveEvent (QMouseEvent *event)
|
||||
{
|
||||
QPoint p = m_volslider->mapFromGlobal(event->globalPos ());
|
||||
QPoint p = m_volslider->mapFromGlobal (event->globalPos ());
|
||||
int volume = 0;
|
||||
int curx = p.x ();
|
||||
|
||||
|
@ -212,12 +224,12 @@ VolButton::mouseMoveEvent (QMouseEvent *event)
|
|||
if(curx < 7)
|
||||
{
|
||||
volume = 0;
|
||||
m_volslider->setVolume(0);
|
||||
m_volslider->setVolume (0);
|
||||
}
|
||||
else if(curx > 61)
|
||||
{
|
||||
volume = 54;
|
||||
m_volslider->setVolume(100);
|
||||
m_volslider->setVolume (100);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -225,12 +237,26 @@ VolButton::mouseMoveEvent (QMouseEvent *event)
|
|||
float b100temp = ((float)(((float)curx - 12) / (float)(68.0f - 19)));
|
||||
volume = (int)(68 * temp) - 7;
|
||||
// This is to make sure the volume slider itself reflects our changes.
|
||||
m_volslider->setVolume((int)(100 * b100temp));
|
||||
m_volslider->setVolume ((int)(100 * b100temp));
|
||||
}
|
||||
|
||||
move(volume, 1);
|
||||
move (volume, 1);
|
||||
}
|
||||
|
||||
void
|
||||
VolButton::setVolume (uint volume_base100)
|
||||
{
|
||||
int volume = (int)((float)(volume_base100) *.68);
|
||||
|
||||
if(volume < 0)
|
||||
volume = 0;
|
||||
else if(volume > 54)
|
||||
volume = 54;
|
||||
|
||||
move (volume,1);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VolButton::setPixmaps (Skin *skin)
|
||||
{
|
||||
|
|
|
@ -20,6 +20,7 @@ class VolButton : public PixWidget
|
|||
|
||||
public slots:
|
||||
void setPixmaps (Skin *skin);
|
||||
void setVolume (uint volume_base100);
|
||||
|
||||
private:
|
||||
void changePixmap (bool pressed);
|
||||
|
@ -43,10 +44,10 @@ class VolumeSlider : public PixWidget
|
|||
void mouseReleaseEvent (QMouseEvent *);
|
||||
|
||||
uint getVolume (void) { return m_volume_base100; };
|
||||
void setVolume (uint volume_base100);
|
||||
|
||||
public slots:
|
||||
void setPixmaps (Skin *skin);
|
||||
void setVolume (uint volume_base100);
|
||||
|
||||
private:
|
||||
void drawPixmaps ();
|
||||
|
|
|
@ -63,6 +63,9 @@ XMMSHandler::connect (const char *path)
|
|||
r = m_xmmsc->broadcast_medialib_entry_changed ();
|
||||
r->connect (sigc::mem_fun (this, &XMMSHandler::medialib_entry_changed));
|
||||
|
||||
XMMSResult *xr = m_xmmsc->broadcast_playback_volume_changed ();
|
||||
xr->connect (sigc::mem_fun (this, &XMMSHandler::volume_changed));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -284,6 +287,36 @@ XMMSHandler::medialib_info (XMMSResultDict *res)
|
|||
delete res;
|
||||
}
|
||||
|
||||
void
|
||||
XMMSHandler::volumeGet (void)
|
||||
{
|
||||
XMMSResultDict *p = m_xmmsc->playback_volume_get ();
|
||||
p->connect (sigc::mem_fun (this, &XMMSHandler::volume_get));
|
||||
}
|
||||
|
||||
void
|
||||
XMMSHandler::volume_changed (XMMSResult *res)
|
||||
{
|
||||
volumeGet ();
|
||||
}
|
||||
|
||||
void
|
||||
XMMSHandler::volume_get (XMMSResultDict *res)
|
||||
{
|
||||
QHash<QString, QString> h (DictToQHash (res));
|
||||
QList<QString> Values = h.values();
|
||||
QListIterator<QString> vol (Values);
|
||||
|
||||
uint right = atol (vol.next().toAscii());
|
||||
uint left = atol (vol.next().toAscii());
|
||||
|
||||
if(left > right)
|
||||
emit getVolume (left);
|
||||
else
|
||||
emit getVolume (right);
|
||||
|
||||
}
|
||||
|
||||
XMMSHandler::~XMMSHandler ()
|
||||
{
|
||||
delete m_xmmsc;
|
||||
|
|
|
@ -24,6 +24,8 @@ class XMMSHandler : public QObject, public sigc::trackable {
|
|||
void playlist_list (XMMSResultValueList<uint> *res);
|
||||
void medialib_entry_changed (XMMSResultValue<uint> *res);
|
||||
void medialib_select (XMMSResultDictList *res);
|
||||
void volume_changed (XMMSResult *res);
|
||||
void volume_get (XMMSResultDict *res);
|
||||
|
||||
void requestMediainfo (uint id);
|
||||
void requestPlaylistList (void);
|
||||
|
@ -34,7 +36,9 @@ class XMMSHandler : public QObject, public sigc::trackable {
|
|||
void playlistMove (uint pos, uint newpos) { delete m_xmmsc->playlist_move (pos, newpos); }
|
||||
uint medialibQuery (QString);
|
||||
void medialibQueryAdd (QString q) { delete m_xmmsc->medialib_add_to_playlist (q.toUtf8 ()); }
|
||||
|
||||
void volumeGet (void);
|
||||
|
||||
|
||||
const XMMSClient *getXMMS () { return m_xmmsc; }
|
||||
|
||||
void updateSettings (void) { emit settingsSaved (); }
|
||||
|
@ -65,6 +69,7 @@ class XMMSHandler : public QObject, public sigc::trackable {
|
|||
void currentID (uint);
|
||||
void playlistChanged (const QHash<QString, QString> &);
|
||||
void medialibResponse (uint, const QList<QHash<QString, QString> > &);
|
||||
void getVolume (uint);
|
||||
|
||||
private:
|
||||
XMMSHandler (void);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue