def makeSettingsButton(self, XnatSetting): """ Constructs a setting button with a wrench icon that opens the appropriate settings tab. """ button = HoverButton() button.setIcon(qt.QIcon(os.path.join(self.MODULE.GLOBALS.LOCAL_URIS['icons'], 'wrench.png')) ) button.setFixedWidth(23) button.setFixedHeight(17) button.setDefaultStyleSheet('border: 1px solid transparent; border-radius: 2px; background-color: transparent; margin-left: 5px; text-align: left; padding-left: 0px; ') button.setHoverStyleSheet('border: 1px solid rgb(150,150,150); border-radius: 2px; background-color: transparent; margin-left: 5px; text-align: left; padding-left: 0px;') def openSettings(): self.MODULE.XnatSettingsWindow.showWindow(XnatSetting.tabTitle) button.connect('clicked()', openSettings) return button
def __init__(self, parent, title, maxHeight=1000, minHeight=60): """ Init function. """ if parent: super(AnimatedCollapsible, self).__init__(parent) else: super(AnimatedCollapsible, self).__init__(self) #-------------------- # We want to grab the sizeGrip right off # the bat so we can control its visibility. #-------------------- self.sizeGrip = self.children()[0] self.sizeGrip.hide() #-------------------- # We hide the module first because # it creates a flikering on loadup #-------------------- self.hide() #-------------------- # Set the arrow characters, # described accordingly. #-------------------- self.rightArrowChar = u'\u25b8' self.downArrowChar = u'\u25be' #-------------------- # Set Collapsed Height #-------------------- self.collapsedHeight = 30 #-------------------- # Set the min/max heights. #-------------------- self.minHeight = minHeight self.maxHeight = maxHeight #-------------------- # Set the toggleButton's height and width #-------------------- self.toggleHeight = 16 self.toggleWidth = 80 #-------------------- # Make sure the widget is 100% its parent's width. #-------------------- self.setStyleSheet('width: 100%') #-------------------- # Set the animation duration #-------------------- self.animDuration = 300 #-------------------- # Set the size policy #-------------------- self.setSizePolicy(qt.QSizePolicy.Ignored, qt.QSizePolicy.MinimumExpanding) #---------------- # Set the animation's easing curve. See: # http://harmattan-dev.nokia.com/docs/library/html/qt4/qeasingcurve.html # for more options. #---------------- self.easingCurve = qt.QEasingCurve(2) #---------------- # Set the minimum hieght #---------------- self.setMinimumHeight(self.minHeight) #---------------- # set the Title #---------------- self.title = title #---------------- # Make the toggle button #---------------- self.toggleButton = HoverButton(self) self.toggleButton.hide() self.toggleButton.setParent(self) self.toggleButton.setFixedHeight(self.toggleHeight) self.toggleButton.setCheckable(True) self.toggleButton.setObjectName('animatedCollapsibleToggleButton') self.toggleButton.setDefaultStyleSheet( '#animatedCollapsibleToggleButton {border: 1px solid transparent; background-color: white; margin-left: 5px; text-align: left; padding-left: 5px;}' ) self.toggleButton.setHoverStyleSheet( '#animatedCollapsibleToggleButton {border: 1px solid rgb(200,200,200); background-color: white; border-radius: 2px; margin-left: 5px; text-align: left; padding-left: 5px;}' ) self.configureButton(True) #---------------- # Make the internal 'frame' and set the style # accordingly. #---------------- self.frame = qt.QFrame(self) # # Prevent style sheet inheritance from # inner contents # self.frame.setObjectName('animateCollapsibleFrame') self.frame.setStyleSheet( '#animateCollapsibleFrame {margin-top: 9px; border: 2px solid lightgray; padding-top: 5px; padding-left: 2px; padding-right: 2px; padding-bottom: 2px}' ) #---------------- # Stack the button on top of the frame via a # QStackedLayout #---------------- self.stackedLayout = qt.QStackedLayout() self.stackedLayout.addWidget(self.toggleButton) self.stackedLayout.addWidget(self.frame) #---------------- # To make sure the button is on top. #---------------- self.stackedLayout.setCurrentIndex(0) self.stackedLayout.setStackingMode(1) #---------------- # Set the sayout #---------------- self.setLayout(self.stackedLayout) #---------------- # Init the animation group and callbacks. #---------------- self.animations = qt.QParallelAnimationGroup() self.onAnimate = None self.onCollapse = None self.onExpand = None self.ContentsWidgets = [] #---------------- # Set the default states after creation. #---------------- self.toggleButton.connect('toggled(bool)', self.setChecked) self.toggled = True #---------------- # Set the stretch height. # # NOTE: This is different from the maximumHeight, # it's a target height that the user sets so that # the collapsible will stretch as far as self.stretchHeight # dictates once its expanded. If we didn't have this # variable, the the widget would have a sendentary height # within a layout, not stretching to the layout's # maximum extents. # # # TODO: Ideally this parameter would be more of a percentage # but setting stylesheet percentages is not possible, becase # we are manipulating the .maximumHeight' property of the widget # during the animation. # Need to determine a more elegant way of of setting the 'stretch' # height to '100%' or equivalent. #---------------- self.stretchHeight = None
def __init__(self, parent, title): """ Init function. """ if parent: super(AnimatedCollapsible, self).__init__(parent) else: super(AnimatedCollapsible, self).__init__(self) #-------------------- # We want to grab the sizeGrip right off # the bat so we can control its visibility. #-------------------- self.sizeGrip = self.children()[0] self.sizeGrip.hide() #self.setSizeGripInside(False) #-------------------- # We hide the module first because # it creates a flikering on loadup #-------------------- self.hide() #-------------------- # Set the arrow characters, # described accordingly. #-------------------- self.rightArrowChar = u'\u25b8' self.downArrowChar = u'\u25be' #-------------------- # Set Collapsed Height #-------------------- self.collapsedHeight = 30 #-------------------- # Set the min/max heights. #-------------------- self.minExpandedHeight = 60 self.maxExpandedHeight = 1000 #-------------------- # Set the toggleButton's height and width #-------------------- self.toggleHeight = 16 self.toggleWidth = 80 #-------------------- # Make sure the widget is 100% its parent's width. #-------------------- self.setStyleSheet('width: 100%') #-------------------- # Set the animation duration #-------------------- self.animDuration = 250 #-------------------- # Set the size policy #-------------------- self.setSizePolicy(qt.QSizePolicy.Ignored, qt.QSizePolicy.MinimumExpanding) #---------------- # Set the animation's easing curve. See: # http://harmattan-dev.nokia.com/docs/library/html/qt4/qeasingcurve.html # for more options. #---------------- self.__easingCurve = qt.QEasingCurve(6) #---------------- # Set the minimum hieght #---------------- self.setMinimumHeight(self.minExpandedHeight) #---------------- # set the Title #---------------- self.title = title #---------------- # Make the toggle button #---------------- self.toggleButton = HoverButton(self) self.toggleButton.hide() self.toggleButton.setParent(self) self.toggleButton.setFixedHeight(self.toggleHeight) self.toggleButton.setCheckable(True) self.toggleButton.setObjectName('animatedCollapsibleToggleButton') buttonDefault = '#animatedCollapsibleToggleButton ' buttonDefault += '{border: 1px solid transparent; ' buttonDefault += 'background-color: white; margin-left: ' buttonDefault += '5px; text-align: left; padding-left: 5px;}' self.toggleButton.setDefaultStyleSheet(buttonDefault) buttonHover = '#animatedCollapsibleToggleButton {' buttonHover += 'border: 1px solid rgb(200,200,200); ' buttonHover += 'background-color: white; border-radius: 2px; ' buttonHover += 'margin-left: 5px; text-align: left; padding-left: 5px;}' self.toggleButton.setHoverStyleSheet(buttonHover) self.__modifyToggleButton(True) #---------------- # Make the internal 'frame' and set the style # accordingly. #---------------- self.frame = qt.QFrame(self) # # Prevent style sheet inheritance from # inner contents # self.frame.setObjectName('animateCollapsibleFrame') frameStyle = '#animateCollapsibleFrame ' frameStyle += '{margin-top: 9px; border: ' frameStyle += '2px solid lightgray; border-radius: 4px; padding-top: 5px; ' frameStyle += 'padding-left: 2px; padding-right: 2px; padding-bottom: 2px}' self.frame.setStyleSheet(frameStyle) #---------------- # Stack the button on top of the frame via a # QStackedLayout #---------------- self.stackedLayout = qt.QStackedLayout() self.stackedLayout.addWidget(self.toggleButton) self.stackedLayout.addWidget(self.frame) #---------------- # To make sure the button is on top. #---------------- self.stackedLayout.setCurrentIndex(0) self.stackedLayout.setStackingMode(1) #---------------- # Set the sayout #---------------- self.setLayout(self.stackedLayout) #---------------- # Init the animation group and callbacks. #---------------- self.animations = qt.QParallelAnimationGroup() self.__eventCallbacks = {} for key in AnimatedCollapsible.EVENT_TYPES: self.__eventCallbacks[key] = [] self.__contents = [] #---------------- # Set the default states after creation. #---------------- self.toggleButton.connect('toggled(bool)', self.setChecked) self.toggled = True self.sizeGrip.installEventFilter(self) self.installEventFilter(self)