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