Class: Qt::PlainTextEdit
Instance Method Summary
collapse
Instance Method Details
#add_formatted_text(text, color = nil) ⇒ Object
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
|
# File 'lib/cosmos/gui/qt.rb', line 431
def add_formatted_text(text, color = nil)
if text =~ /[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F-\xFF]/
text.chomp!
text = text.inspect.remove_quotes
text << "\n"
end
if text =~ /<G>/ or color == Cosmos::GREEN
text.gsub!('<G>', '')
addText(text, Cosmos::GREEN)
elsif text =~ /<Y>/ or color == Cosmos::YELLOW
text.gsub!('<Y>', '')
addText(text, Cosmos::YELLOW)
elsif text =~ /<R>/ or color == Cosmos::RED
text.gsub!('<R>', '')
addText(text, Cosmos::RED)
elsif text =~ /<B>/ or color == Cosmos::BLUE
text.gsub!('<B>', '')
addText(text, Cosmos::BLUE)
else
addText(text) end
end
|
#addText(text, color = Cosmos::BLACK) ⇒ Object
454
455
456
457
458
459
460
461
462
463
|
# File 'lib/cosmos/gui/qt.rb', line 454
def addText(text, color = Cosmos::BLACK)
@current_text = "" if !defined? @current_text or @current_text.nil?
text = text.gsub("&", "&")
text.gsub!("\n", '')
text.gsub!(' ', ' ')
text.gsub!(">", ">")
text.gsub!("<", "<")
rgb_color = "#%02X%02X%02X" % [color.red, color.green, color.blue]
@current_text +="<font color=\"#{rgb_color}\">#{text}</font><br/>"
end
|
#appendText(text, color = Cosmos::BLACK) ⇒ Object
470
471
472
473
474
475
476
477
478
479
|
# File 'lib/cosmos/gui/qt.rb', line 470
def appendText(text, color = Cosmos::BLACK)
text = text.chomp
text.gsub!(/\n/, '<br/>') text.gsub!("&", "&")
text.gsub!(' ', ' ')
text.gsub!(">", ">")
text.gsub!("<", "<")
rgb_color = "#%02X%02X%02X" % [color.red, color.green, color.blue]
appendHtml("<font color=\"#{rgb_color}\">#{text}</font>")
end
|
465
466
467
468
|
# File 'lib/cosmos/gui/qt.rb', line 465
def flush
appendHtml(@current_text)
@current_text = nil
end
|
#selected_lines ⇒ Object
Return the selected lines. If a partial line is selected the entire line will be returned. If there is no selection the line with the cursor will be returned
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
|
# File 'lib/cosmos/gui/qt.rb', line 483
def selected_lines
cursor = textCursor
selection_end = cursor.selectionEnd
cursor.setPosition(textCursor.selectionStart)
cursor.movePosition(Qt::TextCursor::StartOfLine)
cursor.setPosition(selection_end, Qt::TextCursor::KeepAnchor)
unless (cursor.atBlockStart and textCursor.hasSelection)
cursor.movePosition(Qt::TextCursor::EndOfLine, Qt::TextCursor::KeepAnchor)
end
return nil if cursor.selectedText.nil?
cursor.selection.toPlainText
end
|
#selection_end_line ⇒ Object
Return the line number (0 based) of the selection end
520
521
522
523
524
|
# File 'lib/cosmos/gui/qt.rb', line 520
def selection_end_line
cursor = textCursor
cursor.setPosition(textCursor.selectionEnd)
cursor.blockNumber
end
|
#selection_start_line ⇒ Object
Return the line number (0 based) of the selection start
513
514
515
516
517
|
# File 'lib/cosmos/gui/qt.rb', line 513
def selection_start_line
cursor = textCursor
cursor.setPosition(textCursor.selectionStart)
cursor.blockNumber
end
|