2 from PyQt4.QtGui import QColor, QPen, QBrush, QRadialGradient
12 BACKGROUND_SHAPE =
'ROUNDRECT'
15 PEN_COLOR = QColor(242, 230, 242)
16 FILL_COLOR1 = QColor(59, 59, 59, 200)
18 TITLE_COLOR = QColor(Qt.white)
21 AUTOSIZE_KEEP_ASPECT_RATIO =
False
22 SELECTABLE_FLAG =
False
23 USE_BACKGROUND_GRADIENT_FLAG =
False
26 HOVER_COLOR1 = QColor(0, 0, 240)
27 HOVER_COLOR2 = QColor(0, 0, 200)
29 def __init__(self, parent=None, associatedWidget=None, orientation=Qt.Horizontal):
32 logging.debug(
"%s: Constructor" % self.__class__.__name__)
41 VispaWidget.__init__(self, parent)
44 self.setMouseTracking(
True)
58 self._spacer.setAutoscale(
True,
False)
60 self._spacer.setFont(self.font())
61 self._spacer.setText(
" | ")
62 self._spacer.calculateDimensions()
72 entry.setAutoscale(
True,
False)
74 entry.setFont(self.font())
76 entry.calculateDimensions()
77 self._menuEntryTextFields.append(entry)
78 self._menuEntrySlots.append(slot)
85 index = self._menuEntryTextFields.index(entry)
86 self._menuEntryTextFields.remove(entry)
87 self._menuEntrySlots.pop(index)
92 entry.calculateDimensions()
104 """ Calculates needed space for widget content.
115 textFieldWidth += entry.getWidth()
116 textFieldHeight =
max(textFieldHeight, entry.getHeight())
119 neededWidth += textFieldWidth
120 neededHeight += textFieldHeight
123 maxWidth = self.maximumSize().
width()
124 maxHeight = self.maximumSize().
height()
126 maxScaleWidth =
min(1.0, 1.0 * maxWidth/neededWidth)
127 maxScaleHeight =
min(1.0, 1.0 * maxHeight/neededHeight)
128 if maxScaleWidth != 1.0
or maxScaleHeight != 1.0:
132 scale =
min(maxScaleWidth, maxScaleHeight)
134 neededHeight *= scale
136 return QSize(
max(self.minimumSize().
width(), neededWidth),
max(self.minimumSize().
height(), neededHeight))
138 def paint(self, painter, event=None):
139 """ Takes care of painting widget content on given painter.
141 VispaWidget.paint(self, painter, event)
145 """ Tells TextField object of text field to draw title on widget.
149 spacerWidth = self._spacer.getWidth() * self.
zoomFactor()
151 painter.setPen(originalPen)
155 self._spacer.paint(painter, x, y, self.
zoomFactor())
158 hoverRectXOffset = 0.3 * spacerWidth
159 hoverRectYOffset = 0.3 * self.
getDistance(
'topMargin')
160 hoverWidth = entry.getWidth() * self.
zoomFactor() + 2 * hoverRectXOffset
161 hoverHeight = entry.getHeight() * self.
zoomFactor() + 2 * hoverRectYOffset
164 self._hoverGradient.setCenter(QPointF(entry.getDrawRect(self.
zoomFactor()).center()))
165 self._hoverGradient.setFocalPoint(QPointF(entry.getDrawRect(self.
zoomFactor()).center()))
166 self._hoverGradient.setRadius(
min(hoverWidth, hoverHeight))
169 painter.setPen(Qt.NoPen)
171 painter.drawRoundedRect(x - hoverRectXOffset, y - hoverRectYOffset, hoverWidth, hoverHeight, 5, 5)
172 painter.setPen(originalPen)
178 if bool(event.buttons() & Qt.LeftButton):
179 VispaWidget.mouseMoveEvent(self, event)
188 VispaWidget.mousePressEvent(self, event)
203 VispaWidget.hide(self)
207 VispaWidget.showEvent(self, event)
bool contains(EventRange const &lh, EventID const &rh)
const T & max(const T &a, const T &b)