mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
ReaderZooming: Fix defaults handling (#7463)
It appears the fancy split settings from #6885 were not being honored at all. Also: * Made sure "pagewidth" is actually the default zoom mode again, "full" had sneaked in as the default state of the zoom type toggle). * Display human-readable values in the "Make as default" popup, instead of the raw, meaningless numerical setting. * Disable zoom options when reflow is enabled, and restore 'em properly when it's disabled. Fix #7461, #7228, #7192
This commit is contained in:
@@ -20,6 +20,8 @@ function ReaderCropping:onPageCrop(mode)
|
||||
-- backup original zoom mode as cropping use "page" zoom mode
|
||||
self.orig_zoom_mode = self.view.zoom_mode
|
||||
if mode == "auto" then
|
||||
--- @fixme: This is weird. "auto" crop happens to be the default, yet the default zoom mode/genus is "page", not "content".
|
||||
--- This effectively yields different results whether auto is enabled by default, or toggled at runtime...
|
||||
if self.document.configurable.text_wrap ~= 1 then
|
||||
self:setCropZoomMode(true)
|
||||
end
|
||||
@@ -154,6 +156,10 @@ function ReaderCropping:setCropZoomMode(confirmed)
|
||||
self:setZoomMode(zoom_mode_type
|
||||
and "content"..zoom_mode_type
|
||||
or self.orig_zoom_mode)
|
||||
-- Update the configurable, too
|
||||
self.document.configurable.zoom_mode_genus = zoom_mode_type
|
||||
and 3 -- "content"
|
||||
or 4 -- "page"
|
||||
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
||||
else
|
||||
self:setZoomMode(self.orig_zoom_mode)
|
||||
|
||||
@@ -28,6 +28,18 @@ local ReaderZooming = InputContainer:new{
|
||||
"rows",
|
||||
"manual",
|
||||
},
|
||||
zoom_mode_genus_map = {
|
||||
[4] = "page",
|
||||
[3] = "content",
|
||||
[2] = "columns",
|
||||
[1] = "rows",
|
||||
[0] = "manual",
|
||||
},
|
||||
zoom_mode_type_map = {
|
||||
[2] = "",
|
||||
[1] = "width",
|
||||
[0] = "height",
|
||||
},
|
||||
-- default to nil so we can trigger ZoomModeUpdate events on start up
|
||||
zoom_mode = nil,
|
||||
DEFAULT_ZOOM_MODE = "pagewidth",
|
||||
@@ -110,13 +122,32 @@ function ReaderZooming:init()
|
||||
end
|
||||
|
||||
function ReaderZooming:onReadSettings(config)
|
||||
-- If we have a composite zoom_mode stored, use that
|
||||
local zoom_mode = config:readSetting("zoom_mode")
|
||||
or G_reader_settings:readSetting("zoom_mode")
|
||||
or self.DEFAULT_ZOOM_MODE
|
||||
or G_reader_settings:readSetting("zoom_mode")
|
||||
-- Otherwise, build it from the split genus & type settings
|
||||
if not zoom_mode then
|
||||
local zoom_mode_genus = config:readSetting("kopt_zoom_mode_genus")
|
||||
or G_reader_settings:readSetting("kopt_zoom_mode_genus")
|
||||
local zoom_mode_type = config:readSetting("kopt_zoom_mode_type")
|
||||
or G_reader_settings:readSetting("kopt_zoom_mode_type")
|
||||
if zoom_mode_genus or zoom_mode_type then
|
||||
-- Handle defaults
|
||||
zoom_mode_genus = zoom_mode_genus or 4 -- "page"
|
||||
zoom_mode_type = zoom_mode_type or 1 -- "width"
|
||||
zoom_mode_genus = self.zoom_mode_genus_map[zoom_mode_genus]
|
||||
zoom_mode_type = self.zoom_mode_type_map[zoom_mode_type]
|
||||
zoom_mode = zoom_mode_genus .. zoom_mode_type
|
||||
end
|
||||
end
|
||||
zoom_mode = util.arrayContains(self.available_zoom_modes, zoom_mode)
|
||||
and zoom_mode
|
||||
or self.DEFAULT_ZOOM_MODE
|
||||
self:setZoomMode(zoom_mode, true) -- avoid informative message on load
|
||||
|
||||
-- Don't stomp on normal_zoom_mode in ReaderKoptListener if we're reflowed...
|
||||
local is_reflowed = config:has("kopt_text_wrap") and config:readSetting("kopt_text_wrap") == 1
|
||||
|
||||
self:setZoomMode(zoom_mode, true, is_reflowed) -- avoid informative message on load
|
||||
for _, setting in ipairs(self.zoom_pan_settings) do
|
||||
self[setting] = config:readSetting(setting)
|
||||
or G_reader_settings:readSetting(setting)
|
||||
@@ -214,18 +245,8 @@ function ReaderZooming:onDefineZoom(btn, when_applied_callback)
|
||||
})[config.zoom_direction]
|
||||
local zoom_range_number = config.zoom_range_number
|
||||
local zoom_factor = config.zoom_factor
|
||||
local zoom_mode_genus = ({
|
||||
[4] = "page",
|
||||
[3] = "content",
|
||||
[2] = "columns",
|
||||
[1] = "rows",
|
||||
[0] = "manual",
|
||||
})[config.zoom_mode_genus]
|
||||
local zoom_mode_type = ({
|
||||
[2] = "",
|
||||
[1] = "width",
|
||||
[0] = "height",
|
||||
})[config.zoom_mode_type]
|
||||
local zoom_mode_genus = self.zoom_mode_genus_map[config.zoom_mode_genus]
|
||||
local zoom_mode_type = self.zoom_mode_type_map[config.zoom_mode_type]
|
||||
settings.zoom_overlap_h = config.zoom_overlap_h
|
||||
settings.zoom_overlap_v = config.zoom_overlap_v
|
||||
if btn == "set_zoom_overlap_h" then
|
||||
@@ -491,7 +512,7 @@ function ReaderZooming:genSetZoomModeCallBack(mode)
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderZooming:setZoomMode(mode, no_warning)
|
||||
function ReaderZooming:setZoomMode(mode, no_warning, is_reflowed)
|
||||
if not no_warning and self.ui.view.page_scroll then
|
||||
local message
|
||||
if self.paged_modes[mode] then
|
||||
@@ -511,7 +532,8 @@ Please enable page view instead of continuous view (scroll mode).]])
|
||||
end
|
||||
end
|
||||
|
||||
self.ui:handleEvent(Event:new("SetZoomMode", mode))
|
||||
-- Dirty hack to prevent ReaderKoptListener from stomping on normal_zoom_mode...
|
||||
self.ui:handleEvent(Event:new("SetZoomMode", mode, is_reflowed and "koptlistener"))
|
||||
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
||||
end
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ local CreOptions = {
|
||||
}
|
||||
end
|
||||
end,
|
||||
-- For Dispatcher's sake
|
||||
-- For Dispatcher & onMakeDefault's sake
|
||||
labels = {C_("Rotation", "⤹ 90°"), C_("Rotation", "↑ 0°"), C_("Rotation", "⤸ 90°"), C_("Rotation", "↓ 180°")},
|
||||
alternate = false,
|
||||
values = {Screen.ORIENTATION_LANDSCAPE_ROTATED, Screen.ORIENTATION_PORTRAIT, Screen.ORIENTATION_LANDSCAPE, Screen.ORIENTATION_PORTRAIT_ROTATED},
|
||||
|
||||
@@ -64,7 +64,7 @@ local KoptOptions = {
|
||||
}
|
||||
end
|
||||
end,
|
||||
-- For Dispatcher's sake
|
||||
-- For Dispatcher & onMakeDefault's sake
|
||||
labels = {C_("Rotation", "⤹ 90°"), C_("Rotation", "↑ 0°"), C_("Rotation", "⤸ 90°"), C_("Rotation", "↓ 180°")},
|
||||
alternate = false,
|
||||
values = {Screen.ORIENTATION_LANDSCAPE_ROTATED, Screen.ORIENTATION_PORTRAIT, Screen.ORIENTATION_LANDSCAPE, Screen.ORIENTATION_PORTRAIT_ROTATED},
|
||||
@@ -119,6 +119,10 @@ In 'semi-auto' and 'manual' modes, you may need to define areas once on an odd p
|
||||
{
|
||||
name = "zoom_overlap_h",
|
||||
name_text = _("Horizontal overlap"),
|
||||
enabled_func = function(configurable, document)
|
||||
-- NOTE: document.is_reflowable is wonky as hell, don't trust it.
|
||||
return optionsutil.enableIfEquals(configurable, "text_wrap", 0)
|
||||
end,
|
||||
buttonprogress = true,
|
||||
fine_tune = true,
|
||||
values = {0, 12, 24, 36, 48, 60, 72, 84},
|
||||
@@ -137,6 +141,10 @@ In 'semi-auto' and 'manual' modes, you may need to define areas once on an odd p
|
||||
{
|
||||
name = "zoom_overlap_v",
|
||||
name_text = _("Vertical overlap"),
|
||||
enabled_func = function(configurable, document)
|
||||
-- NOTE: document.is_reflowable is wonky as hell, don't trust it.
|
||||
return optionsutil.enableIfEquals(configurable, "text_wrap", 0)
|
||||
end,
|
||||
buttonprogress = true,
|
||||
fine_tune = true,
|
||||
values = {0, 12, 24, 36, 48, 60, 72, 84},
|
||||
@@ -155,10 +163,14 @@ In 'semi-auto' and 'manual' modes, you may need to define areas once on an odd p
|
||||
{
|
||||
name = "zoom_mode_type",
|
||||
name_text = _("Fit"),
|
||||
enabled_func = function(configurable, document)
|
||||
-- NOTE: document.is_reflowable is wonky as hell, don't trust it.
|
||||
return optionsutil.enableIfEquals(configurable, "text_wrap", 0)
|
||||
end,
|
||||
toggle = {_("full"), _("width"), _("height")},
|
||||
alternate = false,
|
||||
values = {2, 1, 0},
|
||||
default_value = 2,
|
||||
default_value = 1,
|
||||
show_func = function(config) return config and config.zoom_mode_genus > 2 end,
|
||||
event = "DefineZoom",
|
||||
args = {"full", "width", "height"},
|
||||
@@ -176,6 +188,10 @@ In 'semi-auto' and 'manual' modes, you may need to define areas once on an odd p
|
||||
return _("Number")
|
||||
end,
|
||||
name_text_true_values = true,
|
||||
enabled_func = function(configurable, document)
|
||||
-- NOTE: document.is_reflowable is wonky as hell, don't trust it.
|
||||
return optionsutil.enableIfEquals(configurable, "text_wrap", 0)
|
||||
end,
|
||||
show_true_value_func = function(str)
|
||||
return string.format("%.1f", str)
|
||||
end,
|
||||
@@ -202,6 +218,10 @@ In 'semi-auto' and 'manual' modes, you may need to define areas once on an odd p
|
||||
name = "zoom_factor",
|
||||
name_text = _("Zoom factor"),
|
||||
name_text_true_values = true,
|
||||
enabled_func = function(configurable, document)
|
||||
-- NOTE: document.is_reflowable is wonky as hell, don't trust it.
|
||||
return optionsutil.enableIfEquals(configurable, "text_wrap", 0)
|
||||
end,
|
||||
show_true_value_func = function(str)
|
||||
return string.format("%.1f", str)
|
||||
end,
|
||||
@@ -226,6 +246,10 @@ In 'semi-auto' and 'manual' modes, you may need to define areas once on an odd p
|
||||
{
|
||||
name = "zoom_mode_genus",
|
||||
name_text = _("Zoom to"),
|
||||
enabled_func = function(configurable, document)
|
||||
-- NOTE: document.is_reflowable is wonky as hell, don't trust it.
|
||||
return optionsutil.enableIfEquals(configurable, "text_wrap", 0)
|
||||
end,
|
||||
-- toggle = {_("page"), _("content"), _("columns"), _("rows"), _("manual")},
|
||||
item_icons = {
|
||||
"zoom.page",
|
||||
@@ -236,6 +260,7 @@ In 'semi-auto' and 'manual' modes, you may need to define areas once on an odd p
|
||||
},
|
||||
alternate = false,
|
||||
values = {4, 3, 2, 1, 0},
|
||||
labels = {_("page"), _("content"), _("columns"), _("rows"), _("manual")},
|
||||
default_value = 4,
|
||||
event = "DefineZoom",
|
||||
args = {"page", "content", "columns", "rows", "manual"},
|
||||
@@ -245,7 +270,7 @@ In 'semi-auto' and 'manual' modes, you may need to define areas once on an odd p
|
||||
name = "zoom_direction",
|
||||
name_text = _("Direction"),
|
||||
enabled_func = function(config)
|
||||
return config.zoom_mode_genus < 3
|
||||
return optionsutil.enableIfEquals(config, "text_wrap", 0) and config.zoom_mode_genus < 3
|
||||
end,
|
||||
item_icons = {
|
||||
"direction.LRTB",
|
||||
@@ -259,6 +284,16 @@ In 'semi-auto' and 'manual' modes, you may need to define areas once on an odd p
|
||||
},
|
||||
alternate = false,
|
||||
values = {7, 6, 5, 4, 3, 2, 1, 0},
|
||||
labels = {
|
||||
_("Left to Right, Top to Bottom"),
|
||||
_("Top to Bottom, Left to Right"),
|
||||
_("Left to Right, Bottom to Top"),
|
||||
_("Bottom to Top, Left to Right"),
|
||||
_("Bottom to Top, Right to Left"),
|
||||
_("Right to Left, Bottom to Top"),
|
||||
_("Top to Bottom, Right to Left"),
|
||||
_("Right to Left, Top to Bottom"),
|
||||
},
|
||||
default_value = 7,
|
||||
event = "DefineZoom",
|
||||
args = {7, 6, 5, 4, 3, 2, 1, 0},
|
||||
@@ -574,7 +609,7 @@ This can also be used to remove some gray background or to convert a grayscale o
|
||||
"column.two",
|
||||
"column.three",
|
||||
},
|
||||
values = {1,2,3},
|
||||
values = {1, 2, 3},
|
||||
default_value = DKOPTREADER_CONFIG_MAX_COLUMNS,
|
||||
enabled_func = function(configurable)
|
||||
return optionsutil.enableIfEquals(configurable, "text_wrap", 1)
|
||||
|
||||
@@ -168,7 +168,7 @@ end
|
||||
|
||||
function OptionIconItem:onHoldSelect()
|
||||
self.config:onMakeDefault(self.name, self.name_text,
|
||||
self.values, self.values, self.current_item)
|
||||
self.values, self.labels or self.values, self.current_item)
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -519,6 +519,7 @@ function ConfigOption:init()
|
||||
option_item.name = self.options[c].name
|
||||
option_item.name_text = name_text or self.options[c].alt_name_text
|
||||
option_item.values = self.options[c].values
|
||||
option_item.labels = self.options[c].labels
|
||||
option_item.args = self.options[c].args
|
||||
option_item.event = self.options[c].event
|
||||
option_item.current_item = d
|
||||
|
||||
Reference in New Issue
Block a user