コード例 #1
0
ファイル: ZLTextView.cpp プロジェクト: mhuber/fbreader
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();
}
コード例 #2
0
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();
}
コード例 #3
0
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);
            }
        }
    }
}
コード例 #4
0
ファイル: ZLTextView.cpp プロジェクト: mhuber/fbreader
size_t ZLTextView::pageIndex() {
    if (empty() || positionIndicator().isNull() || endCursor().isNull()) {
        return 0;
    }
    return positionIndicator()->sizeOfTextBeforeCursor(endCursor()) / 2048 + 1;
}
コード例 #5
0
ファイル: ZLTextView.cpp プロジェクト: mhuber/fbreader
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;
}
コード例 #6
0
ファイル: ZLTextView.cpp プロジェクト: mhuber/fbreader
void ZLTextView::findNext() {
    if (!endCursor().isNull()) {
        gotoMark(myModel->nextMark(endCursor().position()));
    }
}
コード例 #7
0
ファイル: ZLTextView.cpp プロジェクト: mhuber/fbreader
bool ZLTextView::canFindNext() const {
    return !endCursor().isNull() && (myModel->nextMark(endCursor().position()).ParagraphIndex > -1);
}