📄 trwindow.cpp
字号:
curMessage = mmdl->contextItem()->messageItemsInList(); if (setPrevMessage(&curMessage, checkUnfinished)) return true; // found it! } // search all the messages in all the contexts, from bottom curContext = cmdl->contextsInList(); while (setPrevContext(&curContext, checkUnfinished)) { curMessage = mmdl->contextItem()->messageItemsInList(); if (setPrevMessage(&curMessage, checkUnfinished)) return true; // found it! } return false;}bool TrWindow::next(bool checkUnfinished){ int curContext = findCurrentContextRow(); int curMessage = findCurrentMessageRow(); if ((curMessage != -2) && setNextMessage(&curMessage, checkUnfinished)) return true; // found it! // search the other contexts while (setNextContext(&curContext, checkUnfinished)) { curMessage = -1; if (setNextMessage(&curMessage, checkUnfinished)) return true; // found it! } // search all the messages in all the contexts, from top curContext = -1; while (setNextContext(&curContext, checkUnfinished)) { curMessage = -1; if (setNextMessage(&curMessage, checkUnfinished)) return true; // found it! } return false;}void TrWindow::next(){ next(false);}void TrWindow::findNext(const QString &text, int where, bool matchCase){ findText = text; if (findText.isEmpty()) findText = QString("magicwordthatyoushouldavoid"); findWhere = where; findMatchCase = matchCase; findAgainAct->setEnabled(true); findAgain();}void TrWindow::revalidate(){ if (cmdl->contextsInList() <= 0) return; ContextItem *c; MessageItem *m; for (int ci=0; ci<cmdl->contextsInList(); ++ci) { c = cmdl->contextItem(cmdl->index(ci, 0)); for (int mi=0; mi<c->messageItemsInList(); ++mi) { m = c->messageItem(mi); updateDanger(m); if (mmdl->contextItem() == c) mmdl->updateItem(mmdl->index(mi, 0)); } cmdl->updateItem(cmdl->index(ci, 0)); }}QString TrWindow::friendlyString(const QString& str){ QString f = str.toLower(); f.replace(QRegExp(QString("[.,:;!?()-]")), QString(" ")); f.replace("&", QString("")); f = f.simplified(); f = f.toLower(); return f;}void TrWindow::setupMenuBar(){ QMenuBar *m = menuBar(); QMenu *filep = new QMenu(this); QMenu *editp = new QMenu(this); QMenu *translationp = new QMenu(this); QMenu *validationp = new QMenu(this); phrasep = new QMenu(this); closePhraseBookp = new QMenu(this); editPhraseBookp = new QMenu(this); printPhraseBookp = new QMenu(this); QMenu *viewp = new QMenu(this); QMenu *helpp = new QMenu(this); m->addMenu(filep)->setText(tr("&File")); m->addMenu(editp)->setText(tr("&Edit")); m->addMenu(translationp)->setText(tr("&Translation")); m->addMenu(validationp)->setText(tr("V&alidation")); m->addMenu(phrasep)->setText(tr("&Phrases")); m->addMenu(viewp)->setText(tr("&View")); m->addMenu(helpp)->setText(tr("&Help")); connect(closePhraseBookp, SIGNAL(triggered(QAction*)), this, SLOT(closePhraseBook(QAction*))); connect(editPhraseBookp, SIGNAL(triggered(QAction*)), this, SLOT(editPhraseBook(QAction*))); connect(printPhraseBookp, SIGNAL(triggered(QAction*)), this, SLOT(printPhraseBook(QAction*))); // File menu openAct = filep->addAction(QIcon(rsrcString + "/fileopen.png"), tr("&Open..."), this, SLOT(open())); openAct->setShortcut(QKeySequence("Ctrl+O")); filep->addSeparator(); saveAct = filep->addAction(QIcon(rsrcString + "/filesave.png"), tr("&Save"), this, SLOT(save())); saveAct->setShortcut(QKeySequence("Ctrl+S")); saveAsAct = filep->addAction(tr("Save &As..."), this, SLOT(saveAs())); releaseAct = filep->addAction(tr("&Release..."), this, SLOT(release())); filep->addSeparator(); printAct = filep->addAction(QIcon(rsrcString + "/print.png"), tr("&Print..."), this, SLOT(print())); printAct->setShortcut(QKeySequence("Ctrl+P")); filep->addSeparator(); recentFilesMenu = new QMenu(this); filep->addMenu(recentFilesMenu)->setText(tr("Re¢ly opened files")); connect(filep, SIGNAL(aboutToShow()), this, SLOT(setupRecentFilesMenu())); connect(recentFilesMenu, SIGNAL(triggered(QAction*)), this, SLOT(recentFileActivated(QAction*))); filep->addSeparator(); exitAct = filep->addAction(tr("E&xit"), this, SLOT(close())); exitAct->setShortcut(QKeySequence("Ctrl+Q")); // Edit menu undoAct = editp->addAction(QIcon(rsrcString + "/undo.png"), tr("&Undo"), me, SLOT(undo())); undoAct->setShortcut(QKeySequence("Ctrl+Z")); undoAct->setEnabled(false); connect(me, SIGNAL(undoAvailable(bool)), undoAct, SLOT(setEnabled(bool))); redoAct = editp->addAction(QIcon(rsrcString + "/redo.png"), tr("&Redo"), me, SLOT(redo())); redoAct->setShortcut(QKeySequence("Ctrl+Y")); redoAct->setEnabled(false); connect(me, SIGNAL(redoAvailable(bool)), redoAct, SLOT(setEnabled(bool))); editp->addSeparator(); cutAct = editp->addAction(QIcon(rsrcString + "/editcut.png"), tr("Cu&t"), me, SLOT(cut())); cutAct->setShortcut(QKeySequence("Ctrl+X")); cutAct->setEnabled(false); connect(me, SIGNAL(cutAvailable(bool)), cutAct, SLOT(setEnabled(bool))); copyAct = editp->addAction(QIcon(rsrcString + "/editcopy.png"), tr("&Copy"), me, SLOT(copy())); copyAct->setShortcut(QKeySequence("Ctrl+C")); copyAct->setEnabled(false); connect(me, SIGNAL(copyAvailable(bool)), copyAct, SLOT(setEnabled(bool))); pasteAct = editp->addAction(QIcon(rsrcString + "/editpaste.png"), tr("&Paste"), me, SLOT(paste())); pasteAct->setShortcut(QKeySequence("Ctrl+V")); pasteAct->setEnabled(false); connect(me, SIGNAL(pasteAvailable(bool)), pasteAct, SLOT(setEnabled(bool))); selectAllAct = editp->addAction(tr("Select &All"), me, SLOT(selectAll())); selectAllAct->setShortcut(QKeySequence("Ctrl+A")); selectAllAct->setEnabled(false); editp->addSeparator(); findAct = editp->addAction(QIcon(rsrcString + "/searchfind.png"), tr("&Find..."), this, SLOT(find())); findAct->setShortcut(QKeySequence("Ctrl+F")); findAct->setEnabled(false); findAgainAct = editp->addAction(tr("Find &Next"), this, SLOT(findAgain())); findAgainAct->setShortcut(Qt::Key_F3); findAgainAct->setEnabled(false); // Translation menu // when updating the accelerators, remember the status bar prevUnfinishedAct = translationp->addAction(QIcon(rsrcString + "/prevunfinished.png"), tr("&Prev Unfinished"), this, SLOT(prevUnfinished())); prevUnfinishedAct->setShortcut(QKeySequence("Ctrl+K")); nextUnfinishedAct = translationp->addAction(QIcon(rsrcString + "/nextunfinished.png"), tr("&Next Unfinished"), this, SLOT(nextUnfinished())); nextUnfinishedAct->setShortcut(QKeySequence("Ctrl+L")); prevAct = translationp->addAction(QIcon(rsrcString + "/prev.png"), tr("P&rev"), this, SLOT(prev())); prevAct->setShortcut(QKeySequence("Ctrl+Shift+K")); nextAct = translationp->addAction(QIcon(rsrcString + "/next.png"), tr("Ne&xt"), this, SLOT(next())); nextAct->setShortcut(QKeySequence("Ctrl+Shift+L")); doneAndNextAct = translationp->addAction(QIcon(rsrcString + "/doneandnext.png"), tr("Done and &Next"), this, SLOT(doneAndNext())); doneAndNextAct->setShortcut(QKeySequence("Ctrl+Enter")); doneAndNextAct->setEnabled(false); doneAndNextAlt = new QAction(this); doneAndNextAlt->setShortcut(QKeySequence("Ctrl+Return")); doneAndNextAlt->setEnabled(false); connect(doneAndNextAlt, SIGNAL(triggered()), this, SLOT(doneAndNext())); addAction(doneAndNextAlt); beginFromSourceAct = translationp->addAction(tr("&Begin from Source"), me, SLOT(beginFromSource())); beginFromSourceAct->setShortcut(QKeySequence("Ctrl+B")); beginFromSourceAct->setEnabled(false); connect(me, SIGNAL(updateActions(bool)), beginFromSourceAct, SLOT(setEnabled(bool))); // Phrasebook menu newPhraseBookAct = phrasep->addAction(tr("&New Phrase Book..."), this, SLOT(newPhraseBook())); newPhraseBookAct->setShortcut(QKeySequence("Ctrl+N")); openPhraseBookAct = phrasep->addAction(QIcon(rsrcString + "/book.png"), tr("&Open Phrase Book..."), this, SLOT(openPhraseBook())); openPhraseBookAct->setShortcut(QKeySequence("Ctrl+H")); closePhraseBookId = phrasep->addMenu(closePhraseBookp); closePhraseBookId->setText(tr("&Close Phrase Book")); phrasep->addSeparator(); editPhraseBookId = phrasep->addMenu(editPhraseBookp); editPhraseBookId->setText(tr("&Edit Phrase Book...")); printPhraseBookId = phrasep->addMenu(printPhraseBookp); printPhraseBookId->setText(tr("&Print Phrase Book...")); connect(phrasep, SIGNAL(aboutToShow()), this, SLOT(setupPhrase())); // Validation menu acceleratorsAct = validationp->addAction(QIcon(rsrcString + "/accelerator.png"), tr("&Accelerators"), this, SLOT(revalidate())); acceleratorsAct->setCheckable(true); acceleratorsAct->setChecked(true); endingPunctuationAct = validationp->addAction(QIcon(rsrcString + "/punctuation.png"), tr("&Ending Punctuation"), this, SLOT(revalidate())); endingPunctuationAct->setCheckable(true); endingPunctuationAct->setChecked(true); phraseMatchesAct = validationp->addAction(QIcon(rsrcString + "/phrase.png"), tr("&Phrase Matches"), this, SLOT(revalidate())); phraseMatchesAct->setCheckable(true); phraseMatchesAct->setChecked(true); // View menu revertSortingAct = viewp->addAction(tr("&Revert Sorting"), this, SLOT(revertSorting())); doGuessesAct = viewp->addAction(tr("&Display guesses"), this, SLOT(toggleGuessing())); doGuessesAct->setCheckable(true); doGuessesAct->setChecked(true); toggleStats = viewp->addAction(tr("&Statistics"), this, SLOT(toggleStatistics())); toggleStats->setCheckable(true); viewp->addSeparator(); tbMenu = new QMenu(this); QMenu *dwMenu = new QMenu(this); dwMenu->addAction(dwScope->toggleViewAction()); dwMenu->addAction(me->sourceDockWnd()->toggleViewAction()); dwMenu->addAction(me->phraseDockWnd()->toggleViewAction()); viewp->addMenu(tbMenu)->setText(tr("&Toolbars")); viewp->addMenu(dwMenu)->setText(tr("Vie&ws")); connect(viewp, SIGNAL(aboutToShow()), this, SLOT(updateViewMenu())); // Help manualAct = helpp->addAction(tr("&Manual"), this, SLOT(manual())); manualAct->setShortcut(Qt::Key_F1); helpp->addSeparator(); aboutAct = helpp->addAction(tr("&About"), this, SLOT(about())); aboutQtAct = helpp->addAction(tr("About &Qt"), this, SLOT(aboutQt())); helpp->addSeparator(); whatsThisAct = helpp->addAction(QIcon(rsrcString + "/whatsthis.png"), tr("&What's This?"), this, SLOT(onWhatsThis())); whatsThisAct->setShortcut(Qt::SHIFT + Qt::Key_F1); openAct->setWhatsThis(tr("Open a Qt translation source file (TS file) for" " editing.")); saveAct->setWhatsThis(tr("Save changes made to this Qt translation " "source file.")); saveAsAct->setWhatsThis(tr("Save changes made to this Qt translation" "source file into a new file.")); releaseAct->setWhatsThis(tr("Create a Qt message file suitable for" " released applications" " from the current message file.")); printAct->setWhatsThis(tr("Print a list of all the phrases in the current" " Qt translation source file.")); exitAct->setWhatsThis(tr("Close this window and exit.")); undoAct->setWhatsThis(tr("Undo the last editing operation performed on the" " translation.")); redoAct->setWhatsThis(tr("Redo an undone editing operation performed on" " the translation.")); cutAct->setWhatsThis(tr("Copy the selected translation text to the" " clipboard and deletes it.")); copyAct->setWhatsThis(tr("Copy the selected translation text to the" " clipboard.")); pasteAct->setWhatsThis(tr("Paste the clipboard text into the" " translation.") ); selectAllAct->setWhatsThis( tr("Select the whole translation text.")); findAct->setWhatsThis(tr("Search for some text in the translation " "source file.") ); findAgainAct->setWhatsThis(tr("Continue the search where it was left.")); newPhraseBookAct->setWhatsThis(tr("Create a new phrase book.")); openPhraseBookAct->setWhatsThis(tr("Open a phrase book to assist" " translation.")); acceleratorsAct->setWhatsThis(tr("Toggle validity checks of" " accelerators.")); endingPunctuationAct->setWhatsThis(tr("Toggle validity checks" " of ending punctuation.")); phraseMatchesAct->setWhatsThis(tr("Toggle checking that phrase" " suggestions are used.")); revertSortingAct->setWhatsThis(tr("Sort the items back in the same order" " as in the message file.")); doGuessesAct->setWhatsThis(tr("Set whether or not to display translation guesses.")); manualAct->setWhatsThis(tr("Display the manual for %1.").arg(tr("Qt Linguist"))); aboutAct->setWhatsThis(tr("Display information about %1.").arg(tr("Qt Linguist"))); aboutQtAct->setWhatsThis(tr("Display information about the Qt toolkit by" " Trolltech.")); whatsThisAct->setWhatsThis(tr("Enter What's This? mode.")); beginFromSourceAct->setWhatsThis(tr("Copies the source text into" " the translation field.")); nextAct->setWhatsThis(tr("Moves to the next item.")); prevAct->setWhatsThis(tr("Moves to the previous item.")); nextUnfinishedAct->setWhatsThis(tr("Moves to the next unfinished item.")); prevUnfinishedAct->setWhatsThis(tr("Moves to the previous unfinished item.")); doneAndNextAct->setWhatsThis(tr("Marks this item as done and moves to the" " next unfinished item.")); doneAndNextAlt->setWhatsThis(doneAndNextAct->whatsThis());}void TrWindow::updateViewMenu(){ if (stats) toggleStats->setChecked(stats->isVisible()); else toggleStats->setChecked(false);}void TrWindow::onWhatsThis(){ QWhatsThis::enterWhatsThisMode();}void TrWindow::setupToolBars(){ QToolBar *filet = new QToolBar(this); filet->setWindowTitle(tr("File")); this->addToolBar(filet); tbMenu->addAction(filet->toggleViewAction()); QToolBar *editt = new QToolBar(this); editt->setWindowTitle(tr("Edit")); this->addToolBar(editt); tbMenu->addAction(editt->toggleViewAction()); QToolBar *translationst = new QToolBar(this); translationst->setWindowTitle(tr("Translation")); this->addToolBar(translationst); tbMenu->addAction(translationst->toggleViewAction()); QToolBar *validationt = new QToolBar(this); validationt->setWindowTitle(tr("Validation")); this->addToolBar(validationt); tbMenu->addAction(validationt->toggleViewAction()); QToolBar *helpt = new QToolBar(this); helpt->setWindowTitle(tr("Help")); this->addToolBar(helpt); tbMenu->addAction(helpt->toggleViewAction()); filet->addAction(openAct); filet->addAction(saveAct); filet->addAction(printAct); filet->addSeparator(); filet->addAction(openPhraseBookAct); editt->addAction(undoAct); editt->addAction(redoAct); editt->addSeparator(); editt->addAction(cutAct); editt->addAction(copyAct); editt->addAction(pasteAct); editt->addSeparator(); editt->addAction(findAct); translationst->addAction(prevAct); translationst->addAction(nextAct); translationst->addAction(prevUnfinishedAct);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -