2
0
mirror of https://github.com/koreader/koreader synced 2024-11-10 01:10:34 +00:00
koreader/frontend/ui/readerui.lua

268 lines
6.2 KiB
Lua
Raw Normal View History

require "ui/reader/readerview"
require "ui/reader/readerzooming"
require "ui/reader/readerpanning"
require "ui/reader/readerrotation"
require "ui/reader/readerpaging"
2012-06-05 07:23:36 +00:00
require "ui/reader/readerrolling"
2012-05-27 11:47:22 +00:00
require "ui/reader/readertoc"
require "ui/reader/readerbookmark"
2012-06-12 09:42:02 +00:00
require "ui/reader/readerfont"
2013-01-17 22:12:50 +00:00
require "ui/reader/readertypeset"
require "ui/reader/readermenu"
require "ui/reader/readerconfig"
require "ui/reader/readercropping"
require "ui/reader/readerkopt"
require "ui/reader/readercopt"
require "ui/reader/readerhinting"
require "ui/reader/readerhighlight"
require "ui/reader/readerscreenshot"
require "ui/reader/readerfrontlight"
require "ui/reader/readerdictionary"
2013-04-16 17:11:28 +00:00
require "ui/reader/readerhyphenation"
require "ui/reader/readeractivityindicator"
--[[
This is an abstraction for a reader interface
it works using data gathered from a document interface
]]--
ReaderUI = InputContainer:new{
key_events = {
2013-04-08 07:21:59 +00:00
Close = { { "Home" },
doc = _("close document"), event = "Close" },
},
active_widgets = {},
-- our own size
dimen = Geom:new{ w = 400, h = 600 },
-- if we have a parent container, it must be referenced for now
dialog = nil,
-- the document interface
document = nil,
-- initial page or percent inside document on opening
start_pos = nil,
-- password for document unlock
password = nil,
postInitCallback = nil,
}
function ReaderUI:init()
self.postInitCallback = {}
-- if we are not the top level dialog ourselves, it must be given in the table
if not self.dialog then
self.dialog = self
end
2012-06-26 09:05:09 +00:00
if Device:hasKeyboard() then
2013-04-08 07:21:59 +00:00
self.key_events.Back = {
{ "Back" }, doc = _("close document"),
event = "Close" }
end
2012-06-26 09:05:09 +00:00
self.doc_settings = DocSettings:open(self.document.file)
-- a view container (so it must be child #1!)
self[1] = ReaderView:new{
dialog = self.dialog,
2012-06-12 16:14:23 +00:00
dimen = self.dimen,
2012-12-13 04:41:48 +00:00
ui = self,
document = self.document,
}
-- rotation controller
2012-06-05 07:23:36 +00:00
self[2] = ReaderRotation:new{
dialog = self.dialog,
view = self[1],
ui = self
}
2012-12-31 00:13:46 +00:00
-- reader menu controller
self[3] = ReaderMenu:new{
2012-05-27 11:47:22 +00:00
view = self[1],
ui = self
}
2012-12-31 00:13:46 +00:00
self.menu = self[3] -- hold reference to menu widget
2013-01-01 19:38:29 +00:00
-- Table of content controller
2012-12-31 00:13:46 +00:00
self[4] = ReaderToc:new{
dialog = self.dialog,
view = self[1],
ui = self
}
2013-01-01 19:38:29 +00:00
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{
dialog = self.dialog,
view = self[1],
ui = self,
document = self.document,
}
table.insert(self, highlight)
-- dictionary
local dict = ReaderDictionary:new{
dialog = self.dialog,
view = self[1],
ui = self,
document = self.document,
}
table.insert(self, dict)
-- screenshot controller
local reader_ss = ReaderScreenshot:new{
dialog = self.dialog,
view = self[1],
ui = self
}
-- frontlight controller
local reader_fl = ReaderFrontLight:new{
dialog = self.dialog,
view = self[1],
ui = self
}
table.insert(self.active_widgets, reader_ss)
table.insert(self.active_widgets, reader_fl)
if self.document.info.has_pages then
2012-06-05 07:23:36 +00:00
-- for page specific controller
2013-04-08 07:21:59 +00:00
-- if needed, insert a paging container
local pager = ReaderPaging:new{
dialog = self.dialog,
view = self[1],
ui = self
}
table.insert(self, pager)
2012-06-05 07:23:36 +00:00
-- zooming controller
local zoomer = ReaderZooming:new{
dialog = self.dialog,
view = self[1],
ui = self
}
table.insert(self, zoomer)
-- panning controller
local panner = ReaderPanning:new{
dialog = self.dialog,
view = self[1],
ui = self
}
table.insert(self, panner)
-- cropping controller
local cropper = ReaderCropping:new{
dialog = self.dialog,
view = self[1],
ui = self,
document = self.document,
}
table.insert(self, cropper)
-- hinting controller
local hinter = ReaderHinting:new{
dialog = self.dialog,
view = self[1],
ui = self,
document = self.document,
}
table.insert(self, hinter)
2012-06-05 07:23:36 +00:00
else
-- make sure we load document first before calling any callback
table.insert(self.postInitCallback, function()
self.document:loadDocument()
end)
2012-06-12 09:42:02 +00:00
-- rolling controller
2012-06-05 07:23:36 +00:00
local roller = ReaderRolling:new{
dialog = self.dialog,
view = self[1],
ui = self
}
table.insert(self, roller)
2012-06-12 09:42:02 +00:00
-- font menu
local font_menu = ReaderFont:new{
dialog = self.dialog,
view = self[1],
ui = self
}
table.insert(self, font_menu)
2013-01-17 22:12:50 +00:00
-- typeset controller
local typeset = ReaderTypeset:new{
dialog = self.dialog,
view = self[1],
ui = self
}
table.insert(self, typeset)
2013-04-16 17:11:28 +00:00
table.insert(self, ReaderHyphenation:new{
dialog = self.dialog,
view = self[1],
ui = self
})
end
if self.document.info.configurable then
-- configurable controller
local config_dialog = ReaderConfig:new{
configurable = self.document.configurable,
options = self.document.options,
dialog = self.dialog,
view = self[1],
ui = self
}
table.insert(self, config_dialog)
-- kopt option controller
local koptlistener = ReaderKoptListener:new{
dialog = self.dialog,
view = self[1],
ui = self,
document = self.document,
}
table.insert(self, koptlistener)
-- cre option controller
local coptlistener = ReaderCoptListener:new{
dialog = self.dialog,
view = self[1],
ui = self,
document = self.document,
}
table.insert(self, coptlistener)
-- activity indicator
local activity_listener = 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
self:handleEvent(Event:new("ReadSettings", self.doc_settings))
-- notify childs of dimensions
self:handleEvent(Event:new("SetDimensions", self.dimen))
for _,v in ipairs(self.postInitCallback) do
v()
end
end
2012-06-12 16:14:23 +00:00
function ReaderUI:onSetDimensions(dimen)
self.dimen = dimen
end
function ReaderUI:onClose()
DEBUG("closing reader")
2012-06-26 09:05:09 +00:00
self:handleEvent(Event:new("CloseDocument"))
self.doc_settings:flush()
if self.document ~= nil then
self.document:close()
self.document = nil
self.start_pos = nil
end
UIManager:close(self.dialog)
return true
end