summaryrefslogtreecommitdiffstats
path: root/examples/dirview/dirview.h
blob: 9885345098cd9930db19ad08d2442fbb66c8a7c8 (plain)
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
/****************************************************************************
**
** Copyright (C) 1992-2008 Trolltech ASA.  All rights reserved.
**
** This file is part of an example program for TQt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#ifndef DIRVIEW_H
#define DIRVIEW_H

#include <ntqlistview.h>
#include <ntqstring.h>
#include <ntqfile.h>
#include <ntqfileinfo.h>
#include <ntqtimer.h>

class TQWidget;
class TQDragEnterEvent;
class TQDragMoveEvent;
class TQDragLeaveEvent;
class TQDropEvent;

class FileItem : public TQListViewItem
{
public:
    FileItem( TQListViewItem *parent, const TQString &s1, const TQString &s2 )
	: TQListViewItem( parent, s1, s2 ), pix( 0 ) {}

    const TQPixmap *pixmap( int i ) const;
#if !defined(Q_NO_USING_KEYWORD)
    using TQListViewItem::setPixmap;
#endif
    void setPixmap( TQPixmap *p );

private:
    TQPixmap *pix;

};

class Directory : public TQListViewItem
{
public:
    Directory( TQListView * parent, const TQString& filename );
    Directory( Directory * parent, const TQString& filename, const TQString &col2 )
	: TQListViewItem( parent, filename, col2 ), pix( 0 ) {}
    Directory( Directory * parent, const TQString& filename );

    TQString text( int column ) const;

    TQString fullName();

    void setOpen( bool );
    void setup();

    const TQPixmap *pixmap( int i ) const;
#if !defined(Q_NO_USING_KEYWORD)
    using TQListViewItem::setPixmap;
#endif
    void setPixmap( TQPixmap *p );

private:
    TQFile f;
    Directory * p;
    bool readable;
    bool showDirsOnly;
    TQPixmap *pix;

};

class DirectoryView : public TQListView
{
    Q_OBJECT

public:
    DirectoryView( TQWidget *parent = 0, const char *name = 0, bool sdo = FALSE );
    bool showDirsOnly() { return dirsOnly; }

public slots:
    void setDir( const TQString & );

signals:
    void folderSelected( const TQString & );

protected slots:
    void slotFolderSelected( TQListViewItem * );
    void openFolder();

protected:
    void contentsDragEnterEvent( TQDragEnterEvent *e );
    void contentsDragMoveEvent( TQDragMoveEvent *e );
    void contentsDragLeaveEvent( TQDragLeaveEvent *e );
    void contentsDropEvent( TQDropEvent *e );
    void contentsMouseMoveEvent( TQMouseEvent *e );
    void contentsMousePressEvent( TQMouseEvent *e );
    void contentsMouseReleaseEvent( TQMouseEvent *e );

private:
    TQString fullPath(TQListViewItem* item);
    bool dirsOnly;
    TQListViewItem *oldCurrent;
    TQListViewItem *dropItem;
    TQTimer* autoopen_timer;
    TQPoint presspos;
    bool mousePressed;

};

#endif