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 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of 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 
00033 PlayListSelection::PlayListSelection( QWidget *parent, const char *name )
00034     : QListView( parent, name )
00035 {
00036     setAllColumnsShowFocus( TRUE );
00037     addColumn( tr( "Command Selection" ) );
00038     header()->hide();
00039     setSorting( -1, FALSE );
00040 }
00041 
00042 
00043 PlayListSelection::~PlayListSelection() {
00044 }
00045 
00046 
00047 
00048 void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) {
00049     if ( event->state() == QMouseEvent::LeftButton ) {
00050   QListViewItem *currentItem = selectedItem();
00051   QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) );
00052   if ( currentItem && currentItem->itemAbove() == itemUnder )
00053       moveSelectedUp();
00054   else if ( currentItem && currentItem->itemBelow() == itemUnder )
00055       moveSelectedDown();
00056     }
00057 }
00058 
00059 
00060 const QString *PlayListSelection::current() {
00061     PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem();
00062     if ( item )
00063   return item->file();
00064     return NULL;
00065 }
00066 
00067 
00068 void PlayListSelection::addToSelection( QListViewItem *lnk ) {
00069 PlayListSelectionItem *item = new PlayListSelectionItem( this, new QString( lnk->text(0) ) );
00070     QListViewItem *current = selectedItem();
00071     if ( current )
00072         item->moveItem( current );
00073     setSelected( item, TRUE );
00074     ensureItemVisible( selectedItem() );
00075 }
00076 
00077 void PlayListSelection::addStringToSelection (const QString & lnk) {
00078     PlayListSelectionItem *item = new PlayListSelectionItem( this, new QString( lnk ) );
00079     QListViewItem *current = selectedItem();
00080     if ( current )
00081         item->moveItem( current );
00082     setSelected( item, TRUE );
00083     ensureItemVisible( selectedItem() );
00084 
00085 }
00086 void PlayListSelection::removeSelected() {
00087     odebug << "removeSelected()" << oendl;
00088     QListViewItem *item = selectedItem();
00089     if ( item )
00090   delete item;
00091     setSelected( currentItem(), TRUE );
00092     ensureItemVisible( selectedItem() );
00093 }
00094 
00095 
00096 void PlayListSelection::moveSelectedUp() {
00097     QListViewItem *item = selectedItem();
00098     if ( item && item->itemAbove() )
00099   item->itemAbove()->moveItem( item );
00100     ensureItemVisible( selectedItem() );
00101 }
00102 
00103 
00104 void PlayListSelection::moveSelectedDown() {
00105     QListViewItem *item = selectedItem();
00106     if ( item && item->itemBelow() )
00107         item->moveItem( item->itemBelow() );
00108     ensureItemVisible( selectedItem() );
00109 }
00110 
00111 
00112 bool PlayListSelection::prev() {
00113     QListViewItem *item = selectedItem();
00114     if ( item && item->itemAbove() )
00115         setSelected( item->itemAbove(), TRUE );
00116     else
00117   return FALSE;
00118     ensureItemVisible( selectedItem() );
00119     return TRUE;
00120 }
00121 
00122 
00123 bool PlayListSelection::next() {
00124     QListViewItem *item = selectedItem();
00125     if ( item && item->itemBelow() )
00126         setSelected( item->itemBelow(), TRUE );
00127     else
00128   return FALSE;
00129     ensureItemVisible( selectedItem() );
00130     return TRUE;
00131 }
00132 
00133 
00134 bool PlayListSelection::first() {
00135     QListViewItem *item = firstChild();
00136     if ( item )
00137         setSelected( item, TRUE );
00138     else
00139   return FALSE;
00140     ensureItemVisible( selectedItem() );
00141     return TRUE;
00142 }
00143 
00144 
00145 bool PlayListSelection::last() {
00146     QListViewItem *prevItem = NULL;
00147     QListViewItem *item = firstChild();
00148     while ( ( item = item->nextSibling() ) )
00149   prevItem = item;
00150     if ( prevItem )
00151         setSelected( prevItem, TRUE );
00152     else
00153   return FALSE;
00154     ensureItemVisible( selectedItem() );
00155     return TRUE;
00156 }
00157 

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