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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
/***************************************************************************
* Copyright (C) 2006 - 2008 Robert Hogan *
* robert@roberthogan.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. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "dndlistview.h"
#include "torkconfig.h"
#include "kdebug.h"
#include <qapplication.h>
#include <qheader.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include <qsimplerichtext.h>
#include <qpainter.h>
DndListView::DndListView( QWidget * parent, const char * name, WFlags f ) :
QListView( parent, name, f ), oldCurrent( 0 ),
dropItem( 0 ), mousePressed( FALSE ),m_recentDrop( FALSE)
{
setAllColumnsShowFocus( TRUE );
//setResizeMode( QListView::AllColumns );
setSelectionMode( QListView::Extended );
setAcceptDrops( TRUE );
viewport()->setAcceptDrops( TRUE );
}
//static const int autoopenTime = 750;
void DndListView::contentsDragEnterEvent( QDragEnterEvent *e )
{
setSelectionMode( QListView::Single );
if ( !QTextDrag::canDecode( e ) ) {
e->ignore();
return;
}
oldCurrent = currentItem();
QListViewItem *i = itemAt( contentsToViewport(e->pos()) );
if ( i ) {
dropItem = i;
/* autoopen_timer->start( autoopenTime );*/
}
}
void DndListView::contentsDragMoveEvent( QDragMoveEvent *e )
{
if ( !QTextDrag::canDecode( e ) ) {
e->ignore();
return;
}
QPoint vp = contentsToViewport( ( (QDragMoveEvent*)e )->pos() );
QListViewItem *i = itemAt( vp );
//!(e->source() == this) &&
if ((QString(this->name()).contains("circuitList")) &&
(QString(e->source()->name()).contains("serverList"))) {
if ( i ){
setSelected( i, TRUE );
if ( i != dropItem ) {
dropItem = i;
}
}
e->accept();
}else if ((QString(this->name()).contains("circuitList")) &&
(QString(e->source()->name()).contains("circuitList"))) {
if ( i ){
setSelected( i, TRUE );
if ( i != dropItem ) {
dropItem = i;
}
}
e->accept();
}else if ((QString(this->name()).contains("circuitList")) &&
(QString(e->source()->name()).contains("ORList"))) {
if ( i ){
setSelected( i, TRUE );
if ( i != dropItem ) {
dropItem = i;
}
}
e->accept();
}else if ((QString(this->name()).contains("circuitList")) &&
(QString(e->source()->name()).contains("streamList"))) {
if ( i ){
setSelected( i, TRUE );
if ( i != dropItem ) {
dropItem = i;
}
}
e->accept();
}else {
e->ignore();
dropItem = 0;
}
}
void DndListView::contentsDragLeaveEvent( QDragLeaveEvent * )
{
/* autoopen_timer->stop();*/
dropItem = 0;
setCurrentItem( oldCurrent );
setSelected( oldCurrent, TRUE );
setSelectionMode( QListView::Extended );
}
void DndListView::contentsDropEvent( QDropEvent *e )
{
// autoopen_timer->stop();
m_recentDrop = true;
dropTimer = startTimer( 3000 );
setSelectionMode( QListView::Extended );
QString text;
if ( !QTextDrag::decode( e, text ) ) {
e->ignore();
return;
}
m_mousepos = e->pos() ;
QListViewItem *item = itemAt( contentsToViewport(e->pos()) );
if (QString(this->name()).contains("circuitList")){
e->accept();
if ( item ) {
if (QString(e->source()->name()).contains("serverList"))
emit extendCircuit(item->text(0),text,true);
else if (QString(e->source()->name()).contains("circuitList"))
emit extendCircuit(item->text(0),text, true);
else if (QString(e->source()->name()).contains("ORList"))
emit extendCircuit(item->text(0),text, false);
else if (QString(e->source()->name()).contains("streamList"))
emit attach(item->text(0),text);
} else{
if (QString(e->source()->name()).contains("serverList"))
emit createCircuit(text,true);
else if (QString(e->source()->name()).contains("ORList"))
emit createCircuit(text,false);
}
}else
e->ignore();
}
void DndListView::contentsMousePressEvent( QMouseEvent* e )
{
QPoint p( contentsToViewport( e->pos() ) );
//QListViewItem *i = itemAt( p );
/* if ( i ) {
// if the user clicked into the root decoration of the item, don't try to start a drag!
if ( p.x() > header()->cellPos( header()->mapToActual( 0 ) ) +
treeStepSize() * ( i->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ||
p.x() < header()->cellPos( header()->mapToActual( 0 ) ) ) {
presspos = e->pos();
mousePressed = TRUE;
}
}*/
if (e->button() == Qt::LeftButton){
presspos = e->pos();
mousePressed = TRUE;
}
QListView::contentsMousePressEvent( e );
}
void DndListView::contentsMouseMoveEvent( QMouseEvent* e )
{
if ( mousePressed ) {
kdDebug() << "in mouse move drag" << endl;
mousePressed = FALSE;
//QListViewItem *item = itemAt( contentsToViewport(presspos) );
int column;
if (QString(this->name()).contains("circuitList"))
column = 2;
else if (QString(this->name()).contains("ORList"))
column = 1;
else if (QString(this->name()).contains("streamList"))
column = 0;
else
column = 2;
QString selectedItems;
QListViewItemIterator it(this, QListViewItemIterator::Selected);
while ( it.current() ) {
if (this->isSelected( it.current()))
selectedItems.append(it.current()->text(column)+" ");
++it;
}
if (!selectedItems.isEmpty()){
selectedItems = selectedItems.stripWhiteSpace();
QDragObject *d = new QTextDrag( selectedItems, this );
d->dragCopy(); // do NOT delete d.
}
}else
QListView::contentsMouseMoveEvent( e );
}
void DndListView::contentsMouseReleaseEvent( QMouseEvent* e)
{
/* kdDebug() << "mouse released" << endl;*/
mousePressed = FALSE;
QListView::contentsMouseReleaseEvent(e);
}
void DndListView::mouseReleaseEvent( QMouseEvent* e)
{
/* kdDebug() << "mouse released" << endl;*/
mousePressed = FALSE;
QListView::mouseReleaseEvent(e);
}
QPoint DndListView::getMousePos()
{
return m_mousepos;
}
void DndListView::timerEvent( QTimerEvent * )
{
//if ( e->timerId() == dropTimer ) // stop showing date
m_recentDrop = false;
killTimer( dropTimer );
dropTimer = -1;
}
void
DndListView::viewportPaintEvent( QPaintEvent *e )
{
QListView::viewportPaintEvent( e );
if (!TorkConfig::displayBubble())
return;
// Superimpose bubble help
// Taken from mediabrowser.cpp in Amarok
if (( childCount() == 0 ) && (QString(this->name()).contains("streamList")))
{
QPainter p( viewport() );
QSimpleRichText t( i18n(
"<div align=center>"
"<h4>Almost Everything Is Clickable.</h4>"
"You can drag servers to create circuits. You can drag connections onto circuits "
" if you right-click here first. "
"You can right-click on servers to include/exclude them or their country from your "
"connections. Remember though: <b> messing with stuff is fun, but generally bad for "
"anonymity.</b>"
"</div>" ), QApplication::font() );
t.setWidth( width() - 50 );
const uint w = t.width() + 20;
const uint h = t.height() + 20;
p.setBrush( colorGroup().background() );
p.drawRoundRect( 15, 15, w, h, (8*200)/w, (8*200)/h );
t.draw( &p, 20, 20, QRect(), colorGroup() );
}
}
// QDragObject *DndListView::dragObject()
// {
// kdDebug() << "dragging item" << endl;
// return new QTextDrag( currentItem()->text(0), this );
// }
// void DndListView::dragEnterEvent( QDragEnterEvent *evt )
// {
// kdDebug() << "drag enter event" << endl;
// if ( QTextDrag::canDecode( evt ) )
// evt->accept();
// }
//
//
// void DndListView::dropEvent( QDropEvent *evt )
// {
// QString text;
//
// if ( QTextDrag::decode( evt, text ) )
// kdDebug() << text << endl;
// }
//
//
// void DndListView::contentsMousePressEvent( QMouseEvent *evt )
// {
// dragging = TRUE;
// kdDebug() << "draggng mouse" << endl;
// QListView::mousePressEvent( evt );
//
// }
//
//
// void DndListView::contentsMouseMoveEvent( QMouseEvent * )
// {
// if ( dragging ) {
// kdDebug() << "dragging" << endl;
// QDragObject *d = new QTextDrag( currentItem()->text(0), this );
// d->dragCopy(); // do NOT delete d.
// dragging = FALSE;
// }
// }
#include "dndlistview.moc"
|