trwindow.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 1,877 行 · 第 1/5 页
CPP
1,877 行
void TrWindow::resetAltSource(){ altTranslatorModel->init(); altTranslatorModel->clearContextList(); altTranslatorModel->updateAll(); m_ui.actionResetAltSource->setEnabled(false); showMessages(tv->currentIndex());}void TrWindow::openAltSource( const QString& name ){ if (name.isEmpty()) return; statusBar()->showMessage(tr("Loading alternative translation...")); qApp->processEvents(); if (!altTranslatorModel->load(name)) { statusBar()->clearMessage(); QMessageBox::warning(this, tr("Qt Linguist"), tr("Cannot open '%1'.").arg(name)); return; } statusBar()->showMessage(tr("%n alternative translation(s) loaded.", 0, altTranslatorModel->getMessageCount()), MessageMS); m_ui.actionResetAltSource->setEnabled(true); QString lang = QLocale::languageToString(altTranslatorModel->language()); me->setAltTextLabel(QString(tr("Existing %1 translation")).arg(lang)); showMessages(tv->currentIndex());}void TrWindow::save(){ if (filename.isEmpty()) return; if (cmdl->save(filename)) { updateCaption(); statusBar()->showMessage(tr("File saved."), MessageMS); } else { QMessageBox::warning(this, tr("Qt Linguist"), tr("Cannot save '%1'.").arg(filename)); }}void TrWindow::saveAs(){ QString newFilename = QFileDialog::getSaveFileName(this, QString(), filename, tr( "Qt translation source (*.ts)\nXLIFF localization file (*.xlf)\nAll files (*)")); if (!newFilename.isEmpty()) { filename = newFilename; save(); updateCaption(); }}void TrWindow::releaseAs(){ QString newFilename = filename; newFilename.replace(QRegExp(QLatin1String(".ts$")), QLatin1String("")); newFilename += QString(QLatin1String(".qm")); newFilename = QFileDialog::getSaveFileName(this, tr("Release"), newFilename, tr("Qt message files for released applications (*.qm)\nAll files (*)")); 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)); }}// No-questionvoid TrWindow::release(){ QString newFilename = filename; newFilename.replace(QRegExp(QLatin1String(".ts$")), QLatin1String("")); newFilename += QString(QLatin1String(".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") : QLatin1String("unfinished"); break; case MetaTranslatorMessage::Obsolete: type = tr("obsolete"); break; default: type = QString(QLatin1String("")); } pout.addBox(40, m->sourceText()); pout.addBox(4); if (m->message().isPlural() && cmdl->language() != QLocale::C) { QStringList transls = m->translations(); pout.addBox(40, transls.join(QLatin1String("\n"))); } else { 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: if (searchItem(m->comment(), 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 {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?