Mercurial > hg > easyhg-kdiff3
comparison kdiff3/src/smalldialogs.cpp @ 69:8febbfb1148c
KDiff3 0.9.89
author | joachim99 |
---|---|
date | Mon, 10 Apr 2006 08:40:51 +0000 |
parents | |
children | 5bbfe4784324 |
comparison
equal
deleted
inserted
replaced
68:d7cafcda8c99 | 69:8febbfb1148c |
---|---|
1 /*************************************************************************** | |
2 * Copyright (C) 2005-2006 by Joachim Eibl * | |
3 * joachim.eibl at gmx.de * | |
4 * * | |
5 * This program is free software; you can redistribute it and/or modify * | |
6 * it under the terms of the GNU General Public License as published by * | |
7 * the Free Software Foundation; either version 2 of the License, or * | |
8 * (at your option) any later version. * | |
9 * * | |
10 * This program is distributed in the hope that it will be useful, * | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
13 * GNU General Public License for more details. * | |
14 * * | |
15 * You should have received a copy of the GNU General Public License * | |
16 * along with this program; if not, write to the * | |
17 * Free Software Foundation, Inc., * | |
18 * 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. * | |
19 ***************************************************************************/ | |
20 | |
21 #include "smalldialogs.h" | |
22 #include "optiondialog.h" | |
23 | |
24 #include <qcombobox.h> | |
25 #include <qcheckbox.h> | |
26 #include <qlineedit.h> | |
27 #include <qlabel.h> | |
28 #include <qlayout.h> | |
29 #include <qpushbutton.h> | |
30 #include <qdragobject.h> | |
31 #include <qregexp.h> | |
32 #include <qtooltip.h> | |
33 #include <qpopupmenu.h> | |
34 #include <qcursor.h> | |
35 | |
36 | |
37 #include <kfiledialog.h> | |
38 #include <klocale.h> | |
39 | |
40 // OpenDialog ************************************************************** | |
41 | |
42 OpenDialog::OpenDialog( | |
43 QWidget* pParent, const QString& n1, const QString& n2, const QString& n3, | |
44 bool bMerge, const QString& outputName, const char* slotConfigure, OptionDialog* pOptions ) | |
45 : QDialog( pParent, "OpenDialog", true /*modal*/ ) | |
46 { | |
47 m_pOptions = pOptions; | |
48 | |
49 QVBoxLayout* v = new QVBoxLayout( this, 5 ); | |
50 QGridLayout* h = new QGridLayout( v, 5, 4, 5 ); | |
51 h->setColStretch( 1, 10 ); | |
52 | |
53 QLabel* label = new QLabel( i18n("A (Base):"), this ); | |
54 | |
55 m_pLineA = new QComboBox( true, this ); | |
56 m_pLineA->insertStringList( m_pOptions->m_recentAFiles ); | |
57 m_pLineA->setEditText( KURL(n1).prettyURL() ); | |
58 m_pLineA->setMinimumSize( 200, m_pLineA->size().height() ); | |
59 QPushButton * button = new QPushButton( i18n("File..."), this ); | |
60 connect( button, SIGNAL(clicked()), this, SLOT( selectFileA() ) ); | |
61 QPushButton * button2 = new QPushButton( i18n("Dir..."), this ); | |
62 connect( button2, SIGNAL(clicked()), this, SLOT( selectDirA() ) ); | |
63 connect( m_pLineA, SIGNAL(textChanged(const QString&)), this, SLOT(inputFilenameChanged() ) ); | |
64 | |
65 h->addWidget( label, 0, 0 ); | |
66 h->addWidget( m_pLineA, 0, 1 ); | |
67 h->addWidget( button, 0, 2 ); | |
68 h->addWidget( button2, 0, 3 ); | |
69 | |
70 label = new QLabel( "B:", this ); | |
71 m_pLineB = new QComboBox( true, this ); | |
72 m_pLineB->insertStringList( m_pOptions->m_recentBFiles ); | |
73 m_pLineB->setEditText( KURL(n2).prettyURL() ); | |
74 m_pLineB->setMinimumSize( 200, m_pLineB->size().height() ); | |
75 button = new QPushButton( i18n("File..."), this ); | |
76 connect( button, SIGNAL(clicked()), this, SLOT( selectFileB() ) ); | |
77 button2 = new QPushButton( i18n("Dir..."), this ); | |
78 connect( button2, SIGNAL(clicked()), this, SLOT( selectDirB() ) ); | |
79 connect( m_pLineB, SIGNAL(textChanged(const QString&)), this, SLOT(inputFilenameChanged() ) ); | |
80 | |
81 h->addWidget( label, 1, 0 ); | |
82 h->addWidget( m_pLineB, 1, 1 ); | |
83 h->addWidget( button, 1, 2 ); | |
84 h->addWidget( button2, 1, 3 ); | |
85 | |
86 label = new QLabel( i18n("C (Optional):"), this ); | |
87 m_pLineC= new QComboBox( true, this ); | |
88 m_pLineC->insertStringList( m_pOptions->m_recentCFiles ); | |
89 m_pLineC->setEditText( KURL(n3).prettyURL() ); | |
90 m_pLineC->setMinimumSize( 200, m_pLineC->size().height() ); | |
91 button = new QPushButton( i18n("File..."), this ); | |
92 connect( button, SIGNAL(clicked()), this, SLOT( selectFileC() ) ); | |
93 button2 = new QPushButton( i18n("Dir..."), this ); | |
94 connect( button2, SIGNAL(clicked()), this, SLOT( selectDirC() ) ); | |
95 connect( m_pLineC, SIGNAL(textChanged(const QString&)), this, SLOT(inputFilenameChanged() ) ); | |
96 | |
97 h->addWidget( label, 2, 0 ); | |
98 h->addWidget( m_pLineC, 2, 1 ); | |
99 h->addWidget( button, 2, 2 ); | |
100 h->addWidget( button2, 2, 3 ); | |
101 | |
102 m_pMerge = new QCheckBox( i18n("Merge"), this ); | |
103 h->addWidget( m_pMerge, 3, 0 ); | |
104 | |
105 QHBoxLayout* hl = new QHBoxLayout(); | |
106 h->addLayout( hl, 3, 1 ); | |
107 hl->addStretch(2); | |
108 button = new QPushButton(i18n("Swap/Copy Names ..."), this); | |
109 //button->setToggleButton(false); | |
110 hl->addWidget( button ); | |
111 | |
112 QPopupMenu* m = new QPopupMenu(this); | |
113 int id=0; | |
114 m->insertItem( i18n("Swap %1<->%2").arg("A").arg("B"), id++ ); | |
115 m->insertItem( i18n("Swap %1<->%2").arg("B").arg("C"), id++ ); | |
116 m->insertItem( i18n("Swap %1<->%2").arg("C").arg("A"), id++ ); | |
117 m->insertItem( i18n("Copy %1->Output").arg("A"), id++ ); | |
118 m->insertItem( i18n("Copy %1->Output").arg("B"), id++ ); | |
119 m->insertItem( i18n("Copy %1->Output").arg("C"), id++ ); | |
120 m->insertItem( i18n("Swap %1<->Output").arg("A"), id++ ); | |
121 m->insertItem( i18n("Swap %1<->Output").arg("B"), id++ ); | |
122 m->insertItem( i18n("Swap %1<->Output").arg("C"), id++ ); | |
123 connect( m, SIGNAL(activated(int)), this, SLOT(slotSwapCopyNames(int))); | |
124 button->setPopup(m); | |
125 | |
126 | |
127 hl->addStretch(2); | |
128 | |
129 label = new QLabel( i18n("Output (optional):"), this ); | |
130 m_pLineOut = new QComboBox( true, this ); | |
131 m_pLineOut->insertStringList( m_pOptions->m_recentOutputFiles ); | |
132 m_pLineOut->setEditText( KURL(outputName).prettyURL() ); | |
133 m_pLineOut->setMinimumSize( 200, m_pLineOut->size().height() ); | |
134 button = new QPushButton( i18n("File..."), this ); | |
135 connect( button, SIGNAL(clicked()), this, SLOT( selectOutputName() ) ); | |
136 button2 = new QPushButton( i18n("Dir..."), this ); | |
137 connect( button2, SIGNAL(clicked()), this, SLOT( selectOutputDir() ) ); | |
138 connect( m_pMerge, SIGNAL(stateChanged(int)), this, SLOT(internalSlot(int)) ); | |
139 connect( this, SIGNAL(internalSignal(bool)), m_pLineOut, SLOT(setEnabled(bool)) ); | |
140 connect( this, SIGNAL(internalSignal(bool)), button, SLOT(setEnabled(bool)) ); | |
141 connect( this, SIGNAL(internalSignal(bool)), button2, SLOT(setEnabled(bool)) ); | |
142 | |
143 m_pMerge->setChecked( !bMerge ); | |
144 m_pMerge->setChecked( bMerge ); | |
145 // m_pLineOutput->setEnabled( bMerge ); | |
146 | |
147 // button->setEnabled( bMerge ); | |
148 | |
149 h->addWidget( label, 4, 0 ); | |
150 h->addWidget( m_pLineOut, 4, 1 ); | |
151 h->addWidget( button, 4, 2 ); | |
152 h->addWidget( button2, 4, 3 ); | |
153 | |
154 h->addColSpacing( 1, 200 ); | |
155 | |
156 QHBoxLayout* l = new QHBoxLayout( v, 5 ); | |
157 | |
158 button = new QPushButton( i18n("Configure..."), this ); | |
159 connect( button, SIGNAL(clicked()), pParent, slotConfigure ); | |
160 l->addWidget( button, 1 ); | |
161 | |
162 l->addStretch(1); | |
163 | |
164 button = new QPushButton( i18n("&OK"), this ); | |
165 button->setDefault( true ); | |
166 connect( button, SIGNAL(clicked()), this, SLOT( accept() ) ); | |
167 l->addWidget( button, 1 ); | |
168 | |
169 button = new QPushButton( i18n("&Cancel"), this ); | |
170 connect( button, SIGNAL(clicked()), this, SLOT( reject() ) ); | |
171 l->addWidget( button,1 ); | |
172 | |
173 QSize sh = sizeHint(); | |
174 setFixedHeight( sh.height() ); | |
175 m_bInputFileNameChanged = false; | |
176 | |
177 #ifdef KREPLACEMENTS_H | |
178 m_pLineA->lineEdit()->installEventFilter( this ); | |
179 m_pLineB->lineEdit()->installEventFilter( this ); | |
180 m_pLineC->lineEdit()->installEventFilter( this ); | |
181 m_pLineOut->lineEdit()->installEventFilter( this ); | |
182 #endif | |
183 } | |
184 | |
185 // Eventfilter: Only needed under Windows. | |
186 // Without this, files dropped in the line edit have URL-encoding. | |
187 // This eventfilter decodes the filenames as needed by KDiff3. | |
188 bool OpenDialog::eventFilter(QObject* o, QEvent* e) | |
189 { | |
190 if (e->type()==QEvent::Drop) | |
191 { | |
192 QDropEvent* d = static_cast<QDropEvent*>(e); | |
193 | |
194 if ( !QUriDrag::canDecode( d ) ) { | |
195 return false; | |
196 } | |
197 | |
198 QStringList lst; | |
199 QUriDrag::decodeLocalFiles( d, lst ); | |
200 | |
201 if ( lst.count() > 0 ) | |
202 { | |
203 static_cast<QLineEdit*>(o)->setText( lst[0] ); | |
204 static_cast<QLineEdit*>(o)->setFocus(); | |
205 } | |
206 | |
207 return true; | |
208 } | |
209 return false; | |
210 } | |
211 | |
212 | |
213 void OpenDialog::selectURL( QComboBox* pLine, bool bDir, int i, bool bSave ) | |
214 { | |
215 QString current = pLine->currentText(); | |
216 if (current.isEmpty() && i>3 ){ current = m_pLineC->currentText(); } | |
217 if (current.isEmpty() ){ current = m_pLineB->currentText(); } | |
218 if (current.isEmpty() ){ current = m_pLineA->currentText(); } | |
219 KURL newURL = bDir ? KFileDialog::getExistingURL( current, this) | |
220 : bSave ? KFileDialog::getSaveURL( current, 0, this) | |
221 : KFileDialog::getOpenURL( current, 0, this); | |
222 if ( !newURL.isEmpty() ) | |
223 { | |
224 pLine->setEditText( newURL.url() ); | |
225 } | |
226 // newURL won't be modified if nothing was selected. | |
227 } | |
228 | |
229 void OpenDialog::selectFileA() { selectURL( m_pLineA, false, 1, false ); } | |
230 void OpenDialog::selectFileB() { selectURL( m_pLineB, false, 2, false ); } | |
231 void OpenDialog::selectFileC() { selectURL( m_pLineC, false, 3, false ); } | |
232 void OpenDialog::selectOutputName(){ selectURL( m_pLineOut, false, 4, true ); } | |
233 void OpenDialog::selectDirA() { selectURL( m_pLineA, true, 1, false ); } | |
234 void OpenDialog::selectDirB() { selectURL( m_pLineB, true, 2, false ); } | |
235 void OpenDialog::selectDirC() { selectURL( m_pLineC, true, 3, false ); } | |
236 void OpenDialog::selectOutputDir() { selectURL( m_pLineOut, true, 4, true ); } | |
237 | |
238 void OpenDialog::internalSlot(int i) | |
239 { | |
240 emit internalSignal(i!=0); | |
241 } | |
242 | |
243 // Clear the output-filename when any input-filename changed, | |
244 // because users forgot to change the output and accidently overwrote it with | |
245 // wrong data during a merge. | |
246 void OpenDialog::inputFilenameChanged() | |
247 { | |
248 if(!m_bInputFileNameChanged) | |
249 { | |
250 m_bInputFileNameChanged=true; | |
251 m_pLineOut->clearEdit(); | |
252 } | |
253 } | |
254 | |
255 void OpenDialog::accept() | |
256 { | |
257 unsigned int maxNofRecentFiles = 10; | |
258 | |
259 QString s = m_pLineA->currentText(); | |
260 s = KURL::fromPathOrURL(s).prettyURL(); | |
261 QStringList* sl = &m_pOptions->m_recentAFiles; | |
262 // If an item exist, remove it from the list and reinsert it at the beginning. | |
263 sl->remove(s); | |
264 if ( !s.isEmpty() ) sl->prepend( s ); | |
265 if (sl->count()>maxNofRecentFiles) sl->erase( sl->at(maxNofRecentFiles), sl->end() ); | |
266 | |
267 s = m_pLineB->currentText(); | |
268 s = KURL::fromPathOrURL(s).prettyURL(); | |
269 sl = &m_pOptions->m_recentBFiles; | |
270 sl->remove(s); | |
271 if ( !s.isEmpty() ) sl->prepend( s ); | |
272 if (sl->count()>maxNofRecentFiles) sl->erase( sl->at(maxNofRecentFiles), sl->end() ); | |
273 | |
274 s = m_pLineC->currentText(); | |
275 s = KURL::fromPathOrURL(s).prettyURL(); | |
276 sl = &m_pOptions->m_recentCFiles; | |
277 sl->remove(s); | |
278 if ( !s.isEmpty() ) sl->prepend( s ); | |
279 if (sl->count()>maxNofRecentFiles) sl->erase( sl->at(maxNofRecentFiles), sl->end() ); | |
280 | |
281 s = m_pLineOut->currentText(); | |
282 s = KURL::fromPathOrURL(s).prettyURL(); | |
283 sl = &m_pOptions->m_recentOutputFiles; | |
284 sl->remove(s); | |
285 if ( !s.isEmpty() ) sl->prepend( s ); | |
286 if (sl->count()>maxNofRecentFiles) sl->erase( sl->at(maxNofRecentFiles), sl->end() ); | |
287 | |
288 QDialog::accept(); | |
289 } | |
290 | |
291 void OpenDialog::slotSwapCopyNames( int id ) // id selected in the popup menu | |
292 { | |
293 QComboBox* cb1=0; | |
294 QComboBox* cb2=0; | |
295 switch(id) | |
296 { | |
297 case 0: cb1=m_pLineA; cb2=m_pLineB; break; | |
298 case 1: cb1=m_pLineB; cb2=m_pLineC; break; | |
299 case 2: cb1=m_pLineC; cb2=m_pLineA; break; | |
300 case 3: cb1=m_pLineA; cb2=m_pLineOut; break; | |
301 case 4: cb1=m_pLineB; cb2=m_pLineOut; break; | |
302 case 5: cb1=m_pLineC; cb2=m_pLineOut; break; | |
303 case 6: cb1=m_pLineA; cb2=m_pLineOut; break; | |
304 case 7: cb1=m_pLineB; cb2=m_pLineOut; break; | |
305 case 8: cb1=m_pLineC; cb2=m_pLineOut; break; | |
306 } | |
307 if ( cb1 && cb2 ) | |
308 { | |
309 QString t1 = cb1->currentText(); | |
310 QString t2 = cb2->currentText(); | |
311 cb2->setCurrentText(t1); | |
312 if ( id<=2 || id>=6 ) | |
313 { | |
314 cb1->setCurrentText( t2 ); | |
315 } | |
316 } | |
317 } | |
318 | |
319 // FindDialog ********************************************* | |
320 | |
321 FindDialog::FindDialog(QWidget* pParent) | |
322 : QDialog( pParent ) | |
323 { | |
324 QGridLayout* layout = new QGridLayout( this ); | |
325 layout->setMargin(5); | |
326 layout->setSpacing(5); | |
327 | |
328 int line=0; | |
329 layout->addMultiCellWidget( new QLabel(i18n("Search text:"),this), line,line,0,1 ); | |
330 ++line; | |
331 | |
332 m_pSearchString = new QLineEdit( this ); | |
333 layout->addMultiCellWidget( m_pSearchString, line,line,0,1 ); | |
334 ++line; | |
335 | |
336 m_pCaseSensitive = new QCheckBox(i18n("Case sensitive"),this); | |
337 layout->addWidget( m_pCaseSensitive, line, 1 ); | |
338 | |
339 m_pSearchInA = new QCheckBox(i18n("Search A"),this); | |
340 layout->addWidget( m_pSearchInA, line, 0 ); | |
341 m_pSearchInA->setChecked( true ); | |
342 ++line; | |
343 | |
344 m_pSearchInB = new QCheckBox(i18n("Search B"),this); | |
345 layout->addWidget( m_pSearchInB, line, 0 ); | |
346 m_pSearchInB->setChecked( true ); | |
347 ++line; | |
348 | |
349 m_pSearchInC = new QCheckBox(i18n("Search C"),this); | |
350 layout->addWidget( m_pSearchInC, line, 0 ); | |
351 m_pSearchInC->setChecked( true ); | |
352 ++line; | |
353 | |
354 m_pSearchInOutput = new QCheckBox(i18n("Search output"),this); | |
355 layout->addWidget( m_pSearchInOutput, line, 0 ); | |
356 m_pSearchInOutput->setChecked( true ); | |
357 ++line; | |
358 | |
359 QPushButton* pButton = new QPushButton( i18n("&Search"), this ); | |
360 layout->addWidget( pButton, line, 0 ); | |
361 connect( pButton, SIGNAL(clicked()), this, SLOT(accept())); | |
362 | |
363 pButton = new QPushButton( i18n("&Cancel"), this ); | |
364 layout->addWidget( pButton, line, 1 ); | |
365 connect( pButton, SIGNAL(clicked()), this, SLOT(reject())); | |
366 | |
367 hide(); | |
368 } | |
369 | |
370 | |
371 RegExpTester::RegExpTester( QWidget* pParent, const QString& autoMergeRegExpToolTip, | |
372 const QString& historyStartRegExpToolTip, const QString& historyEntryStartRegExpToolTip, const QString& historySortKeyOrderToolTip ) | |
373 : QDialog( pParent) | |
374 { | |
375 int line=0; | |
376 setCaption(i18n("Regular Expression Tester")); | |
377 QGridLayout* pGrid = new QGridLayout( this, 11, 2, 5, 5 ); | |
378 | |
379 QLabel* l = new QLabel(i18n("Auto merge regular expression:"), this); | |
380 pGrid->addWidget(l,line,0); | |
381 QToolTip::add( l, autoMergeRegExpToolTip ); | |
382 m_pAutoMergeRegExpEdit = new QLineEdit(this); | |
383 pGrid->addWidget(m_pAutoMergeRegExpEdit,line,1); | |
384 connect( m_pAutoMergeRegExpEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc())); | |
385 ++line; | |
386 | |
387 l = new QLabel(i18n("Example auto merge line:"), this); | |
388 pGrid->addMultiCellWidget(l,line,line,0,1); | |
389 QToolTip::add( l, i18n("For auto merge test copy a line as used in your files.") ); | |
390 m_pAutoMergeExampleEdit = new QLineEdit(this); | |
391 pGrid->addWidget(m_pAutoMergeExampleEdit,line,1); | |
392 connect( m_pAutoMergeExampleEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc())); | |
393 ++line; | |
394 | |
395 l = new QLabel(i18n("Match result:"), this); | |
396 pGrid->addWidget(l,line,0); | |
397 m_pAutoMergeMatchResult = new QLineEdit(this); | |
398 m_pAutoMergeMatchResult->setReadOnly(true); | |
399 pGrid->addWidget(m_pAutoMergeMatchResult,line,1); | |
400 ++line; | |
401 | |
402 pGrid->addItem( new QSpacerItem(100,20), line, 0 ); | |
403 pGrid->setRowStretch( line, 5); | |
404 ++line; | |
405 | |
406 l = new QLabel(i18n("History start regular expression:"), this); | |
407 pGrid->addWidget(l,line,0); | |
408 QToolTip::add( l, historyStartRegExpToolTip ); | |
409 m_pHistoryStartRegExpEdit = new QLineEdit(this); | |
410 pGrid->addWidget(m_pHistoryStartRegExpEdit,line,1); | |
411 connect( m_pHistoryStartRegExpEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc())); | |
412 ++line; | |
413 | |
414 l = new QLabel(i18n("Example history start line (with leading comment):"), this); | |
415 pGrid->addMultiCellWidget(l,line,line,0,1); | |
416 ++line; | |
417 QToolTip::add( l, i18n("Copy a history start line as used in your files,\n" | |
418 "including the leading comment.") ); | |
419 m_pHistoryStartExampleEdit = new QLineEdit(this); | |
420 pGrid->addWidget(m_pHistoryStartExampleEdit,line,1); | |
421 connect( m_pHistoryStartExampleEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc())); | |
422 ++line; | |
423 | |
424 l = new QLabel(i18n("Match result:"), this); | |
425 pGrid->addWidget(l,line,0); | |
426 m_pHistoryStartMatchResult = new QLineEdit(this); | |
427 m_pHistoryStartMatchResult->setReadOnly(true); | |
428 pGrid->addWidget(m_pHistoryStartMatchResult,line,1); | |
429 ++line; | |
430 | |
431 pGrid->addItem( new QSpacerItem(100,20), line, 0 ); | |
432 pGrid->setRowStretch( line, 5); | |
433 ++line; | |
434 | |
435 l = new QLabel(i18n("History entry start regular expression:"), this); | |
436 pGrid->addWidget(l,line,0); | |
437 QToolTip::add( l, historyEntryStartRegExpToolTip ); | |
438 m_pHistoryEntryStartRegExpEdit = new QLineEdit(this); | |
439 pGrid->addWidget(m_pHistoryEntryStartRegExpEdit,line,1); | |
440 connect( m_pHistoryEntryStartRegExpEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc())); | |
441 ++line; | |
442 | |
443 l = new QLabel(i18n("History sort key order:"), this); | |
444 pGrid->addWidget(l,line,0); | |
445 QToolTip::add( l, historySortKeyOrderToolTip ); | |
446 m_pHistorySortKeyOrderEdit = new QLineEdit(this); | |
447 pGrid->addWidget(m_pHistorySortKeyOrderEdit,line,1); | |
448 connect( m_pHistorySortKeyOrderEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc())); | |
449 ++line; | |
450 | |
451 l = new QLabel(i18n("Example history entry start line (without leading comment):"), this); | |
452 pGrid->addMultiCellWidget(l,line,line,0,1); | |
453 QToolTip::add( l, i18n("Copy a history entry start line as used in your files,\n" | |
454 "but omit the leading comment.") ); | |
455 ++line; | |
456 m_pHistoryEntryStartExampleEdit = new QLineEdit(this); | |
457 pGrid->addWidget(m_pHistoryEntryStartExampleEdit,line,1); | |
458 connect( m_pHistoryEntryStartExampleEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc())); | |
459 ++line; | |
460 | |
461 l = new QLabel(i18n("Match result:"), this); | |
462 pGrid->addWidget(l,line,0); | |
463 m_pHistoryEntryStartMatchResult = new QLineEdit(this); | |
464 m_pHistoryEntryStartMatchResult->setReadOnly(true); | |
465 pGrid->addWidget(m_pHistoryEntryStartMatchResult,line,1); | |
466 ++line; | |
467 | |
468 l = new QLabel(i18n("Sort key result:"), this); | |
469 pGrid->addWidget(l,line,0); | |
470 m_pHistorySortKeyResult = new QLineEdit(this); | |
471 m_pHistorySortKeyResult->setReadOnly(true); | |
472 pGrid->addWidget(m_pHistorySortKeyResult,line,1); | |
473 ++line; | |
474 | |
475 QPushButton* pButton = new QPushButton(i18n("OK"), this); | |
476 pGrid->addWidget(pButton,line,0); | |
477 connect( pButton, SIGNAL(clicked()), this, SLOT(accept())); | |
478 | |
479 pButton = new QPushButton(i18n("Cancel"), this); | |
480 pGrid->addWidget(pButton,line,1); | |
481 connect( pButton, SIGNAL(clicked()), this, SLOT(reject())); | |
482 | |
483 resize( 800, sizeHint().height() ); | |
484 } | |
485 | |
486 void RegExpTester::init( const QString& autoMergeRegExp, const QString& historyStartRegExp, const QString& historyEntryStartRegExp, const QString historySortKeyOrder ) | |
487 { | |
488 m_pAutoMergeRegExpEdit->setText( autoMergeRegExp ); | |
489 m_pHistoryStartRegExpEdit->setText( historyStartRegExp ); | |
490 m_pHistoryEntryStartRegExpEdit->setText( historyEntryStartRegExp ); | |
491 m_pHistorySortKeyOrderEdit->setText( historySortKeyOrder ); | |
492 } | |
493 | |
494 QString RegExpTester::autoMergeRegExp() | |
495 { | |
496 return m_pAutoMergeRegExpEdit->text(); | |
497 } | |
498 | |
499 QString RegExpTester::historyStartRegExp() | |
500 { | |
501 return m_pHistoryStartRegExpEdit->text(); | |
502 } | |
503 | |
504 QString RegExpTester::historyEntryStartRegExp() | |
505 { | |
506 return m_pHistoryEntryStartRegExpEdit->text(); | |
507 } | |
508 | |
509 QString RegExpTester::historySortKeyOrder() | |
510 { | |
511 return m_pHistorySortKeyOrderEdit->text(); | |
512 } | |
513 | |
514 void RegExpTester::slotRecalc() | |
515 { | |
516 QRegExp autoMergeRegExp = m_pAutoMergeRegExpEdit->text(); | |
517 if ( autoMergeRegExp.exactMatch( m_pAutoMergeExampleEdit->text() ) ) | |
518 { | |
519 m_pAutoMergeMatchResult->setText( i18n("Match success.") ); | |
520 } | |
521 else | |
522 { | |
523 m_pAutoMergeMatchResult->setText( i18n("Match failed.") ); | |
524 } | |
525 | |
526 QRegExp historyStartRegExp = m_pHistoryStartRegExpEdit->text(); | |
527 if ( historyStartRegExp.exactMatch( m_pHistoryStartExampleEdit->text() ) ) | |
528 { | |
529 m_pHistoryStartMatchResult->setText( i18n("Match success.") ); | |
530 } | |
531 else | |
532 { | |
533 m_pHistoryStartMatchResult->setText( i18n("Match failed.") ); | |
534 } | |
535 | |
536 | |
537 QStringList parenthesesGroups; | |
538 bool bSuccess = findParenthesesGroups( m_pHistoryEntryStartRegExpEdit->text(), parenthesesGroups ); | |
539 if ( ! bSuccess ) | |
540 { | |
541 m_pHistoryEntryStartMatchResult->setText( i18n("Opening and closing parentheses don't match in regular expression.") ); | |
542 m_pHistorySortKeyResult->setText( i18n("") ); | |
543 return; | |
544 } | |
545 QRegExp historyEntryStartRegExp = m_pHistoryEntryStartRegExpEdit->text(); | |
546 QString s = m_pHistoryEntryStartExampleEdit->text(); | |
547 | |
548 if ( historyEntryStartRegExp.exactMatch( s ) ) | |
549 { | |
550 m_pHistoryEntryStartMatchResult->setText( i18n("Match success.") ); | |
551 QString key = calcHistorySortKey( m_pHistorySortKeyOrderEdit->text(),historyEntryStartRegExp,parenthesesGroups); | |
552 m_pHistorySortKeyResult->setText(key); | |
553 } | |
554 else | |
555 { | |
556 m_pHistoryEntryStartMatchResult->setText( i18n("Match failed.") ); | |
557 m_pHistorySortKeyResult->setText( i18n("") ); | |
558 } | |
559 } | |
560 | |
561 #include "smalldialogs.moc" |