📄 trwindow.cpp
字号:
/************************************************************************ Copyright (C) 2000-2002 Trolltech AS. All rights reserved.**** This file is part of Qt Linguist.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************//* TRANSLATOR TrWindow This is the application's main window.*/#include "trwindow.h"#include "listviews.h"#include "finddialog.h"#include "msgedit.h"#include "phrasebookbox.h"#include "printout.h"#include "about.h"#include "phraselv.h"#include <qaccel.h>#include <qaction.h>#include <qapplication.h>#include <qbitmap.h>#include <qdict.h>#include <qdockarea.h>#include <qdockwindow.h>#include <qfile.h>#include <qfiledialog.h>#include <qfileinfo.h>#include <qheader.h>#include <qlabel.h>#include <qlayout.h>#include <qmenubar.h>#include <qmessagebox.h>#include <qpopupmenu.h>#include <qregexp.h>#include <qsettings.h>#include <qstatusbar.h>#include <qtoolbar.h>#include <qwhatsthis.h>#include <qprocess.h>#include <qassistantclient.h>#include <stdlib.h>#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 };typedef QValueList<MetaTranslatorMessage> TML;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;enum Ending { End_None, End_FullStop, End_Interrobang, End_Colon, End_Ellipsis };static Ending ending( QString str ){ str = str.simplifyWhiteSpace(); 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 0x003a: // colon return End_Colon; case 0x2026: // horizontal ellipsis return End_Ellipsis; default: return End_None; }}class Action : public QAction{public: Action( QPopupMenu *pop, const QString& menuText, QObject *receiver, const char *member, const QString &imageName = QString::null, int accel = 0, bool toggle = FALSE ); Action( QPopupMenu *pop, const QString& menuText, int accel = 0, bool toggle = FALSE ); virtual void setWhatsThis( const QString& whatsThis ); bool addToToolbar( QToolBar *tb, const QString& text );};Action::Action( QPopupMenu *pop, const QString& menuText, QObject *receiver, const char *member, const QString &imageName, int accel, bool toggle ) : QAction( pop->parent(), (const char *) 0, toggle ){ setMenuText( menuText ); setAccel( accel ); if ( !imageName.isEmpty() ) { QPixmap enabledPix = QPixmap::fromMimeSource( imageName ); QIconSet s( enabledPix ); if ( imageName != "whatsthis.xpm" ) { QPixmap disabledPix = QPixmap::fromMimeSource( "d_" + imageName ); s.setPixmap( disabledPix, QIconSet::Small, QIconSet::Disabled ); } setIconSet( s ); } QAction::addTo( pop ); connect( this, SIGNAL(activated()), receiver, member );}Action::Action( QPopupMenu *pop, const QString& menuText, int accel, bool toggle ) : QAction( pop->parent(), (const char *) 0, toggle ){ QAction::addTo( pop ); setMenuText( menuText ); setAccel( accel );}void Action::setWhatsThis( const QString& whatsThis ){ QAction::setWhatsThis( whatsThis ); setStatusTip( whatsThis );}bool Action::addToToolbar( QToolBar *tb, const QString& text ){ setText( text ); return QAction::addTo( tb );}const QPixmap TrWindow::pageCurl(){ QPixmap pixmap; pixmap = QPixmap::fromMimeSource( "pagecurl.png" ); if ( !pixmap.isNull() ) { QBitmap pageCurlMask( pagecurl_mask_width, pagecurl_mask_height, pagecurl_mask_bits, TRUE ); pixmap.setMask( pageCurlMask ); } return pixmap;}TrWindow::TrWindow() : QMainWindow( 0, "translation window", WType_TopLevel | WDestructiveClose ){#ifndef Q_WS_MACX setIcon( QPixmap::fromMimeSource( "appicon.png" ) );#endif // Create the application global listview symbols pxOn = new QPixmap( QPixmap::fromMimeSource( "s_check_on.png" ) ); pxOff = new QPixmap( QPixmap::fromMimeSource( "s_check_off.png" ) ); pxObsolete = new QPixmap( QPixmap::fromMimeSource( "d_s_check_obs.png" ) ); pxDanger = new QPixmap( QPixmap::fromMimeSource( "s_check_danger.png" ) ); // Set up the Scope dock window QDockWindow * dwScope = new QDockWindow( QDockWindow::InDock, this, "context"); dwScope->setResizeEnabled( TRUE ); dwScope->setCloseMode( QDockWindow::Always ); addDockWindow( dwScope, tr("Context"), Qt::DockLeft ); dwScope->setCaption( tr("Context") ); dwScope->setFixedExtentWidth( 200 ); lv = new QListView( dwScope, "context list view" ); lv->setShowSortIndicator( TRUE ); lv->setAllColumnsShowFocus( TRUE ); lv->header()->setStretchEnabled( TRUE, 1 ); QFontMetrics fm( font() ); lv->addColumn( tr("Done"), fm.width( tr("Done") ) + 10 ); lv->addColumn( tr("Context") ); lv->addColumn( tr("Items"), 55 ); lv->setColumnAlignment( 0, Qt::AlignCenter ); lv->setColumnAlignment( 2, Qt::AlignRight ); lv->setSorting( 0 ); lv->setHScrollBarMode( QScrollView::AlwaysOff ); dwScope->setWidget( lv ); messageIsShown = FALSE; me = new MessageEditor( &tor, this, "message editor" ); setCentralWidget( me ); slv = me->sourceTextList(); plv = me->phraseList(); setupMenuBar(); setupToolBars(); progress = new QLabel( statusBar(), "progress" ); statusBar()->addWidget( progress, 0, TRUE ); modified = new QLabel( QString(" %1 ").arg(tr("MOD")), statusBar(), "modified?" ); statusBar()->addWidget( modified, 0, TRUE ); dirtyItem = -1; numFinished = 0; numNonobsolete = 0; numMessages = 0; updateProgress(); dirty = FALSE; updateCaption(); phraseBooks.setAutoDelete( TRUE ); f = new FindDialog( FALSE, this, "find", FALSE ); f->setCaption( tr("Qt Linguist") ); h = new FindDialog( TRUE, this, "replace", FALSE ); h->setCaption( tr("Qt Linguist") ); findMatchCase = FALSE; findWhere = 0; foundItem = 0; foundScope = 0; foundWhere = 0; foundOffset = 0; connect( lv, SIGNAL(currentChanged(QListViewItem *)), this, SLOT(showNewScope(QListViewItem *)) ); connect( lv, SIGNAL(clicked(QListViewItem *, const QPoint&, int)), this, SLOT(showNewScope(QListViewItem *)) ); connect( slv, SIGNAL(currentChanged(QListViewItem *)), this, SLOT(showNewCurrent(QListViewItem *)) ); connect( slv, SIGNAL(clicked(QListViewItem *, const QPoint&, int)), this, SLOT(showNewCurrent(QListViewItem *)) ); connect( slv, SIGNAL(clicked(QListViewItem *, const QPoint&, int)), this, SLOT(toggleFinished(QListViewItem *, const QPoint&, int)) ); connect( me, SIGNAL(translationChanged(const QString&)), this, SLOT(updateTranslation(const QString&)) ); 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( f, SIGNAL(findNext(const QString&, int, bool)), this, SLOT(findNext(const QString&, int, bool)) ); QWhatsThis::add( lv, tr("This panel lists the source contexts.") ); QWhatsThis::add( slv, tr("This panel lists the source texts. " "Items that violate validation rules " "are marked with a warning.") ); showNewCurrent( 0 ); QSize as( qApp->desktop()->size() ); as -= QSize( 30, 30 ); resize( QSize( 1000, 800 ).boundedTo( as ) ); readConfig();}TrWindow::~TrWindow(){ writeConfig();}void TrWindow::openFile( const QString& name ){ if ( !name.isEmpty() ) { statusBar()->message( tr("Loading...") ); qApp->processEvents(); if ( tor.load(name) ) { slv->clear(); slv->repaint(); slv->viewport()->repaint(); slv->setUpdatesEnabled( FALSE ); slv->viewport()->setUpdatesEnabled( FALSE ); lv->clear(); lv->repaint(); lv->viewport()->repaint(); lv->setUpdatesEnabled( FALSE ); lv->viewport()->setUpdatesEnabled( FALSE ); setEnabled( FALSE ); numFinished = 0; numNonobsolete = 0; numMessages = 0; foundScope = 0; TML all = tor.messages(); TML::Iterator it; QDict<ContextLVI> contexts( 1009 ); for ( it = all.begin(); it != all.end(); ++it ) { qApp->processEvents(); ContextLVI *c = contexts.find( QString((*it).context()) ); if ( c == 0 ) { c = new ContextLVI( lv, tor.toUnicode((*it).context(), (*it).utf8()) ); contexts.insert( QString((*it).context()), c ); } if ( (*it).sourceText()[0] == '\0' ) { c->appendToComment( tor.toUnicode((*it).comment(), (*it).utf8()) ); } else { MessageLVI * tmp = new MessageLVI( slv, *it, tor.toUnicode((*it).sourceText(), (*it).utf8()), tor.toUnicode((*it).comment(), (*it).utf8()), c ); tmp->setDanger( danger(tmp->sourceText(), tmp->translation()) && tmp->message().type() == MetaTranslatorMessage::Finished ); c->instantiateMessageItem( slv, tmp ); if ( (*it).type() != MetaTranslatorMessage::Obsolete ) { numNonobsolete++; if ( (*it).type() == MetaTranslatorMessage::Finished ) numFinished++; } else { c->incrementObsoleteCount(); } numMessages++; } c->updateStatus(); } slv->viewport()->setUpdatesEnabled( TRUE ); slv->setUpdatesEnabled( TRUE ); lv->viewport()->setUpdatesEnabled( TRUE ); lv->setUpdatesEnabled( TRUE ); setEnabled( TRUE );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -