~ubuntu-branches/ubuntu/breezy/kdemultimedia/breezy

« back to all changes in this revision

Viewing changes to kmix/viewsurround.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-03-24 04:48:58 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050324044858-8ff88o9jxej6ii3d
Tags: 4:3.4.0-0ubuntu3
Add kubuntu_02_hide_arts_menu_entries.diff to hide artsbuilder and artscontrol k-menu entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * KMix -- KDE's full featured mini mixer
 
3
 *
 
4
 *
 
5
 * Copyright (C) 1996-2004 Christian Esken <esken@kde.org>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Library General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2 of the License, or (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Library General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Library General Public
 
18
 * License along with this program; if not, write to the Free
 
19
 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
20
 */
 
21
 
 
22
#include "viewsurround.h"
 
23
 
 
24
// Qt
 
25
#include <qlabel.h>
 
26
#include <qlayout.h>
 
27
#include <qwidget.h>
 
28
 
 
29
// KDE
 
30
#include <kdebug.h>
 
31
#include <kiconloader.h>
 
32
 
 
33
// KMix
 
34
#include "kmixtoolbox.h"
 
35
#include "mdwslider.h"
 
36
#include "mixer.h"
 
37
 
 
38
/**
 
39
 * Demonstration verion of a "surround view"
 
40
 * Not really usable right now.
 
41
 */
 
42
ViewSurround::ViewSurround(QWidget* parent, const char* name, Mixer* mixer, ViewBase::ViewFlags vflags)
 
43
      : ViewBase(parent, name, mixer, WStyle_Customize|WStyle_NoBorder, vflags)
 
44
{
 
45
    _mdSurroundFront = 0;
 
46
    _mdSurroundBack  = 0;
 
47
    _layoutMDW = new QHBoxLayout(this);
 
48
    _layoutMDW->setMargin(8);
 
49
    // Create switch buttonGroup
 
50
    if ( _vflags & ViewBase::Vertical ) {
 
51
        _layoutSliders = new QVBoxLayout(_layoutMDW);
 
52
    }
 
53
    else {
 
54
        _layoutSliders = new QHBoxLayout(_layoutMDW);
 
55
    }
 
56
    _layoutSurround = new QGridLayout(_layoutMDW,3,5);
 
57
    //    _layoutMDW->setMargin(8);
 
58
    init();
 
59
}
 
60
 
 
61
ViewSurround::~ViewSurround() {
 
62
}
 
63
 
 
64
void ViewSurround::setMixSet(MixSet *mixset)
 
65
{
 
66
    MixDevice* md;
 
67
    for ( md = mixset->first(); md != 0; md = mixset->next() ) {
 
68
        if ( ! md->isSwitch() ) {
 
69
            switch ( md->type() ) {
 
70
            case MixDevice::VOLUME:
 
71
            case MixDevice::SURROUND:
 
72
            case MixDevice::SURROUND_BACK:
 
73
            case MixDevice::SURROUND_LFE:
 
74
            case MixDevice::SURROUND_CENTERFRONT:
 
75
            case MixDevice::SURROUND_CENTERBACK:
 
76
            case MixDevice::AC97:
 
77
                _mixSet->append(md);
 
78
                break;
 
79
            default:
 
80
                // we are not interested in other channels
 
81
                break;
 
82
            } // switch(type)
 
83
        } // !is_switch()
 
84
    } // for
 
85
}
 
86
 
 
87
int ViewSurround::count()
 
88
{
 
89
    return ( _mixSet->count() );        
 
90
}
 
91
 
 
92
int ViewSurround::advice() {
 
93
    if (  _mixSet->count() > 0 ) {
 
94
        // The standard input and output views are always advised, if there are devices in it
 
95
        return 100;
 
96
    }
 
97
    else {
 
98
        return 0;
 
99
    }
 
100
}
 
101
 
 
102
QWidget* ViewSurround::add(MixDevice *md)
 
103
{
 
104
    bool small = false;
 
105
    Qt::Orientation orientation = Qt::Vertical;
 
106
    switch ( md->type() ) {
 
107
    case MixDevice::VOLUME:
 
108
        _mdSurroundFront = md;
 
109
        small = true;
 
110
        break;  
 
111
    case MixDevice::SURROUND_BACK:
 
112
        _mdSurroundBack = md;
 
113
        small = true;
 
114
        break;
 
115
    case MixDevice::SURROUND_LFE:
 
116
        orientation = Qt::Horizontal;
 
117
        small = true;
 
118
        break;
 
119
    case MixDevice::SURROUND_CENTERFRONT:
 
120
        orientation = Qt::Horizontal;
 
121
        small = true;
 
122
        break;
 
123
    case MixDevice::SURROUND_CENTERBACK:
 
124
        orientation = Qt::Horizontal;
 
125
        small = true;
 
126
        break;
 
127
        
 
128
    default:
 
129
        small       = false;
 
130
        // these are the sliders on the left side of the surround View
 
131
        orientation = (_vflags & ViewBase::Vertical) ? Qt::Horizontal : Qt::Vertical;
 
132
    } // switch(type)
 
133
 
 
134
    MixDeviceWidget *mdw = createMDW(md, small, orientation);
 
135
 
 
136
    switch ( md->type() ) {
 
137
    case MixDevice::VOLUME:
 
138
        _layoutSurround->addWidget(mdw ,0,0, Qt::AlignBottom | Qt::AlignLeft);
 
139
        break;
 
140
        
 
141
    case MixDevice::SURROUND_BACK:
 
142
        _layoutSurround->addWidget(mdw ,2,0, Qt::AlignTop | Qt::AlignLeft);
 
143
        break;
 
144
    case MixDevice::SURROUND_LFE:
 
145
        _layoutSurround->addWidget(mdw,1,3,  Qt::AlignVCenter | Qt::AlignRight ); break;
 
146
        break;
 
147
    case MixDevice::SURROUND_CENTERFRONT:
 
148
        _layoutSurround->addWidget(mdw,0,2,  Qt::AlignTop | Qt::AlignHCenter); break;
 
149
        break;
 
150
    case MixDevice::SURROUND_CENTERBACK:
 
151
        _layoutSurround->addWidget(mdw,2,2,  Qt::AlignBottom | Qt::AlignHCenter); break;
 
152
        break;
 
153
 
 
154
    case MixDevice::SURROUND:
 
155
    case MixDevice::AC97:
 
156
    default:
 
157
        // Add as slider to the layout on the left side
 
158
        _layoutSliders->add(mdw);
 
159
        break;
 
160
    } // switch(type)
 
161
 
 
162
    return mdw;
 
163
}
 
164
 
 
165
QSize ViewSurround::sizeHint() const {
 
166
    //    kdDebug(67100) << "ViewSurround::sizeHint(): NewSize is " << _layoutMDW->sizeHint() << "\n";
 
167
    return( _layoutMDW->sizeHint() );
 
168
}
 
169
 
 
170
void ViewSurround::constructionFinished() {
 
171
    QLabel* personLabel = new QLabel("Listener", this);
 
172
    QPixmap icon = UserIcon( "Listener" );
 
173
    if ( ! icon.isNull()) personLabel->setPixmap(icon);
 
174
    personLabel->setLineWidth( 4 );
 
175
    personLabel->setMidLineWidth( 3 );
 
176
    personLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken );
 
177
    int rowOfSpeaker = 0;
 
178
    if ( _mdSurroundBack != 0 ) {
 
179
       // let the speaker "sit" in the rear of the room, if there is
 
180
       // rear speaker support in this sound card
 
181
       rowOfSpeaker = 1;
 
182
    }
 
183
    _layoutSurround->addWidget(personLabel ,rowOfSpeaker, 2, Qt::AlignHCenter | Qt::AlignVCenter);
 
184
 
 
185
    if ( _mdSurroundFront != 0 ) {
 
186
        MixDeviceWidget *mdw = createMDW(_mdSurroundFront, true, Qt::Vertical);
 
187
        _layoutSurround->addWidget(mdw,0,4, Qt::AlignBottom | Qt::AlignRight);
 
188
        _mdws.append(mdw);
 
189
 
 
190
        QLabel* speakerIcon = new QLabel("Speaker", this);
 
191
        icon = UserIcon( "SpeakerFrontLeft" );
 
192
        if ( ! icon.isNull()) speakerIcon->setPixmap(icon);
 
193
        _layoutSurround->addWidget(speakerIcon,0,1, Qt::AlignTop | Qt::AlignLeft);
 
194
 
 
195
        speakerIcon = new QLabel("Speaker", this);
 
196
        icon = UserIcon( "SpeakerFrontRight" );
 
197
        if ( ! icon.isNull()) speakerIcon->setPixmap(icon);
 
198
        _layoutSurround->addWidget(speakerIcon,0,3, Qt::AlignTop | Qt::AlignRight);
 
199
 
 
200
    }
 
201
 
 
202
    if ( _mdSurroundBack != 0 ) {
 
203
        MixDeviceWidget *mdw = createMDW(_mdSurroundBack, true, Qt::Vertical);
 
204
        _layoutSurround->addWidget(mdw,2,4, Qt::AlignTop | Qt::AlignRight);
 
205
        _mdws.append(mdw);
 
206
 
 
207
        QLabel* speakerIcon = new QLabel("Speaker", this);
 
208
        icon = UserIcon( "SpeakerRearLeft" );
 
209
        if ( ! icon.isNull()) speakerIcon->setPixmap(icon);
 
210
        _layoutSurround->addWidget(speakerIcon,2,1, Qt::AlignBottom | Qt::AlignLeft);
 
211
 
 
212
        speakerIcon = new QLabel("Speaker", this);
 
213
        icon = UserIcon( "SpeakerRearRight" );
 
214
        if ( ! icon.isNull()) speakerIcon->setPixmap(icon);
 
215
        _layoutSurround->addWidget(speakerIcon,2,3, Qt::AlignBottom | Qt::AlignRight);
 
216
 
 
217
 
 
218
    }
 
219
 
 
220
    // !! just for the demo version
 
221
    KMixToolBox::setIcons (_mdws, true);
 
222
    KMixToolBox::setLabels(_mdws, true);
 
223
    KMixToolBox::setTicks (_mdws, true);
 
224
 
 
225
    _layoutMDW->activate();
 
226
}
 
