Clean up TextSelection and remove unused parts

This commit is contained in:
Sune Vuorela 2024-03-04 14:14:08 +01:00 committed by Albert Astals Cid
parent 239be78930
commit 8bcafd80bb
2 changed files with 3 additions and 77 deletions

View File

@ -16,12 +16,11 @@ class TextSelection::Private
{
public:
int direction;
int it[2];
NormalizedPoint cur[2];
};
TextSelection::TextSelection(const NormalizedPoint &start, const NormalizedPoint &end)
: d(new Private)
: d(std::make_unique<Private>())
{
if (end.y - start.y < 0 || (end.y - start.y == 0 && end.x - start.x < 0)) {
d->direction = 1;
@ -31,41 +30,9 @@ TextSelection::TextSelection(const NormalizedPoint &start, const NormalizedPoint
d->cur[0] = start;
d->cur[1] = end;
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) {
qCDebug(OkularCoreDebug) << "changing direction in selection";
}
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;
}
TextSelection::~TextSelection() = default;
NormalizedPoint TextSelection::start() const
{
@ -76,13 +43,3 @@ 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];
}

View File

@ -14,21 +14,6 @@ namespace Okular
{
/**
@short Wrapper around the information needed to generate the selection area
There are two assumptions inside this class:
1. the start never changes, one instance of this class is used for one selection,
therefore the start of the selection will not change, only end and direction of
the selection will change.
By direction we mean the direction in which the end moves in relation to the start,
forward selection is when end is after the start, backward when its before.
2. The following changes might appear during selection:
a. the end moves without changing the direction (it can move up and down but not past the start):
only itE will be updated
b. the end moves with changing the direction then itB becomes itE if the previous direction was forward
or itE becomes itB
3. Internally it that is related to the start cursor is always at it[0] while it related to end is it[1],
transition between meanings (itB/itE) is done with dir modifier;
*/
class OKULARCORE_EXPORT TextSelection
{
@ -46,19 +31,6 @@ public:
TextSelection(const TextSelection &) = delete;
TextSelection &operator=(const TextSelection &) = delete;
/**
* Changes the end point of the selection to the given @p point.
*/
void end(const NormalizedPoint &point);
void itE(int pos);
void itB(int pos);
/**
* Returns the direction of the selection.
*/
int direction() const;
/**
* Returns the start point of the selection.
*/
@ -69,12 +41,9 @@ public:
*/
NormalizedPoint end() const;
int itB() const;
int itE() const;
private:
class Private;
Private *const d;
std::unique_ptr<Private> d;
};
}