From bd0f3345a938b35ce6a12f6150373b0955b8dd12 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 10 Jul 2011 15:24:15 -0500 Subject: Add Qt3 development HEAD version --- examples/tux/tux.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 examples/tux/tux.cpp (limited to 'examples/tux/tux.cpp') diff --git a/examples/tux/tux.cpp b/examples/tux/tux.cpp new file mode 100644 index 0000000..f02809d --- /dev/null +++ b/examples/tux/tux.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include + +#include + +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(); + +} -- cgit v1.2.3