⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msgedit.cpp

📁 Linux下的基于X11的图形开发环境。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    topDockWnd->setCaption( tr("Source text") );    topDockWnd->setCloseMode( QDockWindow::Always );    topDockWnd->setResizeEnabled( TRUE );    topDockWnd->setFixedExtentHeight( 110 );    srcTextList = new QListView( topDockWnd, "source text list view" );    srcTextList->setShowSortIndicator( TRUE );    srcTextList->setAllColumnsShowFocus( TRUE );    srcTextList->setSorting( 0 );    QFontMetrics fm( font() );    srcTextList->addColumn( tr("Done"), fm.width( tr("Done") ) + 10 );    srcTextList->addColumn( tr("Source text") );    srcTextList->addColumn( tr("Translation"), 300 );    srcTextList->setColumnAlignment( 0, Qt::AlignCenter );    srcTextList->setColumnWidthMode( 1, QListView::Manual );    srcTextList->header()->setStretchEnabled( TRUE, 1 );    srcTextList->setMinimumSize( QSize( 50, 50 ) );    srcTextList->setHScrollBarMode( QScrollView::AlwaysOff );    srcTextList->installEventFilter( this );    topDockWnd->setWidget( srcTextList );    sv = new QScrollView( this, "scroll view" );    sv->setHScrollBarMode( QScrollView::AlwaysOff );    sv->viewport()->setBackgroundMode( PaletteBackground );    editorPage = new EditorPage( sv, "editor page" );    connect( editorPage, SIGNAL(pageHeightUpdated(int)),	     SLOT(updatePageHeight(int)) );    editorPage->translationMed->installEventFilter( this );    sw = new ShadowWidget( editorPage, sv, "editor page shadow" );    sw->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,				    QSizePolicy::Expanding) );    sw->setMinimumSize( QSize( 100, 150 ) );    sv->addChild( sw );    bottomDock = new QDockArea( Qt::Horizontal, QDockArea::Reverse,				this, "bottom dock area" );    bottomDock->setMinimumHeight( 10 );    bottomDock->setSizePolicy( QSizePolicy( QSizePolicy::Minimum,					    QSizePolicy::Minimum) );    bottomDockWnd = new QDockWindow( QDockWindow::InDock, bottomDock,				     "bottom dock window" );    if ( mw ) {	mw->setDockEnabled( bottomDockWnd, Qt::DockTop, TRUE );	mw->setDockEnabled( bottomDockWnd, Qt::DockLeft, TRUE );	mw->setDockEnabled( bottomDockWnd, Qt::DockRight, TRUE );	mw->setDockEnabled( bottomDockWnd, Qt::DockBottom, TRUE );    }    bottomDockWnd->setCaption( tr("Phrases") );    bottomDockWnd->setCloseMode( QDockWindow::Always );    bottomDockWnd->setResizeEnabled( TRUE );    QWidget * w = new QWidget( bottomDockWnd );    w->setSizePolicy( QSizePolicy( QSizePolicy::Minimum,				   QSizePolicy::Minimum ) );    QHBoxLayout *hl = new QHBoxLayout( w, 6 );    QVBoxLayout *vl = new QVBoxLayout( 6 );    phraseLbl = new QLabel( tr("Phrases and guesses:"), w );    phraseLv = new PhraseLV( w, "phrase list view" );    phraseLv->setSorting( PhraseLVI::DefinitionText );    phraseLv->installEventFilter( this );    hl->addLayout( vl );    vl->addWidget( phraseLbl );    vl->addWidget( phraseLv );    accel = new QAccel( this, "accel" );    connect( accel, SIGNAL(activated(int)), this, SLOT(guessActivated(int)) );    for ( int i = 0; i < 9; i++ )	accel->insertItem( CTRL + (Key_1 + i), i + 1 );    bottomDockWnd->setWidget( w );    v->addWidget( topDock );    v->addWidget( sv );    v->addWidget( bottomDock );    // Signals    connect( editorPage->pageCurl, SIGNAL(nextPage()),	     SIGNAL(nextUnfinished()) );    connect( editorPage->pageCurl, SIGNAL(prevPage()),	     SIGNAL(prevUnfinished()) );    connect( editorPage->translationMed, SIGNAL(textChanged()),	     this, SLOT(emitTranslationChanged()) );    connect( editorPage->translationMed, SIGNAL(textChanged()),	     this, SLOT(updateButtons()) );    connect( editorPage->translationMed, SIGNAL(undoAvailable(bool)),	     this, SIGNAL(undoAvailable(bool)) );    connect( editorPage->translationMed, SIGNAL(redoAvailable(bool)),	     this, SIGNAL(redoAvailable(bool)) );    connect( editorPage->translationMed, SIGNAL(copyAvailable(bool)),	     this, SIGNAL(cutAvailable(bool)) );    connect( editorPage->translationMed, SIGNAL(copyAvailable(bool)),	     this, SIGNAL(copyAvailable(bool)) );    connect( qApp->clipboard(), SIGNAL(dataChanged()),	     this, SLOT(updateCanPaste()) );    connect( phraseLv, SIGNAL(doubleClicked(QListViewItem *)),	     this, SLOT(insertPhraseInTranslation(QListViewItem *)) );    connect( phraseLv, SIGNAL(returnPressed(QListViewItem *)),	     this, SLOT(insertPhraseInTranslationAndLeave(QListViewItem *)) );    // What's this    QWhatsThis::add( this, tr("This whole panel allows you to view and edit "			      "the translation of some source text.") );    QWhatsThis::add( editorPage->srcText,		     tr("This area shows the source text.") );    QWhatsThis::add( editorPage->cmtText, tr("This area shows a comment that"			" may guide you, and the context in which the text"			" occurs.") );    QWhatsThis::add( editorPage->translationMed,		     tr("This is where you can enter or modify"			" the translation of some source text.") );}void MessageEditor::toggleFinished(){    if ( itemFinished )	itemFinished = FALSE;    else	itemFinished = TRUE;    emit finished( itemFinished );}bool MessageEditor::eventFilter( QObject * o, QEvent * e ){    static uchar doFocusChange = FALSE;    // Handle keypresses in the message editor - scroll the view if the current    // line is hidden.    if ( o->inherits("QMultiLineEdit") ) {	MED * ed = (MED *) o;	QKeyEvent * ke;	int k;	if ( e->type() == QEvent::KeyPress ) {	    ke = (QKeyEvent *) e;	    k  = ke->key();	    // Hardcode the Tab key to do focus changes when pressed	    // inside the editor	    if ( k == Key_BackTab && doFocusChange ) {		emit focusSourceList();		doFocusChange = FALSE;		return TRUE;	    } else if ( k == Key_Tab && doFocusChange ) {		emit focusPhraseList();		doFocusChange = FALSE;		return TRUE;	    }	} else if ( e->type() == QEvent::KeyRelease ) {	    ke = (QKeyEvent *) e;	    k  = ke->key();	    if ( (k == Key_Up) && (ed->cursorY() < 10) )		sv->verticalScrollBar()->subtractLine();	    else if ( (k == Key_Down) && (ed->cursorY() >= ed->height() - 20) )		sv->verticalScrollBar()->addLine();	    else if ( (k == Key_PageUp) && (ed->cursorY() < 10) )		sv->verticalScrollBar()->subtractPage();	    else if ( (k == Key_PageDown) && (ed->cursorY() >=					      (ed->height() - 50)) )		sv->verticalScrollBar()->addPage();	    else		sv->ensureVisible( sw->margin() + ed->x() + ed->cursorX(),				   sw->margin() + ed->y() + ed->cursorY() );	}	doFocusChange = TRUE;    }    if ( o->inherits("QListView") ) {	// handle the ESC key in the list views	if ( e->type() == QEvent::KeyRelease &&	     ((QKeyEvent *) e)->key() == Key_Escape )	    editorPage->translationMed->setFocus();    }    return FALSE;}void MessageEditor::updatePageHeight( int height ){    sw->resize( sw->width(), height + sw->margin() + sw->shadowWidth() );}void MessageEditor::resizeEvent( QResizeEvent * ){    sw->resize( sv->viewport()->width(), sw->height() );}QListView * MessageEditor::sourceTextList() const{    return srcTextList;}QListView * MessageEditor::phraseList() const{    return phraseLv;}void MessageEditor::showNothing(){    editorPage->srcText->setText( "" );    showContext( QString(""), FALSE );}void MessageEditor::showContext( const QString& context, bool finished ){    setEditionEnabled( FALSE );    sourceText = QString::null;    guesses.clear();    if( context.isEmpty() )	editorPage->cmtText->setText("");    else	editorPage->cmtText->setText( richText(context.simplifyWhiteSpace()) );    setTranslation( QString(""), FALSE );    setFinished( finished );    phraseLv->clear();    editorPage->handleSourceChanges();    editorPage->handleCommentChanges();    editorPage->handleTranslationChanges();    editorPage->updateCommentField();}void MessageEditor::showMessage( const QString& text,				 const QString& comment,				 const QString& fullContext,				 const QString& translation,				 MetaTranslatorMessage::Type type,				 const QValueList<Phrase>& phrases ){    bool obsolete = ( type == MetaTranslatorMessage::Obsolete );    setEditionEnabled( !obsolete );    sourceText = text;    guesses.clear();    editorPage->srcText->setText( QString("<p>") + richText( text ) +				  QString("</p>") );    if ( !fullContext.isEmpty() && !comment.isEmpty() )	editorPage->cmtText->setText( richText(fullContext.simplifyWhiteSpace()) +				      "\n" + richText(comment.simplifyWhiteSpace()) );    else if ( !fullContext.isEmpty() && comment.isEmpty() )	editorPage->cmtText->setText(richText(fullContext.simplifyWhiteSpace() ) );    else if ( fullContext.isEmpty() && !comment.isEmpty() )	editorPage->cmtText->setText( richText(comment.simplifyWhiteSpace() ) );    else	editorPage->cmtText->setText( "" );    setTranslation( translation, FALSE );    setFinished( type != MetaTranslatorMessage::Unfinished );    QValueList<Phrase>::ConstIterator p;    phraseLv->clear();    for ( p = phrases.begin(); p != phrases.end(); ++p ) 	(void) new PhraseLVI( phraseLv, *p );    if ( doGuesses ) {	CandidateList cl = similarTextHeuristicCandidates( tor,							   sourceText.latin1(),							   MaxCandidates );	int n = 0;	QValueList<Candidate>::Iterator it = cl.begin();	while ( it != cl.end() ) {	    QString def;	    if ( n < 9 )		def = tr( "Guess (%1)" ).arg( QString(QKeySequence(CTRL | (Key_0 + (n + 1)))) );	    else		def = tr( "Guess" );	    (void) new PhraseLVI( phraseLv,				  Phrase((*it).source, (*it).target, def),				  n + 1 );	    n++;	    ++it;	}    }    editorPage->handleSourceChanges();    editorPage->handleCommentChanges();    editorPage->handleTranslationChanges();    editorPage->updateCommentField();}void MessageEditor::setTranslation( const QString& translation, bool emitt ){    // Block signals so that 'textChanged()' is not emitted when    // for example a new source text item is selected and *not*    // the actual translation.    editorPage->translationMed->blockSignals( !emitt );    editorPage->translationMed->setText( translation );    editorPage->translationMed->blockSignals( FALSE );    if ( !emitt ) 	updateButtons();    emit cutAvailable( FALSE );    emit copyAvailable( FALSE );}void MessageEditor::setEditionEnabled( bool enabled ){    editorPage->transLbl->setEnabled( enabled );    editorPage->translationMed->setReadOnly( !enabled );    phraseLbl->setEnabled( enabled );    phraseLv->setEnabled( enabled );    updateCanPaste();}void MessageEditor::undo(){    editorPage->translationMed->undo();}void MessageEditor::redo(){    editorPage->translationMed->redo();}void MessageEditor::cut(){    editorPage->translationMed->cut();}void MessageEditor::copy(){    editorPage->translationMed->copy();}void MessageEditor::paste(){    editorPage->translationMed->paste();}void MessageEditor::del(){    editorPage->translationMed->del();}void MessageEditor::selectAll(){    editorPage->translationMed->selectAll();}void MessageEditor::emitTranslationChanged(){    emit translationChanged( editorPage->translationMed->text() );}void MessageEditor::guessActivated( int accelKey ){    QListViewItem *item = phraseLv->firstChild();    while ( item != 0 && ((PhraseLVI *) item)->accelKey() != accelKey )	item = item->nextSibling();    if ( item != 0 )	insertPhraseInTranslation( item );}void MessageEditor::insertPhraseInTranslation( QListViewItem *item ){    editorPage->translationMed->insert(((PhraseLVI *) item)->phrase().target());    emit translationChanged( editorPage->translationMed->text() );}void MessageEditor::insertPhraseInTranslationAndLeave( QListViewItem *item ){    editorPage->translationMed->insert(((PhraseLVI *) item)->phrase().target());    emit translationChanged( editorPage->translationMed->text() );    editorPage->translationMed->setFocus();}void MessageEditor::updateButtons(){    bool overwrite = ( !editorPage->translationMed->isReadOnly() &&	     (editorPage->translationMed->text().stripWhiteSpace().isEmpty() ||	      mayOverwriteTranslation) );    mayOverwriteTranslation = FALSE;    emit updateActions( overwrite );}void MessageEditor::beginFromSource(){    mayOverwriteTranslation = TRUE;    setTranslation( sourceText, TRUE );    if ( !editorPage->hasFocus() )	editorPage->setFocus();}void MessageEditor::finishAndNext(){    setFinished( TRUE );    emit nextUnfinished();    if ( !editorPage->hasFocus() )	editorPage->setFocus();}void MessageEditor::updateCanPaste(){    bool oldCanPaste = canPaste;    canPaste = ( !editorPage->translationMed->isReadOnly() &&		 !qApp->clipboard()->text().isNull() );    if ( canPaste != oldCanPaste )	emit pasteAvailable( canPaste );}void MessageEditor::setFinished( bool finished ){    if ( !finished != !itemFinished )	toggleFinished();}void MessageEditor::toggleGuessing(){    doGuesses = !doGuesses;    if ( !doGuesses ) {	phraseLv->clear();    }}

⌨️ 快捷键说明

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