Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py

changeset 241
aaa856499ed5
parent 236
d03ae0227f1c
child 243
a1d982e68edf
equal deleted inserted replaced
240:b0d829cf4234 241:aaa856499ed5
112 self.__rowHeight = 20 112 self.__rowHeight = 20
113 113
114 self.__branchColors = {} 114 self.__branchColors = {}
115 115
116 self.logTree.setIconSize(QSize(100 * self.__rowHeight, self.__rowHeight)) 116 self.logTree.setIconSize(QSize(100 * self.__rowHeight, self.__rowHeight))
117
118 self.__projectRevision = -1
117 119
118 def closeEvent(self, e): 120 def closeEvent(self, e):
119 """ 121 """
120 Private slot implementing a close event handler. 122 Private slot implementing a close event handler.
121 123
217 edges.append((ecol, next.index(p), self.__revColors[p])) 219 edges.append((ecol, next.index(p), self.__revColors[p]))
218 220
219 self.__revs = next 221 self.__revs = next
220 return col, color, edges 222 return col, color, edges
221 223
222 def __generateIcon(self, column, color, bottomedges, topedges, dotColor): 224 def __generateIcon(self, column, color, bottomedges, topedges, dotColor, currentRev):
223 """ 225 """
224 Private method to generate an icon containing the revision tree for the 226 Private method to generate an icon containing the revision tree for the
225 given data. 227 given data.
226 228
227 @param column column index of the revision (integer) 229 @param column column index of the revision (integer)
229 @param bottomedges list of edges for the bottom of the node 231 @param bottomedges list of edges for the bottom of the node
230 (list of tuples of three integers) 232 (list of tuples of three integers)
231 @param topedges list of edges for the top of the node 233 @param topedges list of edges for the top of the node
232 (list of tuples of three integers) 234 (list of tuples of three integers)
233 @param dotColor color to be used for the dot (QColor) 235 @param dotColor color to be used for the dot (QColor)
236 @param currentRev flag indicating to draw the icon for the
237 current revision (boolean)
234 @return icon for the node (QIcon) 238 @return icon for the node (QIcon)
235 """ 239 """
236 def col2x(col, radius): 240 def col2x(col, radius):
237 return int(1.2 * radius) * col + radius // 2 + 3 241 return int(1.2 * radius) * col + radius // 2 + 3
238 242
239 radius = self.__dotRadius 243 radius = self.__dotRadius
240 w = len(bottomedges) * radius + 20 244 w = len(bottomedges) * radius + 20
241 h = self.__rowHeight 245 h = self.__rowHeight
242 246
243 dot_x = col2x(column, radius) - radius // 2 247 dot_x = col2x(column, radius) - radius // 2
244 dot_y = h // 2 248 dot_y = h // 2
245 249
246 pix = QPixmap(w, h) 250 pix = QPixmap(w, h)
247 pix.fill(QColor(0, 0, 0, 0)) 251 pix.fill(QColor(0, 0, 0, 0))
248 painter = QPainter(pix) 252 painter = QPainter(pix)
249 painter.setRenderHint(QPainter.Antialiasing) 253 painter.setRenderHint(QPainter.Antialiasing)
250 254
251 pen = QPen(Qt.blue) 255 pen = QPen(Qt.blue)
252 pen.setWidth(2) 256 pen.setWidth(2)
253 painter.setPen(pen) 257 painter.setPen(pen)
254 258
255 lpen = QPen(pen) 259 lpen = QPen(pen)
256 lpen.setColor(Qt.black) 260 lpen.setColor(Qt.black)
257 painter.setPen(lpen) 261 painter.setPen(lpen)
258 262
263 # draw the revision history lines
259 for y1, y2, lines in ((0, h, bottomedges), 264 for y1, y2, lines in ((0, h, bottomedges),
260 (-h, 0, topedges)): 265 (-h, 0, topedges)):
261 if lines: 266 if lines:
262 for start, end, ecolor in lines: 267 for start, end, ecolor in lines:
263 lpen = QPen(pen) 268 lpen = QPen(pen)
265 lpen.setWidth(2) 270 lpen.setWidth(2)
266 painter.setPen(lpen) 271 painter.setPen(lpen)
267 x1 = col2x(start, radius) 272 x1 = col2x(start, radius)
268 x2 = col2x(end, radius) 273 x2 = col2x(end, radius)
269 painter.drawLine(x1, dot_y + y1, x2, dot_y + y2) 274 painter.drawLine(x1, dot_y + y1, x2, dot_y + y2)
270 275
271 penradius = 1 276 penradius = 1
272 pencolor = Qt.black 277 pencolor = Qt.black
273 278
274 dot_y = (h // 2) - radius // 2 279 dot_y = (h // 2) - radius // 2
275 280
281 # draw a dot for the revision
282 if currentRev:
283 # enlarge dot for the current revision
284 delta = 2
285 radius += 2 * delta
286 dot_y -= delta
287 dot_x -= delta
276 painter.setBrush(dotColor) 288 painter.setBrush(dotColor)
277 pen = QPen(pencolor) 289 pen = QPen(pencolor)
278 pen.setWidth(penradius) 290 pen.setWidth(penradius)
279 painter.setPen(pen) 291 painter.setPen(pen)
280 painter.drawEllipse(dot_x, dot_y, radius, radius) 292 painter.drawEllipse(dot_x, dot_y, radius, radius)
330 self.trUtf8("Mercurial Error"), 342 self.trUtf8("Mercurial Error"),
331 errMsg) 343 errMsg)
332 344
333 return parents 345 return parents
334 346
347 def __identifyProject(self):
348 """
349 Private method to determine the revision of the project directory.
350 """
351 errMsg = ""
352
353 process = QProcess()
354 args = []
355 args.append("identify")
356 args.append("-n")
357
358 process.setWorkingDirectory(self.repodir)
359 process.start('hg', args)
360 procStarted = process.waitForStarted()
361 if procStarted:
362 finished = process.waitForFinished(30000)
363 if finished and process.exitCode() == 0:
364 output = \
365 str(process.readAllStandardOutput(),
366 Preferences.getSystem("IOEncoding"),
367 'replace')
368 self.__projectRevision = output.strip()
369 else:
370 if not finished:
371 errMsg = self.trUtf8("The hg process did not finish within 30s.")
372 else:
373 errMsg = self.trUtf8("Could not start the hg executable.")
374
375 if errMsg:
376 QMessageBox.critical(self,
377 self.trUtf8("Mercurial Error"),
378 errMsg)
379
335 def __generateLogItem(self, author, date, message, revision, changedPaths, parents, 380 def __generateLogItem(self, author, date, message, revision, changedPaths, parents,
336 branches, tags): 381 branches, tags):
337 """ 382 """
338 Private method to generate a log tree entry. 383 Private method to generate a log tree entry.
339 384
386 .data(0, self.__edgesRole) 431 .data(0, self.__edgesRole)
387 else: 432 else:
388 topedges = None 433 topedges = None
389 434
390 icon = self.__generateIcon(column, color, edges, topedges, 435 icon = self.__generateIcon(column, color, edges, topedges,
391 QColor(self.__branchColor(branches[0]))) 436 QColor(self.__branchColor(branches[0])),
437 rev == self.__projectRevision)
392 itm.setIcon(0, icon) 438 itm.setIcon(0, icon)
393 439
394 try: 440 try:
395 self.__lastRev = int(revision.split(":")[0]) 441 self.__lastRev = int(revision.split(":")[0])
396 except ValueError: 442 except ValueError:
542 588
543 def __processBuffer(self): 589 def __processBuffer(self):
544 """ 590 """
545 Private method to process the buffered output of the hg log command. 591 Private method to process the buffered output of the hg log command.
546 """ 592 """
593 self.__identifyProject()
594
547 noEntries = 0 595 noEntries = 0
548 log = {"message" : []} 596 log = {"message" : []}
549 changedPaths = [] 597 changedPaths = []
550 initialText = True 598 initialText = True
551 fileCopies = {} 599 fileCopies = {}

eric ide

mercurial