Final polisihing for KDE4:
[kdemultimedia.git] / kmix / dialogviewconfiguration.cpp
blob412cbf07600daaee4b95b2f806a468087ada58a3
1 /*
2 * KMix -- KDE's full featured mini mixer
5 * Copyright (C) 1996-2004 Christian Esken <esken@kde.org>
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include <QCheckBox>
23 #include <QLabel>
24 #include <QScrollArea>
25 #include <QVBoxLayout>
26 #include <QGridLayout>
28 #include <kdebug.h>
29 #include <kdialog.h>
30 #include <klocale.h>
31 #include <kvbox.h>
33 #include "dialogviewconfiguration.h"
34 #include "mixdevicewidget.h"
35 #include "mixdevice.h"
38 DialogViewConfiguration::DialogViewConfiguration( QWidget*, ViewBase& view)
39 : KDialog( 0),
40 _view(view)
42 setCaption( i18n( "Configure" ) );
43 setButtons( Ok|Cancel );
44 setDefaultButton( Ok );
45 QList<QWidget *> &mdws = view._mdws;
46 QWidget * frame = new QWidget( this );
47 frame->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding);
49 setMainWidget( frame );
51 // The _layout will hold two items: The title and the scrollarea
52 _layout = new QVBoxLayout(frame );
54 // --- HEADER ---
55 // kDebug(67100) << "DialogViewConfiguration::DialogViewConfiguration add header" << "\n";
56 qlb = new QLabel( i18n("Configuration of the channels."), frame );
57 _layout->addWidget(qlb);
59 QScrollArea* scrollArea = new QScrollArea(frame);
60 scrollArea->setWidgetResizable(true); // avoid unnecesary scrollbars
61 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
62 _layout->addSpacing(KDialog::spacingHint());
63 _layout->addWidget(scrollArea);
65 vboxForScrollView = new QWidget();
66 vboxForScrollView->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
67 QGridLayout* grid = new QGridLayout(vboxForScrollView);
68 grid->setHorizontalSpacing(KDialog::spacingHint());
69 grid->setVerticalSpacing(0);
70 scrollArea->setWidget(vboxForScrollView);
72 qlb = new QLabel( i18n("Show/Hide") );
73 grid->addWidget(qlb,0,0);
74 qlb = new QLabel( i18n("Split"), vboxForScrollView );
75 grid->addWidget(qlb,0,1);
77 qlb = new QLabel( i18n("Limit"), vboxForScrollView );
78 grid->addWidget(qlb,0,2);
80 int i;
81 // --- CONTROLS IN THE GRID ---
82 QPalette::ColorRole bgRole;
83 for ( i=0; i<mdws.count(); ++i ) {
84 if ( i%2 == 0) bgRole = QPalette::Base; else bgRole = QPalette::AlternateBase;
85 QWidget *qw = mdws[i];
86 if ( qw->inherits("MixDeviceWidget") ) {
87 MixDeviceWidget *mdw = static_cast<MixDeviceWidget*>(qw);
88 MixDevice *md = mdw->mixDevice();
89 QString mdName = md->readableName();
90 mdName.replace('&', "&&"); // Quoting the '&' needed, to prevent QCheckBox creating an accelerator
91 QCheckBox* cb = new QCheckBox( mdName, vboxForScrollView ); // enable/disable
92 cb->setBackgroundRole(bgRole);
93 cb->setAutoFillBackground(true);
94 _qEnabledCB.append(cb);
95 cb->setChecked( mdw->isVisible() );
96 grid->addWidget(cb,1+i,0);
98 if ( ! md->isEnum() && ( ( md->playbackVolume().count() > 1) || ( md->captureVolume().count() > 1) ) ) {
99 cb = new QCheckBox( "", vboxForScrollView ); // split
100 cb->setBackgroundRole(bgRole);
101 cb->setAutoFillBackground(true);
102 _qSplitCB.append(cb);
103 cb->setChecked( ! mdw->isStereoLinked() );
104 grid->addWidget(cb,1+i,1);
106 else {
107 _qSplitCB.append(0);
110 if ( ! md->isEnum() && ( md->playbackVolume().count() + md->captureVolume().count() >0 ) ) {
111 cb = new QCheckBox( "", vboxForScrollView ); // limit
112 cb->setBackgroundRole(bgRole);
113 cb->setAutoFillBackground(true);
114 _qLimitCB.append(cb);
115 grid->addWidget(cb,1+i,2);
117 else {
119 _qLimitCB.append(0);
120 /*}*/
122 } // for all MDW's
124 scrollArea->updateGeometry();
125 updateGeometry();
126 connect( this, SIGNAL(okClicked()) , this, SLOT(apply()) );
129 DialogViewConfiguration::~DialogViewConfiguration()
133 void DialogViewConfiguration::apply()
135 QList<QWidget *> &mdws = _view._mdws;
137 // --- 2-Step Apply ---
139 // --- Step 1: Show and Hide Widgets ---
140 for ( int i=0; i<mdws.count(); ++i ) {
141 QWidget *qw = mdws[i];
142 MixDeviceWidget *mdw;
144 if ( qw->inherits("MixDeviceWidget") ) {
145 mdw = static_cast<MixDeviceWidget*>(qw);
147 else {
148 continue;
151 QCheckBox *cb = _qEnabledCB[i];
152 if ( cb != 0 ) {
153 mdw->setVisible( cb->isChecked());
154 } // show-hide
156 cb = _qSplitCB[i];
157 if ( cb != 0 ) {
158 mdw->setStereoLinked( ! cb->isChecked() );
159 } // split
161 } // for all MDW's
163 // --- Step 2: Tell the view, that it has changed (probably it needs some "polishing" ---
164 _view.configurationUpdate();
168 QSize DialogViewConfiguration::sizeHint() const {
169 QSize size = vboxForScrollView->sizeHint();
170 // The +50 is a workaround, because KDialog does not handle our case correctly (using a QScrollarea)
171 size.rwidth() += 50;
172 size.rheight() += KDialog::spacingHint();
173 size.rheight() += qlb->height();
174 return size;
177 #include "dialogviewconfiguration.moc"