3
* Copyright (C) 2002 Richard Moore, <rich@kde.org>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public License
16
* along with this library; see the file COPYING.LIB. If not, write to
17
* the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
22
#include <qcheckbox.h>
34
#include <kiconloader.h>
36
#include <kpopupmenu.h>
39
#include "elegant.moc"
41
KdetvElegant::KdetvElegant(Kdetv *ktv, QWidget *p, const char *name)
42
: KdetvOSDPlugin( ktv, "elegant-osd", p, name ),
44
align(AlignBottom|AlignCenter), indent(20),
45
iconSize(KIcon::SizeLarge), fontSize(48),
46
fontBold(true), fontItalic(false), fontUnderline(false), autoFontSize(false)
48
timer = new QTimer( this );
49
popup = new KPopupTitle( p, "display" );
52
// FIXME: Don't use system colors, they may not work or look bad as OSD
53
popup->setPaletteBackgroundColor( QColor( 200, 200, 200 ) );
58
connect( timer, SIGNAL( timeout() ), popup, SLOT( hide() ) );
59
connect( parent, SIGNAL( resized(int,int) ), this, SLOT( viewResized(int,int) ) );
61
viewResized(p->width(), p->height());
64
KdetvElegant::~KdetvElegant()
66
kdDebug() << "Elegant: destroying plugin." << endl;
69
void KdetvElegant::applySettings()
71
QFont font = popup->font();
72
font.setPointSize( fontSize );
73
font.setBold( fontBold );
74
font.setItalic( fontItalic );
75
font.setUnderline( fontUnderline );
76
popup->setFont( font );
81
void KdetvElegant::readConfig()
83
kdDebug() << "Elegant: reading config" << endl;
85
_cfg->setGroup( "Elegant OSD");
86
timeout = _cfg->readNumEntry( "Timeout", 2000 );
87
indent = _cfg->readNumEntry( "Indent", 20 );
88
align = _cfg->readNumEntry( "Alignment", AlignBottom|AlignCenter );
89
iconSize = _cfg->readNumEntry( "IconSize", KIcon::SizeLarge );
90
fontSize = _cfg->readNumEntry( "FontSize", 48 );
91
fontBold = _cfg->readBoolEntry( "FontBold", true );
92
fontItalic = _cfg->readBoolEntry( "FontItalic", false );
93
fontUnderline = _cfg->readBoolEntry( "FontUnderline", false );
94
autoFontSize = _cfg->readBoolEntry( "AutoFontSize", true );
97
void KdetvElegant::saveConfig()
101
kdDebug() << "Elegant: writing config" << endl;
103
_cfg->setGroup( "Elegant OSD");
104
_cfg->writeEntry( "Timeout", timeout );
105
_cfg->writeEntry( "Indent", indent );
106
_cfg->writeEntry( "Alignment", align );
107
_cfg->writeEntry( "IconSize", iconSize );
108
_cfg->writeEntry( "FontSize", fontSize );
109
_cfg->writeEntry( "FontBold", fontBold );
110
_cfg->writeEntry( "FontItalic", fontItalic );
111
_cfg->writeEntry( "FontUnderline", fontUnderline );
112
_cfg->writeEntry( "AutoFontSize", autoFontSize );
116
void KdetvElegant::updateGeometry()
118
popup->resize( popup->minimumSizeHint() );
121
if ( align & AlignLeft )
123
else if ( align & AlignRight )
124
x = parent->width() - indent - popup->width();
126
x = parent->width()/2 - popup->width()/2;
129
if ( align & AlignTop )
131
else if ( align & AlignBottom )
132
y = parent->height() - indent - popup->height();
134
y = parent->height()/2 - popup->height()/2;
136
popup->move( QPoint(x,y) );
139
void KdetvElegant::clear()
141
static QPixmap kwicon = KGlobal::iconLoader()->loadIcon("kdetv", KIcon::NoGroup, iconSize);
142
popup->setTitle(i18n("Elegant OSD"), &kwicon);
145
void KdetvElegant::showPopup()
147
if ( popup->isHidden() )
155
timer->start(timeout, true);
158
void KdetvElegant::display( const QString &text, const QPixmap &icon )
160
popup->setTitle(text, &icon);
164
void KdetvElegant::display( const QString &text, const QString &icon )
166
QString i = icon.isNull() ? QString("kdetv") : icon;
167
display( text, KGlobal::iconLoader()->loadIcon( i, KIcon::NoGroup, iconSize ) );
170
void KdetvElegant::displayMisc( const QString &text )
172
display( text, "kdetv" );
175
void KdetvElegant::displayChannel( int channel, const QString &name )
177
display( i18n("%1 - %2").arg(channel).arg(name), "kdetv" );
180
void KdetvElegant::displayMuted( bool muted )
183
display( i18n("Mute"), "player_mute" );
185
display( i18n("Unmute"), "player_volume_up" );
188
void KdetvElegant::displayVolume( int vol )
190
display( i18n("Volume: %1%").arg(vol), "player_volume_up" );
193
void KdetvElegant::displayCC( const QString &text )
195
if ( text.isEmpty() )
201
void KdetvElegant::viewResized( int w, int /*h*/ )
205
QFont font = popup->font();
206
font.setPixelSize(w / 15);
207
popup->setFont( font );
208
kdDebug() << "elegant font resized to " << w / 15 << endl;
209
if ( !popup->isHidden() ) {
214
ElegantConfigWidget *KdetvElegant::configWidget( QWidget *parent, const char *name )
216
form = new ElegantConfigWidget( parent, name );
218
if ( align & AlignLeft )
219
form->HSlider->setValue(0);
220
else if ( align & AlignRight )
221
form->HSlider->setValue(2);
223
form->HSlider->setValue(1);
225
if ( align & AlignTop )
226
form->VSlider->setValue(0);
227
else if ( align & AlignBottom )
228
form->VSlider->setValue(2);
230
form->VSlider->setValue(1);
232
form->TimeSpin->setValue( timeout );
233
form->MarginSpin->setValue( indent );
234
form->SizeSpin->setValue( fontSize );
235
form->BoldCheck->setChecked( fontBold );
236
form->ItalicCheck->setChecked( fontItalic );
237
form->UnderlineCheck->setChecked( fontUnderline );
238
form->AutoFontSizeCheck->setChecked( autoFontSize );
243
void KdetvElegant::applyConfigWidget()
245
timeout = form->TimeSpin->value();
246
indent = form->MarginSpin->value();
247
fontSize = form->SizeSpin->value();
248
iconSize = form->SizeSpin->value();
249
fontBold = form->BoldCheck->isChecked();
250
fontItalic = form->ItalicCheck->isChecked();
251
fontUnderline = form->UnderlineCheck->isChecked();
252
autoFontSize = form->AutoFontSizeCheck->isChecked();
254
switch ( form->HSlider->value() ) {
259
align = AlignHCenter;
266
switch ( form->VSlider->value() ) {
268
align = align | AlignTop;
271
align = align | AlignVCenter;
275
align = align | AlignBottom;
283
void KdetvElegant::colourKeyChanged(QColor)
285
// nothing in here, but this suppresses a kdetv complaint
286
// about the colourKeyChanged slot missing in this plugin
290
KdetvElegant* create_elegant( Kdetv *ktv, QWidget *parent )
295
return new KdetvElegant( ktv, parent );
302
static int test_chan_num = 0;
303
static int test_muted = false;
304
static int test_vol = 0;
306
void KdetvElegant::test_channel()
308
displayChannel( test_chan_num, QString("Channel %1").arg(test_chan_num) );
312
void KdetvElegant::test_mute()
314
displayMuted( test_muted );
315
test_muted = !test_muted;
318
void KdetvElegant::test_volume()
320
displayVolume( test_vol );
321
test_vol = test_vol+10;
324
void KdetvElegant::test_config()
326
QWidget *w = configWidget( 0, "conf" );
329
#endif // INCLUDE_TESTS