annotate src/connectionitem.cpp @ 507:459aa20d3eee

use non-redirecting domain name
author Chris Cannam
date Tue, 18 Oct 2011 09:54:21 +0100
parents 470829a21f98
children 2981d2defa61
rev   line source
Chris@57 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@46 2
Chris@57 3 /*
Chris@57 4 EasyMercurial
Chris@57 5
Chris@57 6 Based on HgExplorer by Jari Korhonen
Chris@57 7 Copyright (c) 2010 Jari Korhonen
Chris@244 8 Copyright (c) 2011 Chris Cannam
Chris@244 9 Copyright (c) 2011 Queen Mary, University of London
Chris@57 10
Chris@57 11 This program is free software; you can redistribute it and/or
Chris@57 12 modify it under the terms of the GNU General Public License as
Chris@57 13 published by the Free Software Foundation; either version 2 of the
Chris@57 14 License, or (at your option) any later version. See the file
Chris@57 15 COPYING included with this distribution for more information.
Chris@57 16 */
Chris@46 17
Chris@46 18 #include "connectionitem.h"
Chris@145 19 #include "uncommitteditem.h"
Chris@46 20
Chris@46 21 #include "changesetitem.h"
Chris@53 22 #include "changeset.h"
Chris@53 23 #include "colourset.h"
Chris@46 24
Chris@46 25 #include <QPainter>
Chris@46 26
Chris@46 27 QRectF
Chris@46 28 ConnectionItem::boundingRect() const
Chris@46 29 {
Chris@145 30 if (!m_parent || !(m_child || m_uncommitted)) return QRectF();
Chris@53 31 float xscale = 100;
Chris@53 32 float yscale = 90;
Chris@46 33 float size = 50;
Chris@145 34
Chris@145 35 int p_col = m_parent->column(), p_row = m_parent->row();
Chris@145 36 int c_col, c_row;
Chris@145 37 if (m_child) {
Chris@145 38 c_col = m_child->column(); c_row = m_child->row();
Chris@145 39 } else {
Chris@145 40 c_col = m_uncommitted->column(); c_row = m_uncommitted->row();
Chris@145 41 }
Chris@145 42
Chris@145 43 return QRectF(xscale * c_col + size/2 - 2,
Chris@387 44 yscale * c_row + size - 22,
Chris@390 45 xscale * p_col - xscale * c_col + 6,
Chris@387 46 yscale * p_row - yscale * c_row - size + 44)
Chris@46 47 .normalized();
Chris@46 48 }
Chris@46 49
Chris@46 50 void
Chris@46 51 ConnectionItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *)
Chris@46 52 {
Chris@145 53 if (!m_parent || !(m_child || m_uncommitted)) return;
Chris@46 54 QPainterPath p;
Chris@53 55
Chris@53 56 paint->save();
Chris@53 57
Chris@506 58 int alpha = 255;
Chris@506 59 if (m_child && m_child->isClosed()) alpha = 90;
Chris@506 60
Chris@53 61 ColourSet *colourSet = ColourSet::instance();
Chris@145 62 QString branch;
Chris@145 63 if (m_child) branch = m_child->getChangeset()->branch();
Chris@145 64 else branch = m_uncommitted->branch();
Chris@145 65 QColor branchColour = colourSet->getColourFor(branch);
Chris@145 66
Chris@506 67 branchColour.setAlpha(alpha);
Chris@506 68
Chris@145 69 Qt::PenStyle ls = Qt::SolidLine;
Chris@145 70 if (!m_child) ls = Qt::DashLine;
Chris@54 71
Chris@54 72 QTransform t = paint->worldTransform();
Chris@54 73 float scale = std::min(t.m11(), t.m22());
Chris@145 74 if (scale < 0.2) {
Chris@145 75 paint->setPen(QPen(branchColour, 0, ls));
Chris@54 76 } else {
Chris@145 77 paint->setPen(QPen(branchColour, 2, ls));
Chris@54 78 }
Chris@53 79
Chris@53 80 float xscale = 100;
Chris@53 81
Chris@53 82 float yscale = 90;
Chris@46 83 float size = 50;
Chris@153 84 float ygap = yscale - size - 2;
Chris@53 85
Chris@53 86 int p_col = m_parent->column(), p_row = m_parent->row();
Chris@145 87 int c_col, c_row;
Chris@145 88 if (m_child) {
Chris@145 89 c_col = m_child->column(); c_row = m_child->row();
Chris@145 90 } else {
Chris@145 91 c_col = m_uncommitted->column(); c_row = m_uncommitted->row();
Chris@145 92 }
Chris@53 93
Chris@53 94 float c_x = xscale * c_col + size/2;
Chris@53 95 float p_x = xscale * p_col + size/2;
Chris@53 96
Chris@250 97 // ensure line reaches the box, even if it's in a small height --
Chris@250 98 // doesn't matter if we overshoot as the box is opaque and has a
Chris@250 99 // greater Z value
Chris@250 100 p.moveTo(c_x, yscale * c_row + size - 20);
Chris@250 101
Chris@250 102 p.lineTo(c_x, yscale * c_row + size);
Chris@53 103
Chris@53 104 if (p_col == c_col) {
Chris@53 105
Chris@53 106 p.lineTo(p_x, yscale * p_row);
Chris@53 107
Chris@53 108 } else if (m_type == Split || m_type == Normal) {
Chris@53 109
Chris@53 110 // place the bulk of the line on the child (i.e. branch) row
Chris@53 111
Chris@53 112 if (abs(p_row - c_row) > 1) {
Chris@53 113 p.lineTo(c_x, yscale * p_row - ygap);
Chris@53 114 }
Chris@53 115
Chris@53 116 p.cubicTo(c_x, yscale * p_row,
Chris@53 117 p_x, yscale * p_row - ygap,
Chris@53 118 p_x, yscale * p_row);
Chris@53 119
Chris@53 120 } else if (m_type == Merge) {
Chris@53 121
Chris@53 122 // place bulk of the line on the parent row
Chris@53 123
Chris@53 124 p.cubicTo(c_x, yscale * c_row + size + ygap,
Chris@53 125 p_x, yscale * c_row + size,
Chris@53 126 p_x, yscale * c_row + size + ygap);
Chris@53 127
Chris@53 128 if (abs(p_row - c_row) > 1) {
Chris@53 129 p.lineTo(p_x, yscale * p_row);
Chris@46 130 }
Chris@46 131 }
Chris@53 132
Chris@387 133 // ensure line reaches the node -- again doesn't matter if we
Chris@387 134 // overshoot
Chris@387 135 p.lineTo(p_x, yscale * p_row + 20);
Chris@387 136
Chris@46 137 paint->drawPath(p);
Chris@53 138 paint->restore();
Chris@46 139 }
Chris@46 140
Chris@46 141