📄 qwerty-main-cpp.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Toolkit - qwerty/main.cpp example file</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }--></style></head><body bgcolor="#ffffff"><table width="100%"><tr><td><a href="index.html"><img width="100" height="100" src="qtlogo.png"alt="Home" border="0"><img width="100"height="100" src="face.png" alt="Home" border="0"></a><td valign="top"><div align="right"><img src="dochead.png" width="472" height="27"><br><a href="classes.html"><b>Classes</b></a>- <a href="annotated.html">Annotated</a>- <a href="hierarchy.html">Tree</a>- <a href="functions.html">Functions</a>- <a href="index.html">Home</a>- <a href="topicals.html"><b>Structure</b> <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" align="center" size=32>Qte</font></a></div></table><h1 align=center>Simple HTML Browser</h1><br clear="all"> ??? <hr> Header file: <pre>/****************************************************************************** $Id: qt/examples/qwerty/qwerty.h 2.3.8 edited 2004-05-12 $**** Copyright (C) 1992-2000 Trolltech AS. 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 QWERTY_H#define QWERTY_H#include <<a href="qwidget-h.html">qwidget.h</a>>#include <<a href="qmenubar-h.html">qmenubar.h</a>>#include <<a href="qmultilineedit-h.html">qmultilineedit.h</a>>#include <<a href="qprinter-h.html">qprinter.h</a>>class Editor : public QWidget{ Q_OBJECTpublic: Editor( <a href="qwidget.html">QWidget</a> *parent=0, const char *name="qwerty" ); ~Editor(); void load( const QString& fileName, int code=-1 );public slots: void newDoc(); void load(); bool save(); void print(); void addEncoding(); void toUpper(); void toLower();protected: void resizeEvent( <a href="qresizeevent.html">QResizeEvent</a> * ); void closeEvent( <a href="qcloseevent.html">QCloseEvent</a> * );private slots: void saveAsEncoding( int ); void openAsEncoding( int ); void textChanged();private: bool saveAs( const QString& fileName, int code=-1 ); void rebuildCodecList(); <a href="qmenubar.html">QMenuBar</a> *m; <a href="qmultilineedit.html">QMultiLineEdit</a> *e;#ifndef QT_NO_PRINTER <a href="qprinter.html">QPrinter</a> printer;#endif <a href="qpopupmenu.html">QPopupMenu</a> *save_as; <a href="qpopupmenu.html">QPopupMenu</a> *open_as; bool changed;};#endif // QWERTY_H</pre> <hr> Implementation: <pre>/****************************************************************************** $Id: qt/examples/qwerty/qwerty.cpp 2.3.8 edited 2004-05-12 $**** Copyright (C) 1992-2000 Trolltech AS. 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 "qwerty.h"#include <<a href="qapplication-h.html">qapplication.h</a>>#include <<a href="qfile-h.html">qfile.h</a>>#include <<a href="qfiledialog-h.html">qfiledialog.h</a>>#include <qkeycode.h>#include <<a href="qpopupmenu-h.html">qpopupmenu.h</a>>#include <<a href="qtextstream-h.html">qtextstream.h</a>>#include <<a href="qpainter-h.html">qpainter.h</a>>#include <<a href="qmessagebox-h.html">qmessagebox.h</a>>#include <<a href="qpaintdevicemetrics-h.html">qpaintdevicemetrics.h</a>>#include <<a href="qlist-h.html">qlist.h</a>>#include <<a href="qtextcodec-h.html">qtextcodec.h</a>>const bool no_writing = FALSE;static QList<<a href="qtextcodec.html">QTextCodec</a>> *codecList = 0;enum { Uni = 0, MBug = 1, Lat1 = 2, Local = 3, Guess = 4, Codec = 5 };Editor::Editor( <a href="qwidget.html">QWidget</a> * parent , const char * name ) : <a href="qwidget.html">QWidget</a>( parent, name, WDestructiveClose ){ m = new <a href="qmenubar.html">QMenuBar</a>( this, "menu" ); <a href="qpopupmenu.html">QPopupMenu</a> * file = new <a href="qpopupmenu.html">QPopupMenu</a>(); CHECK_PTR( file ); m->insertItem( "&File", file ); file-><a href="qmenudata.html#deddb9">insertItem</a>( "&New", this, SLOT(<a href=#2>newDoc</a>()), ALT+Key_N ); file-><a href="qmenudata.html#deddb9">insertItem</a>( "&Open", this, SLOT(<a href=#4>load</a>()), ALT+Key_O ); file-><a href="qmenudata.html#deddb9">insertItem</a>( "&Save", this, SLOT(<a href=#6>save</a>()), ALT+Key_S ); file-><a href="qmenudata.html#e34b79">insertSeparator</a>(); open_as = new <a href="qpopupmenu.html">QPopupMenu</a>(); file-><a href="qmenudata.html#deddb9">insertItem</a>( "Open &as", open_as ); save_as = new <a href="qpopupmenu.html">QPopupMenu</a>(); file-><a href="qmenudata.html#deddb9">insertItem</a>( "Save &as", save_as ); file-><a href="qmenudata.html#deddb9">insertItem</a>( "Add &encoding", this, SLOT(<a href=#8>addEncoding</a>()) );#ifndef QT_NO_PRINTER file-><a href="qmenudata.html#e34b79">insertSeparator</a>(); file-><a href="qmenudata.html#deddb9">insertItem</a>( "&Print", this, SLOT(<a href=#10>print</a>()), ALT+Key_P );#endif file-><a href="qmenudata.html#e34b79">insertSeparator</a>(); file-><a href="qmenudata.html#deddb9">insertItem</a>( "&Close", this, SLOT(<a href="qwidget.html#3d9c87">close</a>()),ALT+Key_W ); file-><a href="qmenudata.html#deddb9">insertItem</a>( "&Quit", qApp, SLOT(closeAllWindows()), ALT+Key_Q ); <a href="qobject.html#fbde73">connect</a>( save_as, SIGNAL(activated(int)), this, SLOT(<a href=#7>saveAsEncoding</a>(int)) ); <a href="qobject.html#fbde73">connect</a>( open_as, SIGNAL(activated(int)), this, SLOT(<a href=#5>openAsEncoding</a>(int)) ); <a href=#1>rebuildCodecList</a>(); <a href="qpopupmenu.html">QPopupMenu</a> * edit = new <a href="qpopupmenu.html">QPopupMenu</a>(); CHECK_PTR( edit ); m->insertItem( "&Edit", edit ); edit-><a href="qmenudata.html#deddb9">insertItem</a>( "To &uppercase", this, SLOT(<a href=#13>toUpper</a>()), ALT+Key_U ); edit-><a href="qmenudata.html#deddb9">insertItem</a>( "To &lowercase", this, SLOT(<a href=#14>toLower</a>()), ALT+Key_L ); changed = FALSE; e = new <a href="qmultilineedit.html">QMultiLineEdit</a>( this, "editor" ); <a href="qobject.html#fbde73">connect</a>( e, SIGNAL( <a href=#15>textChanged</a>() ), this, SLOT( <a href=#15>textChanged</a>() ) ); // We use Unifont - if you have it installed you'll see all // Unicode character glyphs. // // Unifont only comes in one pixel size, so we cannot let // it change pixel size as the display DPI changes. // <a href="qfont.html">QFont</a> unifont("unifont",16,50); unifont.<a href="qfont.html#9d3b04">setPixelSize</a>(16); e->setFont( unifont ); e->setFocus();}Editor::~Editor(){}void <a name="1"></a>Editor::rebuildCodecList(){ delete codecList; codecList = new <a href="qlist.html">QList</a><<a href="qtextcodec.html">QTextCodec</a>>; <a href="qtextcodec.html">QTextCodec</a> *codec; int i; for (i = 0; (codec = QTextCodec::codecForIndex(i)); i++) codecList->append( codec ); int n = codecList->count(); for (int pm=0; pm<2; pm++) { <a href="qpopupmenu.html">QPopupMenu</a>* menu = pm ? open_as : save_as; menu-><a href="qmenudata.html#4bd5e3">clear</a>(); <a href="qstring.html">QString</a> local = "Local ("; local += QTextCodec::codecForLocale()->name(); local += ")"; menu-><a href="qmenudata.html#deddb9">insertItem</a>( local, Local ); menu-><a href="qmenudata.html#deddb9">insertItem</a>( "Unicode", Uni ); menu-><a href="qmenudata.html#deddb9">insertItem</a>( "Latin1", Lat1 ); menu-><a href="qmenudata.html#deddb9">insertItem</a>( "Microsoft Unicode", MBug ); if ( pm ) menu-><a href="qmenudata.html#deddb9">insertItem</a>( "[guess]", Guess ); for ( i = 0; i < n; i++ ) menu-><a href="qmenudata.html#deddb9">insertItem</a>( codecList->at(i)->name(), Codec + i ); }}void <a name="2"></a>Editor::newDoc(){ Editor *ed = new Editor; if ( qApp->desktop()->size().width() < 450 || qApp->desktop()->size().height() < 450 ) { ed-><a href="qwidget.html#b6e000">showMaximized</a>(); } else { ed-><a href="qwidget.html#8fcbbe">resize</a>( 400, 400 ); ed-><a href="qwidget.html#200ee5">show</a>(); }}void <a name="4"></a>Editor::load(){#ifndef QT_NO_FILEDIALOG <a href="qstring.html">QString</a> fn = QFileDialog::getOpenFileName( QString::null, QString::null, this ); if ( !fn.<a href="qstring.html#c62623">isEmpty</a>() ) <a href=#4>load</a>( fn, -1 );#endif }void <a name="4"></a>Editor::load( const QString& fileName, int code ){ <a href="qfile.html">QFile</a> f( fileName ); if ( !f.<a href="qfile.html#255995">open</a>( IO_ReadOnly ) ) return; e->setAutoUpdate( FALSE ); <a href="qtextstream.html">QTextStream</a> t(&f);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -