[qt4] move scintilla initialization into to dedicated class

related to #107995

authorAlain Leufroy <alain@leufroy.fr>
changeset821e0d38e782
branchdefault
phasepublic
hiddenno
parent revision#c29cfd3fee66 [qt4] change some toolbar names (closes #103375)
child revision#1c9d6832bd01 [qt4] rename actions container of hg-scintilla object
files modified by this revision
hgviewlib/qt4/hgfileview.py
# HG changeset patch
# User Alain Leufroy <alain@leufroy.fr>
# Date 1369822797 -7200
# Wed May 29 12:19:57 2013 +0200
# Node ID 821e0d38e7820816b55466193c4c7799eb72830d
# Parent c29cfd3fee66663f460196da541ce9711bd869ef
[qt4] move scintilla initialization into to dedicated class

related to #107995

diff --git a/hgviewlib/qt4/hgfileview.py b/hgviewlib/qt4/hgfileview.py
@@ -92,10 +92,39 @@
1 
2      def __init__(self, *args, **kwargs):
3          super(HgQsci, self).__init__(*args, **kwargs)
4          super(HgQsci, self).setUtf8(True)
5          self.createActions()
6 +        self.setFrameStyle(0)
7 +
8 +        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
9 +        self.setReadOnly(True)
10 +
11 +        self.SendScintilla(qsci.SCI_SETCARETSTYLE, 0)
12 +
13 +        # margin 1 is used for line numbers
14 +        self.setMarginLineNumbers(1, True)
15 +        self.setMarginWidth(1, '000')
16 +
17 +        self.SendScintilla(qsci.SCI_INDICSETSTYLE, 8, qsci.INDIC_ROUNDBOX)
18 +        self.SendScintilla(qsci.SCI_INDICSETUNDER, 8, True)
19 +        self.SendScintilla(qsci.SCI_INDICSETFORE, 8, 0xBBFFFF)
20 +        self.SendScintilla(qsci.SCI_INDICSETSTYLE, 9, qsci.INDIC_ROUNDBOX)
21 +        self.SendScintilla(qsci.SCI_INDICSETUNDER, 9, True)
22 +        self.SendScintilla(qsci.SCI_INDICSETFORE, 9, 0x58A8FF)
23 +
24 +        # hide margin 0 (markers)
25 +        self.SendScintilla(qsci.SCI_SETMARGINTYPEN, 0, 0)
26 +        self.SendScintilla(qsci.SCI_SETMARGINWIDTHN, 0, 0)
27 +
28 +        # define markers for colorize zones of diff
29 +        self.markerplus = self.markerDefine(qsci.Background)
30 +        self.SendScintilla(qsci.SCI_MARKERSETBACK, self.markerplus, 0xB0FFA0)
31 +        self.markerminus = self.markerDefine(qsci.Background)
32 +        self.SendScintilla(qsci.SCI_MARKERSETBACK, self.markerminus, 0xA0A0FF)
33 +        self.markertriangle = self.markerDefine(qsci.Background)
34 +        self.SendScintilla(qsci.SCI_MARKERSETBACK, self.markertriangle, 0xFFA0A0)
35 
36      def _action_defs(self):
37          return [
38              ("diffmode", self.tr("Diff mode"), 'diffmode' ,
39               self.tr('Enable/Disable Diff mode'), None, None),
@@ -169,39 +198,11 @@
40          self.execflaglabel.hide()
41          framelayout.addLayout(self.topLayout)
42          framelayout.addLayout(l, 1)
43 
44          self.sci = HgQsci(self)
45 -        self.sci.setFrameStyle(0)
46          l.addWidget(self.sci, 1)
47 -        self.sci.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
48 -        self.sci.setReadOnly(True)
49 -
50 -        self.sci.SendScintilla(qsci.SCI_SETCARETSTYLE, 0)
51 -
52 -        # margin 1 is used for line numbers
53 -        self.sci.setMarginLineNumbers(1, True)
54 -        self.sci.setMarginWidth(1, '000')
55 -
56 -        self.sci.SendScintilla(qsci.SCI_INDICSETSTYLE, 8, qsci.INDIC_ROUNDBOX)
57 -        self.sci.SendScintilla(qsci.SCI_INDICSETUNDER, 8, True)
58 -        self.sci.SendScintilla(qsci.SCI_INDICSETFORE, 8, 0xBBFFFF)
59 -        self.sci.SendScintilla(qsci.SCI_INDICSETSTYLE, 9, qsci.INDIC_ROUNDBOX)
60 -        self.sci.SendScintilla(qsci.SCI_INDICSETUNDER, 9, True)
61 -        self.sci.SendScintilla(qsci.SCI_INDICSETFORE, 9, 0x58A8FF)
62 -
63 -        # hide margin 0 (markers)
64 -        self.sci.SendScintilla(qsci.SCI_SETMARGINTYPEN, 0, 0)
65 -        self.sci.SendScintilla(qsci.SCI_SETMARGINWIDTHN, 0, 0)
66 -
67 -        # define markers for colorize zones of diff
68 -        self.markerplus = self.sci.markerDefine(qsci.Background)
69 -        self.sci.SendScintilla(qsci.SCI_MARKERSETBACK, self.markerplus, 0xB0FFA0)
70 -        self.markerminus = self.sci.markerDefine(qsci.Background)
71 -        self.sci.SendScintilla(qsci.SCI_MARKERSETBACK, self.markerminus, 0xA0A0FF)
72 -        self.markertriangle = self.sci.markerDefine(qsci.Background)
73 -        self.sci.SendScintilla(qsci.SCI_MARKERSETBACK, self.markertriangle, 0xFFA0A0)
74 
75          ll = QtGui.QVBoxLayout()
76          ll.setContentsMargins(0, 0, 0, 0)
77          ll.setSpacing(0)
78          l.insertLayout(0, ll)
@@ -541,25 +542,25 @@
79              tag, alo, ahi, blo, bhi = self._diff.get_opcodes().pop(0)
80              if tag == 'replace':
81                  self._diffs.append([blo, bhi])
82                  self.blk.addBlock('x', blo, bhi)
83                  for i in range(blo, bhi):
84 -                    self.sci.markerAdd(i, self.markertriangle)
85 +                    self.sci.markerAdd(i, self.sci.markertriangle)
86 
87              elif tag == 'delete':
88                  pass
89                  # self.block['left'].addBlock('-', alo, ahi)
90                  # self.diffblock.addBlock('-', alo, ahi, blo, bhi)
91                  # w = self.viewers['left']
92                  # for i in range(alo, ahi):
93 -                #     w.markerAdd(i, self.markerminus)
94 +                #     w.markerAdd(i, self.sci.markerminus)
95 
96              elif tag == 'insert':
97                  self._diffs.append([blo, bhi])
98                  self.blk.addBlock('+', blo, bhi)
99                  for i in range(blo, bhi):
100 -                    self.sci.markerAdd(i, self.markerplus)
101 +                    self.sci.markerAdd(i, self.sci.markerplus)
102 
103              elif tag == 'equal':
104                  pass
105 
106              else: