27 class EditorHighlightingStylesPage(ConfigurationPageBase, |
27 class EditorHighlightingStylesPage(ConfigurationPageBase, |
28 Ui_EditorHighlightingStylesPage): |
28 Ui_EditorHighlightingStylesPage): |
29 """ |
29 """ |
30 Class implementing the Editor Highlighting Styles configuration page. |
30 Class implementing the Editor Highlighting Styles configuration page. |
31 """ |
31 """ |
|
32 FAMILYONLY = 0 |
|
33 SIZEONLY = 1 |
|
34 FAMILYANDSIZE = 2 |
|
35 FONT = 99 |
|
36 |
32 def __init__(self, lexers): |
37 def __init__(self, lexers): |
33 """ |
38 """ |
34 Constructor |
39 Constructor |
35 |
40 |
36 @param lexers reference to the lexers dictionary |
41 @param lexers reference to the lexers dictionary |
37 """ |
42 """ |
38 ConfigurationPageBase.__init__(self) |
43 ConfigurationPageBase.__init__(self) |
39 self.setupUi(self) |
44 self.setupUi(self) |
40 self.setObjectName("EditorHighlightingStylesPage") |
45 self.setObjectName("EditorHighlightingStylesPage") |
|
46 |
|
47 self.__fontButtonMenu = QMenu() |
|
48 act = self.__fontButtonMenu.addAction(self.trUtf8("Font")) |
|
49 act.setData(self.FONT) |
|
50 self.__fontButtonMenu.addSeparator() |
|
51 act = self.__fontButtonMenu.addAction(self.trUtf8("Family and Size only")) |
|
52 act.setData(self.FAMILYANDSIZE) |
|
53 act = self.__fontButtonMenu.addAction(self.trUtf8("Family only")) |
|
54 act.setData(self.FAMILYONLY) |
|
55 act = self.__fontButtonMenu.addAction(self.trUtf8("Size only")) |
|
56 act.setData(self.SIZEONLY) |
|
57 self.__fontButtonMenu.triggered.connect(self.__fontButtonMenuTriggered) |
|
58 self.fontButton.setMenu(self.__fontButtonMenu) |
|
59 |
|
60 self.__allFontsButtonMenu = QMenu() |
|
61 act = self.__allFontsButtonMenu.addAction(self.trUtf8("Font")) |
|
62 act.setData(self.FONT) |
|
63 self.__allFontsButtonMenu.addSeparator() |
|
64 act = self.__allFontsButtonMenu.addAction(self.trUtf8("Family and Size only")) |
|
65 act.setData(self.FAMILYANDSIZE) |
|
66 act = self.__allFontsButtonMenu.addAction(self.trUtf8("Family only")) |
|
67 act.setData(self.FAMILYONLY) |
|
68 act = self.__allFontsButtonMenu.addAction(self.trUtf8("Size only")) |
|
69 act.setData(self.SIZEONLY) |
|
70 self.__allFontsButtonMenu.triggered.connect(self.__allFontsButtonMenuTriggered) |
|
71 self.allFontsButton.setMenu(self.__allFontsButtonMenu) |
41 |
72 |
42 self.lexer = None |
73 self.lexer = None |
43 self.lexers = lexers |
74 self.lexers = lexers |
44 |
75 |
45 # set initial values |
76 # set initial values |
155 self.sampleText.setPalette(pl) |
186 self.sampleText.setPalette(pl) |
156 self.sampleText.repaint() |
187 self.sampleText.repaint() |
157 for style in list(self.lexer.ind2style.values()): |
188 for style in list(self.lexer.ind2style.values()): |
158 self.lexer.setPaper(colour, style) |
189 self.lexer.setPaper(colour, style) |
159 |
190 |
160 @pyqtSlot() |
191 def __changeFont(self, doAll, familyOnly, sizeOnly): |
161 def on_fontButton_clicked(self): |
192 """ |
162 """ |
193 Private slot to change the highlighter font. |
163 Private method used to select the font of the selected style and lexer. |
194 |
164 """ |
195 @param doAll flag indicating to change the font for all styles (boolean) |
|
196 @param familyOnly flag indicating to set the font family only (boolean) |
|
197 @param sizeOnly flag indicating to set the font size only (boolean |
|
198 """ |
|
199 def setFont(font, style, familyOnly, sizeOnly): |
|
200 """ |
|
201 Local function to set the font. |
|
202 |
|
203 @param font font to be set (QFont) |
|
204 @param style style to set the font for (integer) |
|
205 @param familyOnly flag indicating to set the font family only (boolean) |
|
206 @param sizeOnly flag indicating to set the font size only (boolean |
|
207 """ |
|
208 if familyOnly or sizeOnly: |
|
209 newFont = QFont(self.lexer.font(style)) |
|
210 if familyOnly: |
|
211 newFont.setFamily(font.family()) |
|
212 if sizeOnly: |
|
213 newFont.setPointSize(font.pointSize()) |
|
214 self.lexer.setFont(newFont, style) |
|
215 else: |
|
216 self.lexer.setFont(font, style) |
|
217 |
|
218 def setSampleFont(font, familyOnly, sizeOnly): |
|
219 """ |
|
220 Local function to set the font of the sample text. |
|
221 |
|
222 @param font font to be set (QFont) |
|
223 @param familyOnly flag indicating to set the font family only (boolean) |
|
224 @param sizeOnly flag indicating to set the font size only (boolean |
|
225 """ |
|
226 if familyOnly or sizeOnly: |
|
227 newFont = QFont(self.lexer.font(self.style)) |
|
228 if familyOnly: |
|
229 newFont.setFamily(font.family()) |
|
230 if sizeOnly: |
|
231 newFont.setPointSize(font.pointSize()) |
|
232 self.sampleText.setFont(newFont) |
|
233 else: |
|
234 self.sampleText.setFont(font) |
|
235 |
165 font, ok = QFontDialog.getFont(self.lexer.font(self.style)) |
236 font, ok = QFontDialog.getFont(self.lexer.font(self.style)) |
166 if ok: |
237 if ok: |
167 self.sampleText.setFont(font) |
238 setSampleFont(font, familyOnly, sizeOnly) |
168 if len(self.styleElementList.selectedItems()) > 1: |
239 if doAll: |
|
240 for style in list(self.lexer.ind2style.values()): |
|
241 setFont(font, style, familyOnly, sizeOnly) |
|
242 elif len(self.styleElementList.selectedItems()) > 1: |
169 for selItem in self.styleElementList.selectedItems(): |
243 for selItem in self.styleElementList.selectedItems(): |
170 style = self.lexer.ind2style[self.styleElementList.row(selItem)] |
244 style = self.lexer.ind2style[self.styleElementList.row(selItem)] |
171 self.lexer.setFont(font, style) |
245 setFont(font, style, familyOnly, sizeOnly) |
172 else: |
246 else: |
173 self.lexer.setFont(font, self.style) |
247 setFont(font, self.style, familyOnly, sizeOnly) |
174 |
248 |
175 @pyqtSlot() |
249 def __fontButtonMenuTriggered(self, act): |
176 def on_allFontsButton_clicked(self): |
250 """ |
177 """ |
251 Private slot used to select the font of the selected style and lexer. |
178 Private method used to change the font of all styles of a selected lexer. |
252 |
179 """ |
253 @param act reference to the triggering action (QAction) |
180 font, ok = QFontDialog.getFont(self.lexer.font(self.style)) |
254 """ |
181 if ok: |
255 if act is None: |
182 self.sampleText.setFont(font) |
256 return |
183 for style in list(self.lexer.ind2style.values()): |
257 |
184 self.lexer.setFont(font, style) |
258 familyOnly = act.data() in [self.FAMILYANDSIZE, self.FAMILYONLY] |
|
259 sizeOnly = act.data() in [self.FAMILYANDSIZE, self.SIZEONLY] |
|
260 self.__changeFont(False, familyOnly, sizeOnly) |
|
261 |
|
262 def __allFontsButtonMenuTriggered(self, act): |
|
263 """ |
|
264 Private slot used to change the font of all styles of a selected lexer. |
|
265 |
|
266 @param act reference to the triggering action (QAction) |
|
267 """ |
|
268 if act is None: |
|
269 return |
|
270 |
|
271 familyOnly = act.data() in [self.FAMILYANDSIZE, self.FAMILYONLY] |
|
272 sizeOnly = act.data() in [self.FAMILYANDSIZE, self.SIZEONLY] |
|
273 self.__changeFont(True, familyOnly, sizeOnly) |
185 |
274 |
186 def on_eolfillCheckBox_toggled(self, b): |
275 def on_eolfillCheckBox_toggled(self, b): |
187 """ |
276 """ |
188 Private method used to set the eolfill for the selected style and lexer. |
277 Private method used to set the eolfill for the selected style and lexer. |
189 |
278 |