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

« back to all changes in this revision

Viewing changes to kmix/viewbase.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
 
 *
5
 
 * Copyright (C) 1996-2004 Christian Esken <esken@kde.org>
6
 
 *
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.
11
 
 *
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.
16
 
 *
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.
20
 
 */
21
 
 
22
 
#include "viewbase.h"
23
 
 
24
 
// QT
25
 
#include <qcursor.h>
26
 
#include <QMouseEvent>
27
 
 
28
 
// KDE
29
 
#include <kaction.h>
30
 
#include <kmenu.h>
31
 
#include <klocale.h>
32
 
#include <kiconloader.h>
33
 
#include <kactioncollection.h>
34
 
#include <ktoggleaction.h>
35
 
#include <kstandardaction.h>
36
 
// KMix
37
 
#include "dialogviewconfiguration.h"
38
 
#include "guiprofile.h"
39
 
#include "kmixtoolbox.h"
40
 
#include "mixdevicewidget.h"
41
 
#include "mixer.h"
42
 
 
43
 
 
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)
46
 
{
47
 
   setObjectName(id);
48
 
   m_viewId = id;
49
 
   _mixer = mixer;
50
 
   _mixSet = new MixSet();
51
 
 
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 );
57
 
   }
58
 
   _localActionColletion = new KActionCollection( this );
59
 
 
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) ) ) ;
63
 
 
64
 
      //static_cast<KToggleAction*>(KStandardAction::showMenubar( this, SLOT(toggleMenuBarSlot()), _actions ));
65
 
      //_actions->addAction( m->objectName(), m );
66
 
      if ( m != 0 ) {
67
 
         if ( vflags & ViewBase::MenuBarVisible ) {
68
 
            m->setChecked(true);
69
 
         }
70
 
         else {
71
 
            m->setChecked(false);
72
 
         }
73
 
      }
74
 
   }
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()) );
79
 
}
80
 
 
81
 
ViewBase::~ViewBase() {
82
 
    delete _mixSet;
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 )
89
 
               delete _guiprof;
90
 
               _guiprof = 0;
91
 
    }
92
 
}
93
 
 
94
 
 
95
 
void ViewBase::configurationUpdate() {
96
 
}
97
 
 
98
 
QString ViewBase::id() const {
99
 
    return m_viewId;
100
 
}
101
 
 
102
 
bool ViewBase::isValid() const
103
 
{
104
 
   return (_mixSet->count() > 0 );
105
 
}
106
 
 
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 ); }
110
 
 
111
 
/**
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.
117
 
 */
118
 
void ViewBase::createDeviceWidgets()
119
 
{
120
 
    // create devices
121
 
    for ( int i=0; i<_mixSet->count(); i++ )
122
 
    {
123
 
        MixDevice *mixDevice;
124
 
        mixDevice = (*_mixSet)[i];
125
 
        QWidget* mdw = add(mixDevice);
126
 
        _mdws.append(mdw);
127
 
    }
128
 
    // allow view to "polish" itself
129
 
    constructionFinished();
130
 
}
131
 
 
132
 
/*
133
 
 * Rebuild the View from the (existing) Profile.
134
 
 *
135
 
 * Hint: this method signature might be extended in the future by a GUIProfile* paramater.
136
 
 */
137
 
void ViewBase::rebuildFromProfile()
138
 
{
139
 
   emit rebuildGUI();
140
 
/*
141
 
   // Redo everything from scratch, as visibility and the order of the controls might have changed.
142
 
 
143
 
   // As the order of the controls is stored in the profile, we need
144
 
   // to rebuild the _mixSet 
145
 
kDebug() << "rebuild 1";
146
 
   _mixSet->clear();
147
 
kDebug() << "rebuild 2";
148
 
   _mdws.clear();
149
 
kDebug() << "rebuild 3";
150
 
   setMixSet();
151
 
kDebug() << "rebuild 4";
152
 
   createDeviceWidgets();
153
 
kDebug() << "rebuild 5";
154
 
   constructionFinished();
155
 
kDebug() << "rebuild 6";
156
 
*/
157
 
}
158
 
 
159
 
 
160
 
// ---------- Popup stuff START ---------------------
161
 
void ViewBase::mousePressEvent( QMouseEvent *e )
162
 
{
163
 
   if ( e->button() == Qt::RightButton )
164
 
      showContextMenu();
165
 
}
166
 
 
167
 
/**
168
 
 * Return a popup menu. This contains basic entries.
169
 
 * More can be added by the caller.
170
 
 */
171
 
KMenu* ViewBase::getPopup()
172
 
{
173
 
   popupReset();
174
 
   return _popMenu;
175
 
}
176
 
 
177
 
void ViewBase::popupReset()
178
 
{
179
 
    QAction *a;
180
 
 
181
 
    _popMenu = new KMenu( this );
182
 
    _popMenu->addTitle( KIcon( "kmix" ), i18n("Device Settings") );
183
 
 
184
 
    a = _localActionColletion->action( "toggle_channels" );
185
 
    if ( a ) _popMenu->addAction(a);
186
 
 
187
 
    QAction *b = _actions->action( "options_show_menubar" );
188
 
    if ( b ) _popMenu->addAction(b);
189
 
}
190
 
 
191
 
 
192
 
/**
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
195
 
   channels back
196
 
*/
197
 
void ViewBase::showContextMenu()
198
 
{
199
 
    //kDebug(67100) << "ViewBase::showContextMenu()";
200
 
    popupReset();
201
 
 
202
 
    QPoint pos = QCursor::pos();
203
 
    _popMenu->popup( pos );
204
 
}
205
 
 
206
 
 
207
 
void ViewBase::refreshVolumeLevels()
208
 
{
209
 
    // is virtual
210
 
}
211
 
 
212
 
Mixer* ViewBase::getMixer() {
213
 
    return _mixer;
214
 
}
215
 
 
216
 
/**
217
 
 * Open the View configuration dialog. The user can select which channels he wants
218
 
 * to see and which not.
219
 
 */
220
 
void ViewBase::configureView() {
221
 
 
222
 
    DialogViewConfiguration* dvc = new DialogViewConfiguration(0, *this);
223
 
    dvc->show();
224
 
    // !! The dialog is modal. Does it delete itself?
225
 
}
226
 
 
227
 
void ViewBase::toggleMenuBarSlot() {
228
 
    //kDebug(67100) << "ViewBase::toggleMenuBarSlot() start\n";
229
 
    emit toggleMenuBar();
230
 
    //kDebug(67100) << "ViewBase::toggleMenuBarSlot() done\n";
231
 
}
232
 
 
233
 
// ---------- Popup stuff END ---------------------
234
 
 
235
 
#include "viewbase.moc"