annotate kdiff3/src/smalldialogs.cpp @ 70:5bbfe4784324

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