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
|
/***************************************************************************
* tdefiledndiconview.cpp - description
* -------------------
* begin : Wed Nov 1 2000
* copyright : (C) 2000 by Bj�rn Sahlstr�m
* email : kbjorn@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
//////////////////////////////////////////////////////
// TQt specific includes
#include <tqptrlist.h>
#include <tqapplication.h>
//////////////////////////////////////////////////////
// KDE specific includes
#include <tdefileitem.h>
#include <kiconloader.h>
#include <kdebug.h>
//////////////////////////////////////////////////////
// Application specific includes
#include "tdefiledndiconview.h"
#ifndef AUTO_OPEN_TIME
#define AUTO_OPEN_TIME
static int autoOpenTime = 750;
#endif
//-----------------------------------------------
KFileDnDIconView::KFileDnDIconView( TQWidget *parent, const char *name )
: KFileIconView(parent,name), m_autoOpenTimer( this ),
m_autoOpenTime( autoOpenTime ), m_useAutoOpenTimer( true ),
m_dropItem(0), m_dndEnabled( true )
{
setDnDEnabled( true );
setAutoUpdate( true );
useAutoOpenTimer( true );
}
//-----------------------------------------------
KFileDnDIconView::~KFileDnDIconView(){
}
//-----------------------------------------------
void KFileDnDIconView::readConfig( TDEConfig* config, const TQString& group ) {
TDEConfigGroupSaver cs( config, group );
bool dnd = config->readBoolEntry("EnableDND", true );
setDnDEnabled( dnd );
KFileIconView::readConfig( config, group );
}
//-----------------------------------------------
void KFileDnDIconView::writeConfig( TDEConfig* config, const TQString& group ) {
TDEConfigGroupSaver cs( config, group );
config->writeEntry("EnableDND", m_dndEnabled );
KFileIconView::writeConfig( config, group );
}
//-----------------------------------------------
void KFileDnDIconView::slotOpenFolder(){
if( m_useAutoOpenTimer ) {
m_autoOpenTimer.stop();
if( !m_dropItem )
return;
}
KFileItemListIterator it( * KFileView::items() );
for( ; it.current() ;++it ){
if( (*it)->name() == m_dropItem->text() ) {
if( (*it)->isFile() )
return;
else if( (*it)->isDir() || (*it)->isLink()) {
sig->activate( (*it) );
return;
}
}
}
}
//-----------------------------------------------
void KFileDnDIconView::contentsDragEnterEvent( TQDragEnterEvent *e ) {
if ( ! acceptDrag( e ) ) { // can we decode this ?
e->accept( false ); // No
return;
}
e->acceptAction(); // Yes
TQIconViewItem *i = findItem( contentsToViewport( e->pos() ) );
if ( i && m_useAutoOpenTimer) { // are we over an item ?
m_dropItem = i; // set new m_dropItem
m_autoOpenTimer.start( m_autoOpenTime ); // restart timer
}
}
//-----------------------------------------------
void KFileDnDIconView::contentsDragMoveEvent( TQDragMoveEvent *e ) {
if ( ! acceptDrag( e ) ) { // can we decode this ?
e->accept( false ); // No
return;
}
e->acceptAction(); // Yes
TQIconViewItem *i = findItem( contentsToViewport( e->pos() ) );
if( ! m_useAutoOpenTimer )
return;
if ( i ) { // are we over an item ?
if ( i != m_dropItem ) { // if so, is it a new one ?
m_autoOpenTimer.stop(); // stop timer
m_dropItem = i; // set new m_dropItem
m_autoOpenTimer.start( m_autoOpenTime ); // restart timer
}
}
else
m_autoOpenTimer.stop(); // stop timer
}
//-----------------------------------------------
void KFileDnDIconView::contentsDragLeaveEvent( TQDragLeaveEvent* ) {
if( m_useAutoOpenTimer ) {
m_autoOpenTimer.stop();
m_dropItem = 0L;
}
}
//-----------------------------------------------
void KFileDnDIconView::contentsDropEvent( TQDropEvent* e ) {
if( m_useAutoOpenTimer ) {
m_autoOpenTimer.stop();
m_dropItem = 0L;
}
if( ! acceptDrag( e ) ) {
e->acceptAction( false );
return;
}
e->acceptAction();
// the drop was accepted so lets emit this
KURL::List urls;
KURLDrag::decode( e, urls );
emit dropped( e );
}
//-----------------------------------------------
void KFileDnDIconView::startDrag(){
if ( ! currentItem() ) // is there any selected items ?
return; // nope
dragObject()->dragCopy(); // start the drag
}
//-----------------------------------------------
TQDragObject* KFileDnDIconView::dragObject() {
// create a list of the URL:s that we want to drag
KURL::List urls;
KFileItemListIterator it( * KFileView::selectedItems() );
for ( ; it.current(); ++it ){
urls.append( (*it)->url() );
}
TQPixmap pixmap;
if( urls.count() > 1 )
pixmap = DesktopIcon( "application-vnd.tde.tdemultiple", iconSize() );
if( pixmap.isNull() )
pixmap = currentFileItem()->pixmap( iconSize() );
TQPoint hotspot;
hotspot.setX( pixmap.width() / 2 );
hotspot.setY( pixmap.height() / 2 );
TQDragObject* myDragObject = KURLDrag::newDrag( urls, widget() );
myDragObject->setPixmap( pixmap, hotspot );
return myDragObject;
}
//-----------------------------------------------
void KFileDnDIconView::setAutoOpenTime( const int& time ){
m_autoOpenTime = time;
useAutoOpenTimer();
}
//-----------------------------------------------
void KFileDnDIconView::useAutoOpenTimer( bool use ){
m_useAutoOpenTimer = use;
if ( use )
connect( &m_autoOpenTimer, TQ_SIGNAL( timeout() ),this, TQ_SLOT( slotOpenFolder() ) );
else {
disconnect( &m_autoOpenTimer, TQ_SIGNAL( timeout() ),this, TQ_SLOT( slotOpenFolder() ) );
m_dropItem = 0L;
m_autoOpenTimer.stop();
}
}
//-----------------------------------------------
void KFileDnDIconView::setDnDEnabled( bool useDnD ){
m_dndEnabled = useDnD;
setAcceptDrops( useDnD );
viewport()->setAcceptDrops( useDnD );
}
//-----------------------------------------------
bool KFileDnDIconView::acceptDrag(TQDropEvent* e ) const {
return KURLDrag::canDecode( e ) &&
( e->action() == TQDropEvent::Copy
|| e->action() == TQDropEvent::Move
|| e->action() == TQDropEvent::Link );
}
//-----------------------------------------------
#ifndef NO_INCLUDE_MOCFILES
#include "tdefiledndiconview.moc"
#endif
|