diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2009-03-23 09:34:13 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-03-23 09:34:13 (GMT) |
commit | 67ad0519fd165acee4a4d2a94fa502e9e4847bd0 (patch) | |
tree | 1dbf50b3dff8d5ca7e9344733968c72704eb15ff /demos/textedit | |
download | Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.zip Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.gz Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.bz2 |
Long live Qt!
Diffstat (limited to 'demos/textedit')
46 files changed, 1033 insertions, 0 deletions
diff --git a/demos/textedit/example.html b/demos/textedit/example.html new file mode 100644 index 0000000..19b5520 --- /dev/null +++ b/demos/textedit/example.html @@ -0,0 +1,79 @@ +<html><head><meta name="qrichtext" content="1" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>QTextEdit Demonstration</title><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> +<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:20pt; font-weight:600;">QTextEdit</span></p> +<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">The QTextEdit widget is an advanced editor that supports formatted rich text. It can be used to display HTML and other rich document formats. Internally, QTextEdit uses the QTextDocument class to describe both the high-level structure of each document and the low-level formatting of paragraphs.</span></p> +<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">If you are viewing this document in the <span style=" font-style:italic;">textedit</span> demo, you can edit this document to explore Qt's rich text editing features. We have included some comments in each of the following sections to encourage you to experiment. </p> +<p style=" margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:18pt; font-weight:600;"><span style=" font-size:16pt;">Font and Paragraph Styles</span></p> +<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">QTextEdit supports </span><span style=" font-size:11pt; font-weight:600;">bold</span><span style=" font-size:11pt;">, </span><span style=" font-size:11pt; font-style:italic;">italic</span><span style=" font-size:11pt;">, and </span><span style=" font-size:11pt; text-decoration: underline;">underlined</span><span style=" font-size:11pt;"> font styles, and can display </span><span style=" font-size:11pt; font-weight:600; color:#00007f;">multicolored</span><span style=" font-size:11pt;"> </span><span style=" font-size:11pt; font-weight:600; color:#aa0000;">text</span><span style=" font-size:11pt;">. Font families such as </span><span style=" font-family:'Times'; font-size:11pt; font-weight:600;">Times New Roman</span><span style=" font-size:11pt;"> and </span><span style=" font-family:'Courier'; font-size:11pt; font-weight:600;">Courier</span><span style=" font-size:11pt;"> can also be used directly. </span><span style=" font-size:11pt; font-style:italic;">If you place the cursor in a region of styled text, the controls in the tool bars will change to reflect the current style.</span></p> +<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">Paragraphs can be formatted so that the text is left-aligned, right-aligned, centered, or fully justified.</p> +<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-style:italic;">Try changing the alignment of some text and resize the editor to see how the text layout changes.</span> </p> +<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:16pt; font-weight:600;">Lists</span></p> +<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">Different kinds of lists can be included in rich text documents. Standard bullet lists can be nested, using different symbols for each level of the list: </span></p> +<ul style="-qt-list-indent: 1;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Disc symbols are typically used for top-level list items. </li></ul> +<ul type=circle style="-qt-list-indent: 2;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Circle symbols can be used to distinguish between items in lower-level lists.</li></ul> +<ul type=square style="-qt-list-indent: 3;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Square symbols provide a reasonable alternative to discs and circles. </li></ul> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">Ordered lists can be created that can be used for tables of contents. Different characters can be used to enumerate items, and we can use both Roman and Arabic numerals in the same list structure: </p> +<ol style="-qt-list-indent: 1;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Introduction</li> +<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Tools </li></ol> +<ol type=a style="-qt-list-indent: 2;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Assistant</li> +<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Designer</li> +<ol type=A style="-qt-list-indent: 3;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Form Editor</li> +<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Component Architecture</li></ol> +<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Linguist</li></ol> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">The list will automatically be renumbered if you add or remove items. <span style=" font-style:italic;">Try adding new sections to the above list or removing existing item to see the numbers change.</span> </p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p> +<p style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Images</span></p> +<p style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">Inline images are treated like ordinary ranges of characters in the text editor, so they flow with the surrounding text. Images can also be selected in the same way as text, making it easy to cut, copy, and paste them. </span></p> +<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><img src=":/images/logo32.png" /><span style=" font-style:italic;"> Try to select this image by clicking and dragging over it with the mouse, or use the text cursor to select it by holding down Shift and using the arrow keys. You can then cut or copy it, and pasting it into different parts of this document.</span></p> +<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Tables</span></p> +<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">QTextEdit can arrange and format tables, supporting features such as row and column spans, text formatting within cells, and size constraints for columns. </span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p> +<table border="1" align="center" width="90%" cellspacing="0" cellpadding="4"> +<tr> +<td> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> </p></td> +<td> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Development Tools </span></p></td> +<td> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Programming Techniques </span></p></td> +<td> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Graphical User Interfaces </span></p></td></tr> +<tr> +<td> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">9:00 - 11:00 </span></p></td> +<td colspan="3"> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Introduction to <span style=" font-style:italic;">Qt </span></p></td></tr> +<tr> +<td> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">11:00 - 13:00 </span></p></td> +<td> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Using <span style=" font-style:italic;">qmake</span> </p></td> +<td> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Object-oriented Programming </p></td> +<td> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Layouts in <span style=" font-style:italic;">Qt</span> </p></td></tr> +<tr> +<td> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">13:00 - 15:00 </span></p></td> +<td> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Qt Designer</span> Tutorial </p></td> +<td rowspan="2"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Extreme Programming </p></td> +<td> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Writing Custom Styles </p></td></tr> +<tr> +<td> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">15:00 - 17:00 </span></p></td> +<td> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Qt Linguist</span> and Internationalization </p></td> +<td></td></tr></table> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt; font-style:italic;">Try adding text to the cells in the table and experiment with the alignment of the paragraphs.</p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Hyperlinks</span></p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">QTextEdit is designed to support hyperlinks between documents, and this feature is used extensively in </span><span style=" font-size:11pt; font-style:italic;">Qt Assistant</span><span style=" font-size:11pt;">. Hyperlinks are automatically created when an HTML file is imported into an editor. Since the rich text framework supports hyperlinks natively, they can also be created programatically.</span></p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Undo and Redo</span></p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">Full support for undo and redo operations is built into QTextEdit and the underlying rich text framework. Operations on a document can be packaged together to make editing a more comfortable experience for the user.</p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-style:italic;">Try making changes to this document and press Ctrl+Z to undo them. You can always recover the original contents of the document.</span> </p></body></html> diff --git a/demos/textedit/images/logo32.png b/demos/textedit/images/logo32.png Binary files differnew file mode 100644 index 0000000..5f91e98 --- /dev/null +++ b/demos/textedit/images/logo32.png diff --git a/demos/textedit/images/mac/editcopy.png b/demos/textedit/images/mac/editcopy.png Binary files differnew file mode 100644 index 0000000..f551364 --- /dev/null +++ b/demos/textedit/images/mac/editcopy.png diff --git a/demos/textedit/images/mac/editcut.png b/demos/textedit/images/mac/editcut.png Binary files differnew file mode 100644 index 0000000..a784fd5 --- /dev/null +++ b/demos/textedit/images/mac/editcut.png diff --git a/demos/textedit/images/mac/editpaste.png b/demos/textedit/images/mac/editpaste.png Binary files differnew file mode 100644 index 0000000..64c0b2d --- /dev/null +++ b/demos/textedit/images/mac/editpaste.png diff --git a/demos/textedit/images/mac/editredo.png b/demos/textedit/images/mac/editredo.png Binary files differnew file mode 100644 index 0000000..8875bf2 --- /dev/null +++ b/demos/textedit/images/mac/editredo.png diff --git a/demos/textedit/images/mac/editundo.png b/demos/textedit/images/mac/editundo.png Binary files differnew file mode 100644 index 0000000..a3bd5e0 --- /dev/null +++ b/demos/textedit/images/mac/editundo.png diff --git a/demos/textedit/images/mac/exportpdf.png b/demos/textedit/images/mac/exportpdf.png Binary files differnew file mode 100644 index 0000000..ebb44e6 --- /dev/null +++ b/demos/textedit/images/mac/exportpdf.png diff --git a/demos/textedit/images/mac/filenew.png b/demos/textedit/images/mac/filenew.png Binary files differnew file mode 100644 index 0000000..d3882c7 --- /dev/null +++ b/demos/textedit/images/mac/filenew.png diff --git a/demos/textedit/images/mac/fileopen.png b/demos/textedit/images/mac/fileopen.png Binary files differnew file mode 100644 index 0000000..fc06c5e --- /dev/null +++ b/demos/textedit/images/mac/fileopen.png diff --git a/demos/textedit/images/mac/fileprint.png b/demos/textedit/images/mac/fileprint.png Binary files differnew file mode 100644 index 0000000..10ca56c --- /dev/null +++ b/demos/textedit/images/mac/fileprint.png diff --git a/demos/textedit/images/mac/filesave.png b/demos/textedit/images/mac/filesave.png Binary files differnew file mode 100644 index 0000000..b41ecf5 --- /dev/null +++ b/demos/textedit/images/mac/filesave.png diff --git a/demos/textedit/images/mac/textbold.png b/demos/textedit/images/mac/textbold.png Binary files differnew file mode 100644 index 0000000..38400bd --- /dev/null +++ b/demos/textedit/images/mac/textbold.png diff --git a/demos/textedit/images/mac/textcenter.png b/demos/textedit/images/mac/textcenter.png Binary files differnew file mode 100644 index 0000000..2ef5b2e --- /dev/null +++ b/demos/textedit/images/mac/textcenter.png diff --git a/demos/textedit/images/mac/textitalic.png b/demos/textedit/images/mac/textitalic.png Binary files differnew file mode 100644 index 0000000..0170ee2 --- /dev/null +++ b/demos/textedit/images/mac/textitalic.png diff --git a/demos/textedit/images/mac/textjustify.png b/demos/textedit/images/mac/textjustify.png Binary files differnew file mode 100644 index 0000000..39cd6c1 --- /dev/null +++ b/demos/textedit/images/mac/textjustify.png diff --git a/demos/textedit/images/mac/textleft.png b/demos/textedit/images/mac/textleft.png Binary files differnew file mode 100644 index 0000000..83a66d5 --- /dev/null +++ b/demos/textedit/images/mac/textleft.png diff --git a/demos/textedit/images/mac/textright.png b/demos/textedit/images/mac/textright.png Binary files differnew file mode 100644 index 0000000..e7c0464 --- /dev/null +++ b/demos/textedit/images/mac/textright.png diff --git a/demos/textedit/images/mac/textunder.png b/demos/textedit/images/mac/textunder.png Binary files differnew file mode 100644 index 0000000..968bac5 --- /dev/null +++ b/demos/textedit/images/mac/textunder.png diff --git a/demos/textedit/images/mac/zoomin.png b/demos/textedit/images/mac/zoomin.png Binary files differnew file mode 100644 index 0000000..d46f5af --- /dev/null +++ b/demos/textedit/images/mac/zoomin.png diff --git a/demos/textedit/images/mac/zoomout.png b/demos/textedit/images/mac/zoomout.png Binary files differnew file mode 100644 index 0000000..4632656 --- /dev/null +++ b/demos/textedit/images/mac/zoomout.png diff --git a/demos/textedit/images/win/editcopy.png b/demos/textedit/images/win/editcopy.png Binary files differnew file mode 100644 index 0000000..1121b47 --- /dev/null +++ b/demos/textedit/images/win/editcopy.png diff --git a/demos/textedit/images/win/editcut.png b/demos/textedit/images/win/editcut.png Binary files differnew file mode 100644 index 0000000..38e55f7 --- /dev/null +++ b/demos/textedit/images/win/editcut.png diff --git a/demos/textedit/images/win/editpaste.png b/demos/textedit/images/win/editpaste.png Binary files differnew file mode 100644 index 0000000..ffab15a --- /dev/null +++ b/demos/textedit/images/win/editpaste.png diff --git a/demos/textedit/images/win/editredo.png b/demos/textedit/images/win/editredo.png Binary files differnew file mode 100644 index 0000000..9d679fe --- /dev/null +++ b/demos/textedit/images/win/editredo.png diff --git a/demos/textedit/images/win/editundo.png b/demos/textedit/images/win/editundo.png Binary files differnew file mode 100644 index 0000000..eee23d2 --- /dev/null +++ b/demos/textedit/images/win/editundo.png diff --git a/demos/textedit/images/win/exportpdf.png b/demos/textedit/images/win/exportpdf.png Binary files differnew file mode 100644 index 0000000..eef5132 --- /dev/null +++ b/demos/textedit/images/win/exportpdf.png diff --git a/demos/textedit/images/win/filenew.png b/demos/textedit/images/win/filenew.png Binary files differnew file mode 100644 index 0000000..af5d122 --- /dev/null +++ b/demos/textedit/images/win/filenew.png diff --git a/demos/textedit/images/win/fileopen.png b/demos/textedit/images/win/fileopen.png Binary files differnew file mode 100644 index 0000000..fc6f17e --- /dev/null +++ b/demos/textedit/images/win/fileopen.png diff --git a/demos/textedit/images/win/fileprint.png b/demos/textedit/images/win/fileprint.png Binary files differnew file mode 100644 index 0000000..ba7c02d --- /dev/null +++ b/demos/textedit/images/win/fileprint.png diff --git a/demos/textedit/images/win/filesave.png b/demos/textedit/images/win/filesave.png Binary files differnew file mode 100644 index 0000000..8feec99 --- /dev/null +++ b/demos/textedit/images/win/filesave.png diff --git a/demos/textedit/images/win/textbold.png b/demos/textedit/images/win/textbold.png Binary files differnew file mode 100644 index 0000000..9cbc713 --- /dev/null +++ b/demos/textedit/images/win/textbold.png diff --git a/demos/textedit/images/win/textcenter.png b/demos/textedit/images/win/textcenter.png Binary files differnew file mode 100644 index 0000000..11efb4b --- /dev/null +++ b/demos/textedit/images/win/textcenter.png diff --git a/demos/textedit/images/win/textitalic.png b/demos/textedit/images/win/textitalic.png Binary files differnew file mode 100644 index 0000000..b30ce14 --- /dev/null +++ b/demos/textedit/images/win/textitalic.png diff --git a/demos/textedit/images/win/textjustify.png b/demos/textedit/images/win/textjustify.png Binary files differnew file mode 100644 index 0000000..9de0c88 --- /dev/null +++ b/demos/textedit/images/win/textjustify.png diff --git a/demos/textedit/images/win/textleft.png b/demos/textedit/images/win/textleft.png Binary files differnew file mode 100644 index 0000000..16f80bc --- /dev/null +++ b/demos/textedit/images/win/textleft.png diff --git a/demos/textedit/images/win/textright.png b/demos/textedit/images/win/textright.png Binary files differnew file mode 100644 index 0000000..16872df --- /dev/null +++ b/demos/textedit/images/win/textright.png diff --git a/demos/textedit/images/win/textunder.png b/demos/textedit/images/win/textunder.png Binary files differnew file mode 100644 index 0000000..c72eff5 --- /dev/null +++ b/demos/textedit/images/win/textunder.png diff --git a/demos/textedit/images/win/zoomin.png b/demos/textedit/images/win/zoomin.png Binary files differnew file mode 100644 index 0000000..2e586fc --- /dev/null +++ b/demos/textedit/images/win/zoomin.png diff --git a/demos/textedit/images/win/zoomout.png b/demos/textedit/images/win/zoomout.png Binary files differnew file mode 100644 index 0000000..a736d39 --- /dev/null +++ b/demos/textedit/images/win/zoomout.png diff --git a/demos/textedit/main.cpp b/demos/textedit/main.cpp new file mode 100644 index 0000000..fa38ecb --- /dev/null +++ b/demos/textedit/main.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "textedit.h" +#include <QApplication> + +int main( int argc, char ** argv ) +{ + Q_INIT_RESOURCE(textedit); + + QApplication a( argc, argv ); + TextEdit mw; + mw.resize( 700, 800 ); + mw.show(); + return a.exec(); +} diff --git a/demos/textedit/textedit.cpp b/demos/textedit/textedit.cpp new file mode 100644 index 0000000..128cd6a --- /dev/null +++ b/demos/textedit/textedit.cpp @@ -0,0 +1,688 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "textedit.h" + +#include <QAction> +#include <QApplication> +#include <QClipboard> +#include <QColorDialog> +#include <QComboBox> +#include <QFontComboBox> +#include <QFile> +#include <QFileDialog> +#include <QFileInfo> +#include <QFontDatabase> +#include <QMenu> +#include <QMenuBar> +#include <QPrintDialog> +#include <QPrinter> +#include <QTextCodec> +#include <QTextEdit> +#include <QToolBar> +#include <QTextCursor> +#include <QTextDocumentWriter> +#include <QTextList> +#include <QtDebug> +#include <QCloseEvent> +#include <QMessageBox> +#include <QPrintPreviewDialog> + +#ifdef Q_WS_MAC +const QString rsrcPath = ":/images/mac"; +#else +const QString rsrcPath = ":/images/win"; +#endif + +TextEdit::TextEdit(QWidget *parent) + : QMainWindow(parent) +{ + setupFileActions(); + setupEditActions(); + setupTextActions(); + + { + QMenu *helpMenu = new QMenu(tr("Help"), this); + menuBar()->addMenu(helpMenu); + helpMenu->addAction(tr("About"), this, SLOT(about())); + helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt())); + } + + textEdit = new QTextEdit(this); + connect(textEdit, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)), + this, SLOT(currentCharFormatChanged(const QTextCharFormat &))); + connect(textEdit, SIGNAL(cursorPositionChanged()), + this, SLOT(cursorPositionChanged())); + + setCentralWidget(textEdit); + textEdit->setFocus(); + setCurrentFileName(QString()); + + fontChanged(textEdit->font()); + colorChanged(textEdit->textColor()); + alignmentChanged(textEdit->alignment()); + + connect(textEdit->document(), SIGNAL(modificationChanged(bool)), + actionSave, SLOT(setEnabled(bool))); + connect(textEdit->document(), SIGNAL(modificationChanged(bool)), + this, SLOT(setWindowModified(bool))); + connect(textEdit->document(), SIGNAL(undoAvailable(bool)), + actionUndo, SLOT(setEnabled(bool))); + connect(textEdit->document(), SIGNAL(redoAvailable(bool)), + actionRedo, SLOT(setEnabled(bool))); + + setWindowModified(textEdit->document()->isModified()); + actionSave->setEnabled(textEdit->document()->isModified()); + actionUndo->setEnabled(textEdit->document()->isUndoAvailable()); + actionRedo->setEnabled(textEdit->document()->isRedoAvailable()); + + connect(actionUndo, SIGNAL(triggered()), textEdit, SLOT(undo())); + connect(actionRedo, SIGNAL(triggered()), textEdit, SLOT(redo())); + + actionCut->setEnabled(false); + actionCopy->setEnabled(false); + + connect(actionCut, SIGNAL(triggered()), textEdit, SLOT(cut())); + connect(actionCopy, SIGNAL(triggered()), textEdit, SLOT(copy())); + connect(actionPaste, SIGNAL(triggered()), textEdit, SLOT(paste())); + + connect(textEdit, SIGNAL(copyAvailable(bool)), actionCut, SLOT(setEnabled(bool))); + connect(textEdit, SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool))); + + connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged())); + + QString initialFile = ":/example.html"; + const QStringList args = QCoreApplication::arguments(); + if (args.count() == 2) + initialFile = args.at(1); + + if (!load(initialFile)) + fileNew(); +} + +void TextEdit::closeEvent(QCloseEvent *e) +{ + if (maybeSave()) + e->accept(); + else + e->ignore(); +} + +void TextEdit::setupFileActions() +{ + QToolBar *tb = new QToolBar(this); + tb->setWindowTitle(tr("File Actions")); + addToolBar(tb); + + QMenu *menu = new QMenu(tr("&File"), this); + menuBar()->addMenu(menu); + + QAction *a; + + a = new QAction(QIcon(rsrcPath + "/filenew.png"), tr("&New"), this); + a->setShortcut(QKeySequence::New); + connect(a, SIGNAL(triggered()), this, SLOT(fileNew())); + tb->addAction(a); + menu->addAction(a); + + a = new QAction(QIcon(rsrcPath + "/fileopen.png"), tr("&Open..."), this); + a->setShortcut(QKeySequence::Open); + connect(a, SIGNAL(triggered()), this, SLOT(fileOpen())); + tb->addAction(a); + menu->addAction(a); + + menu->addSeparator(); + + actionSave = a = new QAction(QIcon(rsrcPath + "/filesave.png"), tr("&Save"), this); + a->setShortcut(QKeySequence::Save); + connect(a, SIGNAL(triggered()), this, SLOT(fileSave())); + a->setEnabled(false); + tb->addAction(a); + menu->addAction(a); + + a = new QAction(tr("Save &As..."), this); + connect(a, SIGNAL(triggered()), this, SLOT(fileSaveAs())); + menu->addAction(a); + menu->addSeparator(); + +#ifndef QT_NO_PRINTER + a = new QAction(QIcon(rsrcPath + "/fileprint.png"), tr("&Print..."), this); + a->setShortcut(QKeySequence::Print); + connect(a, SIGNAL(triggered()), this, SLOT(filePrint())); + tb->addAction(a); + menu->addAction(a); + + a = new QAction(QIcon(rsrcPath + "/fileprint.png"), tr("Print Preview..."), this); + connect(a, SIGNAL(triggered()), this, SLOT(filePrintPreview())); + menu->addAction(a); + + a = new QAction(QIcon(rsrcPath + "/exportpdf.png"), tr("&Export PDF..."), this); + a->setShortcut(Qt::CTRL + Qt::Key_D); + connect(a, SIGNAL(triggered()), this, SLOT(filePrintPdf())); + tb->addAction(a); + menu->addAction(a); + + menu->addSeparator(); +#endif + + a = new QAction(tr("&Quit"), this); + a->setShortcut(Qt::CTRL + Qt::Key_Q); + connect(a, SIGNAL(triggered()), this, SLOT(close())); + menu->addAction(a); +} + +void TextEdit::setupEditActions() +{ + QToolBar *tb = new QToolBar(this); + tb->setWindowTitle(tr("Edit Actions")); + addToolBar(tb); + + QMenu *menu = new QMenu(tr("&Edit"), this); + menuBar()->addMenu(menu); + + QAction *a; + a = actionUndo = new QAction(QIcon(rsrcPath + "/editundo.png"), tr("&Undo"), this); + a->setShortcut(QKeySequence::Undo); + tb->addAction(a); + menu->addAction(a); + a = actionRedo = new QAction(QIcon(rsrcPath + "/editredo.png"), tr("&Redo"), this); + a->setShortcut(QKeySequence::Redo); + tb->addAction(a); + menu->addAction(a); + menu->addSeparator(); + a = actionCut = new QAction(QIcon(rsrcPath + "/editcut.png"), tr("Cu&t"), this); + a->setShortcut(QKeySequence::Cut); + tb->addAction(a); + menu->addAction(a); + a = actionCopy = new QAction(QIcon(rsrcPath + "/editcopy.png"), tr("&Copy"), this); + a->setShortcut(QKeySequence::Copy); + tb->addAction(a); + menu->addAction(a); + a = actionPaste = new QAction(QIcon(rsrcPath + "/editpaste.png"), tr("&Paste"), this); + a->setShortcut(QKeySequence::Paste); + tb->addAction(a); + menu->addAction(a); + actionPaste->setEnabled(!QApplication::clipboard()->text().isEmpty()); +} + +void TextEdit::setupTextActions() +{ + QToolBar *tb = new QToolBar(this); + tb->setWindowTitle(tr("Format Actions")); + addToolBar(tb); + + QMenu *menu = new QMenu(tr("F&ormat"), this); + menuBar()->addMenu(menu); + + actionTextBold = new QAction(QIcon(rsrcPath + "/textbold.png"), tr("&Bold"), this); + actionTextBold->setShortcut(Qt::CTRL + Qt::Key_B); + QFont bold; + bold.setBold(true); + actionTextBold->setFont(bold); + connect(actionTextBold, SIGNAL(triggered()), this, SLOT(textBold())); + tb->addAction(actionTextBold); + menu->addAction(actionTextBold); + actionTextBold->setCheckable(true); + + actionTextItalic = new QAction(QIcon(rsrcPath + "/textitalic.png"), tr("&Italic"), this); + actionTextItalic->setShortcut(Qt::CTRL + Qt::Key_I); + QFont italic; + italic.setItalic(true); + actionTextItalic->setFont(italic); + connect(actionTextItalic, SIGNAL(triggered()), this, SLOT(textItalic())); + tb->addAction(actionTextItalic); + menu->addAction(actionTextItalic); + actionTextItalic->setCheckable(true); + + actionTextUnderline = new QAction(QIcon(rsrcPath + "/textunder.png"), tr("&Underline"), this); + actionTextUnderline->setShortcut(Qt::CTRL + Qt::Key_U); + QFont underline; + underline.setUnderline(true); + actionTextUnderline->setFont(underline); + connect(actionTextUnderline, SIGNAL(triggered()), this, SLOT(textUnderline())); + tb->addAction(actionTextUnderline); + menu->addAction(actionTextUnderline); + actionTextUnderline->setCheckable(true); + + menu->addSeparator(); + + QActionGroup *grp = new QActionGroup(this); + connect(grp, SIGNAL(triggered(QAction *)), this, SLOT(textAlign(QAction *))); + + // Make sure the alignLeft is always left of the alignRight + if (QApplication::isLeftToRight()) { + actionAlignLeft = new QAction(QIcon(rsrcPath + "/textleft.png"), tr("&Left"), grp); + actionAlignCenter = new QAction(QIcon(rsrcPath + "/textcenter.png"), tr("C&enter"), grp); + actionAlignRight = new QAction(QIcon(rsrcPath + "/textright.png"), tr("&Right"), grp); + } else { + actionAlignRight = new QAction(QIcon(rsrcPath + "/textright.png"), tr("&Right"), grp); + actionAlignCenter = new QAction(QIcon(rsrcPath + "/textcenter.png"), tr("C&enter"), grp); + actionAlignLeft = new QAction(QIcon(rsrcPath + "/textleft.png"), tr("&Left"), grp); + } + actionAlignJustify = new QAction(QIcon(rsrcPath + "/textjustify.png"), tr("&Justify"), grp); + + actionAlignLeft->setShortcut(Qt::CTRL + Qt::Key_L); + actionAlignLeft->setCheckable(true); + actionAlignCenter->setShortcut(Qt::CTRL + Qt::Key_E); + actionAlignCenter->setCheckable(true); + actionAlignRight->setShortcut(Qt::CTRL + Qt::Key_R); + actionAlignRight->setCheckable(true); + actionAlignJustify->setShortcut(Qt::CTRL + Qt::Key_J); + actionAlignJustify->setCheckable(true); + + tb->addActions(grp->actions()); + menu->addActions(grp->actions()); + + menu->addSeparator(); + + QPixmap pix(16, 16); + pix.fill(Qt::black); + actionTextColor = new QAction(pix, tr("&Color..."), this); + connect(actionTextColor, SIGNAL(triggered()), this, SLOT(textColor())); + tb->addAction(actionTextColor); + menu->addAction(actionTextColor); + + + tb = new QToolBar(this); + tb->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea); + tb->setWindowTitle(tr("Format Actions")); + addToolBarBreak(Qt::TopToolBarArea); + addToolBar(tb); + + comboStyle = new QComboBox(tb); + tb->addWidget(comboStyle); + comboStyle->addItem("Standard"); + comboStyle->addItem("Bullet List (Disc)"); + comboStyle->addItem("Bullet List (Circle)"); + comboStyle->addItem("Bullet List (Square)"); + comboStyle->addItem("Ordered List (Decimal)"); + comboStyle->addItem("Ordered List (Alpha lower)"); + comboStyle->addItem("Ordered List (Alpha upper)"); + connect(comboStyle, SIGNAL(activated(int)), + this, SLOT(textStyle(int))); + + comboFont = new QFontComboBox(tb); + tb->addWidget(comboFont); + connect(comboFont, SIGNAL(activated(const QString &)), + this, SLOT(textFamily(const QString &))); + + comboSize = new QComboBox(tb); + comboSize->setObjectName("comboSize"); + tb->addWidget(comboSize); + comboSize->setEditable(true); + + QFontDatabase db; + foreach(int size, db.standardSizes()) + comboSize->addItem(QString::number(size)); + + connect(comboSize, SIGNAL(activated(const QString &)), + this, SLOT(textSize(const QString &))); + comboSize->setCurrentIndex(comboSize->findText(QString::number(QApplication::font() + .pointSize()))); +} + +bool TextEdit::load(const QString &f) +{ + if (!QFile::exists(f)) + return false; + QFile file(f); + if (!file.open(QFile::ReadOnly)) + return false; + + QByteArray data = file.readAll(); + QTextCodec *codec = Qt::codecForHtml(data); + QString str = codec->toUnicode(data); + if (Qt::mightBeRichText(str)) { + textEdit->setHtml(str); + } else { + str = QString::fromLocal8Bit(data); + textEdit->setPlainText(str); + } + + setCurrentFileName(f); + return true; +} + +bool TextEdit::maybeSave() +{ + if (!textEdit->document()->isModified()) + return true; + if (fileName.startsWith(QLatin1String(":/"))) + return true; + QMessageBox::StandardButton ret; + ret = QMessageBox::warning(this, tr("Application"), + tr("The document has been modified.\n" + "Do you want to save your changes?"), + QMessageBox::Save | QMessageBox::Discard + | QMessageBox::Cancel); + if (ret == QMessageBox::Save) + return fileSave(); + else if (ret == QMessageBox::Cancel) + return false; + return true; +} + +void TextEdit::setCurrentFileName(const QString &fileName) +{ + this->fileName = fileName; + textEdit->document()->setModified(false); + + QString shownName; + if (fileName.isEmpty()) + shownName = "untitled.txt"; + else + shownName = QFileInfo(fileName).fileName(); + + setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(tr("Rich Text"))); + setWindowModified(false); +} + +void TextEdit::fileNew() +{ + if (maybeSave()) { + textEdit->clear(); + setCurrentFileName(QString()); + } +} + +void TextEdit::fileOpen() +{ + QString fn = QFileDialog::getOpenFileName(this, tr("Open File..."), + QString(), tr("HTML-Files (*.htm *.html);;All Files (*)")); + if (!fn.isEmpty()) + load(fn); +} + +bool TextEdit::fileSave() +{ + if (fileName.isEmpty()) + return fileSaveAs(); + + QTextDocumentWriter writer(fileName); + bool success = writer.write(textEdit->document()); + if (success) + textEdit->document()->setModified(false); + return success; +} + +bool TextEdit::fileSaveAs() +{ + QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."), + QString(), tr("ODF files (*.odt);;HTML-Files (*.htm *.html);;All Files (*)")); + if (fn.isEmpty()) + return false; + if (! (fn.endsWith(".odt", Qt::CaseInsensitive) || fn.endsWith(".htm", Qt::CaseInsensitive) || fn.endsWith(".html", Qt::CaseInsensitive)) ) + fn += ".odt"; // default + setCurrentFileName(fn); + return fileSave(); +} + +void TextEdit::filePrint() +{ +#ifndef QT_NO_PRINTER + QPrinter printer(QPrinter::HighResolution); + QPrintDialog *dlg = new QPrintDialog(&printer, this); + if (textEdit->textCursor().hasSelection()) + dlg->addEnabledOption(QAbstractPrintDialog::PrintSelection); + dlg->setWindowTitle(tr("Print Document")); + if (dlg->exec() == QDialog::Accepted) { + textEdit->print(&printer); + } + delete dlg; +#endif +} + +void TextEdit::filePrintPreview() +{ +#ifndef QT_NO_PRINTER + QPrinter printer(QPrinter::HighResolution); + QPrintPreviewDialog preview(&printer, this); + connect(&preview, SIGNAL(paintRequested(QPrinter *)), SLOT(printPreview(QPrinter *))); + preview.exec(); +#endif +} + +void TextEdit::printPreview(QPrinter *printer) +{ +#ifdef QT_NO_PRINTER + Q_UNUSED(printer); +#else + textEdit->print(printer); +#endif +} + + +void TextEdit::filePrintPdf() +{ +#ifndef QT_NO_PRINTER +//! [0] + QString fileName = QFileDialog::getSaveFileName(this, "Export PDF", + QString(), "*.pdf"); + if (!fileName.isEmpty()) { + if (QFileInfo(fileName).suffix().isEmpty()) + fileName.append(".pdf"); + QPrinter printer(QPrinter::HighResolution); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setOutputFileName(fileName); + textEdit->document()->print(&printer); + } +//! [0] +#endif +} + +void TextEdit::textBold() +{ + QTextCharFormat fmt; + fmt.setFontWeight(actionTextBold->isChecked() ? QFont::Bold : QFont::Normal); + mergeFormatOnWordOrSelection(fmt); +} + +void TextEdit::textUnderline() +{ + QTextCharFormat fmt; + fmt.setFontUnderline(actionTextUnderline->isChecked()); + mergeFormatOnWordOrSelection(fmt); +} + +void TextEdit::textItalic() +{ + QTextCharFormat fmt; + fmt.setFontItalic(actionTextItalic->isChecked()); + mergeFormatOnWordOrSelection(fmt); +} + +void TextEdit::textFamily(const QString &f) +{ + QTextCharFormat fmt; + fmt.setFontFamily(f); + mergeFormatOnWordOrSelection(fmt); +} + +void TextEdit::textSize(const QString &p) +{ + qreal pointSize = p.toFloat(); + if (p.toFloat() > 0) { + QTextCharFormat fmt; + fmt.setFontPointSize(pointSize); + mergeFormatOnWordOrSelection(fmt); + } +} + +void TextEdit::textStyle(int styleIndex) +{ + QTextCursor cursor = textEdit->textCursor(); + + if (styleIndex != 0) { + QTextListFormat::Style style = QTextListFormat::ListDisc; + + switch (styleIndex) { + default: + case 1: + style = QTextListFormat::ListDisc; + break; + case 2: + style = QTextListFormat::ListCircle; + break; + case 3: + style = QTextListFormat::ListSquare; + break; + case 4: + style = QTextListFormat::ListDecimal; + break; + case 5: + style = QTextListFormat::ListLowerAlpha; + break; + case 6: + style = QTextListFormat::ListUpperAlpha; + break; + } + + cursor.beginEditBlock(); + + QTextBlockFormat blockFmt = cursor.blockFormat(); + + QTextListFormat listFmt; + + if (cursor.currentList()) { + listFmt = cursor.currentList()->format(); + } else { + listFmt.setIndent(blockFmt.indent() + 1); + blockFmt.setIndent(0); + cursor.setBlockFormat(blockFmt); + } + + listFmt.setStyle(style); + + cursor.createList(listFmt); + + cursor.endEditBlock(); + } else { + // #### + QTextBlockFormat bfmt; + bfmt.setObjectIndex(-1); + cursor.mergeBlockFormat(bfmt); + } +} + +void TextEdit::textColor() +{ + QColor col = QColorDialog::getColor(textEdit->textColor(), this); + if (!col.isValid()) + return; + QTextCharFormat fmt; + fmt.setForeground(col); + mergeFormatOnWordOrSelection(fmt); + colorChanged(col); +} + +void TextEdit::textAlign(QAction *a) +{ + if (a == actionAlignLeft) + textEdit->setAlignment(Qt::AlignLeft | Qt::AlignAbsolute); + else if (a == actionAlignCenter) + textEdit->setAlignment(Qt::AlignHCenter); + else if (a == actionAlignRight) + textEdit->setAlignment(Qt::AlignRight | Qt::AlignAbsolute); + else if (a == actionAlignJustify) + textEdit->setAlignment(Qt::AlignJustify); +} + +void TextEdit::currentCharFormatChanged(const QTextCharFormat &format) +{ + fontChanged(format.font()); + colorChanged(format.foreground().color()); +} + +void TextEdit::cursorPositionChanged() +{ + alignmentChanged(textEdit->alignment()); +} + +void TextEdit::clipboardDataChanged() +{ + actionPaste->setEnabled(!QApplication::clipboard()->text().isEmpty()); +} + +void TextEdit::about() +{ + QMessageBox::about(this, tr("About"), tr("This example demonstrates Qt's " + "rich text editing facilities in action, providing an example " + "document for you to experiment with.")); +} + +void TextEdit::mergeFormatOnWordOrSelection(const QTextCharFormat &format) +{ + QTextCursor cursor = textEdit->textCursor(); + if (!cursor.hasSelection()) + cursor.select(QTextCursor::WordUnderCursor); + cursor.mergeCharFormat(format); + textEdit->mergeCurrentCharFormat(format); +} + +void TextEdit::fontChanged(const QFont &f) +{ + comboFont->setCurrentIndex(comboFont->findText(QFontInfo(f).family())); + comboSize->setCurrentIndex(comboSize->findText(QString::number(f.pointSize()))); + actionTextBold->setChecked(f.bold()); + actionTextItalic->setChecked(f.italic()); + actionTextUnderline->setChecked(f.underline()); +} + +void TextEdit::colorChanged(const QColor &c) +{ + QPixmap pix(16, 16); + pix.fill(c); + actionTextColor->setIcon(pix); +} + +void TextEdit::alignmentChanged(Qt::Alignment a) +{ + if (a & Qt::AlignLeft) { + actionAlignLeft->setChecked(true); + } else if (a & Qt::AlignHCenter) { + actionAlignCenter->setChecked(true); + } else if (a & Qt::AlignRight) { + actionAlignRight->setChecked(true); + } else if (a & Qt::AlignJustify) { + actionAlignJustify->setChecked(true); + } +} + diff --git a/demos/textedit/textedit.doc b/demos/textedit/textedit.doc new file mode 100644 index 0000000..53279b9 --- /dev/null +++ b/demos/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/demos/textedit/textedit.h b/demos/textedit/textedit.h new file mode 100644 index 0000000..1fb09f9 --- /dev/null +++ b/demos/textedit/textedit.h @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TEXTEDIT_H +#define TEXTEDIT_H + +#include <QMainWindow> +#include <QMap> +#include <QPointer> + +QT_FORWARD_DECLARE_CLASS(QAction) +QT_FORWARD_DECLARE_CLASS(QComboBox) +QT_FORWARD_DECLARE_CLASS(QFontComboBox) +QT_FORWARD_DECLARE_CLASS(QTextEdit) +QT_FORWARD_DECLARE_CLASS(QTextCharFormat) +QT_FORWARD_DECLARE_CLASS(QMenu) + +class TextEdit : public QMainWindow +{ + Q_OBJECT + +public: + TextEdit(QWidget *parent = 0); + +protected: + virtual void closeEvent(QCloseEvent *e); + +private: + void setupFileActions(); + void setupEditActions(); + void setupTextActions(); + bool load(const QString &f); + bool maybeSave(); + void setCurrentFileName(const QString &fileName); + +private slots: + void fileNew(); + void fileOpen(); + bool fileSave(); + bool fileSaveAs(); + void filePrint(); + void filePrintPreview(); + void filePrintPdf(); + + void textBold(); + void textUnderline(); + void textItalic(); + void textFamily(const QString &f); + void textSize(const QString &p); + void textStyle(int styleIndex); + void textColor(); + void textAlign(QAction *a); + + void currentCharFormatChanged(const QTextCharFormat &format); + void cursorPositionChanged(); + + void clipboardDataChanged(); + void about(); + void printPreview(QPrinter *); + +private: + void mergeFormatOnWordOrSelection(const QTextCharFormat &format); + void fontChanged(const QFont &f); + void colorChanged(const QColor &c); + void alignmentChanged(Qt::Alignment a); + + QAction *actionSave, + *actionTextBold, + *actionTextUnderline, + *actionTextItalic, + *actionTextColor, + *actionAlignLeft, + *actionAlignCenter, + *actionAlignRight, + *actionAlignJustify, + *actionUndo, + *actionRedo, + *actionCut, + *actionCopy, + *actionPaste; + + QComboBox *comboStyle; + QFontComboBox *comboFont; + QComboBox *comboSize; + + QToolBar *tb; + QString fileName; + QTextEdit *textEdit; +}; + +#endif diff --git a/demos/textedit/textedit.pro b/demos/textedit/textedit.pro new file mode 100644 index 0000000..1ef4256 --- /dev/null +++ b/demos/textedit/textedit.pro @@ -0,0 +1,21 @@ +TEMPLATE = app +TARGET = textedit + +CONFIG += qt warn_on + +HEADERS = textedit.h +SOURCES = textedit.cpp \ + main.cpp + +RESOURCES += textedit.qrc +build_all:!build_pass { + CONFIG -= build_all + CONFIG += release +} + +# install +target.path = $$[QT_INSTALL_DEMOS]/textedit +sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.html *.doc images +sources.path = $$[QT_INSTALL_DEMOS]/textedit +INSTALLS += target sources + diff --git a/demos/textedit/textedit.qrc b/demos/textedit/textedit.qrc new file mode 100644 index 0000000..7d6efd7 --- /dev/null +++ b/demos/textedit/textedit.qrc @@ -0,0 +1,44 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource prefix="/"> + <file>images/logo32.png</file> + <file>images/mac/editcopy.png</file> + <file>images/mac/editcut.png</file> + <file>images/mac/editpaste.png</file> + <file>images/mac/editredo.png</file> + <file>images/mac/editundo.png</file> + <file>images/mac/exportpdf.png</file> + <file>images/mac/filenew.png</file> + <file>images/mac/fileopen.png</file> + <file>images/mac/fileprint.png</file> + <file>images/mac/filesave.png</file> + <file>images/mac/textbold.png</file> + <file>images/mac/textcenter.png</file> + <file>images/mac/textitalic.png</file> + <file>images/mac/textjustify.png</file> + <file>images/mac/textleft.png</file> + <file>images/mac/textright.png</file> + <file>images/mac/textunder.png</file> + <file>images/mac/zoomin.png</file> + <file>images/mac/zoomout.png</file> + <file>images/win/editcopy.png</file> + <file>images/win/editcut.png</file> + <file>images/win/editpaste.png</file> + <file>images/win/editredo.png</file> + <file>images/win/editundo.png</file> + <file>images/win/exportpdf.png</file> + <file>images/win/filenew.png</file> + <file>images/win/fileopen.png</file> + <file>images/win/fileprint.png</file> + <file>images/win/filesave.png</file> + <file>images/win/textbold.png</file> + <file>images/win/textcenter.png</file> + <file>images/win/textitalic.png</file> + <file>images/win/textjustify.png</file> + <file>images/win/textleft.png</file> + <file>images/win/textright.png</file> + <file>images/win/textunder.png</file> + <file>images/win/zoomin.png</file> + <file>images/win/zoomout.png</file> + <file>example.html</file> +</qresource> +</RCC> |