227
 
 
228
void ViewSurround::refreshVolumeLevels() {
 
229
    //     kdDebug(67100) << "ViewSurround::refreshVolumeLevels()\n";
 
230
 
 
231
     QWidget *mdw = _mdws.first();
 
232
     MixDevice* md;
 
233
     for ( md = _mixSet->first(); md != 0; md = _mixSet->next() ) {
 
234
         if ( mdw == 0 ) {
 
235
             kdError(67100) << "ViewSurround::refreshVolumeLevels(): mdw == 0\n";
 
236
             break; // sanity check (normally the lists are set up correctly)
 
237
         }
 
238
         else {
 
239
             if ( mdw->inherits("MDWSlider")) {
 
240
                 //kdDebug(67100) << "ViewSurround::refreshVolumeLevels(): updating\n";
 
241
                 // a slider, fine. Lets update its value
 
242
                 static_cast<MDWSlider*>(mdw)->update();
 
243
             }
 
244
             else {
 
245
                 kdError(67100) << "ViewSurround::refreshVolumeLevels(): mdw is not slider\n";
 
246
                 // no slider. Cannot happen in theory => skip it
 
247
             }
 
248
         }
 
249
         mdw = _mdws.next();
 
250
    }
 
251
}
 
252
 
 
253
 
 
254
MixDeviceWidget* ViewSurround::createMDW(MixDevice *md, bool small, Qt::Orientation orientation)
 
255
{
 
256
    MixDeviceWidget* mdw = new MDWSlider(
 
257
                            _mixer,       // the mixer for this device
 
258
                            md,           // MixDevice (parameter)
 
259
                            false,         // Show Mute LED
 
260
                            false,        // Show Record LED
 
261
                            small,        // Small
 
262
                            orientation,  // Orientation
 
263
                            this,         // parent
 
264
                            this,         // View widget
 
265
                            md->name().latin1()
 
266
                            );
 
267
    return mdw;
 
268
}
 
269
 
 
270
#include "viewsurround.moc"