Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

canvas.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** 
00003 ** Copyright ( C ) 2002 Yann Hodique <Yann.Hodique@lifl.fr>.
00004 ** Copyright ( C ) 1992-2000 Trolltech AS.  All rights reserved.
00005 **
00006 ** This file is part of an example program for Qt.  This example
00007 ** program may be used, distributed and modified without limitation.
00008 **
00009 *****************************************************************************/
00010 
00011 #ifndef _CANVAS_H_
00012 #define _CANVAS_H_
00013 
00014 #include <qpen.h>
00015 #include <qpoint.h>
00016 #include <qpixmap.h>
00017 #include <qwidget.h>
00018 #include <qstring.h>
00019 #include <qpointarray.h>
00020 
00021 class QMouseEvent;
00022 class QResizeEvent;
00023 class QPaintEvent;
00024 class QToolButton;
00025 class QSpinBox;
00026 
00027 class Canvas : public QWidget {
00028     Q_OBJECT
00029 
00030 public:
00031     typedef enum {
00032         LINE,
00033         CIRCLE,
00034         TEXT
00035     } Shape;
00036 
00037     Canvas( QWidget *parent = 0, const char *name = 0 );
00038 
00039     void setPenColor( const QColor &c ) {
00040         pen.setColor( c );
00041     }
00042 
00043     void setPenWidth( int w ) {
00044         pen.setWidth( w );
00045         eraser.setWidth(w);
00046     }
00047 
00048     void setDrawingShape( Shape s ) {
00049         shape = s;
00050     }
00051 
00052     QColor penColor() {
00053         return pen.color();
00054     }
00055 
00056     int penWidth() {
00057         return pen.width();
00058     }
00059 
00060     int drawingShape() {
00061         return shape;
00062     }
00063 
00064     void save( const QString &filename, const QString &format );
00065 
00066     void clearScreen();
00067 
00068 protected:
00069     void mousePressEvent( QMouseEvent *e );
00070     void mouseReleaseEvent( QMouseEvent *e );
00071     void mouseMoveEvent( QMouseEvent *e );
00072     void resizeEvent( QResizeEvent *e );
00073     void paintEvent( QPaintEvent *e );
00074 
00075     QPen pen,eraser;
00076     Shape shape;
00077     QPoint start,tmp;
00078 
00079     bool mousePressed;
00080 
00081     QPixmap buffer,over;
00082 
00083 public slots:
00084     void draw(Shape, const QColor &, const QPoint &, const QPoint &, int width=3, const QString & text = QString::null);
00085 
00086 private slots:
00087     void draw(const QPoint &, const QPoint &, bool definitive=true, bool erase=false);
00088 
00089 signals:
00090     void drawing(QString & str);
00091 };
00092 
00093 #endif

Generated on Sat May 10 15:09:26 2003 for qnet by doxygen1.3