Chris@397: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@397: Chris@397: /* Chris@397: EasyMercurial Chris@397: Chris@397: Based on HgExplorer by Jari Korhonen Chris@397: Copyright (c) 2010 Jari Korhonen Chris@644: Copyright (c) 2013 Chris Cannam Chris@644: Copyright (c) 2013 Queen Mary, University of London Chris@397: Chris@397: This program is free software; you can redistribute it and/or Chris@397: modify it under the terms of the GNU General Public License as Chris@397: published by the Free Software Foundation; either version 2 of the Chris@397: License, or (at your option) any later version. See the file Chris@397: COPYING included with this distribution for more information. Chris@397: */ Chris@397: Chris@397: #include "changesetview.h" Chris@397: #include "changesetscene.h" Chris@397: #include "colourset.h" Chris@397: #include "debug.h" Chris@678: #include "common.h" Chris@397: Chris@397: #include Chris@397: Chris@397: ChangesetView::ChangesetView() : Chris@397: Panned() Chris@397: { Chris@397: connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), Chris@397: this, SLOT(horizontalScrollHappened())); Chris@397: } Chris@397: Chris@397: void Chris@397: ChangesetView::horizontalScrollHappened() Chris@397: { Chris@397: DEBUG << "ChangesetView::horizontalScrollHappened" << endl; Chris@397: invalidateScene(rect(), QGraphicsScene::BackgroundLayer); Chris@397: viewport()->update(); Chris@397: } Chris@397: Chris@397: void Chris@397: ChangesetView::drawBackground(QPainter *paint, const QRectF &rect) Chris@397: { Chris@397: DEBUG << "ChangesetView::drawBackground" << endl; Chris@397: Chris@397: ChangesetScene *cs = qobject_cast(scene()); Chris@397: Chris@397: if (!cs) { Chris@397: QGraphicsView::drawBackground(paint, rect); Chris@397: return; Chris@397: } Chris@397: Chris@397: DEBUG << "ChangesetView::drawBackground: have scene" << endl; Chris@397: Chris@397: ChangesetScene::DateRanges ranges = cs->getDateRanges(); Chris@397: Chris@397: paint->setClipRect(rect); Chris@397: Chris@397: DEBUG << "clip rect is " << rect << endl; Chris@397: Chris@397: paint->save(); Chris@397: QFont f(paint->font()); Chris@397: f.setBold(true); Chris@397: paint->setFont(f); Chris@397: Chris@397: float x = mapToScene(0, 0).x(); Chris@397: float w = mapToScene(width(), 0).x() - x; Chris@397: float px = mapToScene(5, 0).x(); Chris@397: Chris@397: QBrush oddBrush(QColor::fromRgb(250, 250, 250)); Chris@397: QBrush evenBrush(QColor::fromRgb(240, 240, 240)); Chris@397: Chris@397: //!!! todo: select only the ranges actually within range! Chris@397: Chris@397: for (ChangesetScene::DateRanges::const_iterator i = ranges.begin(); Chris@397: i != ranges.end(); ++i) { Chris@397: Chris@397: ChangesetScene::DateRange range = i.value(); Chris@397: Chris@678: int rowSpace = scalePixelSize(90); Chris@678: Chris@678: QRectF r = QRectF(x, range.minrow * rowSpace - scalePixelSize(25), Chris@678: w, range.nrows * rowSpace).normalized(); Chris@397: Chris@397: paint->fillRect(r, range.even ? evenBrush : oddBrush); Chris@678: paint->drawText(px, range.minrow * rowSpace - scalePixelSize(10), range.label); Chris@397: } Chris@397: Chris@397: paint->restore(); Chris@397: } Chris@397: Chris@397: