| 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@397 | 62     f.setBold(true); | 
| Chris@397 | 63     paint->setFont(f); | 
| Chris@397 | 64 | 
| Chris@397 | 65     float x = mapToScene(0, 0).x(); | 
| Chris@397 | 66     float w = mapToScene(width(), 0).x() - x; | 
| Chris@397 | 67     float px = mapToScene(5, 0).x(); | 
| Chris@397 | 68 | 
| Chris@397 | 69     QBrush oddBrush(QColor::fromRgb(250, 250, 250)); | 
| Chris@397 | 70     QBrush evenBrush(QColor::fromRgb(240, 240, 240)); | 
| Chris@397 | 71 | 
| Chris@397 | 72     //!!! todo: select only the ranges actually within range! | 
| Chris@397 | 73 | 
| Chris@397 | 74     for (ChangesetScene::DateRanges::const_iterator i = ranges.begin(); | 
| Chris@397 | 75          i != ranges.end(); ++i) { | 
| Chris@397 | 76 | 
| Chris@397 | 77 	ChangesetScene::DateRange range = i.value(); | 
| Chris@397 | 78 | 
| Chris@397 | 79         QRectF r = QRectF(x, range.minrow * 90 - 25, | 
| Chris@397 | 80 			  w, range.nrows * 90).normalized(); | 
| Chris@397 | 81 | 
| Chris@397 | 82 	paint->fillRect(r, range.even ? evenBrush : oddBrush); | 
| Chris@397 | 83         paint->drawText(px, range.minrow * 90 - 10, range.label); | 
| Chris@397 | 84     } | 
| Chris@397 | 85 | 
| Chris@397 | 86     paint->restore(); | 
| Chris@397 | 87 } | 
| Chris@397 | 88 | 
| Chris@397 | 89 |