diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 90825e2392b2d70e43c7a25b8a3752299a933894 (patch) | |
tree | e33aa27f02b74604afbfd0ea4f1cfca8833d882a /qtjava/javalib/examples/picture | |
download | tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'qtjava/javalib/examples/picture')
-rw-r--r-- | qtjava/javalib/examples/picture/PictureDisplay.java | 119 | ||||
-rw-r--r-- | qtjava/javalib/examples/picture/car_orig.pic | bin | 0 -> 1872 bytes | |||
-rw-r--r-- | qtjava/javalib/examples/picture/flag.bmp | bin | 0 -> 1650 bytes |
3 files changed, 119 insertions, 0 deletions
diff --git a/qtjava/javalib/examples/picture/PictureDisplay.java b/qtjava/javalib/examples/picture/PictureDisplay.java new file mode 100644 index 00000000..34b026b4 --- /dev/null +++ b/qtjava/javalib/examples/picture/PictureDisplay.java @@ -0,0 +1,119 @@ +/**************************************************************************** +** $Id$ +** +** Copyright (C) 1992-2000 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.*; + +class PictureDisplay extends QWidget // picture display widget +{ + +static void paintCar( QPainter p ) // paint a car +{ + QPointArray a = new QPointArray(); + QBrush brush = new QBrush( Qt.yellow(), Qt.SolidPattern ); + p.setBrush( brush ); // use solid, yellow brush + + a.setPoints( 5, new short[] { 50,50, 350,50, 450,120, 450,250, 50,250 } ); + p.drawPolygon( a ); // draw car body + + QFont f = new QFont( "courier", 12, QFont.Bold, false ); + p.setFont( f ); + + QColor windowColor = new QColor( 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 = new QPixmap(); + if ( pixmap.load("flag.bmp") ) // load and draw image + p.drawPixmap( 100, 90, 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 +} + + + +private QPicture pict; +private String name; + +public PictureDisplay( String fileName ) +{ + pict = new QPicture(); + name = fileName; + if ( !pict.load(fileName) ) { // cannot load picture + pict = null; + name = "Not able to load picture: " + fileName; + } +} + +protected void paintEvent( QPaintEvent event ) +{ + QPainter paint = new QPainter( this ); // paint widget + if ( pict != null ) + paint.drawPicture( pict ); // draw picture + else + paint.drawText( rect(), AlignCenter, name ); +} + +protected void keyPressEvent( QKeyEvent k ) +{ +// switch ( tolower(k.ascii()) ) { + switch ( k.ascii() ) { + case 'r': // reload + pict.load( name ); + update(); + break; + case 'q': // quit + QApplication.exit(); + break; + } +} + + +static public void main( String[] args ) +{ + QApplication a = new QApplication( args ); // QApplication required! + + String fileName = "car.pic"; // default picture file name + + if ( args.length == 1 ) // use argument as file name + fileName = args[0]; + + if ( !QFile.exists(fileName) ) { + QPicture pict = new QPicture(); // our picture + QPainter paint = new QPainter(); // our painter + + paint.begin( pict ); // begin painting onto picture + paintCar( paint ); // paint! + paint.end(); // painting done + + pict.save( fileName ); // save picture + QMessageBox.information(null, "Qt picture example", "Saved. Run me again!"); + return; + } else { + PictureDisplay test = new PictureDisplay( fileName ); // create picture display + a.setMainWidget( test); // set main widget + test.show(); // show it + + a.exec(); // start event loop + return; + } +} + +static { + qtjava.initialize(); +} + +} + diff --git a/qtjava/javalib/examples/picture/car_orig.pic b/qtjava/javalib/examples/picture/car_orig.pic Binary files differnew file mode 100644 index 00000000..a0141b75 --- /dev/null +++ b/qtjava/javalib/examples/picture/car_orig.pic diff --git a/qtjava/javalib/examples/picture/flag.bmp b/qtjava/javalib/examples/picture/flag.bmp Binary files differnew file mode 100644 index 00000000..b36afdfb --- /dev/null +++ b/qtjava/javalib/examples/picture/flag.bmp |