# kio Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | 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 246919 2003-08-30 17:37:51Z pfeiffer $
    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 <qevent.h>
    00032
    00033 #include <qdir.h>
    00034
    00035 #include <kapplication.h>
    00036 #include <kconfig.h>
    00037 #include <kdebug.h>
    00038 #include <kglobal.h>
    00039
    00040 #include <qvaluelist.h>
    00041
    00042 KCombiView::KCombiView( QWidget *parent, const char *name)
    00043   : QSplitter( parent, name),
    00044     KFileView(),
    00045     right(0),
    00046     m_lastViewForNextItem(0),
    00047     m_lastViewForPrevItem(0)
    00048 {
    00049     left = new KFileIconView( this, "left" );
    00050     left->setAcceptDrops(false);
    00051     left->viewport()->setAcceptDrops(false);
    00052     left->setGridX( 160 );
    00053     left->KFileView::setViewMode( Directories );
    00054     left->setArrangement( QIconView::LeftToRight );
    00055     left->setParentView( this );
    00056     left->setAcceptDrops(false);
    00057     left->installEventFilter( this );
    00058
    00059     connect( sig, SIGNAL( sortingChanged( QDir::SortSpec ) ),
    00060              SLOT( slotSortingChanged( QDir::SortSpec ) ));
    00061 }
    00062
    00063 KCombiView::~KCombiView()
    00064 {
    00065     delete right;
    00066 }
    00067
    00068 void KCombiView::setRight(KFileView *view)
    00069 {
    00070     delete right;
    00071     right = view;
    00072     right->KFileView::setViewMode( Files );
    00073     setViewName( right->viewName() );
    00074
    00075     QValueList<int> lst;
    00076     lst << left->gridX() + 2 * left->spacing();
    00077     setSizes( lst );
    00078     setResizeMode( left, QSplitter::KeepSize );
    00079
    00080     right->setParentView( this );
    00081     right->widget()->setAcceptDrops(acceptDrops());
    00082     right->setDropOptions(dropOptions());
    00083     right->widget()->installEventFilter( this );
    00084 }
    00085
    00086
    00087 void KCombiView::insertItem( KFileItem *item )
    00088 {
    00089     KFileView::insertItem( item );
    00090
    00091     if ( item->isDir() ) {
    00092         left->updateNumbers( item );
    00093         left->insertItem( item );
    00094     }
    00095     else {
    00096         right->updateNumbers( item );
    00097         right->insertItem( item );
    00098     }
    00099 }
    00100
    00101 void KCombiView::setSorting( QDir::SortSpec sort )
    00102 {
    00103     if ( !right )
    00104         kdFatal() << "You need to call setRight( someview ) before!" << endl;
    00105     right->setSorting( sort );
    00106     left->setSorting( sort );
    00107
    00108     KFileView::setSorting( right->sorting() );
    00109 }
    00110
    00111 void KCombiView::clearView()
    00112 {
    00113     left->clearView();
    00114     if ( right )
    00115         right->clearView();
    00116 }
    00117
    00118 void KCombiView::updateView( bool b )
    00119 {
    00120     left->updateView( b );
    00121     if ( right )
    00122         right->updateView( b );
    00123 }
    00124
    00125 void KCombiView::updateView( const KFileItem *i )
    00126 {
    00127     left->updateView( i );
    00128     if ( right )
    00129         right->updateView( i );
    00130 }
    00131
    00132 void KCombiView::removeItem( const KFileItem *i )
    00133 {
    00134     left->removeItem( i );
    00135     if ( right )
    00136         right->removeItem( i );
    00137     KFileView::removeItem( i );
    00138 }
    00139
    00140 void KCombiView::listingCompleted()
    00141 {
    00142     left->listingCompleted();
    00143     if ( right )
    00144         right->listingCompleted();
    00145 }
    00146
    00147 void KCombiView::clear()
    00148 {
    00149     KFileView::clear();
    00150     left->KFileView::clear();
    00151     if ( right )
    00152         right->clear();
    00153 }
    00154
    00155 void KCombiView::clearSelection()
    00156 {
    00157     left->clearSelection();
    00158     if ( right )
    00159         right->clearSelection();
    00160 }
    00161
    00162 void KCombiView::selectAll()
    00163 {
    00164     left->selectAll();
    00165     if ( right )
    00166         right->selectAll();
    00167 }
    00168
    00169 void KCombiView::invertSelection()
    00170 {
    00171     left->invertSelection();
    00172     if ( right )
    00173         right->invertSelection();
    00174 }
    00175
    00176 bool KCombiView::isSelected( const KFileItem *item ) const
    00177 {
    00178     assert( right ); // for performance reasons no if ( right ) check.
    00179     return (right->isSelected( item ) || left->isSelected( item ));
    00180 }
    00181
    00182 void KCombiView::setSelectionMode( KFile::SelectionMode sm )
    00183 {
    00184     // I think the left view (directories should always be in
    00185     // Single-Mode, right?
    00186     // left->setSelectionMode( sm );
    00187     if ( !right )
    00188         kdFatal() << "You need to call setRight( someview ) before!" << endl;
    00189     right->setSelectionMode( sm );
    00190 }
    00191
    00192 void KCombiView::setSelected( const KFileItem *item, bool enable )
    00193 {
    00194     left->setSelected( item, enable );
    00195     if ( right )
    00196         right->setSelected( item, enable );
    00197 }
    00198
    00199 void KCombiView::setCurrentItem( const KFileItem *item )
    00200 {
    00201     left->setCurrentItem( item );
    00202     if ( right )
    00203         right->setCurrentItem( item );
    00204 }
    00205
    00206 KFileItem * KCombiView::currentFileItem() const
    00207 {
    00208     // we can actually have two current items, one in each view. So we simply
    00209     // prefer the fileview's item over the directory's.
    00210     // Smarter: if the right view has focus, prefer that over the left.
    00211     if ( !right )
    00212         return left->currentFileItem();
    00213
    00214     KFileView *preferredView = focusView( right );
    00215     KFileItem *item = preferredView->currentFileItem();
    00216     if ( !item && preferredView != left )
    00217         item = left->currentFileItem();
    00218
    00219     return item;
    00220 }
    00221
    00222 void KCombiView::ensureItemVisible(const KFileItem *item)
    00223 {
    00224     left->ensureItemVisible( item );
    00225     if ( right )
    00226         right->ensureItemVisible( item );
    00227 }
    00228
    00229 KFileItem * KCombiView::firstFileItem() const
    00230 {
    00231     if ( !right )
    00232         return left->firstFileItem();
    00233
    00234     KFileView *preferredView = focusView( left );
    00235     KFileView *otherView = (preferredView == left) ? right : left;
    00236     KFileItem *item = preferredView->firstFileItem();
    00237     if ( !item )
    00238         item = otherView->firstFileItem();
    00239
    00240     return item;
    00241 }
    00242
    00243 KFileItem * KCombiView::nextItem( const KFileItem *fileItem ) const
    00244 {
    00245     if ( !right )
    00246         return left->nextItem( fileItem );
    00247
    00248     KFileView *preferredView = focusView( left );
    00249     KFileView *otherView = (preferredView == left) ? right : left;
    00250     KFileItem *item = preferredView->nextItem( fileItem );
    00251
    00252     if ( item )
    00253         m_lastViewForNextItem = preferredView;
    00254     else { // no item, check other view
    00255         // when changing from one to another view, we need to continue
    00256         // with the next view's first item!
    00257         if ( m_lastViewForNextItem != otherView ) {
    00258             m_lastViewForNextItem = otherView;
    00259             return otherView->firstFileItem();
    00260         }
    00261
    00262         item = otherView->nextItem( fileItem );
    00263         m_lastViewForNextItem = otherView;
    00264     }
    00265
    00266     return item;
    00267 }
    00268
    00269 KFileItem * KCombiView::prevItem( const KFileItem *fileItem ) const
    00270 {
    00271     if ( !right )
    00272         return left->nextItem( fileItem );
    00273
    00274     KFileView *preferredView = focusView( left );
    00275     KFileView *otherView = (preferredView == left) ? right : left;
    00276     KFileItem *item = preferredView->prevItem( fileItem );
    00277     if ( item )
    00278         m_lastViewForPrevItem = preferredView;
    00279
    00280     else { // no item, check other view
    00281         // when changing from one to another view, we need to continue
    00282         // with the next view's last item!
    00283         if ( m_lastViewForPrevItem != otherView ) {
    00284             fileItem = otherView->firstFileItem();
    00285             while ( otherView->nextItem( fileItem ) ) // find the last item
    00286                 fileItem = otherView->nextItem( fileItem );
    00287         }
    00288
    00289         item = otherView->prevItem( fileItem );
    00290         m_lastViewForPrevItem = otherView;
    00291     }
    00292
    00293     return item;
    00294 }
    00295
    00296 void KCombiView::slotSortingChanged( QDir::SortSpec sorting )
    00297 {
    00298     KFileView::setSorting( sorting );
    00299 }
    00300
    00301 KFileView *KCombiView::focusView( KFileView *preferred ) const
    00302 {
    00303     QWidget *w = focusWidget();
    00304     KFileView *other = (right == preferred) ? left : right;
    00305     return (preferred && w == preferred->widget()) ? preferred : other;
    00306 }
    00307
    00308 void KCombiView::readConfig( KConfig *config, const QString& group )
    00309 {
    00310     left->readConfig( config, group );
    00311     if ( right )
    00312         right->readConfig( config, group );
    00313 }
    00314
    00315 void KCombiView::writeConfig( KConfig *config, const QString& group )
    00316 {
    00317     left->writeConfig( config, group );
    00318     if ( right )
    00319         right->writeConfig( config, group );
    00320 }
    00321
    00322 KActionCollection * KCombiView::actionCollection() const
    00323 {
    00324     return focusView( right )->actionCollection();
    00325 }
    00326
    00327 void KCombiView::setAcceptDrops(bool b)
    00328 {
    00329     left->setAcceptDrops(b);
    00330     if (right)
    00331        right->widget()->setAcceptDrops(b);
    00332     QSplitter::setAcceptDrops(b);
    00333 }
    00334
    00335 void KCombiView::setDropOptions_impl(int options)
    00336 {
    00337     KFileView::setDropOptions_impl(options);
    00338     left->setDropOptions(options);
    00339     if (right)
    00340        right->setDropOptions(options);
    00341 }
    00342
    00343 void KCombiView::virtual_hook( int id, void* data )
    00344 {
    00345     switch(id) {
    00346       case VIRTUAL_SET_DROP_OPTIONS:
    00347          setDropOptions_impl(*(int *)data);
    00348          break;
    00349       default:
    00350          KFileView::virtual_hook( id, data );
    00351     }
    00352 }
    00353
    00354 bool KCombiView::eventFilter( QObject *o, QEvent *e )
    00355 {
    00356     int type = e->type();
    00357
    00358     // only the focused view may have a selection
    00359     if ( type == QEvent::FocusIn )
    00360     {
    00361         if ( o == left )
    00362             right->clearSelection();
    00363         else if ( o == right->widget() )
    00364             left->clearSelection();
    00365     }
    00366
    00367     return QSplitter::eventFilter( o, e );
    00368 }
    00369
    00370 #include "kcombiview.moc"
    00371

This file is part of the documentation for kio Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:23:55 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003