From d796c9dd933ab96ec83b9a634feedd5d32e1ba3f Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Tue, 8 Nov 2011 12:31:36 -0600 Subject: Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731 --- examples/fonts/fonts.pro | 5 + .../fonts/simple-qfont-demo/simple-qfont-demo.cpp | 14 ++ .../fonts/simple-qfont-demo/simple-qfont-demo.doc | 28 ++++ .../fonts/simple-qfont-demo/simple-qfont-demo.pro | 11 ++ examples/fonts/simple-qfont-demo/viewer.cpp | 160 +++++++++++++++++++++ examples/fonts/simple-qfont-demo/viewer.h | 37 +++++ 6 files changed, 255 insertions(+) create mode 100644 examples/fonts/fonts.pro create mode 100644 examples/fonts/simple-qfont-demo/simple-qfont-demo.cpp create mode 100644 examples/fonts/simple-qfont-demo/simple-qfont-demo.doc create mode 100644 examples/fonts/simple-qfont-demo/simple-qfont-demo.pro create mode 100644 examples/fonts/simple-qfont-demo/viewer.cpp create mode 100644 examples/fonts/simple-qfont-demo/viewer.h (limited to 'examples/fonts') diff --git a/examples/fonts/fonts.pro b/examples/fonts/fonts.pro new file mode 100644 index 000000000..8659474bd --- /dev/null +++ b/examples/fonts/fonts.pro @@ -0,0 +1,5 @@ +TEMPLATE = subdirs + +CONFIG += ordered + +SUBDIRS = simple-qfont-demo diff --git a/examples/fonts/simple-qfont-demo/simple-qfont-demo.cpp b/examples/fonts/simple-qfont-demo/simple-qfont-demo.cpp new file mode 100644 index 000000000..2e9f8d3a6 --- /dev/null +++ b/examples/fonts/simple-qfont-demo/simple-qfont-demo.cpp @@ -0,0 +1,14 @@ + +#include "viewer.h" + +#include + +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-qfont-demo/simple-qfont-demo.doc b/examples/fonts/simple-qfont-demo/simple-qfont-demo.doc new file mode 100644 index 000000000..8b0a3657e --- /dev/null +++ b/examples/fonts/simple-qfont-demo/simple-qfont-demo.doc @@ -0,0 +1,28 @@ +/*! \page simple-font-demo-example.html + + \ingroup qfont-examples + + \title A simple demonstration of QFont member functions + + This example demonstrates the use of various + QFont member functions. + +
+ + The main window API (viewer.h): + + \include fonts/simple-qfont-demo/viewer.h + +
+ + The main window implementation (viewer.cpp): + + \include fonts/simple-qfont-demo/viewer.cpp + +
+ + main() program (simple-qfont-demo.cpp): + + \include fonts/simple-qfont-demo/simple-qfont-demo.cpp + +*/ diff --git a/examples/fonts/simple-qfont-demo/simple-qfont-demo.pro b/examples/fonts/simple-qfont-demo/simple-qfont-demo.pro new file mode 100644 index 000000000..a85e83ce4 --- /dev/null +++ b/examples/fonts/simple-qfont-demo/simple-qfont-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-qfont-demo.cpp \ + viewer.cpp diff --git a/examples/fonts/simple-qfont-demo/viewer.cpp b/examples/fonts/simple-qfont-demo/viewer.cpp new file mode 100644 index 000000000..505cd42b3 --- /dev/null +++ b/examples/fonts/simple-qfont-demo/viewer.cpp @@ -0,0 +1,160 @@ + +#include "viewer.h" +#include +#include +#include +#include +#include + +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, SIGNAL( clicked() ), + this, SLOT( setDefault() ) ); + + sansSerifButton = new TQPushButton( "Sans Serif", this, + "pushbutton2" ); + sansSerifButton->setFont( TQFont( "Helvetica", 12 ) ); + connect( sansSerifButton, SIGNAL( clicked() ), + this, SLOT( setSansSerif() ) ); + + italicsButton = new TQPushButton( "Italics", this, + "pushbutton3" ); + italicsButton->setFont( TQFont( "lucida", 12, TQFont::Bold, TRUE ) ); + connect( italicsButton, SIGNAL( clicked() ), + this, 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
" + + "Font used: \"" + + info.family() + "\" " + + TQString::number( info.pointSize() ) + "pt

"; + + TQStringList substitutions = TQFont::substitutes( font.family() ); + + if ( ! substitutions.isEmpty() ){ + messageText += "The following substitutions exist for " + \ + font.family() + ":

    "; + + TQStringList::Iterator i = substitutions.begin(); + while ( i != substitutions.end() ){ + messageText += "
  • \"" + (* i) + "\""; + i++; + } + messageText += "
"; + } 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-qfont-demo/viewer.h b/examples/fonts/simple-qfont-demo/viewer.h new file mode 100644 index 000000000..1f72470a6 --- /dev/null +++ b/examples/fonts/simple-qfont-demo/viewer.h @@ -0,0 +1,37 @@ + +#ifndef VIEWER_H +#define VIEWER_H + + +#include +#include + +class TQTextView; +class TQPushButton; + +class Viewer : public TQWidget +{ +Q_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 -- cgit v1.2.1