📄 trwindow.cpp
字号:
slv->repaint(); slv->viewport()->repaint(); lv->triggerUpdate(); 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::open(){ if ( maybeSave() ) { QString newFilename = QFileDialog::getOpenFileName( filename, tr("Qt translation source (*.ts)\n" "All files (*)"), this, "open" ); 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 (*)"), this, "save_as" ); 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 (*)"), this, "release", tr("Release") ); 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(); if ( !delayedMsg.isEmpty() ) statusBar()->message( delayedMsg, MessageMS ); return; } foundWhere = FindDialog::Translations; foundOffset = 0; // fall-through case FindDialog::Translations: if ( searchItem( m->translation(), j, k ) ) { f->hide(); if ( !delayedMsg.isEmpty() ) statusBar()->message( delayedMsg, MessageMS ); return; } foundWhere = FindDialog::Comments; foundOffset = 0; // fall-through case FindDialog::Comments: if ( searchItem( ((ContextLVI *) j)->fullContext(), j, k) ) { f->hide(); if ( !delayedMsg.isEmpty() ) statusBar()->message( delayedMsg, MessageMS ); return; } foundWhere = 0; foundOffset = 0; } k = k->nextSibling(); } j = j->nextSibling(); if ( j ) { setCurrentContextItem( j ); k = slv->firstChild(); } } while ( pass++ != lv->childCount() ); // This is just to keep the current scope and source text item // selected after a search failed. if ( oldScope ) { setCurrentContextItem( oldScope ); QListViewItem * tmp = indexToItem( slv, oldItemNo ); if( tmp ) setCurrentMessageItem( tmp ); } else { if( lv->firstChild() ) setCurrentContextItem( lv->firstChild() ); if( slv->firstChild() ) setCurrentMessageItem( slv->firstChild() ); } slv->setUpdatesEnabled( TRUE ); slv->triggerUpdate(); qApp->beep(); QMessageBox::warning( this, tr("Qt Linguist"), QString( tr("Cannot find the string '%1'.") ).arg(findText) ); foundItem = 0; foundWhere = 0; foundOffset = 0;}void TrWindow::replace(){ f->hide(); h->show(); h->setActiveWindow(); h->raise();}int TrWindow::itemToIndex( QListView * view, QListViewItem * item ){ int no = 0; QListViewItem * tmp; if( view && item ){ if( (tmp = view->firstChild()) != 0 ) do { no++; tmp = tmp->nextSibling(); } while( tmp && (tmp != item) ); } return no;}QListViewItem * TrWindow::indexToItem( QListView * view, int index ){ QListViewItem * item = 0; if ( view && index > 0 ) { item = view->firstChild(); while( item && index-- > 0 ) item = item->nextSibling(); } return item;}bool TrWindow::searchItem( const QString & searchWhat, QListViewItem * j, QListViewItem * k ){ if ( (findWhere & foundWhere) != 0 ) { foundOffset = searchWhat.find( findText, foundOffset, findMatchCase ); if ( foundOffset >= 0 ) { foundItem = itemToIndex( slv, k ); foundScope = j; setCurrentMessageItem( k ); slv->setUpdatesEnabled( TRUE ); slv->triggerUpdate(); return TRUE; } } foundOffset = 0; return FALSE;}void TrWindow::newPhraseBook(){ QString name; for (;;) { name = QFileDialog::getSaveFileName( QString::null, tr("Qt phrase books (*.qph)\n" "All files (*)"), this, "new_phrasebook", tr("Create New Phrase Book") ); 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()->message( tr("Phrase book created."), MessageMS ); } }}void TrWindow::openPhraseBook(){ QString phrasebooks( qInstallPathData() ); QString name = QFileDialog::getOpenFileName( phrasebooks + "/phrasebooks", tr("Qt phrase books (*.qph)\n" "All files (*)"), this, "open_phrasebook", tr("Open Phrase Book") ); if ( !name.isEmpty() && !phraseBookNames.contains(name) ) { if ( openPhraseBook(name) ) { int n = phraseBooks.at( phraseBooks.count() - 1 )->count(); statusBar()->message( tr("%1 phrase(s) loaded.").arg(n), MessageMS ); } }}void TrWindow::closePhraseBook( int id ){ int index = closePhraseBookp->indexOf( id ); phraseBooks.remove( index ); phraseBookNames.remove( phraseBookNames.at(index) ); updatePhraseDict(); dirtyItem = index; // remove the item next time the menu is opened editPhraseBookp->removeItem( editPhraseBookp->idAt(index) ); printPhraseBookp->removeItem( printPhraseBookp->idAt(index) );}void TrWindow::editPhraseBook( int id ){ int index = editPhraseBookp->indexOf( id ); PhraseBookBox box( phraseBookNames[index], *phraseBooks.at(index), this, "phrase book box", TRUE ); box.setCaption( tr("%1 - %2").arg(tr("Qt Linguist")) .arg(friendlyPhraseBookName(index)) ); box.resize( 500, 300 ); box.exec(); *phraseBooks.at( index ) = box.phraseBook(); updatePhraseDict();}void TrWindow::printPhraseBook( int id ){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -