Fixing the text color on dark backgrounds, updating the background to a non-obsolete...
[ejpi] / src / libraries / qtpie.py
index e2ccd20..72888e3 100755 (executable)
@@ -195,6 +195,9 @@ class PieArtist(object):
        ICON_SIZE_DEFAULT = 32
 
        def __init__(self, filing):
+               # @bug The wrong text is being using on unselected pie menus
+               # @bug Plus it would be a good idea to fill in the icon body's
+               # @bug Maybe even make the icons glow?
                self._filing = filing
 
                self._cachedOuterRadius = self._filing.outerRadius()
@@ -256,16 +259,17 @@ class PieArtist(object):
                        if selectionIndex == PieFiling.SELECTION_CENTER and self._filing.center().isEnabled():
                                painter.setBrush(self.palette.highlight())
                        else:
-                               painter.setBrush(self.palette.background())
+                               painter.setBrush(self.palette.window())
+                       painter.setPen(self.palette.mid().color())
 
-                       painter.fillRect(self._canvas.rect(), painter.brush())
+                       painter.drawRect(self._canvas.rect())
                        self._paint_center_foreground(painter, selectionIndex)
                        return self._canvas
                elif numChildren == 1:
                        if selectionIndex == 0 and self._filing[0].isEnabled():
                                painter.setBrush(self.palette.highlight())
                        else:
-                               painter.setBrush(self.palette.background())
+                               painter.setBrush(self.palette.window())
 
                        painter.fillRect(self._canvas.rect(), painter.brush())
                else:
@@ -293,7 +297,7 @@ class PieArtist(object):
                if i == selectionIndex and self._filing[i].isEnabled():
                        painter.setBrush(self.palette.highlight())
                else:
-                       painter.setBrush(self.palette.background())
+                       painter.setBrush(self.palette.window())
                painter.setPen(self.palette.mid().color())
 
                a = self._filing._index_to_angle(i, True)
@@ -363,13 +367,13 @@ class PieArtist(object):
                                        brush = self.palette.highlight()
                                else:
                                        pen = self.palette.mid()
-                                       brush = self.palette.background()
+                                       brush = self.palette.window()
                        else:
                                if action.isEnabled():
-                                       pen = self.palette.text()
+                                       pen = self.palette.windowText()
                                else:
                                        pen = self.palette.mid()
-                               brush = self.palette.background()
+                               brush = self.palette.window()
 
                        leftX = x - averageWidth + iconWidth
                        topY = y + textHeight/2
@@ -383,7 +387,7 @@ class PieArtist(object):
                if selectionIndex == PieFiling.SELECTION_CENTER and self._filing.center().isEnabled():
                        background = self.palette.highlight().color()
                else:
-                       background = self.palette.background().color()
+                       background = self.palette.window().color()
 
                innerRadius = self._cachedInnerRadius
                adjustmentCenterPos = adjustmentRect.center()
@@ -467,8 +471,10 @@ class QPieDisplay(QtGui.QWidget):
                QtGui.QWidget.paintEvent(self, paintEvent)
 
        def selectAt(self, index):
+               oldIndex = self._selectionIndex
                self._selectionIndex = index
-               self.update()
+               if self.isVisible():
+                       self.update()
 
 
 class QPieButton(QtGui.QWidget):
@@ -479,7 +485,11 @@ class QPieButton(QtGui.QWidget):
        aboutToShow = QtCore.pyqtSignal()
        aboutToHide = QtCore.pyqtSignal()
 
+       BUTTON_RADIUS = 24
+       DELAY = 250
+
        def __init__(self, buttonSlice, parent = None):
+               # @bug Artifacts on Maemo 5 due to window 3D effects, find way to disable them for just these?
                QtGui.QWidget.__init__(self, parent)
                self._cachedCenterPosition = self.rect().center()
 
@@ -489,11 +499,17 @@ class QPieButton(QtGui.QWidget):
 
                self._buttonFiling = PieFiling()
                self._buttonFiling.set_center(buttonSlice)
