/*************************************************************************** * * * 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 "TabbedHtml.h" #include "MainView.h" #include "TopicTree.h" #include "History.h" TabbedHtml::TabbedHtml( const QString& f_name, KActionCollection* ac, QWidget* parent, MainView* parent1, const char* name ): KTabWidget( parent, name ), d_fname( f_name ), d_parent( parent1 ), d_ac( ac ), d_close_page( 0 ), d_new_page( 0 ) { QAccel* accel = new QAccel( this ); accel->connectItem( accel->insertItem( SHIFT+Key_Right ), this, SLOT(slotPrevTab()) ); accel->connectItem( accel->insertItem( SHIFT+Key_Left ), this, SLOT(slotNextTab()) ); KStdAction::copy( this, SLOT(slotCopy()), d_ac, "edit_copy" )->setEnabled( false ); new KAction( i18n( "Copy &Link Address" ), "editcopy", KShortcut(), this, SLOT(slotCopyURL()), d_ac, "edit_copy_url" ); KStdAction::selectAll( this, SLOT(slotSelectAll()), d_ac, "edit_select_all" ); setTabPosition( Bottom ); d_close_page = new QToolButton( this , "d_close_page" ); d_close_page->setAutoRaise( true ); d_close_page->setIconSet( SmallIconSet( "view_remove" ) ); d_close_page->setMaximumWidth( 20 ); d_close_page->setMaximumHeight( 20 ); d_close_page->setEnabled( false ); setCornerWidget( d_close_page, Qt::BottomRight ); d_new_page = new QToolButton( this , "d_new_page" ); d_new_page->setAutoRaise( true ); d_new_page->setIconSet( SmallIconSet( "tab_new" ) ); d_new_page->setMaximumWidth( 20 ); d_new_page->setMaximumHeight( 20 ); setCornerWidget( d_new_page, Qt::BottomLeft ); HtmlView* part = new HtmlView( d_fname, d_ac, parent, parent1, "d_html_view" ); connect( part, SIGNAL(setCaption(HtmlView*,const QString&)), this, SLOT(slotSetCaption(HtmlView*,const QString&)) ); addTab( part->view(), ( "Empty" ) ); connect( d_close_page, SIGNAL(clicked()), this, SLOT(slotClosePage()) ); connect( d_new_page, SIGNAL(clicked()), this, SLOT(slotDuplicatePage()) ); connect( this, SIGNAL(currentChanged(QWidget*)), this, SLOT(slotCurrentTabChanged(QWidget*)) ); } TabbedHtml::~TabbedHtml() { } void TabbedHtml::setFileName( const QString& fname ) { d_fname = fname; for ( int i = 0; i < count(); i++ ) { ToPart( page(i) )->setFileName( fname ); } } void TabbedHtml::slotSetUrl( QListViewItem* item ) { currentView()->slotSetUrl( item ); } void TabbedHtml::slotSetUrl( const KURL& url ) { currentView()->slotSetUrl( url ); } void TabbedHtml::up() { currentView()->up(); } void TabbedHtml::back() { currentView()->back(); } void TabbedHtml::forward() { currentView()->forward(); } HtmlView* TabbedHtml::currentView() { return (HtmlView*)((KHTMLView*)currentPage())->part(); } void TabbedHtml::slotClosePage() { if ( count() > 1 ) { delete currentPage(); if ( count() == 1 ) { d_close_page->setEnabled( false ); } } } void TabbedHtml::slotDuplicatePage() { HtmlView* part = new HtmlView( d_fname, d_ac, d_parent, d_parent, "d_html_view" ); connect( part, SIGNAL(setCaption(HtmlView*,const QString&)), this, SLOT(slotSetCaption(HtmlView*,const QString&)) ); QListViewItem* item = d_parent->getTopicTree()->currentItem(); part->slotSetUrl( item ); addTab( part->view(), item?item->text(0):i18n( "Empty" ) ); setCurrentPage( count() - 1 ); d_close_page->setEnabled( true ); } void TabbedHtml::slotPrevTab() { if ( !count() ) { return; } setCurrentPage( (currentPageIndex() + 1) % count() ); } void TabbedHtml::slotNextTab() { if ( !count() ) { return; } setCurrentPage( (currentPageIndex() + count() - 1) % count() ); } void TabbedHtml::slotSetCaption( HtmlView* part, const QString& caption ) { changeTab( part->view(), caption ); } void TabbedHtml::setZoomFactor( int percents ) { for ( int i = 0; i < count(); i++ ) { ToPart( page(i) )->setZoomFactor( percents ); } } void TabbedHtml::slotCopy() { currentView()->slotCopy(); } void TabbedHtml::slotCopyURL() { currentView()->slotCopyURL(); } void TabbedHtml::slotSelectAll() { currentView()->slotSelectAll(); } void TabbedHtml::slotCurrentTabChanged( QWidget* tab ) { HtmlView* part = ToPart( tab ); for ( int i = 0; i < count(); i++ ) { disconnect( ToPart( page(i) )->getHistory(), SIGNAL(stateChanged(bool,bool,bool)), 0, 0 ); disconnect( ToPart( page(i) )->getHistory(), SIGNAL(goUp()), 0, 0 ); } connect( part->getHistory(), SIGNAL(stateChanged(bool,bool,bool)), d_parent, SLOT(slotChangeState(bool,bool,bool)) ); connect( part->getHistory(), SIGNAL(goUp()), d_parent->getTopicTree(), SLOT(slotGoUp()) ); part->updateState(); } #include "TabbedHtml.moc"