|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
|
|
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/canvas/canvas.doc:1 -->
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
|
|
<title>Canvas Example</title>
|
|
|
|
<style type="text/css"><!--
|
|
|
|
fn { margin-left: 1cm; text-indent: -1cm; }
|
|
|
|
a:link { color: #004faf; text-decoration: none }
|
|
|
|
a:visited { color: #672967; text-decoration: none }
|
|
|
|
body { background: #ffffff; color: black; }
|
|
|
|
--></style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
|
|
|
<tr bgcolor="#E5E5E5">
|
|
|
|
<td valign=center>
|
|
|
|
<a href="index.html">
|
|
|
|
<font color="#004faf">Home</font></a>
|
|
|
|
| <a href="classes.html">
|
|
|
|
<font color="#004faf">All Classes</font></a>
|
|
|
|
| <a href="mainclasses.html">
|
|
|
|
<font color="#004faf">Main Classes</font></a>
|
|
|
|
| <a href="annotated.html">
|
|
|
|
<font color="#004faf">Annotated</font></a>
|
|
|
|
| <a href="groups.html">
|
|
|
|
<font color="#004faf">Grouped Classes</font></a>
|
|
|
|
| <a href="functions.html">
|
|
|
|
<font color="#004faf">Functions</font></a>
|
|
|
|
</td>
|
|
|
|
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Canvas Example</h1>
|
|
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
This example shows a <a href="tqcanvas.html">TQCanvas</a> and some <a href="tqcanvasitem.html">TQCanvasItem</a>s in action.
|
|
|
|
You can do a lot more with TQCanvas than we show here, but the
|
|
|
|
example provides a taste of what can be done.
|
|
|
|
<p> <hr>
|
|
|
|
<p> Header file:
|
|
|
|
<p> <pre>#ifndef EXAMPLE_H
|
|
|
|
#define EXAMPLE_H
|
|
|
|
|
|
|
|
#include <<a href="tqpopupmenu-h.html">tqpopupmenu.h</a>>
|
|
|
|
#include <<a href="tqmainwindow-h.html">tqmainwindow.h</a>>
|
|
|
|
#include <<a href="tqintdict-h.html">tqintdict.h</a>>
|
|
|
|
#include <<a href="tqcanvas-h.html">tqcanvas.h</a>>
|
|
|
|
|
|
|
|
class BouncyLogo : public <a href="tqcanvassprite.html">TQCanvasSprite</a> {
|
|
|
|
void initPos();
|
|
|
|
void initSpeed();
|
|
|
|
public:
|
|
|
|
BouncyLogo(TQCanvas*);
|
|
|
|
void advance(int);
|
|
|
|
int rtti() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FigureEditor : public <a href="tqcanvasview.html">TQCanvasView</a> {
|
|
|
|
<a href="metaobjects.html#TQ_OBJECT">TQ_OBJECT</a>
|
|
|
|
|
|
|
|
public:
|
|
|
|
FigureEditor(TQCanvas&, TQWidget* parent=0, const char* name=0, WFlags f=0);
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void contentsMousePressEvent(TQMouseEvent*);
|
|
|
|
void contentsMouseMoveEvent(TQMouseEvent*);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void status(const <a href="tqstring.html">TQString</a>&);
|
|
|
|
|
|
|
|
private:
|
|
|
|
<a href="tqcanvasitem.html">TQCanvasItem</a>* moving;
|
|
|
|
<a href="tqpoint.html">TQPoint</a> moving_start;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Main : public <a href="tqmainwindow.html">TQMainWindow</a> {
|
|
|
|
TQ_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
Main(TQCanvas&, TQWidget* parent=0, const char* name=0, WFlags f=0);
|
|
|
|
~Main();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void help();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void aboutTQt();
|
|
|
|
void newView();
|
|
|
|
void clear();
|
|
|
|
void init();
|
|
|
|
|
|
|
|
void addSprite();
|
|
|
|
void addCircle();
|
|
|
|
void addHexagon();
|
|
|
|
void addPolygon();
|
|
|
|
void addSpline();
|
|
|
|
void addText();
|
|
|
|
void addLine();
|
|
|
|
void addRectangle();
|
|
|
|
void addMesh();
|
|
|
|
void addLogo();
|
|
|
|
void addButterfly();
|
|
|
|
|
|
|
|
void enlarge();
|
|
|
|
void shrink();
|
|
|
|
void rotateClockwise();
|
|
|
|
void rotateCounterClockwise();
|
|
|
|
void zoomIn();
|
|
|
|
void zoomOut();
|
|
|
|
void mirror();
|
|
|
|
void moveL();
|
|
|
|
void moveR();
|
|
|
|
void moveU();
|
|
|
|
void moveD();
|
|
|
|
|
|
|
|
void print();
|
|
|
|
|
|
|
|
void toggleDoubleBuffer();
|
|
|
|
|
|
|
|
private:
|
|
|
|
<a href="tqcanvas.html">TQCanvas</a>& canvas;
|
|
|
|
FigureEditor *editor;
|
|
|
|
|
|
|
|
<a href="tqpopupmenu.html">TQPopupMenu</a>* options;
|
|
|
|
<a href="tqprinter.html">TQPrinter</a>* printer;
|
|
|
|
int dbf_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p> <hr>
|
|
|
|
<p> Implementation:
|
|
|
|
<p> <pre>#include <<a href="tqdatetime-h.html">tqdatetime.h</a>>
|
|
|
|
#include <<a href="tqmainwindow-h.html">tqmainwindow.h</a>>
|
|
|
|
#include <<a href="tqstatusbar-h.html">tqstatusbar.h</a>>
|
|
|
|
#include <<a href="qmessagebox-h.html">ntqmessagebox.h</a>>
|
|
|
|
#include <<a href="tqmenubar-h.html">tqmenubar.h</a>>
|
|
|
|
#include <<a href="qapplication-h.html">ntqapplication.h</a>>
|
|
|
|
#include <<a href="tqpainter-h.html">tqpainter.h</a>>
|
|
|
|
#include <<a href="tqprinter-h.html">tqprinter.h</a>>
|
|
|
|
#include <<a href="tqlabel-h.html">tqlabel.h</a>>
|
|
|
|
#include <<a href="tqimage-h.html">tqimage.h</a>>
|
|
|
|
#include <<a href="qprogressdialog-h.html">ntqprogressdialog.h</a>>
|
|
|
|
#include "canvas.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
// We use a global variable to save memory - all the brushes and pens in
|
|
|
|
// the mesh are shared.
|
|
|
|
static TQBrush *tb = 0;
|
|
|
|
static TQPen *tp = 0;
|
|
|
|
|
|
|
|
class EdgeItem;
|
|
|
|
class NodeItem;
|
|
|
|
|
|
|
|
class EdgeItem: public <a href="tqcanvasline.html">TQCanvasLine</a>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
EdgeItem( NodeItem*, NodeItem*, TQCanvas *canvas );
|
|
|
|
void setFromPoint( int x, int y ) ;
|
|
|
|
void setToPoint( int x, int y );
|
|
|
|
static int count() { return c; }
|
|
|
|
void moveBy(double dx, double dy);
|
|
|
|
private:
|
|
|
|
static int c;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int imageRTTI = 984376;
|
|
|
|
|
|
|
|
|
|
|
|
class ImageItem: public <a href="tqcanvasrectangle.html">TQCanvasRectangle</a>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ImageItem( <a href="tqimage.html">TQImage</a> img, TQCanvas *canvas );
|
|
|
|
int rtti () const { return imageRTTI; }
|
|
|
|
bool hit( const <a href="tqpoint.html">TQPoint</a>&) const;
|
|
|
|
protected:
|
|
|
|
void drawShape( <a href="tqpainter.html">TQPainter</a> & );
|
|
|
|
private:
|
|
|
|
<a href="tqimage.html">TQImage</a> image;
|
|
|
|
<a href="tqpixmap.html">TQPixmap</a> pixmap;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
<a name="f623"></a>ImageItem::ImageItem( <a href="tqimage.html">TQImage</a> img, TQCanvas *canvas )
|
|
|
|
: <a href="tqcanvasrectangle.html">TQCanvasRectangle</a>( canvas ), image(img)
|
|
|
|
{
|
|
|
|
<a name="x2935"></a><a name="x2932"></a> <a href="tqcanvasrectangle.html#setSize">setSize</a>( image.<a href="tqimage.html#width">width</a>(), image.<a href="tqimage.html#height">height</a>() );
|
|
|
|
|
|
|
|
<a name="x2943"></a> pixmap.<a href="tqpixmap.html#convertFromImage">convertFromImage</a>(image, OrderedAlphaDither);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
<a name="x2925"></a>void ImageItem::<a href="tqcanvasrectangle.html#drawShape">drawShape</a>( <a href="tqpainter.html">TQPainter</a> &p )
|
|
|
|
{
|
|
|
|
p.<a href="tqpainter.html#drawPixmap">drawPixmap</a>( int(<a href="tqcanvasitem.html#x">x</a>()), int(<a href="tqcanvasitem.html#y">y</a>()), pixmap );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool <a name="f624"></a>ImageItem::hit( const <a href="tqpoint.html">TQPoint</a> &p ) const
|
|
|
|
{
|
|
|
|
<a name="x2944"></a> int ix = p.<a href="tqpoint.html#x">x</a>()-int(<a href="tqcanvasitem.html#x">x</a>());
|
|
|
|
<a name="x2945"></a> int iy = p.<a href="tqpoint.html#y">y</a>()-int(<a href="tqcanvasitem.html#y">y</a>());
|
|
|
|
<a name="x2934"></a> if ( !image.<a href="tqimage.html#valid">valid</a>( ix , iy ) )
|
|
|
|
return FALSE;
|
|
|
|
<a name="x2933"></a> TQRgb pixel = image.<a href="tqimage.html#pixel">pixel</a>( ix, iy );
|
|
|
|
return tqAlpha( pixel ) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
class NodeItem: public <a href="tqcanvasellipse.html">TQCanvasEllipse</a>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NodeItem( <a href="tqcanvas.html">TQCanvas</a> *canvas );
|
|
|
|
~NodeItem() {}
|
|
|
|
|
|
|
|
void addInEdge( EdgeItem *edge ) { inList.<a href="tqptrlist.html#append">append</a>( edge ); }
|
|
|
|
void addOutEdge( EdgeItem *edge ) { outList.<a href="tqptrlist.html#append">append</a>( edge ); }
|
|
|
|
|
|
|
|
void moveBy(double dx, double dy);
|
|
|
|
|
|
|
|
// TQPoint center() { return boundingRect().center(); }
|
|
|
|
private:
|
|
|
|
<a href="tqptrlist.html">TQPtrList</a><EdgeItem> inList;
|
|
|
|
<a href="tqptrlist.html">TQPtrList</a><EdgeItem> outList;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int EdgeItem::c = 0;
|
|
|
|
|
|
|
|
|
|
|
|
<a name="x2916"></a>void EdgeItem::<a href="tqcanvasitem.html#moveBy">moveBy</a>(double, double)
|
|
|
|
{
|
|
|
|
//nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
<a name="f618"></a>EdgeItem::EdgeItem( NodeItem *from, NodeItem *to, TQCanvas *canvas )
|
|
|
|
: <a href="tqcanvasline.html">TQCanvasLine</a>( canvas )
|
|
|
|
{
|
|
|
|
c++;
|
|
|
|
setPen( *tp );
|
|
|
|
setBrush( *tb );
|
|
|
|
from->addOutEdge( this );
|
|
|
|
to->addInEdge( this );
|
|
|
|
<a name="x2921"></a><a name="x2920"></a> setPoints( int(from-><a href="tqcanvasitem.html#x">x</a>()), int(from-><a href="tqcanvasitem.html#y">y</a>()), int(to->x()), int(to->y()) );
|
|
|
|
setZ( 127 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f619"></a>EdgeItem::setFromPoint( int x, int y )
|
|
|
|
{
|
|
|
|
setPoints( x,y, endPoint().x(), endPoint().y() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f620"></a>EdgeItem::setToPoint( int x, int y )
|
|
|
|
{
|
|
|
|
setPoints( startPoint().x(), startPoint().y(), x, y );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void NodeItem::<a href="tqcanvasitem.html#moveBy">moveBy</a>(double dx, double dy)
|
|
|
|
{
|
|
|
|
TQCanvasEllipse::<a href="tqcanvasitem.html#moveBy">moveBy</a>( dx, dy );
|
|
|
|
|
|
|
|
<a href="tqptrlistiterator.html">TQPtrListIterator</a><EdgeItem> it1( inList );
|
|
|
|
EdgeItem *edge;
|
|
|
|
<a name="x2949"></a> while (( edge = it1.<a href="tqptrlistiterator.html#current">current</a>() )) {
|
|
|
|
++it1;
|
|
|
|
edge->setToPoint( int(<a href="tqwidget.html#x">x</a>()), int(<a href="tqcanvasitem.html#y">y</a>()) );
|
|
|
|
}
|
|
|
|
<a href="tqptrlistiterator.html">TQPtrListIterator</a><EdgeItem> it2( outList );
|
|
|
|
while (( edge = it2.<a href="tqptrlistiterator.html#current">current</a>() )) {
|
|
|
|
++it2;
|
|
|
|
edge->setFromPoint( int(<a href="tqcanvasitem.html#x">x</a>()), int(<a href="tqcanvasitem.html#y">y</a>()) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
<a name="f655"></a>NodeItem::NodeItem( <a href="tqcanvas.html">TQCanvas</a> *canvas )
|
|
|
|
: <a href="tqcanvasellipse.html">TQCanvasEllipse</a>( 6, 6, canvas )
|
|
|
|
{
|
|
|
|
setPen( *tp );
|
|
|
|
setBrush( *tb );
|
|
|
|
<a href="tqcanvasitem.html#setZ">setZ</a>( 128 );
|
|
|
|
}
|
|
|
|
|
|
|
|
<a name="f621"></a>FigureEditor::FigureEditor(
|
|
|
|
<a href="tqcanvas.html">TQCanvas</a>& c, TQWidget* parent,
|
|
|
|
const char* name, WFlags f) :
|
|
|
|
<a href="tqcanvasview.html">TQCanvasView</a>(&c,parent,name,f)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
<a name="x2951"></a>void FigureEditor::<a href="tqscrollview.html#contentsMousePressEvent">contentsMousePressEvent</a>(TQMouseEvent* e)
|
|
|
|
{
|
|
|
|
<a href="tqpoint.html">TQPoint</a> p = inverseWorldMatrix().map(e->pos());
|
|
|
|
<a href="tqcanvasitemlist.html">TQCanvasItemList</a> l=<a href="tqcanvasitem.html#canvas">canvas</a>()->collisions(p);
|
|
|
|
<a name="x2953"></a><a name="x2952"></a> for (TQCanvasItemList::Iterator it=l.<a href="tqvaluelist.html#begin">begin</a>(); it!=l.<a href="tqvaluelist.html#end">end</a>(); ++it) {
|
|
|
|
if ( (*it)->rtti() == imageRTTI ) {
|
|
|
|
ImageItem *item= (ImageItem*)(*it);
|
|
|
|
if ( !item->hit( p ) )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
moving = *it;
|
|
|
|
moving_start = p;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
moving = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f622"></a>FigureEditor::clear()
|
|
|
|
{
|
|
|
|
<a href="tqcanvasitemlist.html">TQCanvasItemList</a> list = <a href="tqcanvasitem.html#canvas">canvas</a>()->allItems();
|
|
|
|
TQCanvasItemList::Iterator it = list.<a href="tqvaluelist.html#begin">begin</a>();
|
|
|
|
for (; it != list.<a href="tqvaluelist.html#end">end</a>(); ++it) {
|
|
|
|
if ( *it )
|
|
|
|
delete *it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
<a name="x2950"></a>void FigureEditor::<a href="tqscrollview.html#contentsMouseMoveEvent">contentsMouseMoveEvent</a>(TQMouseEvent* e)
|
|
|
|
{
|
|
|
|
if ( moving ) {
|
|
|
|
<a href="tqpoint.html">TQPoint</a> p = inverseWorldMatrix().map(e->pos());
|
|
|
|
moving->moveBy(p.<a href="tqpoint.html#x">x</a>() - moving_start.x(),
|
|
|
|
p.<a href="tqpoint.html#y">y</a>() - moving_start.y());
|
|
|
|
moving_start = p;
|
|
|
|
<a href="tqcanvasitem.html#canvas">canvas</a>()->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a name="f615"></a>BouncyLogo::BouncyLogo(TQCanvas* canvas) :
|
|
|
|
<a href="tqcanvassprite.html">TQCanvasSprite</a>(0,canvas)
|
|
|
|
{
|
|
|
|
static TQCanvasPixmapArray logo("qt-trans.xpm");
|
|
|
|
<a href="tqcanvassprite.html#setSequence">setSequence</a>(&logo);
|
|
|
|
<a href="tqcanvasitem.html#setAnimated">setAnimated</a>(TRUE);
|
|
|
|
initPos();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const int logo_rtti = 1234;
|
|
|
|
|
|
|
|
<a name="x2928"></a>int BouncyLogo::<a href="tqcanvassprite.html#rtti">rtti</a>() const
|
|
|
|
{
|
|
|
|
return logo_rtti;
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f616"></a>BouncyLogo::initPos()
|
|
|
|
{
|
|
|
|
initSpeed();
|
|
|
|
int trial=1000;
|
|
|
|
do {
|
|
|
|
<a href="tqcanvassprite.html#move">move</a>(rand()%canvas()->width(),rand()%canvas()->height());
|
|
|
|
advance(0);
|
|
|
|
} while (trial-- && xVelocity()==0.0 && yVelocity()==0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f617"></a>BouncyLogo::initSpeed()
|
|
|
|
{
|
|
|
|
const double speed = 4.0;
|
|
|
|
double d = (double)(rand()%1024) / 1024.0;
|
|
|
|
setVelocity( d*speed*2-speed, (1-d)*speed*2-speed );
|
|
|
|
}
|
|
|
|
|
|
|
|
<a name="x2927"></a>void BouncyLogo::<a href="tqcanvassprite.html#advance">advance</a>(int stage)
|
|
|
|
{
|
|
|
|
switch ( stage ) {
|
|
|
|
case 0: {
|
|
|
|
double vx = xVelocity();
|
|
|
|
double vy = yVelocity();
|
|
|
|
|
|
|
|
if ( vx == 0.0 && vy == 0.0 ) {
|
|
|
|
// stopped last turn
|
|
|
|
initSpeed();
|
|
|
|
vx = xVelocity();
|
|
|
|
vy = yVelocity();
|
|
|
|
}
|
|
|
|
|
|
|
|
double nx = <a href="tqwidget.html#x">x</a>() + vx;
|
|
|
|
double ny = <a href="tqwidget.html#y">y</a>() + vy;
|
|
|
|
|
|
|
|
if ( nx < 0 || nx >= canvas()->width() )
|
|
|
|
vx = -vx;
|
|
|
|
if ( ny < 0 || ny >= canvas()->height() )
|
|
|
|
vy = -vy;
|
|
|
|
|
|
|
|
for (int bounce=0; bounce<4; bounce++) {
|
|
|
|
<a href="tqcanvasitemlist.html">TQCanvasItemList</a> l=collisions(FALSE);
|
|
|
|
for (TQCanvasItemList::Iterator it=l.<a href="tqvaluelist.html#begin">begin</a>(); it!=l.<a href="tqvaluelist.html#end">end</a>(); ++it) {
|
|
|
|
<a href="tqcanvasitem.html">TQCanvasItem</a> *hit = *it;
|
|
|
|
<a name="x2917"></a><a name="x2914"></a> if ( hit-><a href="tqcanvasitem.html#rtti">rtti</a>()==logo_rtti && hit-><a href="tqcanvasitem.html#collidesWith">collidesWith</a>(this) ) {
|
|
|
|
switch ( bounce ) {
|
|
|
|
case 0:
|
|
|
|
vx = -vx;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
vy = -vy;
|
|
|
|
vx = -vx;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
vx = -vx;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
// Stop for this turn
|
|
|
|
vx = 0;
|
|
|
|
vy = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
setVelocity(vx,vy);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( <a href="tqwidget.html#x">x</a>()+vx < 0 || x()+vx >= canvas()->width() )
|
|
|
|
vx = 0;
|
|
|
|
if ( <a href="tqwidget.html#y">y</a>()+vy < 0 || y()+vy >= canvas()->height() )
|
|
|
|
vy = 0;
|
|
|
|
|
|
|
|
setVelocity(vx,vy);
|
|
|
|
} break;
|
|
|
|
case 1:
|
|
|
|
<a name="x2913"></a> <a href="tqcanvasitem.html">TQCanvasItem</a>::<a href="tqcanvasitem.html#advance">advance</a>(stage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint mainCount = 0;
|
|
|
|
static TQImage *butterflyimg;
|
|
|
|
static TQImage *logoimg;
|
|
|
|
|
|
|
|
<a name="f625"></a>Main::Main(TQCanvas& c, TQWidget* parent, const char* name, WFlags f) :
|
|
|
|
<a href="tqmainwindow.html">TQMainWindow</a>(parent,name,f),
|
|
|
|
canvas(c)
|
|
|
|
{
|
|
|
|
editor = new FigureEditor(canvas,this);
|
|
|
|
<a href="tqmenubar.html">TQMenuBar</a>* menu = <a href="tqmainwindow.html#menuBar">menuBar</a>();
|
|
|
|
|
|
|
|
<a href="tqpopupmenu.html">TQPopupMenu</a>* file = new <a href="tqpopupmenu.html">TQPopupMenu</a>( menu );
|
|
|
|
<a name="x2936"></a> file-><a href="tqmenudata.html#insertItem">insertItem</a>("&Fill canvas", this, TQ_SLOT(init()), CTRL+Key_F);
|
|
|
|
file-><a href="tqmenudata.html#insertItem">insertItem</a>("&Erase canvas", this, TQ_SLOT(clear()), CTRL+Key_E);
|
|
|
|
file-><a href="tqmenudata.html#insertItem">insertItem</a>("&New view", this, TQ_SLOT(newView()), CTRL+Key_N);
|
|
|
|
file-><a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
|
|
|
|
file-><a href="tqmenudata.html#insertItem">insertItem</a>("&Print...", this, TQ_SLOT(print()), CTRL+Key_P);
|
|
|
|
file-><a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
|
|
|
|
file-><a href="tqmenudata.html#insertItem">insertItem</a>("E&xit", tqApp, TQ_SLOT(<a href="ntqapplication.html#quit">quit</a>()), CTRL+Key_Q);
|
|
|
|
menu-><a href="tqmenudata.html#insertItem">insertItem</a>("&File", file);
|
|
|
|
|
|
|
|
<a href="tqpopupmenu.html">TQPopupMenu</a>* edit = new <a href="tqpopupmenu.html">TQPopupMenu</a>( menu );
|
|
|
|
edit-><a href="tqmenudata.html#insertItem">insertItem</a>("Add &Circle", this, TQ_SLOT(addCircle()), ALT+Key_C);
|
|
|
|
edit-><a href="tqmenudata.html#insertItem">insertItem</a>("Add &Hexagon", this, TQ_SLOT(addHexagon()), ALT+Key_H);
|
|
|
|
edit-><a href="tqmenudata.html#insertItem">insertItem</a>("Add &Polygon", this, TQ_SLOT(addPolygon()), ALT+Key_P);
|
|
|
|
edit-><a href="tqmenudata.html#insertItem">insertItem</a>("Add Spl&ine", this, TQ_SLOT(addSpline()), ALT+Key_I);
|
|
|
|
edit-><a href="tqmenudata.html#insertItem">insertItem</a>("Add &Text", this, TQ_SLOT(addText()), ALT+Key_T);
|
|
|
|
edit-><a href="tqmenudata.html#insertItem">insertItem</a>("Add &Line", this, TQ_SLOT(addLine()), ALT+Key_L);
|
|
|
|
edit-><a href="tqmenudata.html#insertItem">insertItem</a>("Add &Rectangle", this, TQ_SLOT(addRectangle()), ALT+Key_R);
|
|
|
|
edit-><a href="tqmenudata.html#insertItem">insertItem</a>("Add &Sprite", this, TQ_SLOT(addSprite()), ALT+Key_S);
|
|
|
|
edit-><a href="tqmenudata.html#insertItem">insertItem</a>("Create &Mesh", this, TQ_SLOT(addMesh()), ALT+Key_M );
|
|
|
|
edit-><a href="tqmenudata.html#insertItem">insertItem</a>("Add &Alpha-blended image", this, TQ_SLOT(addButterfly()), ALT+Key_A);
|
|
|
|
menu-><a href="tqmenudata.html#insertItem">insertItem</a>("&Edit", edit);
|
|
|
|
|
|
|
|
<a href="tqpopupmenu.html">TQPopupMenu</a>* view = new <a href="tqpopupmenu.html">TQPopupMenu</a>( menu );
|
|
|
|
view-><a href="tqmenudata.html#insertItem">insertItem</a>("&Enlarge", this, TQ_SLOT(enlarge()), SHIFT+CTRL+Key_Plus);
|
|
|
|
view-><a href="tqmenudata.html#insertItem">insertItem</a>("Shr&ink", this, TQ_SLOT(shrink()), SHIFT+CTRL+Key_Minus);
|
|
|
|
view-><a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
|
|
|
|
view-><a href="tqmenudata.html#insertItem">insertItem</a>("&Rotate clockwise", this, TQ_SLOT(rotateClockwise()), CTRL+Key_PageDown);
|
|
|
|
view-><a href="tqmenudata.html#insertItem">insertItem</a>("Rotate &counterclockwise", this, TQ_SLOT(rotateCounterClockwise()), CTRL+Key_PageUp);
|
|
|
|
view-><a href="tqmenudata.html#insertItem">insertItem</a>("&Zoom in", this, TQ_SLOT(zoomIn()), CTRL+Key_Plus);
|
|
|
|
view-><a href="tqmenudata.html#insertItem">insertItem</a>("Zoom &out", this, TQ_SLOT(zoomOut()), CTRL+Key_Minus);
|
|
|
|
view-><a href="tqmenudata.html#insertItem">insertItem</a>("Translate left", this, TQ_SLOT(moveL()), CTRL+Key_Left);
|
|
|
|
view-><a href="tqmenudata.html#insertItem">insertItem</a>("Translate right", this, TQ_SLOT(moveR()), CTRL+Key_Right);
|
|
|
|
view-><a href="tqmenudata.html#insertItem">insertItem</a>("Translate up", this, TQ_SLOT(moveU()), CTRL+Key_Up);
|
|
|
|
view-><a href="tqmenudata.html#insertItem">insertItem</a>("Translate down", this, TQ_SLOT(moveD()), CTRL+Key_Down);
|
|
|
|
view-><a href="tqmenudata.html#insertItem">insertItem</a>("&Mirror", this, TQ_SLOT(mirror()), CTRL+Key_Home);
|
|
|
|
menu-><a href="tqmenudata.html#insertItem">insertItem</a>("&View", view);
|
|
|
|
|
|
|
|
options = new <a href="tqpopupmenu.html">TQPopupMenu</a>( menu );
|
|
|
|
dbf_id = options-><a href="tqmenudata.html#insertItem">insertItem</a>("Double buffer", this, TQ_SLOT(toggleDoubleBuffer()));
|
|
|
|
<a name="x2939"></a> options-><a href="tqmenudata.html#setItemChecked">setItemChecked</a>(dbf_id, TRUE);
|
|
|
|
menu-><a href="tqmenudata.html#insertItem">insertItem</a>("&Options",options);
|
|
|
|
|
|
|
|
menu-><a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
|
|
|
|
|
|
|
|
<a href="tqpopupmenu.html">TQPopupMenu</a>* help = new <a href="tqpopupmenu.html">TQPopupMenu</a>( menu );
|
|
|
|
help-><a href="tqmenudata.html#insertItem">insertItem</a>("&About", this, TQ_SLOT(help()), Key_F1);
|
|
|
|
help-><a href="tqmenudata.html#setItemChecked">setItemChecked</a>(dbf_id, TRUE);
|
|
|
|
menu-><a href="tqmenudata.html#insertItem">insertItem</a>("&Help",help);
|
|
|
|
|
|
|
|
<a href="tqmainwindow.html#statusBar">statusBar</a>();
|
|
|
|
|
|
|
|
<a href="tqmainwindow.html#setCentralWidget">setCentralWidget</a>(editor);
|
|
|
|
|
|
|
|
printer = 0;
|
|
|
|
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f626"></a>Main::init()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
|
|
|
|
static int r=24;
|
|
|
|
srand(++r);
|
|
|
|
|
|
|
|
mainCount++;
|
|
|
|
butterflyimg = 0;
|
|
|
|
logoimg = 0;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
<a name="x2912"></a> for ( i=0; i<canvas.<a href="tqcanvas.html#width">width</a>() / 56; i++) {
|
|
|
|
addButterfly();
|
|
|
|
}
|
|
|
|
for ( i=0; i<canvas.<a href="tqcanvas.html#width">width</a>() / 85; i++) {
|
|
|
|
addHexagon();
|
|
|
|
}
|
|
|
|
for ( i=0; i<canvas.<a href="tqcanvas.html#width">width</a>() / 128; i++) {
|
|
|
|
addLogo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Main::~Main()
|
|
|
|
{
|
|
|
|
delete printer;
|
|
|
|
if ( !--mainCount ) {
|
|
|
|
delete[] butterflyimg;
|
|
|
|
butterflyimg = 0;
|
|
|
|
delete[] logoimg;
|
|
|
|
logoimg = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f627"></a>Main::newView()
|
|
|
|
{
|
|
|
|
// Open a new view... have it delete when closed.
|
|
|
|
Main *m = new Main(canvas, 0, 0, WDestructiveClose);
|
|
|
|
tqApp-><a href="ntqapplication.html#setMainWidget">setMainWidget</a>(m);
|
|
|
|
m-><a href="tqwidget.html#show">show</a>();
|
|
|
|
tqApp-><a href="ntqapplication.html#setMainWidget">setMainWidget</a>(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f628"></a>Main::clear()
|
|
|
|
{
|
|
|
|
editor->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f629"></a>Main::help()
|
|
|
|
{
|
|
|
|
static TQMessageBox* about = new <a href="ntqmessagebox.html">TQMessageBox</a>( "TQt Canvas Example",
|
|
|
|
"<h3>The TQCanvas classes example</h3>"
|
|
|
|
"<ul>"
|
|
|
|
"<li> Press ALT-S for some sprites."
|
|
|
|
"<li> Press ALT-C for some circles."
|
|
|
|
"<li> Press ALT-L for some lines."
|
|
|
|
"<li> Drag the objects around."
|
|
|
|
"<li> Read the code!"
|
|
|
|
"</ul>", TQMessageBox::Information, 1, 0, 0, this, 0, FALSE );
|
|
|
|
about->setButtonText( 1, "Dismiss" );
|
|
|
|
about->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f630"></a>Main::aboutTQt()
|
|
|
|
{
|
|
|
|
TQMessageBox::<a href="ntqmessagebox.html#aboutTQt">aboutTQt</a>( this, "TQt Canvas Example" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f631"></a>Main::toggleDoubleBuffer()
|
|
|
|
{
|
|
|
|
<a name="x2938"></a> bool s = !options-><a href="tqmenudata.html#isItemChecked">isItemChecked</a>(dbf_id);
|
|
|
|
options-><a href="tqmenudata.html#setItemChecked">setItemChecked</a>(dbf_id,s);
|
|
|
|
<a name="x2911"></a> canvas.<a href="tqcanvas.html#setDoubleBuffering">setDoubleBuffering</a>(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f632"></a>Main::enlarge()
|
|
|
|
{
|
|
|
|
<a name="x2910"></a><a name="x2909"></a> canvas.<a href="tqcanvas.html#resize">resize</a>(canvas.<a href="tqcanvas.html#width">width</a>()*4/3, canvas.<a href="tqcanvas.html#height">height</a>()*4/3);
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f633"></a>Main::shrink()
|
|
|
|
{
|
|
|
|
canvas.<a href="tqcanvas.html#resize">resize</a>(canvas.<a href="tqcanvas.html#width">width</a>()*3/4, canvas.<a href="tqcanvas.html#height">height</a>()*3/4);
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f634"></a>Main::rotateClockwise()
|
|
|
|
{
|
|
|
|
<a name="x2931"></a> <a href="tqwmatrix.html">TQWMatrix</a> m = editor-><a href="tqcanvasview.html#worldMatrix">worldMatrix</a>();
|
|
|
|
<a name="x2955"></a> m.<a href="tqwmatrix.html#rotate">rotate</a>( 22.5 );
|
|
|
|
<a name="x2930"></a> editor-><a href="tqcanvasview.html#setWorldMatrix">setWorldMatrix</a>( m );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f635"></a>Main::rotateCounterClockwise()
|
|
|
|
{
|
|
|
|
<a href="tqwmatrix.html">TQWMatrix</a> m = editor-><a href="tqcanvasview.html#worldMatrix">worldMatrix</a>();
|
|
|
|
m.<a href="tqwmatrix.html#rotate">rotate</a>( -22.5 );
|
|
|
|
editor-><a href="tqcanvasview.html#setWorldMatrix">setWorldMatrix</a>( m );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f636"></a>Main::zoomIn()
|
|
|
|
{
|
|
|
|
<a href="tqwmatrix.html">TQWMatrix</a> m = editor-><a href="tqcanvasview.html#worldMatrix">worldMatrix</a>();
|
|
|
|
<a name="x2956"></a> m.<a href="tqwmatrix.html#scale">scale</a>( 2.0, 2.0 );
|
|
|
|
editor-><a href="tqcanvasview.html#setWorldMatrix">setWorldMatrix</a>( m );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f637"></a>Main::zoomOut()
|
|
|
|
{
|
|
|
|
<a href="tqwmatrix.html">TQWMatrix</a> m = editor-><a href="tqcanvasview.html#worldMatrix">worldMatrix</a>();
|
|
|
|
m.<a href="tqwmatrix.html#scale">scale</a>( 0.5, 0.5 );
|
|
|
|
editor-><a href="tqcanvasview.html#setWorldMatrix">setWorldMatrix</a>( m );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f638"></a>Main::mirror()
|
|
|
|
{
|
|
|
|
<a href="tqwmatrix.html">TQWMatrix</a> m = editor-><a href="tqcanvasview.html#worldMatrix">worldMatrix</a>();
|
|
|
|
m.<a href="tqwmatrix.html#scale">scale</a>( -1, 1 );
|
|
|
|
editor-><a href="tqcanvasview.html#setWorldMatrix">setWorldMatrix</a>( m );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f639"></a>Main::moveL()
|
|
|
|
{
|
|
|
|
<a href="tqwmatrix.html">TQWMatrix</a> m = editor-><a href="tqcanvasview.html#worldMatrix">worldMatrix</a>();
|
|
|
|
<a name="x2957"></a> m.<a href="tqwmatrix.html#translate">translate</a>( -16, 0 );
|
|
|
|
editor-><a href="tqcanvasview.html#setWorldMatrix">setWorldMatrix</a>( m );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f640"></a>Main::moveR()
|
|
|
|
{
|
|
|
|
<a href="tqwmatrix.html">TQWMatrix</a> m = editor-><a href="tqcanvasview.html#worldMatrix">worldMatrix</a>();
|
|
|
|
m.<a href="tqwmatrix.html#translate">translate</a>( +16, 0 );
|
|
|
|
editor-><a href="tqcanvasview.html#setWorldMatrix">setWorldMatrix</a>( m );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f641"></a>Main::moveU()
|
|
|
|
{
|
|
|
|
<a href="tqwmatrix.html">TQWMatrix</a> m = editor-><a href="tqcanvasview.html#worldMatrix">worldMatrix</a>();
|
|
|
|
m.<a href="tqwmatrix.html#translate">translate</a>( 0, -16 );
|
|
|
|
editor-><a href="tqcanvasview.html#setWorldMatrix">setWorldMatrix</a>( m );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f642"></a>Main::moveD()
|
|
|
|
{
|
|
|
|
<a href="tqwmatrix.html">TQWMatrix</a> m = editor-><a href="tqcanvasview.html#worldMatrix">worldMatrix</a>();
|
|
|
|
m.<a href="tqwmatrix.html#translate">translate</a>( 0, +16 );
|
|
|
|
editor-><a href="tqcanvasview.html#setWorldMatrix">setWorldMatrix</a>( m );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f643"></a>Main::print()
|
|
|
|
{
|
|
|
|
if ( !printer ) printer = new <a href="tqprinter.html">TQPrinter</a>;
|
|
|
|
if ( printer->setup(this) ) {
|
|
|
|
<a href="tqpainter.html">TQPainter</a> pp(printer);
|
|
|
|
<a name="x2908"></a> canvas.<a href="tqcanvas.html#drawArea">drawArea</a>(TQRect(0,0,canvas.<a href="tqcanvas.html#width">width</a>(),canvas.<a href="tqcanvas.html#height">height</a>()),&pp,FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void <a name="f644"></a>Main::addSprite()
|
|
|
|
{
|
|
|
|
<a href="tqcanvasitem.html">TQCanvasItem</a>* i = new BouncyLogo(&canvas);
|
|
|
|
<a name="x2918"></a> i-><a href="tqcanvasitem.html#setZ">setZ</a>(rand()%256);
|
|
|
|
<a name="x2919"></a> i-><a href="tqcanvasitem.html#show">show</a>();
|
|
|
|
}
|
|
|
|
|
|
|
|
TQString butterfly_fn;
|
|
|
|
TQString logo_fn;
|
|
|
|
|
|
|
|
|
|
|
|
void <a name="f645"></a>Main::addButterfly()
|
|
|
|
{
|
|
|
|
if ( butterfly_fn.isEmpty() )
|
|
|
|
return;
|
|
|
|
if ( !butterflyimg ) {
|
|
|
|
butterflyimg = new <a href="tqimage.html">TQImage</a>[4];
|
|
|
|
butterflyimg[0].load( butterfly_fn );
|
|
|
|
butterflyimg[1] = butterflyimg[0].smoothScale( int(butterflyimg[0].width()*0.75),
|
|
|
|
int(butterflyimg[0].height()*0.75) );
|
|
|
|
butterflyimg[2] = butterflyimg[0].smoothScale( int(butterflyimg[0].width()*0.5),
|
|
|
|
int(butterflyimg[0].height()*0.5) );
|
|
|
|
butterflyimg[3] = butterflyimg[0].smoothScale( int(butterflyimg[0].width()*0.25),
|
|
|
|
int(butterflyimg[0].height()*0.25) );
|
|
|
|
}
|
|
|
|
<a href="tqcanvaspolygonalitem.html">TQCanvasPolygonalItem</a>* i = new ImageItem(butterflyimg[rand()%4],&canvas);
|
|
|
|
<a name="x2915"></a> i-><a href="tqcanvasitem.html#move">move</a>(rand()%(canvas.<a href="tqcanvas.html#width">width</a>()-butterflyimg-><a href="tqimage.html#width">width</a>()),
|
|
|
|
rand()%(canvas.<a href="tqcanvas.html#height">height</a>()-butterflyimg-><a href="tqimage.html#height">height</a>()));
|
|
|
|
i-><a href="tqcanvasitem.html#setZ">setZ</a>(rand()%256+250);
|
|
|
|
i-><a href="tqcanvasitem.html#show">show</a>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f646"></a>Main::addLogo()
|
|
|
|
{
|
|
|
|
if ( logo_fn.isEmpty() )
|
|
|
|
return;
|
|
|
|
if ( !logoimg ) {
|
|
|
|
logoimg = new <a href="tqimage.html">TQImage</a>[4];
|
|
|
|
logoimg[0].load( logo_fn );
|
|
|
|
logoimg[1] = logoimg[0].smoothScale( int(logoimg[0].width()*0.75),
|
|
|
|
int(logoimg[0].height()*0.75) );
|
|
|
|
logoimg[2] = logoimg[0].smoothScale( int(logoimg[0].width()*0.5),
|
|
|
|
int(logoimg[0].height()*0.5) );
|
|
|
|
logoimg[3] = logoimg[0].smoothScale( int(logoimg[0].width()*0.25),
|
|
|
|
int(logoimg[0].height()*0.25) );
|
|
|
|
}
|
|
|
|
<a href="tqcanvaspolygonalitem.html">TQCanvasPolygonalItem</a>* i = new ImageItem(logoimg[rand()%4],&canvas);
|
|
|
|
i-><a href="tqcanvasitem.html#move">move</a>(rand()%(canvas.<a href="tqcanvas.html#width">width</a>()-logoimg-><a href="tqimage.html#width">width</a>()),
|
|
|
|
rand()%(canvas.<a href="tqcanvas.html#height">height</a>()-logoimg-><a href="tqimage.html#width">width</a>()));
|
|
|
|
i-><a href="tqcanvasitem.html#setZ">setZ</a>(rand()%256+256);
|
|
|
|
i-><a href="tqcanvasitem.html#show">show</a>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void <a name="f647"></a>Main::addCircle()
|
|
|
|
{
|
|
|
|
<a href="tqcanvaspolygonalitem.html">TQCanvasPolygonalItem</a>* i = new <a href="tqcanvasellipse.html">TQCanvasEllipse</a>(50,50,&canvas);
|
|
|
|
<a name="x2923"></a> i-><a href="tqcanvaspolygonalitem.html#setBrush">setBrush</a>( TQColor(rand()%32*8,rand()%32*8,rand()%32*8) );
|
|
|
|
i-><a href="tqcanvasitem.html#move">move</a>(rand()%canvas.<a href="tqcanvas.html#width">width</a>(),rand()%canvas.<a href="tqcanvas.html#height">height</a>());
|
|
|
|
i-><a href="tqcanvasitem.html#setZ">setZ</a>(rand()%256);
|
|
|
|
i-><a href="tqcanvasitem.html#show">show</a>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f648"></a>Main::addHexagon()
|
|
|
|
{
|
|
|
|
<a href="tqcanvaspolygon.html">TQCanvasPolygon</a>* i = new <a href="tqcanvaspolygon.html">TQCanvasPolygon</a>(&canvas);
|
|
|
|
const int size = canvas.<a href="tqcanvas.html#width">width</a>() / 25;
|
|
|
|
<a href="tqpointarray.html">TQPointArray</a> pa(6);
|
|
|
|
pa[0] = TQPoint(2*size,0);
|
|
|
|
pa[1] = TQPoint(size,-size*173/100);
|
|
|
|
pa[2] = TQPoint(-size,-size*173/100);
|
|
|
|
pa[3] = TQPoint(-2*size,0);
|
|
|
|
pa[4] = TQPoint(-size,size*173/100);
|
|
|
|
pa[5] = TQPoint(size,size*173/100);
|
|
|
|
<a name="x2922"></a> i-><a href="tqcanvasline.html#setPoints">setPoints</a>(pa);
|
|
|
|
i-><a href="tqcanvaspolygonalitem.html#setBrush">setBrush</a>( TQColor(rand()%32*8,rand()%32*8,rand()%32*8) );
|
|
|
|
i-><a href="tqcanvasitem.html#move">move</a>(rand()%canvas.<a href="tqcanvas.html#width">width</a>(),rand()%canvas.<a href="tqcanvas.html#height">height</a>());
|
|
|
|
i-><a href="tqcanvasitem.html#setZ">setZ</a>(rand()%256);
|
|
|
|
i-><a href="tqcanvasitem.html#show">show</a>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f649"></a>Main::addPolygon()
|
|
|
|
{
|
|
|
|
<a href="tqcanvaspolygon.html">TQCanvasPolygon</a>* i = new <a href="tqcanvaspolygon.html">TQCanvasPolygon</a>(&canvas);
|
|
|
|
const int size = canvas.<a href="tqcanvas.html#width">width</a>()/2;
|
|
|
|
<a href="tqpointarray.html">TQPointArray</a> pa(6);
|
|
|
|
pa[0] = TQPoint(0,0);
|
|
|
|
pa[1] = TQPoint(size,size/5);
|
|
|
|
pa[2] = TQPoint(size*4/5,size);
|
|
|
|
pa[3] = TQPoint(size/6,size*5/4);
|
|
|
|
pa[4] = TQPoint(size*3/4,size*3/4);
|
|
|
|
pa[5] = TQPoint(size*3/4,size/4);
|
|
|
|
i-><a href="tqcanvasline.html#setPoints">setPoints</a>(pa);
|
|
|
|
i-><a href="tqcanvaspolygonalitem.html#setBrush">setBrush</a>( TQColor(rand()%32*8,rand()%32*8,rand()%32*8) );
|
|
|
|
i-><a href="tqcanvasitem.html#move">move</a>(rand()%canvas.<a href="tqcanvas.html#width">width</a>(),rand()%canvas.<a href="tqcanvas.html#height">height</a>());
|
|
|
|
i-><a href="tqcanvasitem.html#setZ">setZ</a>(rand()%256);
|
|
|
|
i-><a href="tqcanvasitem.html#show">show</a>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f650"></a>Main::addSpline()
|
|
|
|
{
|
|
|
|
<a href="tqcanvasspline.html">TQCanvasSpline</a>* i = new <a href="tqcanvasspline.html">TQCanvasSpline</a>(&canvas);
|
|
|
|
const int size = canvas.<a href="tqcanvas.html#width">width</a>()/6;
|
|
|
|
<a href="tqpointarray.html">TQPointArray</a> pa(12);
|
|
|
|
pa[0] = TQPoint(0,0);
|
|
|
|
pa[1] = TQPoint(size/2,0);
|
|
|
|
pa[2] = TQPoint(size,size/2);
|
|
|
|
pa[3] = TQPoint(size,size);
|
|
|
|
pa[4] = TQPoint(size,size*3/2);
|
|
|
|
pa[5] = TQPoint(size/2,size*2);
|
|
|
|
pa[6] = TQPoint(0,size*2);
|
|
|
|
pa[7] = TQPoint(-size/2,size*2);
|
|
|
|
pa[8] = TQPoint(size/4,size*3/2);
|
|
|
|
pa[9] = TQPoint(0,size);
|
|
|
|
pa[10]= TQPoint(-size/4,size/2);
|
|
|
|
pa[11]= TQPoint(-size/2,0);
|
|
|
|
<a name="x2926"></a> i-><a href="tqcanvasspline.html#setControlPoints">setControlPoints</a>(pa);
|
|
|
|
i-><a href="tqcanvaspolygonalitem.html#setBrush">setBrush</a>( TQColor(rand()%32*8,rand()%32*8,rand()%32*8) );
|
|
|
|
i-><a href="tqcanvasitem.html#move">move</a>(rand()%canvas.<a href="tqcanvas.html#width">width</a>(),rand()%canvas.<a href="tqcanvas.html#height">height</a>());
|
|
|
|
i-><a href="tqcanvasitem.html#setZ">setZ</a>(rand()%256);
|
|
|
|
i-><a href="tqcanvasitem.html#show">show</a>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f651"></a>Main::addText()
|
|
|
|
{
|
|
|
|
<a href="tqcanvastext.html">TQCanvasText</a>* i = new <a href="tqcanvastext.html">TQCanvasText</a>(&canvas);
|
|
|
|
<a name="x2929"></a> i-><a href="tqcanvastext.html#setText">setText</a>("TQCanvasText");
|
|
|
|
i-><a href="tqcanvasitem.html#move">move</a>(rand()%canvas.<a href="tqcanvas.html#width">width</a>(),rand()%canvas.<a href="tqcanvas.html#height">height</a>());
|
|
|
|
i-><a href="tqcanvasitem.html#setZ">setZ</a>(rand()%256);
|
|
|
|
i-><a href="tqcanvasitem.html#show">show</a>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f652"></a>Main::addLine()
|
|
|
|
{
|
|
|
|
<a href="tqcanvasline.html">TQCanvasLine</a>* i = new <a href="tqcanvasline.html">TQCanvasLine</a>(&canvas);
|
|
|
|
i-><a href="tqcanvasline.html#setPoints">setPoints</a>( rand()%canvas.<a href="tqcanvas.html#width">width</a>(), rand()%canvas.<a href="tqcanvas.html#height">height</a>(),
|
|
|
|
rand()%canvas.<a href="tqcanvas.html#width">width</a>(), rand()%canvas.<a href="tqcanvas.html#height">height</a>() );
|
|
|
|
<a name="x2924"></a> i-><a href="tqcanvaspolygonalitem.html#setPen">setPen</a>( TQPen(TQColor(rand()%32*8,rand()%32*8,rand()%32*8), 6) );
|
|
|
|
i-><a href="tqcanvasitem.html#setZ">setZ</a>(rand()%256);
|
|
|
|
i-><a href="tqcanvasitem.html#show">show</a>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f653"></a>Main::addMesh()
|
|
|
|
{
|
|
|
|
int x0 = 0;
|
|
|
|
int y0 = 0;
|
|
|
|
|
|
|
|
if ( !tb ) tb = new <a href="tqbrush.html">TQBrush</a>( TQt::red );
|
|
|
|
if ( !tp ) tp = new <a href="tqpen.html">TQPen</a>( TQt::black );
|
|
|
|
|
|
|
|
int nodecount = 0;
|
|
|
|
|
|
|
|
int w = canvas.<a href="tqcanvas.html#width">width</a>();
|
|
|
|
int h = canvas.<a href="tqcanvas.html#height">height</a>();
|
|
|
|
|
|
|
|
const int dist = 30;
|
|
|
|
int rows = h / dist;
|
|
|
|
int cols = w / dist;
|
|
|
|
|
|
|
|
#ifndef TQT_NO_PROGRESSDIALOG
|
|
|
|
<a href="ntqprogressdialog.html">TQProgressDialog</a> progress( "Creating mesh...", "Abort", rows,
|
|
|
|
this, "progress", TRUE );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
<a href="tqmemarray.html">TQMemArray</a><NodeItem*> lastRow(cols);
|
|
|
|
for ( int j = 0; j < rows; j++ ) {
|
|
|
|
int n = j%2 ? cols-1 : cols;
|
|
|
|
NodeItem *prev = 0;
|
|
|
|
for ( int i = 0; i < n; i++ ) {
|
|
|
|
NodeItem *el = new NodeItem( &canvas );
|
|
|
|
nodecount++;
|
|
|
|
int r = rand();
|
|
|
|
int xrand = r %20;
|
|
|
|
int yrand = (r/20) %20;
|
|
|
|
el-><a href="tqcanvasitem.html#move">move</a>( xrand + x0 + i*dist + (j%2 ? dist/2 : 0 ),
|
|
|
|
yrand + y0 + j*dist );
|
|
|
|
|
|
|
|
if ( j > 0 ) {
|
|
|
|
if ( i < cols-1 )
|
|
|
|
(new EdgeItem( lastRow[i], el, &canvas ))->show();
|
|
|
|
if ( j%2 )
|
|
|
|
(new EdgeItem( lastRow[i+1], el, &canvas ))->show();
|
|
|
|
else if ( i > 0 )
|
|
|
|
(new EdgeItem( lastRow[i-1], el, &canvas ))->show();
|
|
|
|
}
|
|
|
|
if ( prev ) {
|
|
|
|
(new EdgeItem( prev, el, &canvas ))->show();
|
|
|
|
}
|
|
|
|
if ( i > 0 ) lastRow[i-1] = prev;
|
|
|
|
prev = el;
|
|
|
|
el-><a href="tqcanvasitem.html#show">show</a>();
|
|
|
|
}
|
|
|
|
lastRow[n-1]=prev;
|
|
|
|
#ifndef TQT_NO_PROGRESSDIALOG
|
|
|
|
<a name="x2946"></a> progress.<a href="ntqprogressdialog.html#setProgress">setProgress</a>( j );
|
|
|
|
<a name="x2947"></a> if ( progress.<a href="ntqprogressdialog.html#wasCancelled">wasCancelled</a>() )
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#ifndef TQT_NO_PROGRESSDIALOG
|
|
|
|
progress.<a href="ntqprogressdialog.html#setProgress">setProgress</a>( rows );
|
|
|
|
#endif
|
|
|
|
// tqDebug( "%d nodes, %d edges", nodecount, EdgeItem::count() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void <a name="f654"></a>Main::addRectangle()
|
|
|
|
{
|
|
|
|
<a href="tqcanvaspolygonalitem.html">TQCanvasPolygonalItem</a> *i = new <a href="tqcanvasrectangle.html">TQCanvasRectangle</a>( rand()%canvas.<a href="tqcanvas.html#width">width</a>(),rand()%canvas.<a href="tqcanvas.html#height">height</a>(),
|
|
|
|
canvas.<a href="tqcanvas.html#width">width</a>()/5,canvas.<a href="tqcanvas.html#width">width</a>()/5,&canvas);
|
|
|
|
int z = rand()%256;
|
|
|
|
i-><a href="tqcanvaspolygonalitem.html#setBrush">setBrush</a>( TQColor(z,z,z) );
|
|
|
|
i-><a href="tqcanvaspolygonalitem.html#setPen">setPen</a>( TQPen(TQColor(rand()%32*8,rand()%32*8,rand()%32*8), 6) );
|
|
|
|
i-><a href="tqcanvasitem.html#setZ">setZ</a>(z);
|
|
|
|
i-><a href="tqcanvasitem.html#show">show</a>();
|
|
|
|
}
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p> <hr>
|
|
|
|
<p> Main:
|
|
|
|
<p> <pre>#include <<a href="tqstatusbar-h.html">tqstatusbar.h</a>>
|
|
|
|
#include <<a href="qmessagebox-h.html">ntqmessagebox.h</a>>
|
|
|
|
#include <<a href="tqmenubar-h.html">tqmenubar.h</a>>
|
|
|
|
#include <<a href="qapplication-h.html">ntqapplication.h</a>>
|
|
|
|
#include <<a href="tqimage-h.html">tqimage.h</a>>
|
|
|
|
|
|
|
|
#include "canvas.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
extern TQString butterfly_fn;
|
|
|
|
extern TQString logo_fn;
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
<a href="ntqapplication.html">TQApplication</a> app(argc,argv);
|
|
|
|
|
|
|
|
if ( argc > 1 )
|
|
|
|
butterfly_fn = argv[1];
|
|
|
|
else
|
|
|
|
butterfly_fn = "butterfly.png";
|
|
|
|
|
|
|
|
if ( argc > 2 )
|
|
|
|
logo_fn = argv[2];
|
|
|
|
else
|
|
|
|
logo_fn = "qtlogo.png";
|
|
|
|
|
|
|
|
<a href="tqcanvas.html">TQCanvas</a> canvas(800,600);
|
|
|
|
<a name="x2962"></a> canvas.<a href="tqcanvas.html#setAdvancePeriod">setAdvancePeriod</a>(30);
|
|
|
|
Main m(canvas);
|
|
|
|
<a name="x2969"></a> m.<a href="tqwidget.html#resize">resize</a>(m.<a href="tqwidget.html#sizeHint">sizeHint</a>());
|
|
|
|
m.<a href="tqwidget.html#setCaption">setCaption</a>("TQt Example - Canvas");
|
|
|
|
<a name="x2970"></a><a name="x2958"></a> if ( TQApplication::<a href="ntqapplication.html#desktop">desktop</a>()->width() > m.<a href="tqwidget.html#width">width</a>() + 10
|
|
|
|
<a name="x2964"></a> && TQApplication::<a href="ntqapplication.html#desktop">desktop</a>()->height() > m.<a href="tqwidget.html#height">height</a>() +30 )
|
|
|
|
m.<a href="tqwidget.html#show">show</a>();
|
|
|
|
else
|
|
|
|
<a name="x2968"></a> m.<a href="tqwidget.html#showMaximized">showMaximized</a>();
|
|
|
|
|
|
|
|
TQObject::<a href="tqobject.html#connect">connect</a>( tqApp, TQ_SIGNAL(<a href="ntqapplication.html#lastWindowClosed">lastWindowClosed</a>()), tqApp, TQ_SLOT(<a href="ntqapplication.html#quit">quit</a>()) );
|
|
|
|
|
|
|
|
return app.<a href="ntqapplication.html#exec">exec</a>();
|
|
|
|
}
|
|
|
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>See also <a href="examples.html">Examples</a>.
|
|
|
|
|
|
|
|
<!-- eof -->
|
|
|
|
<p><address><hr><div align=center>
|
|
|
|
<table width=100% cellspacing=0 border=0><tr>
|
|
|
|
<td>Copyright © 2007
|
|
|
|
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
|
|
|
<td align=right><div align=right>TQt 3.3.8</div>
|
|
|
|
</table></div></address></body>
|
|
|
|
</html>
|