38 |
41 |
39 @param state state data generated by saveState |
42 @param state state data generated by saveState |
40 """ |
43 """ |
41 return |
44 return |
42 |
45 |
43 def initColour(self, colourstr, button, prefMethod): |
46 def initColour(self, colourKey, button, prefMethod, byName=False, hasAlpha=False): |
44 """ |
47 """ |
45 Public method to initialize a colour selection button. |
48 Public method to initialize a colour selection button. |
46 |
49 |
47 @param colourstr colour to be set (string) |
50 @param colourKey key of the colour resource (string) |
48 @param button reference to a button to show the colour on (QPushButton) |
51 @param button reference to a button to show the colour on (QPushButton) |
49 @param prefMethod preferences method to get the colour |
52 @param prefMethod preferences method to get the colour |
50 @return reference to the created colour (QColor) |
53 @keyparam byName flag indicating to retrieve/save by colour name (boolean) |
|
54 @keyparam hasAlpha flag indicating to allow alpha channel (boolean) |
51 """ |
55 """ |
52 colour = QColor(prefMethod(colourstr)) |
56 colour = QColor(prefMethod(colourKey)) |
53 size = button.size() |
57 size = button.size() |
54 pm = QPixmap(size.width() / 2, size.height() / 2) |
58 pm = QPixmap(size.width() / 2, size.height() / 2) |
55 pm.fill(colour) |
59 pm.fill(colour) |
56 button.setIconSize(pm.size()) |
60 button.setIconSize(pm.size()) |
57 button.setIcon(QIcon(pm)) |
61 button.setIcon(QIcon(pm)) |
58 return colour |
62 button.setProperty("colorKey", colourKey) |
|
63 button.setProperty("hasAlpha", hasAlpha) |
|
64 button.clicked[()].connect(self.__selectColourSlot) |
|
65 self.__coloursDict[colourKey] = [colour, byName] |
59 |
66 |
60 def initColour2(self, colourDict, colourstr, button, prefMethod, selectSlot): |
67 @pyqtSlot() |
|
68 def __selectColourSlot(self): |
61 """ |
69 """ |
62 Public method to initialize a colour selection button. |
70 Private slot to select a color. |
|
71 """ |
|
72 button = self.sender() |
|
73 colorKey = button.property("colorKey") |
|
74 hasAlpha = button.property("hasAlpha") |
63 |
75 |
64 @param colourDict reference to the dictionary storing the colors |
76 if hasAlpha: |
65 @param colourstr colour to be set (string) |
77 colour = QColorDialog.getColor(self.__coloursDict[colorKey][0], None, "", |
66 @param button reference to a button to show the colour on (QPushButton) |
|
67 @param prefMethod preferences method to get the colour |
|
68 @param selectSlot method to select the color |
|
69 """ |
|
70 colour = QColor(prefMethod(colourstr)) |
|
71 size = button.size() |
|
72 pm = QPixmap(size.width() / 2, size.height() / 2) |
|
73 pm.fill(colour) |
|
74 button.setIconSize(pm.size()) |
|
75 button.setIcon(QIcon(pm)) |
|
76 button.setProperty("colorName", colourstr) |
|
77 button.clicked[()].connect(selectSlot) |
|
78 colourDict[colourstr] = colour |
|
79 |
|
80 def selectColour(self, button, colourVar, showAlpha=False): |
|
81 """ |
|
82 Public method used by the colour selection buttons. |
|
83 |
|
84 @param button reference to a button to show the colour on (QPushButton) |
|
85 @param colourVar reference to the variable containing the colour (QColor) |
|
86 @param showAlpha flag indicating to show a selection for the alpha |
|
87 channel (boolean) |
|
88 @return selected colour (QColor) |
|
89 """ |
|
90 if showAlpha: |
|
91 colour = QColorDialog.getColor(colourVar, None, "", |
|
92 QColorDialog.ShowAlphaChannel) |
78 QColorDialog.ShowAlphaChannel) |
93 else: |
79 else: |
94 colour = QColorDialog.getColor(colourVar) |
80 colour = QColorDialog.getColor(self.__coloursDict[colorKey][0]) |
95 if colour.isValid(): |
81 if colour.isValid(): |
96 size = button.iconSize() |
82 size = button.iconSize() |
97 pm = QPixmap(size.width(), size.height()) |
83 pm = QPixmap(size.width(), size.height()) |
98 pm.fill(colour) |
84 pm.fill(colour) |
99 button.setIcon(QIcon(pm)) |
85 button.setIcon(QIcon(pm)) |
100 else: |
86 self.__coloursDict[colorKey][0] = colour |
101 colour = colourVar |
87 |
102 return colour |
88 def saveColours(self, prefMethod): |
|
89 """ |
|
90 Public method to save the colour selections. |
|
91 |
|
92 @param prefMethod preferences method to set the colour |
|
93 """ |
|
94 for key in self.__coloursDict: |
|
95 if self.__coloursDict[key][1]: |
|
96 prefMethod(key, self.__coloursDict[key][0].name()) |
|
97 else: |
|
98 prefMethod(key, self.__coloursDict[key][0]) |
103 |
99 |
104 def selectFont(self, fontSample, fontVar, showFontInfo=False): |
100 def selectFont(self, fontSample, fontVar, showFontInfo=False): |
105 """ |
101 """ |
106 Public method used by the font selection buttons. |
102 Public method used by the font selection buttons. |
107 |
103 |