Merge pull request #431 from chrox/master

fix adding coptlistener in pdf/djvu reader
pull/440/head
Qingping Hou 11 years ago
commit db27d61833

@ -42,6 +42,10 @@ DSHOWHIDDENFILES = false
-- default to false
DSHOWFILESIZE = false
-- landscape clockwise rotation
-- default to true, set to false for counterclockwise rotation
DLANDSCAPE_CLOCKWISE_ROTATION = true
-- customizable tap zones(rectangles)
-- x: x coordinate of top left corner in proportion of screen width
-- y: y coordinate of top left corner in proportion of screen height

@ -3,6 +3,7 @@ local CreOptions = require("ui/data/creoptions")
local Document = require("document/document")
local Configurable = require("ui/reader/configurable")
local Font = require("ui/font")
local Device = require("ui/device")
local Screen = require("ui/screen")
local DEBUG = require("dbg")
-- TBD: DrawContext
@ -117,6 +118,9 @@ function CreDocument:loadDocument()
if not self.info.has_pages then
self.info.doc_height = self._document:getFullHeight()
end
if Device:getModel() ~= "KindleDXG" then
self:setVisiblePageCount(1)
end
end
function CreDocument:close()

@ -23,6 +23,7 @@ local CreOptions = {
name = "screen_mode",
name_text = S.SCREEN_MODE,
toggle = {S.PORTRAIT, S.LANDSCAPE},
alternate = false,
args = {"portrait", "landscape"},
default_arg = "portrait",
current_func = function() return Screen:getScreenMode() end,
@ -36,9 +37,10 @@ local CreOptions = {
{
name = "line_spacing",
name_text = S.LINE_SPACING,
item_text = {S.DECREASE, S.INCREASE},
toggle = {S.DECREASE, S.INCREASE},
alternate = false,
args = {"decrease", "increase"},
default_arg = nil,
default_arg = "decrease",
event = "ChangeLineSpace",
},
{
@ -82,19 +84,17 @@ local CreOptions = {
{
name = "font_weight",
name_text = S.FONT_WEIGHT,
item_text = {S.TOGGLE_BOLD},
-- args is indeed not used, we put here just to keep the
-- UI happy.
args = {1},
toggle = {S.TOGGLE_BOLD},
default_arg = nil,
event = "ToggleFontBolder",
},
{
name = "font_gamma",
name_text = S.GAMMA,
item_text = {S.DECREASE, S.INCREASE},
toggle = {S.DECREASE, S.INCREASE},
alternate = false,
args = {"decrease", "increase"},
default_arg = nil,
default_arg = "increase",
event = "ChangeFontGamma",
}
}

@ -116,7 +116,7 @@ function Screen:setScreenMode(mode)
end
elseif mode == "landscape" then
if self.cur_rotation_mode == 0 or self.cur_rotation_mode == 2 then
self:setRotationMode(1)
self:setRotationMode(DLANDSCAPE_CLOCKWISE_ROTATION and 1 or 3)
elseif self.cur_rotation_mode == 1 or self.cur_rotation_mode == 3 then
self:setRotationMode((self.cur_rotation_mode + 2) % 4)
end

@ -163,4 +163,42 @@ function ReaderBookmark:toggleBookmark(pn_or_xp)
self:addBookmark(pn_or_xp)
end
function ReaderBookmark:getPreviousBookmarkedPage(pn_or_xp)
for i = #self.bookmarks, 1, -1 do
if pn_or_xp > self.bookmarks[i].page then
return self.bookmarks[i].page
end
end
end
function ReaderBookmark:getNextBookmarkedPage(pn_or_xp)
for i = 1, #self.bookmarks do
if pn_or_xp < self.bookmarks[i].page then
return self.bookmarks[i].page
end
end
end
function ReaderBookmark:onGotoPreviousBookmark(pn_or_xp)
self:GotoBookmark(self:getPreviousBookmarkedPage(pn_or_xp))
return true
end
function ReaderBookmark:onGotoNextBookmark(pn_or_xp)
self:GotoBookmark(self:getNextBookmarkedPage(pn_or_xp))
return true
end
function ReaderBookmark:GotoBookmark(pn_or_xp)
if type(pn_or_xp) == "string" then
if self.view.view_mode == "page" then
self.ui:handleEvent(Event:new("PageUpdate", self.ui.document:getPageFromXPointer(pn_or_xp)))
else
self.ui:handleEvent(Event:new("PosUpdate", self.ui.document:getPosFromXPointer(pn_or_xp)))
end
elseif type(pn_or_xp) == "number" then
self.ui:handleEvent(Event:new("PageUpdate", pn_or_xp))
end
end
return ReaderBookmark

@ -29,6 +29,17 @@ function ReaderDogear:init()
h = Screen:getHeight()*DTAP_ZONE_BOOKMARK.h
}
}
},
Hold = {
GestureRange:new{
ges = "hold",
range = Geom:new{
x = Screen:getWidth()*DTAP_ZONE_BOOKMARK.x,
y = Screen:getHeight()*DTAP_ZONE_BOOKMARK.y,
w = Screen:getWidth()*DTAP_ZONE_BOOKMARK.w,
h = Screen:getHeight()*DTAP_ZONE_BOOKMARK.h
}
}
}
}
end
@ -39,6 +50,11 @@ function ReaderDogear:onTap()
return true
end
function ReaderDogear:onHold()
self.ui:handleEvent(Event:new("ToggleBookmarkFlipping"))
return true
end
function ReaderDogear:onSetDogearVisibility(visible)
self.view.dogear_visible = visible
return true

