]> rtime.felk.cvut.cz Git - orte.git/blob - orte/contrib/shape/richtext.cpp
New version of shapedemo
[orte.git] / orte / contrib / shape / richtext.cpp
1 /****************************************************************************
2 ** $Id: richtext.cpp,v 1.1 2004/03/17 22:46:13 smolik Exp $
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* publisherExamples[] = {
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     0
37 };
38
39 static const char* subscriberExamples[] = {
40     "<b>Example 1:</b><br>"
41     "<hr><br><br>"
42     "<big>Evil is that which one believes of others.  It is a sin to believe evil "
43     "of others, but it is seldom a mistake.</big><br><br>"
44     "<center><i>-- H.L. Mencken</i></center>",
45
46     "<b>Example 2:</b><br>"
47     "<hr><br><br>"
48     "<big>A well-used door needs no oil on its hinges.<br>"
49     "A swift-flowing steam does not grow stagnant.<br>"
50     "Neither sound nor thoughts can travel through a vacuum.<br>"
51     "Software rots if not used.<br><br>"
52     "These are great mysteries.</big><br><br>"
53     "<center><i>-- Geoffrey James, \"The Tao of Programming\"</i></center>",
54
55     0
56 };
57
58
59 MyRichText::MyRichText( QWidget *parent, const char *name )
60     : QVBox( parent, name )
61 {
62     setMargin( 5 );
63     
64     view = new QTextView( this );
65     QBrush paper;
66     paper.setPixmap( QPixmap( "marble.png" ) );
67     if ( paper.pixmap() != 0 )
68         view->setPaper( paper );
69     else
70         view->setPaper( white );
71
72     view->setMinimumSize( 450, 250 );
73
74     QHBox *buttons = new QHBox( this );
75     buttons->setMargin( 5 );
76
77     bClose = new QPushButton( "&Close", buttons );
78     bPrev = new QPushButton( "<< &Prev", buttons );
79     bNext = new QPushButton( "&Next >>", buttons );
80
81     bPrev->setEnabled( FALSE );
82
83     connect( bClose, SIGNAL(clicked()), this, SLOT(close()) );
84     connect( bPrev, SIGNAL( clicked() ), this, SLOT( prev() ) );
85     connect( bNext, SIGNAL( clicked() ), this, SLOT( next() ) );
86
87 }
88
89 void MyRichText::setTextPublisher()
90 {
91     num = 0;
92     sayings=publisherExamples;
93     view->setText(sayings[0]);
94 }
95
96
97 void MyRichText::setTextSubscriber()
98 {
99     num = 0;
100     sayings=subscriberExamples;
101     view->setText(sayings[0]);
102 }
103
104 void MyRichText::prev()
105 {
106     if ( num <= 0 )
107         return;
108
109     num--;
110
111     view->setText( sayings[num] );
112
113     if ( num == 0 )
114         bPrev->setEnabled( FALSE );
115
116     bNext->setEnabled( TRUE );
117 }
118
119 void MyRichText::next()
120 {
121     if ( !sayings[++num] )
122         return;
123
124     view->setText( sayings[num] );
125
126     if ( !sayings[num + 1] )
127         bNext->setEnabled( FALSE );
128
129     bPrev->setEnabled( TRUE );
130 }
131
132
133
134
135