summaryrefslogtreecommitdiffstats
path: root/qtjava/javalib/examples/dragdrop/DropSite.java
blob: 34f41f1226e0a4ba9de1d62cf42404d9ed921cfb (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
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
/***************************************************************************
* $Id$
**
* Drop site example implementation
**
* Created : 979899
**
* Copyright (C) 1997 by Trolltech AS.  All rights reserved.
**
* This file is part of an example program for Qt.  This example
* program may be used, distributed and modified without limitation.
**
****************************************************************************/
import org.kde.qt.*;
import java.util.*;


class DropSite extends TQLabel
{
	SecretSource s;

void setSecretSource(SecretSource source)
{
	s = source;
}

DropSite( TQWidget  parent )
{
	this(parent, null);
}

DropSite( TQWidget  parent, String  name )
{
    super( parent, name );
    setAcceptDrops(true);
}


{
    // nothing necessary
}


protected void dragMoveEvent( TQDragMoveEvent  e )
{
    // Check if you want the drag at e.pos()...
    // Give the user some feedback...
}


protected void dragEnterEvent( TQDragEnterEvent e )
{
    // Check if you want the drag...
    if ( SecretDrag.canDecode( e )
      || TQTextDrag.canDecode( e )
      || TQImageDrag.canDecode( e )
      || TQUriDrag.canDecode( e ) ) {
	e.accept();
	}

    // Give the user some feedback...
    String t = "";
    for( int i=0; e.format( i ) != null; i++ ) {
		t += "\n";
	    t += e.format( i );
    }
    emit("message", t );
    setBackgroundColor(white());
}

protected void dragLeaveEvent( TQDragLeaveEvent e  )
{
    // Give the user some feedback...
    emit("message", "");
    setBackgroundColor(lightGray());
}


protected void dropEvent( TQDropEvent  e )
{
    setBackgroundColor(lightGray());

    // Try to decode to the data you understand...

    StringBuffer str = new StringBuffer("");
	if ( TQTextDrag.decode( e, str ) ) {
	setText( str.toString() );
	setMinimumSize( minimumSize().expandedTo( sizeHint() ) );
	return;
    }

    TQPixmap pm = new TQPixmap();
    if ( TQImageDrag.decode( e, pm ) ) {
	setPixmap( pm );
	setMinimumSize( minimumSize().expandedTo( sizeHint() ) );
	return;
    }

	ArrayList strings = new ArrayList();
    if ( TQUriDrag.decode( e, strings ) ) {
	String m = "Full URLs:\n";
	Iterator it = strings.iterator();
	while (it.hasNext())
		m += "   " + (String) it.next() + "\n";
	ArrayList files = new ArrayList();
	if ( TQUriDrag.decodeLocalFiles( e, files ) ) {
	    m = m + "Files:\n";
		Iterator i = strings.iterator();
		while (i.hasNext())
		m = m + "   " + (String) i.next() + "\n";
	}
	setText( m );
	setMinimumSize( minimumSize().expandedTo( sizeHint() ) );
	return;
    }

    if ( SecretDrag.decode( e, str ) ) {
	setText( str.toString() );
	setMinimumSize( minimumSize().expandedTo( sizeHint() ) );
	return;
    }
}

protected void mousePressEvent( TQMouseEvent  e )
{
    TQDragObject drobj;
    if ( pixmap() != null ) {
	drobj = new TQImageDrag( pixmap().convertToImage(), this );
	TQPixmap pm = new TQPixmap();
	pm.convertFromImage(pixmap().convertToImage().smoothScale(
	    pixmap().width()/3,pixmap().height()/3));
	drobj.setPixmap(pm,new TQPoint(-5,-7));
	// Try it.
//	new DragMoviePlayer(drobj);
    } else {
	drobj = new TQTextDrag( text(), this );
    }
    drobj.dragCopy();
}

class DragMoviePlayer extends TQObject {
    TQDragObject dobj;
    TQMovie movie;

DragMoviePlayer( TQDragObject p )
{
//    TQObject(p),
    dobj = p;
    movie = new TQMovie("trolltech.gif" );
    movie.connectUpdate(this,SLOT("updatePixmap(TQRect)"));
}

void updatePixmap( TQRect rect )
{
    dobj.setPixmap(movie.framePixmap());
}


}

void backgroundColorChange( TQColor color )
{
    // Reduce flicker by using repaint() rather than update()
    repaint();
}

}