summaryrefslogtreecommitdiffstats
path: root/plugins/alsa-sound/alsa-mixer-element.cpp
blob: 12a48f2b15956b301728af2a27ac10cf97b22853 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/***************************************************************************
                          alsa-mixer-element.cpp  -  description
                             -------------------
    begin                : Mon Aug 15 2005
    copyright            : (C) 2005 by Martin Witte
    email                : witte@kawo1.rwth-aachen.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "alsa-mixer-element.h"

#include <knuminput.h>
#include <tqslider.h>
#include <tqlabel.h>
#include <tqcheckbox.h>

#include <math.h>

QAlsaMixerElement::QAlsaMixerElement(TQWidget *parent, const TQString &label, bool has_switch, bool has_volume)
    : AlsaMixerElementUI(parent),
      m_HasVolume(has_volume),
      m_HasSwitch(has_switch),
      m_dirty(false),
      m_ignore_updates(false)
{
    setLabel(label);
    setVolume(0);

    TQObject::connect(m_spinboxVolume, TQ_SIGNAL(valueChanged(int)),
                     this,            TQ_SLOT  (slotSpinboxValueChanged(int)));
    TQObject::connect(m_sliderVolume,  TQ_SIGNAL(valueChanged(int)),
                     this,            TQ_SLOT  (slotSliderValueChanged(int)));

    if (m_HasVolume) {
        TQObject::connect(m_checkboxOverride, TQ_SIGNAL(toggled(bool)),
                         m_spinboxVolume,    TQ_SLOT  (setEnabled(bool)));
        TQObject::connect(m_checkboxOverride, TQ_SIGNAL(toggled(bool)),
                         m_sliderVolume,     TQ_SLOT  (setEnabled(bool)));
    } else {
        m_spinboxVolume->hide();
        m_sliderVolume->hide();
    }
    if (m_HasSwitch) {
        TQObject::connect(m_checkboxOverride, TQ_SIGNAL(toggled(bool)),
                         m_checkboxActive,   TQ_SLOT  (setEnabled(bool)));
    } else {
        //m_checkboxActive->hide();
        m_checkboxActive->setEnabled(false);
        m_checkboxActive->setChecked(true);
    }

    connect(m_checkboxOverride, TQ_SIGNAL(toggled(bool)),     this, TQ_SLOT(slotSetDirty()));
    connect(m_checkboxActive,   TQ_SIGNAL(toggled(bool)),     this, TQ_SLOT(slotSetDirty()));
    connect(m_spinboxVolume,    TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(slotSetDirty()));
    connect(m_sliderVolume,     TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(slotSetDirty()));
}


QAlsaMixerElement::~QAlsaMixerElement()
{
}

float QAlsaMixerElement::getVolume() const
{
    return ((float)m_spinboxVolume->value())/100.0;
}

bool  QAlsaMixerElement::getActive() const
{
    return m_checkboxActive->isChecked();
}

bool  QAlsaMixerElement::getOverride() const
{
    return m_checkboxOverride->isChecked();
}

void QAlsaMixerElement::setLabel(const TQString &label)
{
    m_labelMixerElementName->setText(label);
}

void QAlsaMixerElement::setOverride(bool ov)
{
    m_ignore_updates = true;
    m_checkboxOverride->setChecked(ov);
    m_ignore_updates = false;
}

void QAlsaMixerElement::setActive(bool active)
{
    m_ignore_updates = true;
    m_checkboxActive->setChecked(active);
    m_ignore_updates = false;
}

void QAlsaMixerElement::setVolume(float vol)
{
    m_ignore_updates = true;
    int v = (int)rint(vol*100 + 0.5);
    m_sliderVolume->setValue(100 - v);
    m_spinboxVolume->setValue(v);
    m_ignore_updates = false;
}

void QAlsaMixerElement::slotSpinboxValueChanged(int v)
{
    m_sliderVolume->setValue(100-v);
}

void QAlsaMixerElement::slotSliderValueChanged(int v)
{
    m_spinboxVolume->setValue(100-v);
}


void QAlsaMixerElement::slotSetDirty()
{
    if (!m_dirty && !m_ignore_updates) {
        m_dirty = true;
        emit sigDirty();
    }
}


void QAlsaMixerElement::slotResetDirty()
{
    m_dirty = false;
}

#include "alsa-mixer-element.moc"