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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
/* This file is part of the KDE project
Copyright (C) 2000 David Faure <faure@kde.org>
2000 Carsten Pfeiffer <pfeiffer@kde.org>
2002 Klaas Freitag <freitag@suse.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef kfile_tree_view_h
#define kfile_tree_view_h
#include <tqmap.h>
#include <tqpoint.h>
#include <tqpixmap.h>
#include <tqstrlist.h>
#include <tqtooltip.h>
#include <klistview.h>
#include <kdirnotify.h>
#include <kio/job.h>
#include <kfiletreeviewitem.h>
#include <kfiletreebranch.h>
class TQTimer;
class KIO_EXPORT KFileTreeViewToolTip : public QToolTip
{
public:
KFileTreeViewToolTip( TQListView *view ) : TQToolTip( view ), m_view( view ) {}
protected:
virtual void maybeTip( const TQPoint & );
private:
TQListView *m_view;
};
/**
* The filetreeview offers a treeview on the file system which behaves like
* a QTreeView showing files and/or directories in the file system.
*
* KFileTreeView is able to handle more than one URL, represented by
* KFileTreeBranch.
*
* Typical usage:
* 1. create a KFileTreeView fitting in your layout and add columns to it
* 2. call addBranch to create one or more branches
* 3. retrieve the root item with KFileTreeBranch::root() and set it open
* if desired. That starts the listing.
*/
class KIO_EXPORT KFileTreeView : public KListView
{
Q_OBJECT
public:
KFileTreeView( TQWidget *parent, const char *name = 0 );
virtual ~KFileTreeView();
/**
* @return the current (i.e. selected) item
*/
KFileTreeViewItem * currentKFileTreeViewItem() const;
/**
* @return the URL of the current selected item.
*/
KURL currentURL() const;
/**
* Adds a branch to the treeview item.
*
* This high-level function creates the branch, adds it to the treeview and
* connects some signals. Note that directory listing does not start until
* a branch is expanded either by opening the root item by user or by setOpen
* on the root item.
*
* @returns a pointer to the new branch or zero
* @param path is the base url of the branch
* @param name is the name of the branch, which will be the text for column 0
* @param showHidden says if hidden files and directories should be visible
*/
KFileTreeBranch* addBranch( const KURL &path, const TQString& name, bool showHidden = false );
/**
* same as the function above but with a pixmap to set for the branch.
*/
virtual KFileTreeBranch* addBranch( const KURL &path, const TQString& name ,
const TQPixmap& pix, bool showHidden = false );
/**
* same as the function above but letting the user create the branch.
*/
virtual KFileTreeBranch* addBranch( KFileTreeBranch * );
/**
* removes the branch from the treeview.
* @param branch is a pointer to the branch
* @returns true on success.
*/
virtual bool removeBranch( KFileTreeBranch *branch );
/**
* @returns a pointer to the KFileTreeBranch in the KFileTreeView or zero on failure.
* @param searchName is the name of a branch
*/
KFileTreeBranch *branch( const TQString& searchName );
/**
* @returns a list of pointers to all existing branches in the treeview.
**/
KFileTreeBranchList& branches();
/**
* set the directory mode for branches. If true is passed, only directories will be loaded.
* @param branch is a pointer to a KFileTreeBranch
*/
virtual void setDirOnlyMode( KFileTreeBranch *branch, bool );
/**
* searches a branch for a KFileTreeViewItem identified by the relative url given as
* second parameter. The method adds the branches base url to the relative path and finds
* the item.
* @returns a pointer to the item or zero if the item does not exist.
* @param brnch is a pointer to the branch to search in
* @param relUrl is the branch relativ url
*/
KFileTreeViewItem *findItem( KFileTreeBranch* brnch, const TQString& relUrl );
/**
* see method above, differs only in the first parameter. Finds the branch by its name.
*/
KFileTreeViewItem *findItem( const TQString& branchName, const TQString& relUrl );
/**
* @returns a flag indicating if extended folder pixmaps are displayed or not.
*/
bool showFolderOpenPixmap() const { return m_wantOpenFolderPixmaps; };
public slots:
/**
* set the flag to show 'extended' folder icons on or off. If switched on, folders will
* have an open folder pixmap displayed if their children are visible, and the standard
* closed folder pixmap (from mimetype folder) if they are closed.
* If switched off, the plain mime pixmap is displayed.
* @param showIt = false displays mime type pixmap only
*/
virtual void setShowFolderOpenPixmap( bool showIt = true )
{ m_wantOpenFolderPixmaps = showIt; }
protected:
/**
* @returns true if we can decode the drag and support the action
*/
virtual bool acceptDrag(TQDropEvent* event) const;
virtual TQDragObject * dragObject();
virtual void startAnimation( KFileTreeViewItem* item, const char * iconBaseName = "kde", uint iconCount = 6 );
virtual void stopAnimation( KFileTreeViewItem* item );
virtual void contentsDragEnterEvent( TQDragEnterEvent *e );
virtual void contentsDragMoveEvent( TQDragMoveEvent *e );
virtual void contentsDragLeaveEvent( TQDragLeaveEvent *e );
virtual void contentsDropEvent( TQDropEvent *ev );
protected slots:
virtual void slotNewTreeViewItems( KFileTreeBranch*,
const KFileTreeViewItemList& );
virtual void slotSetNextUrlToSelect( const KURL &url )
{ m_nextUrlToSelect = url; }
virtual TQPixmap itemIcon( KFileTreeViewItem*, int gap = 0 ) const;
private slots:
void slotExecuted( TQListViewItem * );
void slotExpanded( TQListViewItem * );
void slotCollapsed( TQListViewItem *item );
void slotSelectionChanged();
void slotAnimation();
void slotAutoOpenFolder();
void slotOnItem( TQListViewItem * );
void slotItemRenamed(TQListViewItem*, const TQString &, int);
void slotPopulateFinished( KFileTreeViewItem* );
signals:
void onItem( const TQString& );
/* New signals if you like it ? */
void dropped( TQWidget*, TQDropEvent* );
void dropped( TQWidget*, TQDropEvent*, KURL::List& );
void dropped( KURL::List&, KURL& );
// The drop event allows to differentiate between move and copy
void dropped( TQWidget*, TQDropEvent*, KURL::List&, KURL& );
void dropped( TQDropEvent *e, TQListViewItem * after);
void dropped(KFileTreeView *, TQDropEvent *, TQListViewItem *);
void dropped(TQDropEvent *e, TQListViewItem * parent, TQListViewItem * after);
void dropped(KFileTreeView *, TQDropEvent *, TQListViewItem *, TQListViewItem *);
protected:
KURL m_nextUrlToSelect;
private:
// Returns whether item is still a valid item in the tree
bool isValidItem( TQListViewItem *item);
void clearTree();
/* List that holds the branches */
KFileTreeBranchList m_branches;
struct AnimationInfo
{
AnimationInfo( const char * _iconBaseName, uint _iconCount, const TQPixmap & _originalPixmap )
: iconBaseName(_iconBaseName), iconCount(_iconCount), iconNumber(1), originalPixmap(_originalPixmap) {}
AnimationInfo() : iconCount(0) {}
TQCString iconBaseName;
uint iconCount;
uint iconNumber;
TQPixmap originalPixmap;
};
typedef TQMap<KFileTreeViewItem *, AnimationInfo> MapCurrentOpeningFolders;
MapCurrentOpeningFolders m_mapCurrentOpeningFolders;
TQTimer *m_animationTimer;
TQPoint m_dragPos;
bool m_bDrag;
bool m_wantOpenFolderPixmaps; // Flag weather the folder should have open-folder pixmaps
TQListViewItem *m_currentBeforeDropItem; // The item that was current before the drag-enter event happened
TQListViewItem *m_dropItem; // The item we are moving the mouse over (during a drag)
TQStrList m_lstDropFormats;
TQPixmap m_openFolderPixmap;
TQTimer *m_autoOpenTimer;
KFileTreeViewToolTip m_toolTip;
protected:
virtual void virtual_hook( int id, void* data );
private:
class KFileTreeViewPrivate;
KFileTreeViewPrivate *d;
};
#endif
|