delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / apps / konqueror / src / konqframe.cpp
blob26f4b6251b39b43561add9fb3ac345e779cb8634
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 QString KonqFrameBase::frameTypeToString( const KonqFrameBase::FrameType frameType )
52 switch ( frameType ) {
53 case View :
54 return QString("View");
55 case Tabs :
56 return QString("Tabs");
57 case ContainerBase :
58 return QString("ContainerBase");
59 case Container :
60 return QString("Container");
61 case MainWindow :
62 return QString("MainWindow");
64 Q_ASSERT(0);
65 return QString();
68 KonqFrameBase::FrameType frameTypeFromString( const QString& str )
70 if ( str == "View" )
71 return KonqFrameBase::View;
72 if ( str == "Tabs" )
73 return KonqFrameBase::Tabs;
74 if ( str == "ContainerBase" )
75 return KonqFrameBase::ContainerBase;
76 if ( str == "Container" )
77 return KonqFrameBase::Container;
78 if ( str == "MainWindow" )
79 return KonqFrameBase::MainWindow;
80 Q_ASSERT(0);
81 return KonqFrameBase::View;
84 KonqFrame::KonqFrame( QWidget* parent, KonqFrameContainerBase *parentContainer )
85 : QWidget ( parent )
87 //kDebug(1202) << "KonqFrame::KonqFrame()";
89 m_pLayout = 0L;
90 m_pView = 0L;
92 // the frame statusbar
93 m_pStatusBar = new KonqFrameStatusBar( this);
94 m_pStatusBar->setSizePolicy(QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
95 connect(m_pStatusBar, SIGNAL(clicked()), this, SLOT(slotStatusBarClicked()));
96 connect( m_pStatusBar, SIGNAL( linkedViewClicked( bool ) ), this, SLOT( slotLinkedViewClicked( bool ) ) );
97 m_separator = 0;
98 m_pParentContainer = parentContainer;
101 KonqFrame::~KonqFrame()
103 //kDebug(1202) << "KonqFrame::~KonqFrame() " << this;
106 bool KonqFrame::isActivePart()
108 return ( m_pView &&
109 static_cast<KonqView*>(m_pView) == m_pView->mainWindow()->currentView() );
112 void KonqFrame::saveConfig( KConfigGroup& config, const QString &prefix, const KonqFrameBase::Options &options, KonqFrameBase* docContainer, int /*id*/, int /*depth*/ )
114 childView()->saveConfig(config, prefix, options);
115 //config.writeEntry( QString::fromLatin1( "ShowStatusBar" ).prepend( prefix ), statusbar()->isVisible() );
116 if (this == docContainer) config.writeEntry( QString::fromLatin1( "docContainer" ).prepend( prefix ), true );
118 #if 0 // currently unused
119 KonqConfigEvent ev( config.config(), prefix+'_', true/*save*/);
120 QApplication::sendEvent( childView()->part(), &ev );
121 #endif
124 void KonqFrame::copyHistory( KonqFrameBase *other )
126 assert(other->frameType() == KonqFrameBase::View);
127 childView()->copyHistory( static_cast<KonqFrame *>( other )->childView() );
130 KParts::ReadOnlyPart *KonqFrame::attach( const KonqViewFactory &viewFactory )
132 KonqViewFactory factory( viewFactory );
134 // Note that we set the parent to 0.
135 // We don't want that deleting the widget deletes the part automatically
136 // because we already have that taken care of in KParts...
138 m_pPart = factory.create( this, 0 );
140 assert( m_pPart->widget() );
142 attachWidget(m_pPart->widget());
144 m_pStatusBar->slotConnectToNewView(0, 0, m_pPart);
146 return m_pPart;
149 void KonqFrame::attachWidget(QWidget* widget)
151 //kDebug(1202) << "KonqFrame::attachInternal()";
152 delete m_pLayout;
154 m_pLayout = new QVBoxLayout( this );
155 m_pLayout->setObjectName( "KonqFrame's QVBoxLayout" );
156 m_pLayout->setMargin( 0 );
157 m_pLayout->setSpacing( 0 );
159 m_pLayout->addWidget( widget, 1 );
160 m_pLayout->addWidget( m_pStatusBar, 0 );
161 widget->show();
163 m_pLayout->activate();
165 widget->installEventFilter(this);
168 bool KonqFrame::eventFilter(QObject* /*obj*/, QEvent *ev)
170 if (ev->type()==QEvent::KeyPress)
172 QKeyEvent * keyEv = static_cast<QKeyEvent*>(ev);
173 if ((keyEv->key()==Qt::Key_Tab) && (keyEv->modifiers()==Qt::ControlModifier))
175 emit ((KonqFrameContainer*)parent())->ctrlTabPressed();
176 return true;
179 return false;
182 void KonqFrame::insertTopWidget( QWidget * widget )
184 assert(m_pLayout);
185 assert(widget);
186 m_pLayout->insertWidget( 0, widget );
187 widget->installEventFilter(this);
190 void KonqFrame::setView( KonqView* child )
192 m_pView = child;
193 if (m_pView)
195 connect(m_pView,SIGNAL(sigPartChanged(KonqView *, KParts::ReadOnlyPart *,KParts::ReadOnlyPart *)),
196 m_pStatusBar,SLOT(slotConnectToNewView(KonqView *, KParts::ReadOnlyPart *,KParts::ReadOnlyPart *)));
200 void KonqFrame::setTitle( const QString &title , QWidget* /*sender*/)
202 //kDebug(1202) << "KonqFrame::setTitle( " << title << " )";
203 m_title = title;
204 if (m_pParentContainer) m_pParentContainer->setTitle( title , this);
207 void KonqFrame::setTabIcon( const KUrl &url, QWidget* /*sender*/ )
209 //kDebug(1202) << "KonqFrame::setTabIcon( " << url << " )";
210 if (m_pParentContainer) m_pParentContainer->setTabIcon( url, this );
213 void KonqFrame::slotStatusBarClicked()
215 if ( !isActivePart() && m_pView && !m_pView->isPassiveMode() )
216 m_pView->mainWindow()->viewManager()->setActivePart( part() );
219 void KonqFrame::slotLinkedViewClicked( bool mode )
221 if ( m_pView->mainWindow()->linkableViewsCount() == 2 )
222 m_pView->mainWindow()->slotLinkView();
223 else
224 m_pView->setLinkedView( mode );
227 void
228 KonqFrame::paintEvent( QPaintEvent* )
230 #ifdef __GNUC__
231 #warning "m_pStatusBar->repaint() leads to endless recursion; does anyone know why it's needed?"
232 #endif
233 // m_pStatusBar->repaint();
236 void KonqFrame::slotRemoveView()
238 m_pView->mainWindow()->viewManager()->removeView( m_pView );
241 void KonqFrame::activateChild()
243 if (m_pView && !m_pView->isPassiveMode() )
244 m_pView->mainWindow()->viewManager()->setActivePart( part() );
247 KonqView* KonqFrame::childView() const
249 return m_pView;
252 KonqView* KonqFrame::activeChildView() const
254 return m_pView;
257 bool KonqFrame::accept( KonqFrameVisitor* visitor )
259 return visitor->visit( this );
262 #include "konqframe.moc"