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

📄 trwindow.cpp

📁 QT 开发环境里面一个很重要的文件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    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) +                 "/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(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-2006 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() ? "*" : "");    setWindowTitle(cap);    modified->setEnabled(cmdl->isModified());}void TrWindow::showNewCurrent(const QModelIndex &current, const QModelIndex &old){    if (current.isValid()) {        MessageItem *m = cmdl->messageItem(current);        ContextItem *c = cmdl->contextItem(current);        if (m && c) {            QStringList translations  = cmdl->normalizedTranslations(*m);            me->showMessage(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);    }    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();        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();        me->setEditorFocus();    }    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);

⌨️ 快捷键说明

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