Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / konqueror / src / konqframecontainer.cpp
blobfbc0dacc4c53c208980c40492e6a68da37758ce6
1 /* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Michael Reiher <michael.reiher@gmx.de>
3 Copyright 2007 David Faure <faure@kde.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "konqframecontainer.h"
21 #include <kdebug.h>
22 #include <kglobalsettings.h>
23 #include <kconfig.h>
24 #include <math.h> // pow()
25 #include <kconfiggroup.h>
27 #include "konqframevisitor.h"
29 void KonqFrameContainerBase::replaceChildFrame(KonqFrameBase* oldFrame, KonqFrameBase* newFrame)
31 childFrameRemoved(oldFrame);
32 insertChildFrame(newFrame);
35 KonqFrameContainer* KonqFrameContainerBase::splitChildFrame(KonqFrameBase* splitFrame, Qt::Orientation orientation)
37 KonqFrameContainer *newContainer = new KonqFrameContainer(orientation, asQWidget(), this);
38 replaceChildFrame(splitFrame, newContainer);
39 newContainer->insertChildFrame(splitFrame);
40 return newContainer;
43 ////
45 KonqFrameContainer::KonqFrameContainer( Qt::Orientation o,
46 QWidget* parent,
47 KonqFrameContainerBase* parentContainer )
48 : QSplitter( o, parent ), m_bAboutToBeDeleted(false)
50 m_pParentContainer = parentContainer;
51 m_pFirstChild = 0L;
52 m_pSecondChild = 0L;
53 m_pActiveChild = 0L;
54 setOpaqueResize( KGlobalSettings::opaqueResize() );
55 connect(this, SIGNAL(splitterMoved(int, int)), this, SIGNAL(setRubberbandCalled()));
56 //### CHECKME
59 KonqFrameContainer::~KonqFrameContainer()
61 //kDebug(1202) << "KonqFrameContainer::~KonqFrameContainer() " << this << " - " << className();
62 delete m_pFirstChild;
63 delete m_pSecondChild;
66 void KonqFrameContainer::saveConfig( KConfigGroup& config, const QString &prefix, const KonqFrameBase::Options &options, KonqFrameBase* docContainer, int id, int depth )
68 int idSecond = id + (int)pow( 2.0, depth );
70 //write children sizes
71 config.writeEntry( QString::fromLatin1( "SplitterSizes" ).prepend( prefix ), sizes() );
73 //write children
74 QStringList strlst;
75 if( firstChild() )
76 strlst.append( QString::fromLatin1( firstChild()->frameType() ) + QString::number(idSecond - 1) );
77 if( secondChild() )
78 strlst.append( QString::fromLatin1( secondChild()->frameType() ) + QString::number( idSecond ) );
80 config.writeEntry( QString::fromLatin1( "Children" ).prepend( prefix ), strlst );
82 //write orientation
83 QString o;
84 if( orientation() == Qt::Horizontal )
85 o = QString::fromLatin1("Horizontal");
86 else if( orientation() == Qt::Vertical )
87 o = QString::fromLatin1("Vertical");
88 config.writeEntry( QString::fromLatin1( "Orientation" ).prepend( prefix ), o );
90 //write docContainer
91 if (this == docContainer) config.writeEntry( QString::fromLatin1( "docContainer" ).prepend( prefix ), true );
93 if (m_pSecondChild == m_pActiveChild) config.writeEntry( QString::fromLatin1( "activeChildIndex" ).prepend( prefix ), 1 );
94 else config.writeEntry( QString::fromLatin1( "activeChildIndex" ).prepend( prefix ), 0 );
96 //write child configs
97 if( firstChild() ) {
98 QString newPrefix = QString::fromLatin1( firstChild()->frameType() ) + QString::number(idSecond - 1);
99 newPrefix.append( QLatin1Char( '_' ) );
100 firstChild()->saveConfig( config, newPrefix, options, docContainer, id, depth + 1 );
103 if( secondChild() ) {
104 QString newPrefix = QString::fromLatin1( secondChild()->frameType() ) + QString::number( idSecond );
105 newPrefix.append( QLatin1Char( '_' ) );
106 secondChild()->saveConfig( config, newPrefix, options, docContainer, idSecond, depth + 1 );
110 void KonqFrameContainer::copyHistory( KonqFrameBase *other )
112 Q_ASSERT( other->frameType() == "Container" );
113 if ( firstChild() )
114 firstChild()->copyHistory( static_cast<KonqFrameContainer *>( other )->firstChild() );
115 if ( secondChild() )
116 secondChild()->copyHistory( static_cast<KonqFrameContainer *>( other )->secondChild() );
119 KonqFrameBase* KonqFrameContainer::otherChild( KonqFrameBase* child )
121 if( m_pFirstChild == child )
122 return m_pSecondChild;
123 else if( m_pSecondChild == child )
124 return m_pFirstChild;
125 return 0;
128 void KonqFrameContainer::swapChildren()
130 qSwap( m_pFirstChild, m_pSecondChild );
133 void KonqFrameContainer::setTitle( const QString &title , QWidget* sender)
135 //kDebug(1202) << "KonqFrameContainer::setTitle( " << title << " , " << sender << " )";
136 if (m_pParentContainer && activeChild() && (sender == activeChild()->asQWidget()))
137 m_pParentContainer->setTitle( title , this);
140 void KonqFrameContainer::setTabIcon( const KUrl &url, QWidget* sender )
142 //kDebug(1202) << "KonqFrameContainer::setTabIcon( " << url << " , " << sender << " )";
143 if (m_pParentContainer && activeChild() && (sender == activeChild()->asQWidget()))
144 m_pParentContainer->setTabIcon( url, this );
147 void KonqFrameContainer::insertChildFrame(KonqFrameBase* frame, int index)
149 //kDebug(1202) << "KonqFrameContainer " << this << ": insertChildFrame " << frame;
150 if (frame) {
151 QSplitter::insertWidget(index, frame->asQWidget());
152 // Insert before existing child? Move first to second.
153 if (index == 0 && m_pFirstChild && !m_pSecondChild) {
154 qSwap( m_pFirstChild, m_pSecondChild );
156 if( !m_pFirstChild ) {
157 m_pFirstChild = frame;
158 frame->setParentContainer(this);
159 //kDebug(1202) << "Setting as first child";
160 } else if( !m_pSecondChild ) {
161 m_pSecondChild = frame;
162 frame->setParentContainer(this);
163 //kDebug(1202) << "Setting as second child";
164 } else {
165 kWarning(1202) << this << " already has two children..."
166 << m_pFirstChild << " and " << m_pSecondChild << endl;
168 } else {
169 kWarning(1202) << "KonqFrameContainer " << this << ": insertChildFrame(NULL) !" ;
173 void KonqFrameContainer::childFrameRemoved(KonqFrameBase * frame)
175 //kDebug(1202) << "KonqFrameContainer::RemoveChildFrame " << this << ". Child " << frame << " removed";
177 if( m_pFirstChild == frame ) {
178 m_pFirstChild = m_pSecondChild;
179 m_pSecondChild = 0;
180 } else if( m_pSecondChild == frame ) {
181 m_pSecondChild = 0;
182 } else {
183 kWarning(1202) << this << " Can't find this child:" << frame ;
187 void KonqFrameContainer::childEvent( QChildEvent *c )
189 // Child events cause layout changes. These are unnecessary if we are going
190 // to be deleted anyway.
191 if (!m_bAboutToBeDeleted)
192 QSplitter::childEvent(c);
195 bool KonqFrameContainer::accept( KonqFrameVisitor* visitor )
197 if ( !visitor->visit( this ) )
198 return false;
199 Q_ASSERT( m_pFirstChild );
200 if ( m_pFirstChild && !m_pFirstChild->accept( visitor ) )
201 return false;
202 Q_ASSERT( m_pSecondChild );
203 if ( m_pSecondChild && !m_pSecondChild->accept( visitor ) )
204 return false;
205 if ( !visitor->endVisit( this ) )
206 return false;
207 return true;
210 void KonqFrameContainer::replaceChildFrame(KonqFrameBase* oldFrame, KonqFrameBase* newFrame)
212 const int idx = QSplitter::indexOf(oldFrame->asQWidget());
213 const QList<int> splitterSizes = sizes();
214 childFrameRemoved(oldFrame);
215 insertChildFrame(newFrame, idx);
216 setSizes(splitterSizes);
219 // TODO remove hasWidgetAfter
221 #include "konqframecontainer.moc"