File indexing completed on 2024-04-28 04:32:43
0001 /* 0002 SPDX-FileCopyrightText: 2005 Piotr Szymanski <niedakh@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "core/misc.h" 0008 0009 #include <QDebug> 0010 0011 #include "debug_p.h" 0012 0013 using namespace Okular; 0014 0015 class TextSelection::Private 0016 { 0017 public: 0018 int direction; 0019 int it[2]; 0020 NormalizedPoint cur[2]; 0021 }; 0022 0023 TextSelection::TextSelection(const NormalizedPoint &start, const NormalizedPoint &end) 0024 : d(new Private) 0025 { 0026 if (end.y - start.y < 0 || (end.y - start.y == 0 && end.x - start.x < 0)) { 0027 d->direction = 1; 0028 } else { 0029 d->direction = 0; 0030 } 0031 0032 d->cur[0] = start; 0033 d->cur[1] = end; 0034 d->it[d->direction % 2] = -1; 0035 d->it[(d->direction + 1) % 2] = -1; 0036 } 0037 0038 TextSelection::~TextSelection() 0039 { 0040 delete d; 0041 } 0042 0043 void TextSelection::end(const NormalizedPoint &p) 0044 { 0045 // changing direction as in 2b , assuming the bool->int conversion is correct 0046 int dir1 = d->direction; 0047 d->direction = (p.y - d->cur[0].y < 0 || (p.y - d->cur[0].y == 0 && p.x - d->cur[0].x < 0)); 0048 if (d->direction != dir1) { 0049 qCDebug(OkularCoreDebug) << "changing direction in selection"; 0050 } 0051 0052 d->cur[1] = p; 0053 } 0054 0055 void TextSelection::itE(int p) 0056 { 0057 d->it[(d->direction + 1) % 2] = p; 0058 } 0059 0060 void TextSelection::itB(int p) 0061 { 0062 d->it[(d->direction) % 2] = p; 0063 } 0064 0065 int TextSelection::direction() const 0066 { 0067 return d->direction; 0068 } 0069 0070 NormalizedPoint TextSelection::start() const 0071 { 0072 return d->cur[d->direction % 2]; 0073 } 0074 0075 NormalizedPoint TextSelection::end() const 0076 { 0077 return d->cur[(d->direction + 1) % 2]; 0078 } 0079 0080 int TextSelection::itB() const 0081 { 0082 return d->it[d->direction % 2]; 0083 } 0084 0085 int TextSelection::itE() const 0086 { 0087 return d->it[(d->direction + 1) % 2]; 0088 }