diff options
author | Timothy Pearson <[email protected]> | 2011-11-08 12:31:36 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2011-11-08 12:31:36 -0600 |
commit | d796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch) | |
tree | 6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/textedit | |
download | tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip |
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/textedit')
-rw-r--r-- | examples/textedit/editcopy.xpm | 36 | ||||
-rw-r--r-- | examples/textedit/editcut.xpm | 32 | ||||
-rw-r--r-- | examples/textedit/editpaste.xpm | 36 | ||||
-rw-r--r-- | examples/textedit/editredo.xpm | 36 | ||||
-rw-r--r-- | examples/textedit/editundo.xpm | 36 | ||||
-rw-r--r-- | examples/textedit/example.html | 24 | ||||
-rw-r--r-- | examples/textedit/filenew.xpm | 36 | ||||
-rw-r--r-- | examples/textedit/fileopen.xpm | 36 | ||||
-rw-r--r-- | examples/textedit/fileprint.xpm | 117 | ||||
-rw-r--r-- | examples/textedit/filesave.xpm | 36 | ||||
-rw-r--r-- | examples/textedit/main.cpp | 22 | ||||
-rw-r--r-- | examples/textedit/textbold.xpm | 27 | ||||
-rw-r--r-- | examples/textedit/textcenter.xpm | 27 | ||||
-rw-r--r-- | examples/textedit/textedit.cpp | 455 | ||||
-rw-r--r-- | examples/textedit/textedit.doc | 18 | ||||
-rw-r--r-- | examples/textedit/textedit.h | 82 | ||||
-rw-r--r-- | examples/textedit/textedit.pro | 11 | ||||
-rw-r--r-- | examples/textedit/textitalic.xpm | 27 | ||||
-rw-r--r-- | examples/textedit/textjustify.xpm | 27 | ||||
-rw-r--r-- | examples/textedit/textleft.xpm | 27 | ||||
-rw-r--r-- | examples/textedit/textright.xpm | 27 | ||||
-rw-r--r-- | examples/textedit/textunder.xpm | 27 |
22 files changed, 1202 insertions, 0 deletions
diff --git a/examples/textedit/editcopy.xpm b/examples/textedit/editcopy.xpm new file mode 100644 index 000000000..cc6fb7a68 --- /dev/null +++ b/examples/textedit/editcopy.xpm @@ -0,0 +1,36 @@ +/* XPM */ +static char *magick[] = { +/* columns rows colors chars-per-pixel */ +"22 22 8 1", +" c Gray100", +". c #8b8bfd", +"X c #3c3cfd", +"o c #000082", +"O c Gray0", +"+ c None", +"@ c Gray0", +"# c Gray0", +/* pixels */ +"++++++++++++++++++++++", +"++++++++++++++++++++++", +"OOOOOOOO++++++++++++++", +"O OO+++++++++++++", +"O OOOO O O++++++++++++", +"O O O+++++++++++", +"O OOOO Ooooooooo++++++", +"O Oo oo+++++", +"O OOOOO o OOOO oXo++++", +"O o o.Xo+++", +"O OOOOO o OOOO o .Xo++", +"O o oooooo+", +"O OOOOO o OOOO o+", +"O o o+", +"O OOOOO o OOOOOOOOO o+", +"O o o+", +"OOOOOOOOo OOOOOOOOO o+", +"++++++++o o+", +"++++++++o OOOOOOOOO o+", +"++++++++o o+", +"++++++++ooooooooooooo+", +"++++++++++++++++++++++" +}; diff --git a/examples/textedit/editcut.xpm b/examples/textedit/editcut.xpm new file mode 100644 index 000000000..2391adda5 --- /dev/null +++ b/examples/textedit/editcut.xpm @@ -0,0 +1,32 @@ +/* XPM */ +static char *magick[] = { +/* columns rows colors chars-per-pixel */ +"22 22 4 1", +" c Gray100", +". c #000082", +"X c Gray0", +"o c None", +/* pixels */ +"oooooooooooooooooooooo", +"oooooooXoooooXoooooooo", +"oooooooXoooooXoooooooo", +"oooooooXoooooXoooooooo", +"oooooooXooooXXoooooooo", +"oooooooXXoooXooooooooo", +"ooooooooXoooXooooooooo", +"ooooooooXXoXXooooooooo", +"oooooooooXXXoooooooooo", +"oooooooooXXXoooooooooo", +"ooooooooooXooooooooooo", +"ooooooooo.X.oooooooooo", +"oooooooo..o...oooooooo", +"ooooooo.o.o.oo.ooooooo", +"oooooo.oo.o.ooo.oooooo", +"ooooo.ooo.o.oooo.ooooo", +"oooo.oooo.o.oooo.ooooo", +"oooo.oooo.oo.ooo.ooooo", +"oooo.oooo.oo.oo.oooooo", +"oooo.ooo.oooo..ooooooo", +"ooooo...oooooooooooooo", +"oooooooooooooooooooooo" +}; diff --git a/examples/textedit/editpaste.xpm b/examples/textedit/editpaste.xpm new file mode 100644 index 000000000..3f775920f --- /dev/null +++ b/examples/textedit/editpaste.xpm @@ -0,0 +1,36 @@ +/* XPM */ +static char *magick[] = { +/* columns rows colors chars-per-pixel */ +"22 22 8 1", +" c Gray100", +". c Yellow", +"X c #c6c3c6", +"o c #848284", +"O c #848200", +"+ c #000084", +"@ c Gray0", +"# c None", +/* pixels */ +"######################", +"#######@@@@@##########", +"##@@@@@@...@@@@@@#####", +"#@@@@@@.....@@@@@@####", +"@@oOo@@.@@@.@@oOo@@###", +"@oOo@XXXXXXXXX@oOo@###", +"@OoO@XXXXXXXXX@OoO@###", +"@oOo@@@@@@@@@@@oOo@###", +"@OoOoOoOoOoOoOoOoO@###", +"@oOoOoOoOoOoOoOoOo@###", +"@OoOoOoO++++++++++@###", +"@oOoOoOo+ + +###", +"@OoOoOoO+ +++++ + +##", +"@oOoOoOo+ + +#", +"@OoOoOoO+ +++++ + +", +"@oOoOoOo+ ++++++", +"@OoOoOoO+ +++++ +", +"@oOoOoOo+ +", +"@OoOoOoO+ ++++++++++ +", +"#@@@@@@@+ +", +"########++++++++++++++", +"######################" +}; diff --git a/examples/textedit/editredo.xpm b/examples/textedit/editredo.xpm new file mode 100644 index 000000000..46dc03319 --- /dev/null +++ b/examples/textedit/editredo.xpm @@ -0,0 +1,36 @@ +/* XPM */ +static char *magick[] = { +/* columns rows colors chars-per-pixel */ +"22 22 8 1", +" c Gray100", +". c #848284", +"X c #000084", +"o c Gray0", +"O c None", +"+ c Gray0", +"@ c Gray0", +"# c Gray0", +/* pixels */ +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOO.XXXXXXOOOOOOOOOOO", +"OOOXXXXXXXXXXOOOOOOXOO", +"OO.XXOOOOOOXXXXOOOXXOO", +"OOXXOOOOOOOOOXXXOXXXOO", +"OOXXOOOOOOOOOOXXXXXXOO", +"OOXXOOOOOOOOOOOXXXXXOO", +"OOXXOOOOOOOOOOXXXXXXOO", +"OOXXOOOOOOOOOXXXXXXXOO", +"OO.XXOOOOOOOXXXXXXXXOO", +"OOOXXX.OOOOOOOOOOOOOOO", +"OOOOXXXOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO" +}; diff --git a/examples/textedit/editundo.xpm b/examples/textedit/editundo.xpm new file mode 100644 index 000000000..229c1636e --- /dev/null +++ b/examples/textedit/editundo.xpm @@ -0,0 +1,36 @@ +/* XPM */ +static char *magick[] = { +/* columns rows colors chars-per-pixel */ +"22 22 8 1", +" c Gray100", +". c #848284", +"X c #000084", +"o c Gray0", +"O c None", +"+ c Gray0", +"@ c Gray0", +"# c Gray0", +/* pixels */ +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOXXXXXX.OOOO", +"OOXOOOOOOXXXXXXXXXXOOO", +"OOXXOOOXXXXOOOOOOXX.OO", +"OOXXXOXXXOOOOOOOOOXXOO", +"OOXXXXXXOOOOOOOOOOXXOO", +"OOXXXXXOOOOOOOOOOOXXOO", +"OOXXXXXXOOOOOOOOOOXXOO", +"OOXXXXXXXOOOOOOOOOXXOO", +"OOXXXXXXXXOOOOOOOXX.OO", +"OOOOOOOOOOOOOOO.XXXOOO", +"OOOOOOOOOOOOOOOXXXOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO" +}; diff --git a/examples/textedit/example.html b/examples/textedit/example.html new file mode 100644 index 000000000..39b60ff76 --- /dev/null +++ b/examples/textedit/example.html @@ -0,0 +1,24 @@ +<html><head><meta name="qrichtext" content="1" /></head><body style="font-size:12pt;font-family:helvetica"> +<p align="center"><span style="font-size:24pt;font-weight:600">TQTextEdit</span></p> +<p align="justify">TQTextEdit is an advanced WYSIWYG editor supporting richtext formatting. It is optimized to handle large documents and to respond tquickly to user input.</p> +<p align="justify">TQTextEdit supports font styles such as <span style="font-weight:600">bold</span>, <span style="font-style:italic">italic, </span><span style="text-decoration:underline">underlined</span> as well as various <span style="font-weight:600;color:#00007f">c</span><span style="font-weight:600;color:#aa0000">o</span><span style="font-weight:600;color:#005500">l</span><span style="font-weight:600;color:#aa5500">o</span><span style="font-weight:600;color:#00aa00">r</span><span style="font-weight:600;color:#ff0000">s </span>and <span style="font-size:16pt">s</span><span style="font-size:18pt">i</span><span style="font-size:20pt">z</span><span style="font-size:22pt">e</span><span style="font-size:28pt">s</span>. You can select different font families, for example <span style="font-family:Times;font-weight:600">Times New Roman</span> or <span style="font-family:Courier;font-weight:600">Courier</span>. Futhermore the widget supports different paragraph alignments such as justified,</p> +<p>left aligned,</p> +<p align="center">centered,</p> +<p align="right">and right aligned.</p> +<p align="justify"></p> +<!-- Not public API +<p>In addition to the mentioned character styles, the editor supports both bullet lists</p> +<ul type="disc"><li>Disc</li> +<ul type="circle"><li>Circle</li> +<ul type="square"><li>Square</li></ul></ul></ul> +<p>and ordered lists</p> +<ol><li>One</li> +<li>Two</li> +<ol type="a"><li>Two.a</li> +<li>Two.b</li> +<ol type="A"><li>Two.b.A</li> +<li>Two.b.B</li></ol> +<li>Two.c</li></ol> +<li>Three.</li></ol> +--> +</body></html> diff --git a/examples/textedit/filenew.xpm b/examples/textedit/filenew.xpm new file mode 100644 index 000000000..884d7cbb1 --- /dev/null +++ b/examples/textedit/filenew.xpm @@ -0,0 +1,36 @@ +/* XPM */ +static char *magick[] = { +/* columns rows colors chars-per-pixel */ +"22 22 8 1", +" c Gray100", +". c Gray76", +"X c Gray53", +"o c Gray36", +"O c Gray18", +"+ c Gray0", +"@ c None", +"# c Gray0", +/* pixels */ +"@@@@@@@@@@@@@@@@@@@@@@", +"@@@@++++++++++@@@@@@@@", +"@@@@+ +O+@@@@@@@", +"@@@@+ +oO+@@@@@@", +"@@@@+ +XoO+@@@@@", +"@@@@+ +.XoO+@@@@", +"@@@@+ + .XoO+@@@", +"@@@@+ +++++++@@@", +"@@@@+ +@@@", +"@@@@+ +@@@", +"@@@@+ +@@@", +"@@@@+ +@@@", +"@@@@+ +@@@", +"@@@@+ +@@@", +"@@@@+ +@@@", +"@@@@+ +@@@", +"@@@@+ +@@@", +"@@@@+ +@@@", +"@@@@+ +@@@", +"@@@@+++++++++++++++@@@", +"@@@@@@@@@@@@@@@@@@@@@@", +"@@@@@@@@@@@@@@@@@@@@@@" +}; diff --git a/examples/textedit/fileopen.xpm b/examples/textedit/fileopen.xpm new file mode 100644 index 000000000..82effcf7b --- /dev/null +++ b/examples/textedit/fileopen.xpm @@ -0,0 +1,36 @@ +/* XPM */ +static char *magick[] = { +/* columns rows colors chars-per-pixel */ +"22 22 8 1", +" c Gray100", +". c Yellow", +"X c #848200", +"o c Gray0", +"O c None", +"+ c Gray0", +"@ c Gray0", +"# c Gray0", +/* pixels */ +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO", +"OOOOOOOOOOOOooooOOOOoO", +"OOOOOOOOOOOoOOOOooOooO", +"OOOOOOOOOOOOOOOOOOoooO", +"OOOOOOOOOOOOOOOOOooooO", +"OooooOOOOOOOOOOOoooooO", +"o. . ooooooooooOOOOOOO", +"o . . . . . . oOOOOOOO", +"o. . . . . . .oOOOOOOO", +"o . . . . . . oOOOOOOO", +"o. . . ooooooooooooooo", +"o . . ooXXXXXXXXXXXXoo", +"o. . ooXXXXXXXXXXXXooO", +"o . ooXXXXXXXXXXXXooOO", +"o. ooXXXXXXXXXXXXooOOO", +"o ooXXXXXXXXXXXXooOOOO", +"oooXXXXXXXXXXXXooOOOOO", +"ooXXXXXXXXXXXXooOOOOOO", +"oooooooooooooooOOOOOOO", +"OOOOOOOOOOOOOOOOOOOOOO" +}; diff --git a/examples/textedit/fileprint.xpm b/examples/textedit/fileprint.xpm new file mode 100644 index 000000000..8701d4609 --- /dev/null +++ b/examples/textedit/fileprint.xpm @@ -0,0 +1,117 @@ +/* XPM */ +static char *magick[] = { +/* columns rows colors chars-per-pixel */ +"22 22 89 1", +" c Gray0", +". c #101008081010", +"X c #101010101010", +"o c #101010101818", +"O c #181810101818", +"+ c #181818181818", +"@ c #181818182121", +"# c #212118182121", +"$ c Gray13", +"% c #212121212929", +"& c #292921212929", +"* c Gray16", +"= c #292929293131", +"- c #313129293131", +"; c #313131313131", +": c #313131313939", +"> c #393931313939", +", c #393939393939", +"< c #393939394242", +"1 c #424239394242", +"2 c Gray26", +"3 c #4a4a4a4a5252", +"4 c #5a5a52525a5a", +"5 c #5a5a5a5a6363", +"6 c #6b6b63636b6b", +"7 c Gray42", +"8 c #6b6b6b6b7373", +"9 c #73736b6b7373", +"0 c #7b7b73737b7b", +"q c #7b7b73738484", +"w c #0808ffff0808", +"e c #2929ffff2929", +"r c #3131ffff3131", +"t c #5a5acece5a5a", +"y c #6b6bffff6363", +"u c #7b7bffff7b7b", +"i c #84847b7b8484", +"p c #84847b7b8c8c", +"a c #8c8c7b7b9494", +"s c #848484848c8c", +"d c #8c8c84848c8c", +"f c Gray55", +"g c #8c8c84849494", +"h c #8c8c8c8c9494", +"j c #94948c8c9494", +"k c #94948c8c9c9c", +"l c Gray58", +"z c #949494949c9c", +"x c #9c9c94949c9c", +"c c Gray61", +"v c #9c9c9494a5a5", +"b c #9c9c9c9ca5a5", +"n c #a5a59c9ca5a5", +"m c #a5a59c9cadad", +"M c #adad9c9cadad", +"N c #a5a5a5a5a5a5", +"B c #a5a5a5a5adad", +"V c #adada5a5adad", +"C c Gray68", +"Z c #adadadadb5b5", +"A c #b5b5adadb5b5", +"S c Gray71", +"D c Gray74", +"F c #9494c6c69494", +"G c #9c9ccecea5a5", +"H c #bdbdd6d6bdbd", +"J c #c0c0c0c0c0c0", +"K c #c6c6c6c6c6c6", +"L c #cecec6c6cece", +"P c #cececececece", +"I c #cecececed6d6", +"U c #d6d6ceced6d6", +"Y c #d6d6cecedede", +"T c Gray84", +"R c #d6d6d6d6dede", +"E c #deded6d6dede", +"W c Gray87", +"Q c #deded6d6e7e7", +"! c #dedededee7e7", +"~ c #d6d6ffffd6d6", +"^ c #e7e7dedee7e7", +"/ c #e7e7e7e7e7e7", +"( c #e7e7e7e7efef", +") c #efefe7e7efef", +"_ c #efefefefefef", +"` c #e7e7ffffe7e7", +"' c Gray97", +"] c Gray100", +"[ c None", +/* pixels */ +"[[[[[[SDPPPPKKDDCD[[[[", +"[[[[[[D_/////___WD[[[[", +"[[[[[[DKKKPPKKKKDK[[[[", +"[[[[[[SDDDDSDDSSCD[[[[", +"[[[[[KCKDKKKDDDKS[[[[[", +"[[[[[DDSDDDDDDKKS[[[[[", +"[[[[[DSKDDDDDKDKC[[[[[", +"[[[[[KDDDDDDDDDDS[[[[[", +"[[[[[CP/WWWWWWTWNNZ[[[", +"[[[Dc9STPTPTPTWWj427S[", +"[[Dziq0000000pag8<%@2N", +"[DcE(!ERRRRUYGtFn2##O<", +"Db)]]]]]]]]]~ewePa;@X#", +"V']]]]]]]]]]`yru]Q0@ #", +"BRILITRRW^!E!RHUILhO @", +"jAZVBmBnmmNmnmMvzh6o #", +"jZZmBnnnbnbbbbvxxg6o +", +"lmmnbnbbbvcvxxxvjs6O 3", +"jBnnvcvxvcvxvxzjhd8o+C", +"lsdgfgdhgdhhjhjkhg6+l[", +"S9%@$%&&&=--::>>:-:l[[", +"[[C511,:;;;**%++.2c[[[" +}; diff --git a/examples/textedit/filesave.xpm b/examples/textedit/filesave.xpm new file mode 100644 index 000000000..71cbd331a --- /dev/null +++ b/examples/textedit/filesave.xpm @@ -0,0 +1,36 @@ +/* XPM */ +static char *magick[] = { +/* columns rows colors chars-per-pixel */ +"22 22 8 1", +" c Gray100", +". c #cab5d1", +"X c #c1c1c1", +"o c #848200", +"O c Gray0", +"+ c None", +"@ c Gray0", +"# c Gray0", +/* pixels */ +"++++++++++++++++++++++", +"+OOOOOOOOOOOOOOOOOOOO+", +"+OooOXXXXXXXXXXXXOXXO+", +"+OooOXXXXXXXXXXXXOXXO+", +"+OooOXXXXXXXXX.XXOOOO+", +"+OooOXXX..XXXXXXXOooO+", +"+OooOXXX..XXXXXXXOooO+", +"+OooOXXXXXXXXXXXXOooO+", +"+OooOXXXXXXXXXXXXOooO+", +"+OooOXXXXXXXXXXXXOooO+", +"+OooOXXXXXXXXXXXXOooO+", +"+OoooOOOOOOOOOOOOoooO+", +"+OooooooooooooooooooO+", +"+OooooooooooooooooooO+", +"+OoooOOOOOOOOOOOOOooO+", +"+OoooOOOOOOOOOXXXOooO+", +"+OoooOOOOOOOOOXXXOooO+", +"+OoooOOOOOOOOOXXXOooO+", +"+OoooOOOOOOOOOXXXOooO+", +"+OoooOOOOOOOOOXXXOooO+", +"++OOOOOOOOOOOOOOOOOO++", +"++++++++++++++++++++++" +}; diff --git a/examples/textedit/main.cpp b/examples/textedit/main.cpp new file mode 100644 index 000000000..db2ad21a4 --- /dev/null +++ b/examples/textedit/main.cpp @@ -0,0 +1,22 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include <qapplication.h> +#include "textedit.h" + +int main( int argc, char ** argv ) +{ + TQApplication a( argc, argv ); + TextEdit * mw = new TextEdit(); + mw->setCaption( "Richtext Editor" ); + mw->resize( 640, 800 ); + mw->show(); + a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( tquit() ) ); + return a.exec(); +} diff --git a/examples/textedit/textbold.xpm b/examples/textedit/textbold.xpm new file mode 100644 index 000000000..8398e2eca --- /dev/null +++ b/examples/textedit/textbold.xpm @@ -0,0 +1,27 @@ +/* XPM */ +static char * bold_xpm[] = { +"22 22 2 1", +" c None", +". c #000000", +" ", +" ", +" ", +" ", +" ......... ", +" ... ... ", +" ... ... ", +" ... ... ", +" ... ... ", +" ... ... ", +" ........ ", +" ... .... ", +" ... .... ", +" ... ... ", +" ... ... ", +" ... ... ", +" ... ... ", +" .......... ", +" ", +" ", +" ", +" "}; diff --git a/examples/textedit/textcenter.xpm b/examples/textedit/textcenter.xpm new file mode 100644 index 000000000..837152f67 --- /dev/null +++ b/examples/textedit/textcenter.xpm @@ -0,0 +1,27 @@ +/* XPM */ +static char * center_xpm[] = { +"22 22 2 1", +" c None", +". c #000000", +" ", +" ", +" ................. ", +" ", +" ............. ", +" ", +" ................. ", +" ", +" ............. ", +" ", +" ................. ", +" ", +" ............. ", +" ", +" ................. ", +" ", +" ............. ", +" ", +" ................. ", +" ", +" ", +" "}; diff --git a/examples/textedit/textedit.cpp b/examples/textedit/textedit.cpp new file mode 100644 index 000000000..a64c9d94c --- /dev/null +++ b/examples/textedit/textedit.cpp @@ -0,0 +1,455 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "textedit.h" + +#include <qtextedit.h> +#include <qaction.h> +#include <qmenubar.h> +#include <qpopupmenu.h> +#include <qtoolbar.h> +#include <qtabwidget.h> +#include <qapplication.h> +#include <qfontdatabase.h> +#include <qcombobox.h> +#include <qlineedit.h> +#include <qfileinfo.h> +#include <qfile.h> +#include <qfiledialog.h> +#include <qprinter.h> +#include <qpaintdevicemetrics.h> +#include <qsimplerichtext.h> +#include <qcolordialog.h> +#include <qpainter.h> + +TextEdit::TextEdit( TQWidget *parent, const char *name ) + : TQMainWindow( parent, name ) +{ + setupFileActions(); + setupEditActions(); + setupTextActions(); + + tabWidget = new TQTabWidget( this ); + connect( tabWidget, SIGNAL( currentChanged( TQWidget * ) ), + this, SLOT( editorChanged( TQWidget * ) ) ); + setCentralWidget( tabWidget ); + + if ( qApp->argc() == 1 ) { + load( "example.html" ); + } else { + for ( int i = 1; i < qApp->argc(); ++i ) + load( qApp->argv()[ i ] ); + } +} + +void TextEdit::setupFileActions() +{ + TQToolBar *tb = new TQToolBar( this ); + tb->setLabel( "File Actions" ); + TQPopupMenu *menu = new TQPopupMenu( this ); + menuBar()->insertItem( tr( "&File" ), menu ); + + TQAction *a; + a = new TQAction( TQPixmap::fromMimeSource( "filenew.xpm" ), tr( "&New..." ), CTRL + Key_N, this, "fileNew" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); + a->addTo( tb ); + a->addTo( menu ); + a = new TQAction( TQPixmap::fromMimeSource( "fileopen.xpm" ), tr( "&Open..." ), CTRL + Key_O, this, "fileOpen" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); + a->addTo( tb ); + a->addTo( menu ); + menu->insertSeparator(); + a = new TQAction( TQPixmap::fromMimeSource( "filesave.xpm" ), tr( "&Save..." ), CTRL + Key_S, this, "fileSave" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileSave() ) ); + a->addTo( tb ); + a->addTo( menu ); + a = new TQAction( tr( "Save &As..." ), 0, this, "fileSaveAs" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileSaveAs() ) ); + a->addTo( menu ); + menu->insertSeparator(); + a = new TQAction( TQPixmap::fromMimeSource( "fileprint.xpm" ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" ); + connect( a, SIGNAL( activated() ), this, SLOT( filePrint() ) ); + a->addTo( tb ); + a->addTo( menu ); + a = new TQAction( tr( "&Close" ), 0, this, "fileClose" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileClose() ) ); + a->addTo( menu ); + a = new TQAction( tr( "E&xit" ), 0, this, "fileExit" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileExit() ) ); + a->addTo( menu ); +} + +void TextEdit::setupEditActions() +{ + TQToolBar *tb = new TQToolBar( this ); + tb->setLabel( "Edit Actions" ); + TQPopupMenu *menu = new TQPopupMenu( this ); + menuBar()->insertItem( tr( "&Edit" ), menu ); + + TQAction *a; + a = new TQAction( TQPixmap::fromMimeSource( "editundo.xpm" ), tr( "&Undo" ), CTRL + Key_Z, this, "editUndo" ); + connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) ); + a->addTo( tb ); + a->addTo( menu ); + a = new TQAction( TQPixmap::fromMimeSource( "editredo.xpm" ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" ); + connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) ); + a->addTo( tb ); + a->addTo( menu ); + menu->insertSeparator(); + a = new TQAction( TQPixmap::fromMimeSource( "editcopy.xpm" ), tr( "&Copy" ), CTRL + Key_C, this, "editCopy" ); + connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); + a->addTo( tb ); + a->addTo( menu ); + a = new TQAction( TQPixmap::fromMimeSource( "editcut.xpm" ), tr( "Cu&t" ), CTRL + Key_X, this, "editCut" ); + connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); + a->addTo( tb ); + a->addTo( menu ); + a = new TQAction( TQPixmap::fromMimeSource( "editpaste.xpm" ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" ); + connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); + a->addTo( tb ); + a->addTo( menu ); +} + +void TextEdit::setupTextActions() +{ + TQToolBar *tb = new TQToolBar( this ); + tb->setLabel( "Format Actions" ); + TQPopupMenu *menu = new TQPopupMenu( this ); + menuBar()->insertItem( tr( "F&ormat" ), menu ); + + comboFont = new TQComboBox( TRUE, tb ); + TQFontDatabase db; + comboFont->insertStringList( db.families() ); + connect( comboFont, SIGNAL( activated( const TQString & ) ), + this, SLOT( textFamily( const TQString & ) ) ); + comboFont->lineEdit()->setText( TQApplication::font().family() ); + + comboSize = new TQComboBox( TRUE, tb ); + TQValueList<int> sizes = db.standardSizes(); + TQValueList<int>::Iterator it = sizes.begin(); + for ( ; it != sizes.end(); ++it ) + comboSize->insertItem( TQString::number( *it ) ); + connect( comboSize, SIGNAL( activated( const TQString & ) ), + this, SLOT( textSize( const TQString & ) ) ); + comboSize->lineEdit()->setText( TQString::number( TQApplication::font().pointSize() ) ); + + actionTextBold = new TQAction( TQPixmap::fromMimeSource( "textbold.xpm" ), tr( "&Bold" ), CTRL + Key_B, this, "textBold" ); + connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) ); + actionTextBold->addTo( tb ); + actionTextBold->addTo( menu ); + actionTextBold->setToggleAction( TRUE ); + actionTextItalic = new TQAction( TQPixmap::fromMimeSource( "textitalic.xpm" ), tr( "&Italic" ), CTRL + Key_I, this, "textItalic" ); + connect( actionTextItalic, SIGNAL( activated() ), this, SLOT( textItalic() ) ); + actionTextItalic->addTo( tb ); + actionTextItalic->addTo( menu ); + actionTextItalic->setToggleAction( TRUE ); + actionTextUnderline = new TQAction( TQPixmap::fromMimeSource( "textunder.xpm" ), tr( "&Underline" ), CTRL + Key_U, this, "textUnderline" ); + connect( actionTextUnderline, SIGNAL( activated() ), this, SLOT( textUnderline() ) ); + actionTextUnderline->addTo( tb ); + actionTextUnderline->addTo( menu ); + actionTextUnderline->setToggleAction( TRUE ); + menu->insertSeparator(); + + TQActionGroup *grp = new TQActionGroup( this ); + connect( grp, SIGNAL( selected( TQAction* ) ), this, SLOT( textAlign( TQAction* ) ) ); + + actionAlignLeft = new TQAction( TQPixmap::fromMimeSource( "textleft.xpm" ), tr( "&Left" ), CTRL + Key_L, grp, "textLeft" ); + actionAlignLeft->setToggleAction( TRUE ); + actionAlignCenter = new TQAction( TQPixmap::fromMimeSource( "textcenter.xpm" ), tr( "C&enter" ), CTRL + Key_E, grp, "textCenter" ); + actionAlignCenter->setToggleAction( TRUE ); + actionAlignRight = new TQAction( TQPixmap::fromMimeSource( "textright.xpm" ), tr( "&Right" ), CTRL + Key_R, grp, "textRight" ); + actionAlignRight->setToggleAction( TRUE ); + actionAlignJustify = new TQAction( TQPixmap::fromMimeSource( "textjustify.xpm" ), tr( "&Justify" ), CTRL + Key_J, grp, "textjustify" ); + actionAlignJustify->setToggleAction( TRUE ); + + grp->addTo( tb ); + grp->addTo( menu ); + + menu->insertSeparator(); + + TQPixmap pix( 16, 16 ); + pix.fill( black ); + actionTextColor = new TQAction( pix, tr( "&Color..." ), 0, this, "textColor" ); + connect( actionTextColor, SIGNAL( activated() ), this, SLOT( textColor() ) ); + actionTextColor->addTo( tb ); + actionTextColor->addTo( menu ); +} + +void TextEdit::load( const TQString &f ) +{ + if ( !TQFile::exists( f ) ) + return; + TQTextEdit *edit = new TQTextEdit( tabWidget ); + edit->setTextFormat( RichText ); + doConnections( edit ); + tabWidget->addTab( edit, TQFileInfo( f ).fileName() ); + TQFile file( f ); + if ( !file.open( IO_ReadOnly ) ) + return; + TQTextStream ts( &file ); + TQString txt = ts.read(); + if ( !TQStyleSheet::mightBeRichText( txt ) ) + txt = TQStyleSheet::convertFromPlainText( txt, TQStyleSheetItem::WhiteSpacePre ); + edit->setText( txt ); + tabWidget->showPage( edit ); + edit->viewport()->setFocus(); + filenames.replace( edit, f ); +} + +TQTextEdit *TextEdit::currentEditor() const +{ + if ( tabWidget->currentPage() && + tabWidget->currentPage()->inherits( "TQTextEdit" ) ) + return (TQTextEdit*)tabWidget->currentPage(); + return 0; +} + +void TextEdit::doConnections( TQTextEdit *e ) +{ + connect( e, SIGNAL( currentFontChanged( const TQFont & ) ), + this, SLOT( fontChanged( const TQFont & ) ) ); + connect( e, SIGNAL( currentColorChanged( const TQColor & ) ), + this, SLOT( colorChanged( const TQColor & ) ) ); + connect( e, SIGNAL( currentAlignmentChanged( int ) ), + this, SLOT( alignmentChanged( int ) ) ); +} + +void TextEdit::fileNew() +{ + TQTextEdit *edit = new TQTextEdit( tabWidget ); + edit->setTextFormat( RichText ); + doConnections( edit ); + tabWidget->addTab( edit, tr( "noname" ) ); + tabWidget->showPage( edit ); + edit->viewport()->setFocus(); +} + +void TextEdit::fileOpen() +{ + TQString fn = TQFileDialog::getOpenFileName( TQString::null, tr( "HTML-Files (*.htm *.html);;All Files (*)" ), this ); + if ( !fn.isEmpty() ) + load( fn ); +} + +void TextEdit::fileSave() +{ + if ( !currentEditor() ) + return; + TQString fn; + if ( filenames.find( currentEditor() ) == filenames.end() ) { + fileSaveAs(); + } else { + TQFile file( *filenames.find( currentEditor() ) ); + if ( !file.open( IO_WriteOnly ) ) + return; + TQTextStream ts( &file ); + ts << currentEditor()->text(); + } +} + +void TextEdit::fileSaveAs() +{ + if ( !currentEditor() ) + return; + TQString fn = TQFileDialog::getSaveFileName( TQString::null, tr( "HTML-Files (*.htm *.html);;All Files (*)" ), this ); + if ( !fn.isEmpty() ) { + filenames.replace( currentEditor(), fn ); + fileSave(); + tabWidget->setTabLabel( currentEditor(), TQFileInfo( fn ).fileName() ); + } +} + +void TextEdit::filePrint() +{ + if ( !currentEditor() ) + return; +#ifndef QT_NO_PRINTER + TQPrinter printer( TQPrinter::HighResolution ); + printer.setFullPage(TRUE); + if ( printer.setup( this ) ) { + TQPainter p( &printer ); + // Check that there is a valid device to print to. + if ( !p.device() ) return; + TQPaintDeviceMetrics metrics( p.device() ); + int dpiy = metrics.logicalDpiY(); + int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins + TQRect view( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin ); + TQFont font( currentEditor()->TQWidget::font() ); + font.setPointSize( 10 ); // we define 10pt to be a nice base size for printing + + TQSimpleRichText richText( currentEditor()->text(), font, + currentEditor()->context(), + currentEditor()->styleSheet(), + currentEditor()->mimeSourceFactory(), + view.height() ); + richText.setWidth( &p, view.width() ); + int page = 1; + do { + richText.draw( &p, margin, margin, view, colorGroup() ); + view.moveBy( 0, view.height() ); + p.translate( 0 , -view.height() ); + p.setFont( font ); + p.drawText( view.right() - p.fontMetrics().width( TQString::number( page ) ), + view.bottom() + p.fontMetrics().ascent() + 5, TQString::number( page ) ); + if ( view.top() - margin >= richText.height() ) + break; + printer.newPage(); + page++; + } while (TRUE); + } +#endif +} + +void TextEdit::fileClose() +{ + delete currentEditor(); + if ( currentEditor() ) + currentEditor()->viewport()->setFocus(); +} + +void TextEdit::fileExit() +{ + qApp->tquit(); +} + +void TextEdit::editUndo() +{ + if ( !currentEditor() ) + return; + currentEditor()->undo(); +} + +void TextEdit::editRedo() +{ + if ( !currentEditor() ) + return; + currentEditor()->redo(); +} + +void TextEdit::editCut() +{ + if ( !currentEditor() ) + return; + currentEditor()->cut(); +} + +void TextEdit::editCopy() +{ + if ( !currentEditor() ) + return; + currentEditor()->copy(); +} + +void TextEdit::editPaste() +{ + if ( !currentEditor() ) + return; + currentEditor()->paste(); +} + +void TextEdit::textBold() +{ + if ( !currentEditor() ) + return; + currentEditor()->setBold( actionTextBold->isOn() ); +} + +void TextEdit::textUnderline() +{ + if ( !currentEditor() ) + return; + currentEditor()->setUnderline( actionTextUnderline->isOn() ); +} + +void TextEdit::textItalic() +{ + if ( !currentEditor() ) + return; + currentEditor()->setItalic( actionTextItalic->isOn() ); +} + +void TextEdit::textFamily( const TQString &f ) +{ + if ( !currentEditor() ) + return; + currentEditor()->setFamily( f ); + currentEditor()->viewport()->setFocus(); +} + +void TextEdit::textSize( const TQString &p ) +{ + if ( !currentEditor() ) + return; + currentEditor()->setPointSize( p.toInt() ); + currentEditor()->viewport()->setFocus(); +} + +void TextEdit::textColor() +{ + if ( !currentEditor() ) + return; + TQColor col = TQColorDialog::getColor( currentEditor()->color(), this ); + if ( !col.isValid() ) + return; + currentEditor()->setColor( col ); + TQPixmap pix( 16, 16 ); + pix.fill( black ); + actionTextColor->setIconSet( pix ); +} + +void TextEdit::textAlign( TQAction *a ) +{ + if ( !currentEditor() ) + return; + if ( a == actionAlignLeft ) + currentEditor()->setAlignment( AlignLeft ); + else if ( a == actionAlignCenter ) + currentEditor()->setAlignment( AlignHCenter ); + else if ( a == actionAlignRight ) + currentEditor()->setAlignment( AlignRight ); + else if ( a == actionAlignJustify ) + currentEditor()->setAlignment( AlignJustify ); +} + +void TextEdit::fontChanged( const TQFont &f ) +{ + comboFont->lineEdit()->setText( f.family() ); + comboSize->lineEdit()->setText( TQString::number( f.pointSize() ) ); + actionTextBold->setOn( f.bold() ); + actionTextItalic->setOn( f.italic() ); + actionTextUnderline->setOn( f.underline() ); +} + +void TextEdit::colorChanged( const TQColor &c ) +{ + TQPixmap pix( 16, 16 ); + pix.fill( c ); + actionTextColor->setIconSet( pix ); +} + +void TextEdit::alignmentChanged( int a ) +{ + if ( ( a == AlignAuto ) || ( a & AlignLeft )) + actionAlignLeft->setOn( TRUE ); + else if ( ( a & AlignHCenter ) ) + actionAlignCenter->setOn( TRUE ); + else if ( ( a & AlignRight ) ) + actionAlignRight->setOn( TRUE ); + else if ( ( a & AlignJustify ) ) + actionAlignJustify->setOn( TRUE ); +} + +void TextEdit::editorChanged( TQWidget * ) +{ + if ( !currentEditor() ) + return; + fontChanged( currentEditor()->currentFont() ); + colorChanged( currentEditor()->color() ); + alignmentChanged( currentEditor()->alignment() ); +} diff --git a/examples/textedit/textedit.doc b/examples/textedit/textedit.doc new file mode 100644 index 000000000..53279b93e --- /dev/null +++ b/examples/textedit/textedit.doc @@ -0,0 +1,18 @@ +/*! \page textedit-example.html + + \ingroup examples + \title Text Edit Example + + This example displays a text editor with the user interface written + in pure C++. + + A similar example which uses \link designer-manual.book Qt + Designer\endlink to produce the user interface is in the \link + designer-manual.book Qt Designer manual\endlink. + + + See \c{$QTDIR/examples/textedit} for the source code. + +*/ + + diff --git a/examples/textedit/textedit.h b/examples/textedit/textedit.h new file mode 100644 index 000000000..7b2031f03 --- /dev/null +++ b/examples/textedit/textedit.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef TEXTEDIT_H +#define TEXTEDIT_H + +#include <qmainwindow.h> +#include <qmap.h> + +class TQAction; +class TQComboBox; +class TQTabWidget; +class TQTextEdit; + +class TextEdit : public TQMainWindow +{ + Q_OBJECT + +public: + TextEdit( TQWidget *parent = 0, const char *name = 0 ); + +private: + void setupFileActions(); + void setupEditActions(); + void setupTextActions(); + void load( const TQString &f ); + TQTextEdit *currentEditor() const; + void doConnections( TQTextEdit *e ); + +private slots: + void fileNew(); + void fileOpen(); + void fileSave(); + void fileSaveAs(); + void filePrint(); + void fileClose(); + void fileExit(); + + void editUndo(); + void editRedo(); + void editCut(); + void editCopy(); + void editPaste(); + + void textBold(); + void textUnderline(); + void textItalic(); + void textFamily( const TQString &f ); + void textSize( const TQString &p ); + void textColor(); + void textAlign( TQAction *a ); + + void fontChanged( const TQFont &f ); + void colorChanged( const TQColor &c ); + void alignmentChanged( int a ); + void editorChanged( TQWidget * ); + +private: + TQAction *actionTextBold, + *actionTextUnderline, + *actionTextItalic, + *actionTextColor, + *actionAlignLeft, + *actionAlignCenter, + *actionAlignRight, + *actionAlignJustify; + TQComboBox + *comboFont, + *comboSize; + TQTabWidget *tabWidget; + TQMap<TQTextEdit*, TQString> filenames; + +}; + + +#endif diff --git a/examples/textedit/textedit.pro b/examples/textedit/textedit.pro new file mode 100644 index 000000000..eeb206785 --- /dev/null +++ b/examples/textedit/textedit.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +TARGET = textedit + +CONFIG += qt warn_on release + +REQUIRES = full-config nocrosscompiler + +HEADERS = textedit.h +SOURCES = textedit.cpp \ + main.cpp +IMAGES = editcopy.xpm editcut.xpm editpaste.xpm editredo.xpm editundo.xpm filenew.xpm fileopen.xpm fileprint.xpm filesave.xpm textbold.xpm textcenter.xpm textitalic.xpm textjustify.xpm textleft.xpm textright.xpm textunder.xpm diff --git a/examples/textedit/textitalic.xpm b/examples/textedit/textitalic.xpm new file mode 100644 index 000000000..329e66d3e --- /dev/null +++ b/examples/textedit/textitalic.xpm @@ -0,0 +1,27 @@ +/* XPM */ +static char * italic_xpm[] = { +"22 22 2 1", +" c None", +". c #000000", +" ", +" ", +" ", +" ", +" ..... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ... ", +" ..... ", +" ", +" ", +" ", +" "}; diff --git a/examples/textedit/textjustify.xpm b/examples/textedit/textjustify.xpm new file mode 100644 index 000000000..75b4a274a --- /dev/null +++ b/examples/textedit/textjustify.xpm @@ -0,0 +1,27 @@ +/* XPM */ +static char * block_xpm[] = { +"22 22 2 1", +" c None", +". c #000000", +" ", +" ", +" ................. ", +" ", +" ................. ", +" ", +" ................. ", +" ", +" ................. ", +" ", +" ................. ", +" ", +" ................. ", +" ", +" ................. ", +" ", +" ................. ", +" ", +" ............. ", +" ", +" ", +" "}; diff --git a/examples/textedit/textleft.xpm b/examples/textedit/textleft.xpm new file mode 100644 index 000000000..a63e7cef1 --- /dev/null +++ b/examples/textedit/textleft.xpm @@ -0,0 +1,27 @@ +/* XPM */ +static char * left_xpm[] = { +"22 22 2 1", +" c None", +". c #000000", +" ", +" ", +" ................. ", +" ", +" ............. ", +" ", +" ................. ", +" ", +" ............. ", +" ", +" ................. ", +" ", +" ............. ", +" ", +" ................. ", +" ", +" ............. ", +" ", +" ................. ", +" ", +" ", +" "}; diff --git a/examples/textedit/textright.xpm b/examples/textedit/textright.xpm new file mode 100644 index 000000000..3e896bd7a --- /dev/null +++ b/examples/textedit/textright.xpm @@ -0,0 +1,27 @@ +/* XPM */ +static char * right_xpm[] = { +"22 22 2 1", +" c None", +". c #000000", +" ", +" ", +" ................. ", +" ", +" ............. ", +" ", +" ................. ", +" ", +" ............. ", +" ", +" ................. ", +" ", +" ............. ", +" ", +" ................. ", +" ", +" ............. ", +" ", +" ................. ", +" ", +" ", +" "}; diff --git a/examples/textedit/textunder.xpm b/examples/textedit/textunder.xpm new file mode 100644 index 000000000..ec962a74c --- /dev/null +++ b/examples/textedit/textunder.xpm @@ -0,0 +1,27 @@ +/* XPM */ +static char * under_xpm[] = { +"22 22 2 1", +" c None", +". c #000000", +" ", +" ", +" ", +" ", +" ..... .... ", +" ... . ", +" ... . ", +" ... . ", +" ... . ", +" ... . ", +" ... . ", +" ... . ", +" ... . ", +" ... . ", +" ... .. ", +" ... .. ", +" ...... ", +" ", +" ............ ", +" ", +" ", +" "}; |