confirm and cancel gestures in cropping dialog are replaced by OK/Cancel buttons

Now only "tap" and "pan" gestures are allowed in cropping dialog.
pull/2/merge
chrox 11 years ago
parent e9567fc2d1
commit 7f179c1fa7

@ -26,28 +26,12 @@ function BBoxWidget:init()
range = self.view.dimen, 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
end end
function BBoxWidget:getSize() function BBoxWidget:getSize()
return Geom:new{ return self.view.dimen
x = 0, y = 0,
w = Screen:getWidth(),
h = Screen:getHeight()
}
end end
function BBoxWidget:paintTo(bb, x, y) function BBoxWidget:paintTo(bb, x, y)
@ -170,15 +154,3 @@ function BBoxWidget:onPanAdjust(arg, ges)
self:adjustScreenBBox(ges, 3.0) self:adjustScreenBBox(ges, 3.0)
return true return true
end 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 a button widget
]] ]]
Button = WidgetContainer:new{ Button = InputContainer:new{
text = nil, -- mandatory 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() 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 -- set FrameContainer content
self[1] = FrameContainer:new{ self[1] = FrameContainer:new{
margin = 0, margin = self.margin,
bordersize = 3, bordersize = self.bordersize,
background = 0, background = self.background,
radius = 15, radius = self.radius,
padding = 2, padding = self.padding,
HorizontalGroup:new{ HorizontalGroup:new{
HorizontalSpan:new{ width = 8 }, HorizontalSpan:new{ width = (self.width - text_size.w)/2 },
TextWidget:new{ text_widget,
text = self.text, HorizontalSpan:new{ width = (self.width - text_size.w)/2 },
face = Font:getFace("cfont", 20)
},
HorizontalSpan:new{ width = 8 },
} }
} }
if self.preselect then if self.preselect then
@ -31,6 +41,18 @@ function Button:init()
else else
self[1].color = 5 self[1].color = 5
end 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 end
function Button:onFocus() function Button:onFocus()
@ -43,3 +65,7 @@ function Button:onUnfocus()
return true return true
end end
function Button:onTapSelect()
self.callback()
return true
end

@ -1,5 +1,52 @@
require "ui/widget"
require "ui/bbox" 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{} ReaderCropping = InputContainer:new{}
function ReaderCropping:onPageCrop(mode) function ReaderCropping:onPageCrop(mode)
@ -17,18 +64,28 @@ function ReaderCropping:onPageCrop(mode)
else else
self.ui:handleEvent(Event:new("SetZoomMode", "page", "cropping")) self.ui:handleEvent(Event:new("SetZoomMode", "page", "cropping"))
end 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, ui = self.ui,
view = self.view, view = self.view,
document = self.document, 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 return true
end end
function ReaderCropping:onConfirmPageCrop(new_bbox) function ReaderCropping:confirmPageCrop()
--DEBUG("new bbox", new_bbox) --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) self.ui:handleEvent(Event:new("BBoxUpdate"), new_bbox)
local pageno = self.view.state.page local pageno = self.view.state.page
self.document.bbox[pageno] = new_bbox self.document.bbox[pageno] = new_bbox
@ -37,13 +94,14 @@ function ReaderCropping:onConfirmPageCrop(new_bbox)
return true return true
end end
function ReaderCropping:onCancelPageCrop() function ReaderCropping:cancelPageCrop()
UIManager:close(self.crop_bbox) UIManager:close(self.crop_dialog)
self:exitPageCrop(false) self:exitPageCrop(false)
return true return true
end end
function ReaderCropping:exitPageCrop(confirmed) function ReaderCropping:exitPageCrop(confirmed)
self.ui:handleEvent(Event:new("SetDimensions", self.orig_view_dimen))
self.document.configurable.text_wrap = self.orig_reflow_mode self.document.configurable.text_wrap = self.orig_reflow_mode
self.view:recalculate() self.view:recalculate()
-- Exiting should have the same look and feel with entering. -- Exiting should have the same look and feel with entering.
@ -63,9 +121,7 @@ function ReaderCropping:exitPageCrop(confirmed)
end end
function ReaderCropping:onReadSettings(config) function ReaderCropping:onReadSettings(config)
local bbox = config:readSetting("bbox") self.document.bbox = config:readSetting("bbox")
self.document.bbox = bbox
--DEBUG("read document bbox", self.document.bbox)
end end
function ReaderCropping:onCloseDocument() function ReaderCropping:onCloseDocument()

@ -163,6 +163,20 @@ function CenterContainer:paintTo(bb, x, y)
self[1]:paintTo(bb, x_pos, y_pos) self[1]:paintTo(bb, x_pos, y_pos)
end 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 RightContainer aligns its content (1 widget) at the right of its own dimensions
]] ]]
@ -193,7 +207,7 @@ FrameContainer = WidgetContainer:new{
function FrameContainer:getSize() function FrameContainer:getSize()
local content_size =self[1]:getSize() local content_size =self[1]:getSize()
return { return Geom:new{
w = content_size.w + ( self.margin + self.bordersize + self.padding ) * 2, w = content_size.w + ( self.margin + self.bordersize + self.padding ) * 2,
h = content_size.h + ( self.margin + self.bordersize + self.padding ) * 2 h = content_size.h + ( self.margin + self.bordersize + self.padding ) * 2
} }

Loading…
Cancel
Save