~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kmix/kmixdockwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

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) 2000 Stefan Schimanski <1Stein@gmx.de>
 
6
 * Copyright (C) 2001 Preston Brown <pbrown@kde.org>
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Library General Public
 
10
 * License as published by the Free Software Foundation; either
 
11
 * version 2 of the License, or (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * Library General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Library General Public
 
19
 * License along with this program; if not, write to the Free
 
20
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
21
 */
 
22
 
 
23
#include <klocale.h>
 
24
#include <kapp.h>
 
25
#include <kpanelapplet.h>
 
26
#include <kpopupmenu.h>
 
27
#include <kiconloader.h>
 
28
#include <kdialog.h>
 
29
#include <kconfig.h>
 
30
 
 
31
#include <qvbox.h>
 
32
#include <qtooltip.h>
 
33
 
 
34
#include "mixer.h"
 
35
#include "mixdevicewidget.h"
 
36
#include "kmixdockwidget.h"
 
37
 
 
38
 
 
39
KMixDockWidget::KMixDockWidget( Mixer *mixer,
 
40
                                QWidget *parent, const char *name )
 
41
    : KSystemTray( parent, name ), m_mixer(mixer), masterVol(0L)
 
42
{
 
43
    createMasterVolWidget();
 
44
}
 
45
 
 
46
KMixDockWidget::~KMixDockWidget()
 
47
{
 
48
    delete masterVol;
 
49
}
 
50
 
 
51
void KMixDockWidget::createMasterVolWidget()
 
52
{
 
53
    if (!m_mixer)
 
54
        return;
 
55
 
 
56
   // create devices
 
57
   MixDevice *masterDevice = (*m_mixer)[m_mixer->masterDevice()];
 
58
//   MixDevice *masterDevice = m_mixer->getMixer(m_mixer->masterDevice();
 
59
 
 
60
   masterVol = new QVBox(0L, "masterVol", WStyle_Customize |
 
61
                         WType_Popup);
 
62
   masterVol->setFrameStyle(QFrame::PopupPanel);
 
63
   masterVol->setMargin(KDialog::marginHint());
 
64
 
 
65
   MixDeviceWidget *mdw =
 
66
       new MixDeviceWidget( m_mixer, masterDevice, false, false,
 
67
                            false, KPanelApplet::Up, masterVol,
 
68
                            masterDevice->name().latin1() );
 
69
   connect(mdw, SIGNAL(newVolume(int, Volume)),
 
70
           this, SLOT(setVolumeTip(int, Volume)));
 
71
   setVolumeTip(0, masterDevice->getVolume());
 
72
   masterVol->resize(masterVol->sizeHint());
 
73
}
 
74
 
 
75
void KMixDockWidget::setVolumeTip(int, Volume vol)
 
76
{
 
77
    QToolTip::remove(this);
 
78
    QToolTip::add(this, i18n("Volume at %1%").arg(vol.getVolume(0)));
 
79
}
 
80
 
 
81
void KMixDockWidget::mousePressEvent(QMouseEvent *me)
 
82
{
 
83
    KConfig *config = kapp->config();
 
84
    config->setGroup(0);
 
85
    if( config->readBoolEntry("TrayVolumeControl", true ) )
 
86
        QWidget::mousePressEvent(me);
 
87
    else
 
88
        KSystemTray::mousePressEvent(me);
 
89
}
 
90
 
 
91
void KMixDockWidget::mouseReleaseEvent(QMouseEvent *me)
 
92
{
 
93
    if(!masterVol) {
 
94
        KSystemTray::mouseReleaseEvent(me);
 
95
        return;
 
96
    }
 
97
    KConfig *config = kapp->config();
 
98
    config->setGroup(0);
 
99
    if( config->readBoolEntry("TrayVolumeControl", true ) ) {
 
100
        if (me->button() == QMouseEvent::LeftButton &&
 
101
            !masterVol->isVisible()) {
 
102
            QWidget *desktop = QApplication::desktop();
 
103
            int sw = desktop->width();
 
104
            int sh = desktop->height();
 
105
            int sx = desktop->x();
 
106
            int sy = desktop->y();
 
107
            int x = me->globalPos().x();
 
108
            int y = me->globalPos().y();
 
109
            y -= masterVol->geometry().height();
 
110
            int w = masterVol->width();
 
111
            int h = masterVol->height();
 
112
 
 
113
            if (x+w > sw)
 
114
                x = me->globalPos().x()-w;
 
115
            if (y+h > sh)
 
116
                y = me->globalPos().y()-h;
 
117
            if (x < sx)
 
118
                x = me->globalPos().x();
 
119
            if (y < sy)
 
120
                y = me->globalPos().y();
 
121
 
 
122
        masterVol->move(x, y);
 
123
        masterVol->show();
 
124
        } else if (me->button() == QMouseEvent::LeftButton &&
 
125
                   masterVol->isVisible()) {
 
126
            masterVol->hide();
 
127
        } else {
 
128
            masterVol->hide();
 
129
            KSystemTray::mousePressEvent(me);
 
130
        }
 
131
    } else {
 
132
        KSystemTray::mouseReleaseEvent(me);
 
133
    }
 
134
}
 
135
 
 
136
void KMixDockWidget::mouseDoubleClickEvent(QMouseEvent *me)
 
137
{
 
138
    KSystemTray::mousePressEvent(me);
 
139
}
 
140
 
 
141
void KMixDockWidget::contextMenuAboutToShow( KPopupMenu* menu )
 
142
{
 
143
    for ( unsigned n=0; n<menu->count(); n++ )
 
144
    {
 
145
        if ( QString( menu->text( menu->idAt(n) ) )==i18n("&Quit") )
 
146
            menu->removeItemAt( n );
 
147
    }
 
148
 
 
149
    menu->insertItem( SmallIcon("exit"), i18n("&Quit" ), kapp, SLOT(quit()) );
 
150
}
 
151
 
 
152
#include "kmixdockwidget.moc"