File indexing completed on 2024-05-12 15:54:22
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 "kganttconstraintgraphicsitem.h" 0021 #include "kganttconstraintmodel.h" 0022 #include "kganttgraphicsscene.h" 0023 #include "kganttitemdelegate.h" 0024 #include "kganttsummaryhandlingproxymodel.h" 0025 0026 #include <QPainter> 0027 #include <QApplication> 0028 #include <QDebug> 0029 0030 using namespace KGantt; 0031 0032 0033 ConstraintGraphicsItem::ConstraintGraphicsItem( const Constraint& c, QGraphicsItem* parent, GraphicsScene* scene ) 0034 : QGraphicsItem( parent ), m_constraint( c ) 0035 { 0036 if ( scene ) 0037 scene->addItem( this ); 0038 setPos( QPointF( 0., 0. ) ); 0039 setAcceptHoverEvents( false ); 0040 setAcceptedMouseButtons( Qt::NoButton ); 0041 setZValue( 10. ); 0042 } 0043 0044 ConstraintGraphicsItem::~ConstraintGraphicsItem() 0045 { 0046 } 0047 0048 int ConstraintGraphicsItem::type() const 0049 { 0050 return Type; 0051 } 0052 0053 GraphicsScene* ConstraintGraphicsItem::scene() const 0054 { 0055 return qobject_cast<GraphicsScene*>( QGraphicsItem::scene() ); 0056 } 0057 0058 Constraint ConstraintGraphicsItem::proxyConstraint() const 0059 { 0060 return Constraint( scene()->summaryHandlingModel()->mapFromSource( m_constraint.startIndex() ), 0061 scene()->summaryHandlingModel()->mapFromSource( m_constraint.endIndex() ), 0062 m_constraint.type(), m_constraint.relationType(), m_constraint.dataMap() ); 0063 } 0064 0065 QRectF ConstraintGraphicsItem::boundingRect() const 0066 { 0067 return scene()->itemDelegate()->constraintBoundingRect( m_start, m_end, m_constraint ); 0068 } 0069 0070 void ConstraintGraphicsItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, 0071 QWidget* widget ) 0072 { 0073 Q_UNUSED( widget ); 0074 //qDebug() << "ConstraintGraphicsItem::paint(...), c=" << m_constraint; 0075 QStyleOptionGraphicsItem opt = *option; 0076 if (widget) { 0077 opt.palette = widget->palette(); 0078 }else { 0079 opt.palette = QApplication::palette(); 0080 } 0081 scene()->itemDelegate()->paintConstraintItem( painter, opt, m_start, m_end, m_constraint ); 0082 } 0083 0084 QString ConstraintGraphicsItem::ganttToolTip() const 0085 { 0086 return m_constraint.data( Qt::ToolTipRole ).toString(); 0087 } 0088 0089 void ConstraintGraphicsItem::setStart( const QPointF& start ) 0090 { 0091 prepareGeometryChange(); 0092 m_start = start; 0093 update(); 0094 } 0095 0096 void ConstraintGraphicsItem::setEnd( const QPointF& end ) 0097 { 0098 prepareGeometryChange(); 0099 m_end = end; 0100 update(); 0101 } 0102 0103 void ConstraintGraphicsItem::updateItem( const QPointF& start,const QPointF& end ) 0104 { 0105 setStart( start ); 0106 setEnd( end ); 0107 }