E5Gui/E5MapWidget.py

Tue, 29 May 2018 09:41:52 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 29 May 2018 09:41:52 +0200
changeset 6308
f49ce4c244b1
parent 6279
7c44be92f8a4
child 6645
ad476851d7e0
permissions
-rw-r--r--

E5MapWidget: fixed an issue that causes a crash when eric is used with Python2.

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
6048
82ad8ec9548c Updated copyright for 2018.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6031
diff changeset
3 # Copyright (c) 2014 - 2018 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
3484
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3339
diff changeset
10 from __future__ import unicode_literals
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3339
diff changeset
11
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
12 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
13 from PyQt5.QtGui import QColor, QBrush, QPainter
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
14 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
15
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
16 from Globals import qVersionTuple
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
17
3327
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 class E5MapWidget(QWidget):
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 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
22 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 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
24 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 Constructor
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @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
28 """
3484
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3339
diff changeset
29 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
30 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
31
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
32 self.__width = 14
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
33 self.__lineBorder = 1
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 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
35 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
36 self.__setSliderColor()
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
38 self._master = None
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 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
40 self.__rightSide = True
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 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
43 self.setMaster(parent)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
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 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
46 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
47 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
48 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
49 """
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 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
51 # 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
52 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
53 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
54 # 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
55 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
56
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 def __updateMasterViewportWidth(self):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 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
60 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
61 if self._master:
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 if self.__enabled:
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 width = self.__width
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 else:
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 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
66 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
67 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
68 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
69 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
70
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 def setMaster(self, master):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 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
74
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 @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
76 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
77 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
78 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
79 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
80 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
81 self.__updateMasterViewportWidth()
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 def setWidth(self, width):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 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
86
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 @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
88 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
89 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
90 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
91 self.__updateMasterViewportWidth()
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
92 self.update()
3327
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 def width(self):
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 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
97
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 @return widget width (integer)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 return self.__width
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
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
102 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
103 """
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 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
105 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
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 @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
108 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
109 @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
110 """
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 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
112 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
113 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
114 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
115
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 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
117 """
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 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
119 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
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 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
122 widget
6279
7c44be92f8a4 E5MapWidget: fixed a source docu issue
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6278
diff changeset
123 @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
124 """
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
125 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
126
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 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
128 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 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
130
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 @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
132 @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
133 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
134 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
135 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
136 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
137 self.update()
3327
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 def lineDimensions(self):
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 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
142
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 @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
144 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 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
146
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 def setEnabled(self, enable):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 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
150
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 @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
152 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
153 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
154 self.__enabled = enable
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
155 self.setVisible(enable)
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
156 self.__updateMasterViewportWidth()
3327
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 def isEnabled(self):
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 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
161
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 @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
163 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 return self.__enabled
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 def setBackgroundColor(self, color):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 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
169
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 @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
171 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
172 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
173 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
174 self.__setSliderColor()
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
175 self.update()
3327
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 def backgroundColor(self):
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 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
180
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 @return background color (QColor)
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 return QColor(self.__backgroundColor)
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 def sizeHint(self):
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 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
188
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 @return preferred size (QSize)
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 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
192
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 def paintEvent(self, event):
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 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
196
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 @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
198 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 # 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
200 painter = QPainter(self)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 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
202
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 # 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
204 self._paintIt(painter)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 # 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
207 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
208 penColor = self.__sliderColor
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 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
210 brushColor = Qt.transparent
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 painter.setBrush(QBrush(brushColor))
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 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
213 self._master.verticalScrollBar()))
3327
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 def _paintIt(self, painter):
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 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
218
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 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
220
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 @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
222 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 pass
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 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
226 """
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
227 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
228
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
229 @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
230 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
231 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
232 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
233 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
234 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
235 self.__mousePressPos = None
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236
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
237 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
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 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
240
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 @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
242 """
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
243 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
244 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
245 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
246 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
247
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
248 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
249 """
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
250 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
251
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
252 @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
253 """
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
254 if qVersionTuple() >= (5, 0, 0):
3778
0c5bc18da740 Added more changes to make eric6 usable with PyQt4 as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3698
diff changeset
255 isVertical = event.angleDelta().x() == 0
0c5bc18da740 Added more changes to make eric6 usable with PyQt4 as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3698
diff changeset
256 else:
0c5bc18da740 Added more changes to make eric6 usable with PyQt4 as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3698
diff changeset
257 isVertical = event.orientation() == Qt.Vertical
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
258 if self._master and \
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
259 event.modifiers() == Qt.NoModifier and \
3778
0c5bc18da740 Added more changes to make eric6 usable with PyQt4 as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3698
diff changeset
260 isVertical:
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
261 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
262
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 def calculateGeometry(self):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 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
266 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
267 if self._master:
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
268 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
269 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
270 if vsb.isVisible():
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 vsbw = vsb.contentsRect().width()
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 else:
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 vsbw = 0
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
274 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
275 if right > vsbw:
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 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
277 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
278 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
279 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
280 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
281 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
282 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
283 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
284 self.update()
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 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
287 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 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
289
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 @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
291 (boolean)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 @return scale factor (float)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
294 if self._master:
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 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
296 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
297 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
298 valHeight = vsb.maximum() - vsb.minimum() + vsb.pageStep()
3484
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3339
diff changeset
299 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
300 else:
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 return 1.0
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 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
304 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 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
306
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 @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
308 @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
309 (boolean)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 @return position (integer)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
312 if self._master:
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 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
314 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
315 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
316 else:
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 return value
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 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
320 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 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
322
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 @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
324 @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
325 (boolean)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 @return scrollbar value (integer)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
328 if self._master:
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 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
330 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
331 return vsb.minimum() + max(
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 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
333 else:
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 return position
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 def generateIndicatorRect(self, position):
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 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
339
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 @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
341 @return indicator rectangle (QRect)
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 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
344 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
345
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 def __generateSliderRange(self, scrollbar):
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 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
349
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 @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
351 @return slider rectangle (QRect)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 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
354 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
355 slider=True)
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
356 return QRect(0, pos1, self.__width - 1, pos2 - pos1)

eric ide

mercurial