E5Gui/E5MapWidget.py

Thu, 06 Mar 2014 19:17:09 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 06 Mar 2014 19:17:09 +0100
changeset 3339
d0a603f1bfcd
parent 3329
1ee38e29ed4f
child 3484
645c12de6b0c
permissions
-rw-r--r--

Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).

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
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2014 Detlev Offenbach <detlev@die-offenbachs.de>
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
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
10 from PyQt4.QtCore import Qt, QSize, QRect, QCoreApplication
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from PyQt4.QtGui import QWidget, QAbstractScrollArea, QColor, QBrush, QPainter
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
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 class E5MapWidget(QWidget):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 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
17 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 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
19 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 Constructor
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 @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
23 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 super().__init__(parent)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 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
26
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
27 self.__width = 14
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
28 self.__lineBorder = 1
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 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
30 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
31 self.__setSliderColor()
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
33 self._master = None
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.__enabled = False
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 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
37 self.setMaster(parent)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
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
39 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
40 """
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 Set the slider color depending upon the background color.
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 """
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
43 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
44 # 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
45 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
46 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
47 # 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
48 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
49
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 def __updateMasterViewportWidth(self):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 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
53 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
54 if self._master:
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 if self.__enabled:
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 width = self.__width
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 else:
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 width = 0
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
59 self._master.setViewportMargins(0, 0, width, 0)
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 def setMaster(self, master):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 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
64
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 @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
66 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
67 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
68 self._master.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
69 self._master.verticalScrollBar().valueChanged.connect(self.repaint)
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 self.__updateMasterViewportWidth()
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 def setWidth(self, width):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 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
75
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 @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
77 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
78 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
79 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
80 self.__updateMasterViewportWidth()
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
81 self.update()
3327
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 width(self):
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 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
86
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 @return widget width (integer)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 return self.__width
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 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
92 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 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
94
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 @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
96 @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
97 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
98 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
99 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
100 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
101 self.update()
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 def lineDimensions(self):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 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
106
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 @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
108 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 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
110
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 def setEnabled(self, enable):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 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
114
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 @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
116 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
117 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
118 self.__enabled = enable
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
119 self.setVisible(enable)
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
120 self.__updateMasterViewportWidth()
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 def isEnabled(self):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 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
125
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 @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
127 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 return self.__enabled
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 def setBackgroundColor(self, color):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 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
133
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 @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
135 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
136 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
137 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
138 self.__setSliderColor()
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
139 self.update()
3327
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 def backgroundColor(self):
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 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
144
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 @return background color (QColor)
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 return QColor(self.__backgroundColor)
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 def sizeHint(self):
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 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
152
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 @return preferred size (QSize)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 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
156
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 def paintEvent(self, event):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 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
160
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 @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
162 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 # 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
164 painter = QPainter(self)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 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
166
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 # 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
168 self._paintIt(painter)
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 # 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
171 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
172 penColor = self.__sliderColor
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 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
174 brushColor = Qt.transparent
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 painter.setBrush(QBrush(brushColor))
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 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
177 self._master.verticalScrollBar()))
3327
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 def _paintIt(self, painter):
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 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
182
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 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
184
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 @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
186 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 pass
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188
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
189 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
190 """
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
191 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
192
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
193 @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
194 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
195 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
196 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
197 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
198 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
199 self.__mousePressPos = None
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200
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
201 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
202 """
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
203 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
204
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
205 @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
206 """
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
207 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
208 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
209 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
210 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
211
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
212 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
213 """
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
214 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
215
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
216 @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
217 """
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
218 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
219 event.modifiers() == Qt.NoModifier 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
220 event.orientation() == Qt.Vertical:
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 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
222
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 def calculateGeometry(self):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 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
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 self._master:
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
228 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
229 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
230 if vsb.isVisible():
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 vsbw = vsb.contentsRect().width()
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 else:
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 vsbw = 0
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
234 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
235 if right > vsbw:
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 vsbw = 0
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 self.setGeometry(QRect(cr.right() - self.__width - vsbw, cr.top(),
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 self.__width, cr.height()))
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 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
241 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 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
243
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 @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
245 (boolean)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 @return scale factor (float)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
248 if self._master:
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 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
250 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
251 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
252 valHeight = vsb.maximum() - vsb.minimum() + vsb.pageStep()
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 return posHeight / valHeight
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 else:
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 return 1.0
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 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
258 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 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
260
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 @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
262 @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
263 (boolean)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 @return position (integer)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
266 if self._master:
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 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
268 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
269 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
270 else:
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 return value
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 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
274 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 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
276
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 @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
278 @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
279 (boolean)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 @return scrollbar value (integer)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 """
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
282 if self._master:
3327
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 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
284 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
285 return vsb.minimum() + max(
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 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
287 else:
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 return position
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 def generateIndicatorRect(self, position):
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 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
293
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 @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
295 @return indicator rectangle (QRect)
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 """
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 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
298 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
299
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 def __generateSliderRange(self, scrollbar):
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 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
303
1338767b5315 Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 @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
305 @return slider rectangle (QRect)
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 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
308 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
309 slider=True)
3329
1ee38e29ed4f Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3327
diff changeset
310 return QRect(0, pos1, self.__width - 1, pos2 - pos1)

eric ide

mercurial