annotate src/changesetdetailitem.cpp @ 680:21e03596dd93

Towards Win32 deployment
author Chris Cannam
date Fri, 07 Dec 2018 13:41:32 +0000
parents ce29dc775650
children c0b46d0514a7 751b21af6b6f
rev   line source
Chris@117 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@117 2
Chris@117 3 /*
Chris@117 4 EasyMercurial
Chris@117 5
Chris@117 6 Based on HgExplorer by Jari Korhonen
Chris@117 7 Copyright (c) 2010 Jari Korhonen
Chris@644 8 Copyright (c) 2013 Chris Cannam
Chris@644 9 Copyright (c) 2013 Queen Mary, University of London
Chris@117 10
Chris@117 11 This program is free software; you can redistribute it and/or
Chris@117 12 modify it under the terms of the GNU General Public License as
Chris@117 13 published by the Free Software Foundation; either version 2 of the
Chris@117 14 License, or (at your option) any later version. See the file
Chris@117 15 COPYING included with this distribution for more information.
Chris@117 16 */
Chris@117 17
Chris@117 18 #include "changesetdetailitem.h"
Chris@117 19 #include "changeset.h"
Chris@117 20 #include "textabbrev.h"
Chris@117 21 #include "colourset.h"
Chris@117 22 #include "debug.h"
Chris@118 23 #include "common.h"
Chris@117 24
Chris@118 25 #include <QTextDocument>
Chris@117 26 #include <QPainter>
Chris@600 27 #include <QAbstractTextDocumentLayout>
Chris@117 28
Chris@117 29 ChangesetDetailItem::ChangesetDetailItem(Changeset *cs) :
Chris@118 30 m_changeset(cs), m_doc(0)
Chris@117 31 {
Chris@117 32 m_font = QFont();
Chris@117 33 m_font.setPixelSize(11);
Chris@117 34 m_font.setBold(false);
Chris@117 35 m_font.setItalic(false);
Chris@118 36
Chris@118 37 makeDocument();
Chris@118 38 }
Chris@118 39
Chris@118 40 ChangesetDetailItem::~ChangesetDetailItem()
Chris@118 41 {
Chris@118 42 delete m_doc;
Chris@117 43 }
Chris@117 44
Chris@117 45 QRectF
Chris@117 46 ChangesetDetailItem::boundingRect() const
Chris@117 47 {
Chris@118 48 int w = 350;
Chris@118 49 m_doc->setTextWidth(w);
Chris@124 50 return QRectF(-10, -10, w + 10, m_doc->size().height() + 10);
Chris@117 51 }
Chris@117 52
Chris@402 53 QVariant
Chris@402 54 ChangesetDetailItem::itemChange(GraphicsItemChange c, const QVariant &v)
Chris@402 55 {
Chris@402 56 if (c == ItemVisibleHasChanged) {
Chris@402 57 bool visible = v.toBool();
Chris@402 58 DEBUG << "ChangesetDetailItem::itemChange: visible = " << visible << endl;
Chris@402 59 if (visible && scene()) {
Chris@402 60 ensureVisible();
Chris@402 61 }
Chris@402 62 }
Chris@402 63 return v;
Chris@402 64 }
Chris@402 65
Chris@117 66 void
Chris@117 67 ChangesetDetailItem::paint(QPainter *paint,
Chris@671 68 const QStyleOptionGraphicsItem *,
Chris@671 69 QWidget *)
Chris@117 70 {
Chris@117 71 paint->save();
Chris@117 72
Chris@117 73 ColourSet *colourSet = ColourSet::instance();
Chris@117 74 QColor branchColour = colourSet->getColourFor(m_changeset->branch());
Chris@117 75
Chris@117 76 QTransform t = paint->worldTransform();
Chris@117 77 float scale = std::min(t.m11(), t.m22());
Chris@117 78
Chris@117 79 if (scale < 0.1) {
Chris@117 80 paint->setPen(QPen(branchColour, 0));
Chris@117 81 } else {
Chris@117 82 paint->setPen(QPen(branchColour, 2));
Chris@117 83 }
Chris@600 84
Chris@117 85 int width = 350;
Chris@118 86 m_doc->setTextWidth(width);
Chris@118 87 int height = m_doc->size().height();
Chris@117 88
Chris@117 89 QRectF r(0.5, 0.5, width - 1, height - 1);
Chris@117 90 paint->setBrush(Qt::white);
Chris@386 91 paint->drawRoundedRect(r, 10, 10);
Chris@117 92
Chris@117 93 if (scale < 0.1) {
Chris@117 94 paint->restore();
Chris@117 95 return;
Chris@117 96 }
Chris@118 97
Chris@124 98 // little triangle connecting to its "owning" changeset item
Chris@124 99 paint->setBrush(branchColour);
Chris@124 100 QVector<QPointF> pts;
Chris@124 101 pts.push_back(QPointF(0, height/3 - 5));
Chris@124 102 pts.push_back(QPointF(0, height/3 + 5));
Chris@124 103 pts.push_back(QPointF(-10, height/3));
Chris@124 104 pts.push_back(QPointF(0, height/3 - 5));
Chris@124 105 paint->drawPolygon(QPolygonF(pts));
Chris@124 106
Chris@118 107 m_doc->drawContents(paint, r);
Chris@118 108
Chris@117 109 paint->restore();
Chris@117 110 }
Chris@118 111
Chris@118 112 void
Chris@118 113 ChangesetDetailItem::makeDocument()
Chris@118 114 {
Chris@118 115 delete m_doc;
Chris@118 116 m_doc = new QTextDocument;
Chris@125 117 m_doc->setHtml(m_changeset->formatHtml());
Chris@600 118 m_doc->setDefaultFont(m_font);
Chris@118 119 }
Chris@118 120