add all zoom modes support to reader menu

pull/2/merge
Qingping Hou 12 years ago
parent cf3cc65c03
commit ba3973b2ac

@ -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")
},
}
})

@ -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

@ -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

Loading…
Cancel
Save