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/tutorial2-08.html | 174 ++++++++++++++++++++++----------------------- 1 file changed, 87 insertions(+), 87 deletions(-) (limited to 'doc/html/tutorial2-08.html') diff --git a/doc/html/tutorial2-08.html b/doc/html/tutorial2-08.html index ebffded53..331ee3db8 100644 --- a/doc/html/tutorial2-08.html +++ b/doc/html/tutorial2-08.html @@ -40,12 +40,12 @@ enter label text and choose a label color for each label.

(Extracts from setdataform.h.)

-

    class SetDataForm: public TQDialog
+
    class SetDataForm: public TQDialog
     {
         Q_OBJECT
     public:
         SetDataForm( ElementVector *elements, int decimalPlaces,
-                     TQWidget *parent = 0, const char *name = "set data form",
+                     TQWidget *parent = 0, const char *name = "set data form",
                      bool modal = TRUE, WFlags f = 0 );
         ~SetDataForm() {}
 
@@ -59,10 +59,10 @@ enter label text and choose a label color for each label.
         void accept();
 
     private:
-        TQTable *table;
-        TQPushButton *colorPushButton;
-        TQPushButton *okPushButton;
-        TQPushButton *cancelPushButton;
+        TQTable *table;
+        TQPushButton *colorPushButton;
+        TQPushButton *okPushButton;
+        TQPushButton *cancelPushButton;
 
     protected:
         TQVBoxLayout *tableButtonBox;
@@ -88,20 +88,20 @@ TQt supports. We'll use these in the pattern combobox.
 

The Constructor

    SetDataForm::SetDataForm( ElementVector *elements, int decimalPlaces,
-                              TQWidget* parent,  const char* name,
+                              TQWidget* parent,  const char* name,
                               bool modal, WFlags f )
-        : TQDialog( parent, name, modal, f )
+        : TQDialog( parent, name, modal, f )
 
     {
         m_elements = elements;
         m_decimalPlaces = decimalPlaces;
 
-

We pass most of the arguments to the TQDialog superclass. We assign the +

We pass most of the arguments to the TQDialog superclass. We assign the elements vector pointer and the number of decimal places to display to member variables so that they are accessible by all SetDataForm's member functions. -

        setCaption( "Chart -- Set Data" );
-        resize( 540, 440 );
+

        setCaption( "Chart -- Set Data" );
+        resize( 540, 440 );
 

We set a caption for the dialog and resize it.

        tableButtonBox = new TQVBoxLayout( this, 11, 6, "table button box layout" );
@@ -109,26 +109,26 @@ member functions.
 

The layout of the form is quite simple. The buttons will be grouped together in a horizontal layout and the table and the button layout will be grouped together vertically using the tableButtonBox layout. -

        table = new TQTable( this, "data table" );
-        table->setNumCols( 5 );
-        table->setNumRows( ChartForm::MAX_ELEMENTS );
-        table->setColumnReadOnly( 1, TRUE );
-        table->setColumnReadOnly( 2, TRUE );
-        table->setColumnReadOnly( 4, TRUE );
-        table->setColumnWidth( 0, 80 );
-        table->setColumnWidth( 1, 60 ); // Columns 1 and 4 must be equal
-        table->setColumnWidth( 2, 60 );
-        table->setColumnWidth( 3, 200 );
-        table->setColumnWidth( 4, 60 );
-        TQHeader *th = table->horizontalHeader();
-        th->setLabel( 0, "Value" );
-        th->setLabel( 1, "Color" );
-        th->setLabel( 2, "Pattern" );
-        th->setLabel( 3, "Label" );
-        th->setLabel( 4, "Color" );
+

        table = new TQTable( this, "data table" );
+        table->setNumCols( 5 );
+        table->setNumRows( ChartForm::MAX_ELEMENTS );
+        table->setColumnReadOnly( 1, TRUE );
+        table->setColumnReadOnly( 2, TRUE );
+        table->setColumnReadOnly( 4, TRUE );
+        table->setColumnWidth( 0, 80 );
+        table->setColumnWidth( 1, 60 ); // Columns 1 and 4 must be equal
+        table->setColumnWidth( 2, 60 );
+        table->setColumnWidth( 3, 200 );
+        table->setColumnWidth( 4, 60 );
+        TQHeader *th = table->horizontalHeader();
+        th->setLabel( 0, "Value" );
+        th->setLabel( 1, "Color" );
+        th->setLabel( 2, "Pattern" );
+        th->setLabel( 3, "Label" );
+        th->setLabel( 4, "Color" );
         tableButtonBox->addWidget( table );
 
-

We create a new TQTable with five columns, and the same number of rows +

We create a new TQTable with five columns, and the same number of rows as we have elements in the elements vector. We make the color and pattern columns read only: this is to prevent the user typing in them. We will make the color changeable by the user clicking on a color or @@ -139,9 +139,9 @@ column and finally add the table to the tableButtonBox layout.

        buttonBox = new TQHBoxLayout( 0, 0, 6, "button box layout" );
 

We create a horizontal box layout to hold the buttons. -

        colorPushButton = new TQPushButton( this, "color button" );
-        colorPushButton->setText( "&Color..." );
-        colorPushButton->setEnabled( FALSE );
+

        colorPushButton = new TQPushButton( this, "color button" );
+        colorPushButton->setText( "&Color..." );
+        colorPushButton->setEnabled( FALSE );
         buttonBox->addWidget( colorPushButton );
 

We create a color button and add it to the buttonBox layout. We @@ -153,14 +153,14 @@ on a color cell.

Since we want to separate the color button from the OK and Cancel buttons we next create a spacer and add that to the buttonBox layout. -

        okPushButton = new TQPushButton( this, "ok button" );
-        okPushButton->setText( "OK" );
-        okPushButton->setDefault( TRUE );
+

        okPushButton = new TQPushButton( this, "ok button" );
+        okPushButton->setText( "OK" );
+        okPushButton->setDefault( TRUE );
         buttonBox->addWidget( okPushButton );
 
-        cancelPushButton = new TQPushButton( this, "cancel button" );
-        cancelPushButton->setText( "Cancel" );
-        cancelPushButton->setAccel( Key_Escape );
+        cancelPushButton = new TQPushButton( this, "cancel button" );
+        cancelPushButton->setText( "Cancel" );
+        cancelPushButton->setAccel( Key_Escape );
         buttonBox->addWidget( cancelPushButton );
 

The OK and Cancel buttons are created and added to the buttonBox. We @@ -170,22 +170,22 @@ key an accelerator for the Cancel button.

We add the buttonBox layout to the tableButtonBox and the layout is complete. -

        connect( table, SIGNAL( clicked(int,int,int,const TQPoint&) ),
+

        connect( table, SIGNAL( clicked(int,int,int,const TQPoint&) ),
                  this, SLOT( setColor(int,int) ) );
-        connect( table, SIGNAL( currentChanged(int,int) ),
+        connect( table, SIGNAL( currentChanged(int,int) ),
                  this, SLOT( currentChanged(int,int) ) );
-        connect( table, SIGNAL( valueChanged(int,int) ),
+        connect( table, SIGNAL( valueChanged(int,int) ),
                  this, SLOT( valueChanged(int,int) ) );
-        connect( colorPushButton, SIGNAL( clicked() ), this, SLOT( setColor() ) );
-        connect( okPushButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
-        connect( cancelPushButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
+        connect( colorPushButton, SIGNAL( clicked() ), this, SLOT( setColor() ) );
+        connect( okPushButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
+        connect( cancelPushButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
 

We now "wire up" the form.

  • If the user clicks a cell we call the setColor() slot; this will check that the cell is one that holds a color, and if it is, will invoke the color dialog. -
  • We connect the TQTable's currentChanged() signal to our own +
  • We connect the TQTable's currentChanged() signal to our own currentChanged() slot; this will be used to enable/disable the color button for example, depending on which column the user is in.
  • We connect the table's valueChanged() signal to our own @@ -194,7 +194,7 @@ correct number of decimal places.
  • If the user clicks the Color button we call a setColor() slot.
  • The OK button is connected to the accept() slot; we will update the elements vector in this slot. -
  • The Cancel button is connected to the TQDialog reject() slot, and +
  • The Cancel button is connected to the TQDialog reject() slot, and requires no further code or action on our part.

        TQPixmap patterns[MAX_PATTERNS];
@@ -202,8 +202,8 @@ requires no further code or action on our part.
         patterns[1]  = TQPixmap( pattern02 );
 

We create a pixmap for every brush pattern and store them in the patterns array. -

        TQRect rect = table->cellRect( 0, 1 );
-        TQPixmap pix( rect.width(), rect.height() );
+

        TQRect rect = table->cellRect( 0, 1 );
+        TQPixmap pix( rect.width(), rect.height() );
 

We obtain the rectangle that will be occupied by each color cell and create a blank pixmap of that size. @@ -211,28 +211,28 @@ create a blank pixmap of that size. Element element = (*m_elements)[i]; if ( element.isValid() ) - table->setText( + table->setText( i, 0, TQString( "%1" ).arg( element.value(), 0, 'f', m_decimalPlaces ) ); - TQColor color = element.valueColor(); - pix.fill( color ); - table->setPixmap( i, 1, pix ); - table->setText( i, 1, color.name() ); + TQColor color = element.valueColor(); + pix.fill( color ); + table->setPixmap( i, 1, pix ); + table->setText( i, 1, color.name() ); - TQComboBox *combobox = new TQComboBox; + TQComboBox *combobox = new TQComboBox; for ( int j = 0; j < MAX_PATTERNS; ++j ) - combobox->insertItem( patterns[j] ); - combobox->setCurrentItem( element.valuePattern() - 1 ); - table->setCellWidget( i, 2, combobox ); + combobox->insertItem( patterns[j] ); + combobox->setCurrentItem( element.valuePattern() - 1 ); + table->setCellWidget( i, 2, combobox ); - table->setText( i, 3, element.label() ); + table->setText( i, 3, element.label() ); color = element.labelColor(); - pix.fill( color ); - table->setPixmap( i, 4, pix ); - table->setText( i, 4, color.name() ); + pix.fill( color ); + table->setPixmap( i, 4, pix ); + table->setText( i, 4, color.name() );

For each element in the element vector we must populate the table.

If the element is valid we write its value in the first column (column @@ -246,16 +246,16 @@ CanvasText subclass) and store the color there. But we've taken a simpler route: we set the cell's text to the name of the color.

Next we populate the pattern combobox with the patterns. We will use the position of the chosen pattern in the combobox to determine which -pattern the user has selected. TQTable can make use of TQComboTableItem +pattern the user has selected. TQTable can make use of TQComboTableItem items; but these only support text, so we use setCellWidget() to -insert TQComboBox's into the table instead. +insert TQComboBox's into the table instead.

Next we insert the element's label. Finally we set the label color in the same way as we set the value color.

The Slots

    void SetDataForm::currentChanged( int, int col )
     {
-        colorPushButton->setEnabled( col == 1 || col == 4 );
+        colorPushButton->setEnabled( col == 1 || col == 4 );
     }
 

As the user navigates through the table currentChanged() signals are @@ -265,13 +265,13 @@ we enable the colorPushButton; otherwise we disable it. { if ( col == 0 ) { bool ok; - double d = table->text( row, col ).toDouble( &ok ); + double d = table->text( row, col ).toDouble( &ok ); if ( ok && d > EPSILON ) - table->setText( + table->setText( row, col, TQString( "%1" ).arg( d, 0, 'f', m_decimalPlaces ) ); - else if ( !table->text( row, col ).isEmpty() ) - table->setText( row, col, table->text( row, col ) + "?" ); + else if ( !table->text( row, col ).isEmpty() ) + table->setText( row, col, table->text( row, col ) + "?" ); } }

@@ -279,8 +279,8 @@ we enable the colorPushButton; otherwise we disable it. number of decimal places, or indicate that it is invalid.

    void SetDataForm::setColor()
     {
-        setColor( table->currentRow(), table->currentColumn() );
-        table->setFocus();
+        setColor( table->currentRow(), table->currentColumn() );
+        table->setFocus();
     }
 

If the user presses the Color button we call the other setColor() @@ -290,49 +290,49 @@ function and put the focus back into the table. if ( !( col == 1 || col == 4 ) ) return; - TQColor color = TQColorDialog::getColor( - TQColor( table->text( row, col ) ), + TQColor color = TQColorDialog::getColor( + TQColor( table->text( row, col ) ), this, "color dialog" ); - if ( color.isValid() ) { - TQPixmap pix = table->pixmap( row, col ); - pix.fill( color ); - table->setPixmap( row, col, pix ); - table->setText( row, col, color.name() ); + if ( color.isValid() ) { + TQPixmap pix = table->pixmap( row, col ); + pix.fill( color ); + table->setPixmap( row, col, pix ); + table->setText( row, col, color.name() ); } }

If this function is called with the focus on a color cell we call -the static TQColorDialog::getColor() dialog to get the user's choice of +the static TQColorDialog::getColor() dialog to get the user's choice of color. If they chose a color we fill the color cell's pixmap with that color and set the cell's text to the new color's name. -

    void SetDataForm::accept()
+

    void SetDataForm::accept()
     {
         bool ok;
         for ( int i = 0; i < ChartForm::MAX_ELEMENTS; ++i ) {
             Element &element = (*m_elements)[i];
-            double d = table->text( i, 0 ).toDouble( &ok );
+            double d = table->text( i, 0 ).toDouble( &ok );
             if ( ok )
                 element.setValue( d );
             else
                 element.setValue( Element::INVALID );
-            element.setValueColor( TQColor( table->text( i, 1 ) ) );
+            element.setValueColor( TQColor( table->text( i, 1 ) ) );
             element.setValuePattern(
-                    ((TQComboBox*)table->cellWidget( i, 2 ))->currentItem() + 1 );
-            element.setLabel( table->text( i, 3 ) );
-            element.setLabelColor( TQColor( table->text( i, 4 ) ) );
+                    ((TQComboBox*)table->cellWidget( i, 2 ))->currentItem() + 1 );
+            element.setLabel( table->text( i, 3 ) );
+            element.setLabelColor( TQColor( table->text( i, 4 ) ) );
         }
 
-        TQDialog::accept();
+        TQDialog::accept();
     }
 

If the user clicks OK we must update the elements vector. We iterate over the vector and set each element's value to the value the user has entered or INVALID if the value is invalid. We set the value color -and the label color by constructing TQColor temporaries that take a +and the label color by constructing TQColor temporaries that take a color name as argument. The pattern is set to the pattern combobox's current item with an offset of 1 (since our pattern numbers begin at 1, but the combobox's items are indexed from 0). -

Finally we call TQDialog::accept(). +

Finally we call TQDialog::accept().

« File Handling | Contents | -- cgit v1.2.1