2019-12-06 21:55:39 +00:00
|
|
|
local BD = require("ui/bidi")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Device = require("device")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Geom = require("ui/geometry")
|
2017-08-03 18:06:30 +00:00
|
|
|
local ImageWidget = require("ui/widget/imagewidget")
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local RightContainer = require("ui/widget/container/rightcontainer")
|
2019-04-07 17:00:15 +00:00
|
|
|
local Screen = Device.screen
|
2013-02-24 11:49:23 +00:00
|
|
|
|
2013-12-17 11:53:43 +00:00
|
|
|
local ReaderDogear = InputContainer:new{}
|
2013-02-24 11:49:23 +00:00
|
|
|
|
|
|
|
function ReaderDogear:init()
|
2018-07-19 06:18:55 +00:00
|
|
|
-- This image could be scaled for DPI (with scale_for_dpi=true, scale_factor=0.7),
|
|
|
|
-- but it's as good to scale it to a fraction (1/32) of the screen size.
|
|
|
|
-- For CreDocument, we should additionally take care of not exceeding margins
|
|
|
|
-- to not overwrite the book text.
|
|
|
|
-- For other documents, there is no easy way to know if valuable content
|
|
|
|
-- may be hidden by the icon (kopt's page_margin is quite obscure).
|
|
|
|
self.dogear_max_size = math.ceil( math.min(Screen:getWidth(), Screen:getHeight()) / 32)
|
|
|
|
self.dogear_size = nil
|
|
|
|
self:setupDogear()
|
2016-03-08 06:42:46 +00:00
|
|
|
self:resetLayout()
|
|
|
|
end
|
|
|
|
|
2018-07-19 06:18:55 +00:00
|
|
|
function ReaderDogear:setupDogear(new_dogear_size)
|
|
|
|
if not new_dogear_size then
|
|
|
|
new_dogear_size = self.dogear_max_size
|
|
|
|
end
|
|
|
|
if new_dogear_size ~= self.dogear_size then
|
|
|
|
self.dogear_size = new_dogear_size
|
|
|
|
if self[1] then
|
|
|
|
self[1]:free()
|
|
|
|
end
|
|
|
|
self[1] = RightContainer:new{
|
|
|
|
dimen = Geom:new{w = Screen:getWidth(), h = self.dogear_size},
|
|
|
|
ImageWidget:new{
|
|
|
|
file = "resources/icons/dogear.png",
|
2019-12-06 21:55:39 +00:00
|
|
|
rotation_angle = BD.mirroredUILayout() and 90 or 0,
|
2018-07-19 06:18:55 +00:00
|
|
|
width = self.dogear_size,
|
|
|
|
height = self.dogear_size,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderDogear:onReadSettings(config)
|
|
|
|
if not self.ui.document.info.has_pages then
|
|
|
|
-- Adjust to CreDocument margins (as done in ReaderTypeset)
|
2019-05-01 00:09:01 +00:00
|
|
|
local h_margins = config:readSetting("copt_h_page_margins") or
|
|
|
|
G_reader_settings:readSetting("copt_h_page_margins") or
|
|
|
|
DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM
|
|
|
|
local t_margin = config:readSetting("copt_t_page_margin") or
|
|
|
|
G_reader_settings:readSetting("copt_t_page_margin") or
|
|
|
|
DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE
|
|
|
|
local b_margin = config:readSetting("copt_b_page_margin") or
|
|
|
|
G_reader_settings:readSetting("copt_b_page_margin") or
|
|
|
|
DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE
|
|
|
|
local margins = { h_margins[1], t_margin, h_margins[2], b_margin }
|
|
|
|
self:onSetPageMargins(margins)
|
2018-07-19 06:18:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderDogear:onSetPageMargins(margins)
|
|
|
|
if self.ui.document.info.has_pages then
|
|
|
|
-- we may get called by readerfooter (when hiding the footer)
|
|
|
|
-- on pdf documents and get margins=nil
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local margin_top, margin_right = margins[2], margins[3]
|
|
|
|
-- As the icon is squared, we can take the max() instead of the min() of
|
|
|
|
-- top & right margins and be sure no text is hidden by the icon
|
|
|
|
-- (the provided margins are not scaled, so do as ReaderTypeset)
|
|
|
|
local margin = Screen:scaleBySize(math.max(margin_top, margin_right))
|
|
|
|
local new_dogear_size = math.min(self.dogear_max_size, margin)
|
|
|
|
self:setupDogear(new_dogear_size)
|
|
|
|
end
|
|
|
|
|
2016-03-08 06:42:46 +00:00
|
|
|
function ReaderDogear:resetLayout()
|
2016-03-12 08:59:15 +00:00
|
|
|
local new_screen_width = Screen:getWidth()
|
|
|
|
if new_screen_width == self._last_screen_width then return end
|
|
|
|
self._last_screen_width = new_screen_width
|
|
|
|
|
|
|
|
self[1].dimen.w = new_screen_width
|
2013-02-24 11:49:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderDogear:onSetDogearVisibility(visible)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.view.dogear_visible = visible
|
|
|
|
return true
|
2013-03-12 17:18:53 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
return ReaderDogear
|