blob: 74cd169f1cfc46ad02a5be158202df193952ef5e (
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
|
/***************************************************************************
draglistbox.cpp - description
-------------------
begin : Sun May 29 2005
copyright : (C) 2005 by Jason Harris
email : kstars@30doradus.org
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include <tqdragobject.h>
#include <klocale.h>
#include <kdebug.h>
#include "draglistbox.h"
DragListBox::DragListBox( TQWidget *parent, const char *name, WFlags f )
: KListBox( parent, name, f ) {
setAcceptDrops( TRUE );
dragging = FALSE;
}
DragListBox::~DragListBox() {}
void DragListBox::dragEnterEvent( TQDragEnterEvent *evt )
{
if ( TQTextDrag::canDecode( evt ) )
evt->accept();
}
bool DragListBox::contains( const TQString &s ) const {
for ( uint i=0; i<count(); ++i )
if ( text(i) == s ) return true;
return false;
}
void DragListBox::dropEvent( TQDropEvent *evt ) {
TQString text;
int i = int( float(evt->pos().y())/float(itemHeight()) + 0.5 ) + topItem();
if ( i > count() + 1 ) i = count() + 1;
if ( TQTextDrag::decode( evt, text ) ) {
//If we dragged an "Ignore item from the FieldList to the FieldPool, then we don't
//need to insert the item, because FieldPool already has a persistent Ignore item.
if ( !( text == i18n("Ignore" ) && TQString(evt->source()->name()) == "FieldList" &&
evt->source() != this )) {
insertItem( text, i );
}
//If we dragged the "Ignore" item from FieldPool to FieldList, then we don't
//want to remove the item from the FieldPool
if ( !( text == i18n("Ignore" ) && TQString(evt->source()->name()) == "FieldPool" &&
evt->source() != this ) ) {
DragListBox *fp = (DragListBox*)evt->source();
fp->removeItem( fp->currentItem() );
}
}
}
void DragListBox::mousePressEvent( TQMouseEvent *evt ) {
TQListBox::mousePressEvent( evt );
dragging = TRUE;
//Record position of the Ignore item; we may have to restore it.
if ( currentText() == i18n("Ignore") )
IgnoreIndex = currentItem();
else
IgnoreIndex = -1;
}
void DragListBox::mouseMoveEvent( TQMouseEvent * )
{
if ( dragging ) {
TQDragObject *drag = new TQTextDrag( currentText(), this );
drag->dragMove();
dragging = FALSE;
}
}
#include "draglistbox.moc"
|