+               # @todo Figure out how to make the button auto-fill to content
+               self._buttonFiling.setOuterRadius(self.BUTTON_RADIUS)
                self._buttonArtist = PieArtist(self._buttonFiling)
-               centerSize = self._buttonArtist.centerSize()
-               self._buttonFiling.setOuterRadius(max(centerSize.width(), centerSize.height()))
                self._poppedUp = False
 
+               self._delayPopupTimer = QtCore.QTimer()
+               self._delayPopupTimer.setInterval(self.DELAY)
+               self._delayPopupTimer.setSingleShot(True)
+               self._delayPopupTimer.timeout.connect(self._on_delayed_popup)
+               self._popupLocation = None
+
                self._mousePosition = None
                self.setFocusPolicy(QtCore.Qt.StrongFocus)
 
@@ -530,21 +546,33 @@ class QPieButton(QtGui.QWidget):
        def setOuterRadius(self, radius):
                self._filing.setOuterRadius(radius)
 
+       def buttonRadius(self):
+               return self._buttonFiling.outerRadius()
+
+       def setButtonRadius(self, radius):
+               self._buttonFiling.setOuterRadius(radius)
+
        def sizeHint(self):
                return self._buttonArtist.pieSize()
 
        @misc_utils.log_exception(_moduleLogger)
        def mousePressEvent(self, mouseEvent):
-               self._popup_child(mouseEvent.globalPos())
                lastSelection = self._selectionIndex
 
                lastMousePos = mouseEvent.pos()
                self._mousePosition = lastMousePos
                self._update_selection(self._cachedCenterPosition)
 
-               if lastSelection != self._selectionIndex:
-                       self.highlighted.emit(self._selectionIndex)
-                       self._display.selectAt(self._selectionIndex)
+               self.highlighted.emit(self._selectionIndex)
+
+               self._display.selectAt(self._selectionIndex)
+               self._popupLocation = mouseEvent.globalPos()
+               self._delayPopupTimer.start()
+
+       @misc_utils.log_exception(_moduleLogger)
+       def _on_delayed_popup(self):
+               assert self._popupLocation is not None
+               self._popup_child(self._popupLocation)
 
        @misc_utils.log_exception(_moduleLogger)
        def mouseMoveEvent(self, mouseEvent):
@@ -562,8 +590,14 @@ class QPieButton(QtGui.QWidget):
                        self.highlighted.emit(self._selectionIndex)
                        self._display.selectAt(self._selectionIndex)
 
+               if self._selectionIndex != PieFiling.SELECTION_CENTER and self._delayPopupTimer.isActive():
+                       self._on_delayed_popup()
+
        @misc_utils.log_exception(_moduleLogger)
        def mouseReleaseEvent(self, mouseEvent):
+               self._delayPopupTimer.stop()
+               self._popupLocation = None
+
                lastSelection = self._selectionIndex
 
                lastMousePos = mouseEvent.pos()
@@ -601,9 +635,13 @@ class QPieButton(QtGui.QWidget):
                        self._select_at(PieFiling.SELECTION_CENTER)
                        self._display.selectAt(self._selectionIndex)
                elif keyEvent.key() in [QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter, QtCore.Qt.Key_Space]:
+                       self._delayPopupTimer.stop()
+                       self._popupLocation = None
                        self._activate_at(self._selectionIndex)
                        self._hide_child()
                elif keyEvent.key() in [QtCore.Qt.Key_Escape, QtCore.Qt.Key_Backspace]:
+                       self._delayPopupTimer.stop()
+                       self._popupLocation = None
                        self._activate_at(PieFiling.SELECTION_NONE)
                        self._hide_child()
                else:
@@ -644,6 +682,9 @@ class QPieButton(QtGui.QWidget):
                self._poppedUp = True
                self.aboutToShow.emit()
 
+               self._delayPopupTimer.stop()
+               self._popupLocation = None
+
                position = position - QtCore.QPoint(self._filing.outerRadius(), self._filing.outerRadius())
                self._display.move(position)
                self._display.show()