Mercurial > hg > easyhg
comparison src/uncommitteditem.cpp @ 400:07eaf4e6003a
Merge from branch "item_appearance_adjustments"
author | Chris Cannam |
---|---|
date | Wed, 25 May 2011 14:59:09 +0100 |
parents | b1f0fa991c49 |
children | 533519ebc0cb |
comparison
equal
deleted
inserted
replaced
385:5cc0d897eb26 | 400:07eaf4e6003a |
---|---|
27 #include <QAction> | 27 #include <QAction> |
28 #include <QLabel> | 28 #include <QLabel> |
29 #include <QWidgetAction> | 29 #include <QWidgetAction> |
30 | 30 |
31 UncommittedItem::UncommittedItem() : | 31 UncommittedItem::UncommittedItem() : |
32 m_showBranch(false), m_isNewBranch(false), | 32 m_showBranch(false), m_isNewBranch(false), m_isMerge(false), |
33 m_column(0), m_row(0), m_wide(false) | 33 m_column(0), m_row(0), m_wide(false) |
34 { | 34 { |
35 m_font = QFont(); | 35 m_font = QFont(); |
36 m_font.setPixelSize(11); | 36 m_font.setPixelSize(11); |
37 m_font.setBold(false); | 37 m_font.setBold(false); |
68 | 68 |
69 void | 69 void |
70 UncommittedItem::activateMenu() | 70 UncommittedItem::activateMenu() |
71 { | 71 { |
72 QMenu *menu = new QMenu; | 72 QMenu *menu = new QMenu; |
73 QLabel *label = new QLabel(tr("<qt><b> Uncommitted changes</b></qt>")); | 73 QLabel *label = new QLabel |
74 (m_isMerge ? | |
75 tr("<qt><b> Uncommitted merge</b></qt>") : | |
76 tr("<qt><b> Uncommitted changes</b></qt>")); | |
74 QWidgetAction *wa = new QWidgetAction(menu); | 77 QWidgetAction *wa = new QWidgetAction(menu); |
75 wa->setDefaultWidget(label); | 78 wa->setDefaultWidget(label); |
76 menu->addAction(wa); | 79 menu->addAction(wa); |
77 menu->addSeparator(); | 80 menu->addSeparator(); |
78 | 81 |
100 | 103 |
101 ungrabMouse(); | 104 ungrabMouse(); |
102 } | 105 } |
103 | 106 |
104 void | 107 void |
105 UncommittedItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *option, | 108 UncommittedItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *) |
106 QWidget *w) | 109 { |
110 if (isMerge()) { | |
111 paintMerge(paint); | |
112 } else { | |
113 paintNormal(paint); | |
114 } | |
115 } | |
116 | |
117 void | |
118 UncommittedItem::paintNormal(QPainter *paint) | |
107 { | 119 { |
108 paint->save(); | 120 paint->save(); |
109 | 121 |
110 ColourSet *colourSet = ColourSet::instance(); | 122 ColourSet *colourSet = ColourSet::instance(); |
111 QColor branchColour = colourSet->getColourFor(m_branch); | 123 QColor branchColour = colourSet->getColourFor(m_branch); |
135 int x0 = -((width - 50) / 2 - 1); | 147 int x0 = -((width - 50) / 2 - 1); |
136 | 148 |
137 int height = 49; | 149 int height = 49; |
138 QRectF r(x0, 0, width - 3, height); | 150 QRectF r(x0, 0, width - 3, height); |
139 paint->setBrush(Qt::white); | 151 paint->setBrush(Qt::white); |
140 paint->drawRect(r); | 152 paint->drawRoundedRect(r, 7, 7); |
141 | 153 |
142 if (m_wide) { | 154 if (m_wide) { |
143 QString label = tr("Uncommitted changes"); | 155 QString label = tr("Uncommitted changes"); |
144 paint->drawText(-(fm.width(label) - 50)/2, | 156 paint->drawText(-(fm.width(label) - 50)/2, |
145 25 - fm.height()/2 + fm.ascent(), | 157 25 - fm.height()/2 + fm.ascent(), |
166 } | 178 } |
167 | 179 |
168 paint->restore(); | 180 paint->restore(); |
169 return; | 181 return; |
170 } | 182 } |
183 | |
184 void | |
185 UncommittedItem::paintMerge(QPainter *paint) | |
186 { | |
187 paint->save(); | |
188 | |
189 ColourSet *colourSet = ColourSet::instance(); | |
190 QColor branchColour = colourSet->getColourFor(m_branch); | |
191 | |
192 QFont f(m_font); | |
193 | |
194 QTransform t = paint->worldTransform(); | |
195 float scale = std::min(t.m11(), t.m22()); | |
196 if (scale > 1.0) { | |
197 int ps = int((f.pixelSize() / scale) + 0.5); | |
198 if (ps < 8) ps = 8; | |
199 f.setPixelSize(ps); | |
200 } | |
201 | |
202 if (scale < 0.1) { | |
203 paint->setPen(QPen(branchColour, 0, Qt::DashLine)); | |
204 } else { | |
205 paint->setPen(QPen(branchColour, 2, Qt::DashLine)); | |
206 } | |
207 | |
208 paint->setFont(f); | |
209 QFontMetrics fm(f); | |
210 int fh = fm.height(); | |
211 | |
212 int size = fh * 2; | |
213 int x0 = -size/2 + 25; | |
214 | |
215 paint->setBrush(Qt::white); | |
216 paint->drawEllipse(QRectF(x0, fh, size, size)); | |
217 | |
218 if (m_wide) { | |
219 QString label = tr("Uncommitted merge"); | |
220 paint->drawText(size/2 + 28, | |
221 25 - fm.height()/2 + fm.ascent(), | |
222 label); | |
223 } else { | |
224 QString label = tr("Uncommitted"); | |
225 paint->drawText(size/2 + 28, | |
226 25 - fm.height() + fm.ascent(), | |
227 label); | |
228 label = tr("merge"); | |
229 paint->drawText(size/2 + 28, | |
230 25 + fm.ascent(), | |
231 label); | |
232 } | |
233 | |
234 if (m_showBranch && m_branch != "") { | |
235 // write branch name | |
236 f.setBold(true); | |
237 paint->setFont(f); | |
238 int wid = size * 3; | |
239 QString branch = TextAbbrev::abbreviate(m_branch, QFontMetrics(f), wid); | |
240 paint->drawText(-wid/2 + 25, fm.ascent() - 4, branch); | |
241 } | |
242 | |
243 paint->restore(); | |
244 return; | |
245 } |