diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-07-10 15:24:15 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-07-10 15:24:15 -0500 |
commit | bd0f3345a938b35ce6a12f6150373b0955b8dd12 (patch) | |
tree | 7a520322212d48ebcb9fbe1087e7fca28b76185c /tools/designer/examples/richedit | |
download | qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.tar.gz qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.zip |
Add Qt3 development HEAD version
Diffstat (limited to 'tools/designer/examples/richedit')
18 files changed, 767 insertions, 0 deletions
diff --git a/tools/designer/examples/richedit/images/editcopy.png b/tools/designer/examples/richedit/images/editcopy.png Binary files differnew file mode 100644 index 0000000..abfe86e --- /dev/null +++ b/tools/designer/examples/richedit/images/editcopy.png diff --git a/tools/designer/examples/richedit/images/editcut.png b/tools/designer/examples/richedit/images/editcut.png Binary files differnew file mode 100644 index 0000000..2d179bc --- /dev/null +++ b/tools/designer/examples/richedit/images/editcut.png diff --git a/tools/designer/examples/richedit/images/editpaste.png b/tools/designer/examples/richedit/images/editpaste.png Binary files differnew file mode 100644 index 0000000..356ee55 --- /dev/null +++ b/tools/designer/examples/richedit/images/editpaste.png diff --git a/tools/designer/examples/richedit/images/filenew.png b/tools/designer/examples/richedit/images/filenew.png Binary files differnew file mode 100644 index 0000000..9853d97 --- /dev/null +++ b/tools/designer/examples/richedit/images/filenew.png diff --git a/tools/designer/examples/richedit/images/fileopen.png b/tools/designer/examples/richedit/images/fileopen.png Binary files differnew file mode 100644 index 0000000..85dab43 --- /dev/null +++ b/tools/designer/examples/richedit/images/fileopen.png diff --git a/tools/designer/examples/richedit/images/filesave.png b/tools/designer/examples/richedit/images/filesave.png Binary files differnew file mode 100644 index 0000000..21309aa --- /dev/null +++ b/tools/designer/examples/richedit/images/filesave.png diff --git a/tools/designer/examples/richedit/images/redo.png b/tools/designer/examples/richedit/images/redo.png Binary files differnew file mode 100644 index 0000000..857d093 --- /dev/null +++ b/tools/designer/examples/richedit/images/redo.png diff --git a/tools/designer/examples/richedit/images/textbold.png b/tools/designer/examples/richedit/images/textbold.png Binary files differnew file mode 100644 index 0000000..c51e5c0 --- /dev/null +++ b/tools/designer/examples/richedit/images/textbold.png diff --git a/tools/designer/examples/richedit/images/textcenter.png b/tools/designer/examples/richedit/images/textcenter.png Binary files differnew file mode 100644 index 0000000..032a9bb --- /dev/null +++ b/tools/designer/examples/richedit/images/textcenter.png diff --git a/tools/designer/examples/richedit/images/textitalic.png b/tools/designer/examples/richedit/images/textitalic.png Binary files differnew file mode 100644 index 0000000..b725b43 --- /dev/null +++ b/tools/designer/examples/richedit/images/textitalic.png diff --git a/tools/designer/examples/richedit/images/textleft.png b/tools/designer/examples/richedit/images/textleft.png Binary files differnew file mode 100644 index 0000000..4ef081f --- /dev/null +++ b/tools/designer/examples/richedit/images/textleft.png diff --git a/tools/designer/examples/richedit/images/textright.png b/tools/designer/examples/richedit/images/textright.png Binary files differnew file mode 100644 index 0000000..a9b2b55 --- /dev/null +++ b/tools/designer/examples/richedit/images/textright.png diff --git a/tools/designer/examples/richedit/images/textunder.png b/tools/designer/examples/richedit/images/textunder.png Binary files differnew file mode 100644 index 0000000..5093509 --- /dev/null +++ b/tools/designer/examples/richedit/images/textunder.png diff --git a/tools/designer/examples/richedit/images/undo.png b/tools/designer/examples/richedit/images/undo.png Binary files differnew file mode 100644 index 0000000..9346c6c --- /dev/null +++ b/tools/designer/examples/richedit/images/undo.png diff --git a/tools/designer/examples/richedit/main.cpp b/tools/designer/examples/richedit/main.cpp new file mode 100644 index 0000000..a5a0d6d --- /dev/null +++ b/tools/designer/examples/richedit/main.cpp @@ -0,0 +1,25 @@ +/**************************************************************************** +** +** 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 <qapplication.h> +#include "richedit.h" + + +int main( int argc, char *argv[] ) +{ + QApplication app( argc, argv ); + + EditorForm richeditForm; + app.setMainWidget( &richeditForm ); + richeditForm.show(); + + return app.exec(); +} + + diff --git a/tools/designer/examples/richedit/richedit.pro b/tools/designer/examples/richedit/richedit.pro new file mode 100644 index 0000000..bcc3d4d --- /dev/null +++ b/tools/designer/examples/richedit/richedit.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = richedit +LANGUAGE = C++ + +CONFIG += qt warn_on release +SOURCES += main.cpp +IMAGEFILE = images.cpp +FORMS = richedit.ui +IMAGES = images/editcopy.png images/editcut.png images/editpaste.png images/filenew.png images/fileopen.png images/filesave.png images/redo.png images/textbold.png images/textcenter.png images/textitalic.png images/textleft.png images/textright.png images/textunder.png images/undo.png +DBFILE = richedit.db diff --git a/tools/designer/examples/richedit/richedit.ui b/tools/designer/examples/richedit/richedit.ui new file mode 100644 index 0000000..2ae033f --- /dev/null +++ b/tools/designer/examples/richedit/richedit.ui @@ -0,0 +1,612 @@ +<!DOCTYPE UI><UI version="3.0" stdsetdef="1"> +<class>EditorForm</class> +<include location="global" impldecl="in implementation">qfile.h</include> +<include location="global" impldecl="in implementation">qfontdatabase.h</include> +<include location="global" impldecl="in implementation">qmessagebox.h</include> +<include location="global" impldecl="in implementation">qapplication.h</include> +<include location="global" impldecl="in implementation">qfiledialog.h</include> +<include location="global" impldecl="in implementation">qtextstream.h</include> +<include location="local" implDecl="in declaration">richedit.ui.h</include> +<variable>QString fileName;</variable> +<pixmapinproject/> +<layoutdefaults spacing="6" margin="11"/> +<widget class="QMainWindow"> + <property name="name"> + <cstring>EditorForm</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>646</width> + <height>436</height> + </rect> + </property> + <property name="caption"> + <string>Rich Edit</string> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QTextEdit"> + <property name="name"> + <cstring>textEdit</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="textFormat"> + <enum>RichText</enum> + </property> + </widget> + </hbox> +</widget> +<menubar> + <property name="name"> + <cstring>menubar</cstring> + </property> + <item text="&File" name="fileMenu"> + <action name="fileNewAction"/> + <action name="fileOpenAction"/> + <action name="fileSaveAction"/> + <action name="fileSaveAsAction"/> + <separator/> + <action name="fileExitAction"/> + </item> + <item text="&Edit" name="editMenu"> + <action name="editUndoAction"/> + <action name="editRedoAction"/> + <separator/> + <action name="editCutAction"/> + <action name="editCopyAction"/> + <action name="editPasteAction"/> + </item> + <item text="F&ormat" name="PopupMenu_2"> + <action name="leftAlignAction"/> + <action name="rightAlignAction"/> + <action name="centerAlignAction"/> + <separator/> + <action name="boldAction"/> + <action name="italicAction"/> + <action name="underlineAction"/> + </item> + <item text="&Help" name="helpMenu"> + <action name="helpContentsAction"/> + <action name="helpIndexAction"/> + <separator/> + <action name="helpAboutAction"/> + </item> +</menubar> +<toolbars> + <toolbar dock="2"> + <property name="name"> + <cstring>toolBar</cstring> + </property> + <property name="label"> + <string>Tools</string> + </property> + <action name="fileNewAction"/> + <action name="fileOpenAction"/> + <action name="fileSaveAction"/> + <separator/> + <action name="editUndoAction"/> + <action name="editRedoAction"/> + <action name="editCutAction"/> + <action name="editCopyAction"/> + <action name="editPasteAction"/> + </toolbar> + <toolbar dock="2"> + <property name="name"> + <cstring>Toolbar</cstring> + </property> + <property name="label"> + <string>Toolbar</string> + </property> + <action name="leftAlignAction"/> + <action name="centerAlignAction"/> + <action name="rightAlignAction"/> + <separator/> + <action name="boldAction"/> + <action name="italicAction"/> + <action name="underlineAction"/> + <separator/> + <widget class="QComboBox"> + <property name="name"> + <cstring>fontComboBox</cstring> + </property> + </widget> + <widget class="QSpinBox"> + <property name="name"> + <cstring>SpinBox2</cstring> + </property> + <property name="minValue"> + <number>6</number> + </property> + <property name="value"> + <number>10</number> + </property> + </widget> + </toolbar> +</toolbars> +<actions> + <action> + <property name="name"> + <cstring>fileNewAction</cstring> + </property> + <property name="iconSet"> + <iconset>filenew.png</iconset> + </property> + <property name="text"> + <string>New</string> + </property> + <property name="menuText"> + <string>&New</string> + </property> + <property name="accel"> + <number>4194382</number> + </property> + </action> + <action> + <property name="name"> + <cstring>fileOpenAction</cstring> + </property> + <property name="iconSet"> + <iconset>fileopen.png</iconset> + </property> + <property name="text"> + <string>Open</string> + </property> + <property name="menuText"> + <string>&Open...</string> + </property> + <property name="accel"> + <number>4194383</number> + </property> + </action> + <action> + <property name="name"> + <cstring>fileSaveAction</cstring> + </property> + <property name="iconSet"> + <iconset>filesave.png</iconset> + </property> + <property name="text"> + <string>Save</string> + </property> + <property name="menuText"> + <string>&Save</string> + </property> + <property name="accel"> + <number>4194387</number> + </property> + </action> + <action> + <property name="name"> + <cstring>fileSaveAsAction</cstring> + </property> + <property name="text"> + <string>Save As</string> + </property> + <property name="menuText"> + <string>Save &As...</string> + </property> + <property name="accel"> + <number>0</number> + </property> + </action> + <action> + <property name="name"> + <cstring>fileExitAction</cstring> + </property> + <property name="text"> + <string>Exit</string> + </property> + <property name="menuText"> + <string>E&xit</string> + </property> + <property name="accel"> + <number>0</number> + </property> + </action> + <action> + <property name="name"> + <cstring>editUndoAction</cstring> + </property> + <property name="iconSet"> + <iconset>undo.png</iconset> + </property> + <property name="text"> + <string>Undo</string> + </property> + <property name="menuText"> + <string>&Undo</string> + </property> + <property name="accel"> + <number>4194394</number> + </property> + </action> + <action> + <property name="name"> + <cstring>editRedoAction</cstring> + </property> + <property name="iconSet"> + <iconset>redo.png</iconset> + </property> + <property name="text"> + <string>Redo</string> + </property> + <property name="menuText"> + <string>&Redo</string> + </property> + <property name="accel"> + <number>4194393</number> + </property> + </action> + <action> + <property name="name"> + <cstring>editCutAction</cstring> + </property> + <property name="iconSet"> + <iconset>editcut.png</iconset> + </property> + <property name="text"> + <string>Cut</string> + </property> + <property name="menuText"> + <string>&Cut</string> + </property> + <property name="accel"> + <number>4194392</number> + </property> + </action> + <action> + <property name="name"> + <cstring>editCopyAction</cstring> + </property> + <property name="iconSet"> + <iconset>editcopy.png</iconset> + </property> + <property name="text"> + <string>Copy</string> + </property> + <property name="menuText"> + <string>C&opy</string> + </property> + <property name="accel"> + <number>4194371</number> + </property> + </action> + <action> + <property name="name"> + <cstring>editPasteAction</cstring> + </property> + <property name="iconSet"> + <iconset>editpaste.png</iconset> + </property> + <property name="text"> + <string>Paste</string> + </property> + <property name="menuText"> + <string>&Paste</string> + </property> + <property name="accel"> + <number>4194390</number> + </property> + </action> + <action> + <property name="name"> + <cstring>helpContentsAction</cstring> + </property> + <property name="text"> + <string>Contents</string> + </property> + <property name="menuText"> + <string>&Contents...</string> + </property> + <property name="accel"> + <number>0</number> + </property> + </action> + <action> + <property name="name"> + <cstring>helpIndexAction</cstring> + </property> + <property name="text"> + <string>Index</string> + </property> + <property name="menuText"> + <string>&Index...</string> + </property> + <property name="accel"> + <number>0</number> + </property> + </action> + <action> + <property name="name"> + <cstring>helpAboutAction</cstring> + </property> + <property name="text"> + <string>About</string> + </property> + <property name="menuText"> + <string>&About</string> + </property> + <property name="accel"> + <number>0</number> + </property> + </action> + <action> + <property name="name"> + <cstring>boldAction</cstring> + </property> + <property name="toggleAction"> + <bool>true</bool> + </property> + <property name="iconSet"> + <iconset>textbold.png</iconset> + </property> + <property name="text"> + <string>bold</string> + </property> + <property name="menuText"> + <string>&Bold</string> + </property> + <property name="accel"> + <number>272629826</number> + </property> + </action> + <action> + <property name="name"> + <cstring>italicAction</cstring> + </property> + <property name="toggleAction"> + <bool>true</bool> + </property> + <property name="iconSet"> + <iconset>textitalic.png</iconset> + </property> + <property name="text"> + <string>italic</string> + </property> + <property name="menuText"> + <string>&Italic</string> + </property> + <property name="accel"> + <number>272629833</number> + </property> + </action> + <action> + <property name="name"> + <cstring>underlineAction</cstring> + </property> + <property name="toggleAction"> + <bool>true</bool> + </property> + <property name="iconSet"> + <iconset>textunder.png</iconset> + </property> + <property name="text"> + <string>underline</string> + </property> + <property name="menuText"> + <string>&Underline</string> + </property> + <property name="accel"> + <number>272629845</number> + </property> + </action> + <actiongroup> + <property name="name"> + <cstring>alignActionGroup</cstring> + </property> + <property name="text"> + <string>align</string> + </property> + <property name="usesDropDown"> + <bool>false</bool> + </property> + <action> + <property name="name"> + <cstring>leftAlignAction</cstring> + </property> + <property name="toggleAction"> + <bool>true</bool> + </property> + <property name="iconSet"> + <iconset>textleft.png</iconset> + </property> + <property name="text"> + <string>left</string> + </property> + <property name="menuText"> + <string>&Left</string> + </property> + <property name="accel"> + <number>272629836</number> + </property> + </action> + <action> + <property name="name"> + <cstring>rightAlignAction</cstring> + </property> + <property name="toggleAction"> + <bool>true</bool> + </property> + <property name="iconSet"> + <iconset>textright.png</iconset> + </property> + <property name="text"> + <string>right</string> + </property> + <property name="menuText"> + <string>&Right</string> + </property> + <property name="accel"> + <number>272629842</number> + </property> + </action> + <action> + <property name="name"> + <cstring>centerAlignAction</cstring> + </property> + <property name="toggleAction"> + <bool>true</bool> + </property> + <property name="iconSet"> + <iconset>textcenter.png</iconset> + </property> + <property name="text"> + <string>center</string> + </property> + <property name="menuText"> + <string>&Center</string> + </property> + </action> + </actiongroup> +</actions> +<connections> + <connection language="C++"> + <sender>fileNewAction</sender> + <signal>activated()</signal> + <receiver>EditorForm</receiver> + <slot>fileNew()</slot> + </connection> + <connection language="C++"> + <sender>fileOpenAction</sender> + <signal>activated()</signal> + <receiver>EditorForm</receiver> + <slot>fileOpen()</slot> + </connection> + <connection language="C++"> + <sender>fileSaveAction</sender> + <signal>activated()</signal> + <receiver>EditorForm</receiver> + <slot>fileSave()</slot> + </connection> + <connection language="C++"> + <sender>fileSaveAsAction</sender> + <signal>activated()</signal> + <receiver>EditorForm</receiver> + <slot>fileSaveAs()</slot> + </connection> + <connection language="C++"> + <sender>fileExitAction</sender> + <signal>activated()</signal> + <receiver>EditorForm</receiver> + <slot>fileExit()</slot> + </connection> + <connection language="C++"> + <sender>helpIndexAction</sender> + <signal>activated()</signal> + <receiver>EditorForm</receiver> + <slot>helpIndex()</slot> + </connection> + <connection language="C++"> + <sender>helpContentsAction</sender> + <signal>activated()</signal> + <receiver>EditorForm</receiver> + <slot>helpContents()</slot> + </connection> + <connection language="C++"> + <sender>helpAboutAction</sender> + <signal>activated()</signal> + <receiver>EditorForm</receiver> + <slot>helpAbout()</slot> + </connection> + <connection language="C++"> + <sender>SpinBox2</sender> + <signal>valueChanged(int)</signal> + <receiver>textEdit</receiver> + <slot>setPointSize(int)</slot> + </connection> + <connection language="C++"> + <sender>editCutAction</sender> + <signal>activated()</signal> + <receiver>textEdit</receiver> + <slot>cut()</slot> + </connection> + <connection language="C++"> + <sender>editPasteAction</sender> + <signal>activated()</signal> + <receiver>textEdit</receiver> + <slot>paste()</slot> + </connection> + <connection language="C++"> + <sender>editCopyAction</sender> + <signal>activated()</signal> + <receiver>textEdit</receiver> + <slot>copy()</slot> + </connection> + <connection language="C++"> + <sender>editRedoAction</sender> + <signal>activated()</signal> + <receiver>textEdit</receiver> + <slot>redo()</slot> + </connection> + <connection language="C++"> + <sender>editUndoAction</sender> + <signal>activated()</signal> + <receiver>textEdit</receiver> + <slot>undo()</slot> + </connection> + <connection language="C++"> + <sender>alignActionGroup</sender> + <signal>selected(QAction*)</signal> + <receiver>EditorForm</receiver> + <slot>changeAlignment(QAction*)</slot> + </connection> + <connection language="C++"> + <sender>underlineAction</sender> + <signal>toggled(bool)</signal> + <receiver>textEdit</receiver> + <slot>setUnderline(bool)</slot> + </connection> + <connection language="C++"> + <sender>italicAction</sender> + <signal>toggled(bool)</signal> + <receiver>textEdit</receiver> + <slot>setItalic(bool)</slot> + </connection> + <connection language="C++"> + <sender>boldAction</sender> + <signal>toggled(bool)</signal> + <receiver>textEdit</receiver> + <slot>setBold(bool)</slot> + </connection> + <connection language="C++"> + <sender>fontComboBox</sender> + <signal>activated(const QString&)</signal> + <receiver>textEdit</receiver> + <slot>setFamily(const QString&)</slot> + </connection> + <connection language="C++"> + <sender>fontComboBox</sender> + <signal>activated(const QString&)</signal> + <receiver>textEdit</receiver> + <slot>setFocus()</slot> + </connection> + <slot access="protected" specifier="virtual" language="C++" returnType="void">init()</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">fileExit()</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">fileNew()</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">fileOpen()</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">fileSave()</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">fileSaveAs()</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">helpAbout()</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">helpContents()</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">helpIndex()</slot> + <slot access="public" specifier="virtual" language="C++" returnType="void">changeAlignment( QAction * align )</slot> + <slot access="public" specifier="virtual" language="C++" returnType="int">saveAndContinue( const QString & action )</slot> +</connections> +</UI> diff --git a/tools/designer/examples/richedit/richedit.ui.h b/tools/designer/examples/richedit/richedit.ui.h new file mode 100644 index 0000000..761848e --- /dev/null +++ b/tools/designer/examples/richedit/richedit.ui.h @@ -0,0 +1,120 @@ +void EditorForm::init() +{ + textEdit->setFocus(); + + QFontDatabase fonts; + fontComboBox->insertStringList( fonts.families() ); + QString font = textEdit->family(); + font = font.lower(); + for ( int i = 0 ; i < fontComboBox->count(); i++ ) { + if ( font == fontComboBox->text( i ) ) { + fontComboBox->setCurrentItem( i ); + break; + } + } +} + +void EditorForm::fileExit() +{ + if ( saveAndContinue( "Exit" ) ) + qApp->exit(); +} + +void EditorForm::fileNew() +{ + if ( saveAndContinue( "New" ) ) + textEdit->clear(); +} + +void EditorForm::fileOpen() +{ + if ( saveAndContinue( "Open" ) ) { + QString fn( QFileDialog::getOpenFileName( + QString::null, + "Rich Text Files (*.htm*)", this ) ); + if ( !fn.isEmpty() ) { + fileName = fn; + QFile file( fileName ); + if ( file.open( IO_ReadOnly ) ) { + QTextStream ts( &file ); + textEdit->setText( ts.read() ); + } + } + } +} + +void EditorForm::fileSave() +{ + if ( fileName.isEmpty() ) { + fileSaveAs(); + } else { + QFile f( fileName ); + if ( f.open( IO_WriteOnly ) ) { + QTextStream ts( &f ); + ts << textEdit->text(); + textEdit->setModified( FALSE ); + } + } +} + +void EditorForm::fileSaveAs() +{ + QString fn = QFileDialog::getSaveFileName( + "", "Rich Text Files (*.htm*)", this ); + if ( !fn.isEmpty() ) { + fileName = fn; + fileSave(); + } +} + +void EditorForm::helpAbout() +{ + +} + +void EditorForm::helpContents() +{ + +} + +void EditorForm::helpIndex() +{ + +} + +void EditorForm::changeAlignment(QAction * align) +{ + if ( align == leftAlignAction ) + textEdit->setAlignment( Qt::AlignLeft ); + else if ( align == rightAlignAction ) + textEdit->setAlignment( Qt::AlignRight ); + else if ( align == centerAlignAction ) + textEdit->setAlignment( Qt::AlignCenter ); +} + +int EditorForm::saveAndContinue(const QString & action) +{ + int continueAction = 1; + + if ( textEdit->isModified() ) { + switch( QMessageBox::information( + this, "Rich Edit", + "The document contains unsaved changes.\n" + "Do you want to save the changes?", + "&Save", "&Don't Save", "&Cancel " + action, + 0, // Enter == button 0 + 2 ) ) { // Escape == button 2 + case 0: // Save; continue + fileSave(); + break; + case 1: // Do not save; continue + break; + case 2: // Cancel + continueAction = 0; + break; + } + } + + return continueAction; +} + |