1 /****************************************************************************
2 ** Copyright (C) 2001-2006 Klarälvdalens Datakonsult AB. All rights reserved.
4 ** This file is part of the KD Gantt library.
6 ** This file may be distributed and/or modified under the terms of the
7 ** GNU General Public License version 2 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.GPL included in the
9 ** packaging of this file.
11 ** Licensees holding valid commercial KD Gantt licenses may use this file in
12 ** accordance with the KD Gantt Commercial License Agreement provided with
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 ** See http://www.kdab.net/kdgantt for
19 ** information about KD Gantt Commercial License Agreements.
21 ** Contact info@kdab.net if any conditions of this
22 ** licensing are not clear to you.
24 **********************************************************************/
25 #include "kdganttlistviewrowcontroller.h"
26 #include "kdganttlistviewrowcontroller_p.h"
28 #include <QAbstractProxyModel>
33 using namespace KDGantt
;
35 /*!\class TreeViewRowController
36 * This is an implementation of AbstractRowController that
37 * aligns a gantt view with a QListView. Provided for
38 * convenience for users who want to use View with QListView
39 * instead of QTreeView.
42 ListViewRowController::ListViewRowController( QListView
* lv
, QAbstractProxyModel
* proxy
)
43 : _d( new Private(lv
,proxy
) )
47 ListViewRowController::~ListViewRowController()
54 int ListViewRowController::headerHeight() const
56 return d
->listview
->viewport()->y()-d
->listview
->frameWidth();
59 int ListViewRowController::maximumItemHeight() const
61 return d
->listview
->fontMetrics().height();
64 int ListViewRowController::totalHeight() const
66 return d
->listview
->verticalScrollBar()->maximum()+d
->listview
->viewport()->height();
69 bool ListViewRowController::isRowVisible( const QModelIndex
& _idx
) const
71 const QModelIndex idx
= d
->proxy
->mapToSource( _idx
);
72 assert( idx
.isValid() ? ( idx
.model() == d
->listview
->model() ):( true ) );
73 return d
->listview
->visualRect(idx
).isValid();
76 bool ListViewRowController::isRowExpanded( const QModelIndex
& _idx
) const
81 Span
ListViewRowController::rowGeometry( const QModelIndex
& _idx
) const
83 const QModelIndex idx
= d
->proxy
->mapToSource( _idx
);
84 assert( idx
.isValid() ? ( idx
.model() == d
->listview
->model() ):( true ) );
85 QRect r
= d
->listview
->visualRect(idx
).translated( QPoint( 0,
86 static_cast<Private::HackListView
*>(d
->listview
)->verticalOffset() ) );
87 return Span( r
.y(), r
.height() );
90 QModelIndex
ListViewRowController::indexAt( int height
) const
92 return d
->proxy
->mapFromSource( d
->listview
->indexAt( QPoint( 1,height
) ) );
95 QModelIndex
ListViewRowController::indexAbove( const QModelIndex
& _idx
) const
97 const QModelIndex idx
= d
->proxy
->mapToSource( _idx
);
98 return d
->proxy
->mapFromSource( idx
.sibling( idx
.row()-1, idx
.column()) );
101 QModelIndex
ListViewRowController::indexBelow( const QModelIndex
& _idx
) const
103 const QModelIndex idx
= d
->proxy
->mapToSource( _idx
);
104 if( !idx
.isValid() || idx
.column()!=0 ) return QModelIndex();
105 if( idx
.model()->rowCount(idx
.parent())<idx
.row()+1 ) return QModelIndex();
106 return d
->proxy
->mapFromSource( idx
.sibling( idx
.row()+1, idx
.column()) );