Chris@397
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@397
|
2
|
Chris@397
|
3 /*
|
Chris@397
|
4 EasyMercurial
|
Chris@397
|
5
|
Chris@397
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@397
|
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@397
|
10
|
Chris@397
|
11 This program is free software; you can redistribute it and/or
|
Chris@397
|
12 modify it under the terms of the GNU General Public License as
|
Chris@397
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@397
|
14 License, or (at your option) any later version. See the file
|
Chris@397
|
15 COPYING included with this distribution for more information.
|
Chris@397
|
16 */
|
Chris@397
|
17
|
Chris@397
|
18 #include "changesetview.h"
|
Chris@397
|
19 #include "changesetscene.h"
|
Chris@397
|
20 #include "colourset.h"
|
Chris@397
|
21 #include "debug.h"
|
Chris@397
|
22
|
Chris@397
|
23 #include <QScrollBar>
|
Chris@397
|
24
|
Chris@397
|
25 ChangesetView::ChangesetView() :
|
Chris@397
|
26 Panned()
|
Chris@397
|
27 {
|
Chris@397
|
28 connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
|
Chris@397
|
29 this, SLOT(horizontalScrollHappened()));
|
Chris@397
|
30 }
|
Chris@397
|
31
|
Chris@397
|
32 void
|
Chris@397
|
33 ChangesetView::horizontalScrollHappened()
|
Chris@397
|
34 {
|
Chris@397
|
35 DEBUG << "ChangesetView::horizontalScrollHappened" << endl;
|
Chris@397
|
36 invalidateScene(rect(), QGraphicsScene::BackgroundLayer);
|
Chris@397
|
37 viewport()->update();
|
Chris@397
|
38 }
|
Chris@397
|
39
|
Chris@397
|
40 void
|
Chris@397
|
41 ChangesetView::drawBackground(QPainter *paint, const QRectF &rect)
|
Chris@397
|
42 {
|
Chris@397
|
43 DEBUG << "ChangesetView::drawBackground" << endl;
|
Chris@397
|
44
|
Chris@397
|
45 ChangesetScene *cs = qobject_cast<ChangesetScene *>(scene());
|
Chris@397
|
46
|
Chris@397
|
47 if (!cs) {
|
Chris@397
|
48 QGraphicsView::drawBackground(paint, rect);
|
Chris@397
|
49 return;
|
Chris@397
|
50 }
|
Chris@397
|
51
|
Chris@397
|
52 DEBUG << "ChangesetView::drawBackground: have scene" << endl;
|
Chris@397
|
53
|
Chris@397
|
54 ChangesetScene::DateRanges ranges = cs->getDateRanges();
|
Chris@397
|
55
|
Chris@397
|
56 paint->setClipRect(rect);
|
Chris@397
|
57
|
Chris@397
|
58 DEBUG << "clip rect is " << rect << endl;
|
Chris@397
|
59
|
Chris@397
|
60 paint->save();
|
Chris@397
|
61 QFont f(paint->font());
|
Chris@679
|
62 f.setPixelSize(11);
|
Chris@397
|
63 f.setBold(true);
|
Chris@683
|
64 QTransform t = paint->worldTransform();
|
Chris@683
|
65 float scale = std::min(t.m11(), t.m22());
|
Chris@683
|
66 if (scale > 1.0) {
|
Chris@683
|
67 #ifdef Q_OS_WIN32
|
Chris@683
|
68 f.setHintingPreference(QFont::PreferVerticalHinting);
|
Chris@683
|
69 #endif
|
Chris@683
|
70 }
|
Chris@397
|
71 paint->setFont(f);
|
Chris@397
|
72
|
Chris@397
|
73 float x = mapToScene(0, 0).x();
|
Chris@397
|
74 float w = mapToScene(width(), 0).x() - x;
|
Chris@397
|
75 float px = mapToScene(5, 0).x();
|
Chris@397
|
76
|
Chris@397
|
77 QBrush oddBrush(QColor::fromRgb(250, 250, 250));
|
Chris@397
|
78 QBrush evenBrush(QColor::fromRgb(240, 240, 240));
|
Chris@397
|
79
|
Chris@397
|
80 //!!! todo: select only the ranges actually within range!
|
Chris@397
|
81
|
Chris@397
|
82 for (ChangesetScene::DateRanges::const_iterator i = ranges.begin();
|
Chris@397
|
83 i != ranges.end(); ++i) {
|
Chris@397
|
84
|
Chris@397
|
85 ChangesetScene::DateRange range = i.value();
|
Chris@397
|
86
|
Chris@397
|
87 QRectF r = QRectF(x, range.minrow * 90 - 25,
|
Chris@397
|
88 w, range.nrows * 90).normalized();
|
Chris@397
|
89
|
Chris@397
|
90 paint->fillRect(r, range.even ? evenBrush : oddBrush);
|
Chris@397
|
91 paint->drawText(px, range.minrow * 90 - 10, range.label);
|
Chris@397
|
92 }
|
Chris@397
|
93
|
Chris@397
|
94 paint->restore();
|
Chris@397
|
95 }
|
Chris@397
|
96
|
Chris@397
|
97
|