~ubuntu-branches/ubuntu/raring/calligra/raring-proposed

« back to all changes in this revision

Viewing changes to 3rdparty/kdgantt/kdgantttreeviewrowcontroller.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-01-15 17:26:10 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20130115172610-b193s9546hyssmym
Tags: 1:2.5.94-0ubuntu1
New upstream RC release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 ** Copyright (C) 2001-2006 Klarälvdalens Datakonsult AB.  All rights reserved.
 
3
 **
 
4
 ** This file is part of the KD Gantt library.
 
5
 **
 
6
 ** This file may be used under the terms of the GNU General Public
 
7
 ** License versions 2.0 or 3.0 as published by the Free Software
 
8
 ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
 
9
 ** included in the packaging of this file.  Alternatively you may (at
 
10
 ** your option) use any later version of the GNU General Public
 
11
 ** License if such license has been publicly approved by
 
12
 ** Klarälvdalens Datakonsult AB (or its successors, if any).
 
13
 ** 
 
14
 ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
 
15
 ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
 
16
 ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
 
17
 ** not expressly granted herein.
 
18
 ** 
 
19
 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
20
 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
21
 **
 
22
 **********************************************************************/
 
23
#include "kdgantttreeviewrowcontroller.h"
 
24
#include "kdgantttreeviewrowcontroller_p.h"
 
25
 
 
26
#include <QAbstractProxyModel>
 
27
#include <QHeaderView>
 
28
 
 
29
#include <cassert>
 
30
 
 
31
using namespace KDGantt;
 
32
 
 
33
/*!\class TreeViewRowController
 
34
 * This is an implementation of AbstractRowController that
 
35
 * aligns a gantt view with a QTreeView.
 
36
 */
 
37
 
 
38
TreeViewRowController::TreeViewRowController( QTreeView* tv,
 
39
                                              QAbstractProxyModel* proxy )
 
40
  : _d( new Private )
 
41
{
 
42
    _d->treeview = static_cast<Private::HackTreeView*>(tv);
 
43
    _d->proxy = proxy;
 
44
}
 
45
 
 
46
TreeViewRowController::~TreeViewRowController()
 
47
{
 
48
    delete _d; _d=0;
 
49
}
 
50
 
 
51
#define d d_func()
 
52
 
 
53
int TreeViewRowController::headerHeight() const
 
54
{
 
55
  //return d->treeview->header()->sizeHint().height();
 
56
    return d->treeview->viewport()->y()-d->treeview->frameWidth();
 
57
}
 
58
 
 
59
int TreeViewRowController::maximumItemHeight() const
 
60
{
 
61
    return d->treeview->fontMetrics().height();
 
62
}
 
63
 
 
64
bool TreeViewRowController::isRowVisible( const QModelIndex& _idx ) const
 
65
{
 
66
  //qDebug() << _idx.model()<<d->proxy << d->treeview->model();
 
67
    const QModelIndex idx = d->proxy->mapToSource( _idx );
 
68
    assert( idx.isValid() ? ( idx.model() == d->treeview->model() ):( true ) );
 
69
    return d->treeview->visualRect(idx).isValid();
 
70
}
 
71
 
 
72
Span TreeViewRowController::rowGeometry( const QModelIndex& _idx ) const
 
73
{
 
74
    const QModelIndex idx = d->proxy->mapToSource( _idx );
 
75
    assert( idx.isValid() ? ( idx.model() == d->treeview->model() ):( true ) );
 
76
    QRect r = d->treeview->visualRect(idx).translated( QPoint( 0, d->treeview->verticalOffset() ) );
 
77
    return Span( r.y(), r.height() );
 
78
}
 
79
 
 
80
QModelIndex TreeViewRowController::indexAt( int height ) const
 
81
{
 
82
    return d->proxy->mapFromSource( d->treeview->indexAt( QPoint( 1,height ) ) );
 
83
}
 
84
 
 
85
QModelIndex TreeViewRowController::indexAbove( const QModelIndex& _idx ) const
 
86
{
 
87
    const QModelIndex idx = d->proxy->mapToSource( _idx );
 
88
    return d->proxy->mapFromSource( d->treeview->indexAbove( idx ) );
 
89
}
 
90
 
 
91
QModelIndex TreeViewRowController::indexBelow( const QModelIndex& _idx ) const
 
92
{
 
93
    const QModelIndex idx = d->proxy->mapToSource( _idx );
 
94
    return d->proxy->mapFromSource( d->treeview->indexBelow( idx ) );
 
95
}