trwindow.cpp

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

CPP
2,470
字号
		    showNewScope( cItem );		}		setCurrentContextItem( cItem );		if( mItem ) {		    setCurrentMessageItem( cItem );		} else {		    statusBar()->message( tr("No phrase to translate."),					  MessageMS );		    qApp->beep();		    return;		}	    }	} else {	    setCurrentMessageItem( mItem );	}	MessageLVI * m = (MessageLVI *) mItem;	MessageLVI * n;	ContextLVI * p = (ContextLVI *) cItem;	ContextLVI * q;	// Find the next Unfinished sibling within the same context.	m = (MessageLVI *) mItem->nextSibling();	n = m;	do {	    if ( n == 0 )		break;	    if ( n && !n->finished() && n != mItem ) {		setCurrentMessageItem( n );		return;	    }	    n = (MessageLVI *) n->nextSibling();	} while ( n != m );	// If all siblings are Finished or Obsolete, look in the first	// Unfinished context.	p = (ContextLVI *) p->nextSibling();	q = p;	do {	    if ( q == 0 )		q = (ContextLVI *) lv->firstChild();	    if ( q && !q->finished() ) {		showNewScope( q );		setCurrentContextItem( q );		n = (MessageLVI *) slv->firstChild();		while ( n && n->finished() )		    n = (MessageLVI *) n->nextSibling();		if ( n && q ) {		    setCurrentMessageItem( n );		    return;		}	    }	    q = (ContextLVI *) q->nextSibling();	} while ( q != p );    }    // If no Unfinished message is left, the user has finished the job.  We    // congratulate on a job well done with this ringing bell.    statusBar()->message( tr("No untranslated phrases left."), MessageMS );    qApp->beep();}static QListViewItem * lastChild( QListView * view ){    if ( view ) {	QListViewItem * ret, * tmp;	ret = view->firstChild();	while ( ret ) {	    tmp = ret->nextSibling();	    if ( tmp == 0 )		return ret;	    ret = tmp;	}    }    return 0;}void TrWindow::prevUnfinished(){    if ( prevUnfinishedAct->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();		    showNewScope( cItem );		}		setCurrentContextItem( cItem );		if( mItem ) {		    setCurrentMessageItem( cItem );		} else {		    statusBar()->message( tr("No phrase to translate."),					  MessageMS );		    qApp->beep();		    return;		}	    }	} else {	    setCurrentMessageItem( mItem );	}	MessageLVI * m = (MessageLVI *) mItem;	MessageLVI * n;	ContextLVI * p = (ContextLVI *) cItem;	ContextLVI * q;	// Find the next Unfinished sibling within the same context.	n = m;	do {	    n = (MessageLVI * ) n->itemAbove();	    if ( n == 0 )		break;	    if ( n && !n->finished() ) {		setCurrentMessageItem( n );		return;	    }	} while ( !((ContextLVI *) cItem)->finished() && n != 0 );	// If all siblings are Finished or Obsolete, look in the prev	// Unfinished context.	q = p;	do {	    q = (ContextLVI *) q->itemAbove();	    if ( q == 0 )		q = (ContextLVI *) lastChild( lv );	    if ( q && !q->finished() ) {		showNewScope( q );		setCurrentContextItem( q );		n = (MessageLVI *) lastChild( slv );		while ( n && n->finished() )		    n = (MessageLVI *) n->itemAbove();		if ( n && q ) {		    setCurrentMessageItem( n );		    return;		}	    }	} while ( q != 0 );    }    statusBar()->message( tr("No untranslated phrases left."), MessageMS );    qApp->beep();}void TrWindow::prev(){    QListViewItem * cItem = lv->currentItem();  // context item    QListViewItem * mItem = slv->currentItem(); // message item    QListViewItem * tmp;    if ( !cItem ) {	cItem = lv->firstChild();	if ( !cItem ) return;	setCurrentContextItem( cItem );    }    if ( !mItem ) {	mItem = lastChild( slv );	if ( !mItem ) return;	setCurrentMessageItem( mItem );    } else {	if ( (tmp = mItem->itemAbove()) != 0 ) {	    setCurrentMessageItem( tmp );	    return;	} else {	    if ( (tmp = cItem->itemAbove()) == 0 ) {		tmp = lastChild( lv );	    }	    if ( !tmp ) return;	    setCurrentContextItem( tmp );	    setCurrentMessageItem( lastChild( slv ) );	}    }}void TrWindow::next(){    QListViewItem * cItem = lv->currentItem();  // context item    QListViewItem * mItem = slv->currentItem(); // message item    QListViewItem * tmp;    if ( !cItem ) {	cItem = lv->firstChild();	if ( !cItem ) return;	setCurrentContextItem( cItem );    }    if ( !mItem ) {	mItem = slv->firstChild();	if ( !mItem ) return;	setCurrentMessageItem( mItem );    } else {	if ( (tmp = mItem->nextSibling()) != 0 ) {	    setCurrentMessageItem( tmp );	    return;	} else {	    if ( (tmp = cItem->nextSibling()) == 0 ) {		tmp = lv->firstChild();	    }	    if ( !tmp ) return;	    setCurrentContextItem( tmp );	    setCurrentMessageItem( slv->firstChild() );	}    }}void TrWindow::findNext( const QString& text, int where, bool matchCase ){    findText = text;    if ( findText.isEmpty() )	findText = QString( "magicwordthatyoushouldavoid" );    findWhere = where;    findMatchCase = matchCase;    findAgainAct->setEnabled( TRUE );    findAgain();}void TrWindow::revalidate(){    ContextLVI *c = (ContextLVI *) lv->firstChild();    QListViewItem * oldScope = lv->currentItem();    int oldItemNo = itemToIndex( slv, slv->currentItem() );    slv->setUpdatesEnabled( FALSE );    while ( c != 0 ) {	showNewScope( c );	MessageLVI *m = (MessageLVI *) slv->firstChild();	while ( m != 0 ) {	    m->setDanger( danger(m->sourceText(), m->translation()) &&		    m->message().type() == MetaTranslatorMessage::Finished );	    m = (MessageLVI *) m->nextSibling();	}	c = (ContextLVI *) c->nextSibling();    }    if ( oldScope ){	showNewScope( oldScope );	QListViewItem * tmp = indexToItem( slv, oldItemNo );	if( tmp )	    setCurrentMessageItem( tmp );    }    slv->setUpdatesEnabled( TRUE );    slv->triggerUpdate();}void TrWindow::setupImageDict(){    (void) qembed_findData;    if ( imageDict == 0 ) {	imageDict = new QDict<Embed>( 101 );	Embed *em;	for ( em = embed_vec; em->size > 0; em++ ) {	    QString name = em->name;	    int k = name.findRev( QChar('.') );	    if ( k != -1 )		name.truncate( k );	    imageDict->insert( name, em );	}	// Create the application global listview symbols	pxOn  = new QPixmap;	pxOff = new QPixmap;	pxObsolete = new QPixmap;	pxDanger = new QPixmap;	em = imageDict->find( QString("symbols/check_on") );	pxOn->loadFromData( em->data, em->size );	em = imageDict->find( QString("symbols/check_off") );	pxOff->loadFromData( em->data, em->size );	em = imageDict->find( QString("symbols/check_obs") );	pxObsolete->loadFromData( em->data, em->size );	em = imageDict->find( QString("symbols/check_danger") );	pxDanger->loadFromData( em->data, em->size );	QBitmap onMask( check_on_mask_width, check_on_mask_height,			check_on_mask_bits, TRUE );	QBitmap offMask( check_off_mask_width, check_off_mask_height,			 check_off_mask_bits, TRUE );	QBitmap dangerMask( check_danger_mask_width, check_danger_mask_height,			    check_danger_mask_bits, TRUE );	pxOn->setMask( onMask );	pxOff->setMask( offMask );	pxObsolete->setMask( onMask );	pxDanger->setMask( dangerMask );    }}QString TrWindow::friendlyString( const QString& str ){    QString f = str.lower();    f.replace( QRegExp(QString("[.,:;!?()-]")), QString(" ") );    f.replace( QRegExp(QString("&")), QString("") );    f = f.simplifyWhiteSpace();    f = f.lower();    return f;}void TrWindow::setupMenuBar(){    QMenuBar * m = menuBar();    QPopupMenu * filep = new QPopupMenu( this );    QPopupMenu * editp  = new QPopupMenu( this );    QPopupMenu * translationp = new QPopupMenu( this );    QPopupMenu * validationp = new QPopupMenu( this );    validationp->setCheckable( TRUE );    phrasep = new QPopupMenu( this );    closePhraseBookp = new QPopupMenu( this );    editPhraseBookp = new QPopupMenu( this );    printPhraseBookp = new QPopupMenu( this );    QPopupMenu * viewp = new QPopupMenu( this );    viewp->setCheckable( TRUE );    QPopupMenu * helpp = new QPopupMenu( this );    m->insertItem( tr("&File"), filep );    m->insertItem( tr("&Edit"), editp );    m->insertItem( tr("&Translation"), translationp );    m->insertItem( tr("V&alidation"), validationp );    m->insertItem( tr("&Phrases"), phrasep );    m->insertItem( tr("&View"), viewp );    m->insertSeparator();    m->insertItem( tr("&Help"), helpp );    connect( closePhraseBookp, SIGNAL(activated(int)),	     this, SLOT(closePhraseBook(int)) );    connect( closePhraseBookp, SIGNAL(aboutToShow()),	     this, SLOT(updateClosePhraseBook()) );    connect( editPhraseBookp, SIGNAL(activated(int)),	     this, SLOT(editPhraseBook(int)) );    connect( printPhraseBookp, SIGNAL(activated(int)),	     this, SLOT(printPhraseBook(int)) );    // File menu    openAct = new Action( filep, tr("&Open..."), this, SLOT(open()),			  QAccel::stringToKey(tr("Ctrl+O")) );    filep->insertSeparator();    saveAct = new Action( filep, tr("&Save"), this, SLOT(save()),			  QAccel::stringToKey(tr("Ctrl+S")) );    saveAsAct = new Action( filep, tr("Save &As..."), this, SLOT(saveAs()) );    releaseAct = new Action( filep, tr("&Release..."), this, SLOT(release()) );    filep->insertSeparator();    printAct = new Action( filep, tr("&Print..."), this, SLOT(print()),			   QAccel::stringToKey(tr("Ctrl+P")) );    filep->insertSeparator();    recentFilesMenu = new QPopupMenu( this );    filep->insertItem( tr("Re&cently opened files"), recentFilesMenu );    connect( recentFilesMenu, SIGNAL(aboutToShow()), this,	     SLOT(setupRecentFilesMenu()) );    connect( recentFilesMenu, SIGNAL(activated( int )), this,	     SLOT(recentFileActivated( int )) );    filep->insertSeparator();    exitAct = new Action( filep, tr("E&xit"), this, SLOT(exitApp()),			  QAccel::stringToKey(tr("Ctrl+Q")) );    // Edit menu    undoAct = new Action( editp, tr("&Undo"), me, SLOT(undo()),			  QAccel::stringToKey(tr("Ctrl+Z")) );    undoAct->setEnabled( FALSE );    connect( me, SIGNAL(undoAvailable(bool)), undoAct, SLOT(setEnabled(bool)) );    redoAct = new Action( editp, tr("&Redo"), me, SLOT(redo()),			  QAccel::stringToKey(tr("Ctrl+Y")) );    redoAct->setEnabled( FALSE );    connect( me, SIGNAL(redoAvailable(bool)), redoAct, SLOT(setEnabled(bool)) );    editp->insertSeparator();    cutAct = new Action( editp, tr("Cu&t"), me, SLOT(cut()),			 QAccel::stringToKey(tr("Ctrl+X")) );    cutAct->setEnabled( FALSE );    connect( me, SIGNAL(cutAvailable(bool)), cutAct, SLOT(setEnabled(bool)) );    copyAct = new Action( editp, tr("&Copy"), me, SLOT(copy()),			  QAccel::stringToKey(tr("Ctrl+C")) );    copyAct->setEnabled( FALSE );    connect( me, SIGNAL(copyAvailable(bool)), copyAct, SLOT(setEnabled(bool)) );    pasteAct = new Action( editp, tr("&Paste"), me, SLOT(paste()),			   QAccel::stringToKey(tr("Ctrl+V")) );    pasteAct->setEnabled( FALSE );    connect( me, SIGNAL(pasteAvailable(bool)),	     pasteAct, SLOT(setEnabled(bool)) );    selectAllAct = new Action( editp, tr("Select &All"), me, SLOT(selectAll()),			       QAccel::stringToKey(tr("Ctrl+A")) );    selectAllAct->setEnabled( FALSE );    editp->insertSeparator();    findAct = new Action( editp, tr("&Find..."), this, SLOT(find()),			  QAccel::stringToKey(tr("Ctrl+F")) );    findAct->setEnabled( FALSE );    findAgainAct = new Action( editp, tr("Find &Next"),			       this, SLOT(findAgain()), Key_F3 );    findAgainAct->setEnabled( FALSE );#ifdef notyet    replaceAct = new Action( editp, tr("&Replace..."), this, SLOT(replace()),			     QAccel::stringToKey(tr("Ctrl+H")) );    replaceAct->setEnabled( FALSE );#endif    // Translation menu    // when updating the accelerators, remember the status bar    prevUnfinishedAct = new Action( translationp, tr("&Prev Unfinished"),				    this, SLOT(prevUnfinished()),				    QAccel::stringToKey(tr("Ctrl+K")) );    nextUnfinishedAct = new Action( translationp, tr("&Next Unfinished"),				    this, SLOT(nextUnfinished()),				    QAccel::stringToKey(tr("Ctrl+L")) );    prevAct = new Action( translationp, tr("P&rev"),			  this, SLOT(prev()),			  QAccel::stringToKey(tr("Ctrl+Shift+K")) );    nextAct = new Action( translationp, tr("Ne&xt"),			  this, SLOT(next()),			  QAccel::stringToKey(tr("Ctrl+Shift+L")) );    doneAndNextAct = new Action( translationp, tr("Done and &Next"),				 this, SLOT(doneAndNext()),				 QAccel::stringToKey(tr("Ctrl+Enter")) );    doneAndNextAlt = new QAction( this );    doneAndNextAlt->setAccel( QAccel::stringToKey(tr("Ctrl+Return")) );    connect( doneAndNextAlt, SIGNAL(activated()), this, SLOT(doneAndNext()) );    beginFromSourceAct = new Action( translationp, tr("&Begin from Source"),				     me, SLOT(beginFromSource()),				     QAccel::stringToKey(tr("Ctrl+B")) );    connect( me, SIGNAL(updateActions(bool)), beginFromSourceAct,	     SLOT(setEnabled(bool)) );    // Phrasebook menu    newPhraseBookAct = new Action( phrasep, tr("&New Phrase Book..."),				   this, SLOT(newPhraseBook()),				   QAccel::stringToKey(tr("Ctrl+N")));    openPhraseBookAct = new Action( phrasep, tr("&Open Phrase Book..."),				    this, SLOT(openPhraseBook()),				    QAccel::stringToKey(tr("Ctrl+H")) );    closePhraseBookId = phrasep->insertItem( tr("&Close Phrase Book"),					     closePhraseBookp );    phrasep->insertSeparator();    editPhraseBookId = phrasep->insertItem( tr("&Edit Phrase Book..."),					    editPhraseBookp );    printPhraseBookId = phrasep->insertItem( tr("&Print Phrase Book..."),					     printPhraseBookp );    connect( phrasep, SIGNAL(aboutToShow()), this, SLOT(setupPhrase()) );    // Validation menu    acceleratorsAct = new Action( validationp, tr("&Accelerators"),				  this, SLOT(revalidate()), 0, TRUE );    acceleratorsAct->setOn( TRUE );    endingPunctuationAct = new Action( validationp, tr("&Ending Punctuation"),				       this, SLOT(revalidate()), 0, TRUE );    endingPunctuationAct->setOn( TRUE );    phraseMatchesAct = new Action( validationp, tr("&Phrase Matches"),				   this, SLOT(revalidate()), 0, TRUE );    phraseMatchesAct->setOn( TRUE );    // View menu    revertSortingAct = new Action( viewp, tr("&Revert Sorting"),				   this, SLOT(revertSorting()) );    doGuessesAct = new Action( viewp, tr("&Display guesses"),			       this, SLOT(toggleGuessing()) );    doGuessesAct->setToggleAction( TRUE );    doGuessesAct->setOn( TRUE );    viewp->insertSeparator();    viewp->insertItem( tr("Vie&ws"), createDockWindowMenu( NoToolBars ) );    viewp->insertItem( tr("&Toolbars"), createDockWindowMenu( OnlyToolBars ) );    // Help    manualAct = new Action( helpp, tr("&Manual..."), this, SLOT(manual()),			    Key_F1 );    helpp->insertSeparator();    aboutAct = new Action( helpp, tr("&About..."), this, SLOT(about()) );    aboutQtAct = new Action( helpp, tr("About &Qt..."), this, SLOT(aboutQt()) );    helpp->insertSeparator();    whatsThisAct = new Action( helpp, tr("&What's This?"),			       this, SLOT(whatsThis()), SHIFT + Key_F1 );    openAct->setWhatsThis( tr("Open a Qt translation source file (TS file) for"			      " editing.") );    saveAct->setWhatsThis( tr("Save changes made to this Qt translation "				"source file.") );    saveAsAct->setWhatsThis( tr("Save changes made to this Qt translation"				"source file into a new file.") );    releaseAct->setWhatsThis( tr("Create a Qt message file suitable for"				 " released applications"				 " from the current message file.") );    printAct->setWhatsThis( tr("Print a list

⌨️ 快捷键说明

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