| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# 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.3 2003/03/03 11:53:08 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->setGridX( 160 );
    00052     left->KFileView::setViewMode( Directories );
    00053     left->setArrangement( QIconView::LeftToRight );
    00054     left->setParentView( this );
    00055
    00056     connect( sig, SIGNAL( sortingChanged( QDir::SortSpec ) ),
    00057              SLOT( slotSortingChanged( QDir::SortSpec ) ));
    00058 }
    00059
    00060 KCombiView::~KCombiView()
    00061 {
    00062     delete right;
    00063 }
    00064
    00065 void KCombiView::setRight(KFileView *view)
    00066 {
    00067     delete right;
    00068     right = view;
    00069     right->KFileView::setViewMode( Files );
    00070     setViewName( right->viewName() );
    00071
    00072     QValueList<int> lst;
    00073     lst << left->gridX() + 2 * left->spacing();
    00074     setSizes( lst );
    00075     setResizeMode( left, QSplitter::KeepSize );
    00076
    00077     right->setParentView( this );
    00078 }
    00079
    00080 void KCombiView::insertItem( KFileItem *item )
    00081 {
    00082     KFileView::insertItem( item );
    00083
    00084     if ( item->isDir() ) {
    00085         left->updateNumbers( item );
    00086         left->insertItem( item );
    00087     }
    00088     else {
    00089         right->updateNumbers( item );
    00090         right->insertItem( item );
    00091     }
    00092 }
    00093
    00094 void KCombiView::setSorting( QDir::SortSpec sort )
    00095 {
    00096     if ( !right )
    00097         kdFatal() << "You need to call setRight( someview ) before!" << endl;
    00098     right->setSorting( sort );
    00099     left->setSorting( sort );
    00100
    00101     KFileView::setSorting( right->sorting() );
    00102 }
    00103
    00104 void KCombiView::clearView()
    00105 {
    00106     left->clearView();
    00107     if ( right )
    00108         right->clearView();
    00109 }
    00110
    00111 void KCombiView::updateView( bool b )
    00112 {
    00113     left->updateView( b );
    00114     if ( right )
    00115         right->updateView( b );
    00116 }
    00117
    00118 void KCombiView::updateView( const KFileItem *i )
    00119 {
    00120     left->updateView( i );
    00121     if ( right )
    00122         right->updateView( i );
    00123 }
    00124
    00125 void KCombiView::removeItem( const KFileItem *i )
    00126 {
    00127     left->removeItem( i );
    00128     if ( right )
    00129         right->removeItem( i );
    00130     KFileView::removeItem( i );
    00131 }
    00132
    00133 void KCombiView::listingCompleted()
    00134 {
    00135     left->listingCompleted();
    00136     if ( right )
    00137         right->listingCompleted();
    00138 }
    00139
    00140 void KCombiView::clear()
    00141 {
    00142     KFileView::clear();
    00143     left->KFileView::clear();
    00144     if ( right )
    00145         right->clear();
    00146 }
    00147
    00148 void KCombiView::clearSelection()
    00149 {
    00150     left->clearSelection();
    00151     if ( right )
    00152         right->clearSelection();
    00153 }
    00154
    00155 void KCombiView::selectAll()
    00156 {
    00157     left->selectAll();
    00158     if ( right )
    00159         right->selectAll();
    00160 }
    00161
    00162 void KCombiView::invertSelection()
    00163 {
    00164     left->invertSelection();
    00165     if ( right )
    00166         right->invertSelection();
    00167 }
    00168
    00169 bool KCombiView::isSelected( const KFileItem *item ) const
    00170 {
    00171     assert( right ); // for performance reasons no if ( right ) check.
    00172     return (right->isSelected( item ) || left->isSelected( item ));
    00173 }
    00174
    00175 void KCombiView::setSelectionMode( KFile::SelectionMode sm )
    00176 {
    00177     // I think the left view (directories should always be in
    00178     // Single-Mode, right?
    00179     // left->setSelectionMode( sm );
    00180     if ( !right )
    00181         kdFatal() << "You need to call setRight( someview ) before!" << endl;
    00182     right->setSelectionMode( sm );
    00183 }
    00184
    00185 void KCombiView::setSelected( const KFileItem *item, bool enable )
    00186 {
    00187     left->setSelected( item, enable );
    00188     if ( right )
    00189         right->setSelected( item, enable );
    00190 }
    00191
    00192 void KCombiView::setCurrentItem( const KFileItem *item )
    00193 {
    00194     left->setCurrentItem( item );
    00195     if ( right )
    00196         right->setCurrentItem( item );
    00197 }
    00198
    00199 KFileItem * KCombiView::currentFileItem() const
    00200 {
    00201     // we can actually have two current items, one in each view. So we simply
    00202     // prefer the fileview's item over the directory's.
    00203     // Smarter: if the right view has focus, prefer that over the left.
    00204     if ( !right )
    00205         return left->currentFileItem();
    00206
    00207     KFileView *preferredView = focusView( right );
    00208     KFileItem *item = preferredView->currentFileItem();
    00209     if ( !item && preferredView != left )
    00210         item = left->currentFileItem();
    00211
    00212     return item;
    00213 }
    00214
    00215 void KCombiView::ensureItemVisible(const KFileItem *item)
    00216 {
    00217     left->ensureItemVisible( item );
    00218     if ( right )
    00219         right->ensureItemVisible( item );
    00220 }
    00221
    00222 KFileItem * KCombiView::firstFileItem() const
    00223 {
    00224     if ( !right )
    00225         return left->firstFileItem();
    00226
    00227     KFileView *preferredView = focusView( left );
    00228     KFileView *otherView = (preferredView == left) ? right : left;
    00229     KFileItem *item = preferredView->firstFileItem();
    00230     if ( !item )
    00231         item = otherView->firstFileItem();
    00232
    00233     return item;
    00234 }
    00235
    00236 KFileItem * KCombiView::nextItem( const KFileItem *fileItem ) const
    00237 {
    00238     if ( !right )
    00239         return left->nextItem( fileItem );
    00240
    00241     KFileView *preferredView = focusView( left );
    00242     KFileView *otherView = (preferredView == left) ? right : left;
    00243     KFileItem *item = preferredView->nextItem( fileItem );
    00244
    00245     if ( item )
    00246         m_lastViewForNextItem = preferredView;
    00247     else { // no item, check other view
    00248         // when changing from one to another view, we need to continue
    00249         // with the next view's first item!
    00250         if ( m_lastViewForNextItem != otherView ) {
    00251             m_lastViewForNextItem = otherView;
    00252             return otherView->firstFileItem();
    00253         }
    00254
    00255         item = otherView->nextItem( fileItem );
    00256         m_lastViewForNextItem = otherView;
    00257     }
    00258
    00259     return item;
    00260 }
    00261
    00262 KFileItem * KCombiView::prevItem( const KFileItem *fileItem ) const
    00263 {
    00264     if ( !right )
    00265         return left->nextItem( fileItem );
    00266
    00267     KFileView *preferredView = focusView( left );
    00268     KFileView *otherView = (preferredView == left) ? right : left;
    00269     KFileItem *item = preferredView->prevItem( fileItem );
    00270     if ( item )
    00271         m_lastViewForPrevItem = preferredView;
    00272
    00273     else { // no item, check other view
    00274         // when changing from one to another view, we need to continue
    00275         // with the next view's last item!
    00276         if ( m_lastViewForPrevItem != otherView ) {
    00277             fileItem = otherView->firstFileItem();
    00278             while ( otherView->nextItem( fileItem ) ) // find the last item
    00279                 fileItem = otherView->nextItem( fileItem );
    00280         }
    00281
    00282         item = otherView->prevItem( fileItem );
    00283         m_lastViewForPrevItem = otherView;
    00284     }
    00285
    00286     return item;
    00287 }
    00288
    00289 void KCombiView::slotSortingChanged( QDir::SortSpec sorting )
    00290 {
    00291     KFileView::setSorting( sorting );
    00292 }
    00293
    00294 KFileView *KCombiView::focusView( KFileView *preferred ) const
    00295 {
    00296     QWidget *w = focusWidget();
    00297     KFileView *other = (right == preferred) ? left : right;
    00298     return (preferred && w == preferred->widget()) ? preferred : other;
    00299 }
    00300
    00301 void KCombiView::readConfig( KConfig *config, const QString& group )
    00302 {
    00303     left->readConfig( config, group );
    00304     if ( right )
    00305         right->readConfig( config, group );
    00306 }
    00307
    00308 void KCombiView::writeConfig( KConfig *config, const QString& group )
    00309 {
    00310     left->writeConfig( config, group );
    00311     if ( right )
    00312         right->writeConfig( config, group );
    00313 }
    00314
    00315 KActionCollection * KCombiView::actionCollection() const
    00316 {
    00317     return focusView( right )->actionCollection();
    00318 }
    00319
    00320 void KCombiView::virtual_hook( int id, void* data )
    00321 { KFileView::virtual_hook( id, data ); }
    00322
    00323
    00324 #include "kcombiview.moc"
    00325

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:13:13 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001