Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

playlistselection.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 #include "playlistselection.h"
00021 
00022 /* OPIE */
00023 #include <opie2/odebug.h>
00024 using namespace Opie::Core;
00025 
00026 /* QT */
00027 #include <qheader.h>
00028 
00029 /* STD */
00030 #include <stdlib.h>
00031 
00032 class PlayListSelectionItem : public QListViewItem {
00033 public:
00034     PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) {
00035   setText( 0, f->name() );
00036   setPixmap( 0, f->pixmap() );
00037     }
00038 
00039     ~PlayListSelectionItem() {
00040     };
00041 
00042     const DocLnk *file() const { return fl; }
00043 
00044 private:
00045     const DocLnk *fl;
00046 };
00047 
00048 
00049 PlayListSelection::PlayListSelection( QWidget *parent, const char *name )
00050     : QListView( parent, name )
00051 {
00052 //    odebug << "starting playlistselector" << oendl; 
00053 // #ifdef USE_PLAYLIST_BACKGROUND
00054 //    setStaticBackground( TRUE );
00055 //      setBackgroundPixmap( Resource::loadPixmap( "opieplayer/background" ) );
00056 
00057 //      setBackgroundPixmap( Resource::loadPixmap( "launcher/opielogo" ) );
00058 // #endif
00059 //      addColumn("Title",236);
00060 //      setAllColumnsShowFocus( TRUE );
00061      addColumn( tr( "Playlist Selection" ) );
00062     header()->hide();
00063     setSorting( -1, FALSE );
00064 }
00065 
00066 
00067 PlayListSelection::~PlayListSelection() {
00068 }
00069 
00070 
00071 // #ifdef USE_PLAYLIST_BACKGROUND
00072 void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) {
00073 //  odebug << "drawBackground" << oendl; 
00074    p->fillRect( r, QBrush( white ) );
00075 //        QImage logo = Resource::loadImage( "launcher/opielogo" );
00076 //          if ( !logo.isNull() )
00077 //        p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo );
00078 }
00079 // #endif
00080 
00081 
00082 void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) {
00083     if ( event->state() == QMouseEvent::LeftButton ) {
00084   QListViewItem *currentItem = selectedItem();
00085   QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) );
00086   if ( currentItem && currentItem->itemAbove() == itemUnder )
00087       moveSelectedUp();
00088   else if ( currentItem && currentItem->itemBelow() == itemUnder )
00089       moveSelectedDown();
00090     }
00091 }
00092 
00093 
00094 const DocLnk *PlayListSelection::current() {
00095     PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem();
00096     if ( item )
00097   return item->file();
00098     return NULL;
00099 }
00100 
00101 
00102 void PlayListSelection::addToSelection( const DocLnk &lnk ) {
00103     PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) );
00104     QListViewItem *current = selectedItem();
00105     if ( current )
00106         item->moveItem( current );
00107     setSelected( item, TRUE );
00108     ensureItemVisible( selectedItem() );
00109 }
00110 
00111 
00112 void PlayListSelection::removeSelected() {
00113     QListViewItem *item = selectedItem();
00114     delete item;
00115     setSelected( currentItem(), TRUE );
00116     ensureItemVisible( selectedItem() );
00117 }
00118 
00119 
00120 void PlayListSelection::moveSelectedUp() {
00121     QListViewItem *item = selectedItem();
00122     if ( item && item->itemAbove() )
00123   item->itemAbove()->moveItem( item );
00124     ensureItemVisible( selectedItem() );
00125 }
00126 
00127 
00128 void PlayListSelection::moveSelectedDown() {
00129     QListViewItem *item = selectedItem();
00130     if ( item && item->itemBelow() )
00131         item->moveItem( item->itemBelow() );
00132     ensureItemVisible( selectedItem() );
00133 }
00134 
00135 
00136 bool PlayListSelection::prev() {
00137     QListViewItem *item = selectedItem();
00138     if ( item && item->itemAbove() )
00139         setSelected( item->itemAbove(), TRUE );
00140     else
00141   return FALSE;
00142     ensureItemVisible( selectedItem() );
00143     return TRUE;
00144 }
00145 
00146 bool PlayListSelection::next() {
00147     QListViewItem *item = selectedItem();
00148     if ( item && item->itemBelow() )
00149         setSelected( item->itemBelow(), TRUE );
00150     else
00151   return FALSE;
00152     ensureItemVisible( selectedItem() );
00153     return TRUE;
00154 }
00155 
00156 
00157 bool PlayListSelection::first() {
00158     QListViewItem *item = firstChild();
00159     if ( item )
00160         setSelected( item, TRUE );
00161     else
00162   return FALSE;
00163     ensureItemVisible( selectedItem() );
00164     return TRUE;
00165 }
00166 
00167 
00168 bool PlayListSelection::last() {
00169     QListViewItem *prevItem = NULL;
00170     QListViewItem *item = firstChild();
00171     while ( ( item = item->nextSibling() ) )
00172   prevItem = item;
00173     if ( prevItem )
00174         setSelected( prevItem, TRUE );
00175     else
00176   return FALSE;
00177     ensureItemVisible( selectedItem() );
00178     return TRUE;
00179 }
00180 
00181 void PlayListSelection::unSelect()
00182 {
00183     //QListViewItem *item = selectedItem();
00184     setSelected( currentItem(), FALSE);
00185 }
00186 
00187 void PlayListSelection::writeCurrent( Config& cfg ) {
00188     cfg.setGroup("PlayList");
00189     QListViewItem *item = selectedItem();
00190     if ( item )
00191         cfg.writeEntry("current", item->text(0) );
00192     odebug << item->text(0) << oendl; 
00193 
00194 }
00195 
00196 void  PlayListSelection::setSelectedItem(const QString &strk ) {
00197 
00198     unSelect();
00199     QListViewItemIterator it( this );
00200     for ( ; it.current(); ++it ) {
00201 //        odebug << it.current()->text(0) << oendl; 
00202         if( strk == it.current()->text(0)) {
00203 //             odebug << "We have a match "+strk << oendl; 
00204             setSelected( it.current(), TRUE);
00205             ensureItemVisible( it.current() );
00206             return;
00207         }
00208     }
00209 //     setSelected( item, TRUE );
00210 //     ensureItemVisible( selectedItem() );
00211 }

Generated on Sat Nov 5 16:15:26 2005 for OPIE by  doxygen 1.4.2