/***************************************************************************
 *   Copyright (C) 2005 by James Thorniley                                 *
 *   james@uncommonlygood.co.uk                                            *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "burnprojecttypewidget.h"
#include <qstring.h>
#include <qpixmap.h>
#include <qlabel.h>
#include <qevent.h>
#include <qdragobject.h>
#include <klocale.h>
#include <qheader.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <qevent.h>
#include <qsizepolicy.h>

BurnProjectTypeWidget::BurnProjectTypeWidget( bool enableDVD, QWidget *parent, const char *name )
 : KListView(parent, name)
{
  addColumn( "Project type" );
  header()->hide();
  setColumnWidthMode( 0, QListView::Maximum );
  setResizeMode( QListView::LastColumn );
  setSorting(-1);
  setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );

  m_audioCDItem = new KListViewItem( this, i18n("Audio CD") );
  m_audioCDItem->setDragEnabled( true );

  if( enableDVD )
  {
    m_dataDVDItem = new KListViewItem( this, i18n("Data DVD" ) );
    m_dataDVDItem->setDragEnabled( true );
  }

  m_dataCDItem = new KListViewItem( this, i18n("Data CD") );
  m_dataCDItem->setDragEnabled( true );

  QPixmap dataPixmap = KGlobal::iconLoader()->loadIcon( "cdrom_unmount", KIcon::Desktop, KIcon::SizeSmallMedium );
  m_dataCDItem->setPixmap( 0, dataPixmap );
  dataPixmap = KGlobal::iconLoader()->loadIcon( "cdaudio_unmount", KIcon::Desktop, KIcon::SizeSmallMedium );
  m_audioCDItem->setPixmap( 0, dataPixmap );
  if( enableDVD )
  { 
    dataPixmap = KGlobal::iconLoader()->loadIcon( "dvd_unmount", KIcon::Desktop, KIcon::SizeSmallMedium );
    m_dataDVDItem->setPixmap( 0, dataPixmap );
  }

  int maxheight = m_dataCDItem->totalHeight() + m_audioCDItem->totalHeight()
                     + 2*frameWidth();
  if( enableDVD )
    maxheight += m_dataDVDItem->totalHeight();

  setMaximumHeight( maxheight );

  connect( this, SIGNAL( selectionChanged( QListViewItem * ) ),
           this, SLOT( slotSelectionChanged( QListViewItem * ) ) );
}

//void BurnProjectTypeWidget::resizeEvent( QResizeEvent *)
//{
  //setFixedSize(width(), m_dataCDItem->totalHeight() + m_audioCDItem->totalHeight() + 20 );
  //triggerUpdate();
//}
void BurnProjectTypeWidget::slotSelectionChanged( QListViewItem *item ) 
{
  if( item == m_audioCDItem )
    emit discTypeSelected( BurnSidebarPlugin::AudioCD );

  else if( item == m_dataCDItem )
    emit discTypeSelected( BurnSidebarPlugin::DataCD );

  else if( item == m_dataDVDItem )
    emit discTypeSelected( BurnSidebarPlugin::DataDVD );

}

BurnProjectTypeWidget::~BurnProjectTypeWidget()
{

}

QDragObject * BurnProjectTypeWidget::dragObject( )
{
  QDragObject *d = new QTextDrag( QString::null, this );
  return d;
}

#include "burnprojecttypewidget.moc"
