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

« back to all changes in this revision

Viewing changes to noatun/noatun/modules/noatunui/userinterface.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
 * noatun.cpp
 
3
 *
 
4
 * Copyright (C) 1999 Charles Samuels <charles@kde.org>
 
5
 */
 
6
 
 
7
#include "userinterface.h"
 
8
#include <noatunapp.h>
 
9
#include "player.h"
 
10
#include "controls.h"
 
11
#include <effects.h>
 
12
 
 
13
#include <qpushbutton.h>
 
14
#include <qdragobject.h>
 
15
#include <qlayout.h>
 
16
#include <qtooltip.h>
 
17
#include <qobjcoll.h>
 
18
 
 
19
#include <kpopupmenu.h>
 
20
#include <kstatusbar.h>
 
21
#include <kglobal.h>
 
22
#include <klocale.h>
 
23
#include <kiconloader.h>
 
24
#include <kfiledialog.h>
 
25
#include <kconfig.h>
 
26
#include <noatunplaylist.h>
 
27
#include <noatunstdaction.h>
 
28
 
 
29
MilkChocolate::MilkChocolate() : QWidget(0,"NoatunUI"), UserInterface()
 
30
{
 
31
        NOATUNPLUGINC(Noatun);
 
32
        setAcceptDrops(true);
 
33
        static const int buttonSize=32;
 
34
 
 
35
        { // The buttons
 
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"));
 
41
 
 
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"));
 
47
 
 
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"));
 
54
        
 
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"));
 
60
        
 
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"));
 
67
                
 
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"));
 
73
                
 
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"));
 
79
        }
 
80
 
 
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);
 
84
 
 
85
        mStatusBar=new KStatusBar(this);
 
86
        
 
87
        
 
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);
 
97
        
 
98
        l->addMultiCellWidget(mVolume,1,1,0,6);
 
99
        l->addMultiCellWidget(mSeeker,2,2,0,6);
 
100
        l->addMultiCellWidget(mStatusBar,3,3,0,6);
 
101
        
 
102
        statusBar()->message(i18n("No File Loaded"));
 
103
        statusBar()->insertItem("00:00/00:00", 1, 0, true);
 
104
 
 
105
        connect( napp->player(), SIGNAL(hideYourself()), this, SLOT(hide()) );
 
106
        connect( napp->player(), SIGNAL(showYourself()), this, SLOT(show()) );
 
107
 
 
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();
 
112
 
 
113
        connect(napp->player(), SIGNAL(timeout()), this, SLOT(slotTimeout()));
 
114
        connect(napp->player(), SIGNAL(loopTypeChange(int)), this, SLOT(changeLoopType(int)));
 
115
 
 
116
//      if(seeker())
 
117
        {
 
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)));
 
124
        }
 
125
        connect(mVolume, SIGNAL(sliderMoved(int)), napp->player(), SLOT(setVolume(int)));
 
126
        connect(mVolume, SIGNAL(userChanged(int)), napp->player(), SLOT(setVolume(int)));
 
127
        
 
128
        
 
129
        connect(napp->player(), SIGNAL(playlistShown()), SLOT(playlistShown()));
 
130
        connect(napp->player(), SIGNAL(playlistHidden()), SLOT(playlistHidden()));
 
131
        
 
132
        // Event Filter for the RMB
 
133
        for (QListIterator<QObject> i(*children()); i.current(); ++i)
 
134
                (*i)->installEventFilter(this);
 
135
        
 
136
        setCaption("Noatun");
 
137
        setIcon(BarIcon("noatun"));
 
138
        show();
 
139
 
 
140
        // What it is now, stay, stay.. roll over, good boy!
 
141
        setFixedSize(minimumSize());
 
142
}
 
143
 
 
144
MilkChocolate::~MilkChocolate()
 
145
{
 
146
        // If cfg dialog is still open, delete it so it saves it's position
 
147
//      if(prefDlgExist)
 
148
//              delete prefDlg;
 
149
}
 
150
 
 
151
void MilkChocolate::closeEvent(QCloseEvent*)
 
152
{
 
153
        unload();
 
154
}
 
155
 
 
156
void MilkChocolate::showEvent(QShowEvent*e)
 
157
{
 
158
        QWidget::showEvent(e);
 
159
}
 
160
 
 
161
void MilkChocolate::dragEnterEvent(QDragEnterEvent *event)
 
162
{
 
163
    // accept uri drops only
 
164
    event->accept(QUriDrag::canDecode(event));
 
165
}
 
166
 
 
167
void MilkChocolate::dropEvent(QDropEvent *event)
 
168
{
 
169
        QStrList uri;
 
170
        if (QUriDrag::decode(event, uri))
 
171
        {
 
172
                for (char *file=uri.first(); file != 0; file=uri.next() )
 
173
                        napp->player()->openFile(KURL(file), false);
 
174
        }
 
175
}
 
176
 
 
177
void MilkChocolate::mouseReleaseEvent(QMouseEvent *e)
 
