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 /examples/fonts/simple-tqfont-demo | |
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 'examples/fonts/simple-tqfont-demo')
-rw-r--r-- | examples/fonts/simple-tqfont-demo/simple-tqfont-demo.cpp | 14 | ||||
-rw-r--r-- | examples/fonts/simple-tqfont-demo/simple-tqfont-demo.doc | 28 | ||||
-rw-r--r-- | examples/fonts/simple-tqfont-demo/simple-tqfont-demo.pro | 11 | ||||
-rw-r--r-- | examples/fonts/simple-tqfont-demo/viewer.cpp | 160 | ||||
-rw-r--r-- | examples/fonts/simple-tqfont-demo/viewer.h | 37 |
5 files changed, 250 insertions, 0 deletions
diff --git a/examples/fonts/simple-tqfont-demo/simple-tqfont-demo.cpp b/examples/fonts/simple-tqfont-demo/simple-tqfont-demo.cpp new file mode 100644 index 000000000..aa12a5055 --- /dev/null +++ b/examples/fonts/simple-tqfont-demo/simple-tqfont-demo.cpp @@ -0,0 +1,14 @@ + +#include "viewer.h" + +#include <ntqapplication.h> + +int main( int argc, char **argv ) +{ + TQApplication app( argc, argv ); + Viewer * textViewer = new Viewer(); + textViewer->setCaption( "TQt Example - Simple TQFont Demo" ); + app.setMainWidget( textViewer ); + textViewer->show(); + return app.exec(); +} diff --git a/examples/fonts/simple-tqfont-demo/simple-tqfont-demo.doc b/examples/fonts/simple-tqfont-demo/simple-tqfont-demo.doc new file mode 100644 index 000000000..bc8819260 --- /dev/null +++ b/examples/fonts/simple-tqfont-demo/simple-tqfont-demo.doc @@ -0,0 +1,28 @@ +/*! \page simple-font-demo-example.html + + \ingroup tqfont-examples + + \title A simple demonstration of TQFont member functions + + This example demonstrates the use of various + TQFont member functions. + + <hr> + + The main window API (viewer.h): + + \include fonts/simple-tqfont-demo/viewer.h + + <hr> + + The main window implementation (viewer.cpp): + + \include fonts/simple-tqfont-demo/viewer.cpp + + <hr> + + main() program (simple-tqfont-demo.cpp): + + \include fonts/simple-tqfont-demo/simple-tqfont-demo.cpp + +*/ diff --git a/examples/fonts/simple-tqfont-demo/simple-tqfont-demo.pro b/examples/fonts/simple-tqfont-demo/simple-tqfont-demo.pro new file mode 100644 index 000000000..d740c4701 --- /dev/null +++ b/examples/fonts/simple-tqfont-demo/simple-tqfont-demo.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +TARGET = fontdemo + +CONFIG += qt warn_on release +DEPENDPATH = ../../include + +REQUIRES = full-config + +HEADERS = viewer.h +SOURCES = simple-tqfont-demo.cpp \ + viewer.cpp diff --git a/examples/fonts/simple-tqfont-demo/viewer.cpp b/examples/fonts/simple-tqfont-demo/viewer.cpp new file mode 100644 index 000000000..88c202e3d --- /dev/null +++ b/examples/fonts/simple-tqfont-demo/viewer.cpp @@ -0,0 +1,160 @@ + +#include "viewer.h" +#include <tqstring.h> +#include <tqstringlist.h> +#include <tqtextview.h> +#include <ntqpushbutton.h> +#include <ntqlayout.h> + +Viewer::Viewer() + :TQWidget() +{ + setFontSubstitutions(); + + TQString greeting_heb = TQString::fromUtf8( "\327\251\327\234\327\225\327\235" ); + TQString greeting_ru = TQString::fromUtf8( "\320\227\320\264\321\200\320\260\320\262\321\201\321\202\320\262\321\203\320\271\321\202\320\265" ); + TQString greeting_en( "Hello" ); + + greetings = new TQTextView( this, "textview" ); + + greetings->setText( greeting_en + "\n" + + greeting_ru + "\n" + + greeting_heb ); + + fontInfo = new TQTextView( this, "fontinfo" ); + + setDefault(); + + defaultButton = new TQPushButton( "Default", this, + "pushbutton1" ); + defaultButton->setFont( TQFont( "times" ) ); + connect( defaultButton, TQ_SIGNAL( clicked() ), + this, TQ_SLOT( setDefault() ) ); + + sansSerifButton = new TQPushButton( "Sans Serif", this, + "pushbutton2" ); + sansSerifButton->setFont( TQFont( "Helvetica", 12 ) ); + connect( sansSerifButton, TQ_SIGNAL( clicked() ), + this, TQ_SLOT( setSansSerif() ) ); + + italicsButton = new TQPushButton( "Italics", this, + "pushbutton3" ); + italicsButton->setFont( TQFont( "lucida", 12, TQFont::Bold, TRUE ) ); + connect( italicsButton, TQ_SIGNAL( clicked() ), + this, TQ_SLOT( setItalics() ) ); + + layout(); +} + +void Viewer::setDefault() +{ + TQFont font( "Bavaria" ); + font.setPointSize( 24 ); + + font.setWeight( TQFont::Bold ); + font.setUnderline( TRUE ); + + greetings->setFont( font ); + + showFontInfo( font ); +} + +void Viewer::setSansSerif() +{ + TQFont font( "Newyork", 18 ); + font.setStyleHint( TQFont::SansSerif ); + greetings->setFont( font ); + + showFontInfo( font ); +} + +void Viewer::setItalics() +{ + TQFont font( "Tokyo" ); + font.setPointSize( 32 ); + font.setWeight( TQFont::Bold ); + font.setItalic( TRUE ); + + greetings->setFont( font ); + + showFontInfo( font ); +} + +void Viewer::showFontInfo( TQFont & font ) +{ + TQFontInfo info( font ); + + TQString messageText; + messageText = "Font requested: \"" + + font.family() + "\" " + + TQString::number( font.pointSize() ) + "pt<BR>" + + "Font used: \"" + + info.family() + "\" " + + TQString::number( info.pointSize() ) + "pt<P>"; + + TQStringList substitutions = TQFont::substitutes( font.family() ); + + if ( ! substitutions.isEmpty() ){ + messageText += "The following substitutions exist for " + \ + font.family() + ":<UL>"; + + TQStringList::Iterator i = substitutions.begin(); + while ( i != substitutions.end() ){ + messageText += "<LI>\"" + (* i) + "\""; + i++; + } + messageText += "</UL>"; + } else { + messageText += "No substitutions exist for " + \ + font.family() + "."; + } + + fontInfo->setText( messageText ); +} + +void Viewer::setFontSubstitutions() +{ + TQStringList substitutes; + substitutes.append( "Times" ); + substitutes += "Mincho", + substitutes << "Arabic Newspaper" << "crox"; + + TQFont::insertSubstitutions( "Bavaria", substitutes ); + + TQFont::insertSubstitution( "Tokyo", "Lucida" ); +} + + +// For those who prefer to use TQt Designer for creating GUIs +// the following function might not be of particular interest: +// all it does is creating the widget layout. + +void Viewer::layout() +{ + TQHBoxLayout * textViewContainer = new TQHBoxLayout(); + textViewContainer->addWidget( greetings ); + textViewContainer->addWidget( fontInfo ); + + TQHBoxLayout * buttonContainer = new TQHBoxLayout(); + + buttonContainer->addWidget( defaultButton ); + buttonContainer->addWidget( sansSerifButton ); + buttonContainer->addWidget( italicsButton ); + + int maxButtonHeight = defaultButton->height(); + + if ( sansSerifButton->height() > maxButtonHeight ) + maxButtonHeight = sansSerifButton->height(); + if ( italicsButton->height() > maxButtonHeight ) + maxButtonHeight = italicsButton->height(); + + defaultButton->setFixedHeight( maxButtonHeight ); + sansSerifButton->setFixedHeight( maxButtonHeight ); + italicsButton->setFixedHeight( maxButtonHeight ); + + TQVBoxLayout * container = new TQVBoxLayout( this ); + container->addLayout( textViewContainer ); + container->addLayout( buttonContainer ); + + resize( 700, 250 ); +} diff --git a/examples/fonts/simple-tqfont-demo/viewer.h b/examples/fonts/simple-tqfont-demo/viewer.h new file mode 100644 index 000000000..cfc6be406 --- /dev/null +++ b/examples/fonts/simple-tqfont-demo/viewer.h @@ -0,0 +1,37 @@ + +#ifndef VIEWER_H +#define VIEWER_H + + +#include <tqwidget.h> +#include <tqfont.h> + +class TQTextView; +class TQPushButton; + +class Viewer : public TQWidget +{ +TQ_OBJECT + +public: + Viewer(); + +private slots: + void setDefault(); + void setSansSerif(); + void setItalics(); + +private: + void setFontSubstitutions(); + void layout(); + void showFontInfo( TQFont & ); + + TQTextView * greetings; + TQTextView * fontInfo; + + TQPushButton * defaultButton; + TQPushButton * sansSerifButton; + TQPushButton * italicsButton; +}; + +#endif |