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