⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 helpdialogimpl.cpp

📁 Qt/Embedded是一个多平台的C++图形用户界面应用程序框架
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************************************************************ Copyright (C) 2000 Trolltech AS.  All rights reserved.**** This file is part of Qt Designer.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "helpdialogimpl.h"#include "mainwindow.h"#include "topicchooserimpl.h"#include "help.h"#include <stdlib.h>#include <qprogressbar.h>#include <qfile.h>#include <qtextstream.h>#include <qapplication.h>#include <qstringlist.h>#include <qtl.h>#include <qprogressbar.h>#include <qlabel.h>#include <qframe.h>#include <qobjectlist.h>#include <qtabwidget.h>#include <qpushbutton.h>#include <qurl.h>#include <qheader.h>#include <qtextbrowser.h>class MyString : public QString{public:    MyString() {}    MyString( const QString& other )	:QString( other ){	    lower = other.lower();    }    QString lower;};struct Entry{    QString link;    QString title;    int depth;};#if defined(Q_FULL_TEMPLATE_INSTANTIATION)bool operator==( const Entry&, const Entry& ) { return FALSE; }#endifbool operator<=( const MyString &s1, const MyString &s2 ){ return s1.lower <= s2.lower; }bool operator<( const MyString &s1, const MyString &s2 ){ return s1.lower < s2.lower; }bool operator>( const MyString &s1, const MyString &s2 ){ return s1.lower > s2.lower; }HelpNavigationListItem::HelpNavigationListItem( QListBox *ls, const QString &txt )    : QListBoxText( ls, txt ){}void HelpNavigationListItem::addLink( const QString &link ){    int hash = link.find( '#' );    if ( hash == -1 ) {	linkList << link;	return;    }    QString preHash = link.left( hash );    if ( linkList.grep( preHash, FALSE ).count() > 0 )	return;    linkList << link;}HelpNavigationContentsItem::HelpNavigationContentsItem( QListView *v, QListViewItem *after )    : QListViewItem( v, after ){}HelpNavigationContentsItem::HelpNavigationContentsItem( QListViewItem *v, QListViewItem *after )    : QListViewItem( v, after ){}void HelpNavigationContentsItem::setLink( const QString &lnk ){    theLink = lnk;}QString HelpNavigationContentsItem::link() const{    return theLink;}HelpDialog::HelpDialog( QWidget *parent, MainWindow *mw, Help *h )    : HelpDialogBase( parent, 0, FALSE ), mainWindow( mw ), help( h ){    connect( buttonHelp, SIGNAL( clicked() ), MainWindow::self, SLOT( showDialogHelp() ) );    indexDone = FALSE;    contentsDone = FALSE;    contentsInserted = FALSE;    bookmarksInserted = FALSE;    editIndex->installEventFilter( this );    listBookmarks->header()->hide();    listContents->header()->hide();    framePrepare->hide();    setupTitleMap();}void HelpDialog::loadIndexFile(){    if ( indexDone )	return;    setCursor( WaitCursor );    indexDone = TRUE;    framePrepare->show();    qApp->processEvents();    QProgressBar *bar = progressPrepare;    bar->setTotalSteps( QFileInfo( mainWindow->documentationPath() + "/index" ).size() );    bar->setProgress( 0 );    QString indexFile = mainWindow->documentationPath() + "/index";    HelpNavigationListItem *lastItem = 0;    //### if constructed on stack, it will crash on WindowsNT    QValueList<MyString>* lst = new QValueList<MyString>;    bool buildDb = TRUE;    QFile f( indexFile );    if ( QFile::exists( QDir::homeDirPath() + "/.designer/indexdb" ) ) {	QFile indexin( QDir::homeDirPath() + "/.designer/indexdb" );	if ( !indexin.open( IO_ReadOnly ) )	    goto build_db;	QDataStream ds( &indexin );	QDateTime dt;	uint size;	ds >> dt;	ds >> size;	if ( size != f.size() || dt != QFileInfo( f ).lastModified() )	    goto build_db;	ds >> *lst;	indexin.close();	bar->setProgress( bar->totalSteps() );	qApp->processEvents();	buildDb = FALSE;    } build_db:    if ( buildDb ) {	if ( !f.open( IO_ReadOnly ) )	    return;	QTextStream ts( &f );	while ( !ts.atEnd() ) {	    qApp->processEvents();	    QString l = ts.readLine();	    lst->append( l );	    if ( bar )		bar->setProgress( bar->progress() + l.length() );	}	qHeapSort( *lst );	QFile indexout( QDir::homeDirPath() + "/.designer/indexdb" );	if ( indexout.open( IO_WriteOnly ) ) {		    QDataStream s( &indexout );	    s << QFileInfo( f ).lastModified();	    s << f.size();	    s << *lst;	}	indexout.close();    }    QValueList<MyString>::Iterator it = lst->begin();    for ( ; it != lst->end(); ++it ) {	QString s( *it );	if ( s.find( "::" ) != -1 )	    continue;	if ( s[1] == '~' )	    continue;	if ( s.find( "http://" ) != -1 ||	     s.find( "ftp://" ) != -1 ||	     s.find( "mailto:" ) != -1 )	    continue;	int from = s.find( "\"" );	if ( from == -1 )	    continue;	int to = s.findRev( "\"" );	if ( to == -1 )	    continue;	QString link = s.mid( to + 2, 0xFFFFFF );	s = s.mid( from + 1, to - from - 1 );	if ( s.isEmpty() )	    continue;	if ( !lastItem || lastItem->text() != s )	    lastItem = new HelpNavigationListItem( listIndex, s );	lastItem->addLink( link );    }    delete lst;    f.close();    framePrepare->hide();    setCursor( ArrowCursor );}void HelpDialog::setupTitleMap(){    if ( contentsDone )	return;    contentsDone = TRUE;    QString titleFile = mainWindow->documentationPath() + "/titleindex";    QFile f2( titleFile );    bool buildDb = TRUE;    if ( QFile::exists( QDir::homeDirPath() + "/.designer/titlemapdb" ) ) {	QFile titlein( QDir::homeDirPath() + "/.designer/titlemapdb" );	if ( !titlein.open( IO_ReadOnly ) )	    goto build_db2;	QDataStream ds( &titlein );	QDateTime dt;	uint size;	ds >> dt;	ds >> size;	if ( size != f2.size() || dt != QFileInfo( f2 ).lastModified() )	    goto build_db2;	ds >> titleMap;	titlein.close();	qApp->processEvents();	buildDb = FALSE;    } build_db2:    if ( buildDb ) {	if ( !f2.open( IO_ReadOnly ) )	    return;	QTextStream ts2( &f2 );	while ( !ts2.atEnd() ) {	    QString s = ts2.readLine();	    int pipe = s.find( '|' );	    if ( pipe == -1 )		continue;	    QString title = s.left( pipe - 1 );	    QString link = s.mid( pipe + 1, 0xFFFFFF );	    link = link.simplifyWhiteSpace();	    titleMap[ link ] = title.stripWhiteSpace();	}	QFile titleout( QDir::homeDirPath() + "/.designer/titlemapdb" );	if ( titleout.open( IO_WriteOnly ) ) {		    QDataStream s( &titleout );	    s << QFileInfo( f2 ).lastModified();	    s << f2.size();	    s << titleMap;	}	titleout.close();    }}void HelpDialog::currentTabChanged( const QString &s ){	    if ( s.contains( tr( "Index" ) ) ) {	buttonDisplay->setEnabled( FALSE );	if ( !indexDone )	    QTimer::singleShot( 100, this, SLOT( loadIndexFile() ) );	else if ( listIndex->currentItem() )	    buttonDisplay->setEnabled( TRUE );    } else if ( s.contains( tr( "Bookmarks" ) ) ) {	buttonDisplay->setEnabled( FALSE );	if ( !bookmarksInserted )	    insertBookmarks();	else if ( listBookmarks->currentItem() )	    buttonDisplay->setEnabled( TRUE );    } else if ( s.contains( tr( "Con&tents" ) ) ) {	buttonDisplay->setEnabled( FALSE );	if ( !contentsInserted )	    insertContents();	else if ( listContents->currentItem() )	    buttonDisplay->setEnabled( TRUE );    }}void HelpDialog::currentIndexChanged( QListBoxItem *i ){    buttonDisplay->setEnabled( (bool)i );}void HelpDialog::showTopic(){    if ( tabWidget->tabLabel( tabWidget->currentPage() ).contains( tr( "Index" ) ) )	showIndexTopic();    else if ( tabWidget->tabLabel( tabWidget->currentPage() ).contains( tr( "Bookmarks" ) ) )	showBookmarkTopic();    else if ( tabWidget->tabLabel( tabWidget->currentPage() ).contains( tr( "Con&tents" ) ) )	showContentsTopic();}void HelpDialog::showIndexTopic(){    QListBoxItem *i = listIndex->item( listIndex->currentItem() );    if ( !i )	return;    editIndex->blockSignals( TRUE );    editIndex->setText( i->text() );    editIndex->blockSignals( FALSE );    HelpNavigationListItem *item = (HelpNavigationListItem*)i;    QStringList links = item->links();    if ( links.count() == 1 ) {	emit showLink( links.first(), item->text() );	buttonDisplay->setEnabled( FALSE );    } else {	QStringList::Iterator it = links.begin();	QStringList linkList;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -