diff options
author | mueller <mueller@afe2bf4a-e733-0410-8a33-86f594647bc7> | 1999-12-15 19:25:10 (GMT) |
---|---|---|
committer | mueller <mueller@afe2bf4a-e733-0410-8a33-86f594647bc7> | 1999-12-15 19:25:10 (GMT) |
commit | 719f0a35063be88eddcc4ed8fe7a940de47ef20c (patch) | |
tree | cc1cd70cf5761ddf72ff114c0b65576c3f4c1d2a /tmake/example | |
parent | bd30c025c4651ddda467f1af09d4c7ccab397bde (diff) | |
download | Doxygen-719f0a35063be88eddcc4ed8fe7a940de47ef20c.zip Doxygen-719f0a35063be88eddcc4ed8fe7a940de47ef20c.tar.gz Doxygen-719f0a35063be88eddcc4ed8fe7a940de47ef20c.tar.bz2 |
initial version
Diffstat (limited to 'tmake/example')
-rw-r--r-- | tmake/example/hello.cpp | 102 | ||||
-rw-r--r-- | tmake/example/hello.h | 34 | ||||
-rw-r--r-- | tmake/example/hello.pro | 3 | ||||
-rw-r--r-- | tmake/example/main.cpp | 38 | ||||
-rw-r--r-- | tmake/example/wc.t | 6 |
5 files changed, 183 insertions, 0 deletions
diff --git a/tmake/example/hello.cpp b/tmake/example/hello.cpp new file mode 100644 index 0000000..dc6ff77 --- /dev/null +++ b/tmake/example/hello.cpp @@ -0,0 +1,102 @@ +/**************************************************************************** +** $Id$ +** +** Copyright (C) 1992-1998 Troll Tech 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. +** +*****************************************************************************/ + +#include "hello.h" +#include <qpushbutton.h> +#include <qtimer.h> +#include <qpainter.h> +#include <qpixmap.h> + + +/* + Constructs a Hello widget. Starts a 40 ms animation timer. +*/ + +Hello::Hello( const char *text, QWidget *parent, const char *name ) + : QWidget(parent,name), t(text), b(0) +{ + QTimer *timer = new QTimer(this); + connect( timer, SIGNAL(timeout()), SLOT(animate()) ); + timer->start( 40 ); + + resize( 200, 100 ); +} + + +/* + This private slot is called each time the timer fires. +*/ + +void Hello::animate() +{ + b = (b + 1) & 15; + repaint( FALSE ); +} + + +/* + Handles mouse button release events for the Hello widget. + + We emit the clicked() signal when the mouse is released inside + the widget. +*/ + +void Hello::mouseReleaseEvent( QMouseEvent *e ) +{ + if ( rect().contains( e->pos() ) ) + emit clicked(); +} + + +/* + Handles paint events for the Hello widget. + + Flicker-free update. The text is first drawn in the pixmap and the + pixmap is then blt'ed to the screen. +*/ + +void Hello::paintEvent( QPaintEvent * ) +{ + static int sin_tbl[16] = { + 0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38}; + + if ( t.isEmpty() ) + return; + + // 1: Compute some sizes, positions etc. + QFontMetrics fm = fontMetrics(); + int w = fm.width(t) + 20; + int h = fm.height() * 2; + int pmx = width()/2 - w/2; + int pmy = height()/2 - h/2; + + // 2: Create the pixmap and fill it with the widget's background + QPixmap pm( w, h ); + pm.fill( this, pmx, pmy ); + + // 3: Paint the pixmap. Cool wave effect + QPainter p; + int x = 10; + int y = h/2 + fm.descent(); + int i = 0; + p.begin( &pm ); + p.setFont( font() ); + while ( t[i] ) { + int i16 = (b+i) & 15; + p.setPen( QColor((15-i16)*16,255,255,QColor::Hsv) ); + p.drawText( x, y-sin_tbl[i16]*h/800, &t[i], 1 ); + x += fm.width( t[i] ); + i++; + } + p.end(); + + // 4: Copy the pixmap to the Hello widget + bitBlt( this, pmx, pmy, &pm ); +} diff --git a/tmake/example/hello.h b/tmake/example/hello.h new file mode 100644 index 0000000..16e0871 --- /dev/null +++ b/tmake/example/hello.h @@ -0,0 +1,34 @@ +/**************************************************************************** +** $Id$ +** +** Copyright (C) 1992-1998 Troll Tech 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. +** +*****************************************************************************/ + +#ifndef HELLO_H +#define HELLO_H + +#include <qwidget.h> + + +class Hello : public QWidget +{ + Q_OBJECT +public: + Hello( const char *text, QWidget *parent=0, const char *name=0 ); +signals: + void clicked(); +protected: + void mouseReleaseEvent( QMouseEvent * ); + void paintEvent( QPaintEvent * ); +private slots: + void animate(); +private: + QString t; + int b; +}; + +#endif diff --git a/tmake/example/hello.pro b/tmake/example/hello.pro new file mode 100644 index 0000000..a299923 --- /dev/null +++ b/tmake/example/hello.pro @@ -0,0 +1,3 @@ +HEADERS = hello.h +SOURCES = hello.cpp main.cpp +TARGET = hello diff --git a/tmake/example/main.cpp b/tmake/example/main.cpp new file mode 100644 index 0000000..4b55a58 --- /dev/null +++ b/tmake/example/main.cpp @@ -0,0 +1,38 @@ +// +// File: main.cpp +// +// A small Qt example application written by Troll Tech. +// +// It displays a text in a window and quits when you click +// the mouse in the window. +// + +#include "hello.h" +#include <qapp.h> + + +/* + The program starts here. It parses the command line and build a message + string to be displayed by the Hello widget. +*/ + +int main( int argc, char **argv ) +{ + QApplication a(argc,argv); + QString s; + for ( int i=1; i<argc; i++ ) { + s += argv[i]; + if ( i<argc-1 ) + s += " "; + } + if ( s.isEmpty() ) + s = "Hello, World"; + Hello h( s ); + h.setCaption( "Qt says hello" ); + QObject::connect( &h, SIGNAL(clicked()), &a, SLOT(quit()) ); + h.setFont( QFont("times",32,QFont::Bold) ); // default font + h.setBackgroundColor( white ); // default bg color + a.setMainWidget( &h ); + h.show(); + return a.exec(); +} diff --git a/tmake/example/wc.t b/tmake/example/wc.t new file mode 100644 index 0000000..dc041b5 --- /dev/null +++ b/tmake/example/wc.t @@ -0,0 +1,6 @@ +#! Template that count number of C++ lines +The number of C++ code lines for #$ $text=$project_name; +#${ + $files = $project{"HEADERS"} . " " . $project{"SOURCES"}; + $text = `wc -l $files`; +#$} |