[fbreader] Added optional arguments to ZLTextSelectionModel methods
... extendTo() and selectWord() to make it easier to implement selection by words.
This commit is contained in:
parent
c8bad41b7f
commit
6f6e037eb3
2 changed files with 28 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
|
* Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
|
||||||
|
* Copyright (C) 2016-2017 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -144,7 +145,7 @@ bool ZLTextSelectionModel::BoundElement::operator != (const ZLTextSelectionModel
|
||||||
return !operator == (element);
|
return !operator == (element);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZLTextSelectionModel::ExtensionResult ZLTextSelectionModel::extendTo(int x, int y) {
|
ZLTextSelectionModel::ExtensionResult ZLTextSelectionModel::extendTo(int x, int y, bool word) {
|
||||||
if (!myIsActive || myArea.myTextElementMap.empty()) {
|
if (!myIsActive || myArea.myTextElementMap.empty()) {
|
||||||
return BOUND_NOT_CHANGED;
|
return BOUND_NOT_CHANGED;
|
||||||
}
|
}
|
||||||
|
@ -155,6 +156,25 @@ ZLTextSelectionModel::ExtensionResult ZLTextSelectionModel::extendTo(int x, int
|
||||||
myStoredX = x;
|
myStoredX = x;
|
||||||
myStoredY = y;
|
myStoredY = y;
|
||||||
|
|
||||||
|
if (word) {
|
||||||
|
const bool swap = (mySecondBound < myFirstBound);
|
||||||
|
Bound &from = swap ? mySecondBound : myFirstBound;
|
||||||
|
Bound &to = swap ? myFirstBound : mySecondBound;
|
||||||
|
BoundElement &after = from.After;
|
||||||
|
BoundElement &before = to.Before;
|
||||||
|
ZLTextWordCursor cursor = myArea.startCursor();
|
||||||
|
cursor.moveToParagraph(before.ParagraphIndex);
|
||||||
|
cursor.moveTo(before.ElementIndex, before.CharIndex);
|
||||||
|
const ZLTextElement &element = cursor.element();
|
||||||
|
if (element.kind() == ZLTextElement::WORD_ELEMENT) {
|
||||||
|
const ZLTextWord &word = (const ZLTextWord&)element;
|
||||||
|
before.CharIndex = word.Length;
|
||||||
|
}
|
||||||
|
after.CharIndex = 0;
|
||||||
|
from.Before = after;
|
||||||
|
to.After = before;
|
||||||
|
}
|
||||||
|
|
||||||
ExtensionResult result = BOUND_NOT_CHANGED;
|
ExtensionResult result = BOUND_NOT_CHANGED;
|
||||||
if ((oldRange.first != newRange.first) || (oldRange.second != newRange.second)) {
|
if ((oldRange.first != newRange.first) || (oldRange.second != newRange.second)) {
|
||||||
myTextIsUpToDate = false;
|
myTextIsUpToDate = false;
|
||||||
|
@ -460,7 +480,7 @@ shared_ptr<ZLImageData> ZLTextSelectionModel::image() const {
|
||||||
return myImage;
|
return myImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZLTextSelectionModel::selectWord(int x, int y) {
|
bool ZLTextSelectionModel::selectWord(int x, int y, bool activate) {
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
const ZLTextElementRectangle *rectangle = myArea.elementByCoordinates(x, y);
|
const ZLTextElementRectangle *rectangle = myArea.elementByCoordinates(x, y);
|
||||||
|
@ -517,6 +537,9 @@ bool ZLTextSelectionModel::selectWord(int x, int y) {
|
||||||
mySecondBound.Before.CharIndex = endIndex;
|
mySecondBound.Before.CharIndex = endIndex;
|
||||||
mySecondBound.After = mySecondBound.Before;
|
mySecondBound.After = mySecondBound.Before;
|
||||||
|
|
||||||
|
myStoredX = x;
|
||||||
|
myStoredY = y;
|
||||||
|
myIsActive = activate;
|
||||||
myIsEmpty = false;
|
myIsEmpty = false;
|
||||||
myTextIsUpToDate = false;
|
myTextIsUpToDate = false;
|
||||||
myRangeVectorIsUpToDate = false;
|
myRangeVectorIsUpToDate = false;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
|
* Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
|
||||||
|
* Copyright (C) 2016-2017 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -58,13 +59,13 @@ public:
|
||||||
BOUND_OVER_BEFORE,
|
BOUND_OVER_BEFORE,
|
||||||
BOUND_OVER_AFTER
|
BOUND_OVER_AFTER
|
||||||
};
|
};
|
||||||
ExtensionResult extendTo(int x, int y);
|
ExtensionResult extendTo(int x, int y, bool word = false);
|
||||||
void invalidate();
|
void invalidate();
|
||||||
void update();
|
void update();
|
||||||
void deactivate();
|
void deactivate();
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
bool selectWord(int x, int y);
|
bool selectWord(int x, int y, bool activate = false);
|
||||||
void extendWordSelectionToParagraph();
|
void extendWordSelectionToParagraph();
|
||||||
|
|
||||||
const std::string &text() const;
|
const std::string &text() const;
|
||||||
|
|
Loading…
Reference in a new issue