2
* KMix -- KDE's full featured mini mixer
4
* Copyright (C) 2004 Christian Esken <esken@kde.org>
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.
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.
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.
27
#include <qtoolbutton.h>
28
#include <qapplication.h> // for QApplication::revsreseLayout()
29
#include <QVBoxLayout>
33
#include <kconfiggroup.h>
38
#include <ktabwidget.h>
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"
51
This widget is embedded in the KMix Main window. Each Hardware Card is visualized by one KMixerWidget.
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.
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),
62
_actionCollection(actionCollection)
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 );
83
KMixerWidget::~KMixerWidget()
88
* Creates the widgets as described in the KMixerWidget constructor
90
void KMixerWidget::createLayout(ViewBase::ViewFlags vflags)
93
if( m_balanceSlider ) {
94
delete m_balanceSlider;
101
// create main layout
102
m_topLayout = new QVBoxLayout( this );
103
m_topLayout->setSpacing( 3 );
104
m_topLayout->setObjectName( QLatin1String( "m_topLayout" ) );
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);
115
// kDebug(67100) << "KMixerWidget::createLayout(): EXIT\n";
120
* Creates the View based on the GUIProfile, for the Tab tabId
122
void KMixerWidget::createViewsByProfile(Mixer* mixer, GUIProfile *guiprof, ViewBase::ViewFlags vflags)
124
ViewSliders* view = new ViewSliders( this, "", mixer, vflags, guiprof, _actionCollection );
125
possiblyAddView(view);
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
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() )
138
kError() << "TAB NAME IS NULL";
139
profTab->name() = "Undefined";
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);
148
kDebug(67100) << "KMixerWidget::createViewsByProfile(): Unknown Tab type '" << profTab->type() << "'\n";
150
} // search for correct tab
155
bool KMixerWidget::possiblyAddView(ViewBase* vbase)
157
if ( ! vbase->isValid() ) {
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 );
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.
181
ViewBase* KMixerWidget::currentView()
184
if ( _views.size() > 0 ) {
191
void KMixerWidget::setIcons( bool on )
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);
200
void KMixerWidget::setLabels( bool on )
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);
210
void KMixerWidget::setTicks( bool on )
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);
222
void KMixerWidget::loadConfig( KConfig *config )
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();
230
view->configurationUpdate();
236
void KMixerWidget::saveConfig( KConfig *config )
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();
248
void KMixerWidget::toggleMenuBarSlot() {
249
emit toggleMenuBar();
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)
256
if (QApplication::isRightToLeft())
259
_mixer->setBalance( balance );
262
#include "kmixerwidget.moc"