summaryrefslogtreecommitdiffstats
path: root/qtjava/javalib/examples/tux/MoveMe.java
blob: 185ac7764824a1637e3f1e4b69b93c58ea6c2a61 (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

import org.kde.qt.*;

class MoveMe  extends TQWidget
{
public    MoveMe( TQWidget parent, String name, int f)
{
	super(parent,name, f);
}

private    TQPoint clickPos;

protected void mousePressEvent( TQMouseEvent e )
{
    //    if ( e.button() == LeftButton )
	clickPos = e.pos();
}

protected void mouseMoveEvent( TQMouseEvent e )
{
    //    if ( e.state() & LeftButton )
	move( new TQPoint( e.globalPos().x() - clickPos.x(),
	                  e.globalPos().y() - clickPos.y() ) );
}



public static void main(String[] args)
{
    TQApplication a = new TQApplication( args );

    String fn="tux.png";

    if ( args.length >= 1 )
	fn = args[0];

    if ( ! TQFile.exists( fn ) )
	System.exit( 1 );

    TQImage img = new TQImage( fn );
    TQPixmap p = new TQPixmap();
    p.convertFromImage( img );
    if ( p.mask() == null )
	if ( img.hasAlphaBuffer() ) {
	    TQBitmap bm = new TQBitmap(img.createAlphaMask());
	    p.setMask( bm );
	} else {
	    TQBitmap bm = new TQBitmap(img.createHeuristicMask());
	    p.setMask( bm );
	}
    MoveMe w = new MoveMe(null,null,Qt.WStyle_Customize|Qt.WStyle_NoBorder);
    w.setBackgroundPixmap( p );
    w.setFixedSize( p.size() );
    if ( p.mask() != null )
	w.setMask( p.mask() );
    w.show();
    a.setMainWidget(w);


    a.exec();
    return;
}

	static {
		qtjava.initialize();
	}

}