diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-07-10 15:24:15 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-07-10 15:24:15 -0500 |
commit | bd0f3345a938b35ce6a12f6150373b0955b8dd12 (patch) | |
tree | 7a520322212d48ebcb9fbe1087e7fca28b76185c /examples/picture | |
download | qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.tar.gz qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.zip |
Add Qt3 development HEAD version
Diffstat (limited to 'examples/picture')
-rw-r--r-- | examples/picture/README | 5 | ||||
-rw-r--r-- | examples/picture/car_orig.pic | bin | 0 -> 1872 bytes | |||
-rw-r--r-- | examples/picture/flag.bmp | bin | 0 -> 2386 bytes | |||
-rw-r--r-- | examples/picture/picture.cpp | 130 | ||||
-rw-r--r-- | examples/picture/picture.doc | 17 | ||||
-rw-r--r-- | examples/picture/picture.pro | 10 |
6 files changed, 162 insertions, 0 deletions
diff --git a/examples/picture/README b/examples/picture/README new file mode 100644 index 0000000..84373a4 --- /dev/null +++ b/examples/picture/README @@ -0,0 +1,5 @@ +This program demonstrates how to record, save, load and replay a +picture. + +Run picture to record car.pic, then run it again to replay it. + diff --git a/examples/picture/car_orig.pic b/examples/picture/car_orig.pic Binary files differnew file mode 100644 index 0000000..a0141b7 --- /dev/null +++ b/examples/picture/car_orig.pic diff --git a/examples/picture/flag.bmp b/examples/picture/flag.bmp Binary files differnew file mode 100644 index 0000000..04fc3e4 --- /dev/null +++ b/examples/picture/flag.bmp diff --git a/examples/picture/picture.cpp b/examples/picture/picture.cpp new file mode 100644 index 0000000..380befb --- /dev/null +++ b/examples/picture/picture.cpp @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include <qapplication.h> +#include <qpainter.h> +#include <qpicture.h> +#include <qpixmap.h> +#include <qwidget.h> +#include <qmessagebox.h> +#include <qfile.h> +#include <ctype.h> + + +void paintCar( QPainter *p ) // paint a car +{ + QPointArray a; + QBrush brush( Qt::yellow, Qt::SolidPattern ); + p->setBrush( brush ); // use solid, yellow brush + + a.setPoints( 5, 50,50, 350,50, 450,120, 450,250, 50,250 ); + p->drawPolygon( a ); // draw car body + + QFont f( "courier", 12, QFont::Bold ); + p->setFont( f ); + + QColor windowColor( 120, 120, 255 ); // a light blue color + brush.setColor( windowColor ); // set this brush color + p->setBrush( brush ); // set brush + p->drawRect( 80, 80, 250, 70 ); // car window + p->drawText( 180, 80, 150, 70, Qt::AlignCenter, "-- Qt --\nTrolltech AS" ); + + QPixmap pixmap; + if ( pixmap.load("flag.bmp") ) // load and draw image + p->drawPixmap( 100, 85, pixmap ); + + p->setBackgroundMode( Qt::OpaqueMode ); // set opaque mode + p->setBrush( Qt::DiagCrossPattern ); // black diagonal cross pattern + p->drawEllipse( 90, 210, 80, 80 ); // back wheel + p->setBrush( Qt::CrossPattern ); // black cross fill pattern + p->drawEllipse( 310, 210, 80, 80 ); // front wheel +} + + +class PictureDisplay : public QWidget // picture display widget +{ +public: + PictureDisplay( const char *fileName ); + ~PictureDisplay(); +protected: + void paintEvent( QPaintEvent * ); + void keyPressEvent( QKeyEvent * ); +private: + QPicture *pict; + QString name; +}; + +PictureDisplay::PictureDisplay( const char *fileName ) +{ + pict = new QPicture; + name = fileName; + if ( !pict->load(fileName) ) { // cannot load picture + delete pict; + pict = 0; + name.sprintf( "Not able to load picture: %s", fileName ); + } +} + +PictureDisplay::~PictureDisplay() +{ + delete pict; +} + +void PictureDisplay::paintEvent( QPaintEvent * ) +{ + QPainter paint( this ); // paint widget + if ( pict ) + paint.drawPicture( *pict ); // draw picture + else + paint.drawText( rect(), AlignCenter, name ); +} + +void PictureDisplay::keyPressEvent( QKeyEvent *k ) +{ + switch ( tolower(k->ascii()) ) { + case 'r': // reload + pict->load( name ); + update(); + break; + case 'q': // quit + QApplication::exit(); + break; + } +} + + +int main( int argc, char **argv ) +{ + QApplication a( argc, argv ); // QApplication required! + + const char *fileName = "car.pic"; // default picture file name + + if ( argc == 2 ) // use argument as file name + fileName = argv[1]; + + if ( !QFile::exists(fileName) ) { + QPicture pict; // our picture + QPainter paint; // our painter + + paint.begin( &pict ); // begin painting onto picture + paintCar( &paint ); // paint! + paint.end(); // painting done + + pict.save( fileName ); // save picture + QMessageBox::information(0, "Qt Example - Picture", "Saved. Run me again!"); + return 0; + } else { + PictureDisplay test( fileName ); // create picture display + a.setMainWidget( &test); // set main widget + test.setCaption("Qt Example - Picture"); + test.show(); // show it + + return a.exec(); // start event loop + } +} diff --git a/examples/picture/picture.doc b/examples/picture/picture.doc new file mode 100644 index 0000000..fa4d257 --- /dev/null +++ b/examples/picture/picture.doc @@ -0,0 +1,17 @@ +/* +*/ +/*! \page picture-example.html + + \ingroup examples + \title Picture + + This example shows how to make a picture, store it to a file, and read it as + a set of drawing commands. + + <hr> + + Implementation: + + \include picture/picture.cpp +*/ + diff --git a/examples/picture/picture.pro b/examples/picture/picture.pro new file mode 100644 index 0000000..39e64b7 --- /dev/null +++ b/examples/picture/picture.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = picture + +CONFIG += qt warn_on release +DEPENDPATH = ../../include + +REQUIRES = full-config + +HEADERS = +SOURCES = picture.cpp |