From bd0f3345a938b35ce6a12f6150373b0955b8dd12 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 10 Jul 2011 15:24:15 -0500 Subject: Add Qt3 development HEAD version --- examples/textedit/editcopy.xpm | 36 +++ examples/textedit/editcut.xpm | 32 +++ examples/textedit/editpaste.xpm | 36 +++ examples/textedit/editredo.xpm | 36 +++ examples/textedit/editundo.xpm | 36 +++ examples/textedit/example.html | 24 ++ examples/textedit/filenew.xpm | 36 +++ examples/textedit/fileopen.xpm | 36 +++ examples/textedit/fileprint.xpm | 117 ++++++++++ examples/textedit/filesave.xpm | 36 +++ examples/textedit/main.cpp | 22 ++ examples/textedit/textbold.xpm | 27 +++ examples/textedit/textcenter.xpm | 27 +++ examples/textedit/textedit.cpp | 455 ++++++++++++++++++++++++++++++++++++++ examples/textedit/textedit.doc | 18 ++ examples/textedit/textedit.h | 82 +++++++ examples/textedit/textedit.pro | 11 + examples/textedit/textitalic.xpm | 27 +++ examples/textedit/textjustify.xpm | 27 +++ examples/textedit/textleft.xpm | 27 +++ examples/textedit/textright.xpm | 27 +++ examples/textedit/textunder.xpm | 27 +++ 22 files changed, 1202 insertions(+) create mode 100644 examples/textedit/editcopy.xpm create mode 100644 examples/textedit/editcut.xpm create mode 100644 examples/textedit/editpaste.xpm create mode 100644 examples/textedit/editredo.xpm create mode 100644 examples/textedit/editundo.xpm create mode 100644 examples/textedit/example.html create mode 100644 examples/textedit/filenew.xpm create mode 100644 examples/textedit/fileopen.xpm create mode 100644 examples/textedit/fileprint.xpm create mode 100644 examples/textedit/filesave.xpm create mode 100644 examples/textedit/main.cpp create mode 100644 examples/textedit/textbold.xpm create mode 100644 examples/textedit/textcenter.xpm create mode 100644 examples/textedit/textedit.cpp create mode 100644 examples/textedit/textedit.doc create mode 100644 examples/textedit/textedit.h create mode 100644 examples/textedit/textedit.pro create mode 100644 examples/textedit/textitalic.xpm create mode 100644 examples/textedit/textjustify.xpm create mode 100644 examples/textedit/textleft.xpm create mode 100644 examples/textedit/textright.xpm create mode 100644 examples/textedit/textunder.xpm (limited to 'examples/textedit') diff --git a/examples/textedit/editcopy.xpm b/examples/textedit/editcopy.xpm new file mode 100644 index 0000000..cc6fb7a --- /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 0000000..2391add --- /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 0000000..3f77592 --- /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 0000000..46dc033 --- /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 0000000..229c163 --- /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 0000000..0c8d342 --- /dev/null +++ b/examples/textedit/example.html @@ -0,0 +1,24 @@ + +

QTextEdit

+

QTextEdit is an advanced WYSIWYG editor supporting richtext formatting. It is optimized to handle large documents and to respond quickly to user input.

+

QTextEdit supports font styles such as bold, italic, underlined as well as various colors and sizes. You can select different font families, for example Times New Roman or Courier. Futhermore the widget supports different paragraph alignments such as justified,

+

left aligned,

+

centered,

+

and right aligned.

+

