Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / konqueror / src / konqframe.cpp
blob7f08f583438e05da605746a5a5512194312c249b
1 /* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Michael Reiher <michael.reiher@gmx.de>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 // Own
21 #include "konqframe.h"
23 // Local
24 #include "konqtabs.h"
25 #include "konqview.h"
26 #include "konqviewmanager.h"
27 #include "konqframevisitor.h"
28 #include "konqframestatusbar.h"
30 // std
31 #include <assert.h>
33 // Qt
34 #include <QtGui/QKeyEvent>
35 #include <QtGui/QApplication>
36 #include <QtCore/QEvent>
37 #include <QtGui/QLabel>
38 #include <QtGui/QBoxLayout>
40 // KDE
41 #include <kactioncollection.h>
42 #include <kdebug.h>
43 #include <kicon.h>
44 #include <kiconloader.h>
45 #include <klocale.h>
46 #include <ksqueezedtextlabel.h>
47 #include <konq_events.h>
48 #include <kconfiggroup.h>
50 KonqFrame::KonqFrame( QWidget* parent, KonqFrameContainerBase *parentContainer )
51 : QWidget ( parent )
53 //kDebug(1202) << "KonqFrame::KonqFrame()";
55 m_pLayout = 0L;
56 m_pView = 0L;
58 // the frame statusbar
59 m_pStatusBar = new KonqFrameStatusBar( this);
60 m_pStatusBar->setSizePolicy(QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
61 connect(m_pStatusBar, SIGNAL(clicked()), this, SLOT(slotStatusBarClicked()));
62 connect( m_pStatusBar, SIGNAL( linkedViewClicked( bool ) ), this, SLOT( slotLinkedViewClicked( bool ) ) );
63 m_separator = 0;
64 m_pParentContainer = parentContainer;
67 KonqFrame::~KonqFrame()
69 //kDebug(1202) << "KonqFrame::~KonqFrame() " << this;
72 bool KonqFrame::isActivePart()
74 return ( m_pView &&
75 static_cast<KonqView*>(m_pView) == m_pView->mainWindow()->currentView() );
78 void KonqFrame::saveConfig( KConfigGroup& config, const QString &prefix, const KonqFrameBase::Options &options, KonqFrameBase* docContainer, int /*id*/, int /*depth*/ )
80 childView()->saveConfig(config, prefix, options);
81 //config.writeEntry( QString::fromLatin1( "ShowStatusBar" ).prepend( prefix ), statusbar()->isVisible() );
82 if (this == docContainer) config.writeEntry( QString::fromLatin1( "docContainer" ).prepend( prefix ), true );
84 #if 0 // currently unused
85 KonqConfigEvent ev( config.config(), prefix+'_', true/*save*/);
86 QApplication::sendEvent( childView()->part(), &ev );
87 #endif
90 void KonqFrame::copyHistory( KonqFrameBase *other )
92 assert( other->frameType() == "View" );
93 childView()->copyHistory( static_cast<KonqFrame *>( other )->childView() );
96 KParts::ReadOnlyPart *KonqFrame::attach( const KonqViewFactory &viewFactory )
98 KonqViewFactory factory( viewFactory );
100 // Note that we set the parent to 0.
101 // We don't want that deleting the widget deletes the part automatically
102 // because we already have that taken care of in KParts...
104 m_pPart = factory.create( this, 0 );
106 assert( m_pPart->widget() );
108 attachWidget(m_pPart->widget());
110 m_pStatusBar->slotConnectToNewView(0, 0, m_pPart);
112 return m_pPart;
115 void KonqFrame::attachWidget(QWidget* widget)
117 //kDebug(1202) << "KonqFrame::attachInternal()";
118 delete m_pLayout;
120 m_pLayout = new QVBoxLayout( this );
121 m_pLayout->setObjectName( "KonqFrame's QVBoxLayout" );
122 m_pLayout->setMargin( 0 );
123 m_pLayout->setSpacing( 0 );
125 m_pLayout->addWidget( widget, 1 );
126 m_pLayout->addWidget( m_pStatusBar, 0 );
127 widget->show();
129 m_pLayout->activate();
131 widget->installEventFilter(this);
134 bool KonqFrame::eventFilter(QObject* /*obj*/, QEvent *ev)
136 if (ev->type()==QEvent::KeyPress)
138 QKeyEvent * keyEv = static_cast<QKeyEvent*>(ev);
139 if ((keyEv->key()==Qt::Key_Tab) && (keyEv->modifiers()==Qt::ControlModifier))
141 emit ((KonqFrameContainer*)parent())->ctrlTabPressed();
142 return true;
145 return false;
148 void KonqFrame::insertTopWidget( QWidget * widget )
150 assert(m_pLayout);
151 assert(widget);
152 m_pLayout->insertWidget( 0, widget );
153 widget->installEventFilter(this);
156 void KonqFrame::setView( KonqView* child )
158 m_pView = child;
159 if (m_pView)
161 connect(m_pView,SIGNAL(sigPartChanged(KonqView *, KParts::ReadOnlyPart *,KParts::ReadOnlyPart *)),
162 m_pStatusBar,SLOT(slotConnectToNewView(KonqView *, KParts::ReadOnlyPart *,KParts::ReadOnlyPart *)));
166 void KonqFrame::setTitle( const QString &title , QWidget* /*sender*/)
168 //kDebug(1202) << "KonqFrame::setTitle( " << title << " )";
169 m_title = title;
170 if (m_pParentContainer) m_pParentContainer->setTitle( title , this);
173 void KonqFrame::setTabIcon( const KUrl &url, QWidget* /*sender*/ )
175 //kDebug(1202) << "KonqFrame::setTabIcon( " << url << " )";
176 if (m_pParentContainer) m_pParentContainer->setTabIcon( url, this );
179 void KonqFrame::slotStatusBarClicked()
181 if ( !isActivePart() && m_pView && !m_pView->isPassiveMode() )
182 m_pView->mainWindow()->viewManager()->setActivePart( part() );
185 void KonqFrame::slotLinkedViewClicked( bool mode )
187 if ( m_pView->mainWindow()->linkableViewsCount() == 2 )
188 m_pView->mainWindow()->slotLinkView();
189 else
190 m_pView->setLinkedView( mode );
193 void
194 KonqFrame::paintEvent( QPaintEvent* )
196 #ifdef __GNUC__
197 #warning "m_pStatusBar->repaint() leads to endless recursion; does anyone know why it's needed?"
198 #endif
199 // m_pStatusBar->repaint();
202 void KonqFrame::slotRemoveView()
204 m_pView->mainWindow()->viewManager()->removeView( m_pView );
207 void KonqFrame::activateChild()
209 if (m_pView && !m_pView->isPassiveMode() )
210 m_pView->mainWindow()->viewManager()->setActivePart( part() );
213 KonqView* KonqFrame::childView() const
215 return m_pView;
218 KonqView* KonqFrame::activeChildView() const
220 return m_pView;
223 bool KonqFrame::accept( KonqFrameVisitor* visitor )
225 return visitor->visit( this );
228 #include "konqframe.moc"