1 /* This file is part of the KDE project
3 Copyright (C) 2002-2003 Konqueror Developers <konq-e@kde.org>
4 Copyright (C) 2002-2003 Douglas Hanley <douglash@caltech.edu>
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 Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 #include <QtGui/QApplication>
25 #include <QtGui/QClipboard>
26 #include <QtGui/QMenu>
27 #include <QtGui/QToolButton>
29 #include <kapplication.h>
30 #include <kcolorscheme.h>
32 #include <kiconloader.h>
34 #include <kstringhandler.h>
37 #include "konqviewmanager.h"
39 #include "konqsettingsxt.h"
40 #include "konqframevisitor.h"
41 #include "konqproxystyle.h"
43 #include <kacceleratormanager.h>
44 #include <konqpixmapprovider.h>
45 #include <kstandardshortcut.h>
46 #include <QtGui/QTabBar>
48 #include <QtGui/QStyle>
50 //###################################################################
52 class KonqTabsStyle
: public KonqProxyStyle
55 KonqTabsStyle(QWidget
*parent
) : KonqProxyStyle(parent
) {}
57 void drawPrimitive(PrimitiveElement element
, const QStyleOption
*option
, QPainter
*painter
, const QWidget
*widget
) const;
58 QRect
subElementRect(SubElement element
, const QStyleOption
*option
, const QWidget
*widget
) const;
61 void KonqTabsStyle::drawPrimitive(PrimitiveElement element
, const QStyleOption
*option
,
62 QPainter
*painter
, const QWidget
*widget
) const
64 if (element
== PE_FrameTabWidget
)
66 const KonqFrameTabs
*tw
= static_cast<const KonqFrameTabs
*>(widget
);
67 const QTabBar
*tb
= tw
->tabBar();
69 QStyleOptionTabV2 tab
;
71 tab
.shape
= tb
->shape();
72 int overlap
= style()->pixelMetric(PM_TabBarBaseOverlap
, &tab
, tb
);
74 if (overlap
<= 0 || tw
->isTabBarHidden())
77 QStyleOptionTabBarBase opt
;
80 opt
.selectedTabRect
= tb
->tabRect(tb
->currentIndex());
81 opt
.selectedTabRect
= QRect(tb
->mapToParent(opt
.selectedTabRect
.topLeft()), opt
.selectedTabRect
.size());
82 opt
.tabBarRect
= QRect(tb
->mapToParent(tb
->rect().topLeft()), tb
->size());
84 if (tw
->tabPosition() == QTabWidget::North
)
85 opt
.rect
= QRect(option
->rect
.left(), option
->rect
.top(), option
->rect
.width(), overlap
);
87 opt
.rect
= QRect(option
->rect
.left(), option
->rect
.bottom() - overlap
- 1, option
->rect
.width(), overlap
);
89 style()->drawPrimitive(PE_FrameTabBarBase
, &opt
, painter
, tb
);
93 KonqProxyStyle::drawPrimitive(element
, option
, painter
, widget
);
96 QRect
KonqTabsStyle::subElementRect(SubElement element
, const QStyleOption
*option
, const QWidget
*widget
) const
98 if (element
== SE_TabWidgetTabContents
)
100 QRect rect
= style()->subElementRect(SE_TabWidgetTabPane
, option
, widget
);
102 const KonqFrameTabs
*tw
= static_cast<const KonqFrameTabs
*>(widget
);
103 const QTabBar
*tb
= tw
->tabBar();
105 QStyleOptionTabV2 tab
;
107 tab
.shape
= tb
->shape();
108 int overlap
= style()->pixelMetric(PM_TabBarBaseOverlap
, &tab
, tw
->tabBar());
110 if (overlap
<= 0 || tw
->isTabBarHidden())
113 return tw
->tabPosition() == QTabWidget::North
?
114 rect
.adjusted(0, overlap
, 0, 0) : rect
.adjusted(0, 0, 0, -overlap
);
117 return KonqProxyStyle::subElementRect(element
, option
, widget
);
121 //###################################################################
124 KonqFrameTabs::KonqFrameTabs(QWidget
* parent
, KonqFrameContainerBase
* parentContainer
,
125 KonqViewManager
* viewManager
)
126 : KTabWidget(parent
),
128 m_pSubPopupMenuTab(0),
129 m_rightWidget(0), m_leftWidget(0), m_alwaysTabBar(false),
130 m_konqTabsStyle( new KonqTabsStyle( this ) )
132 // Set an object name so the widget style can identify this widget.
133 setObjectName("kde_konq_tabwidget");
135 KAcceleratorManager::setNoAccel(this);
137 // Set the widget style to a forwarding proxy style that removes the tabwidget frame,
138 // and draws a tabbar base underneath the tabbar.
139 setStyle(m_konqTabsStyle
);
141 // The base will be drawn on the frame instead of on the tabbar, so it extends across
143 tabBar()->setDrawBase(false);
145 tabBar()->setWhatsThis(i18n( "This bar contains the list of currently open tabs. Click on a tab to make it "
146 "active. You can also use keyboard shortcuts to "
147 "navigate through tabs. The text on the tab shows the content "
148 "currently open in it; place your mouse over the tab to see the full title, in "
149 "case it has been shortened to fit the tab width." ) );
150 //kDebug(1202) << "KonqFrameTabs::KonqFrameTabs()";
152 m_pParentContainer
= parentContainer
;
154 m_pViewManager
= viewManager
;
156 connect( this, SIGNAL( currentChanged ( int ) ),
157 this, SLOT( slotCurrentChanged( int ) ) );
159 m_MouseMiddleClickClosesTab
= KonqSettings::mouseMiddleClickClosesTab();
161 m_permanentCloseButtons
= KonqSettings::permanentCloseButton();
162 if (m_permanentCloseButtons
) {
163 setCloseButtonEnabled( true );
166 setCloseButtonEnabled( KonqSettings::hoverCloseButton() );
167 setTabCloseActivatePrevious( KonqSettings::tabCloseActivatePrevious() );
168 if (KonqSettings::tabPosition()=="Bottom")
169 setTabPosition( QTabWidget::South
);
170 connect( this, SIGNAL( closeRequest( QWidget
* )), SLOT(slotCloseRequest( QWidget
* )));
171 connect( this, SIGNAL( removeTabPopup() ),
172 m_pViewManager
->mainWindow(), SLOT( slotRemoveTabPopup() ) );
174 if ( KonqSettings::addTabButton() ) {
175 m_leftWidget
= new NewTabToolButton( this );
176 connect( m_leftWidget
, SIGNAL( clicked() ),
177 m_pViewManager
->mainWindow(), SLOT( slotAddTab() ) );
178 connect( m_leftWidget
, SIGNAL( testCanDecode(const QDragMoveEvent
*, bool & )),
179 SLOT( slotTestCanDecode(const QDragMoveEvent
*, bool & ) ) );
180 connect( m_leftWidget
, SIGNAL( receivedDropEvent( QDropEvent
* )),
181 SLOT( slotReceivedDropEvent( QDropEvent
* ) ) );
182 m_leftWidget
->setIcon( KIcon( "tab-new" ) );
183 m_leftWidget
->adjustSize();
184 m_leftWidget
->setToolTip( i18n("Open a new tab"));
185 setCornerWidget( m_leftWidget
, Qt::TopLeftCorner
);
187 if ( KonqSettings::closeTabButton() ) {
188 m_rightWidget
= new QToolButton( this );
189 connect( m_rightWidget
, SIGNAL( clicked() ),
190 m_pViewManager
->mainWindow(), SLOT( slotRemoveTab() ) );
191 m_rightWidget
->setIcon( KIcon( "tab-close" ) );
192 m_rightWidget
->adjustSize();
193 m_rightWidget
->setToolTip( i18n("Close the current tab"));
194 setCornerWidget( m_rightWidget
, Qt::TopRightCorner
);
197 setAutomaticResizeTabs( true );
198 setTabReorderingEnabled( true );
199 connect( this, SIGNAL( movedTab( int, int ) ),
200 SLOT( slotMovedTab( int, int ) ) );
201 connect( this, SIGNAL( mouseMiddleClick() ),
202 SLOT( slotMouseMiddleClick() ) );
203 connect( this, SIGNAL( mouseMiddleClick( QWidget
* ) ),
204 SLOT( slotMouseMiddleClick( QWidget
* ) ) );
205 connect( this, SIGNAL( mouseDoubleClick() ),
206 m_pViewManager
->mainWindow(), SLOT( slotAddTab() ) );
208 connect( this, SIGNAL( testCanDecode(const QDragMoveEvent
*, bool & )),
209 SLOT( slotTestCanDecode(const QDragMoveEvent
*, bool & ) ) );
210 connect( this, SIGNAL( receivedDropEvent( QDropEvent
* )),
211 SLOT( slotReceivedDropEvent( QDropEvent
* ) ) );
212 connect( this, SIGNAL( receivedDropEvent( QWidget
*, QDropEvent
* )),
213 SLOT( slotReceivedDropEvent( QWidget
*, QDropEvent
* ) ) );
214 connect( this, SIGNAL( initiateDrag( QWidget
* )),
215 SLOT( slotInitiateDrag( QWidget
* ) ) );
221 KonqFrameTabs::~KonqFrameTabs()
223 //kDebug(1202) << "KonqFrameTabs::~KonqFrameTabs() " << this << " - " << className();
224 qDeleteAll( m_childFrameList
);
225 m_childFrameList
.clear();
226 delete m_konqTabsStyle
;
229 void KonqFrameTabs::saveConfig( KConfigGroup
& config
, const QString
&prefix
, const KonqFrameBase::Options
&options
,
230 KonqFrameBase
* docContainer
, int id
, int depth
)
236 foreach (KonqFrameBase
* frame
, m_childFrameList
)
238 newPrefix
= KonqFrameBase::frameTypeToString(frame
->frameType()) + 'T' + QString::number(i
);
239 strlst
.append( newPrefix
);
240 newPrefix
.append( QLatin1Char( '_' ) );
241 frame
->saveConfig( config
, newPrefix
, options
, docContainer
, id
, depth
+ i
);
245 config
.writeEntry( QString::fromLatin1( "Children" ).prepend( prefix
), strlst
);
247 config
.writeEntry( QString::fromLatin1( "activeChildIndex" ).prepend( prefix
),
251 void KonqFrameTabs::copyHistory( KonqFrameBase
*other
)
255 kDebug(1202) << "The Frame does not exist";
259 if(other
->frameType() != KonqFrameBase::Tabs
) {
260 kDebug(1202) << "Frame types are not the same";
264 for (int i
= 0; i
< m_childFrameList
.count(); i
++ )
266 m_childFrameList
.at(i
)->copyHistory( static_cast<KonqFrameTabs
*>( other
)->m_childFrameList
.at(i
) );
270 void KonqFrameTabs::setTitle( const QString
&title
, QWidget
* sender
)
272 // kDebug(1202) << "KonqFrameTabs::setTitle( " << title << " , " << sender << " )";
273 setTabText( indexOf( sender
), title
);
276 void KonqFrameTabs::setTabIcon( const KUrl
&url
, QWidget
* sender
)
278 //kDebug(1202) << "KonqFrameTabs::setTabIcon( " << url << " , " << sender << " )";
279 KIcon iconSet
= KIcon( KonqPixmapProvider::self()->iconNameFor( url
) );
280 const int pos
= indexOf(sender
);
281 if (tabIcon(pos
).pixmap(iconSize()).serialNumber() != iconSet
.pixmap(iconSize()).serialNumber())
282 KTabWidget::setTabIcon( pos
, iconSet
);
285 void KonqFrameTabs::activateChild()
287 if (m_pActiveChild
) {
288 setCurrentIndex( indexOf( m_pActiveChild
->asQWidget() ) );
289 m_pActiveChild
->activateChild();
293 void KonqFrameTabs::insertChildFrame( KonqFrameBase
* frame
, int index
)
295 //kDebug(1202) << "KonqFrameTabs " << this << ": insertChildFrame " << frame;
298 kWarning(1202) << "KonqFrameTabs " << this << ": insertChildFrame(0) !" ;
302 //kDebug(1202) << "Adding frame";
304 //QTabWidget docs say that inserting tabs while already shown causes
306 setUpdatesEnabled(false);
308 frame
->setParentContainer(this);
310 m_childFrameList
.append(frame
);
312 m_childFrameList
.insert(index
, frame
);
315 // note that this can call slotCurrentChanged (e.g. when inserting/replacing the first tab)
316 insertTab(index
, frame
->asQWidget(), "");
319 m_rightWidget
->setEnabled( m_childFrameList
.count() > 1 );
322 if (KonqView
* activeChildView
= frame
->activeChildView()) {
323 activeChildView
->setCaption( activeChildView
->caption() );
324 activeChildView
->setTabIcon( activeChildView
->url() );
327 updateTabBarVisibility();
328 setUpdatesEnabled(true);
331 void KonqFrameTabs::childFrameRemoved( KonqFrameBase
* frame
)
333 //kDebug(1202) << "KonqFrameTabs::RemoveChildFrame " << this << ". Child " << frame << " removed";
335 removeTab(indexOf(frame
->asQWidget()));
336 m_childFrameList
.removeAll(frame
);
338 m_rightWidget
->setEnabled( m_childFrameList
.count()>1 );
340 updateTabBarVisibility();
343 kWarning(1202) << "KonqFrameTabs " << this << ": childFrameRemoved(0L) !" ;
345 //kDebug(1202) << "KonqFrameTabs::RemoveChildFrame finished";
348 void KonqFrameTabs::moveTabBackward( int index
)
352 moveTab( index
, index
-1 );
355 void KonqFrameTabs::moveTabForward( int index
)
357 if ( index
== count()-1 )
359 moveTab( index
, index
+1 );
362 void KonqFrameTabs::slotMovedTab( int from
, int to
)
364 KonqFrameBase
* fromFrame
= m_childFrameList
.at( from
);
365 m_childFrameList
.removeAll( fromFrame
);
366 m_childFrameList
.insert( to
, fromFrame
);
368 KonqFrameBase
* currentFrame
= dynamic_cast<KonqFrameBase
*>( currentWidget() );
369 if ( currentFrame
&& !m_pViewManager
->isLoadingProfile() ) {
370 m_pActiveChild
= currentFrame
;
371 currentFrame
->activateChild();
375 void KonqFrameTabs::slotContextMenu( const QPoint
&p
)
377 refreshSubPopupMenuTab();
378 m_popupActions
["reload"]->setEnabled( false );
379 m_popupActions
["duplicatecurrenttab"]->setEnabled( false );
380 m_popupActions
["breakoffcurrenttab"]->setEnabled( false );
381 m_popupActions
["removecurrenttab"]->setEnabled( false );
382 m_popupActions
["othertabs"]->setEnabled( true );
383 m_popupActions
["closeothertabs"]->setEnabled( false );
385 m_pPopupMenu
->exec( p
);
388 void KonqFrameTabs::slotContextMenu( QWidget
*w
, const QPoint
&p
)
390 refreshSubPopupMenuTab();
391 uint tabCount
= m_childFrameList
.count();
392 m_popupActions
["reload"]->setEnabled( true );
393 m_popupActions
["duplicatecurrenttab"]->setEnabled( true );
394 m_popupActions
["breakoffcurrenttab"]->setEnabled( tabCount
> 1 );
395 m_popupActions
["removecurrenttab"]->setEnabled( tabCount
> 1 );
396 m_popupActions
["othertabs"]->setEnabled( true );
397 m_popupActions
["closeothertabs"]->setEnabled( true );
399 // Yes, I know this is an unchecked dynamic_cast - I'm casting sideways in a
400 // class hierarchy and it could crash one day, but I haven't checked
401 // setWorkingTab so I don't know if it can handle nulls.
403 m_pViewManager
->mainWindow()->setWorkingTab( dynamic_cast<KonqFrameBase
*>(w
) );
404 m_pPopupMenu
->exec( p
);
407 void KonqFrameTabs::refreshSubPopupMenuTab()
409 m_pSubPopupMenuTab
->clear();
411 m_pSubPopupMenuTab
->addAction( KIcon( "view-refresh" ),
412 i18n( "&Reload All Tabs" ),
413 m_pViewManager
->mainWindow(),
414 SLOT( slotReloadAllTabs() ),
415 m_pViewManager
->mainWindow()->action("reload_all_tabs")->shortcut() );
416 m_pSubPopupMenuTab
->addSeparator();
417 foreach (KonqFrameBase
* frameBase
, m_childFrameList
)
419 KonqFrame
* frame
= dynamic_cast<KonqFrame
*>(frameBase
);
420 if ( frame
&& frame
->activeChildView() )
422 QString title
= frame
->title().trimmed();
423 const KUrl url
= frame
->activeChildView()->url();
424 if ( title
.isEmpty() )
425 title
= url
.pathOrUrl();
426 title
= KStringHandler::csqueeze( title
, 50 );
427 QAction
*action
= m_pSubPopupMenuTab
->addAction( KIcon( KonqPixmapProvider::self()->iconNameFor(url
) ), title
);
428 action
->setData( i
);
432 m_pSubPopupMenuTab
->addSeparator();
433 m_popupActions
["closeothertabs"] =
434 m_pSubPopupMenuTab
->addAction( KIcon( "tab-close-other" ),
435 i18n( "Close &Other Tabs" ),
436 m_pViewManager
->mainWindow(),
437 SLOT( slotRemoveOtherTabsPopup() ),
438 m_pViewManager
->mainWindow()->action("removeothertabs")->shortcut() );
441 void KonqFrameTabs::slotCloseRequest( QWidget
*w
)
443 if ( m_childFrameList
.count() > 1 ) {
444 // Yes, I know this is an unchecked dynamic_cast - I'm casting sideways in a class hierarchy and it could crash one day, but I haven't checked setWorkingTab so I don't know if it can handle nulls.
445 m_pViewManager
->mainWindow()->setWorkingTab( dynamic_cast<KonqFrameBase
*>(w
) );
446 emit
removeTabPopup();
450 void KonqFrameTabs::slotSubPopupMenuTabActivated( QAction
*action
)
452 setCurrentIndex( action
->data().toInt() );
455 void KonqFrameTabs::slotMouseMiddleClick()
457 KUrl
filteredURL ( KonqMisc::konqFilteredURL( this, QApplication::clipboard()->text(QClipboard::Selection
) ) );
458 if ( !filteredURL
.isEmpty() ) {
459 KonqView
* newView
= m_pViewManager
->addTab("text/html", QString(), false, false);
460 if (newView
== 0L) return;
461 m_pViewManager
->mainWindow()->openUrl( newView
, filteredURL
, QString() );
462 m_pViewManager
->showTab( newView
);
463 m_pViewManager
->mainWindow()->focusLocationBar();
467 void KonqFrameTabs::slotMouseMiddleClick( QWidget
*w
)
469 if ( m_MouseMiddleClickClosesTab
) {
470 if ( m_childFrameList
.count() > 1 ) {
471 // Yes, I know this is an unchecked dynamic_cast - I'm casting sideways in a class hierarchy and it could crash one day, but I haven't checked setWorkingTab so I don't know if it can handle nulls.
472 m_pViewManager
->mainWindow()->setWorkingTab( dynamic_cast<KonqFrameBase
*>(w
) );
473 emit
removeTabPopup();
477 KUrl
filteredURL ( KonqMisc::konqFilteredURL( this, QApplication::clipboard()->text(QClipboard::Selection
) ) );
478 if ( !filteredURL
.isEmpty() ) {
479 KonqFrameBase
* frame
= dynamic_cast<KonqFrameBase
*>(w
);
481 m_pViewManager
->mainWindow()->openUrl( frame
->activeChildView(), filteredURL
);
487 void KonqFrameTabs::slotTestCanDecode(const QDragMoveEvent
*e
, bool &accept
/* result */)
489 accept
= KUrl::List::canDecode( e
->mimeData() );
492 void KonqFrameTabs::slotReceivedDropEvent( QDropEvent
*e
)
494 const KUrl::List lstDragURLs
= KUrl::List::fromMimeData( e
->mimeData() );
495 if ( !lstDragURLs
.isEmpty() ) {
496 KonqView
* newView
= m_pViewManager
->addTab("text/html", QString(), false, false);
497 if (newView
== 0L) return;
498 m_pViewManager
->mainWindow()->openUrl( newView
, lstDragURLs
.first(), QString() );
499 m_pViewManager
->showTab( newView
);
500 m_pViewManager
->mainWindow()->focusLocationBar();
504 void KonqFrameTabs::slotReceivedDropEvent( QWidget
*w
, QDropEvent
*e
)
506 KUrl::List lstDragURLs
= KUrl::List::fromMimeData( e
->mimeData() );
507 KonqFrameBase
* frame
= dynamic_cast<KonqFrameBase
*>(w
);
508 if ( lstDragURLs
.count() && frame
) {
509 const KUrl dragUrl
= lstDragURLs
.first();
510 if ( dragUrl
!= frame
->activeChildView()->url() ) {
511 emit
openUrl(frame
->activeChildView(), dragUrl
);
516 void KonqFrameTabs::slotInitiateDrag( QWidget
*w
)
518 KonqFrameBase
* frame
= dynamic_cast<KonqFrameBase
*>( w
);
520 QDrag
*d
= new QDrag( this );
521 QMimeData
* md
= new QMimeData();
522 frame
->activeChildView()->url().populateMimeData(md
);
523 d
->setMimeData( md
);
524 QString iconName
= KMimeType::iconNameForUrl(frame
->activeChildView()->url());
525 d
->setPixmap(KIconLoader::global()->loadIcon(iconName
, KIconLoader::Small
, 0));
526 //d->setPixmap( KIconLoader::global()->loadMimeTypeIcon(KMimeType::pixmapForURL( frame->activeChildView()->url(), 0), KIconLoader::Small ) );
531 void KonqFrameTabs::updateTabBarVisibility()
533 if ( m_alwaysTabBar
) {
534 setTabBarHidden(false);
536 setTabBarHidden(count() <= 1);
540 void KonqFrameTabs::setAlwaysTabbedMode( bool enable
)
542 const bool update
= ( enable
!= m_alwaysTabBar
);
543 m_alwaysTabBar
= enable
;
545 updateTabBarVisibility();
549 void KonqFrameTabs::initPopupMenu()
551 m_pPopupMenu
= new QMenu( this );
552 m_popupActions
["newtab"] = m_pPopupMenu
->addAction( KIcon( "tab-new" ),
554 m_pViewManager
->mainWindow(),
555 SLOT( slotAddTab() ),
556 m_pViewManager
->mainWindow()->action("newtab")->shortcut() );
557 m_popupActions
["duplicatecurrenttab"] = m_pPopupMenu
->addAction( KIcon( "tab-duplicate" ),
558 i18n("&Duplicate Tab"),
559 m_pViewManager
->mainWindow(),
560 SLOT( slotDuplicateTabPopup() ),
561 m_pViewManager
->mainWindow()->action("duplicatecurrenttab")->shortcut() );
562 m_popupActions
["reload"] = m_pPopupMenu
->addAction( KIcon( "view-refresh" ),
563 i18n( "&Reload Tab" ),
564 m_pViewManager
->mainWindow(),
565 SLOT( slotReloadPopup() ),
566 m_pViewManager
->mainWindow()->action("reload")->shortcut() );
567 m_pPopupMenu
->addSeparator();
568 m_pSubPopupMenuTab
= new QMenu( this );
569 m_popupActions
["othertabs"] = m_pPopupMenu
->addMenu( m_pSubPopupMenuTab
);
570 m_popupActions
["othertabs"]->setText( i18n("Other Tabs") );
571 connect( m_pSubPopupMenuTab
, SIGNAL( triggered ( QAction
* ) ),
572 this, SLOT( slotSubPopupMenuTabActivated( QAction
* ) ) );
573 m_pPopupMenu
->addSeparator();
574 m_popupActions
["breakoffcurrenttab"] = m_pPopupMenu
->addAction( KIcon( "tab-detach" ),
576 m_pViewManager
->mainWindow(),
577 SLOT( slotBreakOffTabPopup() ),
578 m_pViewManager
->mainWindow()->action("breakoffcurrenttab")->shortcut() );
579 m_pPopupMenu
->addSeparator();
580 m_popupActions
["removecurrenttab"] = m_pPopupMenu
->addAction( KIcon( "tab-close" ),
582 m_pViewManager
->mainWindow(),
583 SLOT( slotRemoveTabPopup() ),
584 m_pViewManager
->mainWindow()->action("removecurrenttab")->shortcut() );
585 connect( this, SIGNAL( contextMenu( QWidget
*, const QPoint
& ) ),
586 SLOT(slotContextMenu( QWidget
*, const QPoint
& ) ) );
587 connect( this, SIGNAL( contextMenu( const QPoint
& ) ),
588 SLOT(slotContextMenu( const QPoint
& ) ) );
592 bool KonqFrameTabs::accept( KonqFrameVisitor
* visitor
)
594 if ( !visitor
->visit( this ) )
596 foreach( KonqFrameBase
* frame
, m_childFrameList
) {
598 if ( !frame
->accept( visitor
) )
601 if ( !visitor
->endVisit( this ) )
606 void KonqFrameTabs::slotCurrentChanged( int index
)
608 const KColorScheme
colorScheme(QPalette::Active
, KColorScheme::Window
);
609 setTabTextColor(index
, colorScheme
.foreground(KColorScheme::NormalText
).color());
611 KonqFrameBase
* currentFrame
= dynamic_cast<KonqFrameBase
*>(widget( index
));
612 if (currentFrame
&& !m_pViewManager
->isLoadingProfile()) {
613 m_pActiveChild
= currentFrame
;
614 currentFrame
->activateChild();
619 * Returns the index position of the tab that contains (directly or indirectly) the frame @p frame,
620 * or -1 if the frame is not in the tab widget.
622 KonqFrameBase
* KonqFrameTabs::tabContaining(KonqFrameBase
* frame
) const
624 KonqFrameBase
* frameBase
= frame
;
625 while (frameBase
&& frameBase
->parentContainer() != this)
626 frameBase
= frameBase
->parentContainer();
633 int KonqFrameTabs::tabWhereActive(KonqFrameBase
* frame
) const
635 for (int i
= 0; i
< m_childFrameList
.count(); i
++ ) {
636 KonqFrameBase
* f
= m_childFrameList
.at(i
);
637 while (f
&& f
!= frame
) {
638 f
= f
->isContainer() ? static_cast<KonqFrameContainerBase
*>(f
)->activeChild() : 0;
646 void KonqFrameTabs::setLoading(KonqFrameBase
* frame
, bool loading
)
648 const int pos
= tabWhereActive(frame
);
652 const KColorScheme
colorScheme(QPalette::Active
, KColorScheme::Window
);
655 color
= colorScheme
.foreground(KColorScheme::NeutralText
).color(); // a tab is currently loading
657 if (currentIndex() != pos
) {
658 // another tab has newly loaded contents. Use "link" because you can click on it to read it.
659 color
= colorScheme
.foreground(KColorScheme::LinkText
).color();
661 // the current tab has finished loading.
662 color
= colorScheme
.foreground(KColorScheme::NormalText
).color();
665 setTabTextColor(pos
, color
);
668 void KonqFrameTabs::replaceChildFrame(KonqFrameBase
* oldFrame
, KonqFrameBase
* newFrame
)
670 const int index
= indexOf(oldFrame
->asQWidget());
671 childFrameRemoved(oldFrame
);
672 insertChildFrame(newFrame
, index
);
673 setCurrentIndex(index
);
676 #include "konqtabs.moc"