+ + diff --git a/examples/textedit/filenew.xpm b/examples/textedit/filenew.xpm new file mode 100644 index 0000000..884d7cb --- /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 0000000..82effcf --- /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 0000000..8701d46 --- /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 0000000..71cbd33 --- /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 0000000..53907dd --- /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 Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include +#include "textedit.h" + +int main( int argc, char ** argv ) +{ + QApplication a( argc, argv ); + TextEdit * mw = new TextEdit(); + mw->setCaption( "Richtext Editor" ); + mw->resize( 640, 800 ); + mw->show(); + a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) ); + return a.exec(); +} diff --git a/examples/textedit/textbold.xpm b/examples/textedit/textbold.xpm new file mode 100644 index 0000000..8398e2e --- /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 0000000..837152f --- /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 0000000..1523d18 --- /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 Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "textedit.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +TextEdit::TextEdit( QWidget *parent, const char *name ) + : QMainWindow( parent, name ) +{ + setupFileActions(); + setupEditActions(); + setupTextActions(); + + tabWidget = new QTabWidget( this ); + connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ), + this, SLOT( editorChanged( QWidget * ) ) ); + 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() +{ + QToolBar *tb = new QToolBar( this ); + tb->setLabel( "File Actions" ); + QPopupMenu *menu = new QPopupMenu( this ); + menuBar()->insertItem( tr( "&File" ), menu ); + + QAction *a; + a = new QAction( QPixmap::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 QAction( QPixmap::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 QAction( QPixmap::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 QAction( tr( "Save &As..." ), 0, this, "fileSaveAs" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileSaveAs() ) ); + a->addTo( menu ); + menu->insertSeparator(); + a = new QAction( QPixmap::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 QAction( tr( "&Close" ), 0, this, "fileClose" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileClose() ) ); + a->addTo( menu ); + a = new QAction( tr( "E&xit" ), 0, this, "fileExit" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileExit() ) ); + a->addTo( menu ); +} + +void TextEdit::setupEditActions() +{ + QToolBar *tb = new QToolBar( this ); + tb->setLabel( "Edit Actions" ); + QPopupMenu *menu = new QPopupMenu( this ); + menuBar()->insertItem( tr( "&Edit" ), menu ); + + QAction *a; + a = new QAction( QPixmap::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 QAction( QPixmap::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 QAction( QPixmap::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 QAction( QPixmap::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 QAction( QPixmap::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() +{ + QToolBar *tb = new QToolBar( this ); + tb->setLabel( "Format Actions" ); + QPopupMenu *menu = new QPopupMenu( this ); + menuBar()->insertItem( tr( "F&ormat" ), menu ); + + comboFont = new QComboBox( TRUE, tb ); + QFontDatabase db; + comboFont->insertStringList( db.families() ); + connect( comboFont, SIGNAL( activated( const QString & ) ), + this, SLOT( textFamily( const QString & ) ) ); + comboFont->lineEdit()->setText( QApplication::font().family() ); + + comboSize = new QComboBox( TRUE, tb ); + QValueList sizes = db.standardSizes(); + QValueList::Iterator it = sizes.begin(); + for ( ; it != sizes.end(); ++it ) + comboSize->insertItem( QString::number( *it ) ); + connect( comboSize, SIGNAL( activated( const QString & ) ), + this, SLOT( textSize( const QString & ) ) ); + comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) ); + + actionTextBold = new QAction( QPixmap::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 QAction( QPixmap::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 QAction( QPixmap::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(); + + QActionGroup *grp = new QActionGroup( this ); + connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) ); + + actionAlignLeft = new QAction( QPixmap::fromMimeSource( "textleft.xpm" ), tr( "&Left" ), CTRL + Key_L, grp, "textLeft" ); + actionAlignLeft->setToggleAction( TRUE ); + actionAlignCenter = new QAction( QPixmap::fromMimeSource( "textcenter.xpm" ), tr( "C&enter" ), CTRL + Key_E, grp, "textCenter" ); + actionAlignCenter->setToggleAction( TRUE ); + actionAlignRight = new QAction( QPixmap::fromMimeSource( "textright.xpm" ), tr( "&Right" ), CTRL + Key_R, grp, "textRight" ); + actionAlignRight->setToggleAction( TRUE ); + actionAlignJustify = new QAction( QPixmap::fromMimeSource( "textjustify.xpm" ), tr( "&Justify" ), CTRL + Key_J, grp, "textjustify" ); + actionAlignJustify->setToggleAction( TRUE ); + + grp->addTo( tb ); + grp->addTo( menu ); + + menu->insertSeparator(); + + QPixmap pix( 16, 16 ); + pix.fill( black ); + actionTextColor = new QAction( pix, tr( "&Color..." ), 0, this, "textColor" ); + connect( actionTextColor, SIGNAL( activated() ), this, SLOT( textColor() ) ); + actionTextColor->addTo( tb ); + actionTextColor->addTo( menu ); +} + +void TextEdit::load( const QString &f ) +{ + if ( !QFile::exists( f ) ) + return; + QTextEdit *edit = new QTextEdit( tabWidget ); + edit->setTextFormat( RichText ); + doConnections( edit ); + tabWidget->addTab( edit, QFileInfo( f ).fileName() ); + QFile file( f ); + if ( !file.open( IO_ReadOnly ) ) + return; + QTextStream ts( &file ); + QString txt = ts.read(); + if ( !QStyleSheet::mightBeRichText( txt ) ) + txt = QStyleSheet::convertFromPlainText( txt, QStyleSheetItem::WhiteSpacePre ); + edit->setText( txt ); + tabWidget->showPage( edit ); + edit->viewport()->setFocus(); + filenames.replace( edit, f ); +} + +QTextEdit *TextEdit::currentEditor() const +{ + if ( tabWidget->currentPage() && + tabWidget->currentPage()->inherits( "QTextEdit" ) ) + return (QTextEdit*)tabWidget->currentPage(); + return 0; +} + +void TextEdit::doConnections( QTextEdit *e ) +{ + connect( e, SIGNAL( currentFontChanged( const QFont & ) ), + this, SLOT( fontChanged( const QFont & ) ) ); + connect( e, SIGNAL( currentColorChanged( const QColor & ) ), + this, SLOT( colorChanged( const QColor & ) ) ); + connect( e, SIGNAL( currentAlignmentChanged( int ) ), + this, SLOT( alignmentChanged( int ) ) ); +} + +void TextEdit::fileNew() +{ + QTextEdit *edit = new QTextEdit( tabWidget ); + edit->setTextFormat( RichText ); + doConnections( edit ); + tabWidget->addTab( edit, tr( "noname" ) ); + tabWidget->showPage( edit ); + edit->viewport()->setFocus(); +} + +void TextEdit::fileOpen() +{ + QString fn = QFileDialog::getOpenFileName( QString::null, tr( "HTML-Files (*.htm *.html);;All Files (*)" ), this ); + if ( !fn.isEmpty() ) + load( fn ); +} + +void TextEdit::fileSave() +{ + if ( !currentEditor() ) + return; + QString fn; + if ( filenames.find( currentEditor() ) == filenames.end() ) { + fileSaveAs(); + } else { + QFile file( *filenames.find( currentEditor() ) ); + if ( !file.open( IO_WriteOnly ) ) + return; + QTextStream ts( &file ); + ts << currentEditor()->text(); + } +} + +void TextEdit::fileSaveAs() +{ + if ( !currentEditor() ) + return; + QString fn = QFileDialog::getSaveFileName( QString::null, tr( "HTML-Files (*.htm *.html);;All Files (*)" ), this ); + if ( !fn.isEmpty() ) { + filenames.replace( currentEditor(), fn ); + fileSave(); + tabWidget->setTabLabel( currentEditor(), QFileInfo( fn ).fileName() ); + } +} + +void TextEdit::filePrint() +{ + if ( !currentEditor() ) + return; +#ifndef QT_NO_PRINTER + QPrinter printer( QPrinter::HighResolution ); + printer.setFullPage(TRUE); + if ( printer.setup( this ) ) { + QPainter p( &printer ); + // Check that there is a valid device to print to. + if ( !p.device() ) return; + QPaintDeviceMetrics metrics( p.device() ); + int dpiy = metrics.logicalDpiY(); + int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins + QRect view( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin ); + QFont font( currentEditor()->QWidget::font() ); + font.setPointSize( 10 ); // we define 10pt to be a nice base size for printing + + QSimpleRichText 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( QString::number( page ) ), + view.bottom() + p.fontMetrics().ascent() + 5, QString::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->quit(); +} + +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 QString &f ) +{ + if ( !currentEditor() ) + return; + currentEditor()->setFamily( f ); + currentEditor()->viewport()->setFocus(); +} + +void TextEdit::textSize( const QString &p ) +{ + if ( !currentEditor() ) + return; + currentEditor()->setPointSize( p.toInt() ); + currentEditor()->viewport()->setFocus(); +} + +void TextEdit::textColor() +{ + if ( !currentEditor() ) + return; + QColor col = QColorDialog::getColor( currentEditor()->color(), this ); + if ( !col.isValid() ) + return; + currentEditor()->setColor( col ); + QPixmap pix( 16, 16 ); + pix.fill( black ); + actionTextColor->setIconSet( pix ); +} + +void TextEdit::textAlign( QAction *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 QFont &f ) +{ + comboFont->lineEdit()->setText( f.family() ); + comboSize->lineEdit()->setText( QString::number( f.pointSize() ) ); + actionTextBold->setOn( f.bold() ); + actionTextItalic->setOn( f.italic() ); + actionTextUnderline->setOn( f.underline() ); +} + +void TextEdit::colorChanged( const QColor &c ) +{ + QPixmap 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( QWidget * ) +{ + 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 0000000..53279b9 --- /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 0000000..3c3aacb --- /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 Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef TEXTEDIT_H +#define TEXTEDIT_H + +#include +#include + +class QAction; +class QComboBox; +class QTabWidget; +class QTextEdit; + +class TextEdit : public QMainWindow +{ + Q_OBJECT + +public: + TextEdit( QWidget *parent = 0, const char *name = 0 ); + +private: + void setupFileActions(); + void setupEditActions(); + void setupTextActions(); + void load( const QString &f ); + QTextEdit *currentEditor() const; + void doConnections( QTextEdit *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 QString &f ); + void textSize( const QString &p ); + void textColor(); + void textAlign( QAction *a ); + + void fontChanged( const QFont &f ); + void colorChanged( const QColor &c ); + void alignmentChanged( int a ); + void editorChanged( QWidget * ); + +private: + QAction *actionTextBold, + *actionTextUnderline, + *actionTextItalic, + *actionTextColor, + *actionAlignLeft, + *actionAlignCenter, + *actionAlignRight, + *actionAlignJustify; + QComboBox + *comboFont, + *comboSize; + QTabWidget *tabWidget; + QMap filenames; + +}; + + +#endif diff --git a/examples/textedit/textedit.pro b/examples/textedit/textedit.pro new file mode 100644 index 0000000..eeb2067 --- /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 0000000..329e66d --- /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 0000000..75b4a27 --- /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 0000000..a63e7ce --- /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 0000000..3e896bd --- /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 0000000..ec962a7 --- /dev/null +++ b/examples/textedit/textunder.xpm @@ -0,0 +1,27 @@ +/* XPM */ +static char * under_xpm[] = { +"22 22 2 1", +" c None", +". c #000000", +" ", +" ", +" ", +" ", +" ..... .... ", +" ... . ", +" ... . ", +" ... . ", +" ... . ", +" ... . ", +" ... . ", +" ... . ", +" ... . ", +" ... . ", +" ... .. ", +" ... .. ", +" ...... ", +" ", +" ............ ", +" ", +" ", +" "}; -- cgit v1.2.3