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-08.html | 58 +++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'doc/html/tutorial1-08.html') diff --git a/doc/html/tutorial1-08.html b/doc/html/tutorial1-08.html index 25d8479a9..fb88d4bdb 100644 --- a/doc/html/tutorial1-08.html +++ b/doc/html/tutorial1-08.html @@ -63,38 +63,38 @@ Until now, it has been fixed at 0..99.

    void LCDRange::setRange( int minVal, int maxVal )
     {
         if ( minVal < 0 || maxVal > 99 || minVal > maxVal ) {
-          qWarning( "LCDRange::setRange(%d,%d)\n"
+          qWarning( "LCDRange::setRange(%d,%d)\n"
                    "\tRange must be 0..99\n"
                    "\tand minVal must not be greater than maxVal",
                    minVal, maxVal );
           return;
         }
-        slider->setRange( minVal, maxVal );
+        slider->setRange( minVal, maxVal );
     }
 

SetRange() sets the range of the slider in the LCDRange. Because we -have set up the TQLCDNumber to always display two digits, we want to +have set up the TQLCDNumber to always display two digits, we want to limit the possible range of minVal and maxVal to 0..99 to avoid overflow of the TQLCDNumber. (We could have allowed values down to -9 but chose not to.) If the arguments are illegal, we use TQt's -qWarning() function to issue a warning to the user and return +qWarning() function to issue a warning to the user and return immediately. qWarning() is a printf-like function that by default sends its output to stderr. If you want, you can install your own handler -function using ::qInstallMsgHandler(). +function using ::qInstallMsgHandler().

t8/cannon.h

CannonField is a new custom widget that knows how to display itself.

-

    class CannonField : public TQWidget
+

    class CannonField : public TQWidget
     {
         Q_OBJECT
     public:
-        CannonField( TQWidget *parent=0, const char *name=0 );
+        CannonField( TQWidget *parent=0, const char *name=0 );
 
-

CannonField inherits TQWidget, and we use the same idiom as for LCDRange. +

CannonField inherits TQWidget, and we use the same idiom as for LCDRange.

        int angle() const { return ang; }
-        TQSizePolicy sizePolicy() const;
+        TQSizePolicy sizePolicy() const;
 
     public slots:
         void setAngle( int degrees );
@@ -114,13 +114,13 @@ to update itself (i.e., paint the widget's surface).
 
 

-

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

    CannonField::CannonField( TQWidget *parent, const char *name )
+            : TQWidget( parent, name )
     {
 

Again, we use the same idiom as for LCDRange in the previous chapter.

        ang = 45;
-        setPalette( TQPalette( TQColor( 250, 250, 200) ) );
+        setPalette( TQPalette( TQColor( 250, 250, 200) ) );
     }
 

The constructor initializes the angle value to 45 degrees and sets a @@ -137,7 +137,7 @@ colors will actually be used.) if ( ang == degrees ) return; ang = degrees; - repaint(); + repaint(); emit angleChanged( ang ); }

@@ -146,17 +146,17 @@ colors will actually be used.) chosen not to issue a warning if the new angle is out of range.

If the new angle equals the old one, we return immediately. It is important to only emit the signal angleChanged() when the angle really has changed. -

Then we set the new angle value and repaint our widget. The TQWidget::repaint() function clears the widget (usually filling it with +

Then we set the new angle value and repaint our widget. The TQWidget::repaint() function clears the widget (usually filling it with its background color) and sends a paint event to the widget. This results in a call to the paint event function of the widget.

Finally, we emit the angleChanged() signal to tell the outside world that the angle has changed. The emit keyword is unique to TQt and not regular C++ syntax. In fact, it is a macro. -

    void CannonField::paintEvent( TQPaintEvent * )
+

    void CannonField::paintEvent( TQPaintEvent * )
     {
-        TQString s = "Angle = " + TQString::number( ang );
-        TQPainter p( this );
-        p.drawText( 200, 200, s );
+        TQString s = "Angle = " + TQString::number( ang );
+        TQPainter p( this );
+        p.drawText( 200, 200, s );
     }
 

This is our first attempt to write a paint event handler. The event @@ -164,8 +164,8 @@ argument contains a description of the paint event. T contains the region in the widget that must be updated. For the time being, we will be lazy and just paint everything.

Our code displays the angle value in the widget at a fixed position. -First we create a TQString with some text and the angle; then we create -a TQPainter operating on this widget and use it to paint the string. +First we create a TQString with some text and the angle; then we create +a TQPainter operating on this widget and use it to paint the string. We'll come back to TQPainter later; it can do a great many things.

t8/main.cpp

@@ -174,10 +174,10 @@ We'll come back to TQPainter later; it can do a great many things.

    #include "cannon.h"
 

We include our new class. -

    class MyWidget: public TQWidget
+

    class MyWidget: public TQWidget
     {
     public:
-        MyWidget( TQWidget *parent=0, const char *name=0 );
+        MyWidget( TQWidget *parent=0, const char *name=0 );
     };
 

This time we include a single LCDRange and a CannonField in our top-level @@ -192,9 +192,9 @@ widget. = new CannonField( this, "cannonField" );

We create our CannonField. -

        connect( angle, SIGNAL(valueChanged(int)),
+

        connect( angle, SIGNAL(valueChanged(int)),
                  cannonField, SLOT(setAngle(int)) );
-        connect( cannonField, SIGNAL(angleChanged(int)),
+        connect( cannonField, SIGNAL(angleChanged(int)),
                  angle, SLOT(setValue(int)) );
 

Here we connect the valueChanged() signal of the LCDRange to the @@ -213,7 +213,7 @@ loop upon the first change of one of the values.

        TQGridLayout *grid = new TQGridLayout( this, 2, 2, 10 );
         //2x2, 10 pixel border
 
-

So far we have used the no-assembly-required TQVBox and TQGrid widgets +

So far we have used the no-assembly-required TQVBox and TQGrid widgets for geometry management. Now, however, we want to have a little more control over the layout, and we switch to the more powerful TQGridLayout class. TQGridLayout isn't a widget; it is a different class that can @@ -244,7 +244,7 @@ resized.

We set an initial angle value. Note that this will trigger the connection from LCDRange to CannonField. -

        angle->setFocus();
+

        angle->setFocus();
 

Our last action is to set angle to have keyboard focus so that keyboard input will go to the LCDRange widget by default. @@ -252,11 +252,11 @@ keyboard input will go to the LCDRange widget by default. to be terribly useful. However, its constructor just got a new line:

-

        setFocusProxy( slider );
+
        setFocusProxy( slider );
 

The LCDRange sets the slider to be its focus proxy. That means that when someone (the program or the user) wants to give the LCDRange -keyboard focus, the slider should take care of it. TQSlider has a decent +keyboard focus, the slider should take care of it. TQSlider has a decent keyboard interface, so with just one line of code we've given LCDRange one.

Behavior @@ -278,7 +278,7 @@ and size? Why?

If you give the left-hand column a non-zero stretch factor, what happens when you resize the window?

Leave out the setFocus() call. Which behavior do you prefer? -

Try to change "Quit" to "&Quit" in the TQButton::setText() call. How +

Try to change "Quit" to "&Quit" in the TQButton::setText() call. How does the button's look change? What happens if you press Alt+Q while the program's running? (It is Meta+Q on a few keyboards.)

Center the text in the CannonField. -- cgit v1.2.3