kio Library API Documentation

kcombiview.cpp

00001 /* This file is part of the KDE libraries
00002     Copyright (C) 1998 Stephan Kulow <coolo@kde.org>
00003                   1998 Daniel Grana <grana@ie.iwi.unibe.ch>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 */
00020 
00021 // $Id: kcombiview.cpp,v 1.55.2.2 2003/01/16 20:29:21 pfeiffer Exp $
00022 
00023 #include <assert.h>
00024 
00025 #include "kfileitem.h"
00026 #include "kcombiview.h"
00027 #include "kfileiconview.h"
00028 #include "kfiledetailview.h"
00029 #include "config-kfile.h"
00030 
00031 #include <qpainter.h>
00032 #include <qlistbox.h>
00033 
00034 #include <qdir.h>
00035 
00036 #include <kapplication.h>
00037 #include <kconfig.h>
00038 #include <kdebug.h>
00039 #include <kglobal.h>
00040 
00041 #include <qvaluelist.h>
00042 
00043 KCombiView::KCombiView( QWidget *parent, const char *name)
00044   : QSplitter( parent, name),
00045     KFileView(),
00046     right(0),
00047     m_lastViewForNextItem(0),
00048     m_lastViewForPrevItem(0)
00049 {
00050     left = new KFileIconView( this, "left" );
00051     left->KFileView::setViewMode( Directories );
00052     left->setArrangement( QIconView::LeftToRight );
00053     left->setParentView( this );
00054 
00055     connect( sig, SIGNAL( sortingChanged( QDir::SortSpec ) ),
00056              SLOT( slotSortingChanged( QDir::SortSpec ) ));
00057 }
00058 
00059 KCombiView::~KCombiView()
00060 {
00061     delete right;
00062 }
00063 
00064 void KCombiView::setRight(KFileView *view)
00065 {
00066     delete right;
00067     right = view;
00068     right->KFileView::setViewMode( Files );
00069     setViewName( right->viewName() );
00070 
00071     QValueList<int> lst;
00072     lst << left->gridX() + 2 * left->spacing();
00073     setSizes( lst );
00074     setResizeMode( left, QSplitter::KeepSize );
00075 
00076     right->setParentView( this );
00077 }
00078 
00079 void KCombiView::insertItem( KFileItem *item )
00080 {
00081     KFileView::insertItem( item );
00082 
00083     if ( item->isDir() ) {
00084         left->updateNumbers( item );
00085         left->insertItem( item );
00086     }
00087     else {
00088         right->updateNumbers( item );
00089         right->insertItem( item );
00090     }
00091 }
00092 
00093 void KCombiView::setSorting( QDir::SortSpec sort )
00094 {
00095     if ( !right )
00096         kdFatal() << "You need to call setRight( someview ) before!" << endl;
00097     right->setSorting( sort );
00098     left->setSorting( sort );
00099 
00100     KFileView::setSorting( right->sorting() );
00101 }
00102 
00103 void KCombiView::clearView()
00104 {
00105     left->clearView();
00106     if ( right )
00107         right->clearView();
00108 }
00109 
00110 void KCombiView::updateView( bool b )
00111 {
00112     left->updateView( b );
00113     if ( right )
00114         right->updateView( b );
00115 }
00116 
00117 void KCombiView::updateView( const KFileItem *i )
00118 {
00119     left->updateView( i );
00120     if ( right )
00121         right->updateView( i );
00122 }
00123 
00124 void KCombiView::removeItem( const KFileItem *i )
00125 {
00126     left->removeItem( i );
00127     if ( right )
00128         right->removeItem( i );
00129     KFileView::removeItem( i );
00130 }
00131 
00132 void KCombiView::listingCompleted()
00133 {
00134     left->listingCompleted();
00135     if ( right )
00136         right->listingCompleted();
00137 }
00138 
00139 void KCombiView::clear()
00140 {
00141     KFileView::clear();
00142     left->KFileView::clear();
00143     if ( right )
00144         right->clear();
00145 }
00146 
00147 void KCombiView::clearSelection()
00148 {
00149     left->clearSelection();
00150     if ( right )
00151         right->clearSelection();
00152 }
00153 
00154 void KCombiView::selectAll()
00155 {
00156     left->selectAll();
00157     if ( right )
00158         right->selectAll();
00159 }
00160 
00161 void KCombiView::invertSelection()
00162 {
00163     left->invertSelection();
00164     if ( right )
00165         right->invertSelection();
00166 }
00167 
00168 bool KCombiView::isSelected( const KFileItem *item ) const
00169 {
00170     assert( right ); // for performance reasons no if ( right ) check.
00171     return (right->isSelected( item ) || left->isSelected( item ));
00172 }
00173 
00174 void KCombiView::setSelectionMode( KFile::SelectionMode sm )
00175 {
00176     // I think the left view (directories should always be in
00177     // Single-Mode, right?
00178     // left->setSelectionMode( sm );
00179     if ( !right )
00180         kdFatal() << "You need to call setRight( someview ) before!" << endl;
00181     right->setSelectionMode( sm );
00182 }
00183 
00184 void KCombiView::setSelected( const KFileItem *item, bool enable )
00185 {
00186     left->setSelected( item, enable );
00187     if ( right )
00188         right->setSelected( item, enable );
00189 }
00190 
00191 void KCombiView::setCurrentItem( const KFileItem *item )
00192 {
00193     left->setCurrentItem( item );
00194     if ( right )
00195         right->setCurrentItem( item );
00196 }
00197 
00198 KFileItem * KCombiView::currentFileItem() const
00199 {
00200     // we can actually have two current items, one in each view. So we simply
00201     // prefer the fileview's item over the directory's.
00202     // Smarter: if the right view has focus, prefer that over the left.
00203     if ( !right )
00204         return left->currentFileItem();
00205 
00206     KFileView *preferredView = focusView( right );
00207     KFileItem *item = preferredView->currentFileItem();
00208     if ( !item && preferredView != left )
00209         item = left->currentFileItem();
00210 
00211     return item;
00212 }
00213 
00214 void KCombiView::ensureItemVisible(const KFileItem *item)
00215 {
00216     left->ensureItemVisible( item );
00217     if ( right )
00218         right->ensureItemVisible( item );
00219 }
00220 
00221 KFileItem * KCombiView::firstFileItem() const
00222 {
00223     if ( !right )
00224         return left->firstFileItem();
00225 
00226     KFileView *preferredView = focusView( left );
00227     KFileView *otherView = (preferredView == left) ? right : left;
00228     KFileItem *item = preferredView->firstFileItem();
00229     if ( !item )
00230         item = otherView->firstFileItem();
00231 
00232     return item;
00233 }
00234 
00235 KFileItem * KCombiView::nextItem( const KFileItem *fileItem ) const
00236 {
00237     if ( !right )
00238         return left->nextItem( fileItem );
00239     
00240     KFileView *preferredView = focusView( left );
00241     KFileView *otherView = (preferredView == left) ? right : left;
00242     KFileItem *item = preferredView->nextItem( fileItem );
00243     
00244     if ( item )
00245         m_lastViewForNextItem = preferredView;
00246     else { // no item, check other view
00247         // when changing from one to another view, we need to continue
00248         // with the next view's first item!
00249         if ( m_lastViewForNextItem != otherView ) {
00250             m_lastViewForNextItem = otherView;
00251             return otherView->firstFileItem();
00252         }
00253 
00254         item = otherView->nextItem( fileItem );
00255         m_lastViewForNextItem = otherView;
00256     }
00257 
00258     return item;
00259 }
00260 
00261 KFileItem * KCombiView::prevItem( const KFileItem *fileItem ) const
00262 {
00263     if ( !right )
00264         return left->nextItem( fileItem );
00265 
00266     KFileView *preferredView = focusView( left );
00267     KFileView *otherView = (preferredView == left) ? right : left;
00268     KFileItem *item = preferredView->prevItem( fileItem );
00269     if ( item )
00270         m_lastViewForPrevItem = preferredView;
00271 
00272     else { // no item, check other view
00273         // when changing from one to another view, we need to continue
00274         // with the next view's last item!
00275         if ( m_lastViewForPrevItem != otherView ) {
00276             fileItem = otherView->firstFileItem();
00277             while ( otherView->nextItem( fileItem ) ) // find the last item
00278                 fileItem = otherView->nextItem( fileItem );
00279         }
00280 
00281         item = otherView->prevItem( fileItem );
00282         m_lastViewForPrevItem = otherView;
00283     }
00284 
00285     return item;
00286 }
00287 
00288 void KCombiView::slotSortingChanged( QDir::SortSpec sorting )
00289 {
00290     KFileView::setSorting( sorting );
00291 }
00292 
00293 KFileView *KCombiView::focusView( KFileView *preferred ) const
00294 {
00295     QWidget *w = focusWidget();
00296     KFileView *other = (right == preferred) ? left : right;
00297     return (preferred && w == preferred->widget()) ? preferred : other;
00298 }
00299 
00300 void KCombiView::readConfig( KConfig *config, const QString& group )
00301 {
00302     left->readConfig( config, group );
00303     if ( right )
00304         right->readConfig( config, group );
00305 }
00306 
00307 void KCombiView::writeConfig( KConfig *config, const QString& group )
00308 {
00309     left->writeConfig( config, group );
00310     if ( right )
00311         right->writeConfig( config, group );
00312 }
00313 
00314 KActionCollection * KCombiView::actionCollection() const
00315 {
00316     return focusView( right )->actionCollection();
00317 }
00318 
00319 void KCombiView::virtual_hook( int id, void* data )
00320 { KFileView::virtual_hook( id, data ); }
00321 
00322 
00323 #include "kcombiview.moc"
00324 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:21:28 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001