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.
21 #include "konqframe.h"
26 #include "konqviewmanager.h"
27 #include "konqframevisitor.h"
28 #include "konqframestatusbar.h"
34 #include <QtGui/QKeyEvent>
35 #include <QtGui/QApplication>
36 #include <QtCore/QEvent>
37 #include <QtGui/QLabel>
38 #include <QtGui/QBoxLayout>
41 #include <kactioncollection.h>
44 #include <kiconloader.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
) {
54 return QString("View");
56 return QString("Tabs");
58 return QString("ContainerBase");
60 return QString("Container");
62 return QString("MainWindow");
68 KonqFrameBase::FrameType
frameTypeFromString( const QString
& str
)
71 return KonqFrameBase::View
;
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
;
81 return KonqFrameBase::View
;
84 KonqFrame::KonqFrame( QWidget
* parent
, KonqFrameContainerBase
*parentContainer
)
87 //kDebug(1202) << "KonqFrame::KonqFrame()";
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 ) ) );
98 m_pParentContainer
= parentContainer
;
101 KonqFrame::~KonqFrame()
103 //kDebug(1202) << "KonqFrame::~KonqFrame() " << this;
106 bool KonqFrame::isActivePart()
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
);
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
);
149 void KonqFrame::attachWidget(QWidget
* widget
)
151 //kDebug(1202) << "KonqFrame::attachInternal()";
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 );
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();
182 void KonqFrame::insertTopWidget( QWidget
* widget
)
186 m_pLayout
->insertWidget( 0, widget
);
187 widget
->installEventFilter(this);
190 void KonqFrame::setView( KonqView
* child
)
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 << " )";
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();
224 m_pView
->setLinkedView( mode
);
228 KonqFrame::paintEvent( QPaintEvent
* )
231 #warning "m_pStatusBar->repaint() leads to endless recursion; does anyone know why it's needed?"
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
252 KonqView
* KonqFrame::activeChildView() const
257 bool KonqFrame::accept( KonqFrameVisitor
* visitor
)
259 return visitor
->visit( this );
262 #include "konqframe.moc"