Chris@119
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@119
|
2
|
Chris@119
|
3 /*
|
Chris@119
|
4 EasyMercurial
|
Chris@119
|
5
|
Chris@119
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@119
|
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@119
|
10
|
Chris@119
|
11 This program is free software; you can redistribute it and/or
|
Chris@119
|
12 modify it under the terms of the GNU General Public License as
|
Chris@119
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@119
|
14 License, or (at your option) any later version. See the file
|
Chris@119
|
15 COPYING included with this distribution for more information.
|
Chris@119
|
16 */
|
Chris@119
|
17
|
Chris@119
|
18 #include "changesetscene.h"
|
Chris@119
|
19 #include "changesetitem.h"
|
Chris@141
|
20 #include "uncommitteditem.h"
|
Chris@397
|
21 #include "debug.h"
|
Chris@397
|
22
|
Chris@397
|
23 #include <QPainter>
|
Chris@397
|
24
|
Chris@119
|
25
|
Chris@119
|
26 ChangesetScene::ChangesetScene()
|
Chris@397
|
27 // Supply a non-NULL but trivial scene rect to inhibit automatic
|
Chris@397
|
28 // updates from QGraphicsScene, because we will set the rect
|
Chris@397
|
29 // explicitly in itemAddCompleted
|
Chris@397
|
30 : QGraphicsScene(QRectF(0, 0, 1, 1)), m_detailShown(0)
|
Chris@119
|
31 {
|
Chris@119
|
32 }
|
Chris@119
|
33
|
Chris@119
|
34 void
|
Chris@141
|
35 ChangesetScene::addChangesetItem(ChangesetItem *item)
|
Chris@141
|
36 {
|
Chris@141
|
37 addItem(item);
|
Chris@141
|
38
|
Chris@141
|
39 connect(item, SIGNAL(detailShown()),
|
Chris@141
|
40 this, SLOT(changesetDetailShown()));
|
Chris@141
|
41
|
Chris@168
|
42 connect(item, SIGNAL(detailHidden()),
|
Chris@168
|
43 this, SLOT(changesetDetailHidden()));
|
Chris@168
|
44
|
Chris@141
|
45 connect(item, SIGNAL(updateTo(QString)),
|
Chris@141
|
46 this, SIGNAL(updateTo(QString)));
|
Chris@141
|
47
|
Chris@141
|
48 connect(item, SIGNAL(diffToCurrent(QString)),
|
Chris@141
|
49 this, SIGNAL(diffToCurrent(QString)));
|
Chris@141
|
50
|
Chris@148
|
51 connect(item, SIGNAL(diffToParent(QString, QString)),
|
Chris@148
|
52 this, SIGNAL(diffToParent(QString, QString)));
|
Chris@141
|
53
|
Chris@289
|
54 connect(item, SIGNAL(showSummary(Changeset *)),
|
Chris@289
|
55 this, SIGNAL(showSummary(Changeset *)));
|
Chris@288
|
56
|
Chris@141
|
57 connect(item, SIGNAL(mergeFrom(QString)),
|
Chris@141
|
58 this, SIGNAL(mergeFrom(QString)));
|
Chris@141
|
59
|
Chris@278
|
60 connect(item, SIGNAL(newBranch(QString)),
|
Chris@278
|
61 this, SIGNAL(newBranch(QString)));
|
Chris@278
|
62
|
Chris@141
|
63 connect(item, SIGNAL(tag(QString)),
|
Chris@141
|
64 this, SIGNAL(tag(QString)));
|
Chris@141
|
65 }
|
Chris@141
|
66
|
Chris@141
|
67 void
|
Chris@141
|
68 ChangesetScene::addUncommittedItem(UncommittedItem *item)
|
Chris@141
|
69 {
|
Chris@141
|
70 addItem(item);
|
Chris@141
|
71
|
Chris@141
|
72 connect(item, SIGNAL(commit()),
|
Chris@141
|
73 this, SIGNAL(commit()));
|
Chris@141
|
74
|
Chris@141
|
75 connect(item, SIGNAL(revert()),
|
Chris@141
|
76 this, SIGNAL(revert()));
|
Chris@141
|
77
|
Chris@141
|
78 connect(item, SIGNAL(diff()),
|
Chris@141
|
79 this, SIGNAL(diffWorkingFolder()));
|
Chris@153
|
80
|
Chris@168
|
81 connect(item, SIGNAL(showSummary()),
|
Chris@168
|
82 this, SIGNAL(showSummary()));
|
Chris@168
|
83
|
Chris@153
|
84 connect(item, SIGNAL(showWork()),
|
Chris@153
|
85 this, SIGNAL(showWork()));
|
Chris@311
|
86
|
Chris@311
|
87 connect(item, SIGNAL(newBranch()),
|
Chris@311
|
88 this, SIGNAL(newBranch()));
|
Chris@311
|
89
|
Chris@311
|
90 connect(item, SIGNAL(noBranch()),
|
Chris@311
|
91 this, SIGNAL(noBranch()));
|
Chris@311
|
92
|
Chris@141
|
93 }
|
Chris@141
|
94
|
Chris@141
|
95 void
|
Chris@397
|
96 ChangesetScene::addDateRange(QString label, int minrow, int nrows, bool even)
|
Chris@168
|
97 {
|
Chris@397
|
98 DateRange dr;
|
Chris@397
|
99 dr.label = label;
|
Chris@397
|
100 dr.minrow = minrow;
|
Chris@397
|
101 dr.nrows = nrows;
|
Chris@397
|
102 dr.even = even;
|
Chris@397
|
103 m_dateRanges[minrow] = dr;
|
Chris@397
|
104 }
|
Chris@168
|
105
|
Chris@397
|
106 void
|
Chris@397
|
107 ChangesetScene::itemAddCompleted()
|
Chris@397
|
108 {
|
Chris@397
|
109 QRectF r = itemsBoundingRect();
|
Chris@397
|
110 float minwidth = 300; //!!!
|
Chris@397
|
111 DEBUG << "ChangesetScene::itemAddCompleted: minwidth = " << minwidth
|
Chris@397
|
112 << ", r = " << r << endl;
|
Chris@397
|
113 if (r.width() < minwidth) {
|
Chris@397
|
114 float edgediff = (minwidth - r.width()) / 2;
|
Chris@397
|
115 r.setLeft(r.left() - edgediff);
|
Chris@397
|
116 r.setRight(r.right() + edgediff);
|
Chris@397
|
117 }
|
Chris@397
|
118 DEBUG << "ChangesetScene::itemAddCompleted: r now is " << r << endl;
|
Chris@397
|
119 setSceneRect(r);
|
Chris@168
|
120 }
|
Chris@168
|
121
|
Chris@168
|
122 void
|
Chris@119
|
123 ChangesetScene::changesetDetailShown()
|
Chris@119
|
124 {
|
Chris@119
|
125 ChangesetItem *csi = qobject_cast<ChangesetItem *>(sender());
|
Chris@119
|
126 if (!csi) return;
|
Chris@119
|
127
|
Chris@124
|
128 if (m_detailShown && m_detailShown != csi) {
|
Chris@119
|
129 m_detailShown->hideDetail();
|
Chris@119
|
130 }
|
Chris@119
|
131 m_detailShown = csi;
|
Chris@401
|
132 itemAddCompleted();
|
Chris@401
|
133 csi->ensureVisible();
|
Chris@119
|
134 }
|
Chris@119
|
135
|
Chris@168
|
136 void
|
Chris@168
|
137 ChangesetScene::changesetDetailHidden()
|
Chris@168
|
138 {
|
Chris@168
|
139 m_detailShown = 0;
|
Chris@401
|
140 itemAddCompleted();
|
Chris@168
|
141 }
|
Chris@168
|
142
|
Chris@168
|
143 void
|
Chris@397
|
144 ChangesetScene::drawBackground(QPainter *paint, const QRectF &rect)
|
Chris@168
|
145 {
|
Chris@397
|
146 QGraphicsScene::drawBackground(paint, rect);
|
Chris@168
|
147 }
|
Chris@397
|
148
|
Chris@168
|
149
|
Chris@281
|
150 ChangesetItem *
|
Chris@281
|
151 ChangesetScene::getItemById(QString id)
|
Chris@281
|
152 {
|
Chris@281
|
153 foreach (QGraphicsItem *it, items()) {
|
Chris@281
|
154 ChangesetItem *csit = dynamic_cast<ChangesetItem *>(it);
|
Chris@281
|
155 if (csit && csit->getId() == id) return csit;
|
Chris@281
|
156 }
|
Chris@288
|
157 return 0;
|
Chris@281
|
158 }
|
Chris@281
|
159
|
Chris@281
|
160
|