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
|
#include "tmixpopup.h"
#include "devicewidget.h"
#include "../model/audiodevice.h"
#include "../model/pulsemodel.h"
#include <tqlayout.h>
#include <tqframe.h>
#include <tqlabel.h>
#include <tqpushbutton.h>
#include <tqapplication.h>
#include <tqdesktopwidget.h>
#include <tdelocale.h>
#include <tdeconfig.h>
#include <tdeglobal.h>
#include <twin.h>
TmixPopup::TmixPopup( PulseModel *model, TQWidget *parent )
: TQWidget( parent, "TmixPopup",
WStyle_Customize | WType_Popup | WStyle_DialogBorder ),
m_model(model), m_devWidget(0)
{
// Single frame fills the popup — header and content share the same border
TQVBoxLayout *outer = new TQVBoxLayout( this, 0, 0 );
TQFrame *frame = new TQFrame( this );
frame->setFrameStyle( TQFrame::NoFrame );
outer->addWidget( frame );
m_layout = new TQVBoxLayout( frame, 0, 0 );
// Thin title strip — inside the frame, so edges line up exactly
TQLabel *header = new TQLabel( i18n("Volume"), frame );
header->setAlignment( TQt::AlignCenter );
header->setFixedHeight( 23 );
header->setPaletteBackgroundColor( palette().active().mid() );
header->setPaletteForegroundColor( palette().active().text() );
m_layout->addWidget( header );
// Spacer between header and device widget
m_layout->addSpacing( 4 );
// device widget inserted at index 0 by setDevice()
m_layout->addSpacing( 4 );
// "Mixer" button — flat, compact
TQPushButton *btn = new TQPushButton( i18n("Mixer"), frame );
btn->setFlat( true );
btn->setFixedWidth( 70 );
m_layout->addWidget( btn, 0, TQt::AlignHCenter );
m_layout->addSpacing( 4 );
connect( btn, TQ_SIGNAL(clicked()), this, TQ_SIGNAL(showMixerRequested()) );
connect( model, TQ_SIGNAL(defaultOutputChanged(AudioDevice*)),
this, TQ_SLOT(onDefaultOutputChanged(AudioDevice*)) );
setDevice( model->defaultOutput() );
}
void TmixPopup::setDevice( AudioDevice *dev )
{
if ( m_devWidget ) {
m_layout->remove( m_devWidget );
delete m_devWidget;
m_devWidget = 0;
}
if ( !dev ) return;
m_devWidget = new DeviceWidget( dev, m_model,
static_cast<TQWidget*>( m_layout->parent() ) );
m_devWidget->setSeparatorVisible( false );
m_layout->insertWidget( 2, m_devWidget );
m_devWidget->show();
adjustSize();
}
void TmixPopup::onDefaultOutputChanged( AudioDevice *dev )
{
setDevice( dev );
}
void TmixPopup::toggleAt( const TQPoint &trayPos, const TQSize &traySize )
{
if ( isVisible() ) {
hide();
return;
}
adjustSize();
TQRect screen = TQApplication::desktop()->screenGeometry( trayPos );
int x = trayPos.x() + traySize.width() / 2 - width() / 2;
int y = trayPos.y() - height();
if ( y < screen.top() )
y = trayPos.y() + traySize.height();
if ( x + width() > screen.right() )
x = screen.right() - width();
if ( x < screen.left() )
x = screen.left();
move( x, y );
show();
KWin::setState( winId(), NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager );
KWin::setOnAllDesktops( winId(), true );
}
bool TmixPopup::justHidden() const
{
return m_hideTime.isValid() && m_hideTime.elapsed() < 300;
}
void TmixPopup::hideEvent( TQHideEvent *e )
{
TQWidget::hideEvent( e );
m_hideTime.start();
}
void TmixPopup::wheelEvent( TQWheelEvent *e )
{
AudioDevice *dev = m_model->defaultOutput();
if ( !dev ) return;
TDEConfig *cfg = TDEGlobal::config();
cfg->setGroup("General");
int step = cfg->readNumEntry("ScrollStep", 5);
int delta = e->delta() > 0 ? step : -step;
int vol = TQMAX( 0, TQMIN( 100, dev->volume() + delta ) );
dev->setVolume( vol );
}
#include "tmixpopup.moc"
|