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