kio
kcombiview.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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 );
00179 return (right->isSelected( item ) || left->isSelected( item ));
00180 }
00181
00182 void KCombiView::setSelectionMode( KFile::SelectionMode sm )
00183 {
00184
00185
00186
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
00209
00210
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 {
00255
00256
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 {
00281
00282
00283 if ( m_lastViewForPrevItem != otherView ) {
00284 fileItem = otherView->firstFileItem();
00285 while ( otherView->nextItem( fileItem ) )
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
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