3
* Copyright (C) 2002 Richard Moore <rich@kde.org>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
13
#include <qlcdnumber.h>
16
#include <qstylesheet.h>
22
#include <kmainwindow.h>
24
#include <kstatusbar.h>
26
#include <kdockwidget.h>
30
#include "actions.moc"
36
LCDNumberAction::LCDNumberAction( const QString &text, int accel,
37
QObject* receiver, const char* slot,
38
QObject *parent, const char *name )
39
:KAction( text, accel, receiver, slot, parent, name ),
44
int LCDNumberAction::plug( QWidget *widget, int index )
46
//do not call the previous implementation here
48
if ( widget->inherits( "KToolBar" ) ) {
50
KToolBar *tb = static_cast<KToolBar *>(widget);
51
int id = KAction::getToolButtonID();
53
QLCDNumber *lcd = createWidget( tb );
54
tb->insertWidget( id, lcd->width(), lcd, index );
55
addContainer( tb, id );
57
connect( tb, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
58
return containerCount() - 1;
61
if ( widget->inherits( "QPopupMenu" ) ) {
62
QPopupMenu *pop = static_cast<QPopupMenu *>(widget);
65
QHBox *box = new QHBox( pop );
70
QLCDNumber *num = createWidget( box );
71
num->setFixedSize( QSize(18,18) );
74
QLabel *l = new QLabel( box );
78
int id = pop->insertItem( box, -1, index );
79
addContainer( box, id );
80
connect( box, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
82
return containerCount() - 1;
88
void LCDNumberAction::unplug( QWidget *widget )
90
if ( widget->inherits( "KToolBar" ) ) {
91
KToolBar *bar = static_cast<KToolBar *>(widget);
92
int idx = findContainer( bar );
95
bar->removeItem( menuId( idx ) );
96
removeContainer( idx );
99
else if ( widget->inherits( "QPopupMenu" ) ) {
100
QPopupMenu *pop = static_cast<QPopupMenu *>(widget);
102
int idx = findContainer( pop );
104
pop->removeItem( menuId( idx ) );
105
removeContainer( idx );
110
QLCDNumber *LCDNumberAction::createWidget( QWidget *parent, const char *name )
112
QLCDNumber *lcd = new QLCDNumber( parent, name );
113
lcd->setFrameStyle( QFrame::Panel | QFrame::Sunken );
114
lcd->setLineWidth(2);
115
lcd->setMidLineWidth(1);
117
lcd->setSegmentStyle( QLCDNumber::Flat );
118
lcd->setBackgroundColor( Qt::black );
119
lcd->setPaletteForegroundColor( Qt::green );
121
lcd->setNumDigits( numDig );
124
if ( !text().isEmpty() )
125
QToolTip::add( lcd, text() );
127
connect( this, SIGNAL( valueChanged(const QString &) ),
128
lcd, SLOT( display(const QString &) ) );
132
void LCDNumberAction::setNumDigits( int nDigits )
137
void LCDNumberAction::display( int num )
139
display( QString::number(num) );
142
void LCDNumberAction::display( const QString &s )
145
emit valueChanged( val );
152
KdetvSlider::KdetvSlider( int minValue, int maxValue, int pageStep, int value, Orientation o,
153
QWidget *parent, const char* name )
154
: QSlider( minValue, maxValue, pageStep, value, o, parent, name)
158
KdetvSlider::~KdetvSlider()
162
void KdetvSlider::setOrientation( Orientation o )
164
QSlider::setOrientation(o);
165
emit orientationChanged(o);
168
void KdetvSlider::updateOrientation()
170
if (!parent()->inherits("QDockWindow"))
173
QDockWindow* d = static_cast<QDockWindow*>(parent());
174
setOrientation( d->orientation() );
178
SliderAction::SliderAction( int min_, int max_, int step_, int val_,
179
const QString &text, QObject *parent,
181
: KAction( parent, name ), inhibitRecursion(false), min(min_),
182
max(max_), step(step_), val(val_), tickStep(-1)
187
int SliderAction::plug( QWidget *widget, int index )
189
//do not call the previous implementation here
190
kdDebug() << "Plugging Slider into class '" << widget->className() << "'" << endl;
192
if ( widget->inherits( "KToolBar" ) || widget->isA("KToolBar")) {
193
KToolBar *bar = static_cast<KToolBar *>(widget);
195
int id = KAction::getToolButtonID();
197
KdetvSlider* s = createWidget( bar, "ToolbarSlider" );
198
s->setOrientation( bar->orientation() );
200
int sz = (s->orientation() == Horizontal) ? s->width() : s->height();
201
bar->insertWidget( id, sz, s, index );
202
addContainer( bar, id );
204
connect( bar, SIGNAL( orientationChanged(Orientation) ),
205
s, SLOT( setOrientation(Orientation) ) );
208
* FIXME: This is a really bad hack to get events
209
* _after_ the GUI has been created.
210
* If I don't do this, the slider orientation
211
* is not updated at startup.
212
* It seems QToolBar does not emit orientationChanged()
213
* during startup phase.
214
* This connection creates loads of unnesscessary
215
* updateOrientation() calls...
216
* I tried lots of other signals (QToolBar::visibilityChanged(),
217
* QMainWindow::dockWindowPositionChanged() and many others)
218
* but none of them works.
220
if (bar->mainWindow()->inherits("KDockMainWindow")) {
221
KDockMainWindow* kdmw = static_cast<KDockMainWindow*>(bar->mainWindow());
222
connect( kdmw->manager(), SIGNAL( change() ),
223
s, SLOT( updateOrientation() ) );
226
connect( bar, SIGNAL( destroyed() ),
227
this, SLOT( slotDestroyed() ) );
229
return containerCount() - 1;
232
if ( widget->inherits( "QPopupMenu" ) ) {
233
QPopupMenu *pop = static_cast<QPopupMenu *>(widget);
236
QHBox *box = new QHBox( pop );
238
box->setSpacing( 6 );
241
QLabel *p = new QLabel( box );
242
if ( hasIconSet() ) {
243
QPixmap pix = iconSet().pixmap( QIconSet::Small, true );
246
p->setFixedSize( QSize(18,18) );
249
QLabel *l = new QLabel( box );
250
l->setText( text() );
253
KdetvSlider* s = createWidget( box, "PopupSlider" );
256
s->setFocusPolicy( QWidget::TabFocus );
258
box->setFocusProxy( s );
261
int id = pop->insertItem( box, -1, index );
262
addContainer( pop, id );
263
connect( box, SIGNAL( destroyed() ),
264
this, SLOT( slotDestroyed() ) );
266
return containerCount() - 1;
273
void SliderAction::unplug( QWidget *widget )
275
if ( widget->inherits( "KToolBar" ) )
277
KToolBar *bar = static_cast<KToolBar *>(widget);
279
int idx = findContainer( bar );
282
bar->removeItem( menuId( idx ) );
283
removeContainer( idx );
289
if ( widget->inherits( "QPopupMenu" ) ) {
290
QPopupMenu *pop = static_cast<QPopupMenu *>(widget);
292
int idx = findContainer( pop );
295
pop->removeItem( menuId( idx ) );
296
removeContainer( idx );
303
void SliderAction::setOrientation( Orientation o )
305
const QObject* cobj = sender();
306
QObject* obj = const_cast<QObject*>(cobj);
308
if (!obj->inherits("KdetvSlider"))
311
KdetvSlider* s = static_cast<KdetvSlider*>(obj);
315
s->setTickmarks( QSlider::Below );
316
disconnect( s, SIGNAL(valueChanged(int)), this, SLOT(setInverseInternal(int)) );
317
connect( s, SIGNAL(valueChanged(int)), this, SLOT(setValueInternal(int)));
321
s->setTickmarks( QSlider::Right );
322
disconnect( s, SIGNAL(valueChanged(int)), this, SLOT(setValueInternal(int)));
323
connect( s, SIGNAL(valueChanged(int)), this, SLOT(setInverseInternal(int)) );
324
s->setValue( max-val );
331
void SliderAction::setValueInternal( int num )
333
if (inhibitRecursion)
336
inhibitRecursion = true;
338
inhibitRecursion = false;
339
emit valueChanged(num);
342
void SliderAction::setInverseInternal( int num )
344
setValueInternal (max - num);
347
void SliderAction::setValue( int num )
353
for (QPtrListIterator<KdetvSlider> it(_sliders);
356
if (it.current()->orientation() == Qt::Horizontal) {
357
it.current()->setValue(val);
359
it.current()->setValue(max - val);
364
void SliderAction::setTickInterval( int ticks )
367
for (QPtrListIterator<KdetvSlider> it(_sliders);
370
it.current()->setTickInterval( ticks );
374
KdetvSlider *SliderAction::createWidget( QWidget *parent, const char *name )
376
KdetvSlider *s = new KdetvSlider( min, max, step, val, Horizontal, parent, name );
379
connect( s, SIGNAL( destroyed(QObject*) ),
380
this, SLOT( removeSlider(QObject*) ) );
382
connect( s, SIGNAL( valueChanged(int) ),
383
this, SLOT( setValueInternal(int) ) );
384
connect( s, SIGNAL( orientationChanged(Orientation) ),
385
this, SLOT( setOrientation(Orientation) ) );
388
s->setTickInterval( tickStep );
390
s->setTickmarks( QSlider::Below );
392
if ( !text().isEmpty() )
393
QToolTip::add( s, text() );
398
void SliderAction::removeSlider( QObject* o )
400
KdetvSlider* s = static_cast<KdetvSlider*>(o);
404
int SliderAction::value() const
410
// Channel import/export action
413
ImpExChannelsAction::ImpExChannelsAction( const QString &text, int accel, const QString& fmt, Kdetv* ktv,
414
int direction, QObject *parent, const char *name)
415
: KAction(text, accel, parent, name),
418
_direction(direction)
420
connect(this, SIGNAL( activated() ),
421
this, SLOT( slotActivated() ));
424
ImpExChannelsAction::~ImpExChannelsAction()
428
void ImpExChannelsAction::slotActivated()
431
_ktv->importChannelFile(_fmt);
433
_ktv->exportChannelFile(_fmt);
441
DeviceAction::DeviceAction( const QString &text, int accel, const QString& dev,
442
Kdetv* ktv, QObject *parent, const char *name)
443
: KToggleAction(text, accel, parent, name),
447
connect(this, SIGNAL( activated() ),
448
this, SLOT( slotActivated() ));
451
DeviceAction::~DeviceAction()
455
void DeviceAction::slotActivated()
457
_ktv->playDevice(_dev);
464
AudioModeAction::AudioModeAction( const QString &text, int accel, const QString& mode,
465
Kdetv* ktv, QObject *parent, const char *name)
466
: KToggleAction(text, accel, parent, name),
470
connect(this, SIGNAL( activated() ),
471
this, SLOT( slotActivated() ));
474
AudioModeAction::~AudioModeAction()
478
void AudioModeAction::slotActivated()
480
_ktv->setAudioMode(_mode);