annotate src/changesetview.cpp @ 678:c0b46d0514a7 scale

Incomplete scaling updates. Should do this differently
author Chris Cannam
date Thu, 06 Dec 2018 14:55:45 +0000
parents ae67ea0af696
children
rev   line source
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@678 22 #include "common.h"
Chris@397 23
Chris@397 24 #include <QScrollBar>
Chris@397 25
Chris@397 26 ChangesetView::ChangesetView() :
Chris@397 27 Panned()
Chris@397 28 {
Chris@397 29 connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
Chris@397 30 this, SLOT(horizontalScrollHappened()));
Chris@397 31 }
Chris@397 32
Chris@397 33 void
Chris@397 34 ChangesetView::horizontalScrollHappened()
Chris@397 35 {
Chris@397 36 DEBUG << "ChangesetView::horizontalScrollHappened" << endl;
Chris@397 37 invalidateScene(rect(), QGraphicsScene::BackgroundLayer);
Chris@397 38 viewport()->update();
Chris@397 39 }
Chris@397 40
Chris@397 41 void
Chris@397 42 ChangesetView::drawBackground(QPainter *paint, const QRectF &rect)
Chris@397 43 {
Chris@397 44 DEBUG << "ChangesetView::drawBackground" << endl;
Chris@397 45
Chris@397 46 ChangesetScene *cs = qobject_cast<ChangesetScene *>(scene());
Chris@397 47
Chris@397 48 if (!cs) {
Chris@397 49 QGraphicsView::drawBackground(paint, rect);
Chris@397 50 return;
Chris@397 51 }
Chris@397 52
Chris@397 53 DEBUG << "ChangesetView::drawBackground: have scene" << endl;
Chris@397 54
Chris@397 55 ChangesetScene::DateRanges ranges = cs->getDateRanges();
Chris@397 56
Chris@397 57 paint->setClipRect(rect);
Chris@397 58
Chris@397 59 DEBUG << "clip rect is " << rect << endl;
Chris@397 60
Chris@397 61 paint->save();
Chris@397 62 QFont f(paint->font());
Chris@397 63 f.setBold(true);
Chris@397 64 paint->setFont(f);
Chris@397 65
Chris@397 66 float x = mapToScene(0, 0).x();
Chris@397 67 float w = mapToScene(width(), 0).x() - x;
Chris@397 68 float px = mapToScene(5, 0).x();
Chris@397 69
Chris@397 70 QBrush oddBrush(QColor::fromRgb(250, 250, 250));
Chris@397 71 QBrush evenBrush(QColor::fromRgb(240, 240, 240));
Chris@397 72
Chris@397 73 //!!! todo: select only the ranges actually within range!
Chris@397 74
Chris@397 75 for (ChangesetScene::DateRanges::const_iterator i = ranges.begin();
Chris@397 76 i != ranges.end(); ++i) {
Chris@397 77
Chris@397 78 ChangesetScene::DateRange range = i.value();
Chris@397 79
Chris@678 80 int rowSpace = scalePixelSize(90);
Chris@678 81
Chris@678 82 QRectF r = QRectF(x, range.minrow * rowSpace - scalePixelSize(25),
Chris@678 83 w, range.nrows * rowSpace).normalized();
Chris@397 84
Chris@397 85 paint->fillRect(r, range.even ? evenBrush : oddBrush);
Chris@678 86 paint->drawText(px, range.minrow * rowSpace - scalePixelSize(10), range.label);
Chris@397 87 }
Chris@397 88
Chris@397 89 paint->restore();
Chris@397 90 }
Chris@397 91
Chris@397 92