comparison src/changesetscene.cpp @ 397:61bde1f0ff0a item_appearance_adjustments

Replace DateItems (background items for date shading) with a date range list in the scene and dedicated rendering for it in the graphics view: this way we can ensure the shading spans the full width and the dates are always visible
author Chris Cannam
date Wed, 25 May 2011 14:32:32 +0100
parents b9c153e00e84
children c3276f8998ee
comparison
equal deleted inserted replaced
396:1e73b5911631 397:61bde1f0ff0a
16 */ 16 */
17 17
18 #include "changesetscene.h" 18 #include "changesetscene.h"
19 #include "changesetitem.h" 19 #include "changesetitem.h"
20 #include "uncommitteditem.h" 20 #include "uncommitteditem.h"
21 #include "dateitem.h" 21 #include "debug.h"
22
23 #include <QPainter>
24
22 25
23 ChangesetScene::ChangesetScene() 26 ChangesetScene::ChangesetScene()
24 : QGraphicsScene(), m_detailShown(0) 27 // Supply a non-NULL but trivial scene rect to inhibit automatic
28 // updates from QGraphicsScene, because we will set the rect
29 // explicitly in itemAddCompleted
30 : QGraphicsScene(QRectF(0, 0, 1, 1)), m_detailShown(0)
25 { 31 {
26 } 32 }
27 33
28 void 34 void
29 ChangesetScene::addChangesetItem(ChangesetItem *item) 35 ChangesetScene::addChangesetItem(ChangesetItem *item)
85 this, SIGNAL(noBranch())); 91 this, SIGNAL(noBranch()));
86 92
87 } 93 }
88 94
89 void 95 void
90 ChangesetScene::addDateItem(DateItem *item) 96 ChangesetScene::addDateRange(QString label, int minrow, int nrows, bool even)
91 { 97 {
92 addItem(item); 98 DateRange dr;
99 dr.label = label;
100 dr.minrow = minrow;
101 dr.nrows = nrows;
102 dr.even = even;
103 m_dateRanges[minrow] = dr;
104 }
93 105
94 connect(item, SIGNAL(clicked()), 106 void
95 this, SLOT(dateItemClicked())); 107 ChangesetScene::itemAddCompleted()
108 {
109 QRectF r = itemsBoundingRect();
110 float minwidth = 300; //!!!
111 DEBUG << "ChangesetScene::itemAddCompleted: minwidth = " << minwidth
112 << ", r = " << r << endl;
113 if (r.width() < minwidth) {
114 float edgediff = (minwidth - r.width()) / 2;
115 r.setLeft(r.left() - edgediff);
116 r.setRight(r.right() + edgediff);
117 }
118 DEBUG << "ChangesetScene::itemAddCompleted: r now is " << r << endl;
119 setSceneRect(r);
96 } 120 }
97 121
98 void 122 void
99 ChangesetScene::changesetDetailShown() 123 ChangesetScene::changesetDetailShown()
100 { 124 {
112 { 136 {
113 m_detailShown = 0; 137 m_detailShown = 0;
114 } 138 }
115 139
116 void 140 void
117 ChangesetScene::dateItemClicked() 141 ChangesetScene::drawBackground(QPainter *paint, const QRectF &rect)
118 { 142 {
119 if (m_detailShown) { 143 QGraphicsScene::drawBackground(paint, rect);
120 m_detailShown->hideDetail();
121 }
122 } 144 }
145
123 146
124 ChangesetItem * 147 ChangesetItem *
125 ChangesetScene::getItemById(QString id) 148 ChangesetScene::getItemById(QString id)
126 { 149 {
127 foreach (QGraphicsItem *it, items()) { 150 foreach (QGraphicsItem *it, items()) {