trwindow.cpp

来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 1,877 行 · 第 1/5 页

CPP
1,877
字号
        updateCaption();        updateStatistics();        // Notify the view(s)        QModelIndex idx = cmdl->modelIndex(context, message);        cmdl->updateItem(idx);    }}void TrWindow::updateFinished(bool finished){    QModelIndex item = tv->currentIndex();    if (!item.isValid())        return;    MessageItem *m = cmdl->messageItem(item);    if (finished != m->finished()) {        m->setFinished(finished);        updateProgress();        updateCaption();        updateStatistics();        cmdl->updateItem(item);    }}void TrWindow::doneAndNext(){    if (!tv->currentIndex().isValid())        return;    MessageItem *m = cmdl->messageItem(tv->currentIndex());    if (!m->danger()) {        updateFinished(true);        nextUnfinished();    }    else {        qApp->beep();    }}void TrWindow::toggleFinished(const QModelIndex &index){    if ( !index.isValid() || (index.column() != 0) || (index.parent() == QModelIndex()) )        return;    MessageItem *m = cmdl->messageItem(index);    if (m->message().type() == MetaTranslatorMessage::Obsolete)        return;    if (m->danger())        printDanger(m);    if (!m->danger() && !m->finished())        updateFinished(true);    else if (m->finished())        updateFinished(false);}int TrWindow::findCurrentContextRow(){    QModelIndex index = tv->selectionModel()->currentIndex();    if (index.isValid())        return index.row();    //if no context is selected    setCurrentContextRow(0);    return 0;}bool TrWindow::setNextContext(int *currentrow, bool checkUnfinished){    QModelIndex mindx;    ++(*currentrow);    for (; *currentrow < cmdl->contextsInList(); ++(*currentrow)) {        if (!checkUnfinished) {            setCurrentContextRow(*currentrow);            return true; //it is one more item        }        mindx = cmdl->index(*currentrow, 0);        if (cmdl->contextItem(mindx)->unFinishedCount() > 0) {            setCurrentContext(mindx);            return true; // found a unfinished context        }    }    return false; // done}bool TrWindow::setPrevContext(int *currentrow, bool checkUnfinished){    QModelIndex mindx;    --(*currentrow);    for (; *currentrow >= 0; --(*currentrow)) {        if (!checkUnfinished) {            setCurrentContextRow(*currentrow);            return true; //it is one more item        }        mindx = cmdl->index(*currentrow, 0);        if (cmdl->contextItem(mindx)->unFinishedCount() > 0) {            setCurrentContext(mindx);            return true; // found a unfinished context        }    }    return false; // done}bool TrWindow::setNextMessage(QModelIndex *currentIndex, bool checkUnfinished){    bool found = false;    Q_ASSERT(currentIndex);    QModelIndex idx = currentIndex->isValid() ? *currentIndex : cmdl->index(0, 0);    do {        int row = 0;        QModelIndex par = idx.parent();        if (par.isValid()) {            row = idx.row() + 1;        } else {        //In case we are located on a top-level node            par = idx;        }        if (row >= cmdl->rowCount(par)) {            int toprow = par.row() + 1;            if (toprow >= cmdl->rowCount()) toprow = 0;            par = cmdl->index(toprow, 0);            row = 0;            idx = cmdl->index(row, 1, par);        } else {            idx = cmdl->index(row, 1, par);        }        MessageItem *m = cmdl->messageItem(idx);        if (m)            found = checkUnfinished ? !(m->finished() || m->obsolete()) : true;        if (idx == *currentIndex) break;    } while(!found);    if (found) {        *currentIndex = idx;        tv->setCurrentIndex(*currentIndex);    }    return found;}bool TrWindow::setPrevMessage(QModelIndex *currentIndex, bool checkUnfinished){    bool found = false;    Q_ASSERT(currentIndex);    QModelIndex idx = currentIndex->isValid() ? *currentIndex : cmdl->index(0, 0);    do {        int row = idx.row() - 1;        QModelIndex par = idx.parent();        if (!par.isValid()) {   //In case we are located on a top-level node            par = idx;            row = -1;        }        if (row < 0) {            int toprow = par.row() - 1;            if (toprow < 0) toprow = cmdl->rowCount() - 1;            par = cmdl->index(toprow, 0);            row = cmdl->rowCount(par) - 1;            idx = cmdl->index(row, 1, par);        } else {            idx = cmdl->index(row, 1, par);        }        MessageItem *m = cmdl->messageItem(idx);        if (m)            found = checkUnfinished ? !(m->finished() || m->obsolete()) : true;        if (idx == *currentIndex) break;    } while(!found);    if (found) {        *currentIndex = idx;        tv->setCurrentIndex(*currentIndex);    }    return found;}void TrWindow::nextUnfinished(){    if (m_ui.actionNextUnfinished->isEnabled()) {        if (!next(true)) {            // If no Unfinished message is left, the user has finished the job.  We            // congratulate on a job well done with this ringing bell.            statusBar()->showMessage(tr("No untranslated phrases left."), MessageMS);            qApp->beep();        }    }}void TrWindow::prevUnfinished(){    if (m_ui.actionNextUnfinished->isEnabled()) {        if (!prev(true)) {            // If no Unfinished message is left, the user has finished the job.  We            // congratulate on a job well done with this ringing bell.            statusBar()->showMessage(tr("No untranslated phrases left."), MessageMS);            qApp->beep();        }    }}void TrWindow::prev(){    prev(false);}bool TrWindow::prev(bool checkUnfinished){    QModelIndex current = tv->currentIndex();    bool ok = setPrevMessage(&current, checkUnfinished);        me->setEditorFocus();    return ok;}bool TrWindow::next(bool checkUnfinished){    QModelIndex current = tv->currentIndex();    bool ok = setNextMessage(&current, checkUnfinished);    me->setEditorFocus();    return ok;}void TrWindow::next(){    next(false);}void TrWindow::findNext(const QString &text, int where, bool matchCase){    if (text.isEmpty())        return;    findText = text;    findWhere = where;    findMatchCase = matchCase;    m_ui.actionFindNext->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 (cmdl->contextItem() == c)            //    cmdl->updateItem(cmdl->index(mi, 0));        }        cmdl->updateItem(cmdl->index(ci, 0));    }}QString TrWindow::friendlyString(const QString& str){    QString f = str.toLower();    f.replace(QRegExp(QString(QLatin1String("[.,:;!?()-]"))), QString(QLatin1String(" ")));    f.replace(QLatin1String("&"), QString(QLatin1String("")));    f = f.simplified();    f = f.toLower();    return f;}void TrWindow::setupMenuBar(){    m_ui.setupUi(this);    m_ui.actionAccelerators->setIcon(QIcon(rsrcString + QLatin1String("/accelerator.png")));    m_ui.actionOpenPhraseBook->setIcon(QIcon(rsrcString + QLatin1String("/book.png")));    m_ui.actionDoneAndNext->setIcon(QIcon(rsrcString + QLatin1String("/doneandnext.png")));    m_ui.actionCopy->setIcon(QIcon(rsrcString + QLatin1String("/editcopy.png")));    m_ui.actionCut->setIcon(QIcon(rsrcString + QLatin1String("/editcut.png")));    m_ui.actionPaste->setIcon(QIcon(rsrcString + QLatin1String("/editpaste.png")));    m_ui.actionOpen->setIcon(QIcon(rsrcString + QLatin1String("/fileopen.png")));    m_ui.actionOpenAltSource->setIcon(QIcon(rsrcString + QLatin1String("/fileopen.png")));    m_ui.actionSave->setIcon(QIcon(rsrcString + QLatin1String("/filesave.png")));    m_ui.actionNext->setIcon(QIcon(rsrcString + QLatin1String("/next.png")));    m_ui.actionNextUnfinished->setIcon(QIcon(rsrcString + QLatin1String("/nextunfinished.png")));    m_ui.actionPhraseMatches->setIcon(QIcon(rsrcString + QLatin1String("/phrase.png")));    m_ui.actionEndingPunctuation->setIcon(QIcon(rsrcString + QLatin1String("/punctuation.png")));    m_ui.actionPrev->setIcon(QIcon(rsrcString + QLatin1String("/prev.png")));    m_ui.actionPrevUnfinished->setIcon(QIcon(rsrcString + QLatin1String("/prevunfinished.png")));    m_ui.actionPrint->setIcon(QIcon(rsrcString + QLatin1String("/print.png")));    m_ui.actionRedo->setIcon(QIcon(rsrcString + QLatin1String("/redo.png")));    m_ui.actionFind->setIcon(QIcon(rsrcString + QLatin1String("/searchfind.png")));    m_ui.actionUndo->setIcon(QIcon(rsrcString + QLatin1String("/undo.png")));    m_ui.actionPlaceMarkerMatches->setIcon(QIcon(rsrcString + QLatin1String("/validateplacemarkers.png")));    m_ui.actionWhatsThis->setIcon(QIcon(rsrcString + QLatin1String("/whatsthis.png")));        // File menu    connect(m_ui.actionOpen, SIGNAL(triggered()), this, SLOT(open()));    connect(m_ui.actionOpenAltSource, SIGNAL(triggered()), this, SLOT(openAltSource()));    connect(m_ui.actionResetAltSource, SIGNAL(triggered()), this, SLOT(resetAltSource()));    connect(m_ui.actionSave, SIGNAL(triggered()), this, SLOT(save()));    connect(m_ui.actionSaveAs, SIGNAL(triggered()), this, SLOT(saveAs()));    connect(m_ui.actionRelease, SIGNAL(triggered()), this, SLOT(release()));    connect(m_ui.actionReleaseAs, SIGNAL(triggered()), this, SLOT(releaseAs()));    connect(m_ui.actionPrint, SIGNAL(triggered()), this, SLOT(print()));    connect(m_ui.actionExit, SIGNAL(triggered()), this, SLOT(close()));    // Edit menu    connect(m_ui.actionUndo, SIGNAL(triggered()), me, SLOT(undo()));    connect(me, SIGNAL(undoAvailable(bool)), m_ui.actionUndo, SLOT(setEnabled(bool)));    connect(m_ui.actionRedo, SIGNAL(triggered()), me, SLOT(redo()));    connect(me, SIGNAL(redoAvailable(bool)), m_ui.actionRedo, SLOT(setEnabled(bool)));    connect(m_ui.actionCopy, SIGNAL(triggered()), me, SLOT(copy()));    connect(me, SIGNAL(copyAvailable(bool)), m_ui.actionCopy, SLOT(setEnabled(bool)));    connect(me, SIGNAL(cutAvailable(bool)), m_ui.actionCut, SLOT(setEnabled(bool)));    connect(m_ui.actionCut, SIGNAL(triggered()), me, SLOT(cut()));    connect(me, SIGNAL(pasteAvailable(bool)), m_ui.actionPaste, SLOT(setEnabled(bool)));    connect(m_ui.actionPaste, SIGNAL(triggered()), me, SLOT(paste()));    connect(m_ui.actionSelectAll, SIGNAL(triggered()), me, SLOT(selectAll()));    connect(m_ui.actionFind, SIGNAL(triggered()), this, SLOT(find()));    connect(m_ui.actionFindNext, SIGNAL(triggered()), this, SLOT(findAgain()));    connect(m_ui.actionSearchAndTranslate, SIGNAL(triggered()), this, SLOT(showTranslateDialog()));    connect(m_ui.actionBatchTranslation, SIGNAL(triggered()), this, SLOT(showBatchTranslateDialog()));        connect( m_ui.actionTranslationFileSettings, SIGNAL(triggered()), this, SLOT(showTranslationSettings()) );    // Translation menu    // when updating the accelerators, remember the status bar    connect(m_ui.actionPrevUnfinished, SIGNAL(triggered()), this, SLOT(prevUnfinished()));    connect(m_ui.actionNextUnfinished, SIGNAL(triggered()), this, SLOT(nextUnfinished()));    connect(m_ui.actionNext, SIGNAL(triggered()), this, SLOT(next()));    connect(m_ui.actionPrev, SIGNAL(triggered()), this, SLOT(prev()));    connect(m_ui.actionDoneAndNext, SIGNAL(triggered()), this, SLOT(doneAndNext()));    connect(m_ui.actionBeginFromSource, SIGNAL(triggered()), me, SLOT(beginFromSource()));    connect(me, SIGNAL(updateActions(bool)), m_ui.actionBeginFromSource, SLOT(setEnabled(bool)));    // Phrasebook menu    connect(m_ui.actionNewPhraseBook, SIGNAL(triggered()), this, SLOT(newPhraseBook()));    connect(m_ui.actionOpenPhraseBook, SIGNAL(triggered()), this, SLOT(openPhraseBook()));    connect(m_ui.menuClosePhraseBook, SIGNAL(triggered(QAction*)),        this, SLOT(closePhraseBook(QAction*)));    connect(m_ui.menuEditPhraseBook, SIGNAL(triggered(QAction*)),        this, SLOT(editPhraseBook(QAction*)));    connect(m_ui.menuPrintPhraseBook, SIGNAL(triggered(QAction*)),        this, SLOT(printPhraseBook(QAction*)));    // Validation menu    connect(m_ui.actionAccelerators, SIGNAL(triggered()), this, SLOT(revalidate()));    connect(m_ui.actionEndingPunctuation, SIGNAL(triggered()), this, SLOT(revalidate()));    connect(m_ui.actionPhraseMatches, SIGNAL(triggered()), this, SLOT(revalidate()));    connect(m_ui.actionPlaceMarkerMatches, SIGNAL(triggered()), this, SLOT(revalidate()));    // View menu    connect(m_ui.actionRevertSorting, SIGNAL(triggered()), this, SLOT(revertSorting()));    connect(m_ui.actionDisplayGuesses, SIGNAL(triggered()), this, SLOT(toggleGuessing()));    connect(m_ui.actionStatistics, SIGNAL(triggered()), this, SLOT(toggleStatistics()));    connect(m_ui.menuView, SIGNAL(aboutToShow()), this, SLOT(updateViewMenu()));    m_ui.menuViewViews->addAction( dwScope->toggleViewAction() );    m_ui.menuViewViews->addAction( me->phraseDockWnd()->toggleViewAction() );    // Tools menu    connect(m_batchTranslateDlg, SIGNAL(finished()), this, SLOT(finishedBatchTranslation()));    connect(m_ui.actionPreviewForm, SIGNAL(triggered()), this, SLOT(previewForm()));

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?