Ejemplo n.º 1
0
 def slideIn(self, index, direction=Direction.Automatic):
     """
     Slides in the panel at the inputed index in the given
     direction for this widget.
     
     :param      index | <int>
                 direction | <XStackedWidget.Direction>
     
     :return     <bool> | success
     """
     # do not allow multiple slides while it is active
     if self._active:
         return False
     
     # determine the proper index to calculate
     invert = False
     if self.count() <= index:
         if not self.wrap():
             return False
         index = self.count() % index
         invert = True
     elif index < 0:
         if not self.wrap():
             return False
         index = self.count() + index
         invert = True
     
     # define the direction information
     if index == self.currentIndex():
         return False
     elif self.currentIndex() < index:
         if direction == XStackedWidget.Direction.Automatic:
             if self.isVerticalMode():
                 direction = XStackedWidget.Direction.BottomToTop
             else:
                 direction = XStackedWidget.Direction.RightToLeft
     else:
         if direction == XStackedWidget.Direction.Automatic:
             if self.isVerticalMode():
                 direction = XStackedWidget.Direction.TopToBottom
             else:
                 direction = XStackedWidget.Direction.LeftToRight
     
     # invert the animation if we are wrapping
     if invert:
         if direction == XStackedWidget.Direction.BottomToTop:
             direction = XStackedWidget.Direction.TopToBottom
         elif direction == XStackedWidget.Direction.TopToBottom:
             direction = XStackedWidget.Direction.BottomToTop
         elif direction == XStackedWidget.Direction.LeftToRight:
             direction = XStackedWidget.Direction.RightToLeft
         else:
             direction = XStackedWidget.Direction.LeftToRight
     
     self._active = True
     offset_x = self.frameRect().width()
     offset_y = self.frameRect().height()
     
     next_widget = self.widget(index)
     curr_widget = self.widget(self.currentIndex())
     
     next_widget.setGeometry(0, 0, offset_x, offset_y)
     
     if direction == XStackedWidget.Direction.BottomToTop:
         offset_x = 0
         offset_y = -offset_y
     elif direction == XStackedWidget.Direction.TopToBottom:
         offset_x = 0
     elif direction == XStackedWidget.Direction.RightToLeft:
         offset_x = -offset_x
         offset_y = 0
     elif direction == XStackedWidget.Direction.LeftToRight:
         offset_y = 0
     
     next_point = next_widget.pos()
     curr_point = curr_widget.pos()
     
     self._nextIndex = index
     self._lastIndex = self.currentIndex()
     self._lastPoint = QPoint(curr_point)
     
     next_widget.move(next_point.x()-offset_x, next_point.y()-offset_y)
     next_widget.raise_()
     next_widget.show()
     
     curr_anim = QPropertyAnimation(curr_widget, 'pos')
     curr_anim.setDuration(self.speed())
     curr_anim.setEasingCurve(self.animationType())
     curr_anim.setStartValue(curr_point)
     curr_anim.setEndValue(QPoint(curr_point.x()+offset_x,
                                  curr_point.y()+offset_y))
     
     next_anim = QPropertyAnimation(next_widget, 'pos')
     next_anim.setDuration(self.speed())
     next_anim.setEasingCurve(self.animationType())
     next_anim.setStartValue(QPoint(next_point.x()-offset_x,
                                    next_point.y()-offset_y))
     next_anim.setEndValue(next_point)
     
     anim_group = QParallelAnimationGroup(self)
     anim_group.addAnimation(curr_anim)
     anim_group.addAnimation(next_anim)
     
     anim_group.finished.connect(self._finishAnimation)
     anim_group.finished.connect(anim_group.deleteLater)
     anim_group.start()
     
     return True
