annotate src/connectionitem.cpp @ 400:07eaf4e6003a

Merge from branch "item_appearance_adjustments"
author Chris Cannam
date Wed, 25 May 2011 14:59:09 +0100
parents ef31a55c86b6
children 470829a21f98
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@53 58 ColourSet *colourSet = ColourSet::instance();
Chris@145 59 QString branch;
Chris@145 60 if (m_child) branch = m_child->getChangeset()->branch();
Chris@145 61 else branch = m_uncommitted->branch();
Chris@145 62 QColor branchColour = colourSet->getColourFor(branch);
Chris@145 63
Chris@145 64 Qt::PenStyle ls = Qt::SolidLine;
Chris@145 65 if (!m_child) ls = Qt::DashLine;
Chris@54 66
Chris@54 67 QTransform t = paint->worldTransform();
Chris@54 68 float scale = std::min(t.m11(), t.m22());
Chris@145 69 if (scale < 0.2) {
Chris@145 70 paint->setPen(QPen(branchColour, 0, ls));
Chris@54 71 } else {
Chris@145 72 paint->setPen(QPen(branchColour, 2, ls));
Chris@54 73 }
Chris@53 74
Chris@53 75 float xscale = 100;
Chris@53 76
Chris@53 77 float yscale = 90;
Chris@46 78 float size = 50;
Chris@153 79 float ygap = yscale - size - 2;
Chris@53 80
Chris@53 81 int p_col = m_parent->column(), p_row = m_parent->row();
Chris@145 82 int c_col, c_row;
Chris@145 83 if (m_child) {
Chris@145 84 c_col = m_child->column(); c_row = m_child->row();
Chris@145 85 } else {
Chris@145 86 c_col = m_uncommitted->column(); c_row = m_uncommitted->row();
Chris@145 87 }
Chris@53 88
Chris@53 89 float c_x = xscale * c_col + size/2;
Chris@53 90 float p_x = xscale * p_col + size/2;
Chris@53 91
Chris@250 92 // ensure line reaches the box, even if it's in a small height --
Chris@250 93 // doesn't matter if we overshoot as the box is opaque and has a
Chris@250 94 // greater Z value
Chris@250 95 p.moveTo(c_x, yscale * c_row + size - 20);
Chris@250 96
Chris@250 97 p.lineTo(c_x, yscale * c_row + size);
Chris@53 98
Chris@53 99 if (p_col == c_col) {
Chris@53 100
Chris@53 101 p.lineTo(p_x, yscale * p_row);
Chris@53 102
Chris@53 103 } else if (m_type == Split || m_type == Normal) {
Chris@53 104
Chris@53 105 // place the bulk of the line on the child (i.e. branch) row
Chris@53 106
Chris@53 107 if (abs(p_row - c_row) > 1) {
Chris@53 108 p.lineTo(c_x, yscale * p_row - ygap);
Chris@53 109 }
Chris@53 110
Chris@53 111 p.cubicTo(c_x, yscale * p_row,
Chris@53 112 p_x, yscale * p_row - ygap,
Chris@53 113 p_x, yscale * p_row);
Chris@53 114
Chris@53 115 } else if (m_type == Merge) {
Chris@53 116
Chris@53 117 // place bulk of the line on the parent row
Chris@53 118
Chris@53 119 p.cubicTo(c_x, yscale * c_row + size + ygap,
Chris@53 120 p_x, yscale * c_row + size,
Chris@53 121 p_x, yscale * c_row + size + ygap);
Chris@53 122
Chris@53 123 if (abs(p_row - c_row) > 1) {
Chris@53 124 p.lineTo(p_x, yscale * p_row);
Chris@46 125 }
Chris@46 126 }
Chris@53 127
Chris@387 128 // ensure line reaches the node -- again doesn't matter if we
Chris@387 129 // overshoot
Chris@387 130 p.lineTo(p_x, yscale * p_row + 20);
Chris@387 131
Chris@46 132 paint->drawPath(p);
Chris@53 133 paint->restore();
Chris@46 134 }
Chris@46 135
Chris@46 136