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

📄 trwindow.cpp

📁 QT 开发环境里面一个很重要的文件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.**** This file is part of the Qt Linguist of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************//*  TRANSLATOR TrWindow  This is the application's main window.*/#include "trwindow.h"#include "finddialog.h"#include "translatedialog.h"#include "batchtranslationdialog.h"#include "translationsettingsdialog.h"#include "msgedit.h"#include "phrasebookbox.h"#include "printout.h"#include "statistics.h"#include "messagemodel.h"#include "phrasemodel.h"#include "translator.h"#include "previewtool/trpreviewtool.h"#include <QAction>#include <QApplication>#include <QBitmap>#include <QDockWidget>#include <QFile>#include <QFileDialog>#include <QFileInfo>#include <QHeaderView>#include <QLabel>#include <QLayout>#include <QMenuBar>#include <QMessageBox>#include <QMenu>#include <QRegExp>#include <QSettings>#include <QStatusBar>#include <QToolBar>#include <QWhatsThis>#include <QAssistantClient>#include <QDesktopWidget>#include <QPrintDialog>#include <QLibraryInfo>#include <QUiLoader>#define pagecurl_mask_width 53#define pagecurl_mask_height 51static const uchar pagecurl_mask_bits[] = {   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,   0xff, 0x0f, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0xfe, 0xff,   0xff, 0xff, 0xff, 0x0f, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00,   0xc0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff,   0x0f, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0xff,   0xff, 0xff, 0x0f, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00,   0xfc, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x0f,   0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xf0, 0xff, 0xff,   0xff, 0x0f, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xf0,   0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x0f, 0x00,   0x00, 0xe0, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff,   0x0f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xe0, 0xff,   0xff, 0xff, 0x0f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00,   0xe0, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x0f,   0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xe0, 0xff, 0xff,   0xff, 0x0f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xe0,   0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x0f, 0x00,   0x00, 0xe0, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff,   0x0f, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0xfc,   0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x0f, 0x00, 0x00,   0x00, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0f,   0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,   0xe0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00,   0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00,   0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,   0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,   0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08 };static const int ErrorMS = 600000; // for error messagesstatic const int MessageMS = 2500;QPixmap *TrWindow::pxOn = 0;QPixmap *TrWindow::pxOff = 0;QPixmap *TrWindow::pxObsolete = 0;QPixmap *TrWindow::pxDanger = 0;QPixmap *TrWindow::pxWarning = 0;QPixmap *TrWindow::pxEmpty = 0;enum Ending {End_None, End_FullStop, End_Interrobang, End_Colon,              End_Ellipsis};static Ending ending(QString str, QLocale::Language lang){    str = str.simplified();    int ch = 0;    if (!str.isEmpty())        ch = str.right(1)[0].unicode();    switch (ch) {    case 0x002e: // full stop        if (str.endsWith(QString("...")))            return End_Ellipsis;        else            return End_FullStop;    case 0x0589: // armenian full stop    case 0x06d4: // arabic full stop    case 0x3002: // ideographic full stop        return End_FullStop;    case 0x0021: // exclamation mark    case 0x003f: // question mark    case 0x00a1: // inverted exclamation mark    case 0x00bf: // inverted question mark    case 0x01c3: // latin letter retroflex click    case 0x037e: // greek question mark    case 0x061f: // arabic question mark    case 0x203c: // double exclamation mark    case 0x203d: // interrobang    case 0x2048: // question exclamation mark    case 0x2049: // exclamation question mark    case 0x2762: // heavy exclamation mark ornament        return End_Interrobang;    case 0x003b: // greek 'compatibility' questionmark        return lang == QLocale::Greek ? End_Interrobang : End_None;    case 0x003a: // colon        return End_Colon;    case 0x2026: // horizontal ellipsis        return End_Ellipsis;    default:        return End_None;    }}const QPixmap TrWindow::pageCurl(){    QPixmap pixmap;    pixmap.load(":/images/pagecurl.png" );    if ( !pixmap.isNull() ) {        QBitmap pageCurlMask = QBitmap::fromData(QSize(pagecurl_mask_width, pagecurl_mask_height),                                                 pagecurl_mask_bits, QImage::Format_MonoLSB);        pixmap.setMask(pageCurlMask);    }    return pixmap;}#ifdef Q_WS_MACconst QString rsrcString = ":/images/mac";#elseconst QString rsrcString = ":/images/win";#endifTrWindow::TrWindow()    : QMainWindow(0, Qt::Window){    ac = 0;#ifndef Q_WS_MAC    setWindowIcon(QPixmap(":/images/appicon.png" ));#endif    m_previewTool = 0;    // Create the application global listview symbols    pxOn  = new QPixmap(":/images/s_check_on.png");    pxOff = new QPixmap(":/images/s_check_off.png");    pxObsolete = new QPixmap(":/images/s_check_obsolete.png");    pxDanger = new QPixmap(":/images/s_check_danger.png");    pxWarning = new QPixmap(":/images/s_check_warning.png");    pxEmpty = new QPixmap(":/images/s_check_empty.png");    setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);    setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);    setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);    setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);    // Set up the Scope dock window    dwScope = new QDockWidget(this);    dwScope->setObjectName("ContextDockWidget");    dwScope->setAllowedAreas(Qt::AllDockWidgetAreas);    dwScope->setFeatures(QDockWidget::AllDockWidgetFeatures);    dwScope->setWindowTitle(tr("Context"));    tv = new MessagesTreeView(dwScope);    cmdl = new MessageModel(dwScope);    tv->setModel(cmdl);    dwScope->setWidget(tv);    addDockWidget(Qt::LeftDockWidgetArea, dwScope);    me = new MessageEditor(cmdl, this);    //setCentralWidget(me);    ptv = me->phraseView();    pmdl = qobject_cast<PhraseModel *>(ptv->model());    connect(tv->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),             this, SLOT(showNewCurrent(QModelIndex,QModelIndex)));    connect(cmdl, SIGNAL(languageChanged(QLocale::Language)), this, SLOT(updateLanguage(QLocale::Language)));    m_translatedlg = new TranslateDialog(this);    m_batchTranslateDlg = new BatchTranslationDialog(cmdl, this);    m_translationSettingsDialog = 0;    finddlg = new FindDialog(this);    findMatchCase = false;    findWhere = 0;    foundWhere = 0;    foundOffset = 0;    setupMenuBar();    setupToolBars();    // We can't call setCentralWidget(me), since it is already called in m_ui.setupUi()    QBoxLayout *lout = new QBoxLayout(QBoxLayout::TopToBottom, m_ui.centralwidget);    lout->addWidget(me);    lout->setMargin(0);    m_ui.centralwidget->setLayout(lout);    progress = new QLabel(statusBar());    statusBar()->addPermanentWidget(progress);    modified = new QLabel(QString(" %1 ").arg(tr("MOD")), statusBar());    statusBar()->addPermanentWidget(modified);    updateProgress();    updateCaption();    connect(tv, SIGNAL(clicked(QModelIndex)),        this, SLOT(toggleFinished(QModelIndex)));    connect(me, SIGNAL(translationChanged(QStringList)),        this, SLOT(updateTranslation(QStringList)));    connect(me, SIGNAL(finished(bool)), this, SLOT(updateFinished(bool)));    connect(me, SIGNAL(prevUnfinished()), this, SLOT(prevUnfinished()));    connect(me, SIGNAL(nextUnfinished()), this, SLOT(nextUnfinished()));    connect(me, SIGNAL(focusSourceList()), this, SLOT(focusSourceList()));    connect(me, SIGNAL(focusPhraseList()), this, SLOT(focusPhraseList()));    connect(finddlg, SIGNAL(findNext(QString,int,bool)),        this, SLOT(findNext(QString,int,bool)));    connect(m_translatedlg, SIGNAL( translateAndFindNext(QString,QString,int,int,bool) ),        this, SLOT( translateAndFindNext(QString,QString,int,int,bool) ));    connect(tv->header(), SIGNAL(sectionClicked(int)),        tv, SLOT(clearSelection()));    tv->setWhatsThis(tr("This panel lists the source contexts."));    QSize as( qApp->desktop()->size() );    as -= QSize( 30, 30 );    resize( QSize( 1000, 800 ).boundedTo( as ) );    readConfig();    stats = 0;    QWidget::setTabOrder(ptv, tv);}void TrWindow::updateLanguage(QLocale::Language lang){    QStringList forms;    QByteArray rules;    getNumerusInfo(lang, cmdl->country(), &rules, &forms);    me->setNumerusForms(tr("Translation"), forms);}TrWindow::~TrWindow(){    writeConfig();    cmdl->clearContextList();    delete stats;    delete m_previewTool;}void TrWindow::openFile( const QString& name ){    if (name.isEmpty())        return;    statusBar()->showMessage(tr("Loading..."));    qApp->processEvents();    if (!cmdl->load(name)) {        statusBar()->clearMessage();        QMessageBox::warning(this, tr("Qt Linguist"), tr("Cannot open '%1'.").arg(name));        return;    }    MessageItem *m;    for (MessageModel::iterator it = cmdl->begin() ; (m = it.current()) ; ++it) {        updateDanger(m);    }    tv->clearSelection();    setEnabled(true);    updateProgress();    filename = name;        updateCaption();    me->showNothing();    m_ui.actionDoneAndNext->setEnabled(false);    m_ui.actionPreviewForm->setEnabled(true);    statusBar()->showMessage(tr("%n source phrase(s) loaded.", 0, cmdl->getMessageCount()), MessageMS);    foundWhere = 0;    foundOffset = 0;    if (cmdl->contextsInList() > 0) {        m_ui.actionFind->setEnabled(true);        m_ui.actionFindNext->setEnabled(false);        m_ui.actionTranslationFileSettings->setEnabled(true);        m_ui.actionBatchTranslation->setEnabled(true);        m_ui.actionSearchAndTranslate->setEnabled(true);    }    addRecentlyOpenedFile(name, recentFiles);    updateStatistics();}void TrWindow::open(){    if (maybeSave()) {        QString newFilename = QFileDialog::getOpenFileName( this, QString(), filename,            tr("Qt translation source (*.ts)\nAll files (*)"));        openFile(newFilename);    }}void TrWindow::save(){    if (filename.isEmpty())        return;    if (cmdl->save(filename)) {        updateCaption();        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::releaseAs(){    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 (cmdl->release(newFilename, false, false, Translator::Everything))            statusBar()->showMessage(tr("File created."), MessageMS);        else            QMessageBox::warning(this, tr("Qt Linguist"), tr("Cannot save '%1'.").arg(newFilename));    }}// No-questionvoid TrWindow::release()

⌨️ 快捷键说明

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