source: trunk/examples/richtext/richtext.cpp@ 8

Last change on this file since 8 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1/****************************************************************************
2** $Id: richtext.cpp 2 2005-11-16 15:49:26Z dmik $
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
20static 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
78MyRichText::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 if ( paper.pixmap() != 0 )
88 view->setPaper( paper );
89 else
90 view->setPaper( white );
91
92 view->setText( sayings[0] );
93 view->setMinimumSize( 450, 250 );
94
95 QHBox *buttons = new QHBox( this );
96 buttons->setMargin( 5 );
97
98 bClose = new QPushButton( "&Close", buttons );
99 bPrev = new QPushButton( "<< &Prev", buttons );
100 bNext = new QPushButton( "&Next >>", buttons );
101
102 bPrev->setEnabled( FALSE );
103
104 connect( bClose, SIGNAL( clicked() ), qApp, SLOT( quit() ) );
105 connect( bPrev, SIGNAL( clicked() ), this, SLOT( prev() ) );
106 connect( bNext, SIGNAL( clicked() ), this, SLOT( next() ) );
107
108 num = 0;
109}
110
111void MyRichText::prev()
112{
113 if ( num <= 0 )
114 return;
115
116 num--;
117
118 view->setText( sayings[num] );
119
120 if ( num == 0 )
121 bPrev->setEnabled( FALSE );
122
123 bNext->setEnabled( TRUE );
124}
125
126void MyRichText::next()
127{
128 if ( !sayings[++num] )
129 return;
130
131 view->setText( sayings[num] );
132
133 if ( !sayings[num + 1] )
134 bNext->setEnabled( FALSE );
135
136 bPrev->setEnabled( TRUE );
137}
138
139
140
141
142
Note: See TracBrowser for help on using the repository browser.