trwindow.cpp
来自「qt-x11-free-3.0.3.tar.gz minigui图形界面工具」· C++ 代码 · 共 2,470 行 · 第 1/5 页
CPP
2,470 行
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, 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, const char *imageName );};Action::Action( QPopupMenu *pop, const QString& menuText, QObject *receiver, const char *member, int accel, bool toggle ) : QAction( pop->parent(), (const char *) 0, toggle ){ QAction::addTo( pop ); setMenuText( menuText ); setAccel( accel ); 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, const char *imageName ){ setText( text ); Embed *en = imageDict->find( QString("enabled/") + QString(imageName) ); if ( en != 0 ) { QPixmap enabled; enabled.loadFromData( en->data, en->size ); QIconSet s( enabled ); Embed *dis = imageDict->find( QString("disabled/") + QString(imageName) ); if ( dis != 0 ) { QPixmap disabled; disabled.loadFromData( dis->data, dis->size ); // work around a bug in QIconSet s.setPixmap( disabled, QIconSet::Small, QIconSet::Disabled, QIconSet::On ); s.setPixmap( disabled, QIconSet::Small, QIconSet::Disabled, QIconSet::Off ); } setIconSet( s ); } return QAction::addTo( tb );}const QPixmap TrWindow::splash(){ Embed *splash = 0; setupImageDict(); splash = imageDict->find( QString("splash") ); if ( splash == 0 ) return 0; QPixmap pixmap; pixmap.loadFromData( splash->data, splash->size ); return pixmap;}const QPixmap TrWindow::pageCurl(){ Embed *ess = 0; setupImageDict(); ess = imageDict->find( QString("pagecurl") ); if ( ess == 0 ) return 0; QPixmap pixmap; pixmap.loadFromData( ess->data, ess->size ); 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 ){ setIcon( QPixmap(logo_xpm) ); setupImageDict(); // 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 ); lv->addColumn( tr("Done"), 40 ); 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; 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 ); slv->repaint(); slv->viewport()->repaint(); lv->repaint(); lv->viewport()->repaint(); updateProgress(); filename = name; dirty = FALSE; updateCaption(); me->showNothing(); doneAndNextAct->setEnabled( FALSE ); doneAndNextAlt->setEnabled( FALSE ); messageIsShown = FALSE; statusBar()->message( tr("%1 source phrase(s) loaded.").arg(numMessages), MessageMS ); foundItem = 0; foundWhere = 0; foundOffset = 0; if ( lv->childCount() > 0 ) { findAct->setEnabled( TRUE ); findAgainAct->setEnabled( FALSE );#ifdef notyet replaceAct->setEnabled( TRUE );#endif lv->setCurrentItem( lv->firstChild() ); } addRecentlyOpenedFile( name, recentFiles ); } else { statusBar()->clear(); QMessageBox::warning( this, tr("Qt Linguist"), tr("Cannot open '%1'.").arg(name) ); } }}void TrWindow::exitApp(){ if ( maybeSave() ) close();}void TrWindow::open(){ if ( maybeSave() ) { QString newFilename = QFileDialog::getOpenFileName( filename, tr("Qt translation source (*.ts)\n" "All files (*)"), this ); openFile( newFilename ); }}void TrWindow::save(){ if ( filename.isEmpty() ) return; if ( tor.save(filename) ) { dirty = FALSE; updateCaption(); statusBar()->message( tr("File saved."), MessageMS ); } else { QMessageBox::warning( this, tr("Qt Linguist"), tr("Cannot save '%1'.") .arg(filename) ); }}void TrWindow::saveAs(){ QString newFilename = QFileDialog::getSaveFileName( filename, tr("Qt translation source (*.ts)\n" "All files (*)") ); if ( !newFilename.isEmpty() ) { filename = newFilename; save(); updateCaption(); }}void TrWindow::release(){ QString newFilename = filename; newFilename.replace( QRegExp(".ts$"), "" ); newFilename += QString( ".qm" ); newFilename = QFileDialog::getSaveFileName( newFilename, tr("Qt message files for released applications (*.qm)\n" "All files (*)") ); if ( !newFilename.isEmpty() ) { if ( tor.release(newFilename) ) statusBar()->message( tr("File created."), MessageMS ); else QMessageBox::warning( this, tr("Qt Linguist"), tr("Cannot save '%1'.").arg(newFilename) ); }}void TrWindow::print(){ int pageNum = 0; if ( printer.setup(this) ) { QApplication::setOverrideCursor( WaitCursor ); printer.setDocName( filename ); statusBar()->message( tr("Printing...") ); PrintOut pout( &printer ); ContextLVI *c = (ContextLVI *) lv->firstChild(); while ( c != 0 ) { setCurrentContextItem( c ); 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 ); MessageLVI *m = (MessageLVI *) slv->firstChild(); while ( m != 0 ) { 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()->message( tr("Printing... (page %1)") .arg(pageNum) ); } m = (MessageLVI *) m->nextSibling(); } c = (ContextLVI *) c->nextSibling(); } pout.flushLine( TRUE ); QApplication::restoreOverrideCursor(); statusBar()->message( tr("Printing completed"), MessageMS ); } else { statusBar()->message( tr("Printing aborted"), MessageMS ); }}void TrWindow::find(){ h->hide(); f->show(); f->setActiveWindow(); f->raise();}void TrWindow::findAgain(){ int pass = 0; int oldItemNo = itemToIndex( slv, slv->currentItem() ); QString delayedMsg; QListViewItem * j = foundScope; QListViewItem * k = indexToItem( slv, foundItem ); QListViewItem * oldScope = lv->currentItem(); if ( lv->childCount() == 0 ) return;#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 slv->setUpdatesEnabled( FALSE ); do { // Iterate through every item in all contexts if ( j == 0 ) { j = lv->firstChild(); setCurrentContextItem( j ); if ( foundScope != 0 ) delayedMsg = tr("Search wrapped."); } if ( k == 0 ) k = slv->firstChild(); while ( k ) { MessageLVI * m = (MessageLVI *) k; switch ( foundWhere ) { case 0: foundWhere = FindDialog::SourceText; foundOffset = 0; // fall-through case FindDialog::SourceText: if ( searchItem( m->sourceText(), j, k ) ) { f->hide();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?