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/designer-manual-4.html | 154 ++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 77 deletions(-) (limited to 'doc/html/designer-manual-4.html') diff --git a/doc/html/designer-manual-4.html b/doc/html/designer-manual-4.html index 4f1f7102c..d378ec9dd 100644 --- a/doc/html/designer-manual-4.html +++ b/doc/html/designer-manual-4.html @@ -58,8 +58,8 @@ body { background: #ffffff; color: black; }

We can use one of TQt's static dialogs to get the user to choose a color, but we need our own dialog to get them to give it a name. We'll create that dialog now.

Click File|New to invoke the New File dialog, then click "Dialog", then click OK. Drag a corner of the new form to make it a lot smaller. Change the form's name (in the Property Editor) to "ColorNameForm", and change its caption to "Color Tool -- Color Name". Click File|Save, then click Save to save it.

We'll now add some widgets to the dialog. Don't worry about precise positioning or sizing; we'll get TQt Designer to lay the form out perfectly for us shortly.

-

We need to create a TQLabel that will show the color the user has chosen. Click the TextLabel tool in the Toolbox, then click on the left hand side of the form. Change the label's name property to "colorLabel", and delete the text in the text property. Click the pixmap property's ellipsis button and choose the "editraise.png" image. Change the minimumSize property's width sub-property to 80, and set the scaledContents property to True.

-

Click the TextLabel tool again, then click to the right of the colorLabel, towards the top of the form. Change the text property to "&Name". Note that the ampersand is displayed; this is because a TQLabel cannot accept focus and we haven't specified a focus widget ("buddy") yet.

+

We need to create a TQLabel that will show the color the user has chosen. Click the TextLabel tool in the Toolbox, then click on the left hand side of the form. Change the label's name property to "colorLabel", and delete the text in the text property. Click the pixmap property's ellipsis button and choose the "editraise.png" image. Change the minimumSize property's width sub-property to 80, and set the scaledContents property to True.

+

Click the TextLabel tool again, then click to the right of the colorLabel, towards the top of the form. Change the text property to "&Name". Note that the ampersand is displayed; this is because a TQLabel cannot accept focus and we haven't specified a focus widget ("buddy") yet.

Click the LineEdit tool, then click to the right of the "Name" label, again towards the top of the form. Change the name property to "colorLineEdit".

Click on the "Name" label and change its buddy property to "colorLineEdit". The ampersand has now disappeared and Alt+N will set the focus in the colorLineEdit.

Click the PushButton tool, then click below the "colorLabel". Change the button's name property to "okPushButton", its text property to "OK", and its default property to True.

@@ -120,9 +120,9 @@ body { background: #ffffff; color: black; }

The situation is different for variables. If you add these to Members, Class Variables, they will be included as private variables in the class definition. If you type them at the top of the .ui.h file they will be form-global variables.

We'll start by adding some includes.

-
    #include <qcolor.h>
-    #include <qmap.h>
-    #include <qstring.h>
+
    #include <ntqcolor.h>
+    #include <ntqmap.h>
+    #include <ntqstring.h>
 

Enter these above the validate() function.

We also need a variable to hold the list of colors.

@@ -130,7 +130,7 @@ body { background: #ffffff; color: black; }

Add this line; we'll store the colors in a local m_colors map.

We also need a function that the caller can call to populate the m_colors map with the current colors.

-
    void ColorNameForm::setColors( const TQMap<TQString,TQColor>& colors )
+
    void ColorNameForm::setColors( const TQMap<TQString,TQColor>& colors )
     {
         m_colors = colors;
     }
@@ -138,9 +138,9 @@ body { background: #ffffff; color: black; }
  

Now that we've got a means of obtaining the list of color names we are ready to write the validate() function.

    void ColorNameForm::validate()
     {
-        TQString name = colorLineEdit->text();
-        if ( ! name.isEmpty() &&
-             ( m_colors.isEmpty() || ! m_colors.contains( name ) ) )
+        TQString name = colorLineEdit->text();
+        if ( ! name.isEmpty() &&
+             ( m_colors.isEmpty() || ! m_colors.contains( name ) ) )
             accept();
         else
             colorLineEdit->selectAll();
@@ -151,42 +151,42 @@ body { background: #ffffff; color: black; }
 

Using the Dialog

The ColorNameForm dialog will be called from the main form. The caller will firstly call one of TQt's static "choose a color" dialogs, and if the user chooses a color, will then invoke our custom dialog. Since we're going to use a "choose a color" dialog we will need the appropriate header file. We'll also be accessing the dialog's colorLabel (to set it to the chosen color), and the dialog's line edit (to retrieve the color name), so we'll need appropriate headers for these too.

Click "MainForm" in the Project Overview window so that Object Explorer shows the main form's objects.

-

Click Object Explorer's Members tab. Right click "Includes (in Implementation)", then click Edit to invoke the Edit Includes (in Implementation) dialog. Click Add then enter "qcolordialog.h". Click Add again, and enter "qlabel.h". Similarly add "qlineedit.h". We also need to include the header for the form we've just created, so add "colornameform.h", and since it is our last entry press Enter, then click Close.

+

Click Object Explorer's Members tab. Right click "Includes (in Implementation)", then click Edit to invoke the Edit Includes (in Implementation) dialog. Click Add then enter "ntqcolordialog.h". Click Add again, and enter "ntqlabel.h". Similarly add "ntqlineedit.h". We also need to include the header for the form we've just created, so add "colornameform.h", and since it is our last entry press Enter, then click Close.

You should now have added the following declarations to your includes (in implementation):

-
  • "qcolordialog.h"

    -
  • "qlabel.h"

    -
  • "qlineedit.h"

    +
    • "ntqcolordialog.h"

      +
    • "ntqlabel.h"

      +
    • "ntqlineedit.h"

    • "colornameform.h"

    Now we're ready to enter the editAdd() slot's code. Click "mainform.ui.h" in the Project Overview to invoke the code editor.

    editAdd()
        void MainForm::editAdd()
         {
    -        TQColor color = white;
    +        TQColor color = white;
             if ( ! m_colors.isEmpty() ) {
    -            TQWidget *visible = colorWidgetStack->visibleWidget();
    -            if ( visible == tablePage )
    +            TQWidget *visible = colorWidgetStack->visibleWidget();
    +            if ( visible == tablePage )
                     color = colorTable->text( colorTable->currentRow(),
                                               colorTable->currentColumn() );
                 else
                     color = colorIconView->currentItem()->text();
             }
    -        color = TQColorDialog::getColor( color, this );
    -        if ( color.isValid() ) {
    -            TQPixmap pixmap( 80, 10 );
    -            pixmap.fill( color );
    +        color = TQColorDialog::getColor( color, this );
    +        if ( color.isValid() ) {
    +            TQPixmap pixmap( 80, 10 );
    +            pixmap.fill( color );
                 ColorNameForm *colorForm = new ColorNameForm( this, "color", TRUE );
                 colorForm->setColors( m_colors );
                 colorForm->colorLabel->setPixmap( pixmap );
                 if ( colorForm->exec() ) {
    -                TQString name = colorForm->colorLineEdit->text();
    +                TQString name = colorForm->colorLineEdit->text();
                     m_colors[name] = color;
    -                TQPixmap pixmap( 22, 22 );
    -                pixmap.fill( color );
    +                TQPixmap pixmap( 22, 22 );
    +                pixmap.fill( color );
                     int row = colorTable->currentRow();
                     colorTable->insertRows( row, 1 );
                     colorTable->setText( row, COL_NAME, name );
                     colorTable->setPixmap( row, COL_NAME, pixmap );
    -                colorTable->setText( row, COL_HEX, color.name().upper() );
    +                colorTable->setText( row, COL_HEX, color.name().upper() );
                     if ( m_show_web ) {
                         TQCheckTableItem *item = new TQCheckTableItem( colorTable, "" );
                         item->setChecked( isWebColor( color ) );
    @@ -201,7 +201,7 @@ body { background: #ffffff; color: black; }
             }
         }
     
    -

    The code for this function is quite long, but it isn't difficult. We start by setting a default color to white. If there are any colors in the m_colors map we set the default color to be the current color showing in the current view. We then invoke TQt's static getColor() dialog, passing it the default color. (If the user cancels an invalid color is returned.)

    +

    The code for this function is quite long, but it isn't difficult. We start by setting a default color to white. If there are any colors in the m_colors map we set the default color to be the current color showing in the current view. We then invoke TQt's static getColor() dialog, passing it the default color. (If the user cancels an invalid color is returned.)

    If the user chose a color we want to show their chosen color in our custom dialog, so we create a pixmap and fill it with their chosen color. We create an instance of our ColorNameForm as a modal dialog (third argument is TRUE). We then call its setColors() function to set the colors in the m_colors map (so that the validate() function will work correctly). We set its colorLabel's pixmap to the pixmap we've just created, i.e. to a rectangle in the user's chosen color.

    We execute (exec()) the dialog. If the user clicks OK (and the color name they've entered is valid), the call will return a true value. In this case we retrieve the name they've entered from the line edit and create a new entry in the m_colors map using the name the user has given and the color they chose.

    At this point we could simply mark the views "dirty" and call repopulate. Instead we'll add the new color to each view directly and save the overhead of a full update (which might be considerable if we have thousands of colors).

    @@ -271,23 +271,23 @@ body { background: #ffffff; color: black; } { if ( ! findForm ) { findForm = new FindForm( this ); - connect( findForm, SIGNAL( lookfor(const TQString&) ), - this, SLOT( lookfor(const TQString&) ) ); + connect( findForm, SIGNAL( lookfor(const TQString&) ), + this, SLOT( lookfor(const TQString&) ) ); } findForm->show(); }

If we haven't created the FindForm, we create it and connect its lookfor() signal to a corresponding lookfor() slot that we'll create in the main form. We then show the FindForm so that the user can enter their search text and click find.

lookfor()
-
    void MainForm::lookfor( const TQString& text )
+
    void MainForm::lookfor( const TQString& text )
     {
-        if ( text.isEmpty() )
+        if ( text.isEmpty() )
             return;
-        TQString ltext = text.lower();
-        TQWidget *visible = colorWidgetStack->visibleWidget();
+        TQString ltext = text.lower();
+        TQWidget *visible = colorWidgetStack->visibleWidget();
         bool found = FALSE;
 
-        if ( visible == tablePage && colorTable->numRows() ) {
+        if ( visible == tablePage && colorTable->numRows() ) {
             int row = colorTable->currentRow();
             for ( int i = row + 1; i < colorTable->numRows(); ++i )
                 if ( colorTable->text( i, 0 ).lower().contains( ltext ) ) {
@@ -301,7 +301,7 @@ body { background: #ffffff; color: black; }
                 colorTable->setCurrentCell( row, 0 );
 
         }
-        else if ( visible == iconsPage ) {
+        else if ( visible == iconsPage ) {
             TQIconViewItem *start = colorIconView->currentItem();
             for ( TQIconViewItem *item = start->nextItem(); item; item = item->nextItem() )
                 if ( item->text().lower().contains( ltext ) ) {
@@ -397,29 +397,29 @@ body { background: #ffffff; color: black; }
     }
 

We create a new options form, passing it TRUE to make it modal. We set the radio buttons depending on the current setting of the m_clip_as variable. We set the check box to correspond with the m_show_web variable. We execute the form, and if the user clicks OK, we reflect their choices back into the relevant main form variables. If the user changed the m_show_web variable (by clicking the webCheckBox), we mark the table as "dirty" since it will need updating. We then call populate() which will update the table view if required.

-

Because we use our OptionsForm and access its radio buttons and checkbox we must add "optionsform.h", "qradiobutton.h" and "qcheckbox.h" to our includes in implementation. (Click Object Explorer's Members tab, right click "Includes (in Implementation)", then click Edit. Click Add and enter "optionsform.h"; click Add again and enter "qradiobutton.h"; click Add again and enter "qcheckbox.h". Press Enter, then click Close.)

+

Because we use our OptionsForm and access its radio buttons and checkbox we must add "optionsform.h", "ntqradiobutton.h" and "ntqcheckbox.h" to our includes in implementation. (Click Object Explorer's Members tab, right click "Includes (in Implementation)", then click Edit. Click Add and enter "optionsform.h"; click Add again and enter "ntqradiobutton.h"; click Add again and enter "ntqcheckbox.h". Press Enter, then click Close.)

You should now have added the following declarations to your includes (in implementation):

  • "optionsform.h"

    -
  • "qcheckbox.h"

    -
  • "qradiobutton.h"

    +
  • "ntqcheckbox.h"

    +
  • "ntqradiobutton.h"

Now the user can change options to suit their own preferences. But these option settings will be lost when they exit the application. We'll finish off by adding functions to load and save the user's settings.

Saving and Loading Settings

Logically we think of loading settings first, e.g. at application start up, and of saving settings last, e.g. at application termination. But we will code saving settings first, since then we'll know what it is that we must load.

-

TQt 3.0 introduced a new class TQSettings, that handles user settings in a platform independent way (e.g. it uses the registry on windows and rc files on Unix). Add the "qsettings.h" header to the includes in implementation. (Click Object Explorer's Members tab, right click "Includes (in Implementation)", click New, enter "qsettings.h", then press Enter.)

+

TQt 3.0 introduced a new class TQSettings, that handles user settings in a platform independent way (e.g. it uses the registry on windows and rc files on Unix). Add the "ntqsettings.h" header to the includes in implementation. (Click Object Explorer's Members tab, right click "Includes (in Implementation)", click New, enter "ntqsettings.h", then press Enter.)

You should now have added the following declaration to your includes (in implementation):

-
  • "qsettings.h"

    +
    • "ntqsettings.h"

    saveSettings()

        void MainForm::saveSettings()
         {
    -        TQSettings settings;
    -        settings.insertSearchPath( TQSettings::Windows, WINDOWS_REGISTRY );
    -        settings.writeEntry( APP_KEY + "WindowWidth", width() );
    -        settings.writeEntry( APP_KEY + "WindowHeight", height() );
    -        settings.writeEntry( APP_KEY + "WindowX", x() );
    -        settings.writeEntry( APP_KEY + "WindowY", y() );
    -        settings.writeEntry( APP_KEY + "ClipAs", m_clip_as );
    -        settings.writeEntry( APP_KEY + "ShowWeb", m_show_web );
    -        settings.writeEntry( APP_KEY + "View",
    +        TQSettings settings;
    +        settings.insertSearchPath( TQSettings::Windows, WINDOWS_REGISTRY );
    +        settings.writeEntry( APP_KEY + "WindowWidth", width() );
    +        settings.writeEntry( APP_KEY + "WindowHeight", height() );
    +        settings.writeEntry( APP_KEY + "WindowX", x() );
    +        settings.writeEntry( APP_KEY + "WindowY", y() );
    +        settings.writeEntry( APP_KEY + "ClipAs", m_clip_as );
    +        settings.writeEntry( APP_KEY + "ShowWeb", m_show_web );
    +        settings.writeEntry( APP_KEY + "View",
                     colorWidgetStack->visibleWidget() == tablePage );
         }
     
    @@ -429,7 +429,7 @@ body { background: #ffffff; color: black; } { if ( okToClear() ) { saveSettings(); - TQApplication::exit( 0 ); + TQApplication::exit( 0 ); } }
@@ -437,15 +437,15 @@ body { background: #ffffff; color: black; }

loadSettings()

    void MainForm::loadSettings()
     {
-        TQSettings settings;
-        settings.insertSearchPath( TQSettings::Windows, WINDOWS_REGISTRY );
-        int windowWidth = settings.readNumEntry( APP_KEY + "WindowWidth", 550 );
-        int windowHeight = settings.readNumEntry( APP_KEY + "WindowHeight", 500 );
-        int windowX = settings.readNumEntry( APP_KEY + "WindowX", 0 );
-        int windowY = settings.readNumEntry( APP_KEY + "WindowY", 0 );
-        m_clip_as = settings.readNumEntry( APP_KEY + "ClipAs", CLIP_AS_HEX );
-        m_show_web = settings.readBoolEntry( APP_KEY + "ShowWeb", TRUE );
-        if ( ! settings.readBoolEntry( APP_KEY + "View", TRUE ) ) {
+        TQSettings settings;
+        settings.insertSearchPath( TQSettings::Windows, WINDOWS_REGISTRY );
+        int windowWidth = settings.readNumEntry( APP_KEY + "WindowWidth", 550 );
+        int windowHeight = settings.readNumEntry( APP_KEY + "WindowHeight", 500 );
+        int windowX = settings.readNumEntry( APP_KEY + "WindowX", 0 );
+        int windowY = settings.readNumEntry( APP_KEY + "WindowY", 0 );
+        m_clip_as = settings.readNumEntry( APP_KEY + "ClipAs", CLIP_AS_HEX );
+        m_show_web = settings.readBoolEntry( APP_KEY + "ShowWeb", TRUE );
+        if ( ! settings.readBoolEntry( APP_KEY + "View", TRUE ) ) {
             colorWidgetStack->raiseWidget( iconsPage );
             viewIconsAction->setOn( TRUE );
         }
@@ -482,28 +482,28 @@ body { background: #ffffff; color: black; }
 
  • "findform.h"

Includes (in Implementation):

  • "optionsform.h"

    -
  • "qlineedit.h"

    -
  • "qlabel.h"

    -
  • "qclipboard.h"

    -
  • "qmessagebox.h"

    -
  • "qstatusbar.h"

    -
  • "qpainter.h"

    -
  • "qstring.h"

    -
  • "qcolor.h"

    -
  • "qapplication.h"

    -
  • "qfiledialog.h"

    -
  • "qfile.h"

    -
  • "qregexp.h"

    -
  • "qcolordialog.h"

    +
  • "ntqlineedit.h"

    +
  • "ntqlabel.h"

    +
  • "ntqclipboard.h"

    +
  • "ntqmessagebox.h"

    +
  • "ntqstatusbar.h"

    +
  • "ntqpainter.h"

    +
  • "ntqstring.h"

    +
  • "ntqcolor.h"

    +
  • "ntqapplication.h"

    +
  • "ntqfiledialog.h"

    +
  • "ntqfile.h"

    +
  • "ntqregexp.h"

    +
  • "ntqcolordialog.h"

  • "colornameform.h"

    -
  • "qcheckbox.h"

    -
  • "qradiobutton.h"

    -
  • "qsettings.h"

    +
  • "ntqcheckbox.h"

    +
  • "ntqradiobutton.h"

    +
  • "ntqsettings.h"

ColorNameForm Members

We put all the ColorNameForm declarations in the source code file. The file colornameform.ui.h should begin with the following declarations:

-
    #include <qcolor.h>
-    #include <qmap.h>
-    #include <qstring.h>
+
    #include <ntqcolor.h>
+    #include <ntqmap.h>
+    #include <ntqstring.h>
 
     TQMap<TQString,TQColor> m_colors;
 
@@ -514,7 +514,7 @@ body { background: #ffffff; color: black; }

The OptionsForm has no members.

main.cpp Members

This file should begin with the following declarations:

-
    #include <qapplication.h>
+
    #include <ntqapplication.h>
     #include "mainform.h"
 
-- cgit v1.2.1