Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/jldrill/views/gtk/widgets/ProblemDisplay.rb | 175 | 131 | 61.71%
|
51.15%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 require 'jldrill/views/gtk/widgets/ProblemPane' |
2 require 'Context/Views/Gtk/Widgets/VBox' |
3 require 'jldrill/views/gtk/widgets/KanjiPopupFactory' |
4 require 'jldrill/views/gtk/widgets/VocabPopupFactory' |
5 require 'gtk2' |
6 |
7 module JLDrill::Gtk |
8 |
9 # This is the widget that displays the problem. |
10 # The display is made up of 2 pieces: |
11 # the QuestionPane, which shows the question for the problem |
12 # and the AnswerPane which shows the answer. |
13 # The ProblemDisplay also interacts with the PopupFactory |
14 # to display the kanji/kana Popup when hovering over a character. |
15 class ProblemDisplay < Context::Gtk::VBox |
16 attr_reader :question, :answer, :accel |
17 |
18 def initialize(view) |
19 @view = view |
20 @context = @view.context |
21 super() |
22 @vpane = nil |
23 @question = QuestionPane.new(self) |
24 @answer = AnswerPane.new(self) |
25 @problem = nil |
26 @kanjiPopupFactory = KanjiPopupFactory.new(view) |
27 @vocabPopupFactory = VocabPopupFactory.new(view) |
28 # Default to Kanji Popups |
29 @popupFactory = @kanjiPopupFactory |
30 @lastEvent = nil |
31 @accel = Gtk::AccelGroup.new |
32 packVPane |
33 connectSignals |
34 afterWidgetIsAdded do |
35 gtkWidgetMainWindow.add_accel_group(@accel) |
36 end |
37 end |
38 |
39 def removeVPane |
40 if !@vpane.nil? |
41 @vpane.remove(@question) |
42 @vpane.remove(@answer) |
43 self.remove(@vpane) |
44 @vpane = nil |
45 end |
46 end |
47 |
48 def packVPane |
49 @vpane = Gtk::VPaned.new |
50 @vpane.set_border_width(5) |
51 @vpane.pack1(@question, true, true) |
52 @vpane.pack2(@answer, true, true) |
53 self.pack_end(@vpane, true, true) |
54 @vpane.show |
55 end |
56 |
57 def connectSignals |
58 @question.contents.add_events(Gdk::Event::POINTER_MOTION_MASK) |
59 @question.contents.add_events(Gdk::Event::LEAVE_NOTIFY_MASK) |
60 @answer.contents.add_events(Gdk::Event::POINTER_MOTION_MASK) |
61 @answer.contents.add_events(Gdk::Event::LEAVE_NOTIFY_MASK) |
62 |
63 @accel.connect(Gdk::Keyval::GDK_space, 0, Gtk::ACCEL_VISIBLE) do |
64 @popupFactory.closePopup |
65 if @context.dictionaryLoaded? |
66 if @popupFactory == @kanjiPopupFactory |
67 @popupFactory = @vocabPopupFactory |
68 else |
69 @popupFactory = @kanjiPopupFactory |
70 end |
71 if !@lastEvent.nil? |
72 @popupFactory.notify(@lastEvent) |
73 end |
74 end |
75 end |
76 |
77 @question.contents.signal_connect('motion_notify_event') do |widget, motion| |
78 @lastEvent = MotionEvent.new(widget, motion) |
79 @popupFactory.notify(@lastEvent) |
80 end |
81 |
82 @answer.contents.signal_connect('motion_notify_event') do |widget, motion| |
83 @lastEvent = MotionEvent.new(widget, motion) |
84 @popupFactory.notify(@lastEvent) |
85 end |
86 |
87 @question.contents.signal_connect('leave_notify_event') do |
88 @popupFactory.closePopup |
89 end |
90 |
91 @answer.contents.signal_connect('leave_notify_event') do |
92 @popupFactory.closePopup |
93 end |
94 end |
95 |
96 def newProblem(problem) |
97 @popupFactory.closePopup |
98 @problem = problem |
99 @answer.clear(@problem) |
100 @question.update(problem) |
101 adjustSizeForQuestion |
102 end |
103 |
104 # Attempt to adjust the size of the question pane |
105 # to accomodate the size of the question |
106 # Note: This method is in an idle_add block because |
107 # we have to wait until the pane has been redrawn before |
108 # we calculate the size. By putting it in an idle_add |
109 # block we can ensure that the events that draw the pane |
110 # have finished. |
111 def adjustSizeForQuestion |
112 Gtk.idle_add do |
113 pos = @question.bufferSize |
114 # But don't adjust the size unnecessarily |
115 if pos > @vpane.position |
116 @vpane.position = pos |
117 end |
118 false |
119 end |
120 end |
121 |
122 def showAnswer |
123 if !@problem.nil? |
124 @answer.update(@problem) |
125 adjustSizeForAnswer |
126 end |
127 end |
128 |
129 # Try to accomodate the answer size. Always |
130 # keep 10% of the panel for the question, though. |
131 # Note: This method is in an idle_add block because |
132 # we have to wait until the pane has been redrawn before |
133 # we calculate the size. By putting it in an idle_add |
134 # block we can ensure that the events that draw the pane |
135 # have finished. |
136 def adjustSizeForAnswer |
137 Gtk.idle_add do |
138 maxPos = @vpane.max_position |
139 minPos = (maxPos.to_f * 0.10).to_i |
140 pos = maxPos - @answer.bufferSize |
141 if pos < minPos |
142 pos = minPos |
143 end |
144 # Don't adjust the size unnecessarily |
145 if pos < @vpane.position |
146 @vpane.position = pos |
147 end |
148 end |
149 end |
150 |
151 |
152 def expire |
153 if !@problem.nil? |
154 @question.expire |
155 end |
156 end |
157 |
158 def showingAnswer? |
159 !@answer.clear? |
160 end |
161 |
162 def updateProblem(problem) |
163 needToDisplayAnswer = showingAnswer? |
164 newProblem(problem) |
165 if needToDisplayAnswer |
166 showAnswer |
167 end |
168 end |
169 |
170 def expandWithSavePath(filename) |
171 @context.expandWithSavePath(filename) |
172 end |
173 |
174 end |
175 end |
Generated on Mon May 23 16:17:47 +0900 2011 with rcov 0.9.8