~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to parts/fileview/fileitemfactory.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2003 by Mario Scalas                                    *
3
 
 *   mario.scalas@libero.it                                                *
4
 
 *                                                                         *
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.                                   *
9
 
 *                                                                         *
10
 
 ***************************************************************************/
11
 
 
12
 
#include <qpainter.h>
13
 
#include <kdebug.h>
14
 
 
15
 
#include "filetreewidget.h"
16
 
#include "fileitemfactory.h"
17
 
 
18
 
using namespace filetreeview;
19
 
 
20
 
///////////////////////////////////////////////////////////////////////////////
21
 
// class FileTreeViewItem
22
 
///////////////////////////////////////////////////////////////////////////////
23
 
 
24
 
FileTreeWidget* FileTreeViewItem::listView() const
25
 
{
26
 
    return static_cast<FileTreeWidget*>( QListViewItem::listView() );
27
 
}
28
 
 
29
 
///////////////////////////////////////////////////////////////////////////////
30
 
 
31
 
void FileTreeViewItem::hideOrShow()
32
 
{
33
 
    kdDebug( 9017 ) << "MyFileTreeViewItem::hideOrShow(): " + path() << endl;
34
 
    setVisible( listView()->shouldBeShown( this ) );
35
 
    FileTreeViewItem* item = static_cast<FileTreeViewItem*>( firstChild() );
36
 
    while (item)
37
 
    {
38
 
        //kdDebug( 9017 ) << "MyFileTreeViewItem::hideOrShow(): " + item->path() << endl;
39
 
        item->hideOrShow();
40
 
        item = static_cast<FileTreeViewItem*>( item->nextSibling() );
41
 
    }
42
 
}
43
 
 
44
 
bool FileTreeViewItem::changeActiveDir( const QString& olddir, const QString& newdir, bool foundolddir, bool foundnewdir )
45
 
{
46
 
    kdDebug( 9017 ) << "FileTreeViewItem::changeActiveDir(): " + olddir << " new: " << newdir << " for: " << path() << endl;
47
 
 
48
 
    if ( this->path() == olddir && isDir() && m_isActiveDir )
49
 
    {
50
 
        m_isActiveDir = false;
51
 
        setVisible( listView()->shouldBeShown( this ) );
52
 
        foundolddir = true;
53
 
        repaint();
54
 
    }
55
 
 
56
 
    if ( this->path() == newdir && isDir() && !m_isActiveDir )
57
 
    {
58
 
        m_isActiveDir = true;
59
 
        setVisible( listView()->shouldBeShown( this ) );
60
 
        foundnewdir = true;
61
 
        repaint();
62
 
    }
63
 
 
64
 
    if( foundnewdir && foundolddir )
65
 
        return true;
66
 
 
67
 
    FileTreeViewItem* item = static_cast<FileTreeViewItem*>( firstChild() );
68
 
    while( item )
69
 
    {
70
 
        if ( item->changeActiveDir( olddir, newdir, foundnewdir, foundolddir ) )
71
 
            return true;
72
 
        else
73
 
            item = static_cast<FileTreeViewItem*>(item->nextSibling());
74
 
    }
75
 
    return false;
76
 
}
77
 
 
78
 
///////////////////////////////////////////////////////////////////////////////
79
 
 
80
 
bool FileTreeViewItem::setProjectFile( QString const & path, bool pf )
81
 
{
82
 
 
83
 
    if ( this->path() == path && isProjectFile() != pf )
84
 
    {
85
 
        kdDebug( 9017 ) << "FileTreeViewItem::setProjectFile(): " + path << " projectfile: " << pf << endl;
86
 
        m_isProjectFile = pf;
87
 
        setVisible( listView()->shouldBeShown( this ) );
88
 
        repaint();
89
 
        return true;
90
 
    }
91
 
 
92
 
    FileTreeViewItem* item = static_cast<FileTreeViewItem*>( firstChild() );
93
 
    while( item )
94
 
    {
95
 
        if ( item->setProjectFile( path, pf ) )
96
 
            return true;
97
 
        else
98
 
            item = static_cast<FileTreeViewItem*>(item->nextSibling());
99
 
    }
100
 
    return false;
101
 
}
102
 
 
103
 
///////////////////////////////////////////////////////////////////////////////
104
 
 
105
 
void FileTreeViewItem::paintCell(QPainter *p, const QColorGroup &cg,
106
 
    int column, int width, int alignment)
107
 
{
108
 
    if ( listView()->showNonProjectFiles() && isProjectFile() )
109
 
    {
110
 
        QFont font( p->font() );
111
 
        font.setBold( true );
112
 
        p->setFont( font );
113
 
    }
114
 
 
115
 
    if( isActiveDir() )
116
 
    {
117
 
        QFont font( p->font() );
118
 
        font.setItalic( true );
119
 
        p->setFont( font );
120
 
    }
121
 
 
122
 
    QListViewItem::paintCell( p, cg, column, width, alignment );
123
 
}
124
 
 
125
 
 
126
 
///////////////////////////////////////////////////////////////////////////////
127
 
 
128
 
int FileTreeViewItem::compare( QListViewItem *i, int col, bool ascending ) const
129
 
{
130
 
    KFileTreeViewItem* rhs = dynamic_cast<KFileTreeViewItem*>( i );
131
 
    if (rhs)
132
 
    {
133
 
        if (rhs->isDir() && !isDir())
134
 
            return (ascending) ? 1 : -1;
135
 
        else
136
 
            if (!rhs->isDir() && isDir())
137
 
                return (ascending) ? -1 : 1;
138
 
    }
139
 
 
140
 
    return QListViewItem::compare( i, col, ascending );
141
 
}
142
 
 
143
 
///////////////////////////////////////////////////////////////////////////////
144
 
// class BranchItemFactory
145
 
///////////////////////////////////////////////////////////////////////////////