@ -37,7 +37,7 @@ function ReaderFlipping:init()
end
function ReaderFlipping:onTap()
self.ui:handleEvent(Event:new("ToggleFlipping"))
self.ui:handleEvent(Event:new("TogglePageFlipping"))
return true
end

@ -18,6 +18,9 @@ local ReaderPaging = InputContainer:new{
page_area = nil,
show_overlap_enable = nil,
overlap = Screen:scaleByDPI(20),
page_flipping_mode = false,
bookmark_flipping_mode = false,
flip_steps = {0,1,2,5,10,20,50,100}
}
@ -145,7 +148,11 @@ end
function ReaderPaging:addToMainMenu(tab_item_table)
if self.ui.document.info.has_pages then
table.insert(tab_item_table.typeset, {
text = _("Toggle page overlap"),
text_func = function()
return self.show_overlap_enable and
_("Turn off page overlap") or
_("Turn on page overlap")
end,
callback = function()
self.show_overlap_enable = not self.show_overlap_enable
end
@ -186,12 +193,12 @@ function ReaderPaging:onTapBackward()
return true
end
function ReaderPaging:onToggleFlipping()
function ReaderPaging:onTogglePageFlipping()
self.view.flipping_visible = not self.view.flipping_visible
self.flipping_mode = self.view.flipping_visible
self.page_flipping_mode = self.view.flipping_visible
self.flipping_page = self.current_page
if self.flipping_mode then
if self.page_flipping_mode then
self:updateOriginalPage(self.current_page)
self:enterFlippingMode()
else
@ -199,8 +206,30 @@ function ReaderPaging:onToggleFlipping()
self:exitFlippingMode()
end
self.view:resetLayout()
self.ui:handleEvent(Event:new("SetFlippingMode", self.flipping_mode))
self.ui:handleEvent(Event:new("SetHinting", not self.flipping_mode))
self.ui:handleEvent(Event:new("SetHinting", not self.page_flipping_mode))
self.ui:handleEvent(Event:new("ReZoom"))
UIManager:setDirty(self.view.dialog, "partial")
end
function ReaderPaging:onToggleBookmarkFlipping()
self.bookmark_flipping_mode = not self.bookmark_flipping_mode
if self.bookmark_flipping_mode then
self.orig_flipping_mode = self.view.flipping_visible
self.orig_dogear_mode = self.view.dogear_visible
self.view.flipping_visible = true
self.view.dogear_visible = true
self.bm_flipping_orig_page = self.current_page
self:enterFlippingMode()
else
self.view.flipping_visible = self.orig_flipping_mode
self.view.dogear_visible = self.orig_dogear_mode
self:exitFlippingMode()
self:gotoPage(self.bm_flipping_orig_page)
end
self.view:resetLayout()
self.ui:handleEvent(Event:new("SetHinting", not self.bookmark_flipping_mode))
self.ui:handleEvent(Event:new("ReZoom"))
UIManager:setDirty(self.view.dialog, "partial")
end
@ -239,7 +268,7 @@ function ReaderPaging:updateFlippingPage(page)
self.flipping_page = page
end
function ReaderPaging:flipping(flipping_page, flipping_ges)
function ReaderPaging:pageFlipping(flipping_page, flipping_ges)
local whole = self.number_of_pages
local steps = #self.flip_steps
local stp_proportion = flipping_ges.distance / Screen:getWidth()
@ -256,9 +285,20 @@ function ReaderPaging:flipping(flipping_page, flipping_ges)
UIManager:setDirty(self.view.dialog, "partial")
end
function ReaderPaging:bookmarkFlipping(flipping_page, flipping_ges)
if flipping_ges.direction == "east" then
self.ui:handleEvent(Event:new("GotoPreviousBookmark", flipping_page))
elseif flipping_ges.direction == "west" then
self.ui:handleEvent(Event:new("GotoNextBookmark", flipping_page))
end
UIManager:setDirty(self.view.dialog, "partial")
end
function ReaderPaging:onSwipe(arg, ges)
if self.flipping_mode then
self:flipping(self.flipping_page, ges)
if self.bookmark_flipping_mode then
self:bookmarkFlipping(self.current_page, ges)
elseif self.page_flipping_mode then
self:pageFlipping(self.flipping_page, ges)
self:updateFlippingPage(self.current_page)
elseif ges.direction == "west" then
self:onPagingRel(1)
@ -277,9 +317,11 @@ function ReaderPaging:onTwoFingerSwipe(arg, ges)
end
function ReaderPaging:onPan(arg, ges)
if self.flipping_mode then
if self.bookmark_flipping_mode then
return true
elseif self.page_flipping_mode then
if self.view.zoom_mode == "page" then
self:flipping(self.flipping_page, ges)
self:pageFlipping(self.flipping_page, ges)
else
self.view:PanningStart(-ges.relative.x, -ges.relative.y)
end
@ -291,7 +333,7 @@ function ReaderPaging:onPan(arg, ges)
end
function ReaderPaging:onPanRelease(arg, ges)
if self.flipping_mode then
if self.page_flipping_mode then
if self.view.zoom_mode == "page" then
self:updateFlippingPage(self.current_page)
else
@ -709,7 +751,7 @@ end
-- wrapper for bounds checking
function ReaderPaging:gotoPage(number, orig)
if number == self.current_page then
if number == self.current_page or not number then
return true
end
if number > self.number_of_pages

@ -268,6 +268,7 @@ function ReaderRolling:updatePos()
self.old_page = new_page
self.ui:handleEvent(Event:new("UpdateToc"))
end
UIManager.repaint_all = true
end
function ReaderRolling:onChangeViewMode()

@ -128,7 +128,11 @@ function ReaderTypeset:addToMainMenu(tab_item_table)
sub_item_table = self:genStyleSheetMenu(),
})
table.insert(tab_item_table.typeset, {
text = _("Toggle floating punctuation"),
text_func = function()
return self.floating_punctuation == 1 and
_("Turn off floating punctuation") or
_("Turn on floating punctuation")
end,
callback = function () self:toggleFloatingPunctuation() end,
})
end

