File indexing completed on 2024-05-12 15:54:28
0001 /* 0002 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KGantt library. 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 0018 */ 0019 0020 #include "kganttlistviewrowcontroller.h" 0021 #include "kganttlistviewrowcontroller_p.h" 0022 0023 #include <QAbstractProxyModel> 0024 #include <QScrollBar> 0025 0026 #include <cassert> 0027 0028 using namespace KGantt; 0029 0030 0031 0032 ListViewRowController::ListViewRowController( QListView* lv, QAbstractProxyModel* proxy ) 0033 : _d( new Private(lv,proxy) ) 0034 { 0035 } 0036 0037 ListViewRowController::~ListViewRowController() 0038 { 0039 delete _d; _d = nullptr; 0040 } 0041 0042 #define d d_func() 0043 0044 int ListViewRowController::headerHeight() const 0045 { 0046 return d->listview->viewport()->y()-d->listview->frameWidth(); 0047 } 0048 0049 int ListViewRowController::maximumItemHeight() const 0050 { 0051 return d->listview->fontMetrics().height(); 0052 } 0053 0054 int ListViewRowController::totalHeight() const 0055 { 0056 return d->listview->verticalScrollBar()->maximum()+d->listview->viewport()->height(); 0057 } 0058 0059 bool ListViewRowController::isRowVisible( const QModelIndex& _idx ) const 0060 { 0061 const QModelIndex idx = d->proxy->mapToSource( _idx ); 0062 assert( idx.isValid() ? ( idx.model() == d->listview->model() ):( true ) ); 0063 return d->listview->visualRect(idx).isValid(); 0064 } 0065 0066 bool ListViewRowController::isRowExpanded( const QModelIndex& _idx ) const 0067 { 0068 Q_UNUSED(_idx); 0069 0070 return false; 0071 } 0072 0073 Span ListViewRowController::rowGeometry( const QModelIndex& _idx ) const 0074 { 0075 const QModelIndex idx = d->proxy->mapToSource( _idx ); 0076 assert( idx.isValid() ? ( idx.model() == d->listview->model() ):( true ) ); 0077 QRect r = d->listview->visualRect(idx).translated( QPoint( 0, 0078 static_cast<Private::HackListView*>(d->listview)->verticalOffset() ) ); 0079 return Span( r.y(), r.height() ); 0080 } 0081 0082 QModelIndex ListViewRowController::indexAt( int height ) const 0083 { 0084 return d->proxy->mapFromSource( d->listview->indexAt( QPoint( 1,height ) ) ); 0085 } 0086 0087 QModelIndex ListViewRowController::indexAbove( const QModelIndex& _idx ) const 0088 { 0089 const QModelIndex idx = d->proxy->mapToSource( _idx ); 0090 return d->proxy->mapFromSource( idx.sibling( idx.row()-1, idx.column()) ); 0091 } 0092 0093 QModelIndex ListViewRowController::indexBelow( const QModelIndex& _idx ) const 0094 { 0095 const QModelIndex idx = d->proxy->mapToSource( _idx ); 0096 if ( !idx.isValid() || idx.column()!=0 ) return QModelIndex(); 0097 if ( idx.model()->rowCount(idx.parent())<idx.row()+1 ) return QModelIndex(); 0098 return d->proxy->mapFromSource( idx.sibling( idx.row()+1, idx.column()) ); 0099 } 0100