mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
confirm and cancel gestures in cropping dialog are replaced by OK/Cancel buttons
Now only "tap" and "pan" gestures are allowed in cropping dialog.
This commit is contained in:
@@ -26,28 +26,12 @@ function BBoxWidget:init()
|
||||
range = self.view.dimen,
|
||||
}
|
||||
},
|
||||
Confirm = {
|
||||
GestureRange:new{
|
||||
ges = "double_tap",
|
||||
range = self.view.dimen,
|
||||
}
|
||||
},
|
||||
Cancel = {
|
||||
GestureRange:new{
|
||||
ges = "hold",
|
||||
range = self.view.dimen,
|
||||
}
|
||||
},
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function BBoxWidget:getSize()
|
||||
return Geom:new{
|
||||
x = 0, y = 0,
|
||||
w = Screen:getWidth(),
|
||||
h = Screen:getHeight()
|
||||
}
|
||||
return self.view.dimen
|
||||
end
|
||||
|
||||
function BBoxWidget:paintTo(bb, x, y)
|
||||
@@ -170,15 +154,3 @@ function BBoxWidget:onPanAdjust(arg, ges)
|
||||
self:adjustScreenBBox(ges, 3.0)
|
||||
return true
|
||||
end
|
||||
|
||||
function BBoxWidget:onConfirm()
|
||||
local new_bbox = self:getModifiedPageBBox()
|
||||
self.ui:handleEvent(Event:new("ConfirmPageCrop", new_bbox))
|
||||
return true
|
||||
end
|
||||
|
||||
function BBoxWidget:onCancel()
|
||||
UIManager:close(self.crop_bbox)
|
||||
self.ui:handleEvent(Event:new("CancelPageCrop"))
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -3,27 +3,37 @@ require "ui/widget"
|
||||
--[[
|
||||
a button widget
|
||||
]]
|
||||
Button = WidgetContainer:new{
|
||||
Button = InputContainer:new{
|
||||
text = nil, -- mandatory
|
||||
preselect = false
|
||||
preselect = false,
|
||||
callback = nil,
|
||||
margin = 0,
|
||||
bordersize = 3,
|
||||
background = 0,
|
||||
radius = 15,
|
||||
padding = 2,
|
||||
width = nil,
|
||||
text_font_face = "cfont",
|
||||
text_font_size = 20,
|
||||
}
|
||||
|
||||
function Button:init()
|
||||
local text_widget = TextWidget:new{
|
||||
text = self.text,
|
||||
face = Font:getFace(self.text_font_face, self.text_font_size)
|
||||
}
|
||||
local text_size = text_widget:getSize()
|
||||
-- set FrameContainer content
|
||||
self[1] = FrameContainer:new{
|
||||
margin = 0,
|
||||
bordersize = 3,
|
||||
background = 0,
|
||||
radius = 15,
|
||||
padding = 2,
|
||||
|
||||
margin = self.margin,
|
||||
bordersize = self.bordersize,
|
||||
background = self.background,
|
||||
radius = self.radius,
|
||||
padding = self.padding,
|
||||
HorizontalGroup:new{
|
||||
HorizontalSpan:new{ width = 8 },
|
||||
TextWidget:new{
|
||||
text = self.text,
|
||||
face = Font:getFace("cfont", 20)
|
||||
},
|
||||
HorizontalSpan:new{ width = 8 },
|
||||
HorizontalSpan:new{ width = (self.width - text_size.w)/2 },
|
||||
text_widget,
|
||||
HorizontalSpan:new{ width = (self.width - text_size.w)/2 },
|
||||
}
|
||||
}
|
||||
if self.preselect then
|
||||
@@ -31,6 +41,18 @@ function Button:init()
|
||||
else
|
||||
self[1].color = 5
|
||||
end
|
||||
self.dimen = self[1]:getSize()
|
||||
if Device:isTouchDevice() then
|
||||
self.ges_events = {
|
||||
TapSelect = {
|
||||
GestureRange:new{
|
||||
ges = "tap",
|
||||
range = self.dimen,
|
||||
},
|
||||
doc = "Tap Button",
|
||||
},
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function Button:onFocus()
|
||||
@@ -43,3 +65,7 @@ function Button:onUnfocus()
|
||||
return true
|
||||
end
|
||||
|
||||
function Button:onTapSelect()
|
||||
self.callback()
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -1,5 +1,52 @@
|
||||
require "ui/widget"
|
||||
require "ui/bbox"
|
||||
|
||||
PageCropDialog = VerticalGroup:new{
|
||||
ok_text = "OK",
|
||||
cancel_text = "Cancel",
|
||||
ok_callback = function() end,
|
||||
cancel_callback = function() end,
|
||||
button_width = math.floor(70*Screen:getDPI()/167),
|
||||
}
|
||||
|
||||
function PageCropDialog:init()
|
||||
local horizontal_group = HorizontalGroup:new{}
|
||||
local ok_button = Button:new{
|
||||
text = self.ok_text,
|
||||
callback = self.ok_callback,
|
||||
width = self.button_width,
|
||||
bordersize = 2,
|
||||
radius = 7,
|
||||
text_font_face = "cfont",
|
||||
text_font_size = 20,
|
||||
}
|
||||
local cancel_button = Button:new{
|
||||
text = self.cancel_text,
|
||||
callback = self.cancel_callback,
|
||||
width = self.button_width,
|
||||
bordersize = 2,
|
||||
radius = 7,
|
||||
text_font_face = "cfont",
|
||||
text_font_size = 20,
|
||||
}
|
||||
local ok_container = RightContainer:new{
|
||||
dimen = Geom:new{ w = Screen:getWidth()*0.33, h = Screen:getHeight()/12},
|
||||
ok_button,
|
||||
}
|
||||
local cancel_container = LeftContainer:new{
|
||||
dimen = Geom:new{ w = Screen:getWidth()*0.33, h = Screen:getHeight()/12},
|
||||
cancel_button,
|
||||
}
|
||||
table.insert(horizontal_group, ok_container)
|
||||
table.insert(horizontal_group, HorizontalSpan:new{ width = Screen:getWidth()*0.34})
|
||||
table.insert(horizontal_group, cancel_container)
|
||||
self[2] = FrameContainer:new{
|
||||
background = 0,
|
||||
bordersize = 0,
|
||||
horizontal_group,
|
||||
}
|
||||
end
|
||||
|
||||
ReaderCropping = InputContainer:new{}
|
||||
|
||||
function ReaderCropping:onPageCrop(mode)
|
||||
@@ -17,18 +64,28 @@ function ReaderCropping:onPageCrop(mode)
|
||||
else
|
||||
self.ui:handleEvent(Event:new("SetZoomMode", "page", "cropping"))
|
||||
end
|
||||
self.crop_bbox = BBoxWidget:new{
|
||||
self.orig_view_dimen = self.view.dimen:copy()
|
||||
self.ui:handleEvent(Event:new("SetDimensions",
|
||||
Geom:new{w = Screen:getWidth(), h = Screen:getHeight()*11/12})
|
||||
)
|
||||
self.bbox_widget = BBoxWidget:new{
|
||||
ui = self.ui,
|
||||
view = self.view,
|
||||
document = self.document,
|
||||
}
|
||||
UIManager:show(self.crop_bbox)
|
||||
self.crop_dialog = PageCropDialog:new{
|
||||
self.bbox_widget,
|
||||
ok_callback = function() self:confirmPageCrop() end,
|
||||
cancel_callback = function() self:cancelPageCrop() end,
|
||||
}
|
||||
UIManager:show(self.crop_dialog)
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderCropping:onConfirmPageCrop(new_bbox)
|
||||
function ReaderCropping:confirmPageCrop()
|
||||
--DEBUG("new bbox", new_bbox)
|
||||
UIManager:close(self.crop_bbox)
|
||||
UIManager:close(self.crop_dialog)
|
||||
local new_bbox = self.bbox_widget:getModifiedPageBBox()
|
||||
self.ui:handleEvent(Event:new("BBoxUpdate"), new_bbox)
|
||||
local pageno = self.view.state.page
|
||||
self.document.bbox[pageno] = new_bbox
|
||||
@@ -37,13 +94,14 @@ function ReaderCropping:onConfirmPageCrop(new_bbox)
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderCropping:onCancelPageCrop()
|
||||
UIManager:close(self.crop_bbox)
|
||||
function ReaderCropping:cancelPageCrop()
|
||||
UIManager:close(self.crop_dialog)
|
||||
self:exitPageCrop(false)
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderCropping:exitPageCrop(confirmed)
|
||||
self.ui:handleEvent(Event:new("SetDimensions", self.orig_view_dimen))
|
||||
self.document.configurable.text_wrap = self.orig_reflow_mode
|
||||
self.view:recalculate()
|
||||
-- Exiting should have the same look and feel with entering.
|
||||
@@ -63,9 +121,7 @@ function ReaderCropping:exitPageCrop(confirmed)
|
||||
end
|
||||
|
||||
function ReaderCropping:onReadSettings(config)
|
||||
local bbox = config:readSetting("bbox")
|
||||
self.document.bbox = bbox
|
||||
--DEBUG("read document bbox", self.document.bbox)
|
||||
self.document.bbox = config:readSetting("bbox")
|
||||
end
|
||||
|
||||
function ReaderCropping:onCloseDocument()
|
||||
|
||||
@@ -163,6 +163,20 @@ function CenterContainer:paintTo(bb, x, y)
|
||||
self[1]:paintTo(bb, x_pos, y_pos)
|
||||
end
|
||||
|
||||
--[[
|
||||
LeftContainer aligns its content (1 widget) at the left of its own dimensions
|
||||
]]
|
||||
LeftContainer = WidgetContainer:new()
|
||||
|
||||
function LeftContainer:paintTo(bb, x, y)
|
||||
local contentSize = self[1]:getSize()
|
||||
if contentSize.w > self.dimen.w or contentSize.h > self.dimen.h then
|
||||
-- throw error? paint to scrap buffer and blit partially?
|
||||
-- for now, we ignore this
|
||||
end
|
||||
self[1]:paintTo(bb, x , y + (self.dimen.h - contentSize.h)/2)
|
||||
end
|
||||
|
||||
--[[
|
||||
RightContainer aligns its content (1 widget) at the right of its own dimensions
|
||||
]]
|
||||
@@ -193,7 +207,7 @@ FrameContainer = WidgetContainer:new{
|
||||
|
||||
function FrameContainer:getSize()
|
||||
local content_size =self[1]:getSize()
|
||||
return {
|
||||
return Geom:new{
|
||||
w = content_size.w + ( self.margin + self.bordersize + self.padding ) * 2,
|
||||
h = content_size.h + ( self.margin + self.bordersize + self.padding ) * 2
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user