summaryrefslogtreecommitdiffstats
path: root/examples/tux/tux.cpp
blob: f02809d7409a6162731809bcca319ba879ce1261 (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
#include <qapplication.h>
#include <qwidget.h>
#include <qimage.h>
#include <qpixmap.h>
#include <qbitmap.h>
#include <qfile.h>

#include <stdlib.h>

class MoveMe : public QWidget
{
public:
    MoveMe( QWidget *parent=0, const char *name=0, WFlags f = 0)
	:QWidget(parent,name, f) {}

protected:
    void mousePressEvent( QMouseEvent *);
    void mouseMoveEvent( QMouseEvent *);
private:
    QPoint clickPos;
};

void MoveMe::mousePressEvent( QMouseEvent *e )
{
    clickPos = e->pos();
}

void MoveMe::mouseMoveEvent( QMouseEvent *e )
{
    move( e->globalPos() - clickPos );
}



int main( int argc, char **argv )
{
    QApplication a( argc, argv );

    QString fn="tux.png";

    if ( argc >= 2 )
	fn = argv[1];

    if ( ! QFile::exists( fn ) )
	exit( 1 );

    QImage img( fn );
    QPixmap p;
    p.convertFromImage( img );
    if ( !p.mask() )
	if ( img.hasAlphaBuffer() ) {
	    QBitmap bm;
	    bm = img.createAlphaMask();
	    p.setMask( bm );
	} else {
	    QBitmap bm;
	    bm = img.createHeuristicMask();
	    p.setMask( bm );
	}
    MoveMe w(0,0,Qt::WStyle_Customize|Qt::WStyle_NoBorder);
    w.setBackgroundPixmap( p );
    w.setFixedSize( p.size() );
    if ( p.mask() )
	w.setMask( *p.mask() );
    w.show();
    a.setMainWidget(&w);


    return a.exec();

}