[190] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
| 2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/rot13/rot13.doc:4 -->
|
---|
| 3 | <html>
|
---|
| 4 | <head>
|
---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
| 6 | <title>Rot13</title>
|
---|
| 7 | <style type="text/css"><!--
|
---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
| 9 | a:link { color: #004faf; text-decoration: none }
|
---|
| 10 | a:visited { color: #672967; text-decoration: none }
|
---|
| 11 | body { background: #ffffff; color: black; }
|
---|
| 12 | --></style>
|
---|
| 13 | </head>
|
---|
| 14 | <body>
|
---|
| 15 |
|
---|
| 16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
| 17 | <tr bgcolor="#E5E5E5">
|
---|
| 18 | <td valign=center>
|
---|
| 19 | <a href="index.html">
|
---|
| 20 | <font color="#004faf">Home</font></a>
|
---|
| 21 | | <a href="classes.html">
|
---|
| 22 | <font color="#004faf">All Classes</font></a>
|
---|
| 23 | | <a href="mainclasses.html">
|
---|
| 24 | <font color="#004faf">Main Classes</font></a>
|
---|
| 25 | | <a href="annotated.html">
|
---|
| 26 | <font color="#004faf">Annotated</font></a>
|
---|
| 27 | | <a href="groups.html">
|
---|
| 28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
| 29 | | <a href="functions.html">
|
---|
| 30 | <font color="#004faf">Functions</font></a>
|
---|
| 31 | </td>
|
---|
| 32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Rot13</h1>
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | <p>
|
---|
| 36 | This example lets you enter a text into a mulitilineedit widget.
|
---|
| 37 | It will be displayed in the edit widget to the right transformed using
|
---|
| 38 | the rot13 algorithm.
|
---|
| 39 | <p> <hr>
|
---|
| 40 | <p> Header file:
|
---|
| 41 | <p> <pre>/****************************************************************************
|
---|
| 42 | ** $Id: rot-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 43 | **
|
---|
| 44 | ** Definition of something or other
|
---|
| 45 | **
|
---|
| 46 | ** Created : 979899
|
---|
| 47 | **
|
---|
| 48 | ** Copyright (C) 1997-2007 Trolltech ASA. All rights reserved.
|
---|
| 49 | **
|
---|
| 50 | ** This file is part of an example program for Qt. This example
|
---|
| 51 | ** program may be used, distributed and modified without limitation.
|
---|
| 52 | **
|
---|
| 53 | *****************************************************************************/
|
---|
| 54 |
|
---|
| 55 | #ifndef ROT13_H
|
---|
| 56 | #define ROT13_H
|
---|
| 57 |
|
---|
| 58 | #include <<a href="qwidget-h.html">qwidget.h</a>>
|
---|
| 59 |
|
---|
| 60 | class QMultiLineEdit;
|
---|
| 61 |
|
---|
| 62 | class Rot13: public <a href="qwidget.html">QWidget</a> {
|
---|
| 63 | <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
|
---|
| 64 | public:
|
---|
| 65 | Rot13();
|
---|
| 66 |
|
---|
| 67 | <a href="qstring.html">QString</a> rot13( const <a href="qstring.html">QString</a> & ) const;
|
---|
| 68 |
|
---|
| 69 | private slots:
|
---|
| 70 | void changeLeft();
|
---|
| 71 | void changeRight();
|
---|
| 72 |
|
---|
| 73 | private:
|
---|
| 74 | <a href="qmultilineedit.html">QMultiLineEdit</a> * left, * right;
|
---|
| 75 | };
|
---|
| 76 |
|
---|
| 77 | #endif
|
---|
| 78 | </pre>
|
---|
| 79 |
|
---|
| 80 | <p> <hr>
|
---|
| 81 | <p> Implementation:
|
---|
| 82 | <p> <pre>/****************************************************************************
|
---|
| 83 | ** $Id: rot-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 84 | **
|
---|
| 85 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
| 86 | **
|
---|
| 87 | ** This file is part of an example program for Qt. This example
|
---|
| 88 | ** program may be used, distributed and modified without limitation.
|
---|
| 89 | **
|
---|
| 90 | *****************************************************************************/
|
---|
| 91 |
|
---|
| 92 | #include "rot13.h"
|
---|
| 93 |
|
---|
| 94 | #include <<a href="qmultilineedit-h.html">qmultilineedit.h</a>>
|
---|
| 95 | #include <<a href="qpushbutton-h.html">qpushbutton.h</a>>
|
---|
| 96 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
| 97 | #include <<a href="qlayout-h.html">qlayout.h</a>>
|
---|
| 98 |
|
---|
| 99 | <a name="f432"></a>Rot13::Rot13()
|
---|
| 100 | {
|
---|
| 101 | left = new <a href="qmultilineedit.html">QMultiLineEdit</a>( this, "left" );
|
---|
| 102 | right = new <a href="qmultilineedit.html">QMultiLineEdit</a>( this, "right" );
|
---|
| 103 | <a name="x1375"></a> <a href="qobject.html#connect">connect</a>( left, SIGNAL(<a href="qtextedit.html#textChanged">textChanged</a>()), this, SLOT(changeRight()) );
|
---|
| 104 | <a href="qobject.html#connect">connect</a>( right, SIGNAL(<a href="qtextedit.html#textChanged">textChanged</a>()), this, SLOT(changeLeft()) );
|
---|
| 105 |
|
---|
| 106 | <a href="qpushbutton.html">QPushButton</a> * quit = new <a href="qpushbutton.html">QPushButton</a>( "&Quit", this );
|
---|
| 107 | <a name="x1379"></a> quit-><a href="qwidget.html#setFocusPolicy">setFocusPolicy</a>( NoFocus );
|
---|
| 108 | <a href="qobject.html#connect">connect</a>( quit, SIGNAL(<a href="qbutton.html#clicked">clicked</a>()), qApp, SLOT(<a href="qapplication.html#quit">quit</a>()) );
|
---|
| 109 |
|
---|
| 110 | <a href="qgridlayout.html">QGridLayout</a> * l = new <a href="qgridlayout.html">QGridLayout</a>( this, 2, 2, 5 );
|
---|
| 111 | <a name="x1370"></a> l-><a href="qgridlayout.html#addWidget">addWidget</a>( left, 0, 0 );
|
---|
| 112 | l-><a href="qgridlayout.html#addWidget">addWidget</a>( right, 0, 1 );
|
---|
| 113 | l-><a href="qgridlayout.html#addWidget">addWidget</a>( quit, 1, 1, AlignRight );
|
---|
| 114 |
|
---|
| 115 | <a name="x1378"></a> left-><a href="qwidget.html#setFocus">setFocus</a>();
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 |
|
---|
| 119 | void <a name="f433"></a>Rot13::changeLeft()
|
---|
| 120 | {
|
---|
| 121 | <a name="x1371"></a> left-><a href="qobject.html#blockSignals">blockSignals</a>( TRUE );
|
---|
| 122 | <a name="x1374"></a><a name="x1373"></a> left-><a href="qtextedit.html#setText">setText</a>( rot13( right-><a href="qtextedit.html#text">text</a>() ) );
|
---|
| 123 | left-><a href="qobject.html#blockSignals">blockSignals</a>( FALSE );
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 | void <a name="f434"></a>Rot13::changeRight()
|
---|
| 128 | {
|
---|
| 129 | right-><a href="qobject.html#blockSignals">blockSignals</a>( TRUE );
|
---|
| 130 | right-><a href="qtextedit.html#setText">setText</a>( rot13( left-><a href="qtextedit.html#text">text</a>() ) );
|
---|
| 131 | right-><a href="qobject.html#blockSignals">blockSignals</a>( FALSE );
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | QString <a name="f435"></a>Rot13::rot13( const <a href="qstring.html">QString</a> & input ) const
|
---|
| 136 | {
|
---|
| 137 | <a href="qstring.html">QString</a> r = input;
|
---|
| 138 | <a name="x1372"></a> int i = r.<a href="qstring.html#length">length</a>();
|
---|
| 139 | while( i-- ) {
|
---|
| 140 | if ( r[i] >= QChar('A') && r[i] <= QChar('M') ||
|
---|
| 141 | r[i] >= QChar('a') && r[i] <= QChar('m') )
|
---|
| 142 | r[i] = (char)((int)QChar(r[i]) + 13);
|
---|
| 143 | else if ( r[i] >= QChar('N') && r[i] <= QChar('Z') ||
|
---|
| 144 | r[i] >= QChar('n') && r[i] <= QChar('z') )
|
---|
| 145 | r[i] = (char)((int)QChar(r[i]) - 13);
|
---|
| 146 | }
|
---|
| 147 | return r;
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 |
|
---|
| 151 | int main( int argc, char ** argv )
|
---|
| 152 | {
|
---|
| 153 | <a href="qapplication.html">QApplication</a> a( argc, argv );
|
---|
| 154 | Rot13 r;
|
---|
| 155 | r.<a href="qwidget.html#resize">resize</a>( 400, 400 );
|
---|
| 156 | a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &r );
|
---|
| 157 | r.<a href="qwidget.html#setCaption">setCaption</a>("Qt Example - ROT13");
|
---|
| 158 | r.<a href="qwidget.html#show">show</a>();
|
---|
| 159 | return a.<a href="qapplication.html#exec">exec</a>();
|
---|
| 160 | }
|
---|
| 161 | </pre>
|
---|
| 162 |
|
---|
| 163 | <p>See also <a href="examples.html">Examples</a>.
|
---|
| 164 |
|
---|
| 165 | <!-- eof -->
|
---|
| 166 | <p><address><hr><div align=center>
|
---|
| 167 | <table width=100% cellspacing=0 border=0><tr>
|
---|
| 168 | <td>Copyright © 2007
|
---|
| 169 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
| 170 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
| 171 | </table></div></address></body>
|
---|
| 172 | </html>
|
---|