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