Ejemplo n.º 2
0
 def setCurrentAction(self, action):
     """
     Sets the current action for this widget that highlights the size
     for this toolbar.
     
     :param      action | <QAction>
     """
     if action == self._currentAction:
         return
     
     self._currentAction = action
     self.currentActionChanged.emit(action)
     
     labels   = self.actionLabels()
     anim_grp = QParallelAnimationGroup(self)
     max_size = self.maximumPixmapSize()
     min_size = self.minimumPixmapSize()
     
     if action:
         label = self.labelForAction(action)
         index = labels.index(label)
         
         # create the highlight effect
         palette = self.palette()
         effect = QGraphicsDropShadowEffect(label)
         effect.setXOffset(0)
         effect.setYOffset(0)
         effect.setBlurRadius(20)
         effect.setColor(QColor(40, 40, 40))
         label.setGraphicsEffect(effect)
         
         offset = self.padding()
         if self.position() in (XDockToolbar.Position.East,
                                XDockToolbar.Position.West):
             self.resize(max_size.width() + offset, self.height())
         
         elif self.position() in (XDockToolbar.Position.North,
                                  XDockToolbar.Position.South):
             self.resize(self.width(), max_size.height() + offset)
         
         w  = max_size.width()
         h  = max_size.height()
         dw = (max_size.width() - min_size.width()) / 3
         dh = (max_size.height() - min_size.height()) / 3
         
         for i in range(4):
             before = index - i
             after  = index + i
             
             if 0 <= before and before < len(labels):
                 anim = XObjectAnimation(labels[before],
                                         'setPixmapSize',
                                         anim_grp)
                 
                 anim.setEasingCurve(self.easingCurve())
                 anim.setStartValue(labels[before].pixmapSize())
                 anim.setEndValue(QSize(w, h))
                 anim.setDuration(self.duration())
                 anim_grp.addAnimation(anim)
                 
                 if i:
                     labels[before].setGraphicsEffect(None)
             
             if after != before and 0 <= after and after < len(labels):
                 anim = XObjectAnimation(labels[after],
                                         'setPixmapSize',
                                         anim_grp)
                 
                 anim.setEasingCurve(self.easingCurve())
                 anim.setStartValue(labels[after].pixmapSize())
                 anim.setEndValue(QSize(w, h))
                 anim.setDuration(self.duration())
                 anim_grp.addAnimation(anim)
                 
                 if i:
                     labels[after].setGraphicsEffect(None)
         
             w -= dw
             h -= dh
     else:
         offset = self.padding()
         for label in self.actionLabels():
             # clear the graphics effect 
             label.setGraphicsEffect(None)
             
             # create the animation
             anim = XObjectAnimation(label, 'setPixmapSize', self)
             anim.setEasingCurve(self.easingCurve())
             anim.setStartValue(label.pixmapSize())
             anim.setEndValue(min_size)
             anim.setDuration(self.duration())
             anim_grp.addAnimation(anim)
         
         anim_grp.finished.connect(self.resizeToMinimum)
     
     anim_grp.start()
     self._animating = True
     anim_grp.finished.connect(anim_grp.deleteLater)
     anim_grp.finished.connect(self.__markAnimatingFinished)
     
     if self._currentAction:
         self._hoverTimer.start()
     else:
         self._hoverTimer.stop()
Ejemplo n.º 3
0
    def slideIn(self, index, direction=Direction.Automatic):
        """
        Slides in the panel at the inputed index in the given
        direction for this widget.
        
        :param      index | <int>
                    direction | <XStackedWidget.Direction>
        
        :return     <bool> | success
        """
        # do not allow multiple slides while it is active
        if self._active:
            return False

        # determine the proper index to calculate
        invert = False
        if self.count() <= index:
            if not self.wrap():
                return False
            index = self.count() % index
            invert = True
        elif index < 0:
            if not self.wrap():
                return False
            index = self.count() + index
            invert = True

        # define the direction information
        if index == self.currentIndex():
            return False
        elif self.currentIndex() < index:
            if direction == XStackedWidget.Direction.Automatic:
                if self.isVerticalMode():
                    direction = XStackedWidget.Direction.BottomToTop
                else:
                    direction = XStackedWidget.Direction.RightToLeft
        else:
            if direction == XStackedWidget.Direction.Automatic:
                if self.isVerticalMode():
                    direction = XStackedWidget.Direction.TopToBottom
                else:
                    direction = XStackedWidget.Direction.LeftToRight

        # invert the animation if we are wrapping
        if invert:
            if direction == XStackedWidget.Direction.BottomToTop:
                direction = XStackedWidget.Direction.TopToBottom
            elif direction == XStackedWidget.Direction.TopToBottom:
                direction = XStackedWidget.Direction.BottomToTop
            elif direction == XStackedWidget.Direction.LeftToRight:
                direction = XStackedWidget.Direction.RightToLeft
            else:
                direction = XStackedWidget.Direction.LeftToRight

        self._active = True
        offset_x = self.frameRect().width()
        offset_y = self.frameRect().height()

        next_widget = self.widget(index)
        curr_widget = self.widget(self.currentIndex())

        next_widget.setGeometry(0, 0, offset_x, offset_y)

        if direction == XStackedWidget.Direction.BottomToTop:
            offset_x = 0
            offset_y = -offset_y
        elif direction == XStackedWidget.Direction.TopToBottom:
            offset_x = 0
        elif direction == XStackedWidget.Direction.RightToLeft:
            offset_x = -offset_x
            offset_y = 0
        elif direction == XStackedWidget.Direction.LeftToRight:
            offset_y = 0

        next_point = next_widget.pos()
        curr_point = curr_widget.pos()

        self._nextIndex = index
        self._lastIndex = self.currentIndex()
        self._lastPoint = QPoint(curr_point)

        next_widget.move(next_point.x() - offset_x, next_point.y() - offset_y)
        next_widget.raise_()
        next_widget.show()

        curr_anim = QPropertyAnimation(curr_widget, 'pos')
        curr_anim.setDuration(self.speed())
        curr_anim.setEasingCurve(self.animationType())
        curr_anim.setStartValue(curr_point)
        curr_anim.setEndValue(
            QPoint(curr_point.x() + offset_x,
                   curr_point.y() + offset_y))

        next_anim = QPropertyAnimation(next_widget, 'pos')
        next_anim.setDuration(self.speed())
        next_anim.setEasingCurve(self.animationType())
        next_anim.setStartValue(
            QPoint(next_point.x() - offset_x,
                   next_point.y() - offset_y))
        next_anim.setEndValue(next_point)

        anim_group = QParallelAnimationGroup(self)
        anim_group.addAnimation(curr_anim)
        anim_group.addAnimation(next_anim)

        anim_group.finished.connect(self._finishAnimation)
        anim_group.finished.connect(anim_group.deleteLater)
        anim_group.start()

        return True