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@402
|
109 connect(this, SIGNAL(changed(const QList<QRectF> &)),
|
Chris@402
|
110 this, SLOT(recalculateSceneRect()));
|
Chris@402
|
111 recalculateSceneRect();
|
Chris@402
|
112 }
|
Chris@402
|
113
|
Chris@402
|
114 void
|
Chris@402
|
115 ChangesetScene::recalculateSceneRect()
|
Chris@402
|
116 {
|
Chris@402
|
117 QRectF existingSr = sceneRect();
|
Chris@402
|
118
|
Chris@397
|
119 QRectF r = itemsBoundingRect();
|
Chris@397
|
120 float minwidth = 300; //!!!
|
Chris@402
|
121 DEBUG << "ChangesetScene::recalculateSceneRect: minwidth = " << minwidth
|
Chris@397
|
122 << ", r = " << r << endl;
|
Chris@397
|
123 if (r.width() < minwidth) {
|
Chris@397
|
124 float edgediff = (minwidth - r.width()) / 2;
|
Chris@397
|
125 r.setLeft(r.left() - edgediff);
|
Chris@397
|
126 r.setRight(r.right() + edgediff);
|
Chris@397
|
127 }
|
Chris@402
|
128 DEBUG << "ChangesetScene::recalculateSceneRect: r now is " << r << endl;
|
Chris@402
|
129
|
Chris@402
|
130 setSceneRect(r.united(existingSr));
|
Chris@168
|
131 }
|
Chris@168
|
132
|
Chris@168
|
133 void
|
Chris@119
|
134 ChangesetScene::changesetDetailShown()
|
Chris@119
|
135 {
|
Chris@119
|
136 ChangesetItem *csi = qobject_cast<ChangesetItem *>(sender());
|
Chris@119
|
137 if (!csi) return;
|
Chris@119
|
138
|
Chris@124
|
139 if (m_detailShown && m_detailShown != csi) {
|
Chris@119
|
140 m_detailShown->hideDetail();
|
Chris@119
|
141 }
|
Chris@119
|
142 m_detailShown = csi;
|
Chris@119
|
143 }
|
Chris@119
|
144
|
Chris@168
|
145 void
|
Chris@168
|
146 ChangesetScene::changesetDetailHidden()
|
Chris@168
|
147 {
|
Chris@168
|
148 m_detailShown = 0;
|
Chris@401
|
149 itemAddCompleted();
|
Chris@168
|
150 }
|
Chris@168
|
151
|
Chris@168
|
152 void
|
Chris@397
|
153 ChangesetScene::drawBackground(QPainter *paint, const QRectF &rect)
|
Chris@168
|
154 {
|
Chris@397
|
155 QGraphicsScene::drawBackground(paint, rect);
|
Chris@168
|
156 }
|
Chris@397
|
157
|
Chris@168
|
158
|
Chris@281
|
159 ChangesetItem *
|
Chris@281
|
160 ChangesetScene::getItemById(QString id)
|
Chris@281
|
161 {
|
Chris@281
|
162 foreach (QGraphicsItem *it, items()) {
|
Chris@281
|
163 ChangesetItem *csit = dynamic_cast<ChangesetItem *>(it);
|
Chris@281
|
164 if (csit && csit->getId() == id) return csit;
|
Chris@281
|
165 }
|
Chris@288
|
166 return 0;
|
Chris@281
|
167 }
|
Chris@281
|
168
|
Chris@281
|
169
|