⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trwindow.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    translationst->addAction(nextUnfinishedAct);    translationst->addAction(doneAndNextAct);    validationt->addAction(acceleratorsAct);    validationt->addAction(endingPunctuationAct);    validationt->addAction(phraseMatchesAct);    helpt->addAction(whatsThisAct);}void TrWindow::setCurrentContext(const QModelIndex &indx){    tv->setCurrentIndex(indx);    tv->scrollTo(indx);}void TrWindow::setCurrentContextRow(int row){    QModelIndex mdlI = cmdl->index(row,1);    tv->setCurrentIndex(mdlI);    tv->scrollTo(mdlI);}void TrWindow::setCurrentMessage(const QModelIndex &indx){    stv->setCurrentIndex(indx);    stv->scrollTo(indx);}void TrWindow::setCurrentMessageRow(int row){    QModelIndex mdlI = mmdl->index(row,1);    stv->setCurrentIndex(mdlI);    stv->scrollTo(mdlI);}QString TrWindow::friendlyPhraseBookName(const PhraseBook &pb) const{    return QFileInfo(pb.fileName()).fileName();}bool TrWindow::openPhraseBook(const QString& name){    PhraseBook pb;    if (!pb.load(name)) {        QMessageBox::warning(this, tr("Qt Linguist"),            tr("Cannot read from phrase book '%1'.").arg(name));        return false;    }    QAction *a = closePhraseBookp->addAction(friendlyPhraseBookName(pb));    phraseBooks[PhraseCloseMenu].insert(a, pb);    a->setWhatsThis(tr("Close this phrase book."));    a = editPhraseBookp->addAction(friendlyPhraseBookName(pb));    phraseBooks[PhraseEditMenu].insert(a, pb);    a->setWhatsThis(tr("Allow you to add, modify, or delete"        " phrases of this phrase book."));    a = printPhraseBookp->addAction(friendlyPhraseBookName(pb));    phraseBooks[PhrasePrintMenu].insert(a, pb);    a->setWhatsThis(tr("Print the entries of the phrase"        " book."));    updatePhraseDict();    return true;}bool TrWindow::savePhraseBook(QString &name, const PhraseBook &pb){    if (!name.contains(".qph") && !name.contains("."))        name += ".qph";    if (!pb.save(name)) {        QMessageBox::warning(this, tr("Qt Linguist"),            tr("Cannot create phrase book '%1'.").arg(name));        return false;    }    return true;}void TrWindow::updateProgress(){    if (numNonobsolete == 0)        progress->setText(QString("    " "    "));    else        progress->setText(QString(" %1/%2 ").arg(numFinished)        .arg(numNonobsolete));    prevUnfinishedAct->setEnabled(numFinished != numNonobsolete);    nextUnfinishedAct->setEnabled(numFinished != numNonobsolete);    prevAct->setEnabled(cmdl->contextsInList() > 0);    nextAct->setEnabled(cmdl->contextsInList() > 0);}void TrWindow::updatePhraseDict(){    phraseDict.clear();    foreach (PhraseBook pb, phraseBooks[PhraseCloseMenu]) {        foreach (Phrase p, pb) {            QString f = friendlyString(p.source());            if ( f.length() > 0 ) {                f = f.split(QChar(' ')).first();                if (!phraseDict.contains(f)) {                    PhraseBook pbe;                    phraseDict.insert(f, pbe);                }                phraseDict[f].append(p);            }        }    }    revalidate();}PhraseBook TrWindow::getPhrases(const QString &source){    PhraseBook phrases;    QString f = friendlyString(source);    QStringList lookupWords = f.split(QChar(' '));    foreach (QString s, lookupWords) {        if (phraseDict.contains(s)) {            PhraseBook ent = phraseDict.value(s);            foreach (Phrase p, ent) {                if (f.indexOf(friendlyString((p).source())) >= 0)                    phrases.append(p);            }        }    }    return phrases;}void TrWindow::printDanger(MessageItem *m){    danger(m->sourceText(), m->translation(), true);}bool TrWindow::updateDanger(MessageItem *m, bool verbose){    bool dngr = danger(m->sourceText(), m->translation(), verbose);    if (dngr != m->danger())        m->setDanger(dngr);    return dngr;}bool TrWindow::danger( const QString& source, const QString& translation,                       bool verbose ){    if (acceleratorsAct->isChecked()) {        bool sk = source.contains(Qt::Key_Ampersand);        bool tk = translation.contains(Qt::Key_Ampersand);        if (!sk && tk) {            if (verbose)                statusBar()->showMessage(tr("Accelerator possibly superfluous in"                                         " translation."), ErrorMS);            return true;        } else if (sk && !tk) {            if (verbose)                statusBar()->showMessage(tr("Accelerator possibly missing in"                                         " translation."), ErrorMS);            return true;        }    }    if (endingPunctuationAct->isChecked()) {        if (ending(source) != ending(translation)) {            if (verbose)                statusBar()->showMessage(tr("Translation does not end with the"                    " same punctuation as the source text."), ErrorMS);            return true;        }    }    if (phraseMatchesAct->isChecked()) {        QString fsource = friendlyString(source);        QString ftranslation = friendlyString(translation);        QStringList lookupWords = fsource.split(QChar(' '));        bool phraseFound;        foreach (QString s, lookupWords) {            if (phraseDict.contains(s)) {                PhraseBook ent = phraseDict.value(s);                phraseFound = false;                foreach (Phrase p, ent) {                    if (fsource.indexOf(friendlyString(p.source())) < 0 ||                        ftranslation.indexOf(friendlyString(p.target())) >= 0) {                        phraseFound = true;                        break;                    }                }                if (!phraseFound) {                    if (verbose)                        statusBar()->showMessage(tr("A phrase book suggestion for"                            " '%1' was ignored.").arg(s), ErrorMS );                    return true;                }            }        }    }    if (verbose)        statusBar()->clearMessage();    return false;}void TrWindow::readConfig(){    QString keybase(QString::number((QT_VERSION >> 16) & 0xff)                    + "." + QString::number((QT_VERSION >> 8) & 0xff) + "/");    QSettings config;    QRect r( pos(), size() );    recentFiles = config.value(keybase + "RecentlyOpenedFiles").toStringList();    r.setX(config.value(keybase + "Geometry/MainwindowX", r.x()).toInt());    r.setY(config.value(keybase + "Geometry/MainwindowY", r.y()).toInt());    r.setWidth(config.value(keybase + "Geometry/MainwindowWidth", r.width()).toInt());    r.setHeight(config.value(keybase + "Geometry/MainwindowHeight", r.height()).toInt());    if (!r.intersects(QApplication::desktop()->geometry()))        r.moveTopLeft(QApplication::desktop()->availableGeometry().topLeft());    if (r.isValid()) {        setGeometry(r);    }     QDockWidget *dw;    dw = static_cast<QDockWidget *>(tv->parent());    Qt::DockWidgetArea place;    place = static_cast<Qt::DockWidgetArea>(config.value(keybase + "Geometry/ContextwindowInDock",        dockWidgetArea(dw)).toInt());    if (dockWidgetArea(dw) != place)        addDockWidget(place, dw);    dw = static_cast<QDockWidget *>(stv->parent());    place = static_cast<Qt::DockWidgetArea>(config.value(keybase + "Geometry/SourcewindowInDock",        dockWidgetArea(dw)).toInt());    if (dockWidgetArea(dw) != place)        addDockWidget(place, dw);    dw = static_cast<QDockWidget *>(ptv->parent()->parent());    place = static_cast<Qt::DockWidgetArea>(config.value(keybase + "Geometry/PhrasewindowInDock",        dockWidgetArea(dw)).toInt());    if (dockWidgetArea(dw) != place)        addDockWidget(place, dw);    acceleratorsAct->setChecked(config.value(keybase+ "Validators/Accelerator", true).toBool());    endingPunctuationAct->setChecked(config.value(keybase+ "Validators/EndingPunctuation", true).toBool());    phraseMatchesAct->setChecked(config.value(keybase+ "Validators/PhraseMatch", true).toBool());    QApplication::sendPostedEvents();}void TrWindow::writeConfig(){    QString keybase(QString::number( (QT_VERSION >> 16) & 0xff ) +                     "." + QString::number( (QT_VERSION >> 8) & 0xff ) + "/" );    QSettings config;    config.setValue(keybase + "RecentlyOpenedFiles", recentFiles);    config.setValue(keybase + "Geometry/MainwindowMaximized", isMaximized());    config.setValue(keybase + "Geometry/MainwindowX", normalGeometry().x());    config.setValue(keybase + "Geometry/MainwindowY", normalGeometry().y());    config.setValue(keybase + "Geometry/MainwindowWidth", normalGeometry().width());    config.setValue(keybase + "Geometry/MainwindowHeight", normalGeometry().height());    QDockWidget * dw = static_cast<QDockWidget *>(tv->parent());    config.setValue(keybase + "Geometry/ContextwindowInDock", dockWidgetArea(dw));    dw = static_cast<QDockWidget *>(stv->parent());    config.setValue(keybase + "Geometry/SourcewindowInDock", dockWidgetArea(dw));    dw = static_cast<QDockWidget *>(ptv->parent()->parent());    config.setValue(keybase + "Geometry/PhrasewindowInDock", dockWidgetArea(dw));    config.setValue(keybase+ "Validators/Accelerator", acceleratorsAct->isChecked());    config.setValue(keybase+ "Validators/EndingPunctuation", endingPunctuationAct->isChecked());    config.setValue(keybase+ "Validators/PhraseMatch", phraseMatchesAct->isChecked());}void TrWindow::setupRecentFilesMenu(){    recentFilesMenu->clear();    if (recentFiles.count() > 0) {        recentFilesMenu->setEnabled(true);        QStringList::Iterator it = recentFiles.begin();        for (; it != recentFiles.end(); ++it) {            recentFilesMenu->addAction(*it);        }    } else {        recentFilesMenu->setEnabled(false);    }}void TrWindow::recentFileActivated(QAction *action){    if (!action->text().isEmpty()) {        if (maybeSave())            openFile(action->text());    }}void TrWindow::addRecentlyOpenedFile(const QString &fn, QStringList &lst){    QFileInfo fi(fn);    if (lst.contains(fi.absoluteFilePath()))        return;    if ( lst.count() >= 10 )        lst.removeLast();    lst.prepend(fi.absoluteFilePath());}void TrWindow::toggleGuessing(){    me->toggleGuessing();}void TrWindow::focusSourceList(){    stv->setFocus();}void TrWindow::focusPhraseList(){    ptv->setFocus();}void TrWindow::toggleStatistics(){    if (toggleStats->isChecked()) {        if (!stats) {            stats = new Statistics(this);            connect(this, SIGNAL(statsChanged(int,int,int,int,int,int)), stats,                SLOT(updateStats(int,int,int,int,int,int)));        }        stats->show();        updateStatistics();    }    else if (stats) {        stats->close();    }}void TrWindow::updateStatistics(){    // don't call this if stats dialog is not open    // because this can be slow...    if (!stats || !stats->isVisible())        return;    QList<ContextItem *> ctxtList;    QList<MessageItem *> msgList;    const MessageItem *mi;    int trW = 0;    int trC = 0;    int trCS = 0;    ctxtList = cmdl->contextList();    for (int i=0; i<ctxtList.count(); i++) {        msgList = ctxtList.at(i)->messageItemList();        for (int j=0; j<msgList.count(); j++) {            mi = msgList.at(j);            if (mi->finished() && !(mi->message().type() == MetaTranslatorMessage::Obsolete))                doCharCounting(mi->translation(), trW, trC, trCS);        }    }    emit statsChanged(srcWords, srcChars, srcCharsSpc, trW, trC, trCS);}void TrWindow::doCharCounting(const QString& text, int& trW, int& trC, int& trCS){    trCS += text.length();    bool inWord = false;    for (int i=0; i<(int)text.length(); ++i) {        if (text[i].isLetterOrNumber() || text[i] == QChar('_')) {            if (!inWord) {                ++trW;                inWord = true;            }        } else {            inWord = false;        }        if (!text[i].isSpace())            trC++;    }}

⌨️ 快捷键说明

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