Mon, 12 Oct 2020 18:23:44 +0200
Performed some code cleanup.
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
7360
9190402e4505
Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7252
diff
changeset
|
3 | # Copyright (c) 2014 - 2020 Detlev Offenbach <detlev@die-offenbachs.de> |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing a base class for showing a document map. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
5736
000ea446ff4b
Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
10 | from PyQt5.QtCore import Qt, QSize, QRect, QCoreApplication |
3656
441956d8fce5
Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3591
diff
changeset
|
11 | from PyQt5.QtGui import QColor, QBrush, QPainter |
441956d8fce5
Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3591
diff
changeset
|
12 | from PyQt5.QtWidgets import QWidget, QAbstractScrollArea |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | class E5MapWidget(QWidget): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | Class implementing a base class for showing a document map. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | def __init__(self, parent=None): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | Constructor |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | @param parent reference to the parent widget (QWidget) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | """ |
3484
645c12de6b0c
Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3339
diff
changeset
|
25 | super(E5MapWidget, self).__init__(parent) |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | self.setAttribute(Qt.WA_OpaquePaintEvent) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
28 | self.__width = 14 |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
29 | self.__lineBorder = 1 |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | self.__lineHeight = 2 |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
31 | self.__backgroundColor = QColor("#e7e7e7") |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
32 | self.__setSliderColor() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
34 | self._master = None |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | self.__enabled = False |
6278
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
36 | self.__rightSide = True |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | if parent is not None and isinstance(parent, QAbstractScrollArea): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | self.setMaster(parent) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
41 | def __setSliderColor(self): |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
42 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3484
diff
changeset
|
43 | Private method to set the slider color depending upon the background |
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3484
diff
changeset
|
44 | color. |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
45 | """ |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
46 | if self.__backgroundColor.toHsv().value() < 128: |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
47 | # dark background, use white slider |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
48 | self.__sliderColor = Qt.white |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
49 | else: |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
50 | # light background, use black slider |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
51 | self.__sliderColor = Qt.black |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
52 | |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | def __updateMasterViewportWidth(self): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | Private method to update the master's viewport width. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
57 | if self._master: |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | if self.__enabled: |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | width = self.__width |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | else: |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | width = 0 |
6278
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
62 | if self.__rightSide: |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
63 | self._master.setViewportMargins(0, 0, width, 0) |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
64 | else: |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
65 | self._master.setViewportMargins(width, 0, 0, 0) |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | def setMaster(self, master): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | Public method to set the map master widget. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | @param master map master widget (QAbstractScrollArea) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
72 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
73 | self._master = master |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
74 | self._master.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) |
6308
f49ce4c244b1
E5MapWidget: fixed an issue that causes a crash when eric is used with Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6279
diff
changeset
|
75 | self._master.verticalScrollBar().valueChanged.connect(self.update) |
f49ce4c244b1
E5MapWidget: fixed an issue that causes a crash when eric is used with Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6279
diff
changeset
|
76 | self._master.verticalScrollBar().rangeChanged.connect(self.update) |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | self.__updateMasterViewportWidth() |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | def setWidth(self, width): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | Public method to set the widget width. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | @param width widget width (integer) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
85 | if width != self.__width: |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
86 | self.__width = max(6, width) # minimum width 6 pixels |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
87 | self.__updateMasterViewportWidth() |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
88 | self.update() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | def width(self): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | Public method to get the widget's width. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | @return widget width (integer) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | return self.__width |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | |
6278
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
98 | def setMapPosition(self, onRight): |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
99 | """ |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
100 | Public method to set, whether the map should be shown to the right or |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
101 | left of the master widget. |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
102 | |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
103 | @param onRight flag indicating to show the map on the right side of |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
104 | the master widget |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
105 | @type bool |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
106 | """ |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
107 | if onRight != self.__rightSide: |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
108 | self.__rightSide = onRight |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
109 | self.__updateMasterViewportWidth() |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
110 | self.update() |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
111 | |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
112 | def isOnRightSide(self): |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
113 | """ |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
114 | Public method to test, if the map is shown on the right side of the |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
115 | master widget. |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
116 | |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
117 | @return flag indicating that the map is to the right of the master |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
118 | widget |
6279
7c44be92f8a4
E5MapWidget: fixed a source docu issue
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6278
diff
changeset
|
119 | @rtype bool |
6278
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
120 | """ |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
121 | return self.__rightSide |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
122 | |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | def setLineDimensions(self, border, height): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | Public method to set the line (indicator) dimensions. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | @param border border width on each side in x-direction (integer) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | @param height height of the line in pixels (integer) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
130 | if border != self.__lineBorder or height != self.__lineHeight: |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
131 | self.__lineBorder = max(1, border) # min border 1 pixel |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
132 | self.__lineHeight = max(1, height) # min height 1 pixel |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
133 | self.update() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | def lineDimensions(self): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | Public method to get the line (indicator) dimensions. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | @return tuple with border width (integer) and line height (integer) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
141 | return self.__lineBorder, self.__lineHeight |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | def setEnabled(self, enable): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
144 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
145 | Public method to set the enabled state. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
146 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
147 | @param enable flag indicating the enabled state (boolean) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
149 | if enable != self.__enabled: |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
150 | self.__enabled = enable |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
151 | self.setVisible(enable) |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
152 | self.__updateMasterViewportWidth() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
153 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
154 | def isEnabled(self): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
155 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
156 | Public method to check the enabled state. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | @return flag indicating the enabled state (boolean) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
160 | return self.__enabled |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
162 | def setBackgroundColor(self, color): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
163 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
164 | Public method to set the widget background color. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
165 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
166 | @param color color for the background (QColor) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
167 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
168 | if color != self.__backgroundColor: |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
169 | self.__backgroundColor = color |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
170 | self.__setSliderColor() |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
171 | self.update() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
172 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
173 | def backgroundColor(self): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
174 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
175 | Public method to get the background color. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
177 | @return background color (QColor) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
178 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | return QColor(self.__backgroundColor) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
180 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
181 | def sizeHint(self): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
182 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
183 | Public method to give an indication about the preferred size. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
184 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
185 | @return preferred size (QSize) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
186 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
187 | return QSize(self.__width, 0) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
188 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
189 | def paintEvent(self, event): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
190 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
191 | Protected method to handle a paint event. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
192 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
193 | @param event paint event (QPaintEvent) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
194 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
195 | # step 1: fill the whole painting area |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
196 | painter = QPainter(self) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
197 | painter.fillRect(event.rect(), self.__backgroundColor) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
198 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
199 | # step 2: paint the indicators |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
200 | self._paintIt(painter) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
201 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
202 | # step 3: paint the slider |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
203 | if self._master: |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
204 | penColor = self.__sliderColor |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
205 | painter.setPen(penColor) |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
206 | brushColor = Qt.transparent |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
207 | painter.setBrush(QBrush(brushColor)) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
208 | painter.drawRect(self.__generateSliderRange( |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
209 | self._master.verticalScrollBar())) |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
210 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
211 | def _paintIt(self, painter): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
212 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
213 | Protected method for painting the widget's indicators. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
215 | Note: This method should be implemented by subclasses. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
216 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
217 | @param painter reference to the painter object (QPainter) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
218 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
219 | pass |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
220 | |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
221 | def mousePressEvent(self, event): |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
222 | """ |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
223 | Protected method to handle a mouse button press. |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
224 | |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
225 | @param event reference to the mouse event (QMouseEvent) |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
226 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
227 | if event.button() == Qt.LeftButton and self._master: |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
228 | vsb = self._master.verticalScrollBar() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
229 | value = self.position2Value(event.pos().y() - 1) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
230 | vsb.setValue(value - 0.5 * vsb.pageStep()) # center on page |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
231 | self.__mousePressPos = None |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
232 | |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
233 | def mouseMoveEvent(self, event): |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
234 | """ |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
235 | Protected method to handle a mouse moves. |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
236 | |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
237 | @param event reference to the mouse event (QMouseEvent) |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
238 | """ |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
239 | if event.buttons() & Qt.LeftButton and self._master: |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
240 | vsb = self._master.verticalScrollBar() |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
241 | value = self.position2Value(event.pos().y() - 1) |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
242 | vsb.setValue(value - 0.5 * vsb.pageStep()) # center on page |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
243 | |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
244 | def wheelEvent(self, event): |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
245 | """ |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
246 | Protected slot handling mouse wheel events. |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
247 | |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
248 | @param event reference to the wheel event (QWheelEvent) |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
249 | """ |
7198
684261ef2165
Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6942
diff
changeset
|
250 | isVertical = event.angleDelta().x() == 0 |
7252
c5e3705073eb
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
251 | if ( |
c5e3705073eb
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
252 | self._master and |
c5e3705073eb
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
253 | event.modifiers() == Qt.NoModifier and |
c5e3705073eb
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
254 | isVertical |
c5e3705073eb
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
255 | ): |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
256 | QCoreApplication.sendEvent(self._master.verticalScrollBar(), event) |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
257 | |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
258 | def calculateGeometry(self): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
259 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | Public method to recalculate the map widget's geometry. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
262 | if self._master: |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
263 | cr = self._master.contentsRect() |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
264 | vsb = self._master.verticalScrollBar() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | if vsb.isVisible(): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
266 | vsbw = vsb.contentsRect().width() |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
267 | else: |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
268 | vsbw = 0 |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
269 | left, top, right, bottom = self._master.getContentsMargins() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
270 | if right > vsbw: |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
271 | vsbw = 0 |
6278
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
272 | if self.__rightSide: |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
273 | self.setGeometry( |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
274 | QRect(cr.right() - self.__width - vsbw, cr.top(), |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
275 | self.__width, cr.height())) |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
276 | else: |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
277 | self.setGeometry( |
13fd8759f981
Editor, E5MapWidget: added a configuration option (Editor->Style page) to show the marker map on the left or right of the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
6048
diff
changeset
|
278 | QRect(0, cr.top(), self.__width, cr.height())) |
4371
e09838aa0a9f
Fixed an issue in the marker map causing its contents to disappear on Mac OS X when the scrollbar got hidden.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4021
diff
changeset
|
279 | self.update() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
280 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
281 | def scaleFactor(self, slider=False): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
282 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
283 | Public method to determine the scrollbar's scale factor. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
284 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
285 | @param slider flag indicating to calculate the result for the slider |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
286 | (boolean) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
287 | @return scale factor (float) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
288 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
289 | if self._master: |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
290 | delta = 0 if slider else 2 |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
291 | vsb = self._master.verticalScrollBar() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
292 | posHeight = vsb.height() - delta - 1 |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
293 | valHeight = vsb.maximum() - vsb.minimum() + vsb.pageStep() |
3484
645c12de6b0c
Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3339
diff
changeset
|
294 | return float(posHeight) / valHeight |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
295 | else: |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
296 | return 1.0 |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
297 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
298 | def value2Position(self, value, slider=False): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
299 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
300 | Public method to convert a scrollbar value into a position. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
301 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
302 | @param value value to convert (integer) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
303 | @param slider flag indicating to calculate the result for the slider |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
304 | (boolean) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
305 | @return position (integer) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
306 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
307 | if self._master: |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
308 | offset = 0 if slider else 1 |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
309 | vsb = self._master.verticalScrollBar() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
310 | return (value - vsb.minimum()) * self.scaleFactor(slider) + offset |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
311 | else: |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
312 | return value |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
313 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
314 | def position2Value(self, position, slider=False): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
315 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
316 | Public method to convert a position into a scrollbar value. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
317 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
318 | @param position scrollbar position to convert (integer) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
319 | @param slider flag indicating to calculate the result for the slider |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
320 | (boolean) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
321 | @return scrollbar value (integer) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
322 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
323 | if self._master: |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
324 | offset = 0 if slider else 1 |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
325 | vsb = self._master.verticalScrollBar() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
326 | return vsb.minimum() + max( |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
327 | 0, (position - offset) / self.scaleFactor(slider)) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
328 | else: |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
329 | return position |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
330 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
331 | def generateIndicatorRect(self, position): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
332 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
333 | Public method to generate an indicator rectangle. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
334 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
335 | @param position indicator position (integer) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
336 | @return indicator rectangle (QRect) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
337 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
338 | return QRect(self.__lineBorder, position - self.__lineHeight // 2, |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
339 | self.__width - self.__lineBorder, self.__lineHeight) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
340 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
341 | def __generateSliderRange(self, scrollbar): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
342 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
343 | Private method to generate the slider rectangle. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
344 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
345 | @param scrollbar reference to the vertical scrollbar (QScrollBar) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
346 | @return slider rectangle (QRect) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
347 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
348 | pos1 = self.value2Position(scrollbar.value(), slider=True) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
349 | pos2 = self.value2Position(scrollbar.value() + scrollbar.pageStep(), |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
350 | slider=True) |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
351 | return QRect(0, pos1, self.__width - 1, pos2 - pos1) |