trwindow.cpp

来自「qt-x11-free-3.0.3.tar.gz minigui图形界面工具」· C++ 代码 · 共 2,470 行 · 第 1/5 页

CPP
2,470
字号
			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 - Find"),			  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 (*)"), 0, "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 qtdirenv = getenv("QTDIR");    QString name = QFileDialog::getOpenFileName( QString( qtdirenv + "/tools/linguist/phrasebooks" ),	    tr("Qt phrase books (*.qph)\n"	       "All files (*)"), 0, "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 ){    int index = printPhraseBookp->indexOf( id );    int pageNum = 0;    if ( printer.setup(this) ) {	printer.setDocName( phraseBookNames[index] );	statusBar()->message( tr("Printing...") );	PrintOut pout( &printer );	PhraseBook *phraseBook = phraseBooks.at( index );	PhraseBook::Iterator p;	pout.setRule( PrintOut::ThinRule );	for ( p = phraseBook->begin(); p != phraseBook->end(); ++p ) {	    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()->message( tr("Printing... (page %1)")				      .arg(pageNum) );	    }	    pout.setRule( PrintOut::NoRule );	    pout.flushLine( TRUE );	}	pout.flushLine( TRUE );	statusBar()->message( tr("Printing completed"), MessageMS );    } else {	statusBar()->message( tr("Printing aborted"), MessageMS );    }}void TrWindow::revertSorting(){    lv->setSorting( 0 );    slv->setSorting( 0 );}void TrWindow::manual(){    QStringList lst;#ifdef Q_OS_MACX    lst << QDir::cleanDirPath(QString(getenv("QTDIR")) + QDir::separator() +			      "bin" + QDir::separator() +			      "assistant.app/Contents/MacOS/assistant");#else    lst << "assistant";#endif    lst << "linguist-manual.html";    QProcess proc( lst );    proc.start();}void TrWindow::about(){    AboutDialog about( this, 0, TRUE );    about.exec();}void TrWindow::aboutQt(){    QMessageBox::aboutQt( this, tr("Qt Linguist") );}void TrWindow::setupPhrase(){    bool enabled = !phraseBooks.isEmpty();    phrasep->setItemEnabled( closePhraseBookId, enabled );    phrasep->setItemEnabled( editPhraseBookId, enabled );    phrasep->setItemEnabled( printPhraseBookId, enabled );}void TrWindow::closeEvent( QCloseEvent *e ){    if ( maybeSave() )	e->accept();    else	e->ignore();}bool TrWindow::maybeSave(){    if ( dirty ) {	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();		break;	    case QMessageBox::No:		break;	}    }    return TRUE;}void TrWindow::updateCaption(){    QString cap;    bool enable = !filename.isEmpty();    saveAct->setEnabled( enable );    saveAsAct->setEnabled( enable );    releaseAct->setEnabled( enable );    printAct->setEnabled( enable );    acceleratorsAct->setEnabled( enable );    endingPunctuationAct->setEnabled( enable );    phraseMatchesAct->setEnabled( enable );    revertSortingAct->setEnabled( enable );    if ( filename.isEmpty() )	cap = tr( "Qt Linguist by Trolltech" );    else	cap = tr( "%1 - %2" ).arg( tr("Qt Linguist by Trolltech") )			     .arg( filename );    setCaption( cap );    modified->setEnabled( dirty );}//// New scope selected - build a new list of source text items// for that scope.//void TrWindow::showNewScope( QListViewItem *item ){    static ContextLVI * oldContext = 0;    if( item != 0 ) {	ContextLVI * c = (ContextLVI *) item;	bool upe = slv->isUpdatesEnabled();	slv->setUpdatesEnabled( FALSE );	slv->viewport()->setUpdatesEnabled( FALSE );	if ( oldContext != 0 ) {	    MessageLVI * tmp;	    slv->blockSignals( TRUE );	    while ( (tmp = (MessageLVI *) slv->firstChild()) != 0 )		oldContext->appendMessageItem( slv, tmp );	    slv->blockSignals( FALSE );	}	MessageLVI * tmp;	while ( c->messageItemsInList() ) {	    tmp = c->takeMessageItem( c->messageItemsInList() - 1);	    slv->insertItem( tmp );	    tmp->updateTranslationText();	}		slv->viewport()->setUpdatesEnabled( upe );	slv->setUpdatesEnabled( upe );	if( upe )	    slv->triggerUpdate();	oldContext = (ContextLVI *) item;	statusBar()->clear();    }}void TrWindow::showNewCurrent( QListViewItem *item ){    messageIsShown = (item != 0);    MessageLVI *m = (MessageLVI *) item;    ContextLVI *c = (ContextLVI *) m ? m->contextLVI() : 0;    if ( messageIsShown ) {	me->showMessage( m->sourceText(), m->comment(), c->fullContext(),			 m->translation(), m->message().type(),			 getPhrases(m->sourceText()) );	if ( (m->message().type() != MetaTranslatorMessage::Finished) &&	     m->danger() )	    danger( m->sourceText(), m->translation(), TRUE );	else	    statusBar()->clear();	doneAndNextAct->setEnabled( m->message().type() !=				    MetaTranslatorMessage::Obsolete );    } else {	if ( item == 0 )	    me->showNothing();	else	    me->showContext( c->fullContext(), c->finished() );	doneAndNextAct->setEnabled( FALSE );    }    doneAndNextAlt->setEnabled( doneAndNextAct->isEnabled() );    selectAllAct->setEnabled( messageIsShown );}void TrWindow::updateTranslation( const QString& translation ){    QListViewItem *item = slv->currentItem();    if ( item != 0 ) {	MessageLVI *m = (MessageLVI *) item;	if ( translation != m->translation() ) {	    bool dngr;	    m->setTranslation( translation );	    if ( m->finished() &&		 (dngr = danger( m->sourceText(), m->translation(), TRUE )) ) {		numFinished -= 1;		m->setDanger( dngr );		m->setFinished( FALSE );		m->contextLVI()->updateStatus();		updateProgress();	    }	    tor.insert( m->message() );	    if ( !dirty ) {		dirty = TRUE;		updateCaption();	    }	    m->updateTranslationText();	}    }}void TrWindow::updateFinished( bool finished ){    QListViewItem *item = slv->currentItem();    if ( item != 0 ) {	MessageLVI *m = (MessageLVI *) item;	if ( finished != m->finished() ) {	    numFinished += finished ? +1 : -1;	    updateProgress();	    m->setFinished( finished );	    bool oldDanger = m->danger();	    m->setDanger( /*m->finished() &&*/			  danger(m->sourceText(), m->translation(),			  !oldDanger) );	    if ( !oldDanger && m->danger() )		qApp->beep();	    tor.insert( m->message() );	    if ( !dirty ) {		dirty = TRUE;		updateCaption();	    }	}    }}void TrWindow::doneAndNext(){    MessageLVI * m = (MessageLVI *) slv->currentItem();    bool dngr = FALSE;    if ( !m ) return;    dngr = danger( m->sourceText(), m->translation(), TRUE );    if ( !dngr ) {	me->finishAndNext();	m->contextLVI()->updateStatus();    } else {	if ( m->danger() != dngr )	    m->setDanger( dngr );	tor.insert( m->message() );	if ( !dirty ) {	    dirty = TRUE;	    updateCaption();	}	qApp->beep();    }}void TrWindow::toggleFinished( QListViewItem *item, const QPoint& /* p */,			       int column ){    if ( item != 0 && column == 0 ) {	MessageLVI *m = (MessageLVI *) item;	bool dngr = FALSE;	if ( m->message().type() == MetaTranslatorMessage::Unfinished ) {	    dngr = danger( m->sourceText(), m->translation(), TRUE );	}	if ( !dngr && m->message().type() != MetaTranslatorMessage::Obsolete) {	    setCurrentMessageItem( m );	    me->setFinished( !m->finished() );	    m->contextLVI()->updateStatus();	} else {	    bool oldDanger = m->danger();	    m->setDanger( danger(m->sourceText(), m->translation(),				 !oldDanger) );	    if ( !oldDanger && m->danger() )		qApp->beep();	    tor.insert( m->message() );	    if ( !dirty ) {		dirty = TRUE;		updateCaption();	    }	}    }}void TrWindow::nextUnfinished(){    if ( nextUnfinishedAct->isEnabled() ) {	// Select a message to translate, grab the first available if	// there are no current selection.	QListViewItem * cItem = lv->currentItem(); // context item	QListViewItem * mItem = slv->currentItem(); // message item	// Make sure an item is selected from both the context and the	// message list.	if( (mItem == 0) && !(mItem = slv->firstChild()) ) {	    if( (cItem == 0) && !(cItem = lv->firstChild()) ) {		statusBar()->message( tr("No phrase to translate."),				      MessageMS );		qApp->beep();		return;	    } else {		showNewScope( cItem );		while( cItem && !(mItem = slv->firstChild()) ) {		    // no children in this node - try next one		    cItem = cItem->nextSibling();

⌨️ 快捷键说明

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