From 15318cad33835e4e2dc620d033e43cd930676cdd Mon Sep 17 00:00:00 2001 From: kergoth Date: Fri, 25 Jan 2002 22:14:26 +0000 Subject: Initial revision --- (limited to 'core/multimedia/opieplayer/playlistselection.cpp') 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 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "playlistselection.h" + +#include + + +class PlayListSelectionItem : public QListViewItem { +public: + PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) { + setText( 0, f->name() ); + setPixmap( 0, f->pixmap() ); + } + + ~PlayListSelectionItem() { + }; + + const DocLnk *file() const { return fl; } + +private: + const DocLnk *fl; +}; + + +PlayListSelection::PlayListSelection( QWidget *parent, const char *name ) + : QListView( parent, name ) +{ +#ifdef USE_PLAYLIST_BACKGROUND + setStaticBackground( TRUE ); + setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/background" ) ); +#endif + setAllColumnsShowFocus( TRUE ); + addColumn( tr( "Playlist Selection" ) ); + header()->hide(); + setSorting( -1, FALSE ); +} + + +PlayListSelection::~PlayListSelection() { +} + + +#ifdef USE_PLAYLIST_BACKGROUND +void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) { + p->fillRect( r, QBrush( white ) ); + QImage logo = Resource::loadImage( "mpegplayer/background" ); + if ( !logo.isNull() ) + p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo ); +} +#endif + + +void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) { + if ( event->state() == QMouseEvent::LeftButton ) { + QListViewItem *currentItem = selectedItem(); + QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) ); + if ( currentItem && currentItem->itemAbove() == itemUnder ) + moveSelectedUp(); + else if ( currentItem && currentItem->itemBelow() == itemUnder ) + moveSelectedDown(); + } +} + + +const DocLnk *PlayListSelection::current() { + PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem(); + if ( item ) + return item->file(); + return NULL; +} + + +void PlayListSelection::addToSelection( const DocLnk &lnk ) { + PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) ); + QListViewItem *current = selectedItem(); + if ( current ) + item->moveItem( current ); + setSelected( item, TRUE ); + ensureItemVisible( selectedItem() ); +} + + +void PlayListSelection::removeSelected() { + QListViewItem *item = selectedItem(); + if ( item ) + delete item; + setSelected( currentItem(), TRUE ); + ensureItemVisible( selectedItem() ); +} + + +void PlayListSelection::moveSelectedUp() { + QListViewItem *item = selectedItem(); + if ( item && item->itemAbove() ) + item->itemAbove()->moveItem( item ); + ensureItemVisible( selectedItem() ); +} + + +void PlayListSelection::moveSelectedDown() { + QListViewItem *item = selectedItem(); + if ( item && item->itemBelow() ) + item->moveItem( item->itemBelow() ); + ensureItemVisible( selectedItem() ); +} + + +bool PlayListSelection::prev() { + QListViewItem *item = selectedItem(); + if ( item && item->itemAbove() ) + setSelected( item->itemAbove(), TRUE ); + else + return FALSE; + ensureItemVisible( selectedItem() ); + return TRUE; +} + + +bool PlayListSelection::next() { + QListViewItem *item = selectedItem(); + if ( item && item->itemBelow() ) + setSelected( item->itemBelow(), TRUE ); + else + return FALSE; + ensureItemVisible( selectedItem() ); + return TRUE; +} + + +bool PlayListSelection::first() { + QListViewItem *item = firstChild(); + if ( item ) + setSelected( item, TRUE ); + else + return FALSE; + ensureItemVisible( selectedItem() ); + return TRUE; +} + + +bool PlayListSelection::last() { + QListViewItem *prevItem = NULL; + QListViewItem *item = firstChild(); + while ( ( item = item->nextSibling() ) ) + prevItem = item; + if ( prevItem ) + setSelected( prevItem, TRUE ); + else + return FALSE; + ensureItemVisible( selectedItem() ); + return TRUE; +} + -- cgit v0.9.0.2