comparison src/changesetview.cpp @ 400:07eaf4e6003a

Merge from branch "item_appearance_adjustments"
author Chris Cannam
date Wed, 25 May 2011 14:59:09 +0100
parents 61bde1f0ff0a
children 533519ebc0cb
comparison
equal deleted inserted replaced
385:5cc0d897eb26 400:07eaf4e6003a
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) 2011 Chris Cannam
9 Copyright (c) 2011 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 "changesetview.h"
19 #include "changesetscene.h"
20 #include "colourset.h"
21 #include "debug.h"
22
23 #include <QScrollBar>
24
25 ChangesetView::ChangesetView() :
26 Panned()
27 {
28 connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
29 this, SLOT(horizontalScrollHappened()));
30 }
31
32 void
33 ChangesetView::horizontalScrollHappened()
34 {
35 DEBUG << "ChangesetView::horizontalScrollHappened" << endl;
36 invalidateScene(rect(), QGraphicsScene::BackgroundLayer);
37 viewport()->update();
38 }
39
40 void
41 ChangesetView::drawBackground(QPainter *paint, const QRectF &rect)
42 {
43 DEBUG << "ChangesetView::drawBackground" << endl;
44
45 ChangesetScene *cs = qobject_cast<ChangesetScene *>(scene());
46
47 if (!cs) {
48 QGraphicsView::drawBackground(paint, rect);
49 return;
50 }
51
52 DEBUG << "ChangesetView::drawBackground: have scene" << endl;
53
54 ChangesetScene::DateRanges ranges = cs->getDateRanges();
55
56 paint->setClipRect(rect);
57
58 DEBUG << "clip rect is " << rect << endl;
59
60 paint->save();
61 QFont f(paint->font());
62 f.setBold(true);
63 paint->setFont(f);
64
65 float x = mapToScene(0, 0).x();
66 float w = mapToScene(width(), 0).x() - x;
67 float px = mapToScene(5, 0).x();
68
69 QBrush oddBrush(QColor::fromRgb(250, 250, 250));
70 QBrush evenBrush(QColor::fromRgb(240, 240, 240));
71
72 //!!! todo: select only the ranges actually within range!
73
74 for (ChangesetScene::DateRanges::const_iterator i = ranges.begin();
75 i != ranges.end(); ++i) {
76
77 ChangesetScene::DateRange range = i.value();
78
79 QRectF r = QRectF(x, range.minrow * 90 - 25,
80 w, range.nrows * 90).normalized();
81
82 paint->fillRect(r, range.even ? evenBrush : oddBrush);
83 paint->drawText(px, range.minrow * 90 - 10, range.label);
84 }
85
86 paint->restore();
87 }
88
89