Sun, 18 May 2014 14:13:09 +0200
Corrected a bunch of source docu issues.
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 | |
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 | |
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
|
12 | 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
|
13 | 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
|
14 | |
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 E5MapWidget(QWidget): |
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 | 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
|
19 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | 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
|
21 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | Constructor |
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 | @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
|
25 | """ |
3484
645c12de6b0c
Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3339
diff
changeset
|
26 | 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
|
27 | 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
|
28 | |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
29 | self.__width = 14 |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
30 | self.__lineBorder = 1 |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | 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
|
32 | 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
|
33 | self.__setSliderColor() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
35 | self._master = None |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | self.__enabled = False |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | if parent is not None and isinstance(parent, QAbstractScrollArea): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | self.setMaster(parent) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
41 | def __setSliderColor(self): |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
42 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3484
diff
changeset
|
43 | Private method to set the slider color depending upon the background |
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3484
diff
changeset
|
44 | color. |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
45 | """ |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
46 | if self.__backgroundColor.toHsv().value() < 128: |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
47 | # dark background, use white slider |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
48 | self.__sliderColor = Qt.white |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
49 | else: |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
50 | # light background, use black slider |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
51 | self.__sliderColor = Qt.black |
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
52 | |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | def __updateMasterViewportWidth(self): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | Private method to update the master's viewport width. |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
57 | if self._master: |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | if self.__enabled: |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | width = self.__width |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | else: |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | width = 0 |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
62 | 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
|
63 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | def setMaster(self, master): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | 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
|
67 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | @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
|
69 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
70 | 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
|
71 | 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
|
72 | 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
|
73 | self.__updateMasterViewportWidth() |
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 | def setWidth(self, width): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | 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
|
78 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | @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
|
80 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
81 | 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
|
82 | 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
|
83 | self.__updateMasterViewportWidth() |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
84 | self.update() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
86 | def width(self): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | 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
|
89 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | @return widget width (integer) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | return self.__width |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | 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
|
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 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
|
97 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | @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
|
99 | @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
|
100 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
101 | 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
|
102 | 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
|
103 | 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
|
104 | self.update() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | def lineDimensions(self): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | 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
|
109 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | @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
|
111 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | 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
|
113 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | def setEnabled(self, enable): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
115 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | 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
|
117 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
118 | @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
|
119 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
120 | 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
|
121 | self.__enabled = enable |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
122 | self.setVisible(enable) |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
123 | self.__updateMasterViewportWidth() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | def isEnabled(self): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | 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
|
128 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | @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
|
130 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | return self.__enabled |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | def setBackgroundColor(self, color): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | 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
|
136 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | @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
|
138 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
139 | 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
|
140 | 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
|
141 | self.__setSliderColor() |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
142 | self.update() |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
144 | def backgroundColor(self): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
145 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
146 | 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
|
147 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | @return background color (QColor) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
149 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
150 | return QColor(self.__backgroundColor) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
151 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
152 | def sizeHint(self): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
153 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
154 | 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
|
155 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
156 | @return preferred size (QSize) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | return QSize(self.__width, 0) |
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 | def paintEvent(self, event): |
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 | 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
|
163 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
164 | @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
|
165 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
166 | # 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
|
167 | painter = QPainter(self) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
168 | 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
|
169 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
170 | # 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
|
171 | self._paintIt(painter) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
172 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
173 | # 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
|
174 | 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
|
175 | penColor = self.__sliderColor |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | 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
|
177 | brushColor = Qt.transparent |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
178 | painter.setBrush(QBrush(brushColor)) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | 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
|
180 | self._master.verticalScrollBar())) |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
181 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
182 | def _paintIt(self, painter): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
183 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
184 | 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
|
185 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
186 | 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
|
187 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
188 | @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
|
189 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
190 | pass |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
191 | |
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
|
192 | 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
|
193 | """ |
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
|
194 | 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
|
195 | |
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
|
196 | @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
|
197 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
198 | 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
|
199 | 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
|
200 | 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
|
201 | 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
|
202 | self.__mousePressPos = None |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | |
3339
d0a603f1bfcd
Added support for wheel events and mouse move events to the map widget and made some adjustments to the representation (colors).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3329
diff
changeset
|
204 | 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
|
205 | """ |
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 | 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
|
207 | |
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 | @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
|
209 | """ |
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 | 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
|
211 | 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
|
212 | 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
|
213 | 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
|
214 | |
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
|
215 | 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
|
216 | """ |
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 | 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
|
218 | |
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 | @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
|
220 | """ |
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 | 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
|
222 | 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
|
223 | 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
|
224 | 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
|
225 | |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
226 | def calculateGeometry(self): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
227 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
228 | 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
|
229 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
230 | if self._master: |
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
231 | 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
|
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 | if vsb.isVisible(): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
234 | vsbw = vsb.contentsRect().width() |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
235 | else: |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
236 | vsbw = 0 |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
237 | 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
|
238 | if right > vsbw: |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
239 | vsbw = 0 |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
240 | 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
|
241 | self.__width, cr.height())) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
242 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
243 | 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
|
244 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
245 | 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
|
246 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
247 | @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
|
248 | (boolean) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
249 | @return scale factor (float) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
250 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
251 | if self._master: |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
252 | 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
|
253 | 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
|
254 | 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
|
255 | valHeight = vsb.maximum() - vsb.minimum() + vsb.pageStep() |
3484
645c12de6b0c
Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3339
diff
changeset
|
256 | 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
|
257 | else: |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
258 | return 1.0 |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
259 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | 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
|
261 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
262 | 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
|
263 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
264 | @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
|
265 | @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
|
266 | (boolean) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
267 | @return position (integer) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
268 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
269 | if self._master: |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
270 | 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
|
271 | 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
|
272 | 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
|
273 | else: |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
274 | return value |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
275 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
276 | 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
|
277 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
278 | 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
|
279 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
280 | @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
|
281 | @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
|
282 | (boolean) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
283 | @return scrollbar value (integer) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
284 | """ |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
285 | if self._master: |
3327
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
286 | 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
|
287 | 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
|
288 | return vsb.minimum() + max( |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | 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
|
290 | else: |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
291 | return position |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
292 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
293 | def generateIndicatorRect(self, position): |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
294 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
295 | 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
|
296 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
297 | @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
|
298 | @return indicator rectangle (QRect) |
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 | 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
|
301 | 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
|
302 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
303 | def __generateSliderRange(self, scrollbar): |
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 | 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
|
306 | |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
307 | @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
|
308 | @return slider rectangle (QRect) |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
309 | """ |
1338767b5315
Started implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
310 | 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
|
311 | 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
|
312 | slider=True) |
3329
1ee38e29ed4f
Continued implementing support for a marker map in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3327
diff
changeset
|
313 | return QRect(0, pos1, self.__width - 1, pos2 - pos1) |