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-12.html | 94 +++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 47 deletions(-) (limited to 'doc/html/tutorial1-12.html') diff --git a/doc/html/tutorial1-12.html b/doc/html/tutorial1-12.html index 5951815b..4db7280e 100644 --- a/doc/html/tutorial1-12.html +++ b/doc/html/tutorial1-12.html @@ -55,13 +55,13 @@ implementation.

    class TQLabel;
 
-

We name declare TQLabel because we want to use a pointer to it in the class +

We name declare TQLabel because we want to use a pointer to it in the class definition. -

    class LCDRange : public TQVBox
+

    class LCDRange : public TQVBox
     {
         Q_OBJECT
     public:
-        LCDRange( TQWidget *parent=0, const char *name=0 );
+        LCDRange( TQWidget *parent=0, const char *name=0 );
         LCDRange( const char *s, TQWidget *parent=0,
                   const char *name=0 );
 
@@ -78,7 +78,7 @@ the parent and name.

Because we now have two constructors, we have chosen to put the common initialization in the private init() function. -

        TQLabel      *label;
+

        TQLabel      *label;
 

We also have a new private variable: a TQLabel. TQLabel is one of TQt's standard widgets and can show a text or a pixmap with or without a @@ -87,11 +87,11 @@ frame.

-

    #include <qlabel.h>
+

    #include <ntqlabel.h>
 
-

Here we include the TQLabel class definition. -

    LCDRange::LCDRange( TQWidget *parent, const char *name )
-            : TQVBox( parent, name )
+

Here we include the TQLabel class definition. +

    LCDRange::LCDRange( TQWidget *parent, const char *name )
+            : TQVBox( parent, name )
     {
         init();
     }
@@ -100,7 +100,7 @@ frame.
 initialization code.
 

    LCDRange::LCDRange( const char *s, TQWidget *parent,
                         const char *name )
-            : TQVBox( parent, name )
+            : TQVBox( parent, name )
     {
         init();
         setText( s );
@@ -109,35 +109,35 @@ initialization code.
 

This constructor first calls init() and then sets the label text.

    void LCDRange::init()
     {
-        TQLCDNumber *lcd  = new TQLCDNumber( 2, this, "lcd"  );
-        slider = new TQSlider( Horizontal, this, "slider" );
-        slider->setRange( 0, 99 );
-        slider->setValue( 0 );
+        TQLCDNumber *lcd  = new TQLCDNumber( 2, this, "lcd"  );
+        slider = new TQSlider( Horizontal, this, "slider" );
+        slider->setRange( 0, 99 );
+        slider->setValue( 0 );
 
-        label = new TQLabel( " ", this, "label"  );
-        label->setAlignment( AlignCenter );
+        label = new TQLabel( " ", this, "label"  );
+        label->setAlignment( AlignCenter );
 
-        connect( slider, SIGNAL(valueChanged(int)),
-                 lcd, SLOT(display(int)) );
-        connect( slider, SIGNAL(valueChanged(int)),
+        connect( slider, SIGNAL(valueChanged(int)),
+                 lcd, SLOT(display(int)) );
+        connect( slider, SIGNAL(valueChanged(int)),
                  SIGNAL(valueChanged(int)) );
 
-        setFocusProxy( slider );
+        setFocusProxy( slider );
     }
 

The setup of lcd and slider is the same as in the previous -chapter. Next we create a TQLabel and tell it to align the contents +chapter. Next we create a TQLabel and tell it to align the contents centered (both vertically and horizontally). The connect() statements have also been taken from the previous chapter.

    const char *LCDRange::text() const
     {
-        return label->text();
+        return label->text();
     }
 

This function returns the label text.

    void LCDRange::setText( const char *s )
     {
-        label->setText( s );
+        label->setText( s );
     }
 

This function sets the label text. @@ -158,22 +158,22 @@ it contains a target. signal is emitted when the shot moves beyond the right or bottom edge of the widget (i.e., it is certain that it has not and will not hit the target). -

        void  paintTarget( TQPainter * );
+

        void  paintTarget( TQPainter * );
 

This private function paints the target. -

        TQRect targetRect() const;
+

        TQRect targetRect() const;
 

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

        TQPoint target;
+

        TQPoint target;
 

This private variable contains the center point of the target.

t12/cannon.cpp

-

    #include <qdatetime.h>
+

    #include <ntqdatetime.h>
 
-

We include the TQDate, TQTime, and TQDateTime class definitions. +

We include the TQDate, TQTime, and TQDateTime class definitions.

    #include <stdlib.h>
 

We include the stdlib library because we need the rand() function. @@ -192,10 +192,10 @@ repaint() on a hidden widget. TQTime midnight( 0, 0, 0 ); srand( midnight.secsTo(TQTime::currentTime()) ); } - TQRegion r( targetRect() ); + TQRegion r( targetRect() ); target = TQPoint( 200 + rand() % 190, 10 + rand() % 255 ); - repaint( r.unite( targetRect() ) ); + repaint( r.unite( targetRect() ) ); }

This private function creates a target center point at a new "random" @@ -214,7 +214,7 @@ because we set first_time to FALSE inside the if block.

Then we create the TQTime object midnight, which represents the time 00:00:00. Next we fetch the number of seconds from midnight until now and use it as a random seed. See the documentation for TQDate, -TQTime, and TQDateTime for more information. +TQTime, and TQDateTime for more information.

Finally we calculate the target's center point. We keep it within the rectangle (x=200, y=35, width=190, height=255), (i.e., the possible x and y values are x = 200..389 and y = 35..289) in a @@ -225,14 +225,14 @@ the left edge and with x values increasing to the right.

Note that rand() returns a random integer >= 0.

    void CannonField::moveShot()
     {
-        TQRegion r( shotRect() );
+        TQRegion r( shotRect() );
         timerCount++;
 
-        TQRect shotR = shotRect();
+        TQRect shotR = shotRect();
 

This part of the timer event has not changed from the previous chapter. -

        if ( shotR.intersects( targetRect() ) ) {
-            autoShootTimer->stop();
+

        if ( shotR.intersects( targetRect() ) ) {
+            autoShootTimer->stop();
             emit hit();
 

This if statement checks whether the shot rectangle intersects the @@ -242,8 +242,8 @@ world that a target was destroyed, and return.

Note that we could have created a new target on the spot, but because the CannonField is a component we leave such decisions to the user of the component. -

        } else if ( shotR.x() > width() || shotR.y() > height() ) {
-            autoShootTimer->stop();
+

        } else if ( shotR.x() > width() || shotR.y() > height() ) {
+            autoShootTimer->stop();
             emit missed();
 

This if statement is the same as in the previous chapter, except that @@ -254,30 +254,30 @@ failure.

And the rest of the function is as before.

CannonField::paintEvent() is as before, except that this has been added: -

        if ( updateR.intersects( targetRect() ) )
+

        if ( updateR.intersects( targetRect() ) )
             paintTarget( &p );
 

These two lines make sure that the target is also painted when necessary. -

    void CannonField::paintTarget( TQPainter *p )
+

    void CannonField::paintTarget( TQPainter *p )
     {
-        p->setBrush( red );
-        p->setPen( black );
-        p->drawRect( targetRect() );
+        p->setBrush( red );
+        p->setPen( black );
+        p->drawRect( targetRect() );
     }
 

This private function paints the target; a rectangle filled with red and with a black outline.

    TQRect CannonField::targetRect() const
     {
-        TQRect r( 0, 0, 20, 10 );
-        r.moveCenter( TQPoint(target.x(),height() - 1 - target.y()) );
+        TQRect r( 0, 0, 20, 10 );
+        r.moveCenter( TQPoint(target.x(),height() - 1 - target.y()) );
         return r;
     }
 

This private function returns the enclosing rectangle of the target. Remember from newTarget() that the target point uses y coordinate 0 at the bottom of the widget. We calculate the point in widget coordinates -before we call TQRect::moveCenter(). +before we call TQRect::moveCenter().

The reason we have chosen this coordinate mapping is to fix the distance between the target and the bottom of the widget. Remember that the widget can be resized by the user or the program at any time. @@ -296,7 +296,7 @@ changed the constructor to set the new LCDRange text labels.

Behavior

The LCDRange widgets look a bit strange - the built-in layout -management in TQVBox gives the labels too much space and the rest not +management in TQVBox gives the labels too much space and the rest not enough. We'll fix that in the next chapter.

(See Compiling for how to create a makefile and build the application.) @@ -305,12 +305,12 @@ makefile and build the application.)

Make a cheat button that, when pressed, makes the CannonField display the shot trajectory for five seconds.

If you did the "round shot" exercise from the previous chapter, try -changing the shotRect() to a shotRegion() that returns a TQRegion so +changing the shotRect() to a shotRegion() that returns a TQRegion so you can have really accurate collision detection.

Make a moving target.

Make sure that the target is always created entirely on-screen.

Make sure that the widget cannot be resized so that the target isn't -visible. Hint: TQWidget::setMinimumSize() is your friend. +visible. Hint: TQWidget::setMinimumSize() is your friend.

Not easy; make it possible to have several shots in the air at the same time. Hint: make a Shot object.

You're now ready for Chapter 13. -- cgit v1.2.1