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.
24 #include <QScrollArea>
25 #include <QVBoxLayout>
26 #include <QGridLayout>
33 #include "dialogviewconfiguration.h"
34 #include "mixdevicewidget.h"
35 #include "mixdevice.h"
38 DialogViewConfiguration::DialogViewConfiguration( QWidget
*, ViewBase
& 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
);
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);
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);
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);
124 scrollArea
->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
);
151 QCheckBox
*cb
= _qEnabledCB
[i
];
153 mdw
->setVisible( cb
->isChecked());
158 mdw
->setStereoLinked( ! cb
->isChecked() );
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)
172 size
.rheight() += KDialog::spacingHint();
173 size
.rheight() += qlb
->height();
177 #include "dialogviewconfiguration.moc"