void ZLTextView::setModel(shared_ptr<ZLTextModel> model, const std::string &language) { clear(); myModel = model; myLanguage = language.empty() ? ZLibrary::Language() : language; myStyle.setBaseBidiLevel(ZLLanguageUtil::isRTLLanguage(myLanguage) ? 1 : 0); if (!myModel.isNull() && (myModel->paragraphsNumber() != 0)) { setStartCursor(ZLTextParagraphCursor::cursor(*myModel, myLanguage)); size_t size = myModel->paragraphsNumber(); myTextSize.reserve(size + 1); myTextSize.push_back(0); size_t currentSize = 0; for (size_t i= 0; i < size; ++i) { const ZLTextParagraph ¶ = *(*myModel)[i]; currentSize += para.characterNumber(); switch (para.kind()) { case ZLTextParagraph::END_OF_TEXT_PARAGRAPH: myTextBreaks.push_back(i); currentSize = ((currentSize - 1) / 2048 + 1) * 2048; break; case ZLTextParagraph::END_OF_SECTION_PARAGRAPH: currentSize = ((currentSize - 1) / 2048 + 1) * 2048; break; default: break; } myTextSize.push_back(currentSize); } } }
void ZLTextView::setModel(shared_ptr<ZLTextModel> model) { clear(); myModel = model; if (!myModel.isNull() && (myModel->paragraphsNumber() != 0)) { setStartCursor(ZLTextParagraphCursor::cursor(*myModel)); size_t size = myModel->paragraphsNumber(); myTextSize.reserve(size + 1); myTextSize.push_back(0); for (size_t i= 0; i < size; ++i) { myTextSize.push_back(myTextSize.back() + (*myModel)[i]->textLength()); if ((*myModel)[i]->kind() == ZLTextParagraph::END_OF_TEXT_PARAGRAPH) { myTextBreaks.push_back(i); } } } }
void CollectionView::removeBook(BookDescriptionPtr book) { if (book.isNull()) { return; } if (book == mySelectedBook) { mySelectedBook = 0; } CollectionModel &cModel = collectionModel(); ZLResourceKey boxKey("removeBookBox"); const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), book->title()); if (ZLDialogManager::instance().questionBox(boxKey, message, ZLDialogManager::YES_BUTTON, ZLDialogManager::NO_BUTTON) == 0) { cModel.removeAllMarks(); BookList().removeFileName(book->fileName()); cModel.removeBook(book); if (cModel.paragraphsNumber() == 0) { setStartCursor(0); } else { size_t index = startCursor().paragraphCursor().index(); if (index >= cModel.paragraphsNumber()) { index = cModel.paragraphsNumber() - 1; } while (!((ZLTextTreeParagraph*)cModel[index])->parent()->isOpen()) { --index; } gotoParagraph(index); } rebuildPaintInfo(true); selectBook(mySelectedBook); application().refreshWindow(); myCollection.rebuild(false); } }