/*************************************************************************** * * * begin : 15 Jan 2004 * * copyright : (C) 2003 by Samokhvalov Anton :) * * * ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include #include #include #include #include #include #include "MainView.h" #include "HtmlView.h" #include "TopicLeaf.h" #include "TopicTree.h" #include "Def.h" #include "History.h" HtmlView::HtmlView( const QString& f_name, KActionCollection* ac, QWidget* parent, MainView* parent1, const char* name ): KHTMLPart( parent, name ), d_fname( f_name ), d_parent( parent1 ), d_popup( 0 ), d_ac( ac ), d_copy( d_ac->action( "edit_copy" ) ), d_copy_url( d_ac->action( "edit_copy_url" ) ), d_select_all( d_ac->action( "edit_select_all" ) ), d_topic_tree( parent1->getTopicTree() ), d_last_node( 0 ) { d_history = new History(); connect( d_history, SIGNAL(changeUrl(const KURL&)), this, SLOT(slotSetUrl(const KURL&)) ); connect( this, SIGNAL(onURL(const QString&)), this, SLOT(slotOnURL(const QString&)) ); connect( this, SIGNAL(popupMenu(const QString&,const QPoint&)), this, SLOT(slotPopupMenu(const QString&,const QPoint&)) ); connect( this, SIGNAL(selectionChanged()), this, SLOT(slotSelectionChanged()) ); } HtmlView::~HtmlView() { delete d_history; } //to history void HtmlView::slotSetUrl( QListViewItem* item_ ) { if ( item_ ) { TopicLeaf* item = static_cast( item_ ); d_last_node = item; KURL u = KURL( "chm:" + d_fname + item->path.c_str() ); d_history->add( u ); d_parent->setStatusBarMessage( u.fileName() ); setUrl( u ); emit setCaption( this, item->text( 0 ) ); } } //not to history void HtmlView::slotSetUrl( const KURL& url ) { QString p = url.path(); if ( p.startsWith( d_fname ) ) { p = p.mid( d_fname.length() ); TopicLeaf* tl = d_topic_tree->find( p ); if ( tl ) { d_last_node = tl; d_topic_tree->ensureItemVisible( tl ); d_history->setEnabled( false ); d_topic_tree->setCurrentItem( tl ); d_history->setEnabled( true ); emit setCaption( this, tl->text( 0 ) ); return; } } setUrl( url ); } void HtmlView::urlSelected( const QString &url, int /*button*/, int /*state*/, const QString& /*_target*/, KParts::URLArgs /*args*/ ) { KURL u = completeURL( url ); d_history->add( u ); slotSetUrl( u ); } void HtmlView::setUrl( const KURL& url ) { preloadStyleSheet( url.path(), "p { text-align: justify; }" ); openURL( url ); } void HtmlView::up() { d_history->up(); } void HtmlView::back() { d_history->back(); } void HtmlView::forward() { d_history->forward(); } void HtmlView::setFileName( const QString& fname ) { d_fname = fname; d_history->clear(); } void HtmlView::slotOnURL( const QString& url ) { d_current_url = url; d_parent->setStatusBarMessage( url ); } void HtmlView::slotPopupMenu( const QString& url, const QPoint& point ) { if ( !d_popup ) { d_popup = new KPopupMenu( view() ); d_copy->plug( d_popup ); d_copy_url->plug( d_popup ); d_select_all->plug( d_popup ); } d_copy_url->setEnabled( url != QString::null ); d_popup->popup( point ); } void HtmlView::slotCopy() { KApplication::clipboard()->setText( selectedText(), QClipboard::Clipboard ); } void HtmlView::slotCopyURL() { KApplication::clipboard()->setText( d_current_url, QClipboard::Clipboard ); } void HtmlView::slotSelectAll() { selectAll(); } void HtmlView::slotSelectionChanged() { d_copy->setEnabled( hasSelection() ); } void HtmlView::updateState() { slotSelectionChanged(); if ( d_last_node ) { d_topic_tree->ensureItemVisible( d_last_node ); //d_last_node->setSelected( true ); d_history->setEnabled( false ); d_topic_tree->setCurrentItem( d_last_node ); d_history->setEnabled( true ); } d_history->emitSignal(); } #include "HtmlView.moc"