1 // Implementation of “Linguistica : Corpus View” dialog
2 // Copyright © 2009 The University of Chicago
3 #include "corpusviewdialog.h"
5 #include "linguisticamainwindow.h"
6 #include "LPreferences.h"
8 #include "CorpusWord.h"
13 CorpusViewDialog::CorpusViewDialog( QStringList
* left
, QStringList
* right
,
14 QWidget
* parent
, Qt::WindowFlags fl
)
15 : QDialog( parent
, 0, false, fl
), Ui::CorpusViewDialogBase()
28 CorpusViewDialog::CorpusViewDialog( CLexicon
* pLexicon
, QWidget
* parent
,
30 : QDialog( parent
, 0, false, fl
), Ui::CorpusViewDialogBase()
34 m_left
= pLexicon
->GetCorpus();
35 m_right
= pLexicon
->GetCorpus();
37 m_pLexicon
= pLexicon
;
43 void CorpusViewDialog::init()
53 m_showMarkedUpTextCheckBox
->setEnabled( TRUE
);
58 m_leftTextEdit
->setText( m_left
->join( "\n\n" ) );
59 m_rightTextEdit
->setText( m_right
->join( "\n\n" ) );
63 void CorpusViewDialog::showMarkedUpText( bool b
)
65 CCorpusWord
* pCorpusWord
;
68 StringToString
* OutFilter
= m_pLexicon
->GetOutFilter();
72 m_leftTextEdit
->setText( m_left
->join( "\n\n" ) );
73 m_rightTextEdit
->clear();
75 // Mark up the text in the right edit using lexical
77 for( QStringList::Iterator lineIt
= m_right
->begin(); lineIt
!= m_right
->end(); ++lineIt
)
79 QStringList line
= QStringList::split( " ", *lineIt
);
81 for( QStringList::Iterator wordIt
= line
.begin(); wordIt
!= line
.end(); ++wordIt
)
83 pCorpusWord
= m_pLexicon
->GetCorpusMap()->find( *wordIt
);
87 if( pCorpusWord
->Size() > 1 )
89 for( int i
= 1; i
<= pCorpusWord
->Size(); i
++ )
91 pMorpheme
= pCorpusWord
->GetMorpheme(i
);
95 setRightStyle( "Error" );
96 m_rightTextEdit
->insert( pCorpusWord
->GetPiece(i
).Display( OutFilter
) );
97 setRightStyle( "Main" );
98 if( i
< pCorpusWord
->Size() ) m_rightTextEdit
->insert( "+" );
102 if (CStem
* stem
= dynamic_cast<CStem
*>(pMorpheme
)) {
103 // Print with stem mark-up
104 setRightStyle( "Stem" );
105 m_rightTextEdit
->insert( stem
->Display( OutFilter
) );
106 setRightStyle( "Main" );
107 if( i
< pCorpusWord
->Size() ) m_rightTextEdit
->insert( "+" );
108 } else if (dynamic_cast<CAffix
*>(pMorpheme
) ||
109 dynamic_cast<CLinker
*>(pMorpheme
)) {
110 // Print with affix mark-up
111 setRightStyle( "Affix" );
112 m_rightTextEdit
->insert( pMorpheme
->Display( OutFilter
) );
113 setRightStyle( "Main" );
114 if( i
< pCorpusWord
->Size() ) m_rightTextEdit
->insert( "+" );
116 // Don't know why, print with error mark-up
117 setRightStyle( "Error" );
118 m_rightTextEdit
->insert( pMorpheme
->Display( OutFilter
) );
119 setRightStyle( "Main" );
120 if( i
< pCorpusWord
->Size() ) m_rightTextEdit
->insert( "+" );
126 // CorpusWord is an unanalyzed word, print with word
128 setRightStyle( "Word" );
129 m_rightTextEdit
->insert( pCorpusWord
->Display( OutFilter
) );
130 setRightStyle( "Main" );
133 m_rightTextEdit
->insert( " " );
137 // CorpusWord doesn't exist, just print the string without
139 m_rightTextEdit
->insert( *wordIt
);
140 m_rightTextEdit
->insert( " " );
145 m_rightTextEdit
->insert( "\n\n" );
150 m_leftTextEdit
->setText( m_left
->join( "\n\n" ) );
151 m_rightTextEdit
->setText( m_right
->join( "\n\n" ) );
156 void CorpusViewDialog::moveRightView( int x
, int y
)
158 if( !m_bindScrollBarsCheckBox
->isChecked() ) return;
159 if( m_scrolling
) return;
168 m_rightTextEdit
->scrollBy( byX
, byY
);
173 void CorpusViewDialog::moveLeftView( int x
, int y
)
175 if( !m_bindScrollBarsCheckBox
->isChecked() ) return;
176 if( m_scrolling
) return;
185 m_leftTextEdit
->scrollBy( byX
, byY
);
190 void CorpusViewDialog::wordWrap( bool b
)
194 m_leftTextEdit
->setWordWrap( Q3TextEdit::WidgetWidth
);
195 m_rightTextEdit
->setWordWrap( Q3TextEdit::WidgetWidth
);
199 m_leftTextEdit
->setWordWrap( Q3TextEdit::NoWrap
);
200 m_rightTextEdit
->setWordWrap( Q3TextEdit::NoWrap
);
205 void CorpusViewDialog::setRightStyle( QString style
)
207 // So far, possible values are "Main", "Affix", "Stem",
208 // "Word", "Signature", and "Error". Someday there may
209 // be more. Nothing happens if the style doesn't exist.
211 QFont font
= m_pLexicon
->GetDocument()->GetEastFont();
212 QString color
= m_pLexicon
->GetDocument()->GetPreferences()->GetPreference( style
+ "_Color" );
213 if( color
.length() == 0 ) color
= "black";
215 m_rightTextEdit
->setColor( QColor( color
) );
217 m_rightTextEdit
->setFamily( font
.family() );
218 m_rightTextEdit
->setPointSize( font
.pointSize() );
220 font
= m_pLexicon
->GetDocument()->GetPreferences()->GetFontPreference( style
);
221 m_rightTextEdit
->setBold( font
.bold() );
222 m_rightTextEdit
->setItalic( font
.italic() );
223 m_rightTextEdit
->setUnderline( font
.underline() );