summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/playlistselection.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/playlistselection.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/playlistselection.cpp179
1 files changed, 179 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/playlistselection.cpp b/core/multimedia/opieplayer/playlistselection.cpp
new file mode 100644
index 0000000..fbfb946
--- a/dev/null
+++ b/core/multimedia/opieplayer/playlistselection.cpp
@@ -0,0 +1,179 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qpe/applnk.h>
21#include <qpe/resource.h>
22#include <qpainter.h>
23#include <qimage.h>
24#include <qheader.h>
25#include <qlistview.h>
26#include <qlist.h>
27#include <qpixmap.h>
28
29#include "playlistselection.h"
30
31#include <stdlib.h>
32
33
34class PlayListSelectionItem : public QListViewItem {
35public:
36 PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) {
37 setText( 0, f->name() );
38 setPixmap( 0, f->pixmap() );
39 }
40
41 ~PlayListSelectionItem() {
42 };
43
44 const DocLnk *file() const { return fl; }
45
46private:
47 const DocLnk *fl;
48};
49
50
51PlayListSelection::PlayListSelection( QWidget *parent, const char *name )
52 : QListView( parent, name )
53{
54#ifdef USE_PLAYLIST_BACKGROUND
55 setStaticBackground( TRUE );
56 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/background" ) );
57#endif
58 setAllColumnsShowFocus( TRUE );
59 addColumn( tr( "Playlist Selection" ) );
60 header()->hide();
61 setSorting( -1, FALSE );
62}
63
64
65PlayListSelection::~PlayListSelection() {
66}
67
68
69#ifdef USE_PLAYLIST_BACKGROUND
70void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) {
71 p->fillRect( r, QBrush( white ) );
72 QImage logo = Resource::loadImage( "mpegplayer/background" );
73 if ( !logo.isNull() )
74 p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo );
75}
76#endif
77
78
79void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) {
80 if ( event->state() == QMouseEvent::LeftButton ) {
81 QListViewItem *currentItem = selectedItem();
82 QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) );
83 if ( currentItem && currentItem->itemAbove() == itemUnder )
84 moveSelectedUp();
85 else if ( currentItem && currentItem->itemBelow() == itemUnder )
86 moveSelectedDown();
87 }
88}
89
90
91const DocLnk *PlayListSelection::current() {
92 PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem();
93 if ( item )
94 return item->file();
95 return NULL;
96}
97
98
99void PlayListSelection::addToSelection( const DocLnk &lnk ) {
100 PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) );
101 QListViewItem *current = selectedItem();
102 if ( current )
103 item->moveItem( current );
104 setSelected( item, TRUE );
105 ensureItemVisible( selectedItem() );
106}
107
108
109void PlayListSelection::removeSelected() {
110 QListViewItem *item = selectedItem();
111 if ( item )
112 delete item;
113 setSelected( currentItem(), TRUE );
114 ensureItemVisible( selectedItem() );
115}
116
117
118void PlayListSelection::moveSelectedUp() {
119 QListViewItem *item = selectedItem();
120 if ( item && item->itemAbove() )
121 item->itemAbove()->moveItem( item );
122 ensureItemVisible( selectedItem() );
123}
124
125
126void PlayListSelection::moveSelectedDown() {
127 QListViewItem *item = selectedItem();
128 if ( item && item->itemBelow() )
129 item->moveItem( item->itemBelow() );
130 ensureItemVisible( selectedItem() );
131}
132
133
134bool PlayListSelection::prev() {
135 QListViewItem *item = selectedItem();
136 if ( item && item->itemAbove() )
137 setSelected( item->itemAbove(), TRUE );
138 else
139 return FALSE;
140 ensureItemVisible( selectedItem() );
141 return TRUE;
142}
143
144
145bool PlayListSelection::next() {
146 QListViewItem *item = selectedItem();
147 if ( item && item->itemBelow() )
148 setSelected( item->itemBelow(), TRUE );
149 else
150 return FALSE;
151 ensureItemVisible( selectedItem() );
152 return TRUE;
153}
154
155
156bool PlayListSelection::first() {
157 QListViewItem *item = firstChild();
158 if ( item )
159 setSelected( item, TRUE );
160 else
161 return FALSE;
162 ensureItemVisible( selectedItem() );
163 return TRUE;
164}
165
166
167bool PlayListSelection::last() {
168 QListViewItem *prevItem = NULL;
169 QListViewItem *item = firstChild();
170 while ( ( item = item->nextSibling() ) )
171 prevItem = item;
172 if ( prevItem )
173 setSelected( prevItem, TRUE );
174 else
175 return FALSE;
176 ensureItemVisible( selectedItem() );
177 return TRUE;
178}
179