2013-10-18 22:38:07 +02:00
|
|
|
local ConfigDialog = require("ui/widget/configdialog")
|
2014-10-30 19:42:18 +01:00
|
|
|
local Device = require("device")
|
2013-10-18 22:38:07 +02:00
|
|
|
local Event = require("ui/event")
|
2017-08-05 21:49:00 +02:00
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2013-10-18 22:38:07 +02:00
|
|
|
local UIManager = require("ui/uimanager")
|
2018-10-26 08:27:43 -07:00
|
|
|
local CreOptions = require("ui/data/creoptions")
|
|
|
|
|
local KoptOptions = require("ui/data/koptoptions")
|
2013-10-18 22:38:07 +02:00
|
|
|
local _ = require("gettext")
|
|
|
|
|
|
|
|
|
|
local ReaderConfig = InputContainer:new{
|
2014-03-13 21:52:43 +08:00
|
|
|
last_panel_index = 1,
|
2013-07-14 18:48:06 +08:00
|
|
|
}
|
2012-12-14 18:20:04 +08:00
|
|
|
|
|
|
|
|
function ReaderConfig:init()
|
2018-10-26 08:27:43 -07:00
|
|
|
if self.document.koptinterface ~= nil then
|
|
|
|
|
self.options = KoptOptions
|
|
|
|
|
else
|
|
|
|
|
self.options = CreOptions
|
|
|
|
|
end
|
|
|
|
|
self.configurable:loadDefaults(self.options)
|
|
|
|
|
|
2015-09-13 01:06:22 -07:00
|
|
|
if not self.dimen then self.dimen = Geom:new{} end
|
2018-04-19 21:44:13 +03:00
|
|
|
if Device:hasKeys() then
|
2014-03-13 21:52:43 +08:00
|
|
|
self.key_events = {
|
2018-03-22 21:01:38 +01:00
|
|
|
ShowConfigMenu = { {{"Press","AA"}}, doc = "show config dialog" },
|
2014-03-13 21:52:43 +08:00
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
|
self:initGesListener()
|
|
|
|
|
end
|
2017-08-08 18:20:46 +02:00
|
|
|
self.activation_menu = G_reader_settings:readSetting("activate_menu")
|
|
|
|
|
if self.activation_menu == nil then
|
|
|
|
|
self.activation_menu = "swipe_tap"
|
|
|
|
|
end
|
2013-02-02 14:36:29 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderConfig:initGesListener()
|
2017-08-05 21:49:00 +02:00
|
|
|
self.ui:registerTouchZones({
|
|
|
|
|
{
|
|
|
|
|
id = "readerconfigmenu_tap",
|
|
|
|
|
ges = "tap",
|
|
|
|
|
screen_zone = {
|
|
|
|
|
ratio_x = DTAP_ZONE_CONFIG.x, ratio_y = DTAP_ZONE_CONFIG.y,
|
|
|
|
|
ratio_w = DTAP_ZONE_CONFIG.w, ratio_h = DTAP_ZONE_CONFIG.h,
|
|
|
|
|
},
|
2019-03-30 21:05:44 +01:00
|
|
|
overrides = {
|
|
|
|
|
"tap_forward",
|
|
|
|
|
"tap_backward",
|
|
|
|
|
},
|
2017-08-05 21:49:00 +02:00
|
|
|
handler = function() return self:onTapShowConfigMenu() end,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id = "readerconfigmenu_swipe",
|
|
|
|
|
ges = "swipe",
|
|
|
|
|
screen_zone = {
|
|
|
|
|
ratio_x = DTAP_ZONE_CONFIG.x, ratio_y = DTAP_ZONE_CONFIG.y,
|
|
|
|
|
ratio_w = DTAP_ZONE_CONFIG.w, ratio_h = DTAP_ZONE_CONFIG.h,
|
|
|
|
|
},
|
2019-03-30 21:05:44 +01:00
|
|
|
overrides = {
|
|
|
|
|
"rolling_swipe",
|
|
|
|
|
"paging_swipe",
|
|
|
|
|
},
|
2017-08-05 21:49:00 +02:00
|
|
|
handler = function(ges) return self:onSwipeShowConfigMenu(ges) end,
|
2017-08-13 20:41:10 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id = "readerconfigmenu_pan",
|
|
|
|
|
ges = "pan",
|
|
|
|
|
screen_zone = {
|
|
|
|
|
ratio_x = DTAP_ZONE_CONFIG.x, ratio_y = DTAP_ZONE_CONFIG.y,
|
|
|
|
|
ratio_w = DTAP_ZONE_CONFIG.w, ratio_h = DTAP_ZONE_CONFIG.h,
|
|
|
|
|
},
|
2019-03-30 21:05:44 +01:00
|
|
|
overrides = {
|
|
|
|
|
"rolling_pan",
|
|
|
|
|
"paging_pan",
|
|
|
|
|
},
|
2017-08-13 20:41:10 +02:00
|
|
|
handler = function(ges) return self:onSwipeShowConfigMenu(ges) end,
|
2017-08-05 21:49:00 +02:00
|
|
|
},
|
|
|
|
|
})
|
2012-12-14 18:20:04 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderConfig:onShowConfigMenu()
|
2014-03-13 21:52:43 +08:00
|
|
|
self.config_dialog = ConfigDialog:new{
|
|
|
|
|
dimen = self.dimen:copy(),
|
2019-08-30 13:47:51 +02:00
|
|
|
document = self.document,
|
2014-03-13 21:52:43 +08:00
|
|
|
ui = self.ui,
|
|
|
|
|
configurable = self.configurable,
|
|
|
|
|
config_options = self.options,
|
|
|
|
|
is_always_active = true,
|
|
|
|
|
close_callback = function() self:onCloseCallback() end,
|
|
|
|
|
}
|
|
|
|
|
self.ui:handleEvent(Event:new("DisableHinting"))
|
|
|
|
|
-- show last used panel when opening config dialog
|
|
|
|
|
self.config_dialog:onShowConfigPanel(self.last_panel_index)
|
|
|
|
|
UIManager:show(self.config_dialog)
|
2012-12-14 18:20:04 +08:00
|
|
|
|
2014-03-13 21:52:43 +08:00
|
|
|
return true
|
2012-12-14 18:20:04 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderConfig:onTapShowConfigMenu()
|
2017-08-08 18:20:46 +02:00
|
|
|
if self.activation_menu ~= "swipe" then
|
|
|
|
|
self:onShowConfigMenu()
|
|
|
|
|
return true
|
|
|
|
|
end
|
2012-12-14 18:20:04 +08:00
|
|
|
end
|
|
|
|
|
|
2017-08-05 21:49:00 +02:00
|
|
|
function ReaderConfig:onSwipeShowConfigMenu(ges)
|
2017-08-08 18:20:46 +02:00
|
|
|
if self.activation_menu ~= "tap" and ges.direction == "north" then
|
2017-08-05 21:49:00 +02:00
|
|
|
self:onShowConfigMenu()
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2012-12-14 18:20:04 +08:00
|
|
|
function ReaderConfig:onSetDimensions(dimen)
|
2014-03-13 21:52:43 +08:00
|
|
|
-- since we cannot redraw config_dialog with new size, we close
|
|
|
|
|
-- the old one on screen size change
|
|
|
|
|
if self.config_dialog then
|
|
|
|
|
self.config_dialog:closeDialog()
|
|
|
|
|
end
|
2012-12-14 18:20:04 +08:00
|
|
|
end
|
2012-12-24 17:36:52 +08:00
|
|
|
|
2013-07-14 18:48:06 +08:00
|
|
|
function ReaderConfig:onCloseCallback()
|
2014-03-13 21:52:43 +08:00
|
|
|
self.last_panel_index = self.config_dialog.panel_index
|
2017-10-07 15:23:39 +02:00
|
|
|
self.config_dialog = nil
|
2014-03-13 21:52:43 +08:00
|
|
|
self.ui:handleEvent(Event:new("RestoreHinting"))
|
2013-07-14 18:48:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- event handler for readercropping
|
2014-10-10 18:14:16 +08:00
|
|
|
function ReaderConfig:onCloseConfigMenu()
|
2014-10-25 06:01:37 -04:00
|
|
|
if self.config_dialog then
|
|
|
|
|
self.config_dialog:closeDialog()
|
|
|
|
|
end
|
2013-02-03 04:42:59 +08:00
|
|
|
end
|
|
|
|
|
|
2012-12-24 17:36:52 +08:00
|
|
|
function ReaderConfig:onReadSettings(config)
|
2014-03-13 21:52:43 +08:00
|
|
|
self.configurable:loadSettings(config, self.options.prefix.."_")
|
2018-03-15 15:39:44 +01:00
|
|
|
local config_panel_index = config:readSetting("config_panel_index")
|
|
|
|
|
if config_panel_index then
|
|
|
|
|
config_panel_index = math.min(config_panel_index, #self.options)
|
|
|
|
|
end
|
|
|
|
|
self.last_panel_index = config_panel_index or 1
|
2012-12-24 17:36:52 +08:00
|
|
|
end
|
|
|
|
|
|
2013-12-27 23:18:16 +08:00
|
|
|
function ReaderConfig:onSaveSettings()
|
2014-03-13 21:52:43 +08:00
|
|
|
self.configurable:saveSettings(self.ui.doc_settings, self.options.prefix.."_")
|
|
|
|
|
self.ui.doc_settings:saveSetting("config_panel_index", self.last_panel_index)
|
2012-12-24 17:36:52 +08:00
|
|
|
end
|
2013-10-18 22:38:07 +02:00
|
|
|
|
|
|
|
|
return ReaderConfig
|