From ba3973b2ace0f26bb46c12a7495923fc3b3266d8 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 26 Nov 2012 15:30:24 +0800 Subject: [PATCH] add all zoom modes support to reader menu --- frontend/ui/reader/readermenu.lua | 30 +++++++++++++++-- frontend/ui/reader/readerview.lua | 7 ++-- frontend/ui/reader/readerzooming.lua | 48 +++++++++++++++++++++------- 3 files changed, 69 insertions(+), 16 deletions(-) diff --git a/frontend/ui/reader/readermenu.lua b/frontend/ui/reader/readermenu.lua index 0c778cd9a..17a5c11a3 100644 --- a/frontend/ui/reader/readermenu.lua +++ b/frontend/ui/reader/readermenu.lua @@ -4,6 +4,12 @@ ReaderMenu = InputContainer:new{ }, } +function ReaderMenu:genSetZoomModeCallBack(mode) + return function() + self.ui:handleEvent(Event:new("SetZoomMode", mode)) + end +end + function ReaderMenu:onShowMenu() local item_table = {} @@ -14,14 +20,16 @@ function ReaderMenu:onShowMenu() text = "rotate 90 degree clockwise", callback = function() Screen:screenRotate("clockwise") - self.ui:handleEvent(Event:new("SetDimensions", Screen:getSize())) + self.ui:handleEvent( + Event:new("SetDimensions", Screen:getSize())) end }, { text = "rotate 90 degree anticlockwise", callback = function() Screen:screenRotate("anticlockwise") - self.ui:handleEvent(Event:new("SetDimensions", Screen:getSize())) + self.ui:handleEvent( + Event:new("SetDimensions", Screen:getSize())) end }, } @@ -33,9 +41,27 @@ function ReaderMenu:onShowMenu() sub_item_table = { { text = "Zoom to fit content width", + callback = self:genSetZoomModeCallBack("contentwidth") }, { text = "Zoom to fit content height", + callback = self:genSetZoomModeCallBack("contentheight") + }, + { + text = "Zoom to fit page width", + callback = self:genSetZoomModeCallBack("pagewidth") + }, + { + text = "Zoom to fit page height", + callback = self:genSetZoomModeCallBack("pageheight") + }, + { + text = "Zoom to fit content", + callback = self:genSetZoomModeCallBack("content") + }, + { + text = "Zoom to fit page", + callback = self:genSetZoomModeCallBack("page") }, } }) diff --git a/frontend/ui/reader/readerview.lua b/frontend/ui/reader/readerview.lua index 6f9c1ce94..959d13c9d 100644 --- a/frontend/ui/reader/readerview.lua +++ b/frontend/ui/reader/readerview.lua @@ -56,7 +56,8 @@ end function ReaderView:recalculate() if self.ui.document.info.has_pages then - local page_size = self.ui.document:getPageDimensions(self.state.page, self.state.zoom, self.state.rotation) + local page_size = self.ui.document:getPageDimensions( + self.state.page, self.state.zoom, self.state.rotation) -- TODO: bbox self.page_area = page_size @@ -67,7 +68,7 @@ function ReaderView:recalculate() else self.visible_area:setSizeTo(self.dimen) end - -- flag a repaint + -- flag a repaint so self:paintTo will be called UIManager:setDirty(self.dialog) end @@ -104,7 +105,7 @@ function ReaderView:onPosUpdate(new_pos) self:recalculate() end -function ReaderView:ZoomUpdate(zoom) +function ReaderView:onZoomUpdate(zoom) self.state.zoom = zoom self:recalculate() end diff --git a/frontend/ui/reader/readerzooming.lua b/frontend/ui/reader/readerzooming.lua index 92b88da93..ad891290d 100644 --- a/frontend/ui/reader/readerzooming.lua +++ b/frontend/ui/reader/readerzooming.lua @@ -1,13 +1,37 @@ ReaderZooming = InputContainer:new{ key_events = { - ZoomIn = { { "Shift", Input.group.PgFwd }, doc = "zoom in", event = "Zoom", args = "in" }, - ZoomOut = { { "Shift", Input.group.PgBack }, doc = "zoom out", event = "Zoom", args = "out" }, - ZoomToFitPage = { {"A"}, doc = "zoom to fit page", event = "SetZoomMode", args = "page" }, - ZoomToFitContent = { {"Shift", "A"}, doc = "zoom to fit content", event = "SetZoomMode", args = "content" }, - ZoomToFitPageWidth = { {"S"}, doc = "zoom to fit page width", event = "SetZoomMode", args = "pagewidth" }, - ZoomToFitContentWidth = { {"Shift", "S"}, doc = "zoom to fit content width", event = "SetZoomMode", args = "contentwidth" }, - ZoomToFitPageHeight = { {"D"}, doc = "zoom to fit page height", event = "SetZoomMode", args = "pageheight" }, - ZoomToFitContentHeight = { {"Shift", "D"}, doc = "zoom to fit content height", event = "SetZoomMode", args = "contentheight" }, + ZoomIn = { + { "Shift", Input.group.PgFwd }, + doc = "zoom in", event = "Zoom", args = "in" + }, + ZoomOut = { + { "Shift", Input.group.PgBack }, + doc = "zoom out", event = "Zoom", args = "out" + }, + ZoomToFitPage = { + { "A" }, + doc = "zoom to fit page", event = "SetZoomMode", args = "page" + }, + ZoomToFitContent = { + { "Shift", "A" }, + doc = "zoom to fit content", event = "SetZoomMode", args = "content" + }, + ZoomToFitPageWidth = { + { "S" }, + doc = "zoom to fit page width", event = "SetZoomMode", args = "pagewidth" + }, + ZoomToFitContentWidth = { + { "Shift", "S" }, + doc = "zoom to fit content width", event = "SetZoomMode", args = "contentwidth" + }, + ZoomToFitPageHeight = { + { "D" }, + doc = "zoom to fit page height", event = "SetZoomMode", args = "pageheight" + }, + ZoomToFitContentHeight = { + { "Shift", "D" }, + doc = "zoom to fit content height", event = "SetZoomMode", args = "contentheight" + }, }, zoom = 1.0, zoom_mode = "free", @@ -32,7 +56,9 @@ function ReaderZooming:setZoom() end -- check if we're in bbox mode and work on bbox if that's the case local page_size = {} - if self.zoom_mode == "content" or self.zoom_mode == "contentwidth" or self.zoom_mode == "content_height" then + if self.zoom_mode == "content" + or self.zoom_mode == "contentwidth" + or self.zoom_mode == "contentheight" then -- TODO: enable this, still incomplete page_size = self.ui.document:getUsedBBox(self.current_page) self.view:handleEvent(Event:new("BBoxUpdate", page_size)) @@ -59,7 +85,7 @@ function ReaderZooming:setZoom() elseif self.zoom_mode == "contentheight" or self.zoom_mode == "pageheight" then self.zoom = zoom_h end - self.view:ZoomUpdate(self.zoom) + self.view:onZoomUpdate(self.zoom) end function ReaderZooming:onZoom(direction) @@ -71,7 +97,7 @@ function ReaderZooming:onZoom(direction) end DEBUG("zoom is now at", self.zoom) self:onSetZoomMode("free") - self.view:ZoomUpdate(self.zoom) + self.view:onZoomUpdate(self.zoom) return true end