Class: Ruber::ExceptionDialog::ExceptionBacktraceWidget
- Inherits:
-
KDE::TextEdit
- Object
- KDE::TextEdit
- Ruber::ExceptionDialog::ExceptionBacktraceWidget
- Defined in:
- lib/ruber/exception_widgets.rb
Overview
Subclass of @KDE::TextEdit@ specialized in displaying the backtrace of an exception.
The differences with a standard @KDE::TextEdit@ are:
-
automatically uses a fixed width font
-
doesn’t use word wrapping
-
is always read-only
-
its #size_hint method computes (or at least tries to compute) width and height so that each line of the backtrace fits on a single line.
-
automatically extracts the message and the backtrace from the exception
Instance Method Summary collapse
-
#initialize(ex, parent = nil) ⇒ ExceptionBacktraceWidget
constructor
A new instance of ExceptionBacktraceWidget.
-
#sizeHint ⇒ Qt::Size
Override of @KDE::TextEdit#sizeHint@.
Constructor Details
#initialize(ex, parent = nil) ⇒ ExceptionBacktraceWidget
Returns a new instance of ExceptionBacktraceWidget.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ruber/exception_widgets.rb', line 50 def initialize ex, parent = nil super parent self.line_wrap_mode = NoWrap self.read_only = true #Replace < and > with the corresponding HTML entities in the message msg = ex..gsub(/[<>]/){|s| s == '<' ? '<' : '>'} #Replace < and > with the corresponding HTML entities in the backtrace backtrace = ex.backtrace.map{|l| l.gsub(/[<>]/){|s| s == '<' ? '<' : '>'}} text = "<tt>#{msg}<br/>#{backtrace.join '<br/>'}</tt>" self.html = text end |
Instance Method Details
#sizeHint ⇒ Qt::Size
Override of @KDE::TextEdit#sizeHint@
The width is computed as the size (using the fixed width font) of the longest line, while the height is computed as the height of a single line multiplied by the number of lines.
Both width and height are computed using @Qt::FontMetrics@
73 74 75 76 77 78 79 |
# File 'lib/ruber/exception_widgets.rb', line 73 def sizeHint font = Qt::TextCursor.new(document).char_format.font fm = Qt::FontMetrics.new font lines = to_plain_text.split_lines longest = lines.sort_by{|l| l.size}[-1] Qt::Size.new fm.width(longest), fm.height * lines.size end |