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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
/*
*
* $Id: k3baudiotrackviewitem.cpp 619556 2007-01-03 17:38:12Z trueg $
* Copyright (C) 2004 Sebastian Trueg <[email protected]>
*
* This file is part of the K3b project.
* Copyright (C) 1998-2007 Sebastian Trueg <[email protected]>
*
* 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 "k3baudiotrackviewitem.h"
#include "k3baudiodatasourceviewitem.h"
#include "k3baudiodatasource.h"
#include "k3baudiotrackview.h"
#include "k3baudiotrack.h"
#include <k3bcdtextvalidator.h>
#include <kiconloader.h>
#include <tqpainter.h>
K3bAudioTrackViewItem::K3bAudioTrackViewItem( K3bAudioTrackView* parent,
K3bAudioTrackViewItem* after,
K3bAudioTrack* track )
: K3bListViewItem( parent, after ),
m_track( track ),
m_alreadyRemoved(false),
m_showingSources(false),
m_animationCounter(1)
{
// columns
// 0 - No.
// 1 - Artist (CD-Text)
// 2 - Title (CD-Text)
// 3 - Type
// 4 - Pregap
// 5 - Length
// 6 - Filename
// animationIconNumber = 1;
setEditor( 1, LINE );
setEditor( 2, LINE );
setValidator( 1, new K3bCdTextValidator() );
setValidator( 2, validator(1) );
// setMarginVertical( 5 );
// italic type
TQFont f(listView()->font());
f.setItalic( true );
setFont( 3, f );
// gray out filename
setForegroundColor( 5, listView()->palette().disabled().foreground() );
// smaller filename
f = listView()->font();
f.setPointSize( f.pointSize() - 2 );
setFont( 5, f );
updateSourceItems();
}
K3bAudioTrackViewItem::~K3bAudioTrackViewItem()
{
delete validator(1);
}
void K3bAudioTrackViewItem::paintCell( TQPainter* p, const TQColorGroup& cg, int col, int width, int align )
{
K3bListViewItem::paintCell( p, cg, col, width, align );
// draw the separator
if( listView()->firstChild() != this ) {
p->save();
// FIXME: modify the value from palette().disabled().foreground() to be lighter (or darker, depending on the background color )
p->setPen( TQt::lightGray );
p->drawLine( 0, 0, width, 0 );
p->restore();
}
}
void K3bAudioTrackViewItem::paintBranches( TQPainter* p, const TQColorGroup& cg, int w, int, int h )
{
// we just want empty space
p->fillRect( TQRect( 0, 0, w, h ), cg.base() );
}
TQString K3bAudioTrackViewItem::text(int i) const
{
// to avoid crashes when the track has been deleted and this viewitem is still around
if( m_alreadyRemoved )
return TQString();
//
// We add two spaces after all strings (except the once renameable)
// to increase readability
//
switch( i )
{
case 0:
return TQString::number( m_track->trackNumber() ).rightJustify( 2, ' ' );
case 1:
return m_track->performer();
case 2:
return m_track->title();
case 3:
if( m_showingSources )
return TQString();
else
return m_track->firstSource()->type();
case 4:
return m_track->length().toString();
case 5:
if( m_showingSources )
return TQString();
else
return m_track->firstSource()->sourceComment();
default:
return TDEListViewItem::text(i);
}
}
void K3bAudioTrackViewItem::setText( int col, const TQString& text )
{
//
// Stupid TQListViewItem actually calls setText in paintCell. Thus, once a new item
// is created setText is called and in turn the doc is marked as modified since
// we call setArtist or setPerformer here! :(
//
// Quick fix: check if the field actually changed
//
if( col == 1 ) {
// this is the cd-text artist field
if( text != m_track->performer() )
m_track->setPerformer( text );
}
else if( col == 2 ) {
// this is the cd-text title field
if( text != m_track->title() )
m_track->setTitle( text );
}
TDEListViewItem::setText( col, text );
}
void K3bAudioTrackViewItem::showSources( bool show )
{
setOpen(show);
m_showingSources = show;
}
void K3bAudioTrackViewItem::updateSourceItems()
{
while( firstChild() )
delete firstChild();
K3bAudioDataSource* source = track()->firstSource();
K3bAudioDataSourceViewItem* sourceItem = 0;
while( source ) {
sourceItem = new K3bAudioDataSourceViewItem( this, sourceItem, source );
sourceItem->animate();
source = source->next();
}
}
bool K3bAudioTrackViewItem::animate()
{
//
// We animate if one of the sources have length == 0
// otherwise we set the led
//
bool animate = false;
bool valid = true;
TQListViewItem* item = firstChild();
while( item ) {
K3bAudioDataSourceViewItem* sourceItem = dynamic_cast<K3bAudioDataSourceViewItem*>( item );
animate = animate || sourceItem->animate();
valid = valid && sourceItem->source()->isValid();
item = item->nextSibling();
}
if( animate ) {
TQString icon = TQString( "kde%1" ).arg( m_animationCounter );
setPixmap( 4, SmallIcon( icon ) );
m_animationCounter++;
if ( m_animationCounter > 6 )
m_animationCounter = 1;
}
else {
// set status icon
setPixmap( 4, ( valid ? SmallIcon( "greenled" ) : SmallIcon( "redled" ) ) );
}
return animate;
}
void K3bAudioTrackViewItem::setSelected( bool s )
{
K3bListViewItem::setSelected(s);
// we also select or unselect all source items
TQListViewItem* item = firstChild();
while( item ) {
item->setSelected(s);
item = item->nextSibling();
}
}
void K3bAudioTrackViewItem::insertItem( TQListViewItem* item )
{
K3bListViewItem::insertItem( item );
if( isSelected() )
item->setSelected(true);
}
|