Okular

misc.cpp
1 /*
2  SPDX-FileCopyrightText: 2005 Piotr Szymanski <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "core/misc.h"
8 
9 #include <QDebug>
10 
11 #include "debug_p.h"
12 
13 using namespace Okular;
14 
15 class TextSelection::Private
16 {
17 public:
18  int direction;
19  int it[2];
20  NormalizedPoint cur[2];
21 };
22 
24  : d(new Private)
25 {
26  if (end.y - start.y < 0 || (end.y - start.y == 0 && end.x - start.x < 0))
27  d->direction = 1;
28  else
29  d->direction = 0;
30 
31  d->cur[0] = start;
32  d->cur[1] = end;
33  d->it[d->direction % 2] = -1;
34  d->it[(d->direction + 1) % 2] = -1;
35 }
36 
38 {
39  delete d;
40 }
41 
43 {
44  // changing direction as in 2b , assuming the bool->int conversion is correct
45  int dir1 = d->direction;
46  d->direction = (p.y - d->cur[0].y < 0 || (p.y - d->cur[0].y == 0 && p.x - d->cur[0].x < 0));
47  if (d->direction != dir1)
48  qCDebug(OkularCoreDebug) << "changing direction in selection";
49 
50  d->cur[1] = p;
51 }
52 
53 void TextSelection::itE(int p)
54 {
55  d->it[(d->direction + 1) % 2] = p;
56 }
57 
58 void TextSelection::itB(int p)
59 {
60  d->it[(d->direction) % 2] = p;
61 }
62 
64 {
65  return d->direction;
66 }
67 
69 {
70  return d->cur[d->direction % 2];
71 }
72 
74 {
75  return d->cur[(d->direction + 1) % 2];
76 }
77 
78 int TextSelection::itB() const
79 {
80  return d->it[d->direction % 2];
81 }
82 
83 int TextSelection::itE() const
84 {
85  return d->it[(d->direction + 1) % 2];
86 }
NormalizedPoint is a helper class which stores the coordinates of a normalized point.
Definition: area.h:116
TextSelection(const NormalizedPoint &start, const NormalizedPoint &end)
Creates a new text selection with the given start and end point.
Definition: misc.cpp:23
int direction() const
Returns the direction of the selection.
Definition: misc.cpp:63
~TextSelection()
Destroys the text selection.
Definition: misc.cpp:37
double y
The normalized y coordinate.
Definition: area.h:172
global.h
Definition: action.h:16
NormalizedPoint start() const
Returns the start point of the selection.
Definition: misc.cpp:68
NormalizedPoint end() const
Returns the end point of the selection.
Definition: misc.cpp:73
double x
The normalized x coordinate.
Definition: area.h:167
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Dec 6 2021 22:32:17 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.