1
/***************************************************************************
2
* Copyright (C) 2003 by Mario Scalas *
3
* mario.scalas@libero.it *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
***************************************************************************/
15
#include "filetreewidget.h"
16
#include "fileitemfactory.h"
18
using namespace filetreeview;
20
///////////////////////////////////////////////////////////////////////////////
21
// class FileTreeViewItem
22
///////////////////////////////////////////////////////////////////////////////
24
FileTreeWidget* FileTreeViewItem::listView() const
26
return static_cast<FileTreeWidget*>( QListViewItem::listView() );
29
///////////////////////////////////////////////////////////////////////////////
31
void FileTreeViewItem::hideOrShow()
33
kdDebug( 9017 ) << "MyFileTreeViewItem::hideOrShow(): " + path() << endl;
34
setVisible( listView()->shouldBeShown( this ) );
35
FileTreeViewItem* item = static_cast<FileTreeViewItem*>( firstChild() );
38
//kdDebug( 9017 ) << "MyFileTreeViewItem::hideOrShow(): " + item->path() << endl;
40
item = static_cast<FileTreeViewItem*>( item->nextSibling() );
44
bool FileTreeViewItem::changeActiveDir( const QString& olddir, const QString& newdir, bool foundolddir, bool foundnewdir )
46
kdDebug( 9017 ) << "FileTreeViewItem::changeActiveDir(): " + olddir << " new: " << newdir << " for: " << path() << endl;
48
if ( this->path() == olddir && isDir() && m_isActiveDir )
50
m_isActiveDir = false;
51
setVisible( listView()->shouldBeShown( this ) );
56
if ( this->path() == newdir && isDir() && !m_isActiveDir )
59
setVisible( listView()->shouldBeShown( this ) );
64
if( foundnewdir && foundolddir )
67
FileTreeViewItem* item = static_cast<FileTreeViewItem*>( firstChild() );
70
if ( item->changeActiveDir( olddir, newdir, foundnewdir, foundolddir ) )
73
item = static_cast<FileTreeViewItem*>(item->nextSibling());
78
///////////////////////////////////////////////////////////////////////////////
80
bool FileTreeViewItem::setProjectFile( QString const & path, bool pf )
83
if ( this->path() == path && isProjectFile() != pf )
85
kdDebug( 9017 ) << "FileTreeViewItem::setProjectFile(): " + path << " projectfile: " << pf << endl;
87
setVisible( listView()->shouldBeShown( this ) );
92
FileTreeViewItem* item = static_cast<FileTreeViewItem*>( firstChild() );
95
if ( item->setProjectFile( path, pf ) )
98
item = static_cast<FileTreeViewItem*>(item->nextSibling());
103
///////////////////////////////////////////////////////////////////////////////
105
void FileTreeViewItem::paintCell(QPainter *p, const QColorGroup &cg,
106
int column, int width, int alignment)
108
if ( listView()->showNonProjectFiles() && isProjectFile() )
110
QFont font( p->font() );
111
font.setBold( true );
117
QFont font( p->font() );
118
font.setItalic( true );
122
QListViewItem::paintCell( p, cg, column, width, alignment );
126
///////////////////////////////////////////////////////////////////////////////
128
int FileTreeViewItem::compare( QListViewItem *i, int col, bool ascending ) const
130
KFileTreeViewItem* rhs = dynamic_cast<KFileTreeViewItem*>( i );
133
if (rhs->isDir() && !isDir())
134
return (ascending) ? 1 : -1;
136
if (!rhs->isDir() && isDir())
137
return (ascending) ? -1 : 1;
140
return QListViewItem::compare( i, col, ascending );
143
///////////////////////////////////////////////////////////////////////////////
144
// class BranchItemFactory
145
///////////////////////////////////////////////////////////////////////////////