home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / examples / richtext / richtext.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-11  |  4.3 KB  |  140 lines

  1. /****************************************************************************
  2. ** $Id:  qt/richtext.cpp   3.0.0   edited Jun 22 13:24 $
  3. **
  4. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  5. **
  6. ** This file is part of an example program for Qt.  This example
  7. ** program may be used, distributed and modified without limitation.
  8. **
  9. *****************************************************************************/
  10.  
  11. #include "richtext.h"
  12.  
  13. #include <qhbox.h>
  14. #include <qhbox.h>
  15. #include <qpushbutton.h>
  16. #include <qtextview.h>
  17. #include <qbrush.h>
  18. #include <qapplication.h>
  19.  
  20. static const char* sayings[] = {
  21.     "<b>Saying 1:</b><br>"
  22.     "<hr><br><br>"
  23.     "<big>Evil is that which one believes of others.  It is a sin to believe evil "
  24.     "of others, but it is seldom a mistake.</big><br><br>"
  25.     "<center><i>-- H.L. Mencken</i></center>",
  26.  
  27.     "<b>Saying 2:</b><br>"
  28.     "<hr><br><br>"
  29.     "<big>A well-used door needs no oil on its hinges.<br>"
  30.     "A swift-flowing steam does not grow stagnant.<br>"
  31.     "Neither sound nor thoughts can travel through a vacuum.<br>"
  32.     "Software rots if not used.<br><br>"
  33.     "These are great mysteries.</big><br><br>"
  34.     "<center><i>-- Geoffrey James, \"The Tao of Programming\"</i></center>",
  35.  
  36.     "<b>Saying 3:</b><br>"
  37.     "<hr><br><br>"
  38.     "<big>Show business is just like high school, except you get paid.</big><br><br>"
  39.     "<center><i>-- Martin Mull</i></center>",
  40.  
  41.     "<b>Saying 4:</b><br>"
  42.     "<hr><br><br>"
  43.     "<big><b>The Least Successful Executions</b><br>"
  44.     "<twocolumn><p>      History has furnished us with two executioners worthy of attention. "
  45.     "The first performed in Sydney in Australia.  In 1803 three attempts were "
  46.     "made to hang a Mr. Joseph Samuels.  On the first two of these the rope "
  47.     "snapped, while on the third Mr. Samuels just hung there peacefully until he "
  48.     "and everyone else got bored.  Since he had proved unsusceptible to capital "
  49.     "punishment, he was reprieved.</p>"
  50.     "<p>        The most important British executioner was Mr. James Berry who "
  51.     "tried three times in 1885 to hang Mr. John Lee at Exeter Jail, but on each "
  52.     "occasion failed to get the trap door open.<!p>"
  53.     "<p>        In recognition of this achievement, the Home Secretary commuted "
  54.     "Lee's sentence to \"life\" imprisonment.  He was released in 1917, emigrated "
  55.     "to America and lived until 1933.</p></twocolumn></big><br><br>"
  56.     "<center><i>-- Stephen Pile, \"The Book of Heroic Failures\"</i></center>",
  57.  
  58.     "<b>Saying 5:</b><br>"
  59.     "<hr><br><br>"
  60.     "<big>If you can, help others.  If you can't, at least don't hurt others.</big><br><br>"
  61.     "<center><i>-- the Dalai Lama</i></center>",
  62.  
  63.     "<b>Saying 6:</b><br>"
  64.     "<hr><br><br>"
  65.     "<big>Television has brought back murder into the home -- where it belongs.</big><br><br>"
  66.     "<center><i>-- Alfred Hitchcock</i></center>",
  67.  
  68.     "<b>Saying 7:</b><br>"
  69.     "<hr><br><br>"
  70.     "<big>I don't know who my grandfather was; I am much more concerned to know "
  71.     "what his grandson will be.</big><br><br>"
  72.     "<center><i>-- Abraham Lincoln</i></center>",
  73.  
  74.     0
  75. };
  76.  
  77.  
  78. MyRichText::MyRichText( QWidget *parent, const char *name )
  79.     : QVBox( parent, name )
  80. {
  81.     setMargin( 5 );
  82.  
  83.     view = new QTextView( this );
  84.     view->setText( "This is a <b>Test</b> with <i>italic</i> <u>stuff</u>" );
  85.     QBrush paper;
  86.     paper.setPixmap( QPixmap( "../richtext/marble.png" ) );
  87.     view->setPaper( paper );
  88.  
  89.     view->setText( sayings[0] );
  90.     view->setMinimumSize( 450, 250 );
  91.  
  92.     QHBox *buttons = new QHBox( this );
  93.     buttons->setMargin( 5 );
  94.  
  95.     bClose = new QPushButton( "&Close", buttons );
  96.     bPrev = new QPushButton( "<< &Prev", buttons );
  97.     bNext = new QPushButton( "&Next >>", buttons );
  98.  
  99.     bPrev->setEnabled( FALSE );
  100.  
  101.     connect( bClose, SIGNAL( clicked() ), qApp, SLOT( quit() ) );
  102.     connect( bPrev, SIGNAL( clicked() ), this, SLOT( prev() ) );
  103.     connect( bNext, SIGNAL( clicked() ), this, SLOT( next() ) );
  104.  
  105.     num = 0;
  106. }
  107.  
  108. void MyRichText::prev()
  109. {
  110.     if ( num <= 0 )
  111.         return;
  112.  
  113.     num--;
  114.  
  115.     view->setText( sayings[num] );
  116.  
  117.     if ( num == 0 )
  118.         bPrev->setEnabled( FALSE );
  119.  
  120.     bNext->setEnabled( TRUE );
  121. }
  122.  
  123. void MyRichText::next()
  124. {
  125.     if ( !sayings[++num] )
  126.         return;
  127.  
  128.     view->setText( sayings[num] );
  129.  
  130.     if ( !sayings[num + 1] )
  131.         bNext->setEnabled( FALSE );
  132.  
  133.     bPrev->setEnabled( TRUE );
  134. }
  135.  
  136.  
  137.  
  138.  
  139.  
  140.