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

📄 trwindow.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        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)\nAll files (*)"));    if (!newFilename.isEmpty()) {        filename = newFilename;        save();        updateCaption();    }}void TrWindow::release(){    QString newFilename = filename;    newFilename.replace(QRegExp(".ts$"), "");    newFilename += QString(".qm");    newFilename = QFileDialog::getSaveFileName(this, tr("Release"), newFilename,        tr("Qt message files for released applications (*.qm)\nAll files (*)"));    if (!newFilename.isEmpty()) {        if (tor.release(newFilename))            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") : QString("unfinished");                    break;                case MetaTranslatorMessage::Obsolete:                    type = tr("obsolete");                    break;                default:                    type = QString("");                }                pout.addBox(40, m->sourceText());                pout.addBox(4);                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 = stv->currentIndex();    if (indxItem.isValid())        itemNo = indxItem.row();    QModelIndex indxScope = tv->currentIndex();    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: // what about comments in messages?                    if (searchItem(c->fullContext(), 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));    }    // This is just to keep the current scope and source text item    // selected if a search failed./*    setCurrentContextRow(oldScope.row());    setCurrentMessageRow(oldItemNo.row()); */    qApp->beep();    QMessageBox::warning( this, tr("Qt Linguist"),                          QString( tr("Cannot find the string '%1'.") ).arg(findText) );//    foundItem   = 0;    foundWhere  = 0;    foundOffset = 0;}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) {            //foundItem = m;            //foundScope = c;            setCurrentContextRow(c);            setCurrentMessageRow(m);            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 + "/phrasebooks", tr("Qt phrase books (*.qph)\nAll files (*)"));    if (!name.isEmpty() && !phraseBooksContains(name)) {        if (openPhraseBook(name)) {            int n = phraseBookFromFileName(name).count();            statusBar()->showMessage(tr("%1 phrase(s) loaded.").arg(n), MessageMS);        }    }}void TrWindow::closePhraseBook(QAction *action){    PhraseBook pb = phraseBooks[PhraseCloseMenu].value(action);    phraseBooks[PhraseCloseMenu].remove(action);    closePhraseBookp->removeAction(action);    QAction *act = phraseBooks[PhraseEditMenu].key(pb);    phraseBooks[PhraseEditMenu].remove(act);    editPhraseBookp->removeAction(act);    act = phraseBooks[PhrasePrintMenu].key(pb);    qDebug("Remove: %d", phraseBooks[PhrasePrintMenu].remove(act));    printPhraseBookp->removeAction(act);    updatePhraseDict();}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(friendlyPhraseBookName(pb)));    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);    }    stv->header()->setSortIndicator(1, Qt::AscendingOrder);    stv->header()->setSortIndicatorShown(true);}void TrWindow::manual(){    if (!ac)        ac = new QAssistantClient(QLibraryInfo::location(QLibraryInfo::BinariesPath), this);    ac->showPage(QLibraryInfo::location(QLibraryInfo::DocumentationPath) +                 "/html/linguist-manual.html");}void TrWindow::about(){    AboutDialog about(this);

⌨️ 快捷键说明

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