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