annotate uncommitteditem.cpp @ 129:4986642800f0

* Initial work on showing uncommitted changes (as dashed box) in history graph
author Chris Cannam
date Mon, 29 Nov 2010 20:53:34 +0000
parents
children 2550aaa09240
rev   line source
Chris@129 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@129 2
Chris@129 3 /*
Chris@129 4 EasyMercurial
Chris@129 5
Chris@129 6 Based on HgExplorer by Jari Korhonen
Chris@129 7 Copyright (c) 2010 Jari Korhonen
Chris@129 8 Copyright (c) 2010 Chris Cannam
Chris@129 9 Copyright (c) 2010 Queen Mary, University of London
Chris@129 10
Chris@129 11 This program is free software; you can redistribute it and/or
Chris@129 12 modify it under the terms of the GNU General Public License as
Chris@129 13 published by the Free Software Foundation; either version 2 of the
Chris@129 14 License, or (at your option) any later version. See the file
Chris@129 15 COPYING included with this distribution for more information.
Chris@129 16 */
Chris@129 17
Chris@129 18 #include "uncommitteditem.h"
Chris@129 19 #include "colourset.h"
Chris@129 20 #include "debug.h"
Chris@129 21
Chris@129 22 #include <QPainter>
Chris@129 23 #include <QGraphicsScene>
Chris@129 24
Chris@129 25 UncommittedItem::UncommittedItem() :
Chris@129 26 m_column(0), m_row(0), m_wide(false)
Chris@129 27 {
Chris@129 28 m_font = QFont();
Chris@129 29 m_font.setPixelSize(11);
Chris@129 30 m_font.setBold(false);
Chris@129 31 m_font.setItalic(false);
Chris@129 32 }
Chris@129 33
Chris@129 34 QRectF
Chris@129 35 UncommittedItem::boundingRect() const
Chris@129 36 {
Chris@129 37 //!!! this stuff is gross, refactor with changesetitem
Chris@129 38 int w = 100;
Chris@129 39 if (m_wide) w = 180;
Chris@129 40 return QRectF(-((w-50)/2 - 1), -30, w - 3, 79);
Chris@129 41 }
Chris@129 42
Chris@129 43 void
Chris@129 44 UncommittedItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *option,
Chris@129 45 QWidget *w)
Chris@129 46 {
Chris@129 47 paint->save();
Chris@129 48
Chris@129 49 ColourSet *colourSet = ColourSet::instance();
Chris@129 50 QColor branchColour = colourSet->getColourFor(m_branch);
Chris@129 51
Chris@129 52 QFont f(m_font);
Chris@129 53
Chris@129 54 QTransform t = paint->worldTransform();
Chris@129 55 float scale = std::min(t.m11(), t.m22());
Chris@129 56 if (scale > 1.0) {
Chris@129 57 int ps = int((f.pixelSize() / scale) + 0.5);
Chris@129 58 if (ps < 8) ps = 8;
Chris@129 59 f.setPixelSize(ps);
Chris@129 60 }
Chris@129 61
Chris@129 62 if (scale < 0.1) {
Chris@129 63 paint->setPen(QPen(branchColour, 0, Qt::DashLine));
Chris@129 64 } else {
Chris@129 65 paint->setPen(QPen(branchColour, 2, Qt::DashLine));
Chris@129 66 }
Chris@129 67
Chris@129 68 paint->setFont(f);
Chris@129 69 QFontMetrics fm(f);
Chris@129 70 int fh = fm.height();
Chris@129 71
Chris@129 72 int width = 100;
Chris@129 73 if (m_wide) width = 180;
Chris@129 74 int x0 = -((width - 50) / 2 - 1);
Chris@129 75
Chris@129 76 int height = 49;
Chris@129 77 QRectF r(x0, 0, width - 3, height);
Chris@129 78 paint->drawRect(r);
Chris@129 79
Chris@129 80 QString label = tr("Uncommitted changes");
Chris@129 81 paint->drawText(-(fm.width(label) - 50)/2, 25 - fm.height()/2 + fm.ascent(), label);
Chris@129 82
Chris@129 83 paint->restore();
Chris@129 84 return;
Chris@129 85 }