annotate dateitem.cpp @ 359:550650bbb959 feature_91

Add "Open Recent". Fixes #91
author Chris Cannam
date Thu, 17 Mar 2011 16:35:38 +0000
parents 8fd71f570884
children
rev   line source
Chris@57 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@57 2
Chris@57 3 /*
Chris@57 4 EasyMercurial
Chris@57 5
Chris@57 6 Based on HgExplorer by Jari Korhonen
Chris@57 7 Copyright (c) 2010 Jari Korhonen
Chris@244 8 Copyright (c) 2011 Chris Cannam
Chris@244 9 Copyright (c) 2011 Queen Mary, University of London
Chris@57 10
Chris@57 11 This program is free software; you can redistribute it and/or
Chris@57 12 modify it under the terms of the GNU General Public License as
Chris@57 13 published by the Free Software Foundation; either version 2 of the
Chris@57 14 License, or (at your option) any later version. See the file
Chris@57 15 COPYING included with this distribution for more information.
Chris@57 16 */
Chris@53 17
Chris@53 18 #include "dateitem.h"
Chris@53 19
Chris@168 20 #include "debug.h"
Chris@168 21
Chris@53 22 #include <QPainter>
Chris@53 23 #include <QBrush>
Chris@53 24 #include <QFont>
Chris@168 25 #include <QGraphicsSceneMouseEvent>
Chris@168 26
Chris@168 27 DateItem::DateItem() :
Chris@168 28 m_minrow(0), m_maxrow(0),
Chris@168 29 m_mincol(0), m_maxcol(0),
Chris@168 30 m_even(false)
Chris@168 31 {
Chris@168 32 }
Chris@53 33
Chris@53 34 void
Chris@53 35 DateItem::setRows(int minrow, int n)
Chris@53 36 {
Chris@53 37 m_minrow = minrow;
Chris@53 38 m_maxrow = minrow + n - 1;
Chris@53 39 setY(m_minrow * 90);
Chris@53 40 }
Chris@53 41
Chris@53 42 void
Chris@53 43 DateItem::setCols(int mincol, int n)
Chris@53 44 {
Chris@53 45 m_mincol = mincol;
Chris@53 46 m_maxcol = mincol + n - 1;
Chris@53 47 setX(m_mincol * 100);
Chris@53 48 }
Chris@53 49
Chris@168 50 void
Chris@168 51 DateItem::mousePressEvent(QGraphicsSceneMouseEvent *e)
Chris@168 52 {
Chris@168 53 DEBUG << "DateItem::mousePressEvent" << endl;
Chris@168 54 if (e->button() == Qt::LeftButton) {
Chris@168 55 emit clicked();
Chris@168 56 }
Chris@168 57 e->ignore();
Chris@168 58 }
Chris@168 59
Chris@53 60 QRectF
Chris@53 61 DateItem::boundingRect() const
Chris@53 62 {
Chris@53 63 return QRectF(-75, -25,
Chris@53 64 (m_maxcol - m_mincol + 1) * 100 + 100,
Chris@53 65 (m_maxrow - m_minrow + 1) * 90).normalized();
Chris@53 66 }
Chris@53 67
Chris@53 68 void
Chris@53 69 DateItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *opt, QWidget *w)
Chris@53 70 {
Chris@53 71 QBrush brush;
Chris@53 72
Chris@53 73 if (m_even) {
Chris@53 74 QColor c(QColor::fromRgb(240, 240, 240));
Chris@53 75 brush = QBrush(c);
Chris@53 76 } else {
Chris@53 77 QColor c(QColor::fromRgb(250, 250, 250));
Chris@53 78 brush = QBrush(c);
Chris@53 79 }
Chris@53 80
Chris@53 81 paint->fillRect(boundingRect(), brush);
Chris@53 82
Chris@53 83 paint->save();
Chris@53 84 QFont f(paint->font());
Chris@53 85 f.setBold(true);
Chris@53 86 paint->setFont(f);
Chris@53 87 paint->drawText(-70, -10, m_dateString);
Chris@53 88 paint->restore();
Chris@53 89 }
Chris@53 90
Chris@53 91