void ZLTextView::gotoParagraph(int num, bool end) { if (myModel.isNull()) { return; } if (!startCursor().isNull() && startCursor().isStartOfParagraph() && startCursor().paragraphCursor().isFirst() && (num >= (int)startCursor().paragraphCursor().index()) && !endCursor().isNull() && endCursor().isEndOfParagraph() && endCursor().paragraphCursor().isLast() && (num <= (int)endCursor().paragraphCursor().index())) { return; } if (myModel->kind() == ZLTextModel::TREE_MODEL) { if ((num >= 0) && (num < (int)myModel->paragraphsNumber())) { ZLTextTreeParagraph *tp = (ZLTextTreeParagraph*)(*myModel)[num]; if (myTreeStateIsFrozen) { int corrected = num; ZLTextTreeParagraph *visible = tp; for (ZLTextTreeParagraph *parent = tp->parent(); parent != 0; parent = parent->parent()) { if (!parent->isOpen()) { visible = parent; } } if (visible != tp) { for (--corrected; ((corrected > 0) && visible != (*myModel)[corrected]); --corrected) { } } if (end && (corrected != num)) { ++corrected; } num = corrected; } else { tp->openTree(); rebuildPaintInfo(true); } } } if (end) { if ((num > 0) && (num <= (int)myModel->paragraphsNumber())) { moveEndCursor(num); } } else { if ((num >= 0) && (num < (int)myModel->paragraphsNumber())) { moveStartCursor(num); } } }
void ZLTextView::gotoPage(size_t index) { const size_t symbolIndex = index * 2048 - 128; std::vector<size_t>::const_iterator it = std::lower_bound(myTextSize.begin(), myTextSize.end(), symbolIndex); std::vector<size_t>::const_iterator i = nextBreakIterator(); const size_t startIndex = (i != myTextBreaks.begin()) ? *(i - 1) : 0; const size_t endIndex = (i != myTextBreaks.end()) ? *i : myModel->paragraphsNumber(); size_t paragraphNumber = std::min((size_t)(it - myTextSize.begin()), endIndex) - 1; gotoParagraph(paragraphNumber, true); preparePaintInfo(); const ZLTextWordCursor &cursor = endCursor(); if (!cursor.isNull() && (paragraphNumber == cursor.paragraphCursor().index())) { if (!cursor.paragraphCursor().isLast() || !cursor.isEndOfParagraph()) { size_t paragraphLength = cursor.paragraphCursor().paragraphLength(); if (paragraphLength > 0) { size_t wordNum = (myTextSize[startIndex] + symbolIndex - myTextSize[paragraphNumber]) * paragraphLength / (myTextSize[endIndex] - myTextSize[startIndex]); moveEndCursor(cursor.paragraphCursor().index(), wordNum, 0); } } } }
void ZLTextView::gotoParagraph(int num, bool last) { if (myModel.isNull()) { return; } if (myModel->kind() == ZLTextModel::TREE_MODEL) { if ((num >= 0) && (num < (int)myModel->paragraphsNumber())) { ZLTextTreeParagraph *tp = (ZLTextTreeParagraph*)(*myModel)[num]; if (myTreeStateIsFrozen) { int corrected = num; ZLTextTreeParagraph *parent = tp->parent(); while ((corrected > 0) && (parent != 0) && !parent->isOpen()) { for (--corrected; ((corrected > 0) && parent != (*myModel)[corrected]); --corrected); parent = parent->parent(); } if (last && (corrected != num)) { ++corrected; } num = corrected; } else { tp->openTree(); rebuildPaintInfo(true); } } } if (last) { if ((num > 0) && (num <= (int)myModel->paragraphsNumber())) { moveEndCursor(num); } } else { if ((num >= 0) && (num < (int)myModel->paragraphsNumber())) { moveStartCursor(num); } } }