2021-05-24 07:25:56 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2005 Piotr Szymanski <niedakh@gmail.com>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2007-01-03 14:30:48 +00:00
|
|
|
|
|
|
|
#include "core/misc.h"
|
|
|
|
|
2018-08-31 09:23:45 +00:00
|
|
|
#include <QDebug>
|
2007-05-05 13:50:44 +00:00
|
|
|
|
2008-01-20 16:39:21 +00:00
|
|
|
#include "debug_p.h"
|
|
|
|
|
2007-01-03 14:30:48 +00:00
|
|
|
using namespace Okular;
|
|
|
|
|
|
|
|
class TextSelection::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int direction;
|
|
|
|
int it[2];
|
|
|
|
NormalizedPoint cur[2];
|
|
|
|
};
|
|
|
|
|
2019-12-20 15:40:59 +00:00
|
|
|
TextSelection::TextSelection(const NormalizedPoint &start, const NormalizedPoint &end)
|
2007-01-03 14:30:48 +00:00
|
|
|
: d(new Private)
|
|
|
|
{
|
2019-12-20 15:40:59 +00:00
|
|
|
if (end.y - start.y < 0 || (end.y - start.y == 0 && end.x - start.x < 0)) {
|
2007-01-03 14:30:48 +00:00
|
|
|
d->direction = 1;
|
|
|
|
} else {
|
|
|
|
d->direction = 0;
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2007-01-03 14:30:48 +00:00
|
|
|
|
2019-12-20 15:40:59 +00:00
|
|
|
d->cur[0] = start;
|
|
|
|
d->cur[1] = end;
|
2007-01-03 14:30:48 +00:00
|
|
|
d->it[d->direction % 2] = -1;
|
|
|
|
d->it[(d->direction + 1) % 2] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextSelection::~TextSelection()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextSelection::end(const NormalizedPoint &p)
|
|
|
|
{
|
|
|
|
// changing direction as in 2b , assuming the bool->int conversion is correct
|
|
|
|
int dir1 = d->direction;
|
|
|
|
d->direction = (p.y - d->cur[0].y < 0 || (p.y - d->cur[0].y == 0 && p.x - d->cur[0].x < 0));
|
|
|
|
if (d->direction != dir1) {
|
2014-09-11 17:36:01 +00:00
|
|
|
qCDebug(OkularCoreDebug) << "changing direction in selection";
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2007-01-03 14:30:48 +00:00
|
|
|
|
|
|
|
d->cur[1] = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextSelection::itE(int p)
|
|
|
|
{
|
|
|
|
d->it[(d->direction + 1) % 2] = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextSelection::itB(int p)
|
|
|
|
{
|
|
|
|
d->it[(d->direction) % 2] = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TextSelection::direction() const
|
|
|
|
{
|
|
|
|
return d->direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
NormalizedPoint TextSelection::start() const
|
|
|
|
{
|
|
|
|
return d->cur[d->direction % 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
NormalizedPoint TextSelection::end() const
|
|
|
|
{
|
|
|
|
return d->cur[(d->direction + 1) % 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
int TextSelection::itB() const
|
|
|
|
{
|
|
|
|
return d->it[d->direction % 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
int TextSelection::itE() const
|
|
|
|
{
|
|
|
|
return d->it[(d->direction + 1) % 2];
|
|
|
|
}
|