1 /***************************************************************************
2 * Copyright (C) 2005 by Piotr Szymanski <niedakh@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 ***************************************************************************/
10 #include "core/misc.h"
16 using namespace Okular
;
18 class TextSelection::Private
23 NormalizedPoint cur
[2];
26 TextSelection::TextSelection( const NormalizedPoint
& a
, const NormalizedPoint
& b
)
29 if (b
.y
-a
.y
<0 || (b
.y
-a
.y
==0 && b
.x
-a
.x
<0))
36 d
->it
[d
->direction
% 2] = -1;
37 d
->it
[(d
->direction
+ 1) % 2] = -1;
40 TextSelection::~TextSelection()
45 void TextSelection::end( const NormalizedPoint
& p
)
47 // changing direction as in 2b , assuming the bool->int conversion is correct
48 int dir1
= d
->direction
;
49 d
->direction
= (p
.y
- d
->cur
[0].y
< 0 || (p
.y
- d
->cur
[0].y
== 0 && p
.x
- d
->cur
[0].x
< 0));
50 if (d
->direction
!= dir1
)
51 kDebug(OkularDebug
) << "changing direction in selection";
56 void TextSelection::itE( int p
)
58 d
->it
[(d
->direction
+ 1) % 2] = p
;
61 void TextSelection::itB( int p
)
63 d
->it
[(d
->direction
) % 2] = p
;
66 int TextSelection::direction() const
71 NormalizedPoint
TextSelection::start() const
73 return d
->cur
[d
->direction
% 2];
76 NormalizedPoint
TextSelection::end() const
78 return d
->cur
[(d
->direction
+ 1) % 2];
81 int TextSelection::itB() const
83 return d
->it
[d
->direction
% 2];
86 int TextSelection::itE() const
88 return d
->it
[(d
->direction
+ 1) % 2];