From ea318d1431c89e647598c510c4245c6571aa5f46 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 26 Jan 2012 23:32:43 -0600 Subject: Update to latest tqt3 automated conversion --- doc/html/tutorial1-14.html | 90 +++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 45 deletions(-) (limited to 'doc/html/tutorial1-14.html') diff --git a/doc/html/tutorial1-14.html b/doc/html/tutorial1-14.html index 957e99832..5a24a0d82 100644 --- a/doc/html/tutorial1-14.html +++ b/doc/html/tutorial1-14.html @@ -69,13 +69,13 @@ wall.

In addition to the familiar event handlers, CannonField implements three mouse event handlers. The names say it all. -

        void  paintBarrier( TQPainter * );
+

        void  paintBarrier( TQPainter * );
 

This private function paints the barrier wall. -

        TQRect barrierRect() const;
+

        TQRect barrierRect() const;
 

This private function returns the enclosing rectangle of the barrier. -

        bool  barrelHit( const TQPoint & ) const;
+

        bool  barrelHit( const TQPoint & ) const;
 

This private function checks if a point is inside the barrel of the cannon.

        bool barrelPressed;
@@ -90,12 +90,12 @@ barrel and not released it.
 

This line has been added to the constructor. Initially, the mouse is not pressed on the barrel. -

        } else if ( shotR.x() > width() || shotR.y() > height() ||
-                    shotR.intersects(barrierRect()) ) {
+

        } else if ( shotR.x() > width() || shotR.y() > height() ||
+                    shotR.intersects(barrierRect()) ) {
 

Now that we have a barrier, there are three ways to miss. We test for the third, too. -

    void CannonField::mousePressEvent( TQMouseEvent *e )
+

    void CannonField::mousePressEvent( TQMouseEvent *e )
     {
         if ( e->button() != LeftButton )
             return;
@@ -111,23 +111,23 @@ is within the cannon's barrel. If it is, we set barrelPressed to
 TRUE.
 

Notice that the pos() function returns a point in the widget's coordinate system. -

    void CannonField::mouseMoveEvent( TQMouseEvent *e )
+

    void CannonField::mouseMoveEvent( TQMouseEvent *e )
     {
         if ( !barrelPressed )
             return;
-        TQPoint pnt = e->pos();
-        if ( pnt.x() <= 0 )
-            pnt.setX( 1 );
-        if ( pnt.y() >= height() )
-            pnt.setY( height() - 1 );
-        double rad = atan(((double)rect().bottom()-pnt.y())/pnt.x());
+        TQPoint pnt = e->pos();
+        if ( pnt.x() <= 0 )
+            pnt.setX( 1 );
+        if ( pnt.y() >= height() )
+            pnt.setY( height() - 1 );
+        double rad = atan(((double)rect().bottom()-pnt.y())/pnt.x());
         setAngle( qRound ( rad*180/3.14159265 ) );
     }
 

This is another TQt event handler. It is called when the user already has pressed the mouse button inside this widget and then moves/drags the mouse. (You can make TQt send mouse move events even when no -buttons are pressed. See TQWidget::setMouseTracking().) +buttons are pressed. See TQWidget::setMouseTracking().)

This handler repositions the cannon's barrel according to the position of the mouse cursor.

First, if the barrel is not pressed, we return. Next, we fetch the @@ -138,7 +138,7 @@ the imaginary line between the bottom-left corner of the widget and the cursor position. Finally we set the cannon's angle to the new value converted to degrees.

Remember that setAngle() redraws the cannon. -

    void CannonField::mouseReleaseEvent( TQMouseEvent *e )
+

    void CannonField::mouseReleaseEvent( TQMouseEvent *e )
     {
         if ( e->button() == LeftButton )
             barrelPressed = FALSE;
@@ -149,16 +149,16 @@ button and it was pressed inside this widget.
 

If the left button is released, we can be sure that the barrel is no longer pressed.

The paint event has two extra lines: -

        if ( updateR.intersects( barrierRect() ) )
+

        if ( updateR.intersects( barrierRect() ) )
             paintBarrier( &p );
 

paintBarrier() does the same sort of thing as paintShot(), paintTarget(), and paintCannon(). -

    void CannonField::paintBarrier( TQPainter *p )
+

    void CannonField::paintBarrier( TQPainter *p )
     {
-        p->setBrush( yellow );
-        p->setPen( black );
-        p->drawRect( barrierRect() );
+        p->setBrush( yellow );
+        p->setPen( black );
+        p->drawRect( barrierRect() );
     }
 

This private function paints the barrier as a rectangle filled with @@ -170,26 +170,26 @@ yellow and with a black outline.

This private function returns the rectangle of the barrier. We fix the bottom edge of the barrier to the bottom edge of the widget. -

    bool CannonField::barrelHit( const TQPoint &p ) const
+

    bool CannonField::barrelHit( const TQPoint &p ) const
     {
-        TQWMatrix mtx;
-        mtx.translate( 0, height() - 1 );
-        mtx.rotate( -ang );
-        mtx = mtx.invert();
-        return barrelRect.contains( mtx.map(p) );
+        TQWMatrix mtx;
+        mtx.translate( 0, height() - 1 );
+        mtx.rotate( -ang );
+        mtx = mtx.invert();
+        return barrelRect.contains( mtx.map(p) );
     }
 

This function returns TRUE if the point is in the barrel; otherwise it returns FALSE. -

Here we use the class TQWMatrix. It is defined in the header file -qwmatrix.h, which is included by qpainter.h. -

TQWMatrix defines a coordinate system mapping. It can perform the same -transformations as the TQPainter. +

Here we use the class TQWMatrix. It is defined in the header file +ntqwmatrix.h, which is included by ntqpainter.h. +

TQWMatrix defines a coordinate system mapping. It can perform the same +transformations as the TQPainter.

Here we perform the same transformation steps as we do when drawing the barrel in the paintCannon() function. First we translate the coordinate system and then we rotate it.

Now we need to check whether the point p (in widget coordinates) lies -inside the barrel. To do this, we invert the transformation matrix. +inside the barrel. To do this, we invert the transformation matrix. The inverted matrix performs the inverse transformation that we used when drawing the barrel. We map the point p using the inverted matrix and return TRUE if it is inside the original barrel rectangle. @@ -197,48 +197,48 @@ matrix and return TRUE if it is inside the original barrel rectangle.

-

    #include <qaccel.h>
+

    #include <ntqaccel.h>
 
-

We include the class definition of TQAccel. -

        TQVBox *box = new TQVBox( this, "cannonFrame" );
-        box->setFrameStyle( TQFrame::WinPanel | TQFrame::Sunken );
+

We include the class definition of TQAccel. +

        TQVBox *box = new TQVBox( this, "cannonFrame" );
+        box->setFrameStyle( TQFrame::WinPanel | TQFrame::Sunken );
         cannonField = new CannonField( box, "cannonField" );
 
-

We create and set up a TQVBox, set its frame style, and then create +

We create and set up a TQVBox, set its frame style, and then create CannonField as a child of that box. Because nothing else is in the -box, the effect is that the TQVBox will put a frame around the +box, the effect is that the TQVBox will put a frame around the CannonField. -

        TQAccel *accel = new TQAccel( this );
-        accel->connectItem( accel->insertItem( Key_Enter ),
+

        TQAccel *accel = new TQAccel( this );
+        accel->connectItem( accel->insertItem( Key_Enter ),
                             this, SLOT(fire()) );
-        accel->connectItem( accel->insertItem( Key_Return ),
+        accel->connectItem( accel->insertItem( Key_Return ),
                             this, SLOT(fire()) );
 

Here we create and set up an accelerator. An accelerator is an object that intercepts keyboard events to an application and calls slots if certain keys are pressed. This mechanism is also called shortcut keys. Note that an accelerator is a child of a widget and will be -destroyed when that widget is destroyed. TQAccel is not a widget +destroyed when that widget is destroyed. TQAccel is not a widget and has no visible effect on its parent.

We define two shortcut keys. We want the slot fire() to be called when the user presses Enter, and we want the application to quit when key Ctrl+Q is pressed. Because Enter is sometimes Return and there are even keyboards with both keys, we make both Enter and Return invoke fire(). -

        accel->connectItem( accel->insertItem( CTRL+Key_Q ),
-                            qApp, SLOT(quit()) );
+

        accel->connectItem( accel->insertItem( CTRL+Key_Q ),
+                            qApp, SLOT(quit()) );
 

And then we set up Ctrl+Q to do the same thing as Alt+Q. Some people are more used to Ctrl+Q (and anyway it shows how do do it).

CTRL, Key_Enter, Key_Return and Key_Q are all constants provided by TQt. They're actually TQt::Key_Enter, etc., but practically all classes -inherit the TQt namespace class. +inherit the TQt namespace class.

        TQGridLayout *grid = new TQGridLayout( this, 2, 2, 10 );
         grid->addWidget( quit, 0, 0 );
         grid->addWidget( box, 1, 1 );
         grid->setColStretch( 1, 10 );
 
-

We put box (the TQVBox), not the CannonField, in the lower-right +

We put box (the TQVBox), not the CannonField, in the lower-right cell.

Behavior

-- cgit v1.2.3