summaryrefslogtreecommitdiffstats
path: root/src/projects/k3baudiodatasourceviewitem.cpp
blob: 2f0b7a5534b90c5ada79bc9fb92fc8f48896a11c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* 
 *
 * $Id: k3baudiodatasourceviewitem.cpp 619556 2007-01-03 17:38:12Z trueg $
 * Copyright (C) 2004 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
 *
 * 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.
 * See the file "COPYING" for the exact licensing terms.
 */

#include "k3baudiodatasourceviewitem.h"
#include "k3baudiodatasource.h"
#include "k3baudiotrackviewitem.h"
#include "k3baudiozerodata.h"

#include <k3bmsf.h>

#include <kiconloader.h>


K3bAudioDataSourceViewItem::K3bAudioDataSourceViewItem( K3bAudioTrackViewItem* parent, 
							K3bAudioDataSourceViewItem* after, 
							K3bAudioDataSource* source )
  : K3bListViewItem( parent, after ),
    m_trackViewItem( parent ),
    m_source( source ),
    m_animationCounter(1)
{
  // italic type
  TQFont f(listView()->font());
  f.setItalic( true );
  setFont( 3, f );

  //  setMarginVertical( 2 );

  // gray out filename
  setForegroundColor( 5, listView()->palette().disabled().foreground() );

  // smaller filename
  f = listView()->font();
  f.setPointSize( f.pointSize() - 2 );
  setFont( 5, f );

  // for zero items we make the length editable
  if( dynamic_cast<K3bAudioZeroData*>( source ) )
    setEditor( 4, MSF );
}


TQString K3bAudioDataSourceViewItem::text( int i ) const
{
  switch( i ) {
  case 3:
    return m_source->type();
  case 4:
    return m_source->length().toString();
  case 5:
    return m_source->sourceComment();
  default:
    return TQString();
  }
}


void K3bAudioDataSourceViewItem::setText( int col, const TQString& text )
{
  //
  // See K3bAudioTrackViewItem::setText for an explanation why we have to check if
  // the value really changed
  //
  if( col == 4 ) {
    if( K3bAudioZeroData* zero = dynamic_cast<K3bAudioZeroData*>( source() ) ) {
      bool ok;
      K3b::Msf f = K3b::Msf::fromString( text, &ok );
      if( ok && f != zero->length() )
	zero->setLength( f );
    }
  }
  else
    KListViewItem::setText( col, text );
}


bool K3bAudioDataSourceViewItem::animate()
{
  if( source()->length() == 0 && source()->isValid() ) {
    TQString icon = TQString( "kde%1" ).arg( m_animationCounter );
    setPixmap( 4, SmallIcon( icon ) );
    m_animationCounter++;
    if ( m_animationCounter > 6 )
      m_animationCounter = 1;
    return true;
  }
  else {
    // set status icon
    setPixmap( 4, ( source()->isValid() ? SmallIcon( "greenled" ) : SmallIcon( "redled" ) ) );
    return false;
  }
}


void K3bAudioDataSourceViewItem::setSelected( bool s )
{
  if( s || !m_trackViewItem->isSelected() )
    K3bListViewItem::setSelected(s);
}