annotate kdiff3/src-QT4/smalldialogs.cpp @ 104:3d87e427431d

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