Chris@57: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@46: Chris@57: /* Chris@57: EasyMercurial Chris@57: Chris@57: Based on HgExplorer by Jari Korhonen Chris@57: Copyright (c) 2010 Jari Korhonen Chris@57: Copyright (c) 2010 Chris Cannam Chris@57: Copyright (c) 2010 Queen Mary, University of London Chris@57: Chris@57: This program is free software; you can redistribute it and/or Chris@57: modify it under the terms of the GNU General Public License as Chris@57: published by the Free Software Foundation; either version 2 of the Chris@57: License, or (at your option) any later version. See the file Chris@57: COPYING included with this distribution for more information. Chris@57: */ Chris@46: Chris@46: #include "connectionitem.h" Chris@46: Chris@46: #include "changesetitem.h" Chris@53: #include "changeset.h" Chris@53: #include "colourset.h" Chris@46: Chris@46: #include Chris@46: Chris@46: QRectF Chris@46: ConnectionItem::boundingRect() const Chris@46: { Chris@46: if (!m_parent || !m_child) return QRectF(); Chris@53: float xscale = 100; Chris@53: float yscale = 90; Chris@46: float size = 50; Chris@53: return QRectF(xscale * m_child->column() + size/2 - 2, Chris@53: yscale * m_child->row() + size - 2, Chris@53: xscale * m_parent->column() - xscale * m_child->column() + 4, Chris@53: yscale * m_parent->row() - yscale * m_child->row() - size + 4) Chris@46: .normalized(); Chris@46: } Chris@46: Chris@46: void Chris@46: ConnectionItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *) Chris@46: { Chris@46: QPainterPath p; Chris@53: Chris@53: paint->save(); Chris@53: Chris@53: ColourSet *colourSet = ColourSet::instance(); Chris@53: QColor branchColour = colourSet->getColourFor(m_child->getChangeset()->branch()); Chris@54: Chris@54: QTransform t = paint->worldTransform(); Chris@54: float scale = std::min(t.m11(), t.m22()); Chris@54: if (scale < 0.1) { Chris@54: paint->setPen(QPen(branchColour, 0)); Chris@54: } else { Chris@54: paint->setPen(QPen(branchColour, 2)); Chris@54: } Chris@53: Chris@53: float xscale = 100; Chris@53: Chris@53: float yscale = 90; Chris@46: float size = 50; Chris@53: float ygap = yscale - size; Chris@53: Chris@53: int c_col = m_child->column(), c_row = m_child->row(); Chris@53: int p_col = m_parent->column(), p_row = m_parent->row(); Chris@53: Chris@53: float c_x = xscale * c_col + size/2; Chris@53: float p_x = xscale * p_col + size/2; Chris@53: Chris@53: p.moveTo(c_x, yscale * c_row + size); Chris@53: Chris@53: if (p_col == c_col) { Chris@53: Chris@53: p.lineTo(p_x, yscale * p_row); Chris@53: Chris@53: } else if (m_type == Split || m_type == Normal) { Chris@53: Chris@53: // place the bulk of the line on the child (i.e. branch) row Chris@53: Chris@53: if (abs(p_row - c_row) > 1) { Chris@53: p.lineTo(c_x, yscale * p_row - ygap); Chris@53: } Chris@53: Chris@53: p.cubicTo(c_x, yscale * p_row, Chris@53: p_x, yscale * p_row - ygap, Chris@53: p_x, yscale * p_row); Chris@53: Chris@53: } else if (m_type == Merge) { Chris@53: Chris@53: // place bulk of the line on the parent row Chris@53: Chris@53: p.cubicTo(c_x, yscale * c_row + size + ygap, Chris@53: p_x, yscale * c_row + size, Chris@53: p_x, yscale * c_row + size + ygap); Chris@53: Chris@53: if (abs(p_row - c_row) > 1) { Chris@53: p.lineTo(p_x, yscale * p_row); Chris@46: } Chris@46: } Chris@53: Chris@46: paint->drawPath(p); Chris@53: paint->restore(); Chris@46: } Chris@46: Chris@46: