~ubuntu-branches/ubuntu/natty/kdemultimedia/natty-proposed

« back to all changes in this revision

Viewing changes to kmix/gui/kmixerwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Debian Qt/KDE Maintainers
  • Date: 2011-05-26 02:41:36 UTC
  • mfrom: (0.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 108.
  • Revision ID: james.westby@ubuntu.com-20110526024136-jjwsigfy402jhupm
Tags: upstream-4.6.3
ImportĀ upstreamĀ versionĀ 4.6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * KMix -- KDE's full featured mini mixer
 
3
 *
 
4
 * Copyright (C) 2004 Christian Esken <esken@kde.org>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Library General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Library General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Library General Public
 
17
 * License along with this program; if not, write to the Free
 
18
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
 */
 
20
 
 
21
 
 
22
// Qt
 
23
#include <QLabel>
 
24
#include <qpixmap.h>
 
25
#include <qslider.h>
 
26
#include <QString>
 
27
#include <qtoolbutton.h>
 
28
#include <qapplication.h> // for QApplication::revsreseLayout()
 
29
#include <QVBoxLayout>
 
30
 
 
31
// KDE
 
32
#include <kconfig.h>
 
33
#include <kconfiggroup.h>
 
34
#include <kdebug.h>
 
35
#include <kglobal.h>
 
36
#include <kicon.h>
 
37
#include <klocale.h>
 
38
#include <ktabwidget.h>
 
39
 
 
40
// KMix
 
41
#include "gui/guiprofile.h"
 
42
#include "gui/kmixerwidget.h"
 
43
#include "gui/kmixtoolbox.h"
 
44
#include "gui/mixdevicewidget.h"
 
45
#include "core/mixer.h"
 
46
#include "core/mixertoolbox.h"
 
47
#include "viewsliders.h"
 
48
 
 
49
 
 
50
/**
 
51
   This widget is embedded in the KMix Main window. Each Hardware Card is visualized by one KMixerWidget.
 
52
   KMixerWidget contains
 
53
   (a)  A TabBar with n Tabs (at least one per soundcard). These contain View's with sliders, switches and other GUI elements visualizing the Mixer)
 
54
   (b) A balancing slider : This will be moved to ViewSliders.
 
55
*/
 
56
KMixerWidget::KMixerWidget( Mixer *mixer,
 
57
                            QWidget * parent, ViewBase::ViewFlags vflags, GUIProfile* guiprof,
 
58
                            KActionCollection* actionCollection )
 
59
   : QWidget( parent ), _mixer(mixer), m_balanceSlider(0),
 
60
     m_topLayout(0), _guiprof(guiprof),
 
61
     //_tab(tab), 
 
62
     _actionCollection(actionCollection)
 
63
{
 
64
   if ( _mixer )
 
65
   {
 
66
      createLayout(vflags);
 
67
   }
 
68
   else
 
69
   {
 
70
      // No mixer found
 
71
      // This is normally never shown. Only if the application
 
72
      // creates an invalid KMixerWidget (but this would actually be
 
73
      // a programming error).
 
74
      QBoxLayout *layout = new QHBoxLayout( this );
 
75
      QString s = i18n("Invalid mixer");
 
76
      QLabel *errorLabel = new QLabel( s, this );
 
77
      errorLabel->setAlignment( Qt::AlignCenter );
 
78
      errorLabel->setWordWrap( true );
 
79
      layout->addWidget( errorLabel );
 
80
   }
 
81
}
 
82
 
 
83
KMixerWidget::~KMixerWidget()
 
84
{
 
85
}
 
86
 
 
87
/**
 
88
 * Creates the widgets as described in the KMixerWidget constructor
 
89
 */
 
90
void KMixerWidget::createLayout(ViewBase::ViewFlags vflags)
 
91
{
 
92
   // delete old objects
 
93
   if( m_balanceSlider ) {
 
94
      delete m_balanceSlider;
 
95
      m_balanceSlider = 0;
 
96
   }
 
97
   if( m_topLayout ) {
 
98
      delete m_topLayout;
 
99
   }
 
100
 
 
101
   // create main layout
 
102
   m_topLayout = new QVBoxLayout( this );
 
103
   m_topLayout->setSpacing( 3 );
 
104
   m_topLayout->setObjectName( QLatin1String( "m_topLayout" ) );
 
105
 
 
106
   /*******************************************************************
 
107
   *  Now the main GUI is created.
 
108
   * 1) Select a (GUI) profile,  which defines  which controls to show on which Tab
 
109
   * 2a) Create the Tab's and the corresponding Views
 
110
   * 2b) Create device widgets
 
111
   * 2c) Add Views to Tab
 
112
   ********************************************************************/
 
113
   createViewsByProfile(_mixer, _guiprof, vflags);
 
114
   show();
 
115
   //    kDebug(67100) << "KMixerWidget::createLayout(): EXIT\n";
 
116
}
 
117
 
 
118
 
 
119
/**
 
120
* Creates the View based on the GUIProfile, for the Tab tabId
 
121
 */
 
122
void KMixerWidget::createViewsByProfile(Mixer* mixer, GUIProfile *guiprof, ViewBase::ViewFlags vflags)
 
123
{
 
124
    ViewSliders* view = new ViewSliders( this, "", mixer, vflags, guiprof, _actionCollection );
 
125
    possiblyAddView(view);
 
126
 
 
127
#if 0
 
128
   /*** How it works:
 
129
   * A loop is done over all tabs.
 
130
   * For each Tab a View (e.g. ViewSliders) is instanciated and added to the list of Views
 
131
   */
 
132
   QList<ProfTab*>::const_iterator itEnd = guiprof->tabs().end();
 
133
   for ( QList<ProfTab*>::const_iterator it = guiprof->tabs().begin(); it != itEnd; ++it) {
 
134
       ProfTab* profTab = *it;
 
135
       if ( profTab->type() == "Sliders" ) {
 
136
           if ( profTab->name() == 0 || profTab->name().isNull() )
 
137
            {
 
138
                kError() << "TAB NAME IS NULL";
 
139
                profTab->name() = "Undefined";
 
140
            }
 
141
            kDebug() << ">>> TAB NAME = " << profTab->name();
 
142
           QByteArray qba = profTab->name().toAscii();
 
143
            ViewSliders* view = new ViewSliders( this, qba, mixer, vflags, guiprof, _actionCollection );
 
144
            possiblyAddView(view);
 
145
            break;
 
146
        }
 
147
        else {
 
148
            kDebug(67100) << "KMixerWidget::createViewsByProfile(): Unknown Tab type '" << profTab->type() << "'\n";
 
149
        }
 
150
    } // search for correct tab
 
151
#endif
 
152
}
 
153
 
 
154
 
 
155
bool KMixerWidget::possiblyAddView(ViewBase* vbase)
 
156
{
 
157
   if ( ! vbase->isValid()  ) {
 
158
      delete vbase;
 
159
      return false;
 
160
   }
 
161
   else {
 
162
      vbase->createDeviceWidgets();
 
163
      m_topLayout->addWidget(vbase);
 
164
      _views.push_back(vbase);
 
165
      connect( vbase, SIGNAL(toggleMenuBar()), parentWidget(), SLOT(toggleMenuBar()) );
 
166
      // *this will be deleted on rebuildGUI(), so lets queue the signal
 
167
      connect( vbase, SIGNAL(rebuildGUI())   , parentWidget(), SLOT(recreateGUIwithSavingView()), Qt::QueuedConnection );
 
168
      connect( vbase, SIGNAL(redrawMixer(const QString&)), parentWidget(), SLOT(redrawMixer(const QString&)), Qt::QueuedConnection );
 
169
      return true;
 
170
   }
 
171
}
 
172
 
 
173
 
 
174
 
 
175
/**
 
176
 * Returns the current View. Normally we have only one View, so we always return the first view.
 
177
 * This method is only here for one reason: We can plug in an action in the main menu, so that
 
178
 * 99% of all users will be well served. Those who hack their own XML Profile to contain more than one view
 
179
  must  use the context menu for configuring the additional views.
 
180
 */
 
181
ViewBase* KMixerWidget::currentView()
 
182
{
 
183
    ViewBase* view = 0;
 
184
    if ( _views.size() > 0 ) {
 
185
        view = _views[0];
 
186
    }
 
187
    return view;
 
188
}
 
189
 
 
190
 
 
191
void KMixerWidget::setIcons( bool on )
 
192
{
 
193
const std::vector<ViewBase*>::const_iterator viewsEnd = _views.end();
 
194
    for ( std::vector<ViewBase*>::const_iterator it = _views.begin(); it != viewsEnd; ++it) {
 
195
        ViewBase* mixerWidget = *it;
 
196
        mixerWidget->setIcons(on);
 
197
    } // for all tabs
 
198
}
 
199
 
 
200
void KMixerWidget::setLabels( bool on )
 
201
{
 
202
    const std::vector<ViewBase*>::const_iterator viewsEnd = _views.end();
 
203
    for ( std::vector<ViewBase*>::const_iterator it = _views.begin(); it != viewsEnd; ++it) {
 
204
        ViewBase* mixerWidget = *it;
 
205
        mixerWidget->setLabels(on);
 
206
    } // for all tabs
 
207
//    }
 
208
}
 
209
 
 
210
void KMixerWidget::setTicks( bool on )
 
211
{
 
212
    const std::vector<ViewBase*>::const_iterator viewsEnd = _views.end();
 
213
    for ( std::vector<ViewBase*>::const_iterator it = _views.begin(); it != viewsEnd; ++it) {
 
214
        ViewBase* mixerWidget = *it;
 
215
        mixerWidget->setTicks(on);
 
216
    } // for all tabs
 
217
}
 
218
 
 
219
 
 
220
/**
 
221
 */
 
222
void KMixerWidget::loadConfig( KConfig *config )
 
223
{
 
224
   kDebug(67100) << "KMixerWidget::loadConfig()";
 
225
    const std::vector<ViewBase*>::const_iterator viewsEnd = _views.end();
 
226
    for ( std::vector<ViewBase*>::const_iterator it = _views.begin(); it != viewsEnd; ++it) {
 
227
        ViewBase* view = *it;
 
228
        kDebug(67100) << "KMixerWidget::loadConfig()" << view->id();
 
229
        view->load(config);
 
230
        view->configurationUpdate();
 
231
    } // for all tabs
 
232
}
 
233
 
 
234
 
 
235
 
 
236
void KMixerWidget::saveConfig( KConfig *config )
 
237
{
 
238
   kDebug(67100) << "KMixerWidget::saveConfig()";
 
239
    const std::vector<ViewBase*>::const_iterator viewsEnd = _views.end();
 
240
    for ( std::vector<ViewBase*>::const_iterator it = _views.begin(); it != viewsEnd; ++it) {
 
241
        ViewBase* view = *it;
 
242
        kDebug(67100) << "KMixerWidget::saveConfig()" << view->id();
 
243
        view->save(config);
 
244
    } // for all tabs
 
245
}
 
246
 
 
247
 
 
248
void KMixerWidget::toggleMenuBarSlot() {
 
249
    emit toggleMenuBar();
 
250
}
 
251
 
 
252
// in RTL mode, the slider is reversed, we cannot just connect the signal to setBalance()
 
253
// hack around it before calling _mixer->setBalance()
 
254
void KMixerWidget::balanceChanged(int balance)
 
255
{
 
256
    if (QApplication::isRightToLeft())
 
257
        balance = -balance;
 
258
 
 
259
    _mixer->setBalance( balance );
 
260
}
 
261
 
 
262
#include "kmixerwidget.moc"