compile
[kdegraphics.git] / okular / core / misc.cpp
blob34812c4f88af621590fa8a4270f7ce9b30bf389b
1 /***************************************************************************
2 * Copyright (C) 2005 by Piotr Szymanski <niedakh@gmail.com> *
3 * *
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"
12 #include <kdebug.h>
14 #include "debug_p.h"
16 using namespace Okular;
18 class TextSelection::Private
20 public:
21 int direction;
22 int it[2];
23 NormalizedPoint cur[2];
26 TextSelection::TextSelection( const NormalizedPoint & a, const NormalizedPoint & b )
27 : d( new Private )
29 if (b.y-a.y<0 || (b.y-a.y==0 && b.x-a.x <0))
30 d->direction = 1;
31 else
32 d->direction = 0;
34 d->cur[0] = a;
35 d->cur[1] = b;
36 d->it[d->direction % 2] = -1;
37 d->it[(d->direction + 1) % 2] = -1;
40 TextSelection::~TextSelection()
42 delete d;
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";
53 d->cur[1] = p;
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
68 return d->direction;
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];