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 KonqFrame::KonqFrame( QWidget
* parent
, KonqFrameContainerBase
*parentContainer
)
53 //kDebug(1202) << "KonqFrame::KonqFrame()";
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 ) ) );
64 m_pParentContainer
= parentContainer
;
67 KonqFrame::~KonqFrame()
69 //kDebug(1202) << "KonqFrame::~KonqFrame() " << this;
72 bool KonqFrame::isActivePart()
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
);
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
);
115 void KonqFrame::attachWidget(QWidget
* widget
)
117 //kDebug(1202) << "KonqFrame::attachInternal()";
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 );
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();
148 void KonqFrame::insertTopWidget( QWidget
* widget
)
152 m_pLayout
->insertWidget( 0, widget
);
153 widget
->installEventFilter(this);
156 void KonqFrame::setView( KonqView
* child
)
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 << " )";
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();
190 m_pView
->setLinkedView( mode
);
194 KonqFrame::paintEvent( QPaintEvent
* )
197 #warning "m_pStatusBar->repaint() leads to endless recursion; does anyone know why it's needed?"
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
218 KonqView
* KonqFrame::activeChildView() const
223 bool KonqFrame::accept( KonqFrameVisitor
* visitor
)
225 return visitor
->visit( this );
228 #include "konqframe.moc"