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

📄 kchmmainwindow.cpp

📁 chm阅读器 用于在linux系统下chm文档的阅读
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	if ( vwnd->openUrl (url) )	{		// Open all the tree items to show current item (if needed)		if ( (flags & OPF_CONTENT_TREE) != 0 )			locateInContentTree( vwnd->getOpenedPage() );				if ( flags & OPF_ADD2HISTORY )			currentBrowser()->addNavigationHistory( hist_url, hist_scrollpos );	}		return true;}void KCHMMainWindow::showEvent( QShowEvent * ){	if ( !m_FirstTimeShow )		return;	m_FirstTimeShow = false;		if ( !parseCmdLineArgs( ) )	{		if ( appConfig.m_LoadLatestFileOnStartup && appConfig.m_History.size() > 0 )		{			if ( loadChmFile ( appConfig.m_History[0] ) )				return;		}				emit slotOpenMenuItemActivated();	}}void KCHMMainWindow::setupToolbarsAndMenu( ){	// Create a 'file' toolbar    QToolBar * toolbar = new QToolBar(this);		toolbar->setLabel( i18n( "File Operations") );    QPixmap iconFileOpen (*gIconStorage.getToolbarPixmap(KCHMIconStorage::fileopen));    QToolButton * fileOpen = new QToolButton (iconFileOpen, 				i18n( "Open File" ), 				QString::null,				this, 				SLOT( slotOpenMenuItemActivated() ),				toolbar);		QString fileOpenText = i18n( "Click this button to open an existing chm file." );	QWhatsThis::add( fileOpen, fileOpenText );    QPixmap iconFilePrint (*gIconStorage.getToolbarPixmap(KCHMIconStorage::print));    QToolButton * filePrint	= new QToolButton (iconFilePrint,				i18n( "Print File" ),				QString::null,				this,				SLOT( slotPrintMenuItemActivated() ),				toolbar);	QString filePrintText = i18n( "Click this button to print the current page");	QWhatsThis::add( filePrint, filePrintText );	// Setup the menu	KQPopupMenu * file = new KQPopupMenu( this );	menuBar()->insertItem( i18n( "&File"), file );    int id;	id = file->insertItem ( iconFileOpen, i18n( "&Open..."), this, SLOT( slotOpenMenuItemActivated() ), CTRL+Key_O );    file->setWhatsThis( id, fileOpenText );	id = file->insertItem( iconFilePrint, i18n( "&Print..."), this, SLOT( slotPrintMenuItemActivated() ), CTRL+Key_P );    file->setWhatsThis( id, filePrintText );    file->insertSeparator();	id = file->insertItem ( i18n( "E&xtract CHM content..."), this, SLOT( slotExtractCHM() ) );	file->setWhatsThis( id, i18n( "Click this button to extract the whole CHM file content into a specific directory") );	file->insertSeparator();		m_menuHistory = new KQPopupMenu( file );	connect ( m_menuHistory, SIGNAL( activated(int) ), this, SLOT ( slotHistoryMenuItemActivated(int) ));		file->insertItem( i18n( "&Recent files"), m_menuHistory );		file->insertSeparator();	file->insertItem( i18n( "&Quit"), qApp, SLOT( closeAllWindows() ), CTRL+Key_Q );	KQPopupMenu * menu_edit = new KQPopupMenu( this );	menuBar()->insertItem( i18n( "&Edit"), menu_edit );	menu_edit->insertItem ( i18n( "&Copy"), this, SLOT( slotBrowserCopy()), CTRL+Key_C );	menu_edit->insertItem ( i18n( "&Select all"), this, SLOT( slotBrowserSelectAll()), CTRL+Key_A );    menu_edit->insertSeparator();		// KCHMNavToolbar	m_navToolbar = new KCHMNavToolbar( this );		// KCHMSearchToolbar also adds 'view' menu	m_searchToolbar = new KCHMSearchAndViewToolbar (this);		// m_bookmarkWindow adds 'Bookmarks' menu	m_bookmarkWindow->createMenu( this );		// m_viewWindowMgr creates 'Window' menu	m_viewWindowMgr->createMenu( this );		KQPopupMenu * settings = new KQPopupMenu( this );	menuBar()->insertItem( i18n( "&Settings"), settings );	settings->insertItem( i18n( "&Change settings..."), this, SLOT( slotChangeSettingsMenuItemActivated() ));#if defined(USE_KDE)	QPopupMenu *help = helpMenu( m_aboutDlgMenuText );#else    KQPopupMenu * help = new KQPopupMenu( this );	help->insertItem( i18n( "&About"), this, SLOT( slotAboutMenuItemActivated() ), Key_F1 );	help->insertItem( i18n( "About &Qt"), this, SLOT( slotAboutQtMenuItemActivated() ));	help->insertSeparator();	help->insertItem( i18n( "What's &This"), this, SLOT(whatsThis()), SHIFT+Key_F1 );#endif			menuBar()->insertItem( i18n( "&Help"), help );	updateHistoryMenu();}void KCHMMainWindow::slotAddBookmark( ){	emit m_bookmarkWindow->onAddBookmarkPressed ();}void KCHMMainWindow::setTextEncoding( const LCHMTextEncoding * encoding ){	m_chmFile->setCurrentEncoding( encoding );	m_searchToolbar->setChosenEncodingInMenu( encoding );		// Because updateView() will call view->invalidate(), which clears the view->getOpenedPage(),	// we have to make a copy of it.	QString url = currentBrowser()->getOpenedPage();		// Regenerate the content and index trees		refreshCurrentBrowser();		currentBrowser()->openUrl( url );}void KCHMMainWindow::closeChmFile( ){	// Prepare the settings	if ( appConfig.m_HistoryStoreExtra )	{		m_currentSettings->m_activeencodinglcid = m_chmFile->currentEncoding()->winlcid;		m_currentSettings->m_activetabsystem = m_tabWidget->currentPageIndex( );		m_currentSettings->m_activetabwindow = m_viewWindowMgr->currentPageIndex( );				m_currentSettings->m_window_size_x = width();		m_currentSettings->m_window_size_y = height();		m_currentSettings->m_window_size_splitter = m_windowSplitter->sizes()[0];				if ( m_searchWindow )			m_searchWindow->saveSettings (m_currentSettings->m_searchhistory);						m_bookmarkWindow->saveSettings( m_currentSettings->m_bookmarks );		m_viewWindowMgr->saveSettings( m_currentSettings->m_viewwindows );		m_currentSettings->saveSettings( );	}		appConfig.save();}void KCHMMainWindow::closeEvent ( QCloseEvent * e ){	// Save the settings if we have something opened	if ( m_chmFile )	{		closeChmFile( );		delete m_chmFile;		m_chmFile = 0;	}	QMainWindow::closeEvent ( e );}bool KCHMMainWindow::parseCmdLineArgs( ){	QString filename = QString::null, search_query = QString::null;	QString search_index = QString::null, search_bookmark = QString::null;	bool do_autotest = false;#if defined (USE_KDE)	KCmdLineArgs *args = KCmdLineArgs::parsedArgs();	if ( args->isSet("autotestmode") )		do_autotest = true;		if ( args->isSet("shortautotestmode") )		do_autotest = m_useShortAutotest = true;	search_query = args->getOption ("search");	search_index = args->getOption ("sindex");		if ( args->count() > 0 )		filename = args->arg(0);#else	// argv[0] in Qt is still a program name	for ( int i = 1; i < qApp->argc(); i++  )	{		if ( !strcmp (qApp->argv()[i], "--autotestmode") )			do_autotest = m_useShortAutotest = true;		else if ( !strcmp (qApp->argv()[i], "--shortautotestmode") )			do_autotest = true;		else if ( !strcmp (qApp->argv()[i], "--search") )			search_query = qApp->argv()[++i];		else if ( !strcmp (qApp->argv()[i], "--sindex") )			search_index = qApp->argv()[++i];		else if ( !strcmp (qApp->argv()[i], "-h") || !strcmp (qApp->argv()[i], "--help") )		{			fprintf (stderr, "Usage: %s [chmfile]\n", qApp->argv()[0]);			exit (1);		}		else			filename = qApp->argv()[i];	}#endif	if ( !filename.isEmpty() )	{		if ( !loadChmFile( QString::fromLocal8Bit( filename )) )			return false;		if ( !search_index.isEmpty() )		{			QStringList event_args;			event_args.push_back( search_index );			qApp->postEvent( this, new KCHMUserEvent( "findInIndex", event_args ) );		}				if ( !search_query.isEmpty() )			{			QStringList event_args;			event_args.push_back( search_query );			qApp->postEvent( this, new KCHMUserEvent( "searchQuery", event_args ) );		}				if ( do_autotest )		{#if defined (ENABLE_AUTOTEST_SUPPORT)			if ( filename.isEmpty() )				qFatal ("Could not use Auto Test mode without a chm file!");			m_autoteststate = STATE_INITIAL;			showMinimized ();			runAutoTest();#else			qFatal ("Auto Test mode support is not compiled in.");#endif /* defined (ENABLE_AUTOTEST_SUPPORT) */		}		return true;	}		return false;}void KCHMMainWindow::slotBrowserSelectAll( ){	currentBrowser()->clipSelectAll();}void KCHMMainWindow::slotBrowserCopy( ){	currentBrowser()->clipCopy();}void KCHMMainWindow::slotChangeSettingsMenuItemActivated(){	KCHMSetupDialog dlg ( this );		// Set up the parameters	dlg.m_radioOnBeginOpenDialog->setChecked ( !appConfig.m_LoadLatestFileOnStartup );	dlg.m_radioOnBeginOpenLast->setChecked ( appConfig.m_LoadLatestFileOnStartup );	dlg.m_historySize->setValue ( appConfig.m_HistorySize );	dlg.m_rememberHistoryInfo->setChecked ( appConfig.m_HistoryStoreExtra );		dlg.m_radioExtLinkOpenAlways->setChecked ( appConfig.m_onExternalLinkClick == KCHMConfig::ACTION_ALWAYS_OPEN );	dlg.m_radioExtLinkAsk->setChecked ( appConfig.m_onExternalLinkClick == KCHMConfig::ACTION_ASK_USER );	dlg.m_radioExtLinkOpenNever->setChecked ( appConfig.m_onExternalLinkClick == KCHMConfig::ACTION_DONT_OPEN );		dlg.m_radioNewChmOpenAlways->setChecked ( appConfig.m_onNewChmClick == KCHMConfig::ACTION_ALWAYS_OPEN );	dlg.m_radioNewChmAsk->setChecked ( appConfig.m_onNewChmClick == KCHMConfig::ACTION_ASK_USER );	dlg.m_radioNewChmOpenNever->setChecked ( appConfig.m_onNewChmClick == KCHMConfig::ACTION_DONT_OPEN );#if defined (USE_KDE)	dlg.m_groupQtsettings->setEnabled ( false );	dlg.m_groupKDEsettings->setEnabled ( true );#else	dlg.m_groupQtsettings->setEnabled ( true );	dlg.m_groupKDEsettings->setEnabled ( false );#endif	dlg.m_qtBrowserPath->setText ( appConfig.m_QtBrowserPath );	dlg.m_radioUseQtextBrowser->setChecked ( appConfig.m_kdeUseQTextBrowser );	dlg.m_radioUseKHTMLPart->setChecked ( !appConfig.m_kdeUseQTextBrowser );		dlg.m_enableJS->setChecked ( appConfig.m_kdeEnableJS );	dlg.m_enablePlugins->setChecked ( appConfig.m_kdeEnablePlugins );	dlg.m_enableJava->setChecked ( appConfig.m_kdeEnableJava );	dlg.m_enableRefresh->setChecked ( appConfig.m_kdeEnableRefresh );		dlg.m_advExternalProgramName->setText( appConfig.m_advExternalEditorPath );	dlg.m_advViewSourceExternal->setChecked ( !appConfig.m_advUseInternalEditor );	dlg.m_advViewSourceInternal->setChecked ( appConfig.m_advUseInternalEditor );		// Search engine	dlg.m_useSearchEngineInternal->setChecked( appConfig.m_useSearchEngine == KCHMConfig::SEARCH_USE_CHM );	dlg.m_useSearchEngineNew->setChecked( appConfig.m_useSearchEngine == KCHMConfig::SEARCH_USE_MINE );		// Connect buddies	dlg.m_labelUseSearchEngineInternal->setBuddy( dlg.m_useSearchEngineInternal );	dlg.m_labelUseSearchEngineNew->setBuddy( dlg.m_useSearchEngineNew );		if ( dlg.exec() == QDialog::Accepted )	{		appConfig.m_LoadLatestFileOnStartup = dlg.m_radioOnBeginOpenLast->isChecked();		appConfig.m_HistorySize = dlg.m_historySize->value();		appConfig.m_HistoryStoreExtra = dlg.m_rememberHistoryInfo->isChecked();		if ( dlg.m_radioExtLinkOpenAlways->isChecked () )			appConfig.m_onExternalLinkClick = KCHMConfig::ACTION_ALWAYS_OPEN;		else if ( dlg.m_radioExtLinkAsk->isChecked () )			appConfig.m_onExternalLinkClick = KCHMConfig::ACTION_ASK_USER;		else			appConfig.m_onExternalLinkClick = KCHMConfig::ACTION_DONT_OPEN;		if ( dlg.m_radioNewChmOpenAlways->isChecked () )			appConfig.m_onNewChmClick = KCHMConfig::ACTION_ALWAYS_OPEN;		else if ( dlg.m_radioNewChmAsk->isChecked () )			appConfig.m_onNewChmClick = KCHMConfig::ACTION_ASK_USER;		else			appConfig.m_onNewChmClick = KCHMConfig::ACTION_DONT_OPEN;		appConfig.m_QtBrowserPath = dlg.m_qtBrowserPath->text();				// Check the changes		bool need_restart = false;				if ( appConfig.m_kdeEnableJS != dlg.m_enableJS->isChecked() )		{			need_restart = true;			appConfig.m_kdeEnableJS = dlg.m_enableJS->isChecked();		}				if ( appConfig.m_kdeEnablePlugins != dlg.m_enablePlugins->isChecked() )		{			need_restart = true;			appConfig.m_kdeEnablePlugins = dlg.m_enablePlugins->isChecked();		}				if ( appConfig.m_kdeEnableJava != dlg.m_enableJava->isChecked() )		{			need_restart = true;			appConfig.m_kdeEnableJava = dlg.m_enableJava->isChecked();		}				if ( appConfig.m_kdeEnableRefresh != dlg.m_enableRefresh->isChecked() )		{			need_restart = true;			appConfig.m_kdeEnableRefresh = dlg.m_enableRefresh->isChecked();		}				if ( appConfig.m_kdeUseQTextBrowser != dlg.m_radioUseQtextBrowser->isChecked() )		{			need_restart = true;			appConfig.m_kdeUseQTextBrowser = dlg.m_radioUseQtextBrowser->isChecked();		}				if ( dlg.m_useSearchEngineNew->isChecked() 		&& appConfig.m_useSearchEngine == KCHMConfig::SEARCH_USE_CHM )		{			appConfig.m_useSearchEngine = KCHMConfig::SEARCH_USE_MINE;			m_searchWindow->invalidate();		}				if ( dlg.m_useSearchEngineInternal->isChecked() 		&& appConfig.m_useSearchEngine == KCHMConfig::SEARCH_USE_MINE )		{			appConfig.m_useSearchEngine = KCHMConfig::SEARCH_USE_CHM;			m_searchWindow->invalidate();		}							appConfig.m_advExternalEditorPath = dlg.m_advExternalProgramName->text();		appConfig.m_advUseInternalEditor = dlg.m_advViewSourceExternal->isChecked();		appConfig.m_advUseInternalEditor = dlg.m_advViewSourceInternal->isChecked();				appConfig.save();				if ( need_restart )			QMessageBox::information( 					this,					APP_NAME,					i18n( "Changing browser view options or search engine used\n"							"requires restarting the application to take effect." )	);	}}void KCHMMainWindow::setupSignals( ){#if defined(HAVE_SIGACTION)	struct sigaction sa;    memset ((char *)&sa, 0, sizeof(sa));	sigemptyset (&sa.sa_mask);	sigaddset (&sa.sa_mask, SIGCHLD);#ifdef SA_RESTART	sa.sa_flags = SA_RESTART;#endif		sa.sa_handler = SIG_IGN;	sigaction (SIGCHLD, &sa, (struct sigaction *)0);#else /* !HAVE_SIGACTION */	signal (SIGCHLD, SIG_IGN);#endif /* HAVE_SIGACTION */}void KCHMMainWindow::slotHistoryMenuItemActivated( int item ){	if ( item < 0 || item >= (signed) appConfig.m_History.size() )		qFatal ("KCHMMainWindow::slotHistoryMenuItemActivated: bad history menu id %d", item);		QString filename = appConfig.m_History[item];		// remove it, so it will be added again at the history top, and will not shitf anything.//	appConfig.m_History.remove ( appConfig.m_History.begin() + item);	loadChmFile ( filename );

⌨️ 快捷键说明

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