2013-10-18 20:38:07 +00:00
|
|
|
local ConfigDialog = require("ui/widget/configdialog")
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local Device = require("ui/device")
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local Screen = require("ui/screen")
|
|
|
|
local Event = require("ui/event")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local _ = require("gettext")
|
|
|
|
|
|
|
|
local ReaderConfig = InputContainer:new{
|
2013-07-14 10:48:06 +00:00
|
|
|
last_panel_index = 1,
|
|
|
|
}
|
2012-12-14 10:20:04 +00:00
|
|
|
|
|
|
|
function ReaderConfig:init()
|
2013-02-02 06:36:29 +00:00
|
|
|
if Device:hasKeyboard() then
|
2012-12-14 10:20:04 +00:00
|
|
|
self.key_events = {
|
2013-04-08 07:21:59 +00:00
|
|
|
ShowConfigMenu = { { "AA" }, doc = _("show config dialog") },
|
2012-12-14 10:20:04 +00:00
|
|
|
}
|
|
|
|
end
|
2013-02-02 06:36:29 +00:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self:initGesListener()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderConfig:initGesListener()
|
|
|
|
self.ges_events = {
|
|
|
|
TapShowConfigMenu = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
2013-03-31 08:40:43 +00:00
|
|
|
range = Geom:new{
|
2013-12-15 09:02:52 +00:00
|
|
|
x = Screen:getWidth()*DTAP_ZONE_CONFIG.x,
|
|
|
|
y = Screen:getHeight()*DTAP_ZONE_CONFIG.y,
|
|
|
|
w = Screen:getWidth()*DTAP_ZONE_CONFIG.w,
|
|
|
|
h = Screen:getHeight()*DTAP_ZONE_CONFIG.h,
|
2013-03-31 08:40:43 +00:00
|
|
|
}
|
2013-02-02 06:36:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-12-14 10:20:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderConfig:onShowConfigMenu()
|
2013-02-02 20:42:59 +00:00
|
|
|
self.config_dialog = ConfigDialog:new{
|
2012-12-14 10:20:04 +00:00
|
|
|
dimen = self.dimen:copy(),
|
2012-12-23 23:54:44 +00:00
|
|
|
ui = self.ui,
|
|
|
|
configurable = self.configurable,
|
2013-01-06 05:53:36 +00:00
|
|
|
config_options = self.options,
|
2013-07-14 10:48:06 +00:00
|
|
|
close_callback = function() self:onCloseCallback() end,
|
2012-12-14 10:20:04 +00:00
|
|
|
}
|
2013-03-12 12:28:01 +00:00
|
|
|
self.ui:handleEvent(Event:new("DisableHinting"))
|
2013-07-14 10:48:06 +00:00
|
|
|
-- show last used panel when opening config dialog
|
|
|
|
self.config_dialog:onShowConfigPanel(self.last_panel_index)
|
2013-02-02 20:42:59 +00:00
|
|
|
UIManager:show(self.config_dialog)
|
2012-12-14 10:20:04 +00:00
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderConfig:onTapShowConfigMenu()
|
|
|
|
self:onShowConfigMenu()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderConfig:onSetDimensions(dimen)
|
2013-03-31 08:40:43 +00:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self:initGesListener()
|
|
|
|
end
|
2013-02-03 05:13:46 +00:00
|
|
|
-- since we cannot redraw config_dialog with new size, we close
|
|
|
|
-- the old one on screen size change
|
2013-02-02 09:02:36 +00:00
|
|
|
if self.config_dialog then
|
2013-02-04 07:03:17 +00:00
|
|
|
self.config_dialog:closeDialog()
|
2013-02-02 09:02:36 +00:00
|
|
|
end
|
2012-12-14 10:20:04 +00:00
|
|
|
end
|
2012-12-24 09:36:52 +00:00
|
|
|
|
2013-07-14 10:48:06 +00:00
|
|
|
function ReaderConfig:onCloseCallback()
|
|
|
|
self.last_panel_index = self.config_dialog.panel_index
|
|
|
|
self.ui:handleEvent(Event:new("RestoreHinting"))
|
|
|
|
end
|
|
|
|
|
|
|
|
-- event handler for readercropping
|
2013-02-02 20:42:59 +00:00
|
|
|
function ReaderConfig:onCloseConfig()
|
|
|
|
self.config_dialog:closeDialog()
|
|
|
|
end
|
|
|
|
|
2012-12-24 09:36:52 +00:00
|
|
|
function ReaderConfig:onReadSettings(config)
|
2013-04-10 00:02:57 +00:00
|
|
|
self.configurable:loadSettings(config, self.options.prefix.."_")
|
2013-07-14 10:48:06 +00:00
|
|
|
self.last_panel_index = config:readSetting("config_panel_index") or 1
|
2012-12-24 09:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderConfig:onCloseDocument()
|
2013-04-10 00:02:57 +00:00
|
|
|
self.configurable:saveSettings(self.ui.doc_settings, self.options.prefix.."_")
|
2013-07-14 10:48:06 +00:00
|
|
|
self.ui.doc_settings:saveSetting("config_panel_index", self.last_panel_index)
|
2012-12-24 09:36:52 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
return ReaderConfig
|