Class: Cosmos::RubyEditor
Defined Under Namespace
Classes: LineNumberArea, RubySyntax
Constant Summary
collapse
- CHAR_57 =
Qt::Char.new(57)
- BREAKPOINT_SET =
1
- BREAKPOINT_CLEAR =
-1
- MINIMUM_POINT_SIZE =
4
CompletionTextEdit::SELECTION_DETAILS_POOL, CompletionTextEdit::TRUE_VARIANT
Instance Attribute Summary collapse
Instance Method Summary
collapse
#center_line, #column_number, #current_line, #get_line, #highlight_line, #indent_selection, #keyPressEvent, #line_number, #previous_line, #stop_highlight, #unindent_selection
Constructor Details
#initialize(parent, font = Cosmos.get_default_font) ⇒ RubyEditor
Returns a new instance of RubyEditor.
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 158
def initialize(parent, font = Cosmos.get_default_font)
super(parent)
setFont(font)
@fontMetrics = Cosmos.getFontMetrics(font)
setStyleSheet("selection-background-color: lightblue; selection-color: black;")
@breakpoints = []
@enable_breakpoints = false
@syntax = RubySyntax.new(document())
@lineNumberArea = LineNumberArea.new(self)
connect(self, SIGNAL('blockCountChanged(int)'), self, SLOT('line_count_changed(int)'))
connect(self, SIGNAL('updateRequest(const QRect &, int)'), self, SLOT('update_line_number_area(const QRect &, int)'))
line_count_changed(-1)
end
|
Instance Attribute Details
#enable_breakpoints ⇒ Object
Returns the value of attribute enable_breakpoints.
29
30
31
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 29
def enable_breakpoints
@enable_breakpoints
end
|
Returns the value of attribute filename.
30
31
32
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 30
def filename
@filename
end
|
Instance Method Details
#add_breakpoint(line) ⇒ Object
209
210
211
212
213
214
215
216
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 209
def add_breakpoint(line)
@breakpoints << line
block = document.findBlockByNumber(line-1)
block.setUserState(BREAKPOINT_SET)
block.dispose
block = nil
@lineNumberArea.repaint
end
|
#clear_breakpoint(line) ⇒ Object
218
219
220
221
222
223
224
225
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 218
def clear_breakpoint(line)
@breakpoints.delete(line)
block = document.findBlockByNumber(line-1)
block.setUserState(BREAKPOINT_CLEAR)
block.dispose
block = nil
@lineNumberArea.repaint
end
|
#clear_breakpoints ⇒ Object
227
228
229
230
231
232
233
234
235
236
237
238
239
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 227
def clear_breakpoints
@breakpoints = []
block = document.firstBlock()
while (block.isValid())
block.setUserState(BREAKPOINT_CLEAR)
next_block = block.next()
block.dispose
block = next_block
end
block.dispose
block = nil
@lineNumberArea.repaint
end
|
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 266
def
cursor = textCursor
no_selection = cursor.hasSelection ? false : true
cursor.beginEditBlock
selection_end = cursor.selectionEnd
cursor.setPosition(textCursor.selectionStart)
cursor.movePosition(Qt::TextCursor::StartOfLine)
result = true
while (cursor.position < selection_end && result == true) || (no_selection)
if cursor.block.text =~ /^\S*#~/
cursor.deleteChar
cursor.deleteChar
selection_end -= 2
else
cursor.insertText("#~")
selection_end += 2
end
cursor.movePosition(Qt::TextCursor::StartOfLine)
result = cursor.movePosition(Qt::TextCursor::Down)
break if no_selection
end
cursor.endEditBlock
end
|
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 198
def (point)
= createStandardContextMenu()
return unless @enable_breakpoints
.addSeparator()
.addAction(create_add_breakpoint_action(point))
.addAction(create_clear_breakpoint_action(point))
.addAction(create_clear_all_breakpoints_action())
end
|
192
193
194
195
196
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 192
def dispose
super()
@syntax.dispose
@lineNumberArea.dispose
end
|
#line_number_area_paint_event(event) ⇒ Object
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 337
def line_number_area_paint_event(event)
painter = Qt::Painter.new(@lineNumberArea)
painter.setFont(font())
if painter.isActive and not painter.paintEngine.nil?
event_rect = event.rect()
painter.fillRect(event_rect, Qt::lightGray)
block = firstVisibleBlock()
blockNumber = block.blockNumber()
top, bottom = block_top_and_bottom(block)
width = @lineNumberArea.width()
height = @fontMetrics.height()
ellipse_width = @fontMetrics.width(CHAR_57)
painter.setPen(Cosmos::BLACK)
while (block.isValid() and top <= event_rect.bottom())
if (block.isVisible() and bottom >= event_rect.top())
number = blockNumber + 1
painter.drawText(0,
top,
width,
height,
Qt::AlignRight,
number.to_s)
if @enable_breakpoints and block.userState() == BREAKPOINT_SET
painter.setBrush(Cosmos::RED)
painter.drawEllipse(2,
top+2,
ellipse_width,
ellipse_width)
end
end
next_block = block.next()
block.dispose
block = next_block
top = bottom
rect = blockBoundingRect(block)
bottom = top + rect.height()
rect.dispose
blockNumber += 1
end
block.dispose
block = nil
event_rect.dispose
event_rect = nil
end
painter.dispose
painter = nil
end
|
#resizeEvent(e) ⇒ Object
325
326
327
328
329
330
331
332
333
334
335
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 325
def resizeEvent(e)
super(e)
cr = self.contentsRect()
rect = Qt::Rect.new(cr.left(),
cr.top(),
line_number_area_width(),
cr.height())
@lineNumberArea.setGeometry(rect)
cr.dispose
rect.dispose
end
|
#update_breakpoints ⇒ Object
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 241
def update_breakpoints
return if @breakpoints.empty?
breakpoints = []
block = document.firstBlock()
while (block.isValid())
if block.userState() == BREAKPOINT_SET
line = block.firstLineNumber() + 1
breakpoints << line
end
next_block = block.next()
block.dispose
block = next_block
end
block.dispose
block = nil
if @breakpoints.sort != breakpoints.sort
emit breakpoints_cleared
breakpoints.each {|line| emit breakpoint_set(line)}
@breakpoints = breakpoints
end
end
|
#wheelEvent(event) ⇒ Object
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 180
def wheelEvent(event)
if event.modifiers() == Qt::ControlModifier && event.delta > 0
event.setAccepted(true)
zoom_in()
elsif event.modifiers() == Qt::ControlModifier && event.delta < 0
event.setAccepted(true)
zoom_out()
else
super(event)
end
end
|
#zoom_default ⇒ Object
315
316
317
318
319
320
321
322
323
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 315
def zoom_default
font = Cosmos.get_default_font
setFont(font)
@fontMetrics = Cosmos.getFontMetrics(font)
verticalScrollBar.setValue(verticalScrollBar.minimum+1)
verticalScrollBar.setValue(verticalScrollBar.minimum)
emit font_changed(font)
end
|
300
301
302
303
304
305
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 300
def zoom_in
font = Cosmos.getFont(font().family, font().pointSize + 1)
setFont(font)
@fontMetrics = Cosmos.getFontMetrics(font)
emit font_changed(font)
end
|
307
308
309
310
311
312
313
|
# File 'lib/cosmos/gui/text/ruby_editor.rb', line 307
def zoom_out
return if font().pointSize <= MINIMUM_POINT_SIZE
font = Cosmos.getFont(font().family, font().pointSize - 1)
setFont(font)
@fontMetrics = Cosmos.getFontMetrics(font)
emit font_changed(font)
end
|