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

📄 kchmmainwindow.cpp

📁 chm阅读器 用于在linux系统下chm文档的阅读
💻 CPP
📖 第 1 页 / 共 3 页
字号:
}void KCHMMainWindow::updateHistoryMenu(){	m_menuHistory->clear ();		for ( int i = appConfig.m_History.size() - 1; i >= 0; i-- )		m_menuHistory->insertItem( appConfig.m_History[i], i );}void KCHMMainWindow::slotActivateContentTab( ){	if ( m_tabContextPage != -1 ) 		m_tabWidget->setCurrentPage( m_tabContextPage );}void KCHMMainWindow::slotActivateIndexTab( ){	if ( m_tabIndexPage != -1 ) 		m_tabWidget->setCurrentPage( m_tabIndexPage );}void KCHMMainWindow::slotActivateSearchTab( ){	if ( m_tabSearchPage != -1 ) 		m_tabWidget->setCurrentPage( m_tabSearchPage );}void KCHMMainWindow::slotActivateBookmarkTab( ){	m_tabWidget->setCurrentPage( m_tabBookmarkPage );}void KCHMMainWindow::showOrHideContextWindow( int tabindex ){	if ( tabindex == -1 )	{		if ( m_contentsWindow )		{			m_tabWidget->removePage (m_contentsWindow);			delete m_contentsWindow;			m_contentsWindow = 0;		}	}	else	{		if ( !m_contentsWindow )		{			m_contentsWindow = new KCHMContentsWindow( m_tabWidget );						// Handle clicking on m_contentsWindow element			connect( m_contentsWindow, 					 SIGNAL( clicked( QListViewItem* ) ), 					 this, 					 SLOT( slotOnTreeClicked( QListViewItem* ) ) );						connect( m_contentsWindow, 					 SIGNAL( doubleClicked ( QListViewItem *, const QPoint &, int ) ), 					 this, 					 SLOT( slotOnTreeDoubleClicked ( QListViewItem *, const QPoint &, int ) ) );						m_tabWidget->insertTab (m_contentsWindow, i18n( "Contents" ), tabindex);		}	}}void KCHMMainWindow::showOrHideIndexWindow( int tabindex ){	// Test whether to show/invalidate the index window	if ( tabindex == -1 )	{		if ( m_indexWindow )		{			m_tabWidget->removePage (m_indexWindow);			delete m_indexWindow;			m_indexWindow = 0;		}	}	else	{		if ( !m_indexWindow )		{			m_indexWindow = new KCHMIndexWindow (m_tabWidget);			m_tabWidget->insertTab (m_indexWindow, i18n( "Index" ), tabindex);		}		else			m_indexWindow->invalidate();	}}void KCHMMainWindow::showOrHideSearchWindow( int tabindex ){	if ( tabindex == -1 )	{		if ( m_searchWindow )		{			m_tabWidget->removePage (m_searchWindow);			delete m_searchWindow;			m_searchWindow = 0;		}	}	else	{		if ( !m_searchWindow )		{			m_searchWindow = new KCHMSearchWindow (m_tabWidget);			m_tabWidget->insertTab (m_searchWindow, i18n( "Search" ), tabindex);		}		else			m_searchWindow->invalidate();	}}void KCHMMainWindow::slotEnableFullScreenMode( bool enable ){	if ( enable )	{		if ( !isFullScreen() )		{			showFullScreen ();			menuBar()->hide();			statusBar()->hide();		}	}	else	{		if ( isFullScreen() )		{			showNormal ();			menuBar()->show();			statusBar()->show();		}	}}void KCHMMainWindow::slotShowContentsWindow( bool show ){	if ( show )		m_tabWidget->show();	else		m_tabWidget->hide();}void KCHMMainWindow::slotToggleFullScreenMode( ){	slotEnableFullScreenMode( !isFullScreen() );}void KCHMMainWindow::slotLocateInContentWindow( ){	// There may be no content tab at all	if ( !m_contentsWindow  || m_tabContextPage == -1 )		return;		// Activate a content tab	m_tabWidget->setCurrentPage( m_tabContextPage );		if ( m_contentsWindow )	{		// Open all the tree items to show current item (if needed)		KCHMIndTocItem * treeitem = m_contentsWindow->getTreeItem( currentBrowser()->getOpenedPage() );			if ( treeitem )		{			KCHMIndTocItem * itemparent = treeitem;						while ( (itemparent = (KCHMIndTocItem*) itemparent->parent()) != 0 )				itemparent->setOpen(true);						m_contentsWindow->setCurrentItem (treeitem);			m_contentsWindow->ensureItemVisible (treeitem);		}		else			statusBar()->message( i18n( "Could not locate opened topic in content window"), 2000 );	}}void KCHMMainWindow::slotExtractCHM( ){	QStringList files;	#if defined (USE_KDE)	QString outdir = KFileDialog::getExistingDirectory (			QString::null,			this,			i18n("Choose a directory to store CHM content") );#else	QString outdir = QFileDialog::getExistingDirectory (			QString::null,			this,			0,			i18n("Choose a directory to store CHM content"),			TRUE );#endif		if ( outdir.isEmpty() )		return;		outdir += "/";		// Enumerate all the files in archive	if ( !m_chmFile || !m_chmFile->enumerateFiles( &files ) )		return;	KQProgressModalDialog progress( i18n("Extracting CHM content"), i18n("Extracting files..."), i18n("Abort"), files.size(), this );		for ( unsigned int i = 0; i < files.size(); i++ )	{		progress.setProgress( i );				if ( (i % 3) == 0 )		{			qApp->processEvents();			if ( progress.wasCancelled() )				break;		}		// Extract the file		QByteArray buf;				if ( m_chmFile->getFileContentAsBinary( &buf, files[i] ) )		{			// Split filename to get the list of subdirectories			QStringList dirs = QStringList::split( '/', files[i] );			// Walk through the list of subdirectories, and create them if needed			// dirlevel is used to detect extra .. and prevent overwriting files			// outside the directory (like creating the file images/../../../../../etc/passwd			unsigned int i, dirlevel = 0;			QStringList dirlist;							for ( i = 0; i < dirs.size() - 1; i++ )			{				// Skip .. which lead too far above				if ( dirs[i] == ".." )				{					if ( dirlevel > 0 )					{						dirlevel--;						dirlist.pop_back();					}				}				else				{					dirlist.push_back( dirs[i] );										QDir dir ( outdir + dirlist.join( "/" ) );					if ( !dir.exists() )					{						if ( !dir.mkdir( dir.path() ) )							qWarning( "Could not create subdir %s\n", dir.path().ascii() );					}				}			}						QString filename = outdir + dirlist.join( "/" ) + "/" + dirs[i];			QFile wf( filename );			if ( !wf.open( IO_WriteOnly ) )			{					qWarning( "Could not write file %s\n", filename.ascii() );					continue;			}						wf. writeBlock( buf );			wf.close();		}		else			qWarning( "Could not get file %s\n", files[i].ascii() );	}		progress.setProgress( files.size() );}KCHMViewWindow * KCHMMainWindow::currentBrowser( ) const{	return m_viewWindowMgr->current();}void KCHMMainWindow::slotOpenPageInNewTab( ){	openPage( currentBrowser()->getNewTabLink(), OPF_NEW_TAB | OPF_CONTENT_TREE );}void KCHMMainWindow::slotOpenPageInNewBackgroundTab( ){	openPage( currentBrowser()->getNewTabLink(), OPF_NEW_TAB | OPF_BACKGROUND );}void KCHMMainWindow::slotBrowserChanged( KCHMViewWindow * newbrowser ){	locateInContentTree( newbrowser->getOpenedPage() );}void KCHMMainWindow::locateInContentTree( const QString & url ){	if ( !m_contentsWindow )		return;		KCHMIndTocItem * treeitem = m_contentsWindow->getTreeItem( url );		if ( treeitem )	{		KCHMIndTocItem * itemparent = treeitem;		while ( (itemparent = (KCHMIndTocItem*) itemparent->parent()) != 0 )			itemparent->setOpen(true);					m_contentsWindow->setCurrentItem (treeitem);		m_contentsWindow->ensureItemVisible (treeitem);	}}void KCHMMainWindow::slotOnTreeDoubleClicked( QListViewItem * item, const QPoint &, int ){	// Open/close only existing item which have children	if ( !item || item->childCount() == 0 )		return;		item->setOpen( !item->isOpen() );	item->repaint();}bool KCHMMainWindow::event( QEvent * e ){	if ( e->type() == QEvent::User )		return handleUserEvent( (KCHMUserEvent*) e );		return QWidget::event( e );}bool KCHMMainWindow::handleUserEvent( const KCHMUserEvent * event ){	if ( event->m_action == "loadAndOpen" )	{		if ( event->m_args.size() != 1 && event->m_args.size() != 2 )			qFatal("handleUserEvent: event loadAndOpen must receive 1 or 2 args");				QString chmfile = event->m_args[0];		QString openurl = event->m_args.size() > 1 ? event->m_args[1] : "/";						return loadChmFile( chmfile, false ) && openPage( openurl );	}	else if ( event->m_action == "openPage" )	{		if ( event->m_args.size() != 1 )			qFatal("handleUserEvent: event openPage must receive 1 arg");				return openPage( event->m_args[0] );	}	else if ( event->m_action == "findInIndex" )	{		if ( event->m_args.size() != 1 )			qFatal( "handleUserEvent: event searchQuery must receive 1 arg" );				if ( m_tabIndexPage == -1 )			return false;		slotActivateIndexTab();		m_indexWindow->search( event->m_args[0] );		return true;	}	else if ( event->m_action == "searchQuery" )	{		if ( event->m_args.size() != 1 )			qFatal( "handleUserEvent: event searchQuery must receive 1 arg" );				if ( m_tabSearchPage == -1 )			return false;		slotActivateSearchTab();		m_searchWindow->execSearchQueryInGui( event->m_args[0] );		return true;	}	else		qWarning( "Unknown user event received: %s", event->m_action.ascii() );		return false;}#if defined (ENABLE_AUTOTEST_SUPPORT)void KCHMMainWindow::runAutoTest(){	KCHMIndTocItem * item;	switch (m_autoteststate)	{	case STATE_INITIAL:		if ( m_contentsWindow && !m_useShortAutotest )		{			m_autotestlistiterator = QListViewItemIterator (m_contentsWindow);			m_autoteststate = STATE_CONTENTS_OPENNEXTPAGE;		}		else			m_autoteststate = STATE_OPEN_INDEX;				QTimer::singleShot (500, this, SLOT(runAutoTest()) );		break; // allow to finish the initialization sequence			case STATE_CONTENTS_OPENNEXTPAGE:		if ( (item = (KCHMIndTocItem *) m_autotestlistiterator.current()) != 0 )		{			openPage( item->getUrl(), OPF_CONTENT_TREE | OPF_ADD2HISTORY );			m_autotestlistiterator++;		}		else			m_autoteststate = STATE_OPEN_INDEX;				QTimer::singleShot (50, this, SLOT(runAutoTest()) );		break;	case STATE_OPEN_INDEX:		if ( m_indexWindow )			m_tabWidget->setCurrentPage (1);				m_autoteststate = STATE_SHUTDOWN;		QTimer::singleShot (500, this, SLOT(runAutoTest()) );		break;	case STATE_SHUTDOWN:		qApp->quit();		break;			default:		break;	}}#endif /* defined (ENABLE_AUTOTEST_SUPPORT) *///TODO: KDE: xmlgui//TODO: Search result highlighting

⌨️ 快捷键说明

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