comparison src/dateitem.cpp @ 370:b9c153e00e84

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