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@514
|
63 connect(item, SIGNAL(closeBranch(QString)),
|
Chris@514
|
64 this, SIGNAL(closeBranch(QString)));
|
Chris@514
|
65
|
Chris@141
|
66 connect(item, SIGNAL(tag(QString)),
|
Chris@141
|
67 this, SIGNAL(tag(QString)));
|
Chris@141
|
68 }
|
Chris@141
|
69
|
Chris@141
|
70 void
|
Chris@141
|
71 ChangesetScene::addUncommittedItem(UncommittedItem *item)
|
Chris@141
|
72 {
|
Chris@141
|
73 addItem(item);
|
Chris@141
|
74
|
Chris@141
|
75 connect(item, SIGNAL(commit()),
|
Chris@141
|
76 this, SIGNAL(commit()));
|
Chris@141
|
77
|
Chris@141
|
78 connect(item, SIGNAL(revert()),
|
Chris@141
|
79 this, SIGNAL(revert()));
|
Chris@141
|
80
|
Chris@141
|
81 connect(item, SIGNAL(diff()),
|
Chris@141
|
82 this, SIGNAL(diffWorkingFolder()));
|
Chris@153
|
83
|
Chris@168
|
84 connect(item, SIGNAL(showSummary()),
|
Chris@168
|
85 this, SIGNAL(showSummary()));
|
Chris@168
|
86
|
Chris@153
|
87 connect(item, SIGNAL(showWork()),
|
Chris@153
|
88 this, SIGNAL(showWork()));
|
Chris@311
|
89
|
Chris@311
|
90 connect(item, SIGNAL(newBranch()),
|
Chris@311
|
91 this, SIGNAL(newBranch()));
|
Chris@311
|
92
|
Chris@311
|
93 connect(item, SIGNAL(noBranch()),
|
Chris@311
|
94 this, SIGNAL(noBranch()));
|
Chris@311
|
95
|
Chris@141
|
96 }
|
Chris@141
|
97
|
Chris@141
|
98 void
|
Chris@397
|
99 ChangesetScene::addDateRange(QString label, int minrow, int nrows, bool even)
|
Chris@168
|
100 {
|
Chris@397
|
101 DateRange dr;
|
Chris@397
|
102 dr.label = label;
|
Chris@397
|
103 dr.minrow = minrow;
|
Chris@397
|
104 dr.nrows = nrows;
|
Chris@397
|
105 dr.even = even;
|
Chris@397
|
106 m_dateRanges[minrow] = dr;
|
Chris@397
|
107 }
|
Chris@168
|
108
|
Chris@397
|
109 void
|
Chris@397
|
110 ChangesetScene::itemAddCompleted()
|
Chris@397
|
111 {
|
Chris@402
|
112 connect(this, SIGNAL(changed(const QList<QRectF> &)),
|
Chris@402
|
113 this, SLOT(recalculateSceneRect()));
|
Chris@402
|
114 recalculateSceneRect();
|
Chris@402
|
115 }
|
Chris@402
|
116
|
Chris@402
|
117 void
|
Chris@402
|
118 ChangesetScene::recalculateSceneRect()
|
Chris@402
|
119 {
|
Chris@402
|
120 QRectF existingSr = sceneRect();
|
Chris@402
|
121
|
Chris@397
|
122 QRectF r = itemsBoundingRect();
|
Chris@397
|
123 float minwidth = 300; //!!!
|
Chris@402
|
124 DEBUG << "ChangesetScene::recalculateSceneRect: minwidth = " << minwidth
|
Chris@397
|
125 << ", r = " << r << endl;
|
Chris@397
|
126 if (r.width() < minwidth) {
|
Chris@397
|
127 float edgediff = (minwidth - r.width()) / 2;
|
Chris@397
|
128 r.setLeft(r.left() - edgediff);
|
Chris@397
|
129 r.setRight(r.right() + edgediff);
|
Chris@397
|
130 }
|
Chris@402
|
131 DEBUG << "ChangesetScene::recalculateSceneRect: r now is " << r << endl;
|
Chris@402
|
132
|
Chris@402
|
133 setSceneRect(r.united(existingSr));
|
Chris@168
|
134 }
|
Chris@168
|
135
|
Chris@168
|
136 void
|
Chris@119
|
137 ChangesetScene::changesetDetailShown()
|
Chris@119
|
138 {
|
Chris@119
|
139 ChangesetItem *csi = qobject_cast<ChangesetItem *>(sender());
|
Chris@119
|
140 if (!csi) return;
|
Chris@119
|
141
|
Chris@124
|
142 if (m_detailShown && m_detailShown != csi) {
|
Chris@119
|
143 m_detailShown->hideDetail();
|
Chris@119
|
144 }
|
Chris@119
|
145 m_detailShown = csi;
|
Chris@119
|
146 }
|
Chris@119
|
147
|
Chris@168
|
148 void
|
Chris@168
|
149 ChangesetScene::changesetDetailHidden()
|
Chris@168
|
150 {
|
Chris@168
|
151 m_detailShown = 0;
|
Chris@401
|
152 itemAddCompleted();
|
Chris@168
|
153 }
|
Chris@168
|
154
|
Chris@168
|
155 void
|
Chris@397
|
156 ChangesetScene::drawBackground(QPainter *paint, const QRectF &rect)
|
Chris@168
|
157 {
|
Chris@397
|
158 QGraphicsScene::drawBackground(paint, rect);
|
Chris@168
|
159 }
|
Chris@397
|
160
|
Chris@168
|
161
|
Chris@281
|
162 ChangesetItem *
|
Chris@281
|
163 ChangesetScene::getItemById(QString id)
|
Chris@281
|
164 {
|
Chris@281
|
165 foreach (QGraphicsItem *it, items()) {
|
Chris@281
|
166 ChangesetItem *csit = dynamic_cast<ChangesetItem *>(it);
|
Chris@281
|
167 if (csit && csit->getId() == id) return csit;
|
Chris@281
|
168 }
|
Chris@288
|
169 return 0;
|
Chris@281
|
170 }
|
Chris@281
|
171
|
Chris@281
|
172
|