Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Graphics
Okular
Commits
9d805df0
Commit
9d805df0
authored
Mar 25, 2012
by
Albert Astals Cid
Browse files
Double click selects words
BUGS: 187347
FIXED-IN: 4.9,0
parent
592c0c16
Changes
5
Hide whitespace changes
Inline
Side-by-side
core/page.cpp
View file @
9d805df0
...
...
@@ -217,6 +217,14 @@ bool Page::hasTextPage() const
return
d
->
m_text
!=
0
;
}
RegularAreaRect
*
Page
::
wordAt
(
const
NormalizedPoint
&
p
,
QString
*
word
)
const
{
if
(
d
->
m_text
)
return
d
->
m_text
->
wordAt
(
p
,
word
);
return
0
;
}
RegularAreaRect
*
Page
::
textArea
(
TextSelection
*
selection
)
const
{
if
(
d
->
m_text
)
...
...
core/page.h
View file @
9d805df0
...
...
@@ -204,6 +204,14 @@ class OKULAR_EXPORT Page
* @since 0.14 (KDE 4.8)
*/
TextEntity
::
List
words
(
const
RegularAreaRect
*
rect
,
TextPage
::
TextAreaInclusionBehaviour
b
)
const
;
/**
* Returns the area and text of the word at the given point
* Note that ownership of the returned area belongs to the caller.
* @see TextPage::wordAt()
* @since 0.15 (KDE 4.9)
*/
RegularAreaRect
*
wordAt
(
const
NormalizedPoint
&
p
,
QString
*
word
=
0
)
const
;
/**
* Returns the rectangular area of the given @p selection.
...
...
core/textpage.cpp
View file @
9d805df0
...
...
@@ -1958,3 +1958,84 @@ TextEntity::List TextPage::words(const RegularAreaRect *area, TextAreaInclusionB
}
return
ret
;
}
RegularAreaRect
*
TextPage
::
wordAt
(
const
NormalizedPoint
&
p
,
QString
*
word
)
const
{
TextList
::
ConstIterator
itBegin
=
d
->
m_words
.
constBegin
(),
itEnd
=
d
->
m_words
.
constEnd
();
TextList
::
ConstIterator
it
=
itBegin
;
TextList
::
ConstIterator
posIt
=
itEnd
;
for
(
;
it
!=
itEnd
;
++
it
)
{
if
(
(
*
it
)
->
area
.
contains
(
p
.
x
,
p
.
y
)
)
{
posIt
=
it
;
break
;
}
}
QString
text
;
if
(
posIt
!=
itEnd
)
{
if
(
(
*
posIt
)
->
text
().
simplified
().
isEmpty
()
)
{
return
NULL
;
}
// Find the first TinyTextEntity of the word
while
(
posIt
!=
itBegin
)
{
--
posIt
;
const
QString
itText
=
(
*
posIt
)
->
text
();
if
(
itText
.
right
(
1
).
at
(
0
).
isSpace
()
)
{
if
(
itText
.
endsWith
(
"-
\n
"
))
{
// Is an hyphenated word
// continue searching the start of the word back
continue
;
}
if
(
itText
==
"
\n
"
&&
posIt
!=
itBegin
)
{
--
posIt
;
if
((
*
posIt
)
->
text
().
endsWith
(
"-"
))
{
// Is an hyphenated word
// continue searching the start of the word back
continue
;
}
++
posIt
;
}
++
posIt
;
break
;
}
}
RegularAreaRect
*
ret
=
new
RegularAreaRect
();
for
(
;
posIt
!=
itEnd
;
++
posIt
)
{
const
QString
itText
=
(
*
posIt
)
->
text
();
if
(
itText
.
simplified
().
isEmpty
()
)
{
break
;
}
ret
->
appendShape
(
(
*
posIt
)
->
area
);
text
+=
(
*
posIt
)
->
text
();
if
(
itText
.
right
(
1
).
at
(
0
).
isSpace
())
{
if
(
!
text
.
endsWith
(
"-
\n
"
))
{
break
;
}
}
}
if
(
word
)
{
*
word
=
text
;
}
return
ret
;
}
else
{
return
NULL
;
}
}
core/textpage.h
View file @
9d805df0
...
...
@@ -20,6 +20,7 @@ class QMatrix;
namespace
Okular
{
class
NormalizedPoint
;
class
NormalizedRect
;
class
Page
;
class
PagePrivate
;
...
...
@@ -171,6 +172,13 @@ class OKULAR_EXPORT TextPage
*/
TextEntity
::
List
words
(
const
RegularAreaRect
*
rect
,
TextAreaInclusionBehaviour
b
)
const
;
/**
* Returns the area and text of the word at the given point
* Note that ownership of the returned area belongs to the caller.
* @since 0.15 (KDE 4.9)
*/
RegularAreaRect
*
wordAt
(
const
NormalizedPoint
&
p
,
QString
*
word
=
0
)
const
;
/**
* Returns the rectangular area of the given @p selection.
*/
...
...
ui/pageview.cpp
View file @
9d805df0
...
...
@@ -2803,9 +2803,23 @@ void PageView::mouseDoubleClickEvent( QMouseEvent * e )
if
(
pageItem
)
{
// find out normalized mouse coords inside current item
const
QRect
&
itemRect
=
pageItem
->
uncroppedGeometry
();
double
nX
=
pageItem
->
absToPageX
(
eventPos
.
x
());
double
nY
=
pageItem
->
absToPageY
(
eventPos
.
y
());
if
(
Okular
::
Settings
::
mouseMode
()
==
Okular
::
Settings
::
EnumMouseMode
::
TextSelect
)
{
textSelectionClear
();
Okular
::
RegularAreaRect
*
wordRect
=
pageItem
->
page
()
->
wordAt
(
Okular
::
NormalizedPoint
(
nX
,
nY
)
);
if
(
wordRect
)
{
// TODO words with hyphens across pages
d
->
document
->
setPageTextSelection
(
pageItem
->
pageNumber
(),
wordRect
,
palette
().
color
(
QPalette
::
Active
,
QPalette
::
Highlight
)
);
d
->
pagesWithTextSelection
<<
pageItem
->
pageNumber
();
return
;
}
}
const
QRect
&
itemRect
=
pageItem
->
uncroppedGeometry
();
Okular
::
Annotation
*
ann
=
0
;
const
Okular
::
ObjectRect
*
orect
=
pageItem
->
page
()
->
objectRect
(
Okular
::
ObjectRect
::
OAnnotation
,
nX
,
nY
,
itemRect
.
width
(),
itemRect
.
height
()
);
if
(
orect
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment