def __init__(self, windowid, layerkey, layerslock=None): qtgui.QWidget.__init__(self) # save the layer this is suppose to configure self.layerkey = layerkey self.windowid = windowid # setup ui self.ui = Ui_LayerConfigWidget() self.ui.setupUi(self) self.width = self.geometry().width() self.height = self.geometry().height() # put options in combobox for mode in BlendTranslations.layerallowedmodes: self.ui.blend_mode_box.addItem(mode) # without this the frame background is transparent self.ui.background_frame.setAutoFillBackground(True) # replace layer preview widget with custom widget self.ui.layerThumb = LayerPreviewWidget(self.ui.layerThumb, windowid, layerkey) self.ui.layerThumb.setAutoFillBackground(True) # set initial values according to what the layer has set self.updateValuesFromLayer(layerslock=layerslock)
class LayerConfigWidget(qtgui.QWidget): def __init__(self, windowid, layerkey, layerslock=None): qtgui.QWidget.__init__(self) # save the layer this is suppose to configure self.layerkey = layerkey self.windowid = windowid # setup ui self.ui = Ui_LayerConfigWidget() self.ui.setupUi(self) self.width = self.geometry().width() self.height = self.geometry().height() # put options in combobox for mode in BlendTranslations.layerallowedmodes: self.ui.blend_mode_box.addItem(mode) # without this the frame background is transparent self.ui.background_frame.setAutoFillBackground(True) # replace layer preview widget with custom widget self.ui.layerThumb = LayerPreviewWidget(self.ui.layerThumb, windowid, layerkey) self.ui.layerThumb.setAutoFillBackground(True) # set initial values according to what the layer has set self.updateValuesFromLayer(layerslock=layerslock) # create a quick instance just to figure out the standard geometry def getStandardGeometry(): testwidget = qtgui.QWidget() # setup ui testwidget.ui = Ui_LayerConfigWidget() testwidget.ui.setupUi(testwidget) return testwidget.geometry() getStandardGeometry = staticmethod(getStandardGeometry) # update the gui to reflect the values of the layer def updateValuesFromLayer(self, winlock=None, proplock=None, layerslock=None): win = BeeApp().master.getWindowById(self.windowid, winlock) if not win: return layer = win.getLayerForKey(self.layerkey, layerslock) if not layer: print_debug("WARNING: updateValueFromLayer could not find layer with key %s" % self.layerkey) return if not proplock: proplock = qtcore.QReadLocker(layer.propertieslock) # update visibility box self.ui.visibility_box.setChecked(layer.isVisible()) # update opacity slider # self.ui.opacity_box.setValue(layer.opacity()) self.ui.opacity_slider.setValue(int(layer.opacity() * 100)) # update name displayname = layer.name if layer.type == LayerTypes.animation: displayname += " (Animation)" elif layer.type == LayerTypes.network: displayname += " (Network)" self.ui.layer_name_label.setText(displayname) # update blend mode box self.ui.blend_mode_box.setCurrentIndex( self.ui.blend_mode_box.findText(BlendTranslations.modeToName(layer.compmode)) ) netbuttonstate = False netbuttontext = "" # only need text on the button if it's a network or floating layer if win.type == WindowTypes.networkclient: if win.ownedByNobody(layer.getOwner(proplock)): netbuttontext = "Claim Ownership" netbuttonstate = True elif win.ownedByMe(layer.getOwner(proplock)): netbuttontext = "Give Up Ownership" netbuttonstate = True if layer.type == LayerTypes.floating: netbuttontext = "Anchor On Layer" netbuttonstate = True # disable controls if client shouldn't be able to control them if win.type == WindowTypes.networkclient: if win.ownedByMe(layer.getOwner(proplock)) or layer.type == LayerTypes.floating: self.ui.opacity_slider.setEnabled(True) self.ui.blend_mode_box.setEnabled(True) else: self.ui.opacity_slider.setDisabled(True) self.ui.blend_mode_box.setDisabled(True) self.ui.network_control_button.setText(netbuttontext) self.ui.network_control_button.setEnabled(netbuttonstate) def refreshThumb(self): self.ui.layerThumb.update() def highlight(self): self.ui.background_frame.setBackgroundRole(qtgui.QPalette.Dark) self.refreshThumb() def unhighlight(self): self.ui.background_frame.setBackgroundRole(qtgui.QPalette.Window) self.refreshThumb() def on_visibility_box_toggled(self, state): layer = BeeApp().master.getLayerById(self.windowid, self.layerkey) window = layer.getWindow() # change visibility layer.setVisible(state) # recomposite whole image window.reCompositeImage() def on_opacity_slider_sliderMoved(self, value): # there are two events, one with a float and one with a string, we only need one win = BeeApp().master.getWindowById(self.windowid) win.addOpacityChangeToQueue(self.layerkey, value / 100.0) def on_opacity_slider_sliderReleased(self): win = BeeApp().master.getWindowById(self.windowid) win.addOpacityDoneToQueue(self.layerkey) def on_blend_mode_box_activated(self, value): # we only want the event with the string if not type(value) is qtcore.QString: return newmode = BlendTranslations.nameToMode(value) if newmode != None: layer = BeeApp().master.getLayerById(self.windowid, self.layerkey) if layer: win = layer.getWindow() win.addBlendModeChangeToQueue(layer.key, newmode) def on_network_control_button_pressed(self): layer = BeeApp().master.getLayerById(self.windowid, self.layerkey) win = layer.getWindow() proplock = qtcore.QReadLocker(layer.propertieslock) if layer.type == LayerTypes.floating: parent = layer.layerparent parent.anchor(layer) # the layer is owned locally so change it to be owned by no one elif win.ownedByMe(layer.owner): # print_debug("adding give up layer to queue for layer key: %d" % layer.key) if len(layer.childItems()): result = qtgui.QMessageBox.warning( win, "Floating layers can not be given up", "You are attempting to give up ownership of layer that has floting layers, if you continue the floating layers will be destroyed. To avoid having them destroyed please anchor them or move them to other layers.", "Continue", "Cancel", ) if result: return win.addGiveUpLayerToQueue(layer.key) # if the layer is owned by nobody then request it elif win.ownedByNobody(layer.owner): win.addRequestLayerToQueue(layer.key) def mousePressEvent(self, event): layer = BeeApp().master.getLayerById(self.windowid, self.layerkey) win = BeeApp().master.getWindowById(self.windowid) if layer: win.setActiveLayer(layer.key)