Diffstat (limited to 'noncore/apps/odict/odict.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/odict/odict.cpp | 99 |
1 files changed, 57 insertions, 42 deletions
diff --git a/noncore/apps/odict/odict.cpp b/noncore/apps/odict/odict.cpp index 9f9a8d9..cb9c4e0 100644 --- a/noncore/apps/odict/odict.cpp +++ b/noncore/apps/odict/odict.cpp | |||
@@ -25,181 +25,196 @@ | |||
25 | #include <qpe/config.h> | 25 | #include <qpe/config.h> |
26 | #include <qhbox.h> | 26 | #include <qhbox.h> |
27 | #include <qvbox.h> | 27 | #include <qvbox.h> |
28 | #include <qlabel.h> | 28 | #include <qlabel.h> |
29 | #include <qpushbutton.h> | 29 | #include <qpushbutton.h> |
30 | #include <qlineedit.h> | 30 | #include <qlineedit.h> |
31 | #include <qmainwindow.h> | 31 | #include <qmainwindow.h> |
32 | #include <qstring.h> | 32 | #include <qstring.h> |
33 | #include <qaction.h> | 33 | #include <qaction.h> |
34 | #include <qtextbrowser.h> | 34 | #include <qtextbrowser.h> |
35 | #include <qcombobox.h> | 35 | #include <qcombobox.h> |
36 | 36 | ||
37 | #include <qpe/resource.h> | 37 | #include <qpe/resource.h> |
38 | 38 | ||
39 | 39 | ||
40 | ODict::ODict() : QMainWindow() | 40 | ODict::ODict() : QMainWindow() |
41 | { | 41 | { |
42 | activated_name = QString::null; | 42 | activated_name = QString::null; |
43 | 43 | ||
44 | vbox = new QVBox( this ); | 44 | vbox = new QVBox( this ); |
45 | setCaption( tr( "OPIE-Dictionary" ) ); | 45 | setCaption( tr( "OPIE-Dictionary" ) ); |
46 | setupMenus(); | 46 | setupMenus(); |
47 | 47 | ||
48 | QHBox *hbox = new QHBox( vbox ); | 48 | QHBox *hbox = new QHBox( vbox ); |
49 | QLabel* query_label = new QLabel( tr( "Query:" ) , hbox ); query_label->show(); | 49 | QLabel* query_label = new QLabel( tr( "Query:" ) , hbox ); |
50 | query_label->show(); | ||
50 | query_le = new QLineEdit( hbox ); | 51 | query_le = new QLineEdit( hbox ); |
51 | query_co = new QComboBox( hbox ); | 52 | query_co = new QComboBox( hbox ); |
52 | connect( query_co , SIGNAL( activated(int) ), this, SLOT( slotMethodChanged(int) ) ); | 53 | connect( query_co , SIGNAL( activated(const QString&) ), this, SLOT( slotMethodChanged(const QString&) ) ); |
53 | ok_button = new QPushButton( tr( "&Ok" ), hbox ); | 54 | ok_button = new QPushButton( tr( "&Ok" ), hbox ); |
54 | connect( ok_button, SIGNAL( released() ), this, SLOT( slotStartQuery() ) ); | 55 | connect( ok_button, SIGNAL( released() ), this, SLOT( slotStartQuery() ) ); |
56 | top_name = new QLabel( vbox ); | ||
55 | browser_top = new QTextBrowser( vbox ); | 57 | browser_top = new QTextBrowser( vbox ); |
58 | bottom_name = new QLabel( vbox ); | ||
56 | browser_bottom = new QTextBrowser( vbox ); | 59 | browser_bottom = new QTextBrowser( vbox ); |
57 | 60 | ||
58 | ding = new DingWidget(); | 61 | ding = new DingWidget(); |
59 | ding->loadValues(); | 62 | ding->loadValues(); |
60 | 63 | ||
61 | loadConfig(); | 64 | loadConfig(); |
62 | setCentralWidget( vbox ); | 65 | setCentralWidget( vbox ); |
63 | } | 66 | } |
64 | 67 | ||
65 | void ODict::loadConfig() | 68 | void ODict::loadConfig() |
66 | { | 69 | { |
67 | Config cfg ( "odict" ); | 70 | Config cfg ( "odict" ); |
68 | cfg.setGroup( "generalsettings" ); | 71 | cfg.setGroup( "generalsettings" ); |
69 | errorTol = cfg.readEntry( "errtol" ).toInt(); | 72 | errorTol = cfg.readEntry( "errtol" ).toInt(); |
70 | casesens = cfg.readEntry( "casesens" ).toInt(); | 73 | casesens = cfg.readEntry( "casesens" ).toInt(); |
71 | regexp = cfg.readEntry( "regexp" ).toInt(); | 74 | regexp = cfg.readEntry( "regexp" ).toInt(); |
72 | completewords = cfg.readEntry( "completewords" ).toInt(); | 75 | completewords = cfg.readEntry( "completewords" ).toInt(); |
73 | 76 | ||
74 | QStringList groupListCfg = cfg.groupList().grep( "Method_" ); | 77 | QStringList groupListCfg = cfg.groupList().grep( "Method_" ); |
75 | query_co->clear(); | 78 | query_co->clear(); |
76 | for ( QStringList::Iterator it = groupListCfg.begin() ; it != groupListCfg.end() ; ++it ) | 79 | for ( QStringList::Iterator it = groupListCfg.begin() ; it != groupListCfg.end() ; ++it ) |
77 | { | 80 | { |
78 | cfg.setGroup( *it ); | 81 | cfg.setGroup( *it ); |
79 | query_co->insertItem( cfg.readEntry( "Name" ) ); | 82 | query_co->insertItem( cfg.readEntry( "Name" ) ); |
80 | } | 83 | } |
81 | slotMethodChanged( 1 ); //FIXME: this line should not contain a integer | 84 | //XXXslotMethodChanged( "1" ); //FIXME: this line should not contain a integer |
82 | } | 85 | } |
83 | 86 | ||
84 | 87 | ||
85 | void ODict::saveConfig() | 88 | void ODict::saveConfig() |
86 | { | 89 | { |
87 | Config cfg ( "odict" ); | 90 | Config cfg ( "odict" ); |
88 | cfg.setGroup( "generalsettings" ); | 91 | cfg.setGroup( "generalsettings" ); |
89 | cfg.writeEntry( "errtol" , errorTol ); | 92 | cfg.writeEntry( "errtol" , errorTol ); |
90 | cfg.writeEntry( "casesens" , casesens ); | 93 | cfg.writeEntry( "casesens" , casesens ); |
91 | cfg.writeEntry( "regexp" , regexp ); | 94 | cfg.writeEntry( "regexp" , regexp ); |
92 | cfg.writeEntry( "completewords" , completewords ); | 95 | cfg.writeEntry( "completewords" , completewords ); |
93 | } | 96 | } |
94 | 97 | ||
95 | void ODict::slotStartQuery() | 98 | void ODict::slotStartQuery() |
96 | { | 99 | { |
97 | /* | 100 | if ( !query_le->text( ).isEmpty() ) |
98 | * if the user has not yet defined a dictionary | ||
99 | */ | ||
100 | if ( !query_co->currentText() ) | ||
101 | { | 101 | { |
102 | switch ( QMessageBox::information( this, tr( "OPIE-Dictionary" ), | 102 | /* |
103 | tr( "No dictionary defined" ), | 103 | * if the user has not yet defined a dictionary |
104 | tr( "&Define one" ), | 104 | */ |
105 | tr( "&Cancel" ), | 105 | if ( !query_co->currentText() ) |
106 | 0, // Define a dict choosen | 106 | { |
107 | 1 ) ) // Cancel choosen | 107 | switch ( QMessageBox::information( this, tr( "OPIE-Dictionary" ), |
108 | { | 108 | tr( "No dictionary defined" ), |
109 | 109 | tr( "&Define one" ), | |
110 | case 0: | 110 | tr( "&Cancel" ), |
111 | slotSettings(); | 111 | 0, // Define a dict choosen |
112 | break; | 112 | 1 ) ) // Cancel choosen |
113 | case 1: // stop here | 113 | { |
114 | return; | 114 | |
115 | } | 115 | case 0: |
116 | } | 116 | slotSettings(); |
117 | 117 | break; | |
118 | /* | 118 | case 1: // stop here |
119 | * ok, the user has defined a dict | 119 | return; |
120 | */ | 120 | } |
121 | QString querystring = query_le->text(); | 121 | } |
122 | ding->setCaseSensitive( casesens ); | 122 | |
123 | ding->setCompleteWord( completewords ); | 123 | /* |
124 | ding->setDict( activated_name ); | 124 | * ok, the user has defined a dict |
125 | 125 | */ | |
126 | if ( activated_name != ding->loadedDict() ) | 126 | QString querystring = query_le->text(); |
127 | ding->loadDict(activated_name); | 127 | ding->setCaseSensitive( casesens ); |
128 | 128 | ding->setCompleteWord( completewords ); | |
129 | BroswerContent test = ding->setText( querystring ); | 129 | ding->setDict( activated_name ); |
130 | 130 | top_name->setText( ding->lang1_name ); | |
131 | browser_top->setText( test.top ); | 131 | bottom_name->setText( ding->lang2_name ); |
132 | browser_bottom->setText( test.bottom ); | 132 | |
133 | if ( activated_name != ding->loadedDict() ) | ||
134 | ding->loadDict(activated_name); | ||
135 | |||
136 | BroswerContent test = ding->setText( querystring ); | ||
137 | |||
138 | browser_top->setText( test.top ); | ||
139 | browser_bottom->setText( test.bottom ); | ||
140 | } | ||
133 | } | 141 | } |
134 | 142 | ||
135 | 143 | ||
136 | void ODict::slotSetErrorcount( int count ) | 144 | void ODict::slotSetErrorcount( int count ) |
137 | { | 145 | { |
138 | errorTol = count; | 146 | errorTol = count; |
139 | } | 147 | } |
140 | 148 | ||
141 | void ODict::slotSettings() | 149 | void ODict::slotSettings() |
142 | { | 150 | { |
143 | ConfigDlg dlg( this, "Config" , true); | 151 | ConfigDlg dlg( this, "Config" , true); |
144 | if ( dlg.exec() == QDialog::Accepted ) | 152 | if ( dlg.exec() == QDialog::Accepted ) |
145 | { | 153 | { |
146 | dlg.writeEntries(); | 154 | dlg.writeEntries(); |
147 | loadConfig(); | 155 | loadConfig(); |
148 | } | 156 | } |
149 | else qDebug( "abgebrochen" ); | ||
150 | } | 157 | } |
151 | 158 | ||
152 | void ODict::slotSetParameter( int count ) | 159 | void ODict::slotSetParameter( int count ) |
153 | { | 160 | { |
154 | if ( count == 0 ) | 161 | if ( count == 0 ) |
155 | { | 162 | { |
156 | if ( casesens ) | 163 | if ( casesens ) |
157 | casesens = false; | 164 | casesens = false; |
158 | else | 165 | else |
159 | casesens = true; | 166 | casesens = true; |
160 | } | 167 | } |
161 | 168 | ||
162 | if ( count == 1 ) | 169 | if ( count == 1 ) |
163 | { | 170 | { |
164 | if ( completewords ) | 171 | if ( completewords ) |
165 | completewords = false; | 172 | completewords = false; |
166 | else | 173 | else |
167 | completewords = true; | 174 | completewords = true; |
168 | } | 175 | } |
169 | if ( count == 2 ) | 176 | if ( count == 2 ) |
170 | { | 177 | { |
171 | if ( regexp ) | 178 | if ( regexp ) |
172 | regexp = false; | 179 | regexp = false; |
173 | else | 180 | else |
174 | regexp = true; | 181 | regexp = true; |
175 | } | 182 | } |
176 | else qWarning( "ERROR" ); | 183 | else qWarning( "ERROR" ); |
177 | } | 184 | } |
178 | 185 | ||
179 | void ODict::slotMethodChanged( int /*methodnumber*/ ) | 186 | void ODict::slotMethodChanged( const QString& methodnumber ) |
180 | { | 187 | { |
181 | activated_name = query_co->currentText(); | 188 | activated_name = methodnumber; |
189 | |||
190 | if ( activated_name != ding->loadedDict() ) | ||
191 | ding->loadDict(activated_name); | ||
192 | |||
193 | top_name->setText( ding->lang1_name ); | ||
194 | top_name->setAlignment( AlignHCenter ); | ||
195 | bottom_name->setText( ding->lang2_name ); | ||
196 | bottom_name->setAlignment( AlignHCenter ); | ||
182 | } | 197 | } |
183 | 198 | ||
184 | void ODict::setupMenus() | 199 | void ODict::setupMenus() |
185 | { | 200 | { |
186 | menu = new QMenuBar( this ); | 201 | menu = new QMenuBar( this ); |
187 | 202 | ||
188 | settings = new QPopupMenu( menu ); | 203 | settings = new QPopupMenu( menu ); |
189 | setting_a = new QAction(tr( "Configuration" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 204 | setting_a = new QAction(tr( "Configuration" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); |
190 | connect( setting_a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); | 205 | connect( setting_a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); |
191 | setting_a->addTo( settings ); | 206 | setting_a->addTo( settings ); |
192 | setting_b = new QAction(tr( "Searchmethods" ), Resource::loadPixmap( "edit" ), QString::null, 0, this, 0 ); | 207 | setting_b = new QAction(tr( "Searchmethods" ), Resource::loadPixmap( "edit" ), QString::null, 0, this, 0 ); |
193 | 208 | ||
194 | parameter = new QPopupMenu( menu ); | 209 | parameter = new QPopupMenu( menu ); |
195 | connect( parameter, SIGNAL( activated( int ) ), this, SLOT( slotSetParameter( int ) ) ); | 210 | connect( parameter, SIGNAL( activated( int ) ), this, SLOT( slotSetParameter( int ) ) ); |
196 | parameter->insertItem( tr( "C&ase sensitive" ), 0 ,0 ); | 211 | parameter->insertItem( tr( "C&ase sensitive" ), 0 ,0 ); |
197 | parameter->insertItem( tr( "Only &complete Words" ), 1 , 1) ; | 212 | parameter->insertItem( tr( "Only &complete Words" ), 1 , 1) ; |
198 | parameter->insertItem( tr( "Allow ®. expressions" ), 2 ); | 213 | parameter->insertItem( tr( "Allow ®. expressions" ), 2 ); |
199 | parameter->insertSeparator(); | 214 | parameter->insertSeparator(); |
200 | error_tol_menu = new QPopupMenu( menu ); | 215 | error_tol_menu = new QPopupMenu( menu ); |
201 | error_tol_menu->setCheckable( TRUE ); | 216 | error_tol_menu->setCheckable( TRUE ); |
202 | connect( error_tol_menu, SIGNAL( activated( int ) ), this, SLOT( slotSetErrorcount( int ) ) ); | 217 | connect( error_tol_menu, SIGNAL( activated( int ) ), this, SLOT( slotSetErrorcount( int ) ) ); |
203 | 218 | ||
204 | error_tol_menu->insertItem( tr( "0 Errors" ), 0 ); | 219 | error_tol_menu->insertItem( tr( "0 Errors" ), 0 ); |
205 | error_tol_menu->insertItem( tr( "1 Errors" ), 1 ); | 220 | error_tol_menu->insertItem( tr( "1 Errors" ), 1 ); |