diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-07-15 19:08:22 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-07-18 09:31:41 +0900 |
commit | a30f5359f03c3017fa19a6770fab32d25d22cb87 (patch) | |
tree | cb365dd7a1c3666e3f972c6cad04be7b8e846cba /doc/html/designer-manual-3.html | |
parent | 25ad1267da6916e738a126ff5a9b41cd686adfc6 (diff) | |
download | tqt3-a30f5359f03c3017fa19a6770fab32d25d22cb87.tar.gz tqt3-a30f5359f03c3017fa19a6770fab32d25d22cb87.zip |
Rename graphics class nt* related files to equivalent tq* (part 1)
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'doc/html/designer-manual-3.html')
-rw-r--r-- | doc/html/designer-manual-3.html | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/doc/html/designer-manual-3.html b/doc/html/designer-manual-3.html index 51e2bb3aa..7234bf50c 100644 --- a/doc/html/designer-manual-3.html +++ b/doc/html/designer-manual-3.html @@ -263,16 +263,16 @@ body { background: #ffffff; color: black; } <ul><li><p>class TQString;</p> <li><p>class TQColor;</p> </ul><h4><a name="6-3"></a>Adding Includes</h4> -<p>Our form will also need some included files. Includes may be added in the declaration, or (for preference) in the implementation. Right click "Includes (in Implementation)", then click <b>Edit</b>. Use the dialog that pops up to enter "ntqcolor.h" and "tqstring.h". Since we're going to use the clipboard we'll need access to the global clipboard object via <a href="ntqapplication.html">TQApplication</a>, so also add "ntqapplication.h" and "tqclipboard.h". We'll also be doing some drawing (e.g. the color swatches), so add "ntqpainter.h" too, then close the dialog.</p> +<p>Our form will also need some included files. Includes may be added in the declaration, or (for preference) in the implementation. Right click "Includes (in Implementation)", then click <b>Edit</b>. Use the dialog that pops up to enter "tqcolor.h" and "tqstring.h". Since we're going to use the clipboard we'll need access to the global clipboard object via <a href="ntqapplication.html">TQApplication</a>, so also add "ntqapplication.h" and "tqclipboard.h". We'll also be doing some drawing (e.g. the color swatches), so add "tqpainter.h" too, then close the dialog.</p> <p align="center"><img align="middle" src="mw-editincimp.png" width="339" height="327"> </p> <p>When entering include files you can include double quotes or angle brackets if you wish; if you don't use either <em>TQt Designer</em> will put in double quotes automatically.</p> <p>You should now have added the following includes (in implementation):</p> -<ul><li><p>"ntqcolor.h"</p> +<ul><li><p>"tqcolor.h"</p> <li><p>"tqstring.h"</p> <li><p>"ntqapplication.h"</p> <li><p>"tqclipboard.h"</p> -<li><p>"ntqpainter.h"</p> +<li><p>"tqpainter.h"</p> </ul><h4><a name="6-4"></a>Signals and Slots Connections</h4> <p>Most of the signals and slots connections were created automatically by the main window wizard when we created the main form. We have added some new actions since then, and we need to ensure that they are connected to slots so that we can code their behavior.</p> <p align="center"><img align="middle" src="mw-conn1.png" width="608" height="341"> @@ -385,11 +385,11 @@ body { background: #ffffff; color: black; } int row = 0; TQMap<TQString,TQColor>::ConstIterator it; for ( it = m_colors.constBegin(); it != m_colors.constEnd(); ++it ) { - <a href="ntqcolor.html">TQColor</a> color = it.data(); + <a href="tqcolor.html">TQColor</a> color = it.data(); pixmap.<a href="ntqpixmap.html#fill">fill</a>( color ); colorTable->setText( row, COL_NAME, it.key() ); colorTable->setPixmap( row, COL_NAME, pixmap ); - colorTable->setText( row, COL_HEX, color.<a href="ntqcolor.html#name">name</a>().upper() ); + colorTable->setText( row, COL_HEX, color.<a href="tqcolor.html#name">name</a>().upper() ); if ( m_show_web ) { <a href="qchecktableitem.html">TQCheckTableItem</a> *item = new <a href="qchecktableitem.html">TQCheckTableItem</a>( colorTable, "" ); item-><a href="qchecktableitem.html#setChecked">setChecked</a>( isWebColor( color ) ); @@ -422,17 +422,17 @@ body { background: #ffffff; color: black; } } </pre> <p>This function is at the heart of the application. It visually presents the data to the user. If the table is "dirty" (e.g. if the user has added or deleted colors in the icon view, or has opened a color file) we will populate the table. We start by deleting the contents of every cell. Next we change the number of rows to equal the number of colors in the colors map. For each color we want to display a little square that shows the color, so we create a pixmap of the required size.</p> -<p>We now create an iterator for our colors map, and iterate over every color. The colors map has the user's color names as its keys, and <a href="ntqcolor.html">TQColor</a> instances as values. We retrieve the color and fill our pixmap with that color. We then set the "Name" column (column <tt>COL_NAME</tt>), to have the color's name (<tt>it.key()</tt>) and the pixmap we've just filled with that color. <a href="ntqcolor.html">TQColor</a>'s <tt>name()</tt> function returns a string that is the hex representation of a color, e.g. "#12AB2F"; we retrieve this and set the second ("Hex") column to this value.</p> +<p>We now create an iterator for our colors map, and iterate over every color. The colors map has the user's color names as its keys, and <a href="tqcolor.html">TQColor</a> instances as values. We retrieve the color and fill our pixmap with that color. We then set the "Name" column (column <tt>COL_NAME</tt>), to have the color's name (<tt>it.key()</tt>) and the pixmap we've just filled with that color. <a href="tqcolor.html">TQColor</a>'s <tt>name()</tt> function returns a string that is the hex representation of a color, e.g. "#12AB2F"; we retrieve this and set the second ("Hex") column to this value.</p> <p>If the user wants to see if which colors are web colors we create a <a href="qchecktableitem.html">TQCheckTableItem</a>, and check it if it is a web color. (We'll cover <tt>isWebColor()</tt> shortly.) We then insert this <a href="qchecktableitem.html">TQCheckTableItem</a> into the "Web" column.</p> <p>Having populated the table we call <tt>adjustColumn()</tt> to ensure that each column is just wide enough to show its widest entry, and show or hide the "Web" column depending on the user's preference.</p> <p>Finally we set <tt>m_table_dirty</tt> to FALSE, since it is now up-to-date.</p> <p>If the icon view is "dirty" we <tt>clear()</tt> it of any existing data. We then iterate over each color in our colors map. For each color we create a new <a href="tqiconviewitem.html">TQIconViewItem</a>; we label the item with the user's color name and provide a pixmap (generated by <tt>colorSwatch()</tt>, covered shortly) in the relevant color. Finally we set <tt>m_icons_dirty</tt> to "FALSE", since it is now up-to-date.</p> <h4><a name="6-10"></a>isWebColor()</h4> -<pre> bool MainForm::isWebColor( <a href="ntqcolor.html">TQColor</a> color ) +<pre> bool MainForm::isWebColor( <a href="tqcolor.html">TQColor</a> color ) { - int r = color.<a href="ntqcolor.html#red">red</a>(); - int g = color.<a href="ntqcolor.html#green">green</a>(); - int b = color.<a href="ntqcolor.html#blue">blue</a>(); + int r = color.<a href="tqcolor.html#red">red</a>(); + int g = color.<a href="tqcolor.html#green">green</a>(); + int b = color.<a href="tqcolor.html#blue">blue</a>(); return ( ( r == 0 || r == 51 || r == 102 || r == 153 || r == 204 || r == 255 ) && @@ -444,20 +444,20 @@ body { background: #ffffff; color: black; } </pre> <p>The 216 web colors are those colors whose RGB (Red, Green, Blue) values are all in the set (0, 51, 102, 153, 204, 255).</p> <h4><a name="6-11"></a>colorSwatch()</h4> -<pre> TQPixmap MainForm::colorSwatch( const <a href="ntqcolor.html">TQColor</a> color ) +<pre> TQPixmap MainForm::colorSwatch( const <a href="tqcolor.html">TQColor</a> color ) { <a href="ntqpixmap.html">TQPixmap</a> pixmap( 80, 80 ); pixmap.<a href="ntqpixmap.html#fill">fill</a>( white ); - <a href="ntqpainter.html">TQPainter</a> painter; - painter.<a href="ntqpainter.html#begin">begin</a>( &pixmap ); - painter.<a href="ntqpainter.html#setPen">setPen</a>( <a href="ntqt.html#PenStyle-enum">NoPen</a> ); - painter.<a href="ntqpainter.html#setBrush">setBrush</a>( color ); - painter.<a href="ntqpainter.html#drawEllipse">drawEllipse</a>( 0, 0, 80, 80 ); - painter.<a href="ntqpainter.html#end">end</a>(); + <a href="tqpainter.html">TQPainter</a> painter; + painter.<a href="tqpainter.html#begin">begin</a>( &pixmap ); + painter.<a href="tqpainter.html#setPen">setPen</a>( <a href="ntqt.html#PenStyle-enum">NoPen</a> ); + painter.<a href="tqpainter.html#setBrush">setBrush</a>( color ); + painter.<a href="tqpainter.html#drawEllipse">drawEllipse</a>( 0, 0, 80, 80 ); + painter.<a href="tqpainter.html#end">end</a>(); return pixmap; } </pre> - <p>We create a pixmap of a suitable size and fill it with white. We then create a <a href="ntqpainter.html">TQPainter</a> which we'll use to paint on the pixmap. We don't want a pen because we don't want an outline around the shape we draw. We draw an ellipse (which will be circular since we draw in an 80 x 80 pixel square). We return the resultant pixmap.</p> + <p>We create a pixmap of a suitable size and fill it with white. We then create a <a href="tqpainter.html">TQPainter</a> which we'll use to paint on the pixmap. We don't want a pen because we don't want an outline around the shape we draw. We draw an ellipse (which will be circular since we draw in an 80 x 80 pixel square). We return the resultant pixmap.</p> <h4><a name="6-12"></a>Creating main.cpp</h4> <p>Now that we've entered some of the code it would be nice to build and run the application to get a feel for the progress we've made. To do this we need to create a <tt>main()</tt> function. In TQt we typically create a small <tt>main.cpp</tt> file for the <tt>main()</tt> function. We can ask <em>TQt Designer</em> to create this file for us.</p> <p>Click <b>File|New</b> to invoke the <em>New File</em> dialog. Click "C++ Main-File", then click OK. The <em>Configure Main-File</em> dialog appears, listing the all the forms in the project. We've only got one form, "MainForm", so it is already highlighted. Click <b>OK</b> to create a <tt>main.cpp</tt> file that loads our MainForm.</p> @@ -527,13 +527,13 @@ body { background: #ffffff; color: black; } <p>By default any function that it typed directly into the code editor becomes a public function. To change this, right click the function's name in Object Explorer's Members list, and click <b>Properties</b> to invoke the <em>Edit Functions</em> dialog. This dialog can be used to change various attributes of the function, including changing it into a slot.</p> <pre> void MainForm::changedColor( const <a href="tqstring.html">TQString</a>& name ) { - <a href="ntqcolor.html">TQColor</a> color = m_colors[name]; - int r = color.<a href="ntqcolor.html#red">red</a>(); - int g = color.<a href="ntqcolor.html#green">green</a>(); - int b = color.<a href="ntqcolor.html#blue">blue</a>(); + <a href="tqcolor.html">TQColor</a> color = m_colors[name]; + int r = color.<a href="tqcolor.html#red">red</a>(); + int g = color.<a href="tqcolor.html#green">green</a>(); + int b = color.<a href="tqcolor.html#blue">blue</a>(); statusBar()->message( TQString( "%1 \"%2\" (%3,%4,%5)%6 {%7 %8 %9}" ). arg( <a href="tqobject.html#name-prop">name</a> ). - arg( color.<a href="ntqcolor.html#name">name</a>().upper() ). + arg( color.<a href="tqcolor.html#name">name</a>().upper() ). arg( r ).arg( g ).arg( b ). arg( isWebColor( color ) ? " web" : "" ). arg( r / 255.0, 1, 'f', 3 ). @@ -672,7 +672,7 @@ RED WHITESPACE GREEN WHITESPACE BLUE WHITESPACE NAME </pre> <p>The file may also include comment lines; these begin with '!' for example.</p> <p>There are numerous approaches we could have taken to parsing these files, but we've opted for a simple regular expression (regex). The regex is more "liberal" regarding the whitespace in the input than the format demands.</p> -<p>If a line matches the regex we create a new entry in the <tt>m_colors</tt> <a href="tqmap.html">TQMap</a>, setting its text to be the name of the color (<tt>regex.cap( 4 )</tt>), and its value to be a new <a href="ntqcolor.html">TQColor</a> created from the red, green and blue values. Lines that don't match the regex are treated as comments and are stored in the <tt>m_comments</tt> string list. (When we save the file we write all the comments out first even if they appeared in the middle of the file.)</p> +<p>If a line matches the regex we create a new entry in the <tt>m_colors</tt> <a href="tqmap.html">TQMap</a>, setting its text to be the name of the color (<tt>regex.cap( 4 )</tt>), and its value to be a new <a href="tqcolor.html">TQColor</a> created from the red, green and blue values. Lines that don't match the regex are treated as comments and are stored in the <tt>m_comments</tt> string list. (When we save the file we write all the comments out first even if they appeared in the middle of the file.)</p> <p>Once we've populated the <tt>m_colors</tt> map we mark the visible view as "dirty" and call <tt>populate()</tt> to update it. We then mark the visible view as not dirty and the non-visible view as dirty. This ensures that when user changes the view, the view they switch to will be updated. We could have simply marked both views as dirty and updated them both, but it is more efficient to update "lazily", after all the user may only ever use one view, so why waste their time updating the other one.</p> <p>Since we're using <a href="tqfile.html">TQFile</a> and <a href="tqregexp.html">TQRegExp</a> we need to include the relevant headers. (Right click "Includes (in Implementation)", then click <b>New</b>. Type "tqfile.h" and press <b>Enter</b>. Repeat this process to add "tqregexp.h".)</p> <p>You should now have added the following declarations to your includes (in implementation):</p> @@ -729,11 +729,11 @@ Captures: cap(1) cap(2) cap(3) cap(4) stream << m_comments.join( "\n" ) << "\n"; TQMap<TQString,TQColor>::ConstIterator it; for ( it = m_colors.constBegin(); it != m_colors.constEnd(); ++it ) { - <a href="ntqcolor.html">TQColor</a> color = it.data(); + <a href="tqcolor.html">TQColor</a> color = it.data(); stream << TQString( "%1 %2 %3\t\t%4" ). - arg( color.<a href="ntqcolor.html#red">red</a>(), 3 ). - arg( color.<a href="ntqcolor.html#green">green</a>(), 3 ). - arg( color.<a href="ntqcolor.html#blue">blue</a>(), 3 ). + arg( color.<a href="tqcolor.html#red">red</a>(), 3 ). + arg( color.<a href="tqcolor.html#green">green</a>(), 3 ). + arg( color.<a href="tqcolor.html#blue">blue</a>(), 3 ). arg( it.key() ) << "\n"; } file.<a href="tqfile.html#close">close</a>(); @@ -822,15 +822,15 @@ Captures: cap(1) cap(2) cap(3) cap(4) text = item-><a href="qtableitem.html#text">text</a>(); } if ( ! text.<a href="tqstring.html#isNull">isNull</a>() ) { - <a href="ntqcolor.html">TQColor</a> color = m_colors[text]; + <a href="tqcolor.html">TQColor</a> color = m_colors[text]; switch ( m_clip_as ) { - case CLIP_AS_HEX: text = color.<a href="ntqcolor.html#name">name</a>(); break; + case CLIP_AS_HEX: text = color.<a href="tqcolor.html#name">name</a>(); break; case CLIP_AS_NAME: break; case CLIP_AS_RGB: text = TQString( "%1,%2,%3" ). - arg( color.<a href="ntqcolor.html#red">red</a>() ). - arg( color.<a href="ntqcolor.html#green">green</a>() ). - arg( color.<a href="ntqcolor.html#blue">blue</a>() ); + arg( color.<a href="tqcolor.html#red">red</a>() ). + arg( color.<a href="tqcolor.html#green">green</a>() ). + arg( color.<a href="tqcolor.html#blue">blue</a>() ); break; } clipboard->setText( text ); |