📄 helpviewer-main-cpp.html
字号:
{ <a href="qmainwindow.html#0eb7bc">menuBar</a>()->setItemEnabled( backwardId, b);}void <a name="135"></a>HelpWindow::setForwardAvailable( bool b){ <a href="qmainwindow.html#0eb7bc">menuBar</a>()->setItemEnabled( forwardId, b);}void <a name="136"></a>HelpWindow::textChanged(){ if ( browser->documentTitle().isNull() ) { <a href="qwidget.html#d6a291">setCaption</a>( "Qt Example - Helpviewer - " + browser->context() ); selectedURL = browser->context(); } else { <a href="qwidget.html#d6a291">setCaption</a>( "Qt Example - Helpviewer - " + browser->documentTitle() ) ; selectedURL = browser->documentTitle(); } if ( !selectedURL.isEmpty() && pathCombo ) { bool exists = FALSE; int i; for ( i = 0; i < pathCombo->count(); ++i ) { if ( pathCombo->text( i ) == selectedURL ) { exists = TRUE; break; } } if ( !exists ) { pathCombo->insertItem( selectedURL, 0 ); pathCombo->setCurrentItem( 0 ); mHistory[ hist->insertItem( selectedURL ) ] = selectedURL; } else pathCombo->setCurrentItem( i ); selectedURL = QString::null; }}HelpWindow::~HelpWindow(){ history.clear(); <a href="qmap.html">QMap</a><int, QString>::Iterator it = mHistory.begin(); for ( ; it != mHistory.end(); ++it ) history.append( *it ); <a href="qfile.html">QFile</a> f( <a href="qdir.html#2ec6fd">QDir::currentDirPath</a>() + "/.history" ); f.<a href="qfile.html#255995">open</a>( IO_WriteOnly ); <a href="qdatastream.html">QDataStream</a> s( &f ); s << history; f.<a href="qfile.html#64e640">close</a>(); bookmarks.clear(); <a href="qmap.html">QMap</a><int, QString>::Iterator it2 = mBookmarks.begin(); for ( ; it2 != mBookmarks.end(); ++it2 ) bookmarks.append( *it2 ); <a href="qfile.html">QFile</a> f2( <a href="qdir.html#2ec6fd">QDir::currentDirPath</a>() + "/.bookmarks" ); f2.<a href="qfile.html#255995">open</a>( IO_WriteOnly ); <a href="qdatastream.html">QDataStream</a> s2( &f2 ); s2 << bookmarks; f2.<a href="qfile.html#64e640">close</a>();}void <a name="137"></a>HelpWindow::about(){ <a href="qmessagebox.html#f6c3cd">QMessageBox::about</a>( this, "HelpViewer Example", "<p>This example implements a simple HTML help viewer " "using Qt's rich text capabilities</p>" "<p>It's just about 100 lines of C++ code, so don't expect too much :-)</p>" );}void <a name="138"></a>HelpWindow::aboutQt(){ <a href="qmessagebox.html#b72270">QMessageBox::aboutQt</a>( this, "QBrowser" );}void <a name="139"></a>HelpWindow::openFile(){#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>() ) browser->setSource( fn );#endif}void <a name="140"></a>HelpWindow::newWindow(){ ( new HelpWindow(browser->source(), "qbrowser") )->show();}void <a name="141"></a>HelpWindow::print(){#ifndef QT_NO_PRINTER <a href="qprinter.html">QPrinter</a> printer; printer.<a href="qprinter.html#ec440a">setFullPage</a>(TRUE); if ( printer.<a href="qprinter.html#c3cd23">setup</a>() ) { <a href="qpainter.html">QPainter</a> p( &printer ); <a href="qpaintdevicemetrics.html">QPaintDeviceMetrics</a> metrics(p.<a href="qpainter.html#82920f">device</a>()); int dpix = metrics.<a href="qpaintdevicemetrics.html#a15e9e">logicalDpiX</a>(); int dpiy = metrics.<a href="qpaintdevicemetrics.html#b13b26">logicalDpiY</a>(); const int margin = 72; // pt <a href="qrect.html">QRect</a> body(margin*dpix/72, margin*dpiy/72, metrics.<a href="qpaintdevicemetrics.html#95eb7b">width</a>()-margin*dpix/72*2, metrics.<a href="qpaintdevicemetrics.html#d4fedb">height</a>()-margin*dpiy/72*2 ); <a href="qfont.html">QFont</a> font("times", 10); <a href="qsimplerichtext.html">QSimpleRichText</a> richText( browser->text(), font, browser->context(), browser->styleSheet(), browser->mimeSourceFactory(), body.<a href="qrect.html#581ab8">height</a>() ); richText.<a href="qsimplerichtext.html#6f02c2">setWidth</a>( &p, body.<a href="qrect.html#45fe95">width</a>() ); <a href="qrect.html">QRect</a> view( body ); int page = 1; for (;;) { p.<a href="qpainter.html#898839">setClipRect</a>( body ); richText.<a href="qsimplerichtext.html#4e026f">draw</a>( &p, body.<a href="qrect.html#369cab">left</a>(), body.<a href="qrect.html#4dd27e">top</a>(), view, <a href="qwidget.html#d92bf4">colorGroup</a>() ); p.<a href="qpainter.html#79ea5e">setClipping</a>( FALSE ); view.<a href="qrect.html#3de222">moveBy</a>( 0, body.<a href="qrect.html#581ab8">height</a>() ); p.<a href="qpainter.html#eb778c">translate</a>( 0 , -body.<a href="qrect.html#581ab8">height</a>() ); p.<a href="qpainter.html#998df2">setFont</a>( font ); p.<a href="qpainter.html#0f088f">drawText</a>( view.<a href="qrect.html#896e32">right</a>() - p.<a href="qpainter.html#73b2e5">fontMetrics</a>().width( <a href="qstring.html#1cd85f">QString::number</a>(page) ), view.<a href="qrect.html#2de4b0">bottom</a>() + p.<a href="qpainter.html#73b2e5">fontMetrics</a>().ascent() + 5, QString::number(page) ); if ( view.<a href="qrect.html#4dd27e">top</a>() >= richText.<a href="qsimplerichtext.html#428651">height</a>() ) break; printer.<a href="qprinter.html#d4f693">newPage</a>(); page++; } }#endif}void <a name="142"></a>HelpWindow::pathSelected( const QString &_path ){ browser->setSource( _path ); <a href="qmap.html">QMap</a><int, QString>::Iterator it = mHistory.begin(); bool exists = FALSE; for ( ; it != mHistory.end(); ++it ) { if ( *it == _path ) { exists = TRUE; break; } } if ( !exists ) mHistory[ hist->insertItem( _path ) ] = _path;}void <a name="143"></a>HelpWindow::readHistory(){ if ( <a href="qfile.html#900285">QFile::exists</a>( <a href="qdir.html#2ec6fd">QDir::currentDirPath</a>() + "/.history" ) ) { <a href="qfile.html">QFile</a> f( <a href="qdir.html#2ec6fd">QDir::currentDirPath</a>() + "/.history" ); f.<a href="qfile.html#255995">open</a>( IO_ReadOnly ); <a href="qdatastream.html">QDataStream</a> s( &f ); s >> history; f.<a href="qfile.html#64e640">close</a>(); while ( history.count() > 20 ) history.remove( history.begin() ); }}void <a name="144"></a>HelpWindow::readBookmarks(){ if ( <a href="qfile.html#900285">QFile::exists</a>( <a href="qdir.html#2ec6fd">QDir::currentDirPath</a>() + "/.bookmarks" ) ) { <a href="qfile.html">QFile</a> f( <a href="qdir.html#2ec6fd">QDir::currentDirPath</a>() + "/.bookmarks" ); f.<a href="qfile.html#255995">open</a>( IO_ReadOnly ); <a href="qdatastream.html">QDataStream</a> s( &f ); s >> bookmarks; f.<a href="qfile.html#64e640">close</a>(); }}void <a name="145"></a>HelpWindow::histChosen( int i ){ if ( mHistory.contains( i ) ) browser->setSource( mHistory[ i ] );}void <a name="146"></a>HelpWindow::bookmChosen( int i ){ if ( mBookmarks.contains( i ) ) browser->setSource( mBookmarks[ i ] );}void <a name="147"></a>HelpWindow::addBookmark(){ mBookmarks[ bookm->insertItem( <a href="qwidget.html#f852bc">caption</a>() ) ] = caption();}</pre> <hr>/*! \example qdir/qdir.cpp <h1 align=center>QDir</h1><br clear="all"> ??? <hr> Main:<pre>/****************************************************************************** $Id: qt/examples/helpviewer/main.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 "helpwindow.h"#include <<a name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>>#include <<a name="qwindowsstyle.h"></a><a href="qwindowsstyle-h.html">qwindowsstyle.h</a>>#include <<a name="qstylesheet.h"></a><a href="qstylesheet-h.html">qstylesheet.h</a>>#include <stdlib.h>int main( int argc, char ** argv ){ <a name="QApplication::setColorSpec"></a><a href="qapplication.html#1ee2d1">QApplication::setColorSpec</a>( QApplication::ManyColor ); <a name="QApplication"></a><a href="qapplication.html">QApplication</a> a(argc, argv); <a name="QString"></a><a href="qstring.html">QString</a> home; if (argc > 1) home = argv[1]; else home = QString(getenv("QTDIR")) + "/doc/html/index.html"; HelpWindow *help = new HelpWindow(home, ".", 0, "help viewer"); help-><a name="setCaption"></a><a href="qwidget.html#d6a291">setCaption</a>("Qt Example - Helpviewer"); if ( <a name="QApplication::desktop"></a><a href="qapplication.html#d8ed8c">QApplication::desktop</a>()->width() > 400 && <a href="qapplication.html#d8ed8c">QApplication::desktop</a>()->height() > 500 ) help-><a name="show"></a><a href="qmainwindow.html#eb53e3">show</a>(); else help-><a name="showMaximized"></a><a href="qwidget.html#b6e000">showMaximized</a>(); <a name="QObject::connect"></a><a href="qobject.html#7f8e37">QObject::connect</a>( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) ); return a.<a name="exec"></a><a href="qapplication.html#84c7bf">exec</a>();}</pre><p><address><hr><div align="center"><table width="100%" cellspacing="0" border="0"><tr><td>Copyright
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -