okular
misc.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "core/misc.h"
00011
00012 #include <kdebug.h>
00013
00014 #include "debug_p.h"
00015
00016 using namespace Okular;
00017
00018 class TextSelection::Private
00019 {
00020 public:
00021 int direction;
00022 int it[2];
00023 NormalizedPoint cur[2];
00024 };
00025
00026 TextSelection::TextSelection( const NormalizedPoint & a, const NormalizedPoint & b )
00027 : d( new Private )
00028 {
00029 if (b.y-a.y<0 || (b.y-a.y==0 && b.x-a.x <0))
00030 d->direction = 1;
00031 else
00032 d->direction = 0;
00033
00034 d->cur[0] = a;
00035 d->cur[1] = b;
00036 d->it[d->direction % 2] = -1;
00037 d->it[(d->direction + 1) % 2] = -1;
00038 }
00039
00040 TextSelection::~TextSelection()
00041 {
00042 delete d;
00043 }
00044
00045 void TextSelection::end( const NormalizedPoint & p )
00046 {
00047
00048 int dir1 = d->direction;
00049 d->direction = (p.y - d->cur[0].y < 0 || (p.y - d->cur[0].y == 0 && p.x - d->cur[0].x < 0));
00050 if (d->direction != dir1)
00051 kDebug(OkularDebug) << "changing direction in selection";
00052
00053 d->cur[1] = p;
00054 }
00055
00056 void TextSelection::itE( int p )
00057 {
00058 d->it[(d->direction + 1) % 2] = p;
00059 }
00060
00061 void TextSelection::itB( int p )
00062 {
00063 d->it[(d->direction) % 2] = p;
00064 }
00065
00066 int TextSelection::direction() const
00067 {
00068 return d->direction;
00069 }
00070
00071 NormalizedPoint TextSelection::start() const
00072 {
00073 return d->cur[d->direction % 2];
00074 }
00075
00076 NormalizedPoint TextSelection::end() const
00077 {
00078 return d->cur[(d->direction + 1) % 2];
00079 }
00080
00081 int TextSelection::itB() const
00082 {
00083 return d->it[d->direction % 2];
00084 }
00085
00086 int TextSelection::itE() const
00087 {
00088 return d->it[(d->direction + 1) % 2];
00089 }