From 1329f10fa544fcd63c1b13326d91c49884f37982 Mon Sep 17 00:00:00 2001 From: chrox Date: Wed, 15 Jan 2014 23:34:37 +0800 Subject: [PATCH 1/4] add goto link function for CreDocument --- frontend/document/credocument.lua | 19 +++++++++++++++++++ frontend/ui/reader/readerrolling.lua | 28 ++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index 84c050d20..688bcd10e 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -202,6 +202,10 @@ function CreDocument:getCurrentPos() return self._document:getCurrentPos() end +function CreDocument:getPageLinks() + return self._document:getPageLinks() +end + function Document:gotoPos(pos) DEBUG("CreDocument: goto position", pos) self._document:gotoPos(pos) @@ -212,6 +216,21 @@ function CreDocument:gotoPage(page) self._document:gotoPage(page) end +function CreDocument:gotoLink(link) + DEBUG("CreDocument: goto link", link) + self._document:gotoLink(link) +end + +function CreDocument:goBack() + DEBUG("CreDocument: go back") + self._document:goBack() +end + +function CreDocument:goForward(link) + DEBUG("CreDocument: go forward") + self._document:goForward() +end + function CreDocument:getCurrentPage() return self._document:getCurrentPage() end diff --git a/frontend/ui/reader/readerrolling.lua b/frontend/ui/reader/readerrolling.lua index c915dc213..67b716de1 100644 --- a/frontend/ui/reader/readerrolling.lua +++ b/frontend/ui/reader/readerrolling.lua @@ -183,10 +183,12 @@ function ReaderRolling:onTapBackward() end function ReaderRolling:onSwipe(arg, ges) - if ges.direction == "west" or ges.direction == "north" then - self:onGotoViewRel(1) - elseif ges.direction == "east" or ges.direction == "south" then - self:onGotoViewRel(-1) + if ges.direction == "west" then + self.ui.document:goForward() + self:onUpdateXPointer() + elseif ges.direction == "east" then + self.ui.document:goBack() + self:onUpdateXPointer() end return true end @@ -204,11 +206,13 @@ end function ReaderRolling:onPosUpdate(new_pos) self.current_pos = new_pos + self:updatePageLink() self:updateBatteryState() end function ReaderRolling:onPageUpdate(new_page) self.current_page = new_page + self:updatePageLink() self:updateBatteryState() end @@ -273,6 +277,16 @@ function ReaderRolling:updatePos() UIManager.repaint_all = true end +function ReaderRolling:onUpdateXPointer() + local xp = self.ui.document:getXPointer() + if self.view.view_mode == "page" then + self.ui:handleEvent(Event:new("PageUpdate", self.ui.document:getPageFromXPointer(xp))) + else + self.ui:handleEvent(Event:new("PosUpdate", self.ui.document:getPosFromXPointer(xp))) + end + return true +end + function ReaderRolling:onChangeViewMode() self.ui.document:_readMetadata() self.old_doc_height = self.ui.document.info.doc_height @@ -347,6 +361,12 @@ function ReaderRolling:onGotoPage(number) return true end +function ReaderRolling:updatePageLink() + DEBUG("update page link") + local links = self.ui.document:getPageLinks() + self.view.links = links +end + function ReaderRolling:updateBatteryState() DEBUG("update battery state") if self.view.view_mode == "page" then From bcf2a1994f16306e4efc62663451af375a3f8c68 Mon Sep 17 00:00:00 2001 From: chrox Date: Wed, 15 Jan 2014 23:35:26 +0800 Subject: [PATCH 2/4] refactoring widget registering in readerui --- frontend/ui/readerui.lua | 137 +++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 72 deletions(-) diff --git a/frontend/ui/readerui.lua b/frontend/ui/readerui.lua index dbbe9228d..3ddeac0cf 100644 --- a/frontend/ui/readerui.lua +++ b/frontend/ui/readerui.lua @@ -30,6 +30,7 @@ local ReaderFrontLight = require("ui/reader/readerfrontlight") local ReaderDictionary = require("ui/reader/readerdictionary") local ReaderHyphenation = require("ui/reader/readerhyphenation") local ReaderActivityIndicator = require("ui/reader/readeractivityindicator") +local ReaderLink = require("ui/reader/readerlink") --[[ This is an abstraction for a reader interface @@ -82,41 +83,46 @@ function ReaderUI:init() ui = self, document = self.document, } - -- rotation controller - self[2] = ReaderRotation:new{ - dialog = self.dialog, - view = self[1], - ui = self - } - -- reader menu controller - self[3] = ReaderMenu:new{ - view = self[1], - ui = self - } - self.menu = self[3] -- hold reference to menu widget - -- Table of content controller - self[4] = ReaderToc:new{ - dialog = self.dialog, - view = self[1], - ui = self - } - self.toc = self[4] -- hold reference to bm widget - -- bookmark controller - local reader_bm = ReaderBookmark:new{ - dialog = self.dialog, - view = self[1], - ui = self - } - table.insert(self, reader_bm) - -- text highlight - local highlight = ReaderHighlight:new{ + -- link + table.insert(self, ReaderLink:new{ dialog = self.dialog, view = self[1], ui = self, document = self.document, + }) + -- text highlight + table.insert(self, ReaderHighlight:new{ + dialog = self.dialog, + view = self[1], + ui = self, + document = self.document, + }) + -- rotation controller + table.insert(self, ReaderRotation:new{ + dialog = self.dialog, + view = self[1], + ui = self + }) + -- reader menu controller + self.menu = ReaderMenu:new{ + view = self[1], + ui = self } - table.insert(self, highlight) - -- goto + table.insert(self, self.menu) -- hold reference to menu widget + -- Table of content controller + self.toc = ReaderToc:new{ + dialog = self.dialog, + view = self[1], + ui = self + } + table.insert(self, self.toc) -- hold reference to bm widget + -- bookmark controller + table.insert(self, ReaderBookmark:new{ + dialog = self.dialog, + view = self[1], + ui = self + }) + -- reader goto controller table.insert(self, ReaderGoto:new{ dialog = self.dialog, view = self[1], @@ -124,20 +130,18 @@ function ReaderUI:init() document = self.document, }) -- dictionary - local dict = ReaderDictionary:new{ + table.insert(self, ReaderDictionary:new{ dialog = self.dialog, view = self[1], ui = self, document = self.document, - } - table.insert(self, dict) + }) -- screenshot controller - local reader_ss = ReaderScreenshot:new{ + table.insert(self.active_widgets, ReaderScreenshot:new{ dialog = self.dialog, view = self[1], ui = self - } - table.insert(self.active_widgets, reader_ss) + }) -- frontlight controller if Device:hasFrontlight() then table.insert(self, ReaderFrontLight:new{ @@ -149,117 +153,106 @@ function ReaderUI:init() -- configuable controller if self.document.info.configurable then -- config panel controller - local config_dialog = ReaderConfig:new{ + table.insert(self, ReaderConfig:new{ configurable = self.document.configurable, options = self.document.options, dialog = self.dialog, view = self[1], ui = self - } - table.insert(self, config_dialog) + }) if not self.document.info.has_pages then -- cre option controller - local coptlistener = ReaderCoptListener:new{ + table.insert(self, ReaderCoptListener:new{ dialog = self.dialog, view = self[1], ui = self, document = self.document, - } - table.insert(self, coptlistener) + }) end end -- for page specific controller if self.document.info.has_pages then -- if needed, insert a paging container - local pager = ReaderPaging:new{ + table.insert(self, ReaderPaging:new{ dialog = self.dialog, view = self[1], ui = self - } - table.insert(self, pager) + }) -- zooming controller - local zoomer = ReaderZooming:new{ + self.zoom = ReaderZooming:new{ dialog = self.dialog, view = self[1], ui = self } - table.insert(self, zoomer) + table.insert(self, self.zoom) -- hold reference to zoom controller -- panning controller - local panner = ReaderPanning:new{ + table.insert(self, ReaderPanning:new{ dialog = self.dialog, view = self[1], ui = self - } - table.insert(self, panner) + }) -- cropping controller - local cropper = ReaderCropping:new{ + table.insert(self, ReaderCropping:new{ dialog = self.dialog, view = self[1], ui = self, document = self.document, - } - table.insert(self, cropper) + }) -- hinting controller - local hinter = ReaderHinting:new{ + table.insert(self, ReaderHinting:new{ dialog = self.dialog, - zoom = zoomer, + zoom = self.zoom, view = self[1], ui = self, document = self.document, - } - table.insert(self, hinter) + }) else -- make sure we load document first before calling any callback table.insert(self.postInitCallback, function() self.document:loadDocument() end) -- typeset controller - local typeset = ReaderTypeset:new{ + table.insert(self, ReaderTypeset:new{ dialog = self.dialog, view = self[1], ui = self - } - table.insert(self, typeset) + }) -- font menu - local font_menu = ReaderFont:new{ + table.insert(self, ReaderFont:new{ dialog = self.dialog, view = self[1], ui = self - } - table.insert(self, font_menu) + }) table.insert(self, ReaderHyphenation:new{ dialog = self.dialog, view = self[1], ui = self }) -- rolling controller - local roller = ReaderRolling:new{ + table.insert(self, ReaderRolling:new{ dialog = self.dialog, view = self[1], ui = self - } - table.insert(self, roller) + }) end -- configuable controller if self.document.info.configurable then if self.document.info.has_pages then -- kopt option controller - local koptlistener = ReaderKoptListener:new{ + table.insert(self, ReaderKoptListener:new{ dialog = self.dialog, view = self[1], ui = self, document = self.document, - } - table.insert(self, koptlistener) + }) end -- activity indicator - local activity_listener = ReaderActivityIndicator:new{ + table.insert(self, ReaderActivityIndicator:new{ dialog = self.dialog, view = self[1], ui = self, document = self.document, - } - table.insert(self, activity_listener) + }) end --DEBUG(self.doc_settings) -- we only read settings after all the widgets are initialized From 6f3c538dc2f069e447647186228f005855b618b2 Mon Sep 17 00:00:00 2001 From: chrox Date: Wed, 15 Jan 2014 23:36:00 +0800 Subject: [PATCH 3/4] update koreader-base --- koreader-base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koreader-base b/koreader-base index c4c24367d..d73713f8b 160000 --- a/koreader-base +++ b/koreader-base @@ -1 +1 @@ -Subproject commit c4c24367d29bf1862b0d5f8858b318a03d0a1ce6 +Subproject commit d73713f8b88acf02c6eb6057363e7a42586862a5 From 319403b6954341248cd9c8e85383250268ba5508 Mon Sep 17 00:00:00 2001 From: chrox Date: Wed, 15 Jan 2014 23:36:47 +0800 Subject: [PATCH 4/4] add missing readerlink widget --- frontend/ui/reader/readerlink.lua | 71 +++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 frontend/ui/reader/readerlink.lua diff --git a/frontend/ui/reader/readerlink.lua b/frontend/ui/reader/readerlink.lua new file mode 100644 index 000000000..9e135fed3 --- /dev/null +++ b/frontend/ui/reader/readerlink.lua @@ -0,0 +1,71 @@ +local InputContainer = require("ui/widget/container/inputcontainer") +local GestureRange = require("ui/gesturerange") +local Geom = require("ui/geometry") +local Screen = require("ui/screen") +local Device = require("ui/device") +local Event = require("ui/event") +local DEBUG = require("dbg") + +local ReaderLink = InputContainer:new{} + +function ReaderLink:init() + if Device:isTouchDevice() then + self:initGesListener() + end +end + +function ReaderLink:initGesListener() + if Device:isTouchDevice() then + self.ges_events = { + Tap = { + GestureRange:new{ + ges = "tap", + range = Geom:new{ + x = 0, y = 0, + w = Screen:getWidth(), + h = Screen:getHeight() + } + } + }, + } + end +end + +function ReaderLink:onSetDimensions(dimen) + -- update listening according to new screen dimen + if Device:isTouchDevice() then + self:initGesListener() + end +end + +function ReaderLink:onTap(arg, ges) + local function inside_box(pos, box) + if pos then + local x, y = pos.x, pos.y + if box.x <= x and box.y <= y + and box.x + box.w >= x + and box.y + box.h >= y then + return true + end + end + end + if self.view.links then + local pos = self.view:screenToPageTransform(ges.pos) + for i = 1, #self.view.links do + local link = self.view.links[i] + local lbox = Geom:new{ + x = link.start_x, y = link.start_y, + w = link.end_x - link.start_x, + h = link.end_y - link.start_y > 0 and link.end_y - link.start_y or 30, + } + if inside_box(pos, lbox) then + DEBUG("goto link", link) + self.document:gotoLink(link.section) + self.ui:handleEvent(Event:new("UpdateXPointer")) + return true + end + end + end +end + +return ReaderLink