trwindow.cpp

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

CPP
1,877
字号
        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 + QLatin1String("/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);    m_ui.menuPrintPhraseBook->removeAction(act);    updatePhraseDict();    m_ui.actionBatchTranslation->setEnabled(phraseBooks[PhraseCloseMenu].count() > 0);}void TrWindow::editPhraseBook(QAction *action){    PhraseBook pb = phraseBooks[PhraseEditMenu].value(action);    PhraseBookBox box(pb.fileName(), pb, this);    box.setWindowTitle(tr("%1 - %2").arg(tr("Qt Linguist"))        .arg(pb.friendlyPhraseBookName()));    box.resize(500, 300);    box.exec();    // delete phrasebook from all menus before changing    // this avoids detachment    phraseBooks[PhraseEditMenu].remove(action);    QAction *closeact = phraseBooks[PhraseCloseMenu].key(pb);    phraseBooks[PhraseCloseMenu].remove(closeact);    QAction *printact = phraseBooks[PhrasePrintMenu].key(pb);    phraseBooks[PhrasePrintMenu].remove(printact);    phraseBooks[PhraseEditMenu].insert(action, box.phraseBook());    phraseBooks[PhraseCloseMenu].insert(closeact, box.phraseBook());    phraseBooks[PhrasePrintMenu].insert(printact, box.phraseBook());    updatePhraseDict();}void TrWindow::printPhraseBook(QAction *action){    PhraseBook phraseBook = phraseBooks[PhrasePrintMenu].value(action);    int pageNum = 0;    QPrintDialog dlg(&printer, this);    if (dlg.exec()) {        printer.setDocName(phraseBook.fileName());        statusBar()->showMessage(tr("Printing..."));        PrintOut pout(&printer);        pout.setRule(PrintOut::ThinRule);        foreach (Phrase p, phraseBook) {            pout.setGuide(p.source());            pout.addBox(29, p.source());            pout.addBox(4);            pout.addBox(29, p.target());            pout.addBox(4);            pout.addBox(34, p.definition(), PrintOut::Emphasis);            if (pout.pageNum() != pageNum) {                pageNum = pout.pageNum();                statusBar()->showMessage(tr("Printing... (page %1)")                    .arg(pageNum));            }            pout.setRule(PrintOut::NoRule);            pout.flushLine(true);        }        pout.flushLine(true);        statusBar()->showMessage(tr("Printing completed"), MessageMS);    } else {        statusBar()->showMessage(tr("Printing aborted"), MessageMS);    }}void TrWindow::revertSorting(){    if (cmdl->contextsInList() < 0)        return;    tv->clearSelection();    tv->header()->setSortIndicator(1, Qt::AscendingOrder);    tv->header()->setSortIndicatorShown(true);    cmdl->sort(1, Qt::AscendingOrder);    //mmdl->setContextItem(0);    foreach(ContextItem *c, cmdl->contextList()) {        c->sortMessages(1, Qt::AscendingOrder);    }}void TrWindow::manual(){    if (!ac)        ac = new QAssistantClient(QLibraryInfo::location(QLibraryInfo::BinariesPath), this);    ac->showPage(QLibraryInfo::location(QLibraryInfo::DocumentationPath) +                 QLatin1String("/html/linguist-manual.html"));}void TrWindow::about(){    QMessageBox box(this);    box.setTextFormat(Qt::RichText);    QString version = tr("Version %1");#if QT_EDITION == QT_EDITION_OPENSOURCE    QString open = tr(" Open Source Edition");    version.append(open);#endif    version = version.arg(QLatin1String(QT_VERSION_STR));    QString edition =#if QT_EDITION == QT_EDITION_OPENSOURCE                    tr("This version of Qt Linguist is part of the Qt Open Source Edition, for use "                    "in the development of Open Source applications. "                    "Qt is a comprehensive C++ framework for cross-platform application "                    "development.<br/><br/>"                    "You need a commercial Qt license for development of proprietary (closed "                    "source) applications. Please see <tt>http://www.trolltech.com/company/model"                    ".html</tt> for an overview of Qt licensing.");#else                    tr("This program is licensed to you under the terms of the "                    "Qt Commercial License Agreement. For details, see the file LICENSE "                    "that came with this software distribution.");#endif        box.setText(tr("<center><img src=\":/images/splash.png\"/></img><p>%1</p></center>"                    "<p>Qt Linguist is a tool for adding translations to Qt "                    "applications.</p>"                    "<p>%2</p>"                    "<p>Copyright (C) 2000-2007 Trolltech ASA. All rights reserved."                    "</p><p>The program is provided AS IS with NO WARRANTY OF ANY KIND,"                    " INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A"                    " PARTICULAR PURPOSE.</p>").arg(version).arg(edition));        box.setWindowTitle(QApplication::translate("AboutDialog", "Qt Linguist"));    box.setIcon(QMessageBox::NoIcon);    box.exec();}void TrWindow::aboutQt(){    QMessageBox::aboutQt(this, tr("Qt Linguist"));}void TrWindow::setupPhrase(){    bool enabled = !phraseBooks[PhraseCloseMenu].isEmpty();    m_ui.menuClosePhraseBook->setEnabled(enabled);    m_ui.menuEditPhraseBook->setEnabled(enabled);    m_ui.menuPrintPhraseBook->setEnabled(enabled);}void TrWindow::closeEvent(QCloseEvent *e){    if (maybeSave()) {        e->accept();        delete m_previewTool;        m_previewTool = 0;    } else {        e->ignore();    }}bool TrWindow::maybeSave(){    if (cmdl->isModified()) {        switch (QMessageBox::information(this, tr("Qt Linguist"),            tr("Do you want to save '%1'?").arg(filename),            QMessageBox::Yes | QMessageBox::Default,            QMessageBox::No,            QMessageBox::Cancel | QMessageBox::Escape))        {            case QMessageBox::Cancel:                return false;            case QMessageBox::Yes:                save();                return !cmdl->isModified();            case QMessageBox::No:                break;        }    }    return true;}void TrWindow::updateCaption(){    QString cap;    bool enable = !filename.isEmpty();    m_ui.actionSave->setEnabled(enable);    m_ui.actionSaveAs->setEnabled(enable);    m_ui.actionRelease->setEnabled(enable);    m_ui.actionReleaseAs->setEnabled(enable);    m_ui.actionPrint->setEnabled(enable);    m_ui.actionAccelerators->setEnabled(enable);    m_ui.actionEndingPunctuation->setEnabled(enable);    m_ui.actionPhraseMatches->setEnabled(enable);    m_ui.actionPlaceMarkerMatches->setEnabled(enable);    m_ui.actionRevertSorting->setEnabled(enable);    if (filename.isEmpty())        cap = tr("Qt Linguist by Trolltech");    else        cap = tr("%1 - %2%3").arg( tr("Qt Linguist by Trolltech"))        .arg(filename).arg(cmdl->isModified() ? QLatin1String("*") : QLatin1String(""));    setWindowTitle(cap);    modified->setEnabled(cmdl->isModified());}void TrWindow::showMessages(const QModelIndex &index){    if (index.isValid()) {        MessageItem *m = cmdl->messageItem(index);        ContextItem *c = cmdl->contextItem(index);        if (m && c) {            QStringList translations  = cmdl->normalizedTranslations(*m);            me->showMessage(m->context(), m->sourceText(), m->comment(), c->fullContext(),                translations, m->message().type(), getPhrases(m->sourceText()));            if (m->danger())                printDanger(m);            else                statusBar()->clearMessage();            m_ui.actionDoneAndNext->setEnabled(m->message().type() !=                MetaTranslatorMessage::Obsolete);        } else {            me->showNothing();            m_ui.actionDoneAndNext->setEnabled(false);        }    }    else {        me->showNothing();        m_ui.actionDoneAndNext->setEnabled(false);    }}void TrWindow::showNewCurrent(const QModelIndex &current, const QModelIndex &old){    showMessages(current);    m_ui.actionSelectAll->setEnabled(m_ui.actionDoneAndNext->isEnabled());    Q_UNUSED(old);}void TrWindow::updateTranslation(const QStringList &translations){    QModelIndex item = tv->currentIndex();    if (!item.isValid())        return;    MessageItem *m = cmdl->messageItem(item);    if (m) {        if (translations != m->translations()) {            m->setTranslations(translations);            updateDanger(m, true);            cmdl->updateItem(item);            if (m->finished()) {                updateFinished(false);            } else {                cmdl->setModified(true);                updateCaption();            }        }    }}/** * Updates the translation in *both* the MessageModel and in the flat MetaTranslator 'model'. */void TrWindow::updateTranslation(int context, int message, const QString &translation){    MessageItem *m = cmdl->messageItem(context, message);    if (m && translation != m->translation()) {        m->setTranslation(translation);        updateDanger(m, true);        if (m->finished())            updateFinished(false);        else            updateCaption();        // Notify the view(s)        QModelIndex idx = cmdl->modelIndex(context, message);        cmdl->updateItem(idx);    }}void TrWindow::updateFinished(int context, int message, bool finished){    MessageItem *m = cmdl->messageItem(context, message);    if (finished != m->finished()) {        m->setFinished(finished);        updateProgress();

⌨️ 快捷键说明

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