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.
26
#include <QMouseEvent>
32
#include <kiconloader.h>
33
#include <kactioncollection.h>
34
#include <ktoggleaction.h>
35
#include <kstandardaction.h>
37
#include "dialogviewconfiguration.h"
38
#include "guiprofile.h"
39
#include "kmixtoolbox.h"
40
#include "mixdevicewidget.h"
44
ViewBase::ViewBase(QWidget* parent, const char* id, Mixer* mixer, Qt::WFlags f, ViewBase::ViewFlags vflags, GUIProfile *guiprof, KActionCollection *actionColletion)
45
: QWidget(parent, f), _actions(actionColletion), _vflags(vflags), _guiprof(guiprof)
50
_mixSet = new MixSet();
52
if ( _actions == 0 ) {
53
// We create our own action collection, if the actionColletion was 0.
54
// This is currently done for the ViewDockAreaPopup, but only because it has not been converted to use the app-wide
55
// actionCollection(). This is a @todo.
56
_actions = new KActionCollection( this );
58
_localActionColletion = new KActionCollection( this );
60
// Plug in the "showMenubar" action, if the caller wants it. Typically this is only necessary for views in the KMix main window.
61
if ( vflags & ViewBase::HasMenuBar ) {
62
KToggleAction *m = static_cast<KToggleAction*>( _actions->action( name(KStandardAction::ShowMenubar) ) ) ;
64
//static_cast<KToggleAction*>(KStandardAction::showMenubar( this, SLOT(toggleMenuBarSlot()), _actions ));
65
//_actions->addAction( m->objectName(), m );
67
if ( vflags & ViewBase::MenuBarVisible ) {
75
QAction *action = _localActionColletion->addAction("toggle_channels");
76
action->setText(i18n("&Channels"));
77
connect(action, SIGNAL(triggered(bool) ), SLOT(configureView()));
78
connect ( _mixer, SIGNAL(controlChanged()), this, SLOT(refreshVolumeLevels()) );
81
ViewBase::~ViewBase() {
83
// A GUI profile can be shared by different views
84
// Starting with 5/2009 it is shared by the "tabs" of one card.
85
// So we have to make sure to delete it after all users are gone;
86
if ( _guiprof != 0 ) {
87
_guiprof->decreaseRefcount();
88
if ( _guiprof->refcount() == 0 )
95
void ViewBase::configurationUpdate() {
98
QString ViewBase::id() const {
102
bool ViewBase::isValid() const
104
return (_mixSet->count() > 0 );
107
void ViewBase::setIcons (bool on) { KMixToolBox::setIcons (_mdws, on ); }
108
void ViewBase::setLabels(bool on) { KMixToolBox::setLabels(_mdws, on ); }
109
void ViewBase::setTicks (bool on) { KMixToolBox::setTicks (_mdws, on ); }
112
* Create all widgets.
113
* This is a loop over all supported devices of the corresponding view.
114
* On each device add() is called - the derived class must implement add() for creating and placing
115
* the real MixDeviceWidget.
116
* The added MixDeviceWidget is appended to the _mdws list.
118
void ViewBase::createDeviceWidgets()
121
for ( int i=0; i<_mixSet->count(); i++ )
123
MixDevice *mixDevice;
124
mixDevice = (*_mixSet)[i];
125
QWidget* mdw = add(mixDevice);
128
// allow view to "polish" itself
129
constructionFinished();
133
* Rebuild the View from the (existing) Profile.
135
* Hint: this method signature might be extended in the future by a GUIProfile* paramater.
137
void ViewBase::rebuildFromProfile()
141
// Redo everything from scratch, as visibility and the order of the controls might have changed.
143
// As the order of the controls is stored in the profile, we need
144
// to rebuild the _mixSet
145
kDebug() << "rebuild 1";
147
kDebug() << "rebuild 2";
149
kDebug() << "rebuild 3";
151
kDebug() << "rebuild 4";
152
createDeviceWidgets();
153
kDebug() << "rebuild 5";
154
constructionFinished();
155
kDebug() << "rebuild 6";
160
// ---------- Popup stuff START ---------------------
161
void ViewBase::mousePressEvent( QMouseEvent *e )
163
if ( e->button() == Qt::RightButton )
168
* Return a popup menu. This contains basic entries.
169
* More can be added by the caller.
171
KMenu* ViewBase::getPopup()
177
void ViewBase::popupReset()
181
_popMenu = new KMenu( this );
182
_popMenu->addTitle( KIcon( "kmix" ), i18n("Device Settings") );
184
a = _localActionColletion->action( "toggle_channels" );
185
if ( a ) _popMenu->addAction(a);
187
QAction *b = _actions->action( "options_show_menubar" );
188
if ( b ) _popMenu->addAction(b);
193
This will only get executed, when the user has removed all items from the view.
194
Don't remove this method, because then the user cannot get a menu for getting his
197
void ViewBase::showContextMenu()
199
//kDebug(67100) << "ViewBase::showContextMenu()";
202
QPoint pos = QCursor::pos();
203
_popMenu->popup( pos );
207
void ViewBase::refreshVolumeLevels()
212
Mixer* ViewBase::getMixer() {
217
* Open the View configuration dialog. The user can select which channels he wants
218
* to see and which not.
220
void ViewBase::configureView() {
222
DialogViewConfiguration* dvc = new DialogViewConfiguration(0, *this);
224
// !! The dialog is modal. Does it delete itself?
227
void ViewBase::toggleMenuBarSlot() {
228
//kDebug(67100) << "ViewBase::toggleMenuBarSlot() start\n";
229
emit toggleMenuBar();
230
//kDebug(67100) << "ViewBase::toggleMenuBarSlot() done\n";
233
// ---------- Popup stuff END ---------------------
235
#include "viewbase.moc"