diff options
author | Timothy Pearson <[email protected]> | 2011-07-10 15:24:15 -0500 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2011-07-10 15:24:15 -0500 |
commit | bd0f3345a938b35ce6a12f6150373b0955b8dd12 (patch) | |
tree | 7a520322212d48ebcb9fbe1087e7fca28b76185c /examples/fonts | |
download | qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.tar.gz qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.zip |
Add Qt3 development HEAD version
Diffstat (limited to 'examples/fonts')
-rw-r--r-- | examples/fonts/fonts.pro | 5 | ||||
-rw-r--r-- | examples/fonts/simple-qfont-demo/simple-qfont-demo.cpp | 14 | ||||
-rw-r--r-- | examples/fonts/simple-qfont-demo/simple-qfont-demo.doc | 28 | ||||
-rw-r--r-- | examples/fonts/simple-qfont-demo/simple-qfont-demo.pro | 11 | ||||
-rw-r--r-- | examples/fonts/simple-qfont-demo/viewer.cpp | 160 | ||||
-rw-r--r-- | examples/fonts/simple-qfont-demo/viewer.h | 37 |
6 files changed, 255 insertions, 0 deletions
diff --git a/examples/fonts/fonts.pro b/examples/fonts/fonts.pro new file mode 100644 index 0000000..8659474 --- /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 0000000..a217ee8 --- /dev/null +++ b/examples/fonts/simple-qfont-demo/simple-qfont-demo.cpp @@ -0,0 +1,14 @@ + +#include "viewer.h" + +#include <qapplication.h> + +int main( int argc, char **argv ) +{ + QApplication app( argc, argv ); + Viewer * textViewer = new Viewer(); + textViewer->setCaption( "Qt Example - Simple QFont 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 0000000..8b0a365 --- /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. + + <hr> + + The main window API (viewer.h): + + \include fonts/simple-qfont-demo/viewer.h + + <hr> + + The main window implementation (viewer.cpp): + + \include fonts/simple-qfont-demo/viewer.cpp + + <hr> + + 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 0000000..a85e83c --- /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 0000000..face21c --- /dev/null +++ b/examples/fonts/simple-qfont-demo/viewer.cpp @@ -0,0 +1,160 @@ + +#include "viewer.h" +#include <qstring.h> +#include <qstringlist.h> +#include <qtextview.h> +#include <qpushbutton.h> +#include <qlayout.h> + +Viewer::Viewer() + :QWidget() +{ + setFontSubstitutions(); + + QString greeting_heb = QString::fromUtf8( "\327\251\327\234\327\225\327\235" ); + QString greeting_ru = QString::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" ); + QString greeting_en( "Hello" ); + + greetings = new QTextView( this, "textview" ); + + greetings->setText( greeting_en + "\n" + + greeting_ru + "\n" + + greeting_heb ); + + fontInfo = new QTextView( this, "fontinfo" ); + + setDefault(); + + defaultButton = new QPushButton( "Default", this, + "pushbutton1" ); + defaultButton->setFont( QFont( "times" ) ); + connect( defaultButton, SIGNAL( clicked() ), + this, SLOT( setDefault() ) ); + + sansSerifButton = new QPushButton( "Sans Serif", this, + "pushbutton2" ); + sansSerifButton->setFont( QFont( "Helvetica", 12 ) ); + connect( sansSerifButton, SIGNAL( clicked() ), + this, SLOT( setSansSerif() ) ); + + italicsButton = new QPushButton( "Italics", this, + "pushbutton3" ); + italicsButton->setFont( QFont( "lucida", 12, QFont::Bold, TRUE ) ); + connect( italicsButton, SIGNAL( clicked() ), + this, SLOT( setItalics() ) ); + + layout(); +} + +void Viewer::setDefault() +{ + QFont font( "Bavaria" ); + font.setPointSize( 24 ); + + font.setWeight( QFont::Bold ); + font.setUnderline( TRUE ); + + greetings->setFont( font ); + + showFontInfo( font ); +} + +void Viewer::setSansSerif() +{ + QFont font( "Newyork", 18 ); + font.setStyleHint( QFont::SansSerif ); + greetings->setFont( font ); + + showFontInfo( font ); +} + +void Viewer::setItalics() +{ + QFont font( "Tokyo" ); + font.setPointSize( 32 ); + font.setWeight( QFont::Bold ); + font.setItalic( TRUE ); + + greetings->setFont( font ); + + showFontInfo( font ); +} + +void Viewer::showFontInfo( QFont & font ) +{ + QFontInfo info( font ); + + QString messageText; + messageText = "Font requested: \"" + + font.family() + "\" " + + QString::number( font.pointSize() ) + "pt<BR>" + + "Font used: \"" + + info.family() + "\" " + + QString::number( info.pointSize() ) + "pt<P>"; + + QStringList substitutions = QFont::substitutes( font.family() ); + + if ( ! substitutions.isEmpty() ){ + messageText += "The following substitutions exist for " + \ + font.family() + ":<UL>"; + + QStringList::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() +{ + QStringList substitutes; + substitutes.append( "Times" ); + substitutes += "Mincho", + substitutes << "Arabic Newspaper" << "crox"; + + QFont::insertSubstitutions( "Bavaria", substitutes ); + + QFont::insertSubstitution( "Tokyo", "Lucida" ); +} + + +// For those who prefer to use Qt Designer for creating GUIs +// the following function might not be of particular interest: +// all it does is creating the widget layout. + +void Viewer::layout() +{ + QHBoxLayout * textViewContainer = new QHBoxLayout(); + textViewContainer->addWidget( greetings ); + textViewContainer->addWidget( fontInfo ); + + QHBoxLayout * buttonContainer = new QHBoxLayout(); + + 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 ); + + QVBoxLayout * container = new QVBoxLayout( 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 0000000..a9bd3a0 --- /dev/null +++ b/examples/fonts/simple-qfont-demo/viewer.h @@ -0,0 +1,37 @@ + +#ifndef VIEWER_H +#define VIEWER_H + + +#include <qwidget.h> +#include <qfont.h> + +class QTextView; +class QPushButton; + +class Viewer : public QWidget +{ +Q_OBJECT + +public: + Viewer(); + +private slots: + void setDefault(); + void setSansSerif(); + void setItalics(); + +private: + void setFontSubstitutions(); + void layout(); + void showFontInfo( QFont & ); + + QTextView * greetings; + QTextView * fontInfo; + + QPushButton * defaultButton; + QPushButton * sansSerifButton; + QPushButton * italicsButton; +}; + +#endif |