You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
372 lines
9.4 KiB
372 lines
9.4 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 1998 Stephan Kulow <coolo@kde.org>
|
||
|
1998 Daniel Grana <grana@ie.iwi.unibe.ch>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
// $Id$
|
||
|
|
||
|
#include <assert.h>
|
||
|
|
||
12 years ago
|
#include "tdefileitem.h"
|
||
15 years ago
|
#include "kcombiview.h"
|
||
12 years ago
|
#include "tdefileiconview.h"
|
||
|
#include "tdefiledetailview.h"
|
||
|
#include "config-tdefile.h"
|
||
15 years ago
|
|
||
15 years ago
|
#include <tqevent.h>
|
||
15 years ago
|
|
||
15 years ago
|
#include <tqdir.h>
|
||
15 years ago
|
|
||
|
#include <kapplication.h>
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
#include <kglobal.h>
|
||
|
|
||
15 years ago
|
#include <tqvaluelist.h>
|
||
15 years ago
|
|
||
15 years ago
|
KCombiView::KCombiView( TQWidget *parent, const char *name)
|
||
|
: TQSplitter( parent, name),
|
||
15 years ago
|
KFileView(),
|
||
|
right(0),
|
||
|
m_lastViewForNextItem(0),
|
||
|
m_lastViewForPrevItem(0)
|
||
|
{
|
||
|
left = new KFileIconView( this, "left" );
|
||
|
left->setAcceptDrops(false);
|
||
|
left->viewport()->setAcceptDrops(false);
|
||
|
left->setGridX( 160 );
|
||
|
left->KFileView::setViewMode( Directories );
|
||
15 years ago
|
left->setArrangement( TQIconView::LeftToRight );
|
||
15 years ago
|
left->setParentView( this );
|
||
|
left->setAcceptDrops(false);
|
||
|
left->installEventFilter( this );
|
||
|
|
||
15 years ago
|
connect( sig, TQT_SIGNAL( sortingChanged( TQDir::SortSpec ) ),
|
||
|
TQT_SLOT( slotSortingChanged( TQDir::SortSpec ) ));
|
||
15 years ago
|
}
|
||
|
|
||
|
KCombiView::~KCombiView()
|
||
|
{
|
||
|
delete right;
|
||
|
}
|
||
|
|
||
|
void KCombiView::setRight(KFileView *view)
|
||
|
{
|
||
|
delete right;
|
||
|
right = view;
|
||
|
right->KFileView::setViewMode( Files );
|
||
|
setViewName( right->viewName() );
|
||
|
|
||
15 years ago
|
TQValueList<int> lst;
|
||
15 years ago
|
lst << left->gridX() + 2 * left->spacing();
|
||
|
setSizes( lst );
|
||
15 years ago
|
setResizeMode( left, TQSplitter::KeepSize );
|
||
15 years ago
|
|
||
|
right->setParentView( this );
|
||
|
right->widget()->setAcceptDrops(acceptDrops());
|
||
|
right->setDropOptions(dropOptions());
|
||
|
right->widget()->installEventFilter( this );
|
||
|
}
|
||
|
|
||
|
|
||
|
void KCombiView::insertItem( KFileItem *item )
|
||
|
{
|
||
|
KFileView::insertItem( item );
|
||
|
|
||
|
if ( item->isDir() ) {
|
||
|
left->updateNumbers( item );
|
||
|
left->insertItem( item );
|
||
|
}
|
||
|
else {
|
||
|
right->updateNumbers( item );
|
||
|
right->insertItem( item );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KCombiView::setSorting( TQDir::SortSpec sort )
|
||
15 years ago
|
{
|
||
|
if ( !right )
|
||
|
kdFatal() << "You need to call setRight( someview ) before!" << endl;
|
||
|
right->setSorting( sort );
|
||
|
left->setSorting( sort );
|
||
|
|
||
|
KFileView::setSorting( right->sorting() );
|
||
|
}
|
||
|
|
||
|
void KCombiView::clearView()
|
||
|
{
|
||
|
left->clearView();
|
||
|
if ( right )
|
||
|
right->clearView();
|
||
|
}
|
||
|
|
||
|
void KCombiView::updateView( bool b )
|
||
|
{
|
||
|
left->updateView( b );
|
||
|
if ( right )
|
||
|
right->updateView( b );
|
||
|
}
|
||
|
|
||
|
void KCombiView::updateView( const KFileItem *i )
|
||
|
{
|
||
|
left->updateView( i );
|
||
|
if ( right )
|
||
|
right->updateView( i );
|
||
|
}
|
||
|
|
||
|
void KCombiView::removeItem( const KFileItem *i )
|
||
|
{
|
||
|
left->removeItem( i );
|
||
|
if ( right )
|
||
|
right->removeItem( i );
|
||
|
KFileView::removeItem( i );
|
||
|
}
|
||
|
|
||
|
void KCombiView::listingCompleted()
|
||
|
{
|
||
|
left->listingCompleted();
|
||
|
if ( right )
|
||
|
right->listingCompleted();
|
||
|
}
|
||
|
|
||
|
void KCombiView::clear()
|
||
|
{
|
||
|
KFileView::clear();
|
||
|
left->KFileView::clear();
|
||
|
if ( right )
|
||
|
right->clear();
|
||
|
}
|
||
|
|
||
|
void KCombiView::clearSelection()
|
||
|
{
|
||
|
left->clearSelection();
|
||
|
if ( right )
|
||
|
right->clearSelection();
|
||
|
}
|
||
|
|
||
|
void KCombiView::selectAll()
|
||
|
{
|
||
|
left->selectAll();
|
||
|
if ( right )
|
||
|
right->selectAll();
|
||
|
}
|
||
|
|
||
|
void KCombiView::invertSelection()
|
||
|
{
|
||
|
left->invertSelection();
|
||
|
if ( right )
|
||
|
right->invertSelection();
|
||
|
}
|
||
|
|
||
|
bool KCombiView::isSelected( const KFileItem *item ) const
|
||
|
{
|
||
|
assert( right ); // for performance reasons no if ( right ) check.
|
||
|
return (right->isSelected( item ) || left->isSelected( item ));
|
||
|
}
|
||
|
|
||
|
void KCombiView::setSelectionMode( KFile::SelectionMode sm )
|
||
|
{
|
||
|
// I think the left view (directories should always be in
|
||
|
// Single-Mode, right?
|
||
|
// left->setSelectionMode( sm );
|
||
|
if ( !right )
|
||
|
kdFatal() << "You need to call setRight( someview ) before!" << endl;
|
||
|
right->setSelectionMode( sm );
|
||
|
}
|
||
|
|
||
|
void KCombiView::setSelected( const KFileItem *item, bool enable )
|
||
|
{
|
||
|
left->setSelected( item, enable );
|
||
|
if ( right )
|
||
|
right->setSelected( item, enable );
|
||
|
}
|
||
|
|
||
|
void KCombiView::setCurrentItem( const KFileItem *item )
|
||
|
{
|
||
|
left->setCurrentItem( item );
|
||
|
if ( right )
|
||
|
right->setCurrentItem( item );
|
||
|
}
|
||
|
|
||
|
KFileItem * KCombiView::currentFileItem() const
|
||
|
{
|
||
|
// we can actually have two current items, one in each view. So we simply
|
||
|
// prefer the fileview's item over the directory's.
|
||
|
// Smarter: if the right view has focus, prefer that over the left.
|
||
|
if ( !right )
|
||
|
return left->currentFileItem();
|
||
|
|
||
|
KFileView *preferredView = focusView( right );
|
||
|
KFileItem *item = preferredView->currentFileItem();
|
||
|
if ( !item && preferredView != left )
|
||
|
item = left->currentFileItem();
|
||
|
|
||
|
return item;
|
||
|
}
|
||
|
|
||
|
void KCombiView::ensureItemVisible(const KFileItem *item)
|
||
|
{
|
||
|
left->ensureItemVisible( item );
|
||
|
if ( right )
|
||
|
right->ensureItemVisible( item );
|
||
|
}
|
||
|
|
||
|
KFileItem * KCombiView::firstFileItem() const
|
||
|
{
|
||
|
if ( !right )
|
||
|
return left->firstFileItem();
|
||
|
|
||
|
KFileView *preferredView = focusView( left );
|
||
|
KFileView *otherView = (preferredView == left) ? right : left;
|
||
|
KFileItem *item = preferredView->firstFileItem();
|
||
|
if ( !item )
|
||
|
item = otherView->firstFileItem();
|
||
|
|
||
|
return item;
|
||
|
}
|
||
|
|
||
|
KFileItem * KCombiView::nextItem( const KFileItem *fileItem ) const
|
||
|
{
|
||
|
if ( !right )
|
||
|
return left->nextItem( fileItem );
|
||
|
|
||
|
KFileView *preferredView = focusView( left );
|
||
|
KFileView *otherView = (preferredView == left) ? right : left;
|
||
|
KFileItem *item = preferredView->nextItem( fileItem );
|
||
|
|
||
|
if ( item )
|
||
|
m_lastViewForNextItem = preferredView;
|
||
|
else { // no item, check other view
|
||
|
// when changing from one to another view, we need to continue
|
||
|
// with the next view's first item!
|
||
|
if ( m_lastViewForNextItem != otherView ) {
|
||
|
m_lastViewForNextItem = otherView;
|
||
|
return otherView->firstFileItem();
|
||
|
}
|
||
|
|
||
|
item = otherView->nextItem( fileItem );
|
||
|
m_lastViewForNextItem = otherView;
|
||
|
}
|
||
|
|
||
|
return item;
|
||
|
}
|
||
|
|
||
|
KFileItem * KCombiView::prevItem( const KFileItem *fileItem ) const
|
||
|
{
|
||
|
if ( !right )
|
||
|
return left->nextItem( fileItem );
|
||
|
|
||
|
KFileView *preferredView = focusView( left );
|
||
|
KFileView *otherView = (preferredView == left) ? right : left;
|
||
|
KFileItem *item = preferredView->prevItem( fileItem );
|
||
|
if ( item )
|
||
|
m_lastViewForPrevItem = preferredView;
|
||
|
|
||
|
else { // no item, check other view
|
||
|
// when changing from one to another view, we need to continue
|
||
|
// with the next view's last item!
|
||
|
if ( m_lastViewForPrevItem != otherView ) {
|
||
|
fileItem = otherView->firstFileItem();
|
||
14 years ago
|
while ( otherView->nextItem( fileItem ) ) // find the last item
|
||
15 years ago
|
fileItem = otherView->nextItem( fileItem );
|
||
|
}
|
||
|
|
||
|
item = otherView->prevItem( fileItem );
|
||
|
m_lastViewForPrevItem = otherView;
|
||
|
}
|
||
|
|
||
|
return item;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KCombiView::slotSortingChanged( TQDir::SortSpec sorting )
|
||
15 years ago
|
{
|
||
|
KFileView::setSorting( sorting );
|
||
|
}
|
||
|
|
||
|
KFileView *KCombiView::focusView( KFileView *preferred ) const
|
||
|
{
|
||
13 years ago
|
TQWidget *w = focusWidget();
|
||
15 years ago
|
KFileView *other = (right == preferred) ? left : right;
|
||
|
return (preferred && w == preferred->widget()) ? preferred : other;
|
||
|
}
|
||
|
|
||
12 years ago
|
void KCombiView::readConfig( TDEConfig *config, const TQString& group )
|
||
15 years ago
|
{
|
||
|
left->readConfig( config, group );
|
||
|
if ( right )
|
||
|
right->readConfig( config, group );
|
||
|
}
|
||
|
|
||
12 years ago
|
void KCombiView::writeConfig( TDEConfig *config, const TQString& group )
|
||
15 years ago
|
{
|
||
|
left->writeConfig( config, group );
|
||
|
if ( right )
|
||
|
right->writeConfig( config, group );
|
||
|
}
|
||
|
|
||
|
KActionCollection * KCombiView::actionCollection() const
|
||
|
{
|
||
|
return focusView( right )->actionCollection();
|
||
|
}
|
||
|
|
||
|
void KCombiView::setAcceptDrops(bool b)
|
||
|
{
|
||
|
left->setAcceptDrops(b);
|
||
|
if (right)
|
||
|
right->widget()->setAcceptDrops(b);
|
||
15 years ago
|
TQSplitter::setAcceptDrops(b);
|
||
15 years ago
|
}
|
||
|
|
||
|
void KCombiView::setDropOptions_impl(int options)
|
||
|
{
|
||
|
KFileView::setDropOptions_impl(options);
|
||
|
left->setDropOptions(options);
|
||
|
if (right)
|
||
|
right->setDropOptions(options);
|
||
|
}
|
||
|
|
||
|
void KCombiView::virtual_hook( int id, void* data )
|
||
|
{
|
||
|
switch(id) {
|
||
|
case VIRTUAL_SET_DROP_OPTIONS:
|
||
|
setDropOptions_impl(*(int *)data);
|
||
|
break;
|
||
|
default:
|
||
|
KFileView::virtual_hook( id, data );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KCombiView::eventFilter( TQObject *o, TQEvent *e )
|
||
15 years ago
|
{
|
||
|
int type = e->type();
|
||
|
|
||
|
// only the focused view may have a selection
|
||
15 years ago
|
if ( type == TQEvent::FocusIn )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(left) )
|
||
15 years ago
|
right->clearSelection();
|
||
14 years ago
|
else if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(right->widget()) )
|
||
15 years ago
|
left->clearSelection();
|
||
|
}
|
||
|
|
||
15 years ago
|
return TQSplitter::eventFilter( o, e );
|
||
15 years ago
|
}
|
||
|
|
||
|
#include "kcombiview.moc"
|
||
|
|