kcombiview.cpp
/* 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: kcombiview.cpp 465272 2005-09-29 09:47:40Z mueller $
#include <assert.h>
#include "kfileitem.h"
#include "kcombiview.h"
#include "kfileiconview.h"
#include "kfiledetailview.h"
#include "config-kfile.h"
#include <qevent.h>
#include <qdir.h>
#include <kapplication.h>
#include <kconfig.h>
#include <kdebug.h>
#include <kglobal.h>
#include <qvaluelist.h>
KCombiView::KCombiView( QWidget *parent, const char *name)
: QSplitter( parent, name),
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 );
left->setArrangement( QIconView::LeftToRight );
left->setParentView( this );
left->setAcceptDrops(false);
left->installEventFilter( this );
connect( sig, SIGNAL( sortingChanged( QDir::SortSpec ) ),
SLOT( slotSortingChanged( QDir::SortSpec ) ));
}
KCombiView::~KCombiView()
{
delete right;
}
void KCombiView::setRight(KFileView *view)
{
delete right;
right = view;
right->KFileView::setViewMode( Files );
setViewName( right->viewName() );
QValueList<int> lst;
lst << left->gridX() + 2 * left->spacing();
setSizes( lst );
setResizeMode( left, QSplitter::KeepSize );
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 );
}
}
void KCombiView::setSorting( QDir::SortSpec sort )
{
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();
while ( otherView->nextItem( fileItem ) ) // find the last item
fileItem = otherView->nextItem( fileItem );
}
item = otherView->prevItem( fileItem );
m_lastViewForPrevItem = otherView;
}
return item;
}
void KCombiView::slotSortingChanged( QDir::SortSpec sorting )
{
KFileView::setSorting( sorting );
}
KFileView *KCombiView::focusView( KFileView *preferred ) const
{
QWidget *w = focusWidget();
KFileView *other = (right == preferred) ? left : right;
return (preferred && w == preferred->widget()) ? preferred : other;
}
void KCombiView::readConfig( KConfig *config, const QString& group )
{
left->readConfig( config, group );
if ( right )
right->readConfig( config, group );
}
void KCombiView::writeConfig( KConfig *config, const QString& group )
{
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);
QSplitter::setAcceptDrops(b);
}
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 );
}
}
bool KCombiView::eventFilter( QObject *o, QEvent *e )
{
int type = e->type();
// only the focused view may have a selection
if ( type == QEvent::FocusIn )
{
if ( o == left )
right->clearSelection();
else if ( o == right->widget() )
left->clearSelection();
}
return QSplitter::eventFilter( o, e );
}
#include "kcombiview.moc"
KFileIconView::setSorting
virtual void setSorting(QDir::SortSpec sort)
Sets the sorting order of the view.
Definition: kfileiconview.cpp:675
KFileIconView::listingCompleted
virtual void listingCompleted()
This hook is called when all items of the currently listed directory are listed and inserted into the...
Definition: kfileiconview.cpp:717
KFileIconView::isSelected
virtual bool isSelected(const KFileItem *i) const
Definition: kfileiconview.cpp:429
KCombiView::invertSelection
virtual void invertSelection()
Inverts the current selection, i.e.
Definition: kcombiview.cpp:169
KFileView::setDropOptions
void setDropOptions(int options)
Specify DND options.
Definition: kfileview.cpp:397
KCombiView::ensureItemVisible
void ensureItemVisible(const KFileItem *)
pure virtual function, that should be implemented to make item i visible, i.e.
Definition: kcombiview.cpp:222
KFileIconView::setSelected
virtual void setSelected(const KFileItem *, bool)
Tells the view that it should highlight the item.
Definition: kfileiconview.cpp:301
KFileView::insertItem
virtual void insertItem(KFileItem *i)
The derived view must implement this function to add the file in the widget.
Definition: kfileview.cpp:147
KFileView::actionCollection
virtual KActionCollection * actionCollection() const
Definition: kfileview.cpp:365
KCombiView::clearView
virtual void clearView()
pure virtual function, that should be implemented to clear the view.
Definition: kcombiview.cpp:111
KFileView::setViewName
void setViewName(const QString &name)
Sets the name of the view, which could be displayed somewhere.
Definition: kfileview.h:240
KCombiView::insertItem
virtual void insertItem(KFileItem *i)
The derived view must implement this function to add the file in the widget.
Definition: kcombiview.cpp:87
KCombiView::setSelected
virtual void setSelected(const KFileItem *, bool)
Tells the view that it should highlight the item.
Definition: kcombiview.cpp:192
KFileView
This class defines an interface to all file views.
Definition: kfileview.h:98
KFileIconView::clearView
virtual void clearView()
pure virtual function, that should be implemented to clear the view.
Definition: kfileiconview.cpp:327
KFileView::widget
virtual QWidget * widget()=0
a pure virtual function to get a QWidget, that can be added to other widgets.
KCombiView::isSelected
virtual bool isSelected(const KFileItem *) const
Definition: kcombiview.cpp:176
KFileView::viewName
QString viewName() const
Definition: kfileview.h:234
KCombiView::clearSelection
virtual void clearSelection()
Clears any selection, unhighlights everything.
Definition: kcombiview.cpp:155
KFileView::clear
virtual void clear()
Clears the view and all item lists.
Definition: kfileview.cpp:156
KFileView::clearSelection
virtual void clearSelection()=0
Clears any selection, unhighlights everything.
KCombiView::actionCollection
virtual KActionCollection * actionCollection() const
Definition: kcombiview.cpp:322
KFileIconView::invertSelection
virtual void invertSelection()
Inverts the current selection, i.e.
Definition: kfileiconview.cpp:322
KFileView::selectAll
virtual void selectAll()
Selects all items.
Definition: kfileview.cpp:312
KCombiView::setRight
void setRight(KFileView *view)
Sets the view to be shown in the right.
Definition: kcombiview.cpp:68
KFileView::currentFileItem
virtual KFileItem * currentFileItem() const =0
KCombiView::updateView
virtual void updateView(bool)
does a repaint of the view.
Definition: kcombiview.cpp:118
KFileView::sorting
QDir::SortSpec sorting() const
Returns the sorting order of the internal list.
Definition: kfileview.h:177
KCombiView::clear
virtual void clear()
Clears the view and all item lists.
Definition: kcombiview.cpp:147
KFileView::setSelected
virtual void setSelected(const KFileItem *, bool enable)=0
Tells the view that it should highlight the item.
KFileView::setSorting
virtual void setSorting(QDir::SortSpec sort)
Sets the sorting order of the view.
Definition: kfileview.cpp:151
KFileIconView::removeItem
virtual void removeItem(const KFileItem *)
Removes an item from the list; has to be implemented by the view.
Definition: kfileiconview.cpp:466
KFileView::dropOptions
int dropOptions()
Returns the DND options in effect.
Definition: kfileview.cpp:407
KFileIconView::clearSelection
virtual void clearSelection()
Clears any selection, unhighlights everything.
Definition: kfileiconview.cpp:317
KFileIconView::currentFileItem
virtual KFileItem * currentFileItem() const
Definition: kfileiconview.cpp:381
KFileView::isSelected
virtual bool isSelected(const KFileItem *) const =0
KFileView::removeItem
virtual void removeItem(const KFileItem *item)
Removes an item from the list; has to be implemented by the view.
Definition: kfileview.cpp:346
KFileView::invertSelection
virtual void invertSelection()
Inverts the current selection, i.e.
Definition: kfileview.cpp:323
KFileIconView::setCurrentItem
virtual void setCurrentItem(const KFileItem *)
Reimplement this to set item the current item in the view, e.g.
Definition: kfileiconview.cpp:374
KCombiView::removeItem
virtual void removeItem(const KFileItem *)
Removes an item from the list; has to be implemented by the view.
Definition: kcombiview.cpp:132
KCombiView::listingCompleted
virtual void listingCompleted()
This hook is called when all items of the currently listed directory are listed and inserted into the...
Definition: kcombiview.cpp:140
KFileIconView::ensureItemVisible
void ensureItemVisible(const KFileItem *)
pure virtual function, that should be implemented to make item i visible, i.e.
Definition: kfileiconview.cpp:508
KFileView::updateView
virtual void updateView(bool f=true)
does a repaint of the view.
Definition: kfileview.cpp:259
KFileView::ensureItemVisible
virtual void ensureItemVisible(const KFileItem *i)=0
pure virtual function, that should be implemented to make item i visible, i.e.
KFileView::clearView
virtual void clearView()=0
pure virtual function, that should be implemented to clear the view.
KCombiView::setSorting
virtual void setSorting(QDir::SortSpec sort)
Sets the sorting order of the view.
Definition: kcombiview.cpp:101
KCombiView::currentFileItem
virtual KFileItem * currentFileItem() const
Definition: kcombiview.cpp:206
KFileIconView::selectAll
virtual void selectAll()
Selects all items.
Definition: kfileiconview.cpp:308
KFileIconView::insertItem
virtual void insertItem(KFileItem *i)
The derived view must implement this function to add the file in the widget.
Definition: kfileiconview.cpp:335
KCombiView::setCurrentItem
virtual void setCurrentItem(const KFileItem *)
Reimplement this to set item the current item in the view, e.g.
Definition: kcombiview.cpp:199
KFileIconView
An icon-view capable of showing KFileItem's.
Definition: kfileiconview.h:81
KFileView::updateNumbers
bool updateNumbers(const KFileItem *i)
increases the number of dirs and files.
Definition: kfileview.cpp:110
KFileIconView::updateView
virtual void updateView(bool)
does a repaint of the view.
Definition: kfileiconview.cpp:435
KFileView::listingCompleted
virtual void listingCompleted()
This hook is called when all items of the currently listed directory are listed and inserted into the...
Definition: kfileview.cpp:360
KFileView::setCurrentItem
void setCurrentItem(const QString &filename)
Sets filename the current item in the view, if available.
Definition: kfileview.cpp:268
KCombiView::selectAll
virtual void selectAll()
Selects all items.
Definition: kcombiview.cpp:162

KDE Home | KDE Accessibility Home | Description of Access Keys