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
|
/***************************************************************************
* Copyright (C) 2003 by Mario Scalas *
* [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. *
* *
***************************************************************************/
#include <qpainter.h>
#include <kdebug.h>
#include "filetreewidget.h"
#include "fileitemfactory.h"
using namespace filetreeview;
///////////////////////////////////////////////////////////////////////////////
// class FileTreeViewItem
///////////////////////////////////////////////////////////////////////////////
FileTreeWidget* FileTreeViewItem::listView() const
{
return static_cast<FileTreeWidget*>( QListViewItem::listView() );
}
///////////////////////////////////////////////////////////////////////////////
void FileTreeViewItem::hideOrShow()
{
kdDebug( 9017 ) << "MyFileTreeViewItem::hideOrShow(): " + path() << endl;
setVisible( listView()->shouldBeShown( this ) );
FileTreeViewItem* item = static_cast<FileTreeViewItem*>( firstChild() );
while (item)
{
//kdDebug( 9017 ) << "MyFileTreeViewItem::hideOrShow(): " + item->path() << endl;
item->hideOrShow();
item = static_cast<FileTreeViewItem*>( item->nextSibling() );
}
}
bool FileTreeViewItem::changeActiveDir( const QString& olddir, const QString& newdir, bool foundolddir, bool foundnewdir )
{
kdDebug( 9017 ) << "FileTreeViewItem::changeActiveDir(): " + olddir << " new: " << newdir << " for: " << path() << endl;
if ( this->path() == olddir && isDir() && m_isActiveDir )
{
m_isActiveDir = false;
setVisible( listView()->shouldBeShown( this ) );
foundolddir = true;
repaint();
}
if ( this->path() == newdir && isDir() && !m_isActiveDir )
{
m_isActiveDir = true;
setVisible( listView()->shouldBeShown( this ) );
foundnewdir = true;
repaint();
}
if( foundnewdir && foundolddir )
return true;
FileTreeViewItem* item = static_cast<FileTreeViewItem*>( firstChild() );
while( item )
{
if ( item->changeActiveDir( olddir, newdir, foundnewdir, foundolddir ) )
return true;
else
item = static_cast<FileTreeViewItem*>(item->nextSibling());
}
return false;
}
///////////////////////////////////////////////////////////////////////////////
bool FileTreeViewItem::setProjectFile( QString const & path, bool pf )
{
if ( this->path() == path && isProjectFile() != pf )
{
kdDebug( 9017 ) << "FileTreeViewItem::setProjectFile(): " + path << " projectfile: " << pf << endl;
m_isProjectFile = pf;
setVisible( listView()->shouldBeShown( this ) );
repaint();
return true;
}
FileTreeViewItem* item = static_cast<FileTreeViewItem*>( firstChild() );
while( item )
{
if ( item->setProjectFile( path, pf ) )
return true;
else
item = static_cast<FileTreeViewItem*>(item->nextSibling());
}
return false;
}
///////////////////////////////////////////////////////////////////////////////
void FileTreeViewItem::paintCell(QPainter *p, const QColorGroup &cg,
int column, int width, int alignment)
{
if ( listView()->showNonProjectFiles() && isProjectFile() )
{
QFont font( p->font() );
font.setBold( true );
p->setFont( font );
}
if( isActiveDir() )
{
QFont font( p->font() );
font.setItalic( true );
p->setFont( font );
}
QListViewItem::paintCell( p, cg, column, width, alignment );
}
///////////////////////////////////////////////////////////////////////////////
int FileTreeViewItem::compare( QListViewItem *i, int col, bool ascending ) const
{
KFileTreeViewItem* rhs = dynamic_cast<KFileTreeViewItem*>( i );
if (rhs)
{
if (rhs->isDir() && !isDir())
return (ascending) ? 1 : -1;
else
if (!rhs->isDir() && isDir())
return (ascending) ? -1 : 1;
}
return QListViewItem::compare( i, col, ascending );
}
///////////////////////////////////////////////////////////////////////////////
// class BranchItemFactory
///////////////////////////////////////////////////////////////////////////////
|