void ZLTextView::scrollToStartOfText() { if (endCursor().isNull()) { return; } if (!startCursor().isNull() && startCursor().isStartOfParagraph() && startCursor().paragraphCursor().isFirst()) { return; } std::vector<size_t>::const_iterator i = nextBreakIterator(); gotoParagraph((i != myTextBreaks.begin()) ? *(i - 1) : 0, false); application().refreshWindow(); }
QRect PersistentState::selectionRect() { if (!_persistentCursor.isNull() && _persistentCursor.hasSelection()) { QTextCursor startCursor(editor()->document()); QTextCursor endCursor(editor()->document()); startCursor.setPosition(_persistentCursor.selectionStart()); endCursor.setPosition(_persistentCursor.selectionEnd()); QRect rect = editor()->cursorRect(startCursor).unite(editor()->cursorRect(endCursor)); if (rect.height() > editor()->fontMetrics().height()) { rect.setX(0); rect.setWidth(editor()->width()); } return rect; } return QRect(); }
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); } } } }
size_t ZLTextView::pageIndex() { if (empty() || positionIndicator().isNull() || endCursor().isNull()) { return 0; } return positionIndicator()->sizeOfTextBeforeCursor(endCursor()) / 2048 + 1; }
bool ZLTextView::onStylusPress(int x, int y) { myDoubleClickInfo.update(x, y, true); if (myDoubleClickInfo.Count > 10) { return true; } mySelectionModel.deactivate(); if (myModel.isNull()) { return false; } shared_ptr<ZLTextPositionIndicatorInfo> indicatorInfo = this->indicatorInfo(); if (!indicatorInfo.isNull() && (indicatorInfo->type() == ZLTextPositionIndicatorInfo::FB_INDICATOR) && indicatorInfo->isSensitive()) { myTreeStateIsFrozen = true; bool indicatorAnswer = positionIndicator()->onStylusPress(x, y); myTreeStateIsFrozen = false; if (indicatorAnswer) { application().refreshWindow(); return true; } } if (myModel->kind() == ZLTextModel::TREE_MODEL) { ZLTextTreeNodeMap::const_iterator it = std::find_if(myTreeNodeMap.begin(), myTreeNodeMap.end(), ZLTextTreeNodeArea::RangeChecker(x, y)); if (it != myTreeNodeMap.end()) { int paragraphIndex = it->ParagraphIndex; ZLTextTreeParagraph *paragraph = (ZLTextTreeParagraph*)(*myModel)[paragraphIndex]; paragraph->open(!paragraph->isOpen()); rebuildPaintInfo(true); preparePaintInfo(); if (paragraph->isOpen()) { int nextParagraphIndex = paragraphIndex + paragraph->fullSize(); int lastParagraphIndex = endCursor().paragraphCursor().index(); if (endCursor().isEndOfParagraph()) { ++lastParagraphIndex; } if (lastParagraphIndex < nextParagraphIndex) { gotoParagraph(nextParagraphIndex, true); preparePaintInfo(); } } int firstParagraphIndex = startCursor().paragraphCursor().index(); if (startCursor().isStartOfParagraph()) { --firstParagraphIndex; } if (firstParagraphIndex >= paragraphIndex) { gotoParagraph(paragraphIndex); preparePaintInfo(); } application().refreshWindow(); return true; } } return false; }
void ZLTextView::findNext() { if (!endCursor().isNull()) { gotoMark(myModel->nextMark(endCursor().position())); } }
bool ZLTextView::canFindNext() const { return !endCursor().isNull() && (myModel->nextMark(endCursor().position()).ParagraphIndex > -1); }