mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #122 from chrox/highlight
add strings in highlight dialog for translation
This commit is contained in:
@@ -66,7 +66,7 @@ function ReaderHighlight:onSetDimensions(dimen)
|
||||
end
|
||||
|
||||
function ReaderHighlight:onTap(arg, ges)
|
||||
local function inside_box(box)
|
||||
local function inside_box(ges, box)
|
||||
local pos = self.view:screenToPageTransform(ges.pos)
|
||||
local x, y = pos.x, pos.y
|
||||
if box.x <= x and box.y <= y
|
||||
@@ -83,22 +83,23 @@ function ReaderHighlight:onTap(arg, ges)
|
||||
return true
|
||||
end
|
||||
local pages = self.view:getCurrentPageList()
|
||||
for _, page in pairs(pages) do
|
||||
for key, page in pairs(pages) do
|
||||
local items = self.view.highlight.saved[page]
|
||||
if not items then items = {} end
|
||||
for i = 1, #items do
|
||||
for j = 1, #items[i].boxes do
|
||||
if inside_box(items[i].boxes[j]) then
|
||||
if inside_box(ges, items[i].boxes[j]) then
|
||||
DEBUG("Tap on hightlight")
|
||||
self.edit_highlight_dialog = ButtonTable:new{
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
text="Delete",
|
||||
text = _("Delete"),
|
||||
callback = function() self:deleteHighlight(page, i) end,
|
||||
},
|
||||
{
|
||||
text="Edit",
|
||||
text = _("Edit"),
|
||||
enabled = false,
|
||||
callback = function() self:editHighlight() end,
|
||||
},
|
||||
},
|
||||
@@ -148,7 +149,7 @@ function ReaderHighlight:onHoldPan(arg, ges)
|
||||
self.holdpan_pos = self.view:screenToPageTransform(ges.pos)
|
||||
DEBUG("holdpan position in page", self.holdpan_pos)
|
||||
self.selected_text = self:getTextFromPositions(self.page_boxes, self.hold_pos, self.holdpan_pos)
|
||||
DEBUG("selected text:", self.selected_text)
|
||||
--DEBUG("selected text:", self.selected_text)
|
||||
if self.selected_text then
|
||||
self.view.highlight.temp[self.hold_pos.page] = self.selected_text.boxes
|
||||
UIManager:setDirty(self.dialog, "partial")
|
||||
@@ -178,21 +179,24 @@ function ReaderHighlight:onHoldRelease(arg, ges)
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
text="Highlight",
|
||||
text = _("Highlight"),
|
||||
callback = function() self:saveHighlight() end,
|
||||
},
|
||||
{
|
||||
text="Add Note",
|
||||
text = _("Add Note"),
|
||||
enabled = false,
|
||||
callback = function() self:addNote() end,
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
text="Share",
|
||||
text = _("Share"),
|
||||
enabled = false,
|
||||
callback = function() self:shareHighlight() end,
|
||||
},
|
||||
{
|
||||
text="More",
|
||||
text = _("More"),
|
||||
enabled = false,
|
||||
callback = function() self:moreAction() end,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -7,6 +7,7 @@ Button = InputContainer:new{
|
||||
text = nil, -- mandatory
|
||||
preselect = false,
|
||||
callback = nil,
|
||||
enabled = true,
|
||||
margin = 0,
|
||||
bordersize = 3,
|
||||
background = 0,
|
||||
@@ -18,11 +19,13 @@ Button = InputContainer:new{
|
||||
}
|
||||
|
||||
function Button:init()
|
||||
local text_widget = TextWidget:new{
|
||||
self.text_widget = TextWidget:new{
|
||||
text = self.text,
|
||||
bgcolor = 0.0,
|
||||
fgcolor = self.enabled and 1.0 or 0.5,
|
||||
face = Font:getFace(self.text_font_face, self.text_font_size)
|
||||
}
|
||||
local text_size = text_widget:getSize()
|
||||
local text_size = self.text_widget:getSize()
|
||||
if self.width == nil then
|
||||
self.width = text_size.w
|
||||
end
|
||||
@@ -35,7 +38,7 @@ function Button:init()
|
||||
padding = self.padding,
|
||||
HorizontalGroup:new{
|
||||
HorizontalSpan:new{ width = (self.width - text_size.w)/2 },
|
||||
text_widget,
|
||||
self.text_widget,
|
||||
HorizontalSpan:new{ width = (self.width - text_size.w)/2 },
|
||||
}
|
||||
}
|
||||
@@ -68,7 +71,19 @@ function Button:onUnfocus()
|
||||
return true
|
||||
end
|
||||
|
||||
function Button:enable()
|
||||
self.enabled = true
|
||||
self.text_widget.fgcolor = 1.0
|
||||
end
|
||||
|
||||
function Button:disable()
|
||||
self.enabled = false
|
||||
self.text_widget.fgcolor = 0.5
|
||||
end
|
||||
|
||||
function Button:onTapSelect()
|
||||
self.callback()
|
||||
if self.enabled then
|
||||
self.callback()
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -4,8 +4,8 @@ require "ui/widget/line"
|
||||
ButtonTable = InputContainer:new{
|
||||
buttons = {
|
||||
{
|
||||
{text="OK", callback=nil},
|
||||
{text="Cancel", callback=nil},
|
||||
{text="OK", enabled=true, callback=nil},
|
||||
{text="Cancel", enabled=false, callback=nil},
|
||||
},
|
||||
},
|
||||
tap_close_callback = nil,
|
||||
@@ -43,6 +43,7 @@ function ButtonTable:init()
|
||||
for j = 1, #line do
|
||||
local button = Button:new{
|
||||
text = line[j].text,
|
||||
enabled = line[j].enabled,
|
||||
callback = line[j].callback,
|
||||
width = Screen:getWidth()*0.9/#line,
|
||||
bordersize = 0,
|
||||
|
||||
@@ -8,7 +8,8 @@ A TextWidget puts a string on a single line
|
||||
TextWidget = Widget:new{
|
||||
text = nil,
|
||||
face = nil,
|
||||
color = 15,
|
||||
bgcolor = 0.0, -- [0.0, 1.0]
|
||||
fgcolor = 1.0, -- [0.0, 1.0]
|
||||
_bb = nil,
|
||||
_length = 0,
|
||||
_height = 0,
|
||||
@@ -44,7 +45,8 @@ function TextWidget:paintTo(bb, x, y)
|
||||
--end
|
||||
--bb:blitFrom(self._bb, x, y, 0, 0, self._length, self._bb:getHeight())
|
||||
--@TODO Don't use kerning for monospaced fonts. (houqp)
|
||||
renderUtf8Text(bb, x, y+self._height*0.7, self.face, self.text, true)
|
||||
renderUtf8Text(bb, x, y+self._height*0.7, self.face, self.text,
|
||||
true, self.bgcolor, self.fgcolor)
|
||||
end
|
||||
|
||||
function TextWidget:free()
|
||||
@@ -60,7 +62,8 @@ A TextWidget that handles long text wrapping
|
||||
TextBoxWidget = Widget:new{
|
||||
text = nil,
|
||||
face = nil,
|
||||
color = 15,
|
||||
bgcolor = 0.0, -- [0.0, 1.0]
|
||||
fgcolor = 1.0, -- [0.0, 1.0]
|
||||
width = 400, -- in pixels
|
||||
line_height = 0.3, -- in em
|
||||
v_list = nil,
|
||||
@@ -124,7 +127,8 @@ function TextBoxWidget:_render()
|
||||
for _,w in ipairs(l) do
|
||||
--@TODO Don't use kerning for monospaced fonts. (houqp)
|
||||
-- refert to cb25029dddc42693cc7aaefbe47e9bd3b7e1a750 in master tree
|
||||
renderUtf8Text(self._bb, pen_x, y*0.8, self.face, w.word, true)
|
||||
renderUtf8Text(self._bb, pen_x, y*0.8, self.face, w.word,
|
||||
true, self.bgcolor, self.fgcolor)
|
||||
local is_ascii = not w.word:match("[%z\194-\244][\128-\191]*")
|
||||
pen_x = pen_x + w.width + (is_ascii and space_w or 0)
|
||||
end
|
||||
@@ -176,7 +180,6 @@ function FixedTextWidget:getSize()
|
||||
end
|
||||
|
||||
function FixedTextWidget:paintTo(bb, x, y)
|
||||
renderUtf8Text(bb, x, y+self._height, self.face, self.text, true)
|
||||
renderUtf8Text(bb, x, y+self._height, self.face, self.text,
|
||||
true, self.bgcolor, self.fgcolor)
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user