From 71d6395fba5885226d2ed7befe5895592b84b993 Mon Sep 17 00:00:00 2001 From: chrox Date: Sat, 20 Jul 2013 02:49:03 +0800 Subject: [PATCH] add Translate button when selecting multiple words --- frontend/ui/reader/readerhighlight.lua | 58 +++++++++++++++++++------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/frontend/ui/reader/readerhighlight.lua b/frontend/ui/reader/readerhighlight.lua index 75c3e5695..95f99c71c 100644 --- a/frontend/ui/reader/readerhighlight.lua +++ b/frontend/ui/reader/readerhighlight.lua @@ -165,22 +165,42 @@ function ReaderHighlight:onHoldPan(arg, ges) end end +function ReaderHighlight:lookup(selected_word) + -- if we extracted text directly + if selected_word.word then + self.ui:handleEvent(Event:new("LookupWord", selected_word.word)) + -- or we will do OCR + else + local word_box = selected_word.box + --word_box.x = word_box.x - math.floor(word_box.h * 0.1) + --word_box.y = word_box.y - math.floor(word_box.h * 0.2) + --word_box.w = word_box.w + math.floor(word_box.h * 0.2) + --word_box.h = word_box.h + math.floor(word_box.h * 0.4) + local word = self.ui.document:getOCRWord(self.hold_pos.page, word_box) + DEBUG("OCRed word:", word) + self.ui:handleEvent(Event:new("LookupWord", word)) + end +end + +function ReaderHighlight:translate(selected_text) + if selected_text.text ~= "" then + self.ui:handleEvent(Event:new("LookupWord", selected_text.text)) + -- or we will do OCR + else + local text_box = selected_text.boxes[1] + --text_box.x = text_box.x - math.floor(text_box.h * 0.1) + text_box.y = text_box.y - math.floor(text_box.h * 0.2) + --text_box.w = text_box.w + math.floor(text_box.h * 0.2) + text_box.h = text_box.h + math.floor(text_box.h * 0.4) + local text = self.ui.document:getOCRWord(self.hold_pos.page, text_box) + DEBUG("OCRed text:", text) + self.ui:handleEvent(Event:new("LookupWord", text)) + end +end + function ReaderHighlight:onHoldRelease(arg, ges) if self.selected_word then - -- if we extracted text directly - if self.selected_word.word then - self.ui:handleEvent(Event:new("LookupWord", self.selected_word.word)) - -- or we will do OCR - else - local word_box = self.selected_word.box - word_box.x = word_box.x - math.floor(word_box.h * 0.1) - word_box.y = word_box.y - math.floor(word_box.h * 0.2) - word_box.w = word_box.w + math.floor(word_box.h * 0.2) - word_box.h = word_box.h + math.floor(word_box.h * 0.4) - local word = self.ui.document:getOCRWord(self.hold_pos.page, word_box) - DEBUG("OCRed word:", word) - self.ui:handleEvent(Event:new("LookupWord", word)) - end + self:lookup(self.selected_word) self.selected_word = nil elseif self.selected_text then DEBUG("show highlight dialog") @@ -206,6 +226,14 @@ function ReaderHighlight:onHoldRelease(arg, ges) }, }, { + { + text = _("Translate"), + callback = function() + self:translate(self.selected_text) + UIManager:close(self.highlight_dialog) + self.ui:handleEvent(Event:new("Tap")) + end, + }, { text = _("Share"), enabled = false, @@ -215,6 +243,8 @@ function ReaderHighlight:onHoldRelease(arg, ges) self.ui:handleEvent(Event:new("Tap")) end, }, + }, + { { text = _("More"), enabled = false,