📄 trwindow.cpp
字号:
{ QString newFilename = filename; newFilename.replace(QRegExp(".ts$"), ""); newFilename += QString(".qm"); if (!newFilename.isEmpty()) { if (cmdl->release(newFilename, false, false, Translator::Everything)) statusBar()->showMessage(tr("File created."), MessageMS); else QMessageBox::warning(this, tr("Qt Linguist"), tr("Cannot save '%1'.").arg(newFilename)); }}void TrWindow::print(){ int pageNum = 0; QList <ContextItem *> ctxtList; QList <MessageItem *> msgList; const MessageItem *m; ContextItem *c; QPrintDialog dlg(&printer, this); if (dlg.exec()) { QApplication::setOverrideCursor(Qt::WaitCursor); printer.setDocName(filename); statusBar()->showMessage(tr("Printing...")); PrintOut pout(&printer); ctxtList = cmdl->contextList(); for (int i=0; i<ctxtList.count(); i++) { c = ctxtList.at(i); pout.vskip(); pout.setRule(PrintOut::ThickRule); pout.setGuide(c->context()); pout.addBox(100, tr("Context: %1").arg(c->context()), PrintOut::Strong); pout.flushLine(); pout.addBox(4); pout.addBox(92, c->comment(), PrintOut::Emphasis); pout.flushLine(); pout.setRule(PrintOut::ThickRule); msgList = c->messageItemList(); for (int j=0; j<msgList.count(); j++) { m = msgList.at(j); pout.setRule(PrintOut::ThinRule); QString type; switch (m->message().type()) { case MetaTranslatorMessage::Finished: type = tr("finished"); break; case MetaTranslatorMessage::Unfinished: type = m->danger() ? tr("unresolved") : QString("unfinished"); break; case MetaTranslatorMessage::Obsolete: type = tr("obsolete"); break; default: type = QString(""); } pout.addBox(40, m->sourceText()); pout.addBox(4); pout.addBox(40, m->translation()); pout.addBox(4); pout.addBox(12, type, PrintOut::Normal, Qt::AlignRight); if (!m->comment().isEmpty()) { pout.flushLine(); pout.addBox(4); pout.addBox(92, m->comment(), PrintOut::Emphasis); } pout.flushLine(true); if (pout.pageNum() != pageNum) { pageNum = pout.pageNum(); statusBar()->showMessage(tr("Printing... (page %1)") .arg(pageNum)); } } } pout.flushLine(true); QApplication::restoreOverrideCursor(); statusBar()->showMessage(tr("Printing completed"), MessageMS); } else { statusBar()->showMessage(tr("Printing aborted"), MessageMS); }}void TrWindow::find(){ finddlg->show(); finddlg->activateWindow(); finddlg->raise();}void TrWindow::findAgain(){ if (cmdl->contextsInList() <= 0) return; int pass = 0; int scopeNo = 0; int itemNo = 0; QModelIndex indxItem = tv->currentIndex(); if (indxItem.isValid()) itemNo = indxItem.row(); QModelIndex indxScope = tv->currentIndex().parent(); if (indxScope.isValid()) scopeNo = indxScope.row(); QString delayedMsg; //scopeNo = foundScope; ContextItem *c = cmdl->contextItem(cmdl->index(scopeNo, 1)); MessageItem *m; // = c->messageItem(foundItem);#if 1 /* As long as we don't implement highlighting of the text in the QTextView, we may have only one match per message. */ foundOffset = (int) 0x7fffffff;#else foundOffset++;#endif // We want to search the scope we started from *again*, since we did not necessarily search that *completely* when we started. // (Problaby we started somewhere in the middle of it.) // Therefore, "pass <=" and not "pass < " while (pass <= cmdl->contextsInList()) { for (int mit = itemNo; mit < c->messageItemsInList() ; ++mit) { m = c->messageItem(mit); switch (foundWhere) { case 0: foundWhere = FindDialog::SourceText; foundOffset = 0; // fall-through case FindDialog::SourceText: if (searchItem(m->sourceText(), scopeNo, mit)) { finddlg->hide(); if (!delayedMsg.isEmpty()) statusBar()->showMessage(delayedMsg, MessageMS); return; } foundWhere = FindDialog::Translations; foundOffset = 0; // fall-through case FindDialog::Translations: if (searchItem(m->translation(), scopeNo, mit)) { finddlg->hide(); if (!delayedMsg.isEmpty()) statusBar()->showMessage(delayedMsg, MessageMS); return; } foundWhere = FindDialog::Comments; foundOffset = 0; // fall-through case FindDialog::Comments: // what about comments in messages? if (searchItem(c->fullContext(), scopeNo, mit)) { finddlg->hide(); if (!delayedMsg.isEmpty()) statusBar()->showMessage(delayedMsg, MessageMS); return; } foundWhere = 0; foundOffset = 0; } } itemNo = 0; ++pass; ++scopeNo; if (scopeNo >= cmdl->contextsInList()) { scopeNo = 0; delayedMsg = tr("Search wrapped."); } c = cmdl->contextItem(cmdl->index(scopeNo, 1)); } qApp->beep(); QMessageBox::warning( finddlg, tr("Qt Linguist"), QString( tr("Cannot find the string '%1'.") ).arg(findText));// foundItem = 0; foundWhere = 0; foundOffset = 0;}void TrWindow::showTranslateDialog(){ m_translatedlg->show(); m_translatedlg->activateWindow(); m_translatedlg->raise();}void TrWindow::showBatchTranslateDialog(){ QList<PhraseBook> frasebooks = phraseBooks[PhraseEditMenu].values(); m_batchTranslateDlg->setPhraseBooks(frasebooks); m_batchTranslateDlg->exec(); }void TrWindow::translateAndFindNext(const QString& findWhat, const QString &translateTo, int matchOption, int mode, bool markFinished){ findText = findWhat; m_translateTo = translateTo; findMatchCase = matchOption & TranslateDialog::MatchCase; m_markFinished = markFinished; m_findMatchSubstring = false; translate(mode);}void TrWindow::translate(int mode){ int itemNo = 0; int scopeNo = 0; QModelIndex indxItem = tv->currentIndex(); if (indxItem.isValid()) itemNo = indxItem.row(); // The for-loop condition for the ContextItem will rule this potential overflow on itemNo QModelIndex indxScope = tv->currentIndex().parent(); if (indxScope.isValid()) { scopeNo = indxScope.row(); }else{ scopeNo = itemNo; itemNo = 0; } int translatedCount = 0; bool found = false; MessageModel::iterator it = cmdl->Iterator(scopeNo, itemNo); switch (mode) { case TranslateDialog::TranslateAll: { int passes = cmdl->getMessageCount(); while (passes > 0) { MessageItem *m = it.current(); if (!m) { it.reset(); m = it.current(); } if (m && m->compare(findText, m_findMatchSubstring, findMatchCase ? Qt::CaseSensitive : Qt::CaseInsensitive)) { cmdl->setTranslation(it, m_translateTo); if (indxScope.isValid() && it.contextNo() == scopeNo && it.messageNo() == itemNo) me->setTranslation(m_translateTo, 0, false); updateFinished(it.contextNo(), it.messageNo(), m_markFinished); ++translatedCount; } ++it; --passes; } found = translatedCount == 0 ? false : true; if (found) { QMessageBox::warning( m_translatedlg, tr("Translate"), QString( tr("Translated %n entries to '%1'", 0, translatedCount).arg(m_translateTo) )); } } break; case TranslateDialog::Translate: { MessageItem *m = it.current(); if (m && m->compare(findText, m_findMatchSubstring, findMatchCase ? Qt::CaseSensitive : Qt::CaseInsensitive)) { cmdl->setTranslation(it, m_translateTo); updateFinished(it.contextNo(), it.messageNo(), m_markFinished); ++translatedCount; } } case TranslateDialog::Skip: { ++it; int passes = cmdl->getMessageCount() - 1; while (passes > 0) { MessageItem *m = it.current(); if (!m) { it.reset(); m = it.current(); } if (m && m->compare(findText, m_findMatchSubstring, findMatchCase ? Qt::CaseSensitive : Qt::CaseInsensitive)) { found = true; break; } ++it; --passes; } } break; } if (found) { QModelIndex cidx = cmdl->index(it.contextNo(),0); if (cidx.isValid()) { setCurrentMessage(cmdl->index(it.messageNo(),0, cidx)); } } else { qApp->beep(); QMessageBox::warning( m_translatedlg, tr("Qt Linguist"), QString( tr("Cannot find the string '%1'.") ).arg(findText) ); }}bool TrWindow::searchItem(const QString &searchWhat, int c, int m){ if ((findWhere & foundWhere) != 0) { foundOffset = searchWhat.indexOf(findText, foundOffset, findMatchCase ? Qt::CaseSensitive : Qt::CaseInsensitive); if (foundOffset >= 0) { QModelIndex cidx = cmdl->index(c,0); setCurrentMessage(cmdl->index(m,0, cidx)); return true; } } foundOffset = 0; return false;}void TrWindow::newPhraseBook(){ QString name; for (;;) { name = QFileDialog::getSaveFileName(this, tr("Create New Phrase Book"), QString(), tr("Qt phrase books (*.qph)\nAll files (*)")); if (name.isEmpty()) break; else if (!QFile::exists(name)) { break; QMessageBox::warning(this, tr("Qt Linguist"), tr("A file called '%1' already exists." " Please choose another name.").arg(name)); } } if (!name.isEmpty()) { PhraseBook pb; if (savePhraseBook(name, pb)) { if (openPhraseBook(name)) statusBar()->showMessage(tr("Phrase book created."), MessageMS); } }}bool TrWindow::phraseBooksContains(QString name){ foreach(PhraseBook pb, phraseBooks[PhraseCloseMenu]) { if (pb.fileName() == name) return true; } return false;}PhraseBook TrWindow::phraseBookFromFileName(QString name) const{ foreach(PhraseBook pb, phraseBooks[PhraseCloseMenu]) { if (pb.fileName() == name) return pb; } return PhraseBook(); // empty phrasebook}void TrWindow::openPhraseBook(){ QString phrasebooks(QLibraryInfo::location(QLibraryInfo::DataPath)); QString name = QFileDialog::getOpenFileName(this, tr("Open Phrase Book"), phrasebooks + "/phrasebooks", tr("Qt phrase books (*.qph)\nAll files (*)")); //### The phrasebooks are not stored here!! if (!name.isEmpty() && !phraseBooksContains(name)) { if (openPhraseBook(name)) { int n = phraseBookFromFileName(name).count(); statusBar()->showMessage(tr("%n phrase(s) loaded.", 0, n), MessageMS); } }}void TrWindow::closePhraseBook(QAction *action){ PhraseBook pb = phraseBooks[PhraseCloseMenu].value(action); phraseBooks[PhraseCloseMenu].remove(action); m_ui.menuClosePhraseBook->removeAction(action); QAction *act = phraseBooks[PhraseEditMenu].key(pb); phraseBooks[PhraseEditMenu].remove(act); m_ui.menuEditPhraseBook->removeAction(act); act = phraseBooks[PhrasePrintMenu].key(pb);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -