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 
00021 #include "playlistselection.h"
00022 
00023 /* OPIE */
00024 #include <opie2/odebug.h>
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   // FIXME
00065 }
00066 
00067 
00068 PlayListSelection::~PlayListSelection() {
00069 }
00070 
00071 
00072 // #ifdef USE_PLAYLIST_BACKGROUND
00073 void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) {
00074 //  odebug << "drawBackground" << oendl;
00075    p->fillRect( r, QBrush( white ) );
00076 //        QImage logo = Resource::loadImage( "launcher/opielogo" );
00077 //          if ( !logo.isNull() )
00078 //        p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo );
00079 }
00080 // #endif
00081 
00082 
00083 void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) {
00084     if ( event->state() == QMouseEvent::LeftButton ) {
00085   QListViewItem *currentItem = selectedItem();
00086   QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) );
00087   if ( currentItem && currentItem->itemAbove() == itemUnder )
00088       moveSelectedUp();
00089   else if ( currentItem && currentItem->itemBelow() == itemUnder )
00090       moveSelectedDown();
00091     }
00092 }
00093 
00094 
00095 const DocLnk *PlayListSelection::current() {
00096     PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem();
00097     if ( item )
00098   return item->file();
00099     return NULL;
00100 }
00101 
00102 
00103 void PlayListSelection::addToSelection( const DocLnk &lnk ) {
00104     PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) );
00105      QListViewItem *current = selectedItem();
00106      if ( current )
00107     item->moveItem( current );
00108     setSelected( item, TRUE );
00109     ensureItemVisible( item);
00110 }
00111 
00112 
00113 void PlayListSelection::removeSelected() {
00114     QListViewItem *item = selectedItem();
00115     if ( item )
00116   delete item;
00117     setSelected( currentItem(), TRUE );
00118     ensureItemVisible( selectedItem() );
00119 }
00120 
00121 
00122 void PlayListSelection::moveSelectedUp() {
00123     QListViewItem *item = selectedItem();
00124     if ( item && item->itemAbove() )
00125   item->itemAbove()->moveItem( item );
00126     ensureItemVisible( selectedItem() );
00127 }
00128 
00129 
00130 void PlayListSelection::moveSelectedDown() {
00131     QListViewItem *item = selectedItem();
00132     if ( item && item->itemBelow() )
00133         item->moveItem( item->itemBelow() );
00134     ensureItemVisible( selectedItem() );
00135 }
00136 
00137 
00138 bool PlayListSelection::prev() {
00139     QListViewItem *item = selectedItem();
00140     if ( item && item->itemAbove() )
00141         setSelected( item->itemAbove(), TRUE );
00142     else
00143   return FALSE;
00144     ensureItemVisible( selectedItem() );
00145     return TRUE;
00146 }
00147 
00148 bool PlayListSelection::next() {
00149     QListViewItem *item = selectedItem();
00150     if ( item && item->itemBelow() )
00151         setSelected( item->itemBelow(), TRUE );
00152     else
00153   return FALSE;
00154     ensureItemVisible( selectedItem() );
00155     return TRUE;
00156 }
00157 
00158 
00159 bool PlayListSelection::first() {
00160     QListViewItem *item = firstChild();
00161     if ( item )
00162         setSelected( item, TRUE );
00163     else
00164   return FALSE;
00165     ensureItemVisible( selectedItem() );
00166     return TRUE;
00167 }
00168 
00169 
00170 bool PlayListSelection::last() {
00171     QListViewItem *prevItem = NULL;
00172     QListViewItem *item = firstChild();
00173     while ( ( item = item->nextSibling() ) )
00174   prevItem = item;
00175     if ( prevItem )
00176         setSelected( prevItem, TRUE );
00177     else
00178   return FALSE;
00179     ensureItemVisible( selectedItem() );
00180     return TRUE;
00181 }
00182 
00183 void PlayListSelection::unSelect()
00184 {
00185     setSelected( currentItem() , FALSE);
00186 }
00187 
00188 void PlayListSelection::writeCurrent( Config& cfg ) {
00189     cfg.setGroup("PlayList");
00190     QListViewItem *item = selectedItem();
00191     if ( item )
00192         cfg.writeEntry("current", item->text(0) );
00193     //    odebug << item->text(0) << oendl;
00194 
00195 }
00196 
00197 void  PlayListSelection::setSelectedItem(const QString &strk ) {
00198 
00199     unSelect();
00200     QListViewItemIterator it( this );
00201     for ( ; it.current(); ++it ) {
00202 //        odebug << it.current()->text(0) << oendl;
00203         if( strk == it.current()->text(0)) {
00204 //             odebug << "We have a match "+strk << oendl;
00205             setSelected( it.current(), TRUE);
00206             ensureItemVisible( it.current() );
00207             return;
00208         }
00209     }
00210 //     setSelected( item, TRUE );
00211 //     ensureItemVisible( selectedItem() );
00212 }

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