Chris@117: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@117: Chris@117: /* Chris@117: EasyMercurial Chris@117: Chris@117: Based on HgExplorer by Jari Korhonen Chris@117: Copyright (c) 2010 Jari Korhonen Chris@644: Copyright (c) 2013 Chris Cannam Chris@644: Copyright (c) 2013 Queen Mary, University of London Chris@117: Chris@117: This program is free software; you can redistribute it and/or Chris@117: modify it under the terms of the GNU General Public License as Chris@117: published by the Free Software Foundation; either version 2 of the Chris@117: License, or (at your option) any later version. See the file Chris@117: COPYING included with this distribution for more information. Chris@117: */ Chris@117: Chris@117: #include "changesetdetailitem.h" Chris@117: #include "changeset.h" Chris@117: #include "textabbrev.h" Chris@117: #include "colourset.h" Chris@117: #include "debug.h" Chris@118: #include "common.h" Chris@117: Chris@118: #include Chris@117: #include Chris@600: #include Chris@117: Chris@117: ChangesetDetailItem::ChangesetDetailItem(Changeset *cs) : Chris@118: m_changeset(cs), m_doc(0) Chris@117: { Chris@117: m_font = QFont(); Chris@117: m_font.setPixelSize(11); Chris@117: m_font.setBold(false); Chris@117: m_font.setItalic(false); Chris@118: Chris@118: makeDocument(); Chris@118: } Chris@118: Chris@118: ChangesetDetailItem::~ChangesetDetailItem() Chris@118: { Chris@118: delete m_doc; Chris@117: } Chris@117: Chris@117: QRectF Chris@117: ChangesetDetailItem::boundingRect() const Chris@117: { Chris@118: int w = 350; Chris@118: m_doc->setTextWidth(w); Chris@124: return QRectF(-10, -10, w + 10, m_doc->size().height() + 10); Chris@117: } Chris@117: Chris@402: QVariant Chris@402: ChangesetDetailItem::itemChange(GraphicsItemChange c, const QVariant &v) Chris@402: { Chris@402: if (c == ItemVisibleHasChanged) { Chris@402: bool visible = v.toBool(); Chris@402: DEBUG << "ChangesetDetailItem::itemChange: visible = " << visible << endl; Chris@402: if (visible && scene()) { Chris@402: ensureVisible(); Chris@402: } Chris@402: } Chris@402: return v; Chris@402: } Chris@402: Chris@117: void Chris@117: ChangesetDetailItem::paint(QPainter *paint, Chris@671: const QStyleOptionGraphicsItem *, Chris@671: QWidget *) Chris@117: { Chris@117: paint->save(); Chris@117: Chris@117: ColourSet *colourSet = ColourSet::instance(); Chris@117: QColor branchColour = colourSet->getColourFor(m_changeset->branch()); Chris@117: Chris@117: QTransform t = paint->worldTransform(); Chris@117: float scale = std::min(t.m11(), t.m22()); Chris@117: Chris@117: if (scale < 0.1) { Chris@117: paint->setPen(QPen(branchColour, 0)); Chris@117: } else { Chris@117: paint->setPen(QPen(branchColour, 2)); Chris@117: } Chris@600: Chris@117: int width = 350; Chris@118: m_doc->setTextWidth(width); Chris@118: int height = m_doc->size().height(); Chris@117: Chris@117: QRectF r(0.5, 0.5, width - 1, height - 1); Chris@117: paint->setBrush(Qt::white); Chris@386: paint->drawRoundedRect(r, 10, 10); Chris@117: Chris@117: if (scale < 0.1) { Chris@117: paint->restore(); Chris@117: return; Chris@117: } Chris@118: Chris@124: // little triangle connecting to its "owning" changeset item Chris@124: paint->setBrush(branchColour); Chris@124: QVector pts; Chris@124: pts.push_back(QPointF(0, height/3 - 5)); Chris@124: pts.push_back(QPointF(0, height/3 + 5)); Chris@124: pts.push_back(QPointF(-10, height/3)); Chris@124: pts.push_back(QPointF(0, height/3 - 5)); Chris@124: paint->drawPolygon(QPolygonF(pts)); Chris@124: Chris@118: m_doc->drawContents(paint, r); Chris@118: Chris@117: paint->restore(); Chris@117: } Chris@118: Chris@118: void Chris@118: ChangesetDetailItem::makeDocument() Chris@118: { Chris@118: delete m_doc; Chris@118: m_doc = new QTextDocument; Chris@125: m_doc->setHtml(m_changeset->formatHtml()); Chris@600: m_doc->setDefaultFont(m_font); Chris@118: } Chris@118: