eric6/Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py

changeset 7455
9d0852f0bb2c
parent 7454
a4392387052c
child 7489
6543bcd150fd
equal deleted inserted replaced
7454:a4392387052c 7455:9d0852f0bb2c
11 import re 11 import re
12 import collections 12 import collections
13 13
14 from PyQt5.QtCore import pyqtSlot, Qt, QDate, QRegExp, QSize, QPoint, QFileInfo 14 from PyQt5.QtCore import pyqtSlot, Qt, QDate, QRegExp, QSize, QPoint, QFileInfo
15 from PyQt5.QtGui import ( 15 from PyQt5.QtGui import (
16 QCursor, QColor, QPixmap, QPainter, QPen, QBrush, QIcon, QTextCursor 16 QCursor, QColor, QPixmap, QPainter, QPen, QBrush, QIcon, QTextCursor,
17 QPalette
17 ) 18 )
18 from PyQt5.QtWidgets import ( 19 from PyQt5.QtWidgets import (
19 QWidget, QDialogButtonBox, QHeaderView, QTreeWidgetItem, QApplication, 20 QWidget, QDialogButtonBox, QHeaderView, QTreeWidgetItem, QApplication,
20 QLineEdit, QMenu, QInputDialog 21 QLineEdit, QMenu, QInputDialog
21 ) 22 )
34 35
35 COLORNAMES = ["blue", "darkgreen", "red", "green", "darkblue", "purple", 36 COLORNAMES = ["blue", "darkgreen", "red", "green", "darkblue", "purple",
36 "cyan", "olive", "magenta", "darkred", "darkmagenta", 37 "cyan", "olive", "magenta", "darkred", "darkmagenta",
37 "darkcyan", "gray", "yellow"] 38 "darkcyan", "gray", "yellow"]
38 COLORS = [str(QColor(x).name()) for x in COLORNAMES] 39 COLORS = [str(QColor(x).name()) for x in COLORNAMES]
39 # TODO: make colors configurable 40
41 LIGHTCOLORS = ["#aaaaff", "#7faa7f", "#ffaaaa", "#aaffaa", "#7f7faa",
42 "#ffaaff", "#aaffff", "#d5d579", "#ffaaff", "#d57979",
43 "#d579d5", "#79d5d5", "#d5d5d5", "#d5d500",
44 ]
40 45
41 46
42 class HgLogBrowserDialog(QWidget, Ui_HgLogBrowserDialog): 47 class HgLogBrowserDialog(QWidget, Ui_HgLogBrowserDialog):
43 """ 48 """
44 Class implementing a dialog to browse the log history. 49 Class implementing a dialog to browse the log history.
220 225
221 self.__logTreeNormalFont = self.logTree.font() 226 self.__logTreeNormalFont = self.logTree.font()
222 self.__logTreeNormalFont.setBold(False) 227 self.__logTreeNormalFont.setBold(False)
223 self.__logTreeBoldFont = self.logTree.font() 228 self.__logTreeBoldFont = self.logTree.font()
224 self.__logTreeBoldFont.setBold(True) 229 self.__logTreeBoldFont.setBold(True)
230 self.__logTreeHasDarkBackground = (
231 self.logTree.palette().color(QPalette.Window).lightness() < 128
232 )
225 233
226 self.detailsEdit.anchorClicked.connect(self.__revisionClicked) 234 self.detailsEdit.anchorClicked.connect(self.__revisionClicked)
227 235
228 self.__initActionsMenu() 236 self.__initActionsMenu()
229 237
520 528
521 def __getColor(self, n): 529 def __getColor(self, n):
522 """ 530 """
523 Private method to get the (rotating) name of the color given an index. 531 Private method to get the (rotating) name of the color given an index.
524 532
525 @param n color index (integer) 533 @param n color index
526 @return color name (string) 534 @type int
527 """ 535 @return color name
528 return COLORS[n % len(COLORS)] 536 @type str
537 """
538 if self.__logTreeHasDarkBackground:
539 return LIGHTCOLORS[n % len(LIGHTCOLORS)]
540 else:
541 return COLORS[n % len(COLORS)]
529 542
530 def __branchColor(self, branchName): 543 def __branchColor(self, branchName):
531 """ 544 """
532 Private method to calculate a color for a given branch name. 545 Private method to calculate a color for a given branch name.
533 546
621 @param col column number (integer) 634 @param col column number (integer)
622 @param radius radius of the indicator circle (integer) 635 @param radius radius of the indicator circle (integer)
623 """ 636 """
624 return int(1.2 * radius) * col + radius // 2 + 3 637 return int(1.2 * radius) * col + radius // 2 + 3
625 638
639 textColor = self.logTree.palette().color(QPalette.Text)
640
626 radius = self.__dotRadius 641 radius = self.__dotRadius
627 w = len(bottomedges) * radius + 20 642 w = len(bottomedges) * radius + 20
628 h = self.__rowHeight 643 h = self.__rowHeight
629 644
630 dot_x = col2x(column, radius) - radius // 2 645 dot_x = col2x(column, radius) - radius // 2
631 dot_y = h // 2 646 dot_y = h // 2
632 647
633 pix = QPixmap(w, h) 648 pix = QPixmap(w, h)
634 pix.fill(QColor(0, 0, 0, 0)) 649 pix.fill(QColor(0, 0, 0, 0)) # draw transparent background
635 painter = QPainter(pix) 650 painter = QPainter(pix)
636 painter.setRenderHint(QPainter.Antialiasing) 651 painter.setRenderHint(QPainter.Antialiasing)
637
638 pen = QPen(Qt.blue)
639 pen.setWidth(2)
640 painter.setPen(pen)
641
642 lpen = QPen(pen)
643 lpen.setColor(Qt.black)
644 painter.setPen(lpen)
645 652
646 # draw the revision history lines 653 # draw the revision history lines
647 for y1, y2, lines in ((0, h, bottomedges), 654 for y1, y2, lines in ((0, h, bottomedges),
648 (-h, 0, topedges)): 655 (-h, 0, topedges)):
649 if lines: 656 if lines:
650 for start, end, ecolor in lines: 657 for start, end, ecolor in lines:
651 lpen = QPen(pen) 658 lpen = QPen(QColor(self.__getColor(ecolor)))
652 lpen.setColor(QColor(self.__getColor(ecolor)))
653 lpen.setWidth(2) 659 lpen.setWidth(2)
654 painter.setPen(lpen) 660 painter.setPen(lpen)
655 x1 = col2x(start, radius) 661 x1 = col2x(start, radius)
656 x2 = col2x(end, radius) 662 x2 = col2x(end, radius)
657 painter.drawLine(x1, dot_y + y1, x2, dot_y + y2) 663 painter.drawLine(x1, dot_y + y1, x2, dot_y + y2)
658 664
659 penradius = 1 665 penradius = 1
660 pencolor = Qt.black 666 pencolor = textColor
661 667
662 dot_y = (h // 2) - radius // 2 668 dot_y = (h // 2) - radius // 2
663 669
664 # draw a dot for the revision 670 # draw an indicator for the revision
665 if currentRev: 671 if currentRev:
666 # enlarge dot for the current revision 672 # enlarge for the current revision
667 delta = 1 673 delta = 1
668 radius += 2 * delta 674 radius += 2 * delta
669 dot_y -= delta 675 dot_y -= delta
670 dot_x -= delta 676 dot_x -= delta
671 penradius = 3 677 penradius = 3

eric ide

mercurial