예제 #1
0
void BookTextView::PositionIndicatorWithLabels::draw() {
    PositionIndicator::draw();

    const BookTextView& bookTextView = (const BookTextView&)textView();

    if (bookTextView.ShowTOCMarksOption.value()) {
        shared_ptr<ZLTextModel> contentsModelPtr = bookTextView.myContentsModel;
        if (!contentsModelPtr.isNull()) {
            ContentsModel &contentsModel = (ContentsModel&)*contentsModelPtr;
            const int marksNumber = contentsModel.paragraphsNumber();
            const size_t startIndex = startTextIndex();
            const size_t endIndex = endTextIndex();
            const std::vector<size_t> &textSizeVector = textSize();
            const int fullWidth = right() - left() - 1;
            const size_t startPosition = textSizeVector[startIndex];
            const size_t fullTextSize = textSizeVector[endIndex] - startPosition;
            const int bottom = this->bottom();
            const int top = this->top();
            for (int i = 0; i < marksNumber; ++i) {
                size_t reference = contentsModel.reference((ZLTextTreeParagraph*)contentsModel[i]);
                if ((startIndex < reference) && (reference < endIndex)) {
                    int position = left() + 2 + (int)
                                   (1.0 * fullWidth * (textSizeVector[reference] - startPosition) / fullTextSize);
                    context().drawLine(position, bottom, position, top);
                }
            }
        }
    }
}
예제 #2
0
bool ZLTextView::PositionIndicator::onStylusPress(int x, int y) {
	x = myTextView.visualX(x);

	const long bottom = this->bottom();
	const long top = this->top();
	const long left = this->left();
	const long right = this->right();

	if ((x < left) || (x > right) || (y < top) || (y > bottom)) {
		return false;
	}

	const std::vector<size_t> &textSizeVector = myTextView.myTextSize;
	if (textSizeVector.size() <= 1) {
		return true;
	}

	if (myTextView.endCursor().isNull()) {
		return false;
	}
	size_t fullTextSize = sizeOfTextBeforeParagraph(endTextIndex());
	size_t textSize = muldiv(fullTextSize, x - left + 1, right - left + 1);

	myTextView.gotoCharIndex(textSize);

	return true;
}
예제 #3
0
void ZLTextView::paint() {
	context().clear(backgroundColor());

	myTextAreaController.area().setOffsets(
		textArea().isRtl() ? rightMargin() : leftMargin(), topMargin() + headerHeight()
	);

	preparePaintInfo();

	if (textArea().isEmpty()) {
		return;
	}

	myTextAreaController.area().paint();

	shared_ptr<ZLTextPositionIndicatorInfo> indicatorInfo = this->indicatorInfo();
	if (!indicatorInfo.isNull()) {
		switch (indicatorInfo->type()) {
			default:
				break;
			case ZLTextPositionIndicatorInfo::PAGE_FOOTER:
				positionIndicator()->draw();
				break;
			case ZLTextPositionIndicatorInfo::PAGE_HEADER:
				paintHeader();
				break;
		}
	}

	if (myDoUpdateScrollbar && !indicatorInfo.isNull()) {
		myDoUpdateScrollbar = false;
		const std::size_t full = sizeOfTextBeforeParagraph(endTextIndex());
		const std::size_t from = sizeOfTextBeforeCursor(textArea().startCursor());
		const std::size_t to = sizeOfTextBeforeCursor(textArea().endCursor());

		bool showScrollbar =
			(indicatorInfo->type() == ZLTextPositionIndicatorInfo::OS_SCROLLBAR) &&
			(to - from < full);
		if (showScrollbar) {
			setScrollbarEnabled(VERTICAL, true);
			setScrollbarParameters(VERTICAL, full, from, to);
		} else {
			setScrollbarEnabled(VERTICAL, false);
		}
	}

	ZLTextParagraphCursorCache::cleanup();
}
예제 #4
0
std::string ZLTextView::PositionIndicator::textPositionString() const {
	std::string buffer;
	ZLStringUtil::appendNumber(buffer, 1 + sizeOfTextBeforeCursor(myTextView.endCursor()) / 2048);
	buffer += '/';
	ZLStringUtil::appendNumber(buffer, 1 + sizeOfTextBeforeParagraph(endTextIndex()) / 2048);

	return buffer;

	/*
	std::string buffer;

	const std::vector<size_t> &textSizeVector = myTextView.myTextSize;
	const size_t fullTextSize = textSizeVector[endTextIndex()] - textSizeVector[startTextIndex()];
	ZLStringUtil::appendNumber(buffer, 100 * sizeOfTextBeforeCursor(myTextView.endCursor()) / fullTextSize);

	return buffer + '%';
	*/
}
예제 #5
0
void BookTextView::paintHeader() const {
	const int unit = baseStyle()->fontSize() / 4;
	const int left = leftMargin();
	const int right = context().width() - rightMargin() - 1;
	const int bottom = topMargin() + unit * 4;
	context().setColor(color(ZLTextStyle::REGULAR_TEXT));
	context().setFont(baseStyle()->fontFamily(), unit * 3, false, true);
	context().drawLine(left, bottom, right, bottom);

	// TODO: use chapter name instead
	const std::string leftText = myBook->title();
	context().drawString(left, bottom - unit, leftText.c_str(), leftText.length(), false);

	std::string rightText;
	ZLStringUtil::appendNumber(rightText, 1 + sizeOfTextBeforeCursor(textArea().endCursor()) / 2048);
	rightText += '/';
	ZLStringUtil::appendNumber(rightText, 1 + sizeOfTextBeforeParagraph(endTextIndex()) / 2048);
	const std::size_t rightTextWidth = context().stringWidth(rightText.c_str(), rightText.length(), false);
	context().drawString(right - rightTextWidth, bottom - unit, rightText.c_str(), rightText.length(), false);
}
예제 #6
0
void ZLTextView::PositionIndicator::draw() {
	ZLTextBaseStyle &baseStyle = ZLTextStyleCollection::instance().baseStyle();

	ZLPaintContext &context = this->context();

	ZLTextWordCursor endCursor = myTextView.endCursor();
	bool isEndOfText = false;
	if (endCursor.isEndOfParagraph()) {
		isEndOfText = !endCursor.nextParagraph();
	}

	myExtraWidth = 0;
	if (myInfo.isTimeShown()) {
		drawExtraText(timeString());
	}
	if (myInfo.isBatteryShown()) {
		drawExtraText(batteryString());
	}
	if (myInfo.isTextPositionShown()) {
		drawExtraText(textPositionString());
	}

	const long bottom = this->bottom();
	const long top = this->top();
	const long left = this->left();
	const long right = this->right();

	if (left >= right) {
		return;
	}

	size_t fillWidth = right - left - 1;

	if (!isEndOfText) {
		fillWidth =
			muldiv(fillWidth, sizeOfTextBeforeCursor(myTextView.endCursor()), sizeOfTextBeforeParagraph(endTextIndex()));
	}

	context.setColor(baseStyle.RegularTextColorOption.value());
	context.setFillColor(myInfo.color());
	context.fillRectangle(myTextView.visualX(left + 1), top + 1, myTextView.visualX(left + fillWidth + 1), bottom - 1);
	context.drawLine(myTextView.visualX(left), top, myTextView.visualX(right), top);
	context.drawLine(myTextView.visualX(left), bottom, myTextView.visualX(right), bottom);
	context.drawLine(myTextView.visualX(left), bottom, myTextView.visualX(left), top);
	context.drawLine(myTextView.visualX(right), bottom, myTextView.visualX(right), top);
}
예제 #7
0
int ZLTextView::PositionIndicator::textPosition() const {
	return 100 * (1 + sizeOfTextBeforeCursor(myTextView.endCursor())) / (1 + sizeOfTextBeforeParagraph(endTextIndex()));
}
void ZLTextView::PositionIndicator::draw() {
	ZLPaintContext &context = this->context();

	ZLTextWordCursor endCursor = myTextView.textArea().endCursor();
	bool isEndOfText = false;
	if (endCursor.isEndOfParagraph()) {
		isEndOfText = !endCursor.nextParagraph();
	}

	myExtraWidth = 0;
	if (myInfo.isTimeShown()) {
		drawExtraText(timeString());
	}
	if (myInfo.isTextPositionShown()) {
		drawExtraText(textPositionString());
	}

	const long bottom = this->bottom();
	const long top = this->top();
	const long left = this->left();
	const long right = this->right();

	if (left >= right) {
		return;
	}

	size_t fillWidth = right - left - 1;

	if (!isEndOfText) {
		fillWidth =
			muldiv(fillWidth, sizeOfTextBeforeCursor(myTextView.textArea().endCursor()), sizeOfTextBeforeParagraph(endTextIndex()));
	}

	context.setColor(myTextView.color());
	context.setFillColor(myInfo.color());
	context.fillRectangle(left + 1, top + 1, left + fillWidth + 1, bottom - 1);
	context.drawLine(left, top, right, top);
	context.drawLine(left, bottom, right, bottom);
	context.drawLine(left, bottom, left, top);
	context.drawLine(right, bottom, right, top);
}