summaryrefslogtreecommitdiffstats
path: root/kmix/viewbase.cpp
blob: 41d26f6a032c0190005598980a1beffe27565fac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
 * KMix -- KDE's full featured mini mixer
 *
 *
 * Copyright (C) 1996-2004 Christian Esken <esken@kde.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this program; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "viewbase.h"

// QT
#include <tqlabel.h>
#include <tqcursor.h>

// KDE
#include <tdeaction.h>
#include <tdepopupmenu.h>
#include <tdelocale.h>
#include <kiconloader.h>

// KMix
#include "dialogviewconfiguration.h"
#include "mixdevicewidget.h"
#include "mixer.h"


ViewBase::ViewBase(TQWidget* parent, const char* name, const TQString & caption, Mixer* mixer, WFlags f, ViewBase::ViewFlags vflags)
     : TQWidget(parent, name, f), _vflags(vflags), _caption(caption)
{
    _mixer = mixer;
    _mixSet = new MixSet();

    /* Can't use the following construct:
       setMixSet( & mixer->getMixSet());
       C++ does not use overloaded methods like getMixSet() as long as the constructor has not completed :-(((
    */
    _actions = new TDEActionCollection( this );

    // Plug in the "showMenubar" action, if the caller wants it. Typically this is only neccesary for views in the KMix main window.
    if ( vflags & ViewBase::HasMenuBar ) {
	TDEToggleAction *m = static_cast<TDEToggleAction*>(KStdAction::showMenubar( this, TQ_SLOT(toggleMenuBarSlot()), _actions ));
	if ( vflags & ViewBase::MenuBarVisible ) {
	    m->setChecked(true);
	}
	else {
	    m->setChecked(false);
	}
    }
    new TDEAction(i18n("&Channels"), 0, this, TQ_SLOT(configureView()), _actions, "toggle_channels");
    new TDEAction(i18n("&Select Mixer"), 0, this, TQ_SLOT(selectMixerSlot()), _actions, "select_mixer");
    connect ( _mixer, TQ_SIGNAL(newVolumeLevels()), this, TQ_SLOT(refreshVolumeLevels()) );
}

ViewBase::~ViewBase() {
    delete _mixSet;
}

void ViewBase::init() {
    const MixSet& mixset = _mixer->getMixSet();
    setMixSet( const_cast<MixSet*>(&mixset)); // const_cast<>
}

void ViewBase::setMixSet(MixSet *)
{
   // do nothing. Subclasses can do something if they feel like it
}

/**
 * Dummy implementation for add().
 */
TQWidget* ViewBase::add(MixDevice* mdw) {
    TQWidget* label = new TQLabel( mdw->name(), this, mdw->name().latin1());
    label->move(0, mdw->num()*12);
    return label;
}

void ViewBase::configurationUpdate() {
}

/**
 * Create all widgets.
 * This is a loop over all supported devices of the corresponding view.
 * On each device add() is called - the derived class must implement add() for creating and placing
 * the real MixDeviceWidget.
 * The added MixDeviceWidget is appended to the _mdws list.
 */
void ViewBase::createDeviceWidgets()
{
    // create devices
    MixDevice *mixDevice;
    for ( mixDevice = _mixSet->first(); mixDevice != 0; mixDevice = _mixSet->next())
    {
	TQWidget* mdw = add(mixDevice);
	_mdws.append(mdw);
    }
    // allow view to "polish" itself
    constructionFinished();
}

// ---------- Popup stuff START ---------------------
void ViewBase::mousePressEvent( TQMouseEvent *e )
{
   if ( e->button()==TQt::RightButton )
      showContextMenu();
}

/**
 * Return a popup menu. This contains basic entries.
 * More can be added by the caller.
 */
TDEPopupMenu* ViewBase::getPopup()
{
   popupReset();
   return _popMenu;
}

void ViewBase::popupReset()
{
    TDEAction *a;
    _popMenu = new TDEPopupMenu( this );

    TDEAction *smb = _actions->action( "options_show_menubar" );

    if (!smb && Mixer::mixers().count() > 1)
    {
        _popMenu->insertTitle( SmallIcon( "kmix" ), i18n("General") );
        a = _actions->action( "select_mixer" );
        a->plug(_popMenu);
    }

    _popMenu->insertTitle( SmallIcon( "kmix" ), i18n("Device Settings") );
    a = _actions->action( "toggle_channels" );
    if (a)
    {
        a->plug(_popMenu);
    }

    if (smb)
    {
        smb->plug(_popMenu);
    }
}


/**
   This will only get executed, when the user has removed all items from the view.
   Don't remove this method, because then the user cannot get a menu for getting his
   channels back
*/
void ViewBase::showContextMenu()
{
    //kdDebug(67100) << "ViewBase::showContextMenu()" << endl;
    popupReset();

    TQPoint pos = TQCursor::pos();
    _popMenu->popup( pos );
}


void ViewBase::refreshVolumeLevels()
{
    // is virtual
}

Mixer* ViewBase::getMixer()
{
    return _mixer;
}

/**
 * Open the View configuration dialog. The user can select which channels he wants
 * to see and which not.
 */
void ViewBase::configureView()
{
    DialogViewConfiguration* dvc = new DialogViewConfiguration(0, *this);
    dvc->show();
    // !! The dialog is modal. Does it delete itself?
}

void ViewBase::toggleMenuBarSlot()
{
    //kdDebug(67100) << "ViewBase::toggleMenuBarSlot() start\n";
    emit toggleMenuBar();
    //kdDebug(67100) << "ViewBase::toggleMenuBarSlot() done\n";
}

void ViewBase::selectMixerSlot()
{
    //kdDebug(67100) << "ViewBase::selectMixerSlot() start\n";
    emit selectMixer();
    //kdDebug(67100) << "ViewBase::selectMixerSlot() done\n";
}

// ---------- Popup stuff END ---------------------

#include "viewbase.moc"