1
/***************************************************************************
2
* Copyright (C) 2004-2005 by Georgy Yunaev, gyunaev@ulduzsoft.com *
3
* Please do not use email address above for bug reports; see *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License as published by *
8
* the Free Software Foundation; either version 2 of the License, or *
9
* (at your option) any later version. *
11
* This program is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU General Public License for more details. *
16
* You should have received a copy of the GNU General Public License *
17
* along with this program; if not, write to the *
18
* Free Software Foundation, Inc., *
19
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20
***************************************************************************/
22
#include "kchmconfig.h"
23
#include "kchmmainwindow.h"
24
#include "kchmviewwindow.h"
25
#include "kchmviewwindowmgr.h"
26
#include "iconstorage.h"
28
#include "kchmviewwindow_qtextbrowser.h"
31
#include "kchmviewwindow_khtmlpart.h"
35
KCHMViewWindowMgr::KCHMViewWindowMgr( QWidget *parent )
36
: QTabWidget( parent ) //QTabWidget
40
// on current tab changed
41
connect( this, SIGNAL( currentChanged(QWidget *) ), this, SLOT( onTabChanged(QWidget *) ) );
43
// Create an iconset for the button
44
QIconSet iset( *gIconStorage.getCloseWindowIcon() );
46
// Create a pushbutton
47
m_closeButton = new QPushButton( iset, QString::null, this );
48
m_closeButton->setFlat( true );
49
m_closeButton->setEnabled( false );
50
connect( m_closeButton, SIGNAL( clicked() ), this, SLOT( closeCurrentWindow() ) );
52
setCornerWidget( m_closeButton );
55
KCHMViewWindowMgr::~KCHMViewWindowMgr( )
59
void KCHMViewWindowMgr::createMenu( KCHMMainWindow * parent )
61
// Create the approptiate menu entries in 'View' main menu
62
m_MenuWindow = new KQPopupMenu( parent );
63
parent->menuBar()->insertItem( i18n( "&Window"), m_MenuWindow );
65
m_menuIdClose = m_MenuWindow->insertItem( i18n( "&Close"), this, SLOT( closeCurrentWindow()), CTRL+Key_W );
66
m_MenuWindow->insertSeparator();
68
connect( m_MenuWindow, SIGNAL( activated(int) ), this, SLOT ( onCloseWindow(int) ));
71
void KCHMViewWindowMgr::invalidate()
78
KCHMViewWindow * KCHMViewWindowMgr::current()
80
QWidget * w = currentPage();
83
if ( !w || (it = m_Windows.find( w )) == m_Windows.end() )
84
qFatal( "KCHMViewWindowMgr::current called without any windows!" );
86
return it.data().window;
89
KCHMViewWindow * KCHMViewWindowMgr::addNewTab( bool set_active )
91
KCHMViewWindow * viewvnd;
94
if ( !appConfig.m_kdeUseQTextBrowser )
95
viewvnd = new KCHMViewWindow_KHTMLPart( this );
98
viewvnd = new KCHMViewWindow_QTextBrowser( this );
100
QWidget * widget = viewvnd->getQWidget();
101
m_Windows[widget].window = viewvnd;
102
m_Windows[widget].menuitem = 0;
103
m_Windows[widget].widget = widget;
105
addTab( widget, "" );
107
Q_ASSERT( m_Windows.size() == (unsigned int) count() );
109
// Set active if it is the first tab
110
if ( set_active || m_Windows.size() == 1 )
113
// Handle clicking on link in browser window
114
connect( viewvnd->getQObject(), SIGNAL( signalLinkClicked (const QString &, bool &) ), ::mainWindow, SLOT( slotLinkClicked(const QString &, bool &) ) );
119
void KCHMViewWindowMgr::deleteAllWindows( )
121
// No it++ - we removing the window by every closeWindow call
122
while ( m_Windows.begin() != m_Windows.end() )
123
closeWindow( m_Windows.begin().data() );
126
void KCHMViewWindowMgr::setTabName( KCHMViewWindow * window )
128
WindowsIterator it = m_Windows.find( window->getQWidget() );
130
if ( it == m_Windows.end() )
131
qFatal( "KCHMViewWindowMgr::setTabName called with unknown window!" );
133
QString title = window->getTitle();
134
setTabLabel( window->getQWidget(), title );
136
if ( it.data().menuitem == 0 )
138
int menuid = m_Windows.size();
139
QString menutitle = "&" + QString::number(menuid) + " " + title;
140
it.data().menuitem = m_MenuWindow->insertItem( menutitle, menuid );
144
QString menutitle = "&" + QString::number(it.data().menuitem) + " " + title;
145
m_MenuWindow->changeItem( it.data().menuitem, menutitle );
148
updateCloseButtons();
151
void KCHMViewWindowMgr::closeCurrentWindow( )
153
// Do not allow to close the last window
154
if ( m_Windows.size() == 1 )
157
QWidget * w = currentPage();
160
if ( !w || (it = m_Windows.find( w )) == m_Windows.end() )
161
qFatal( "KCHMViewWindowMgr::closeCurrentWindow called without any windows!" );
163
closeWindow( it.data() );
166
void KCHMViewWindowMgr::closeWindow( const tab_window_t & tab )
168
WindowsIterator it = m_Windows.find( tab.widget );
170
if ( it == m_Windows.end() )
171
qFatal( "KCHMViewWindowMgr::closeWindow called with unknown widget!" );
173
if ( tab.menuitem != 0 )
174
m_MenuWindow->removeItem( tab.menuitem );
176
removePage( tab.widget );
179
m_Windows.remove( it );
180
updateCloseButtons();
183
void KCHMViewWindowMgr::onCloseWindow( int id )
185
for ( WindowsIterator it = m_Windows.begin(); it != m_Windows.end(); it++ )
187
if ( it.data().menuitem != id )
190
closeWindow( it.data() );
196
void KCHMViewWindowMgr::restoreSettings( const KCHMSettings::viewindow_saved_settings_t & settings )
198
// Destroy pre-created tab
199
closeWindow( m_Windows.begin().data() );
201
for ( unsigned int i = 0; i < settings.size(); i++ )
203
KCHMViewWindow * window = addNewTab( false );
204
window->openUrl( settings[i].url ); // will call setTabName()
205
window->setScrollbarPosition( settings[i].scroll_y );
206
window->setZoomFactor( settings[i].zoom );
211
void KCHMViewWindowMgr::saveSettings( KCHMSettings::viewindow_saved_settings_t & settings )
215
for ( int i = 0; i < count(); i++ )
217
QWidget * p = page( i );
218
WindowsIterator it = m_Windows.find( p );
220
if ( it == m_Windows.end() )
221
qFatal( "KCHMViewWindowMgr::saveSettings: could not find widget!" );
224
KCHMSettings::SavedViewWindow(
225
it.data().window->getOpenedPage(),
226
it.data().window->getScrollbarPosition(),
227
it.data().window->getZoomFactor()) );
231
void KCHMViewWindowMgr::updateCloseButtons( )
233
m_MenuWindow->setItemEnabled( m_menuIdClose, m_Windows.size() > 1 );
234
m_closeButton->setEnabled( m_Windows.size() > 1 );
237
void KCHMViewWindowMgr::onTabChanged( QWidget * newtab )
239
WindowsIterator it = m_Windows.find( newtab );
241
if ( it == m_Windows.end() )
242
qFatal( "KCHMViewWindowMgr::onTabChanged called with unknown widget!" );
244
it.data().window->updateNavigationToolbar();
245
mainWindow->slotBrowserChanged( it.data().window );
248
#include "kchmviewwindowmgr.moc"