178
{
 
179
        QWidget::mouseReleaseEvent(e);
 
180
        if (e->button()!=RightButton) return;
 
181
        NoatunStdAction::ContextMenu::showContextMenu();
 
182
}
 
183
 
 
184
void MilkChocolate::changeStatusbar(const QString& text, const QString &text2)
 
185
{
 
186
        if (!text2.isNull())
 
187
                statusBar()->changeItem(text2, 1);
 
188
 
 
189
        statusBar()->message(!text.isNull() ? text : napp->player()->current()->title());
 
190
}
 
191
 
 
192
void MilkChocolate::changeCaption(const QString& text)
 
193
{
 
194
    setCaption(text);
 
195
}
 
196
 
 
197
void MilkChocolate::slotPlaying()
 
198
{
 
199
//      connect(kwinmodule, SIGNAL(windowAdded(WId)), view, SLOT(attemptReparent(WId)));
 
200
        changeStatusbar(napp->player()->current()->title(), napp->player()->lengthString());
 
201
        mPlay->setOn(true);
 
202
        mStop->setEnabled(true);
 
203
        mPlay->setPixmap(BarIcon("noatunpause"));
 
204
}
 
205
 
 
206
void MilkChocolate::slotStopped()
 
207
{
 
208
        if (!napp->player()->current()) return;
 
209
        changeStatusbar(i18n("No File Loaded"), napp->player()->lengthString());
 
210
        mStop->setEnabled(false);
 
211
        mPlay->setOn(false);
 
212
        seeker()->setValue(0);
 
213
        mPlay->setPixmap(BarIcon("noatunplay"));
 
214
}
 
215
 
 
216
void MilkChocolate::slotPaused()
 
217
{
 
218
        mStop->setEnabled(true);
 
219
        mPlay->setOn(false);
 
220
        mPlay->setPixmap(BarIcon("noatunplay"));
 
221
}
 
222
 
 
223
void MilkChocolate::slotTimeout()
 
224
{
 
225
        mVolume->setValue(napp->player()->volume());
 
226
 
 
227
        if (!napp->player()->current()) return;
 
228
        if (static_cast<L33tSlider*>(seeker())->currentlyPressed()) return;
 
229
        if (seeker())
 
230
        {
 
231
                seeker()->setRange ( 0, (int)napp->player()->getLength()/1000 );
 
232
                seeker()->setValue ( (int)napp->player()->getTime()/1000 );
 
233
        }
 
234
        changeStatusbar(0, napp->player()->lengthString());
 
235
}
 
236
 
 
237
void MilkChocolate::sliderMoved(int seconds)
 
238
{
 
239
        if (napp->player()->current())
 
240
                changeStatusbar(0, napp->player()->lengthString(seconds*1000));
 
241
}
 
242
 
 
243
void MilkChocolate::skipToWrapper(int second)
 
244
{
 
245
        emit skipTo((long)(second*1000));
 
246
}
 
247
 
 
248
void MilkChocolate::changeLoopType(int t)
 
249
{
 
250
        static const int time=2000;
 
251
        switch (t)
 
252
        {
 
253
        case(Player::None):
 
254
                statusBar()->message(i18n("No looping"), time);
 
255
                mLoop->setPixmap(BarIcon("noatunloopnone"));
 
256
                break;
 
257
        case(Player::Song):
 
258
                statusBar()->message(i18n("Song looping"), time);
 
259
                mLoop->setPixmap(BarIcon("noatunloopsong"));
 
260
                break;
 
261
        case(Player::Playlist):
 
262
                statusBar()->message(i18n("Playlist looping"), time);
 
263
                mLoop->setPixmap(BarIcon("noatunloopplaylist"));
 
264
        }
 
265
 
 
266
}
 
267
 
 
268
bool MilkChocolate::eventFilter(QObject *o, QEvent *e)
 
269
{
 
270
        if ((e->type() == QEvent::MouseButtonRelease)
 
271
                && ((static_cast<QMouseEvent*>(e))->button()==RightButton))
 
272
        {
 
273
                mouseReleaseEvent(static_cast<QMouseEvent*>(e));
 
274
                return true;
 
275
        }
 
276
 
 
277
        if (e->type() == QEvent::Wheel)
 
278
        {
 
279
                wheelEvent(static_cast<QWheelEvent*>(e));
 
280
                return true;
 
281
        }
 
282
        return QWidget::eventFilter(o, e);
 
283
}
 
284
 
 
285
void MilkChocolate::playlistShown()
 
286
{
 
287
        mPlaylist->setOn(true);
 
288
}
 
289
 
 
290
void MilkChocolate::playlistHidden()
 
291
{
 
292
        mPlaylist->setOn(false);
 
293
}
 
294
 
 
295
void MilkChocolate::wheelEvent(QWheelEvent *e)
 
296
{
 
297
        int delta=e->delta();
 
298
        mVolume->setValue(mVolume->value()+(delta/120));
 
299
        napp->player()->setVolume(mVolume->value()+(delta/120));
 
300
}
 
301
 
 
302
#include "userinterface.moc"