kdganttlistviewrowcontroller.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (C) 2001-2010 Klaralvdalens Datakonsult AB.  All rights reserved.
00003 **
00004 ** This file is part of the KD Chart library.
00005 **
00006 ** Licensees holding valid commercial KD Chart licenses may use this file in
00007 ** accordance with the KD Chart Commercial License Agreement provided with
00008 ** the Software.
00009 **
00010 **
00011 ** This file may be distributed and/or modified under the terms of the
00012 ** GNU General Public License version 2 and version 3 as published by the
00013 ** Free Software Foundation and appearing in the file LICENSE.GPL included.
00014 **
00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 **
00018 ** Contact info@kdab.com if any conditions of this licensing are not
00019 ** clear to you.
00020 **
00021 **********************************************************************/
00022 
00023 #include "kdganttlistviewrowcontroller.h"
00024 #include "kdganttlistviewrowcontroller_p.h"
00025 
00026 #include <QAbstractProxyModel>
00027 #include <QScrollBar>
00028 
00029 #include <cassert>
00030 
00031 using namespace KDGantt;
00032 
00040 ListViewRowController::ListViewRowController( QListView* lv, QAbstractProxyModel* proxy )
00041   : _d( new Private(lv,proxy) )
00042 {
00043 }
00044 
00045 ListViewRowController::~ListViewRowController()
00046 {
00047     delete _d; _d = 0;
00048 }
00049 
00050 #define d d_func()
00051 
00052 int ListViewRowController::headerHeight() const
00053 {
00054     return d->listview->viewport()->y()-d->listview->frameWidth();
00055 }
00056 
00057 int ListViewRowController::maximumItemHeight() const
00058 {
00059     return d->listview->fontMetrics().height();
00060 }
00061 
00062 int ListViewRowController::totalHeight() const
00063 {
00064     return d->listview->verticalScrollBar()->maximum()+d->listview->viewport()->height();
00065 }
00066 
00067 bool ListViewRowController::isRowVisible( const QModelIndex& _idx ) const
00068 {
00069     const QModelIndex idx = d->proxy->mapToSource( _idx );
00070     assert( idx.isValid() ? ( idx.model() == d->listview->model() ):( true ) );
00071     return d->listview->visualRect(idx).isValid();
00072 }
00073 
00074 bool ListViewRowController::isRowExpanded( const QModelIndex& _idx ) const
00075 {
00076     Q_UNUSED(_idx);
00077 
00078     return false;
00079 }
00080 
00081 Span ListViewRowController::rowGeometry( const QModelIndex& _idx ) const
00082 {
00083     const QModelIndex idx = d->proxy->mapToSource( _idx );
00084     assert( idx.isValid() ? ( idx.model() == d->listview->model() ):( true ) );
00085     QRect r = d->listview->visualRect(idx).translated( QPoint( 0,
00086                   static_cast<Private::HackListView*>(d->listview)->verticalOffset() ) );
00087     return Span( r.y(), r.height() );
00088 }
00089 
00090 QModelIndex ListViewRowController::indexAt( int height ) const
00091 {
00092     return d->proxy->mapFromSource( d->listview->indexAt( QPoint( 1,height ) ) );
00093 }
00094 
00095 QModelIndex ListViewRowController::indexAbove( const QModelIndex& _idx ) const
00096 {
00097     const QModelIndex idx = d->proxy->mapToSource( _idx );
00098     return d->proxy->mapFromSource( idx.sibling( idx.row()-1, idx.column()) );
00099 }
00100 
00101 QModelIndex ListViewRowController::indexBelow( const QModelIndex& _idx ) const
00102 {
00103     const QModelIndex idx = d->proxy->mapToSource( _idx );
00104     if( !idx.isValid() || idx.column()!=0 ) return QModelIndex();
00105     if( idx.model()->rowCount(idx.parent())<idx.row()+1 ) return QModelIndex();
00106     return d->proxy->mapFromSource( idx.sibling( idx.row()+1, idx.column()) );
00107 }
00108