CMiniLexicon::FindMajorSignatures(): use log file routines
[linguistica.git] / corpusviewdialog.cpp
bloba109c56c0638e114668a379afcbb3cd29bb64e6b
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"
7 #include "Lexicon.h"
8 #include "CorpusWord.h"
9 #include "Linker.h"
10 #include "Affix.h"
11 #include "Stem.h"
13 CorpusViewDialog::CorpusViewDialog( QStringList* left, QStringList* right,
14 QWidget* parent, Qt::WindowFlags fl )
15 : QDialog( parent, 0, false, fl ), Ui::CorpusViewDialogBase()
17 setupUi( this );
19 m_left = left;
20 m_right = right;
22 m_pLexicon = NULL;
24 init();
28 CorpusViewDialog::CorpusViewDialog( CLexicon* pLexicon, QWidget* parent,
29 Qt::WindowFlags fl )
30 : QDialog( parent, 0, false, fl ), Ui::CorpusViewDialogBase()
32 setupUi( this );
34 m_left = pLexicon->GetCorpus();
35 m_right = pLexicon->GetCorpus();
37 m_pLexicon = pLexicon;
39 init();
43 void CorpusViewDialog::init()
45 m_lx = 0;
46 m_ly = 0;
48 m_rx = 0;
49 m_ry = 0;
51 if( m_pLexicon )
53 m_showMarkedUpTextCheckBox->setEnabled( TRUE );
56 m_scrolling = FALSE;
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;
66 CLParse* pMorpheme;
68 StringToString* OutFilter = m_pLexicon->GetOutFilter();
70 if(b && m_pLexicon)
72 m_leftTextEdit->setText( m_left->join( "\n\n" ) );
73 m_rightTextEdit->clear();
75 // Mark up the text in the right edit using lexical
76 // information
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 );
85 if( pCorpusWord )
87 if( pCorpusWord->Size() > 1 )
89 for( int i = 1; i <= pCorpusWord->Size(); i++ )
91 pMorpheme = pCorpusWord->GetMorpheme(i);
93 if( !pMorpheme )
95 setRightStyle( "Error" );
96 m_rightTextEdit->insert( pCorpusWord->GetPiece(i).Display( OutFilter ) );
97 setRightStyle( "Main" );
98 if( i < pCorpusWord->Size() ) m_rightTextEdit->insert( "+" );
99 continue;
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( "+" );
115 } else {
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( "+" );
124 else
126 // CorpusWord is an unanalyzed word, print with word
127 // mark-up
128 setRightStyle( "Word" );
129 m_rightTextEdit->insert( pCorpusWord->Display( OutFilter ) );
130 setRightStyle( "Main" );
133 m_rightTextEdit->insert( " " );
135 else
137 // CorpusWord doesn't exist, just print the string without
138 // mark-up
139 m_rightTextEdit->insert( *wordIt );
140 m_rightTextEdit->insert( " " );
144 // End of line;
145 m_rightTextEdit->insert( "\n\n" );
148 else
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;
161 int byX = x - m_lx,
162 byY = y - m_ly;
164 m_lx = x;
165 m_ly = y;
167 m_scrolling = TRUE;
168 m_rightTextEdit->scrollBy( byX, byY );
169 m_scrolling = FALSE;
173 void CorpusViewDialog::moveLeftView( int x, int y )
175 if( !m_bindScrollBarsCheckBox->isChecked() ) return;
176 if( m_scrolling ) return;
178 int byX = x - m_rx,
179 byY = y - m_ry;
181 m_rx = x;
182 m_ry = y;
184 m_scrolling = TRUE;
185 m_leftTextEdit->scrollBy( byX, byY );
186 m_scrolling = FALSE;
190 void CorpusViewDialog::wordWrap( bool b )
192 if(b)
194 m_leftTextEdit->setWordWrap( Q3TextEdit::WidgetWidth );
195 m_rightTextEdit->setWordWrap( Q3TextEdit::WidgetWidth );
197 else
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() );