@ -157,14 +157,16 @@ function ReaderUI:init()
ui = self
}
table.insert(self, config_dialog)
-- cre option controller
local coptlistener = ReaderCoptListener:new{
dialog = self.dialog,
view = self[1],
ui = self,
document = self.document,
}
table.insert(self, coptlistener)
if not self.document.info.has_pages then
-- cre option controller
local coptlistener = 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
@ -207,9 +209,6 @@ function ReaderUI:init()
}
table.insert(self, hinter)
else
if Device:getModel() ~= "KindleDXG" then
self.document:setVisiblePageCount(1)
end
-- make sure we load document first before calling any callback
table.insert(self.postInitCallback, function()
self.document:loadDocument()
@ -243,14 +242,16 @@ function ReaderUI:init()
end
-- configuable controller
if self.document.info.configurable then
-- kopt option controller
local koptlistener = ReaderKoptListener:new{
dialog = self.dialog,
view = self[1],
ui = self,
document = self.document,
}
table.insert(self, koptlistener)
if self.document.info.has_pages then
-- kopt option controller
local koptlistener = 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{
dialog = self.dialog,

@ -96,26 +96,8 @@ function OptionTextItem:onTapSelect()
item[1].color = 0
end
self[1].color = 15
local option_value = nil
local option_arg = nil
if self.values then
self.values = self.values or {}
option_value = self.values[self.current_item]
self.config:onConfigChoice(self.name, option_value)
end
if self.event then
self.args = self.args or {}
option_arg = self.args[self.current_item]
self.config:onConfigEvent(self.event, option_arg)
end
if self.events then
for i=0,#self.events do
self.events[i].args = self.events[i].args or {}
option_arg = self.events[i].args[self.current_item]
self.config:onConfigEvent(self.events[i].event, option_arg)
end
end
UIManager.repaint_all = true
self.config:onConfigChoose(self.values, self.name, self.event, self.args, self.events, self.current_item)
UIManager:setDirty(self.config, "partial")
return true
end
@ -148,16 +130,8 @@ function OptionIconItem:onTapSelect()
end
--self[1][1].invert = true
self[1].color = 15
local option_value = nil
local option_arg = nil
if type(self.values) == "table" then
option_value = self.values[self.current_item]
self.config:onConfigChoice(self.name, option_value, self.event)
elseif type(self.args) == "table" then
option_arg = self.args[self.current_item]
self.config:onConfigChoice(self.name, option_arg, self.event)
end
UIManager.repaint_all = true
self.config:onConfigChoose(self.values, self.name, self.event, self.args, self.events, self.current_item)
UIManager:setDirty(self.config, "partial")
return true
end
@ -500,7 +474,6 @@ function ConfigDialog:onConfigChoice(option_name, option_value)
--DEBUG("config option value", option_name, option_value)
self.configurable[option_name] = option_value
self.ui:handleEvent(Event:new("StartActivityIndicator"))
self:closeDialog()
return true
end
@ -510,6 +483,31 @@ function ConfigDialog:onConfigEvent(option_event, option_arg)
return true
end
function ConfigDialog:onConfigEvents(option_events, arg_index)
--DEBUG("config option events", option_events, arg_index)
for i=1, #option_events do
option_events[i].args = option_events[i].args or {}
self.ui:handleEvent(Event:new(option_events[i].event, option_events[i].args[arg_index]))
end
return true
end
function ConfigDialog:onConfigChoose(values, name, event, args, events, position)
UIManager:scheduleIn(0.05, function()
if values then
self:onConfigChoice(name, values[position])
end
if event then
args = args or {}
self:onConfigEvent(event, args[position])
end
if events then
self:onConfigEvents(events, position)
end
UIManager.repaint_all = true
end)
end
function ConfigDialog:closeDialog()
UIManager:close(self)
if self.close_callback then

@ -103,6 +103,8 @@ function ToggleSwitch:togglePosition(position)
if self.n_pos == 2 and self.alternate ~= false then
self.position = (self.position+1)%self.n_pos
self.position = self.position == 0 and self.n_pos or self.position
elseif self.n_pos == 1 then
self.position = self.position == 1 and 0 or 1
else
self.position = position
end
@ -115,26 +117,22 @@ function ToggleSwitch:onTapSelect(arg, gev)
)
--DEBUG("toggle position:", position)
self:togglePosition(position)
local option_value = nil
local option_arg = nil
--[[
if self.values then
self.values = self.values or {}
option_value = self.values[self.position]
self.config:onConfigChoice(self.name, option_value)
self.config:onConfigChoice(self.name, self.values[self.position])
end
if self.event then
self.args = self.args or {}
option_arg = self.args[self.position]
self.config:onConfigEvent(self.event, option_arg)
self.config:onConfigEvent(self.event, self.args[self.position])
end
if self.events then
for i=1,#self.events do
self.events[i].args = self.events[i].args or {}
option_arg = self.events[i].args[self.position]
self.config:onConfigEvent(self.events[i].event, option_arg)
end
self.config:onConfigEvents(self.events, self.position)
end
UIManager.repaint_all = true
--]]
self.config:onConfigChoose(self.values, self.name, self.event, self.args, self.events, self.position)
UIManager:setDirty(self.config, "partial")
return true
end
return ToggleSwitch

@ -49,7 +49,7 @@ function TouchMenuItem:init()
align = "center",
HorizontalSpan:new{ width = 10 },
TextWidget:new{
text = self.item.text,
text = self.item.text or self.item.text_func(),
face = self.face,
},
},
@ -393,9 +393,9 @@ function TouchMenu:onPrevPage()
end
function TouchMenu:onSwipe(arg, ges_ev)
if ges_ev.direction == "west" then
if ges_ev.direction == "west" or ges_ev.direction == "north" then
self:onNextPage()
elseif ges_ev.direction == "east" then
elseif ges_ev.direction == "east" or ges_ev.direction == "south" then
self:onPrevPage()
end
end

Loading…
Cancel
Save