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 
32  d->cur[0] = start;
33  d->cur[1] = end;
34  d->it[d->direction % 2] = -1;
35  d->it[(d->direction + 1) % 2] = -1;
36 }
37 
39 {
40  delete d;
41 }
42 
44 {
45  // changing direction as in 2b , assuming the bool->int conversion is correct
46  int dir1 = d->direction;
47  d->direction = (p.y - d->cur[0].y < 0 || (p.y - d->cur[0].y == 0 && p.x - d->cur[0].x < 0));
48  if (d->direction != dir1) {
49  qCDebug(OkularCoreDebug) << "changing direction in selection";
50  }
51 
52  d->cur[1] = p;
53 }
54 
55 void TextSelection::itE(int p)
56 {
57  d->it[(d->direction + 1) % 2] = p;
58 }
59 
60 void TextSelection::itB(int p)
61 {
62  d->it[(d->direction) % 2] = p;
63 }
64 
66 {
67  return d->direction;
68 }
69 
71 {
72  return d->cur[d->direction % 2];
73 }
74 
76 {
77  return d->cur[(d->direction + 1) % 2];
78 }
79 
80 int TextSelection::itB() const
81 {
82  return d->it[d->direction % 2];
83 }
84 
85 int TextSelection::itE() const
86 {
87  return d->it[(d->direction + 1) % 2];
88 }
NormalizedPoint end() const
Returns the end point of the selection.
Definition: misc.cpp:75
NormalizedPoint start() const
Returns the start point of the selection.
Definition: misc.cpp:70
double y
The normalized y coordinate.
Definition: area.h:171
The documentation to the global Okular namespace.
Definition: action.h:16
Q_SCRIPTABLE Q_NOREPLY void start()
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:65
double x
The normalized x coordinate.
Definition: area.h:166
~TextSelection()
Destroys the text selection.
Definition: misc.cpp:38
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Mar 23 2023 04:04:24 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.