4
* Copyright (C) 1999 Charles Samuels <charles@kde.org>
7
#include "userinterface.h"
13
#include <qpushbutton.h>
14
#include <qdragobject.h>
19
#include <kpopupmenu.h>
20
#include <kstatusbar.h>
23
#include <kiconloader.h>
24
#include <kfiledialog.h>
26
#include <noatunplaylist.h>
27
#include <noatunstdaction.h>
29
MilkChocolate::MilkChocolate() : QWidget(0,"NoatunUI"), UserInterface()
31
NOATUNPLUGINC(Noatun);
33
static const int buttonSize=32;
36
mBack=new QPushButton(this);
37
mBack->setFixedSize(buttonSize,buttonSize);
38
mBack->setPixmap(BarIcon("noatunback"));
39
connect(mBack, SIGNAL(clicked()), napp->player(), SLOT(back()));
40
QToolTip::add(mBack,i18n("Back"));
42
mStop=new QPushButton(this);
43
mStop->setFixedSize(buttonSize,buttonSize);
44
mStop->setPixmap(BarIcon("noatunstop"));
45
connect(mStop, SIGNAL(clicked()), napp->player(), SLOT(stop()));
46
QToolTip::add(mStop, i18n("Stop"));
48
mPlay=new QPushButton(this);
49
mPlay->setToggleButton(true);
50
mPlay->setFixedSize(buttonSize,buttonSize);
51
mPlay->setPixmap(BarIcon("noatunplay"));
52
connect(mPlay, SIGNAL(clicked()), napp->player(), SLOT(playpause()));
53
QToolTip::add(mStop, i18n("Play"));
55
mForward=new QPushButton(this);
56
mForward->setFixedSize(buttonSize,buttonSize);
57
mForward->setPixmap(BarIcon("noatunforward"));
58
connect(mForward, SIGNAL(clicked()), napp->player(), SLOT(fastForward()));
59
QToolTip::add(mStop, i18n("Forward"));
61
mPlaylist=new QPushButton(this);
62
mPlaylist->setToggleButton(true);
63
mPlaylist->setFixedSize(buttonSize,buttonSize);
64
mPlaylist->setPixmap(BarIcon("noatunplaylist"));
65
connect(mPlaylist, SIGNAL(clicked()), napp->player(), SLOT(toggleListView()));
66
QToolTip::add(mStop, i18n("Playlist"));
68
mRemoveCurrent=new QPushButton(this);
69
mRemoveCurrent->setFixedSize(buttonSize,buttonSize);
70
mRemoveCurrent->setPixmap(BarIcon("editdelete"));
71
connect(mRemoveCurrent, SIGNAL(clicked()), napp->player(), SLOT(removeCurrent()));
72
QToolTip::add(mRemoveCurrent, i18n("Remove Current File from Playlist"));
74
mLoop=new QPushButton(this);
75
mLoop->setFixedSize(buttonSize,buttonSize);
76
mLoop->setPixmap(BarIcon("noatunloopnone"));
77
connect(mLoop, SIGNAL(clicked()), napp->player(), SLOT(loop()));
78
QToolTip::add(mLoop, i18n("Change Loop Style"));
81
mVolume=new L33tSlider(0,100,10,0, Horizontal, this);
82
mVolume->setValue(napp->player()->volume());
83
mSeeker=new L33tSlider(0,1000,10,0, Horizontal, this);
85
mStatusBar=new KStatusBar(this);
88
QGridLayout *l=new QGridLayout(this);
89
l->addWidget(mBack,0,0);
90
l->addWidget(mStop,0,1);
91
l->addWidget(mPlay,0,2);
92
l->addWidget(mForward,0,3);
93
l->addWidget(mPlaylist,0,4, Qt::AlignLeft);
94
l->addWidget(mRemoveCurrent,0,5);
95
l->addWidget(mLoop,0,6);
96
l->addColSpacing(4, buttonSize+8);
98
l->addMultiCellWidget(mVolume,1,1,0,6);
99
l->addMultiCellWidget(mSeeker,2,2,0,6);
100
l->addMultiCellWidget(mStatusBar,3,3,0,6);
102
statusBar()->message(i18n("No File Loaded"));
103
statusBar()->insertItem("00:00/00:00", 1, 0, true);
105
connect( napp->player(), SIGNAL(hideYourself()), this, SLOT(hide()) );
106
connect( napp->player(), SIGNAL(showYourself()), this, SLOT(show()) );
108
connect(napp->player(), SIGNAL(playing()), this, SLOT(slotPlaying()));
109
connect(napp->player(), SIGNAL(stopped()), this, SLOT(slotStopped()));
110
connect(napp->player(), SIGNAL(paused()), this, SLOT(slotPaused()));
111
napp->player()->handleButtons();
113
connect(napp->player(), SIGNAL(timeout()), this, SLOT(slotTimeout()));
114
connect(napp->player(), SIGNAL(loopTypeChange(int)), this, SLOT(changeLoopType(int)));
118
/* This skipToWrapper is needed to pass milliseconds to Player() as everybody
119
* below the GUI is based on milliseconds instead of some unprecise thingy
120
* like seconds or mille */
121
connect(seeker(), SIGNAL(userChanged(int)), this, SLOT(skipToWrapper(int)));
122
connect(this, SIGNAL(skipTo(int)), napp->player(), SLOT(skipTo(int)));
123
connect(seeker(), SIGNAL(sliderMoved(int)), SLOT(sliderMoved(int)));
125
connect(mVolume, SIGNAL(sliderMoved(int)), napp->player(), SLOT(setVolume(int)));
126
connect(mVolume, SIGNAL(userChanged(int)), napp->player(), SLOT(setVolume(int)));
129
connect(napp->player(), SIGNAL(playlistShown()), SLOT(playlistShown()));
130
connect(napp->player(), SIGNAL(playlistHidden()), SLOT(playlistHidden()));
132
// Event Filter for the RMB
133
for (QListIterator<QObject> i(*children()); i.current(); ++i)
134
(*i)->installEventFilter(this);
136
setCaption("Noatun");
137
setIcon(BarIcon("noatun"));
140
// What it is now, stay, stay.. roll over, good boy!
141
setFixedSize(minimumSize());
144
MilkChocolate::~MilkChocolate()
146
// If cfg dialog is still open, delete it so it saves it's position
151
void MilkChocolate::closeEvent(QCloseEvent*)
156
void MilkChocolate::showEvent(QShowEvent*e)
158
QWidget::showEvent(e);
161
void MilkChocolate::dragEnterEvent(QDragEnterEvent *event)
163
// accept uri drops only
164
event->accept(QUriDrag::canDecode(event));
167
void MilkChocolate::dropEvent(QDropEvent *event)
170
if (QUriDrag::decode(event, uri))
172
for (char *file=uri.first(); file != 0; file=uri.next() )
173
napp->player()->openFile(KURL(file), false);
177
void MilkChocolate::mouseReleaseEvent(QMouseEvent *e)
179
QWidget::mouseReleaseEvent(e);
180
if (e->button()!=RightButton) return;
181
NoatunStdAction::ContextMenu::showContextMenu();
184
void MilkChocolate::changeStatusbar(const QString& text, const QString &text2)
187
statusBar()->changeItem(text2, 1);
189
statusBar()->message(!text.isNull() ? text : napp->player()->current()->title());
192
void MilkChocolate::changeCaption(const QString& text)
197
void MilkChocolate::slotPlaying()
199
// connect(kwinmodule, SIGNAL(windowAdded(WId)), view, SLOT(attemptReparent(WId)));
200
changeStatusbar(napp->player()->current()->title(), napp->player()->lengthString());
202
mStop->setEnabled(true);
203
mPlay->setPixmap(BarIcon("noatunpause"));
206
void MilkChocolate::slotStopped()
208
if (!napp->player()->current()) return;
209
changeStatusbar(i18n("No File Loaded"), napp->player()->lengthString());
210
mStop->setEnabled(false);
212
seeker()->setValue(0);
213
mPlay->setPixmap(BarIcon("noatunplay"));
216
void MilkChocolate::slotPaused()
218
mStop->setEnabled(true);
220
mPlay->setPixmap(BarIcon("noatunplay"));
223
void MilkChocolate::slotTimeout()
225
mVolume->setValue(napp->player()->volume());
227
if (!napp->player()->current()) return;
228
if (static_cast<L33tSlider*>(seeker())->currentlyPressed()) return;
231
seeker()->setRange ( 0, (int)napp->player()->getLength()/1000 );
232
seeker()->setValue ( (int)napp->player()->getTime()/1000 );
234
changeStatusbar(0, napp->player()->lengthString());
237
void MilkChocolate::sliderMoved(int seconds)
239
if (napp->player()->current())
240
changeStatusbar(0, napp->player()->lengthString(seconds*1000));
243
void MilkChocolate::skipToWrapper(int second)
245
emit skipTo((long)(second*1000));
248
void MilkChocolate::changeLoopType(int t)
250
static const int time=2000;
254
statusBar()->message(i18n("No looping"), time);
255
mLoop->setPixmap(BarIcon("noatunloopnone"));
258
statusBar()->message(i18n("Song looping"), time);
259
mLoop->setPixmap(BarIcon("noatunloopsong"));
261
case(Player::Playlist):
262
statusBar()->message(i18n("Playlist looping"), time);
263
mLoop->setPixmap(BarIcon("noatunloopplaylist"));
268
bool MilkChocolate::eventFilter(QObject *o, QEvent *e)
270
if ((e->type() == QEvent::MouseButtonRelease)
271
&& ((static_cast<QMouseEvent*>(e))->button()==RightButton))
273
mouseReleaseEvent(static_cast<QMouseEvent*>(e));
277
if (e->type() == QEvent::Wheel)
279
wheelEvent(static_cast<QWheelEvent*>(e));
282
return QWidget::eventFilter(o, e);
285
void MilkChocolate::playlistShown()
287
mPlaylist->setOn(true);
290
void MilkChocolate::playlistHidden()
292
mPlaylist->setOn(false);
295
void MilkChocolate::wheelEvent(QWheelEvent *e)
297
int delta=e->delta();
298
mVolume->setValue(mVolume->value()+(delta/120));
299
napp->player()->setVolume(mVolume->value()+(delta/120));
302
#include "userinterface.moc"