joachim99@69: /*************************************************************************** joachim99@77: * Copyright (C) 2005-2007 by Joachim Eibl * joachim99@69: * joachim.eibl at gmx.de * joachim99@69: * * joachim99@69: * This program is free software; you can redistribute it and/or modify * joachim99@69: * it under the terms of the GNU General Public License as published by * joachim99@69: * the Free Software Foundation; either version 2 of the License, or * joachim99@69: * (at your option) any later version. * joachim99@69: * * joachim99@69: * This program is distributed in the hope that it will be useful, * joachim99@69: * but WITHOUT ANY WARRANTY; without even the implied warranty of * joachim99@69: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * joachim99@69: * GNU General Public License for more details. * joachim99@69: * * joachim99@69: * You should have received a copy of the GNU General Public License * joachim99@69: * along with this program; if not, write to the * joachim99@69: * Free Software Foundation, Inc., * joachim99@69: * 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. * joachim99@69: ***************************************************************************/ joachim99@69: joachim99@69: #include "smalldialogs.h" joachim99@69: #include "optiondialog.h" joachim99@75: #include "diff.h" joachim99@69: joachim99@75: #include joachim99@75: #include joachim99@75: #include joachim99@75: #include joachim99@75: #include joachim99@75: #include joachim99@75: #include joachim99@75: #include joachim99@70: #include joachim99@75: #include joachim99@80: #include Chris@113: #include joachim99@69: joachim99@69: #include joachim99@69: #include joachim99@69: joachim99@69: // OpenDialog ************************************************************** joachim99@69: joachim99@69: OpenDialog::OpenDialog( joachim99@69: QWidget* pParent, const QString& n1, const QString& n2, const QString& n3, joachim99@69: bool bMerge, const QString& outputName, const char* slotConfigure, OptionDialog* pOptions ) joachim99@75: : QDialog( pParent ) joachim99@69: { joachim99@75: setObjectName("OpenDialog"); joachim99@75: setModal(true); joachim99@69: m_pOptions = pOptions; joachim99@69: joachim99@75: QVBoxLayout* v = new QVBoxLayout( this ); joachim99@75: v->setMargin(5); joachim99@75: QGridLayout* h = new QGridLayout(); joachim99@75: v->addLayout(h); joachim99@75: h->setSpacing( 5 ); joachim99@75: h->setColumnStretch( 1, 10 ); joachim99@69: joachim99@69: QLabel* label = new QLabel( i18n("A (Base):"), this ); joachim99@69: joachim99@75: m_pLineA = new QComboBox(); joachim99@75: m_pLineA->setEditable(true); joachim99@75: m_pLineA->insertItems( 0, m_pOptions->m_recentAFiles ); joachim99@80: m_pLineA->setEditText( KUrl(n1).prettyUrl() ); joachim99@75: m_pLineA->setMinimumWidth( 200 ); joachim99@69: QPushButton * button = new QPushButton( i18n("File..."), this ); joachim99@69: connect( button, SIGNAL(clicked()), this, SLOT( selectFileA() ) ); joachim99@69: QPushButton * button2 = new QPushButton( i18n("Dir..."), this ); joachim99@69: connect( button2, SIGNAL(clicked()), this, SLOT( selectDirA() ) ); joachim99@75: connect( m_pLineA, SIGNAL(editTextChanged(const QString&)), this, SLOT(inputFilenameChanged() ) ); joachim99@69: joachim99@69: h->addWidget( label, 0, 0 ); joachim99@69: h->addWidget( m_pLineA, 0, 1 ); joachim99@69: h->addWidget( button, 0, 2 ); joachim99@69: h->addWidget( button2, 0, 3 ); joachim99@69: joachim99@69: label = new QLabel( "B:", this ); joachim99@75: m_pLineB = new QComboBox(); joachim99@75: m_pLineB->setEditable(true); joachim99@75: m_pLineB->insertItems( 0, m_pOptions->m_recentBFiles ); joachim99@80: m_pLineB->setEditText( KUrl(n2).prettyUrl() ); joachim99@75: m_pLineB->setMinimumWidth( 200 ); joachim99@69: button = new QPushButton( i18n("File..."), this ); joachim99@69: connect( button, SIGNAL(clicked()), this, SLOT( selectFileB() ) ); joachim99@69: button2 = new QPushButton( i18n("Dir..."), this ); joachim99@69: connect( button2, SIGNAL(clicked()), this, SLOT( selectDirB() ) ); joachim99@75: connect( m_pLineB, SIGNAL(editTextChanged(const QString&)), this, SLOT(inputFilenameChanged() ) ); joachim99@69: joachim99@69: h->addWidget( label, 1, 0 ); joachim99@75: h->addWidget( m_pLineB, 1, 1 ); joachim99@69: h->addWidget( button, 1, 2 ); joachim99@69: h->addWidget( button2, 1, 3 ); joachim99@69: joachim99@69: label = new QLabel( i18n("C (Optional):"), this ); joachim99@75: m_pLineC= new QComboBox(); joachim99@75: m_pLineC->setEditable(true); joachim99@75: m_pLineC->insertItems( 0, m_pOptions->m_recentCFiles ); joachim99@80: m_pLineC->setEditText( KUrl(n3).prettyUrl() ); joachim99@75: m_pLineC->setMinimumWidth( 200 ); joachim99@69: button = new QPushButton( i18n("File..."), this ); joachim99@69: connect( button, SIGNAL(clicked()), this, SLOT( selectFileC() ) ); joachim99@69: button2 = new QPushButton( i18n("Dir..."), this ); joachim99@69: connect( button2, SIGNAL(clicked()), this, SLOT( selectDirC() ) ); joachim99@75: connect( m_pLineC, SIGNAL(editTextChanged(const QString&)), this, SLOT(inputFilenameChanged() ) ); joachim99@69: joachim99@69: h->addWidget( label, 2, 0 ); joachim99@69: h->addWidget( m_pLineC, 2, 1 ); joachim99@69: h->addWidget( button, 2, 2 ); joachim99@69: h->addWidget( button2, 2, 3 ); joachim99@69: joachim99@69: m_pMerge = new QCheckBox( i18n("Merge"), this ); joachim99@69: h->addWidget( m_pMerge, 3, 0 ); joachim99@69: joachim99@75: QHBoxLayout* hl = new QHBoxLayout(); joachim99@69: h->addLayout( hl, 3, 1 ); joachim99@69: hl->addStretch(2); joachim99@69: button = new QPushButton(i18n("Swap/Copy Names ..."), this); joachim99@69: //button->setToggleButton(false); joachim99@69: hl->addWidget( button ); joachim99@69: joachim99@75: QMenu* m = new QMenu(this); joachim99@80: m->addAction( i18n("Swap %1<->%2", QString("A"),QString("B") )); joachim99@80: m->addAction( i18n("Swap %1<->%2",QString("B"),QString("C") )); joachim99@80: m->addAction( i18n("Swap %1<->%2",QString("C"),QString("A") )); joachim99@80: m->addAction( i18n("Copy %1->Output",QString("A") )); joachim99@80: m->addAction( i18n("Copy %1->Output",QString("B") )); joachim99@80: m->addAction( i18n("Copy %1->Output",QString("C") )); joachim99@80: m->addAction( i18n("Swap %1<->Output",QString("A") )); joachim99@80: m->addAction( i18n("Swap %1<->Output",QString("B") )); joachim99@80: m->addAction( i18n("Swap %1<->Output",QString("C") )); joachim99@75: connect( m, SIGNAL(triggered(QAction*)), this, SLOT(slotSwapCopyNames(QAction*))); joachim99@75: button->setMenu(m); joachim99@69: joachim99@69: joachim99@69: hl->addStretch(2); joachim99@69: joachim99@69: label = new QLabel( i18n("Output (optional):"), this ); joachim99@75: m_pLineOut = new QComboBox(); joachim99@75: m_pLineOut->setEditable(true); joachim99@75: m_pLineOut->insertItems( 0, m_pOptions->m_recentOutputFiles ); joachim99@80: m_pLineOut->setEditText( KUrl(outputName).prettyUrl() ); joachim99@75: m_pLineOut->setMinimumWidth( 200 ); joachim99@69: button = new QPushButton( i18n("File..."), this ); joachim99@69: connect( button, SIGNAL(clicked()), this, SLOT( selectOutputName() ) ); joachim99@69: button2 = new QPushButton( i18n("Dir..."), this ); joachim99@69: connect( button2, SIGNAL(clicked()), this, SLOT( selectOutputDir() ) ); joachim99@69: connect( m_pMerge, SIGNAL(stateChanged(int)), this, SLOT(internalSlot(int)) ); joachim99@69: connect( this, SIGNAL(internalSignal(bool)), m_pLineOut, SLOT(setEnabled(bool)) ); joachim99@69: connect( this, SIGNAL(internalSignal(bool)), button, SLOT(setEnabled(bool)) ); joachim99@69: connect( this, SIGNAL(internalSignal(bool)), button2, SLOT(setEnabled(bool)) ); joachim99@69: joachim99@69: m_pMerge->setChecked( !bMerge ); joachim99@69: m_pMerge->setChecked( bMerge ); joachim99@69: // m_pLineOutput->setEnabled( bMerge ); joachim99@69: joachim99@69: // button->setEnabled( bMerge ); joachim99@69: joachim99@69: h->addWidget( label, 4, 0 ); joachim99@69: h->addWidget( m_pLineOut, 4, 1 ); joachim99@69: h->addWidget( button, 4, 2 ); joachim99@69: h->addWidget( button2, 4, 3 ); joachim99@69: joachim99@75: h->addItem(new QSpacerItem(200, 0), 0, 1); joachim99@69: joachim99@75: QHBoxLayout* l = new QHBoxLayout(); joachim99@75: v->addLayout( l ); joachim99@75: l->setSpacing(5); joachim99@69: joachim99@69: button = new QPushButton( i18n("Configure..."), this ); joachim99@69: connect( button, SIGNAL(clicked()), pParent, slotConfigure ); joachim99@69: l->addWidget( button, 1 ); joachim99@69: joachim99@69: l->addStretch(1); joachim99@69: joachim99@69: button = new QPushButton( i18n("&OK"), this ); joachim99@69: button->setDefault( true ); joachim99@69: connect( button, SIGNAL(clicked()), this, SLOT( accept() ) ); joachim99@69: l->addWidget( button, 1 ); joachim99@69: joachim99@69: button = new QPushButton( i18n("&Cancel"), this ); joachim99@69: connect( button, SIGNAL(clicked()), this, SLOT( reject() ) ); joachim99@69: l->addWidget( button,1 ); joachim99@69: joachim99@69: QSize sh = sizeHint(); joachim99@69: setFixedHeight( sh.height() ); joachim99@69: m_bInputFileNameChanged = false; joachim99@69: joachim99@69: #ifdef KREPLACEMENTS_H joachim99@69: m_pLineA->lineEdit()->installEventFilter( this ); joachim99@69: m_pLineB->lineEdit()->installEventFilter( this ); joachim99@69: m_pLineC->lineEdit()->installEventFilter( this ); joachim99@69: m_pLineOut->lineEdit()->installEventFilter( this ); joachim99@69: #endif joachim99@69: } joachim99@69: joachim99@69: // Eventfilter: Only needed under Windows. joachim99@69: // Without this, files dropped in the line edit have URL-encoding. joachim99@69: // This eventfilter decodes the filenames as needed by KDiff3. joachim99@69: bool OpenDialog::eventFilter(QObject* o, QEvent* e) joachim99@69: { joachim99@75: if ( e->type()==QEvent::DragEnter ) joachim99@75: { joachim99@75: QDragEnterEvent* d = static_cast(e); joachim99@75: d->setAccepted( d->mimeData()->hasUrls() ); joachim99@75: return true; joachim99@75: } joachim99@69: if (e->type()==QEvent::Drop) joachim99@69: { joachim99@69: QDropEvent* d = static_cast(e); joachim99@69: joachim99@75: if ( !d->mimeData()->hasUrls() ) joachim99@69: return false; joachim99@69: joachim99@75: QList lst = d->mimeData()->urls(); joachim99@69: joachim99@69: if ( lst.count() > 0 ) joachim99@69: { joachim99@75: static_cast(o)->setText( QDir::toNativeSeparators( lst[0].toLocalFile() ) ); joachim99@69: static_cast(o)->setFocus(); joachim99@69: } joachim99@69: joachim99@69: return true; joachim99@69: } joachim99@69: return false; joachim99@69: } joachim99@69: joachim99@69: joachim99@69: void OpenDialog::selectURL( QComboBox* pLine, bool bDir, int i, bool bSave ) joachim99@69: { joachim99@69: QString current = pLine->currentText(); joachim99@69: if (current.isEmpty() && i>3 ){ current = m_pLineC->currentText(); } joachim99@69: if (current.isEmpty() ){ current = m_pLineB->currentText(); } joachim99@69: if (current.isEmpty() ){ current = m_pLineA->currentText(); } joachim99@80: KUrl newURL = bDir ? KFileDialog::getExistingDirectoryUrl( current, this) joachim99@80: : bSave ? KFileDialog::getSaveUrl( current, 0, this) joachim99@80: : KFileDialog::getOpenUrl( current, 0, this); joachim99@69: if ( !newURL.isEmpty() ) joachim99@69: { joachim99@69: pLine->setEditText( newURL.url() ); joachim99@69: } joachim99@69: // newURL won't be modified if nothing was selected. joachim99@69: } joachim99@69: joachim99@69: void OpenDialog::selectFileA() { selectURL( m_pLineA, false, 1, false ); } joachim99@69: void OpenDialog::selectFileB() { selectURL( m_pLineB, false, 2, false ); } joachim99@69: void OpenDialog::selectFileC() { selectURL( m_pLineC, false, 3, false ); } joachim99@69: void OpenDialog::selectOutputName(){ selectURL( m_pLineOut, false, 4, true ); } joachim99@69: void OpenDialog::selectDirA() { selectURL( m_pLineA, true, 1, false ); } joachim99@69: void OpenDialog::selectDirB() { selectURL( m_pLineB, true, 2, false ); } joachim99@69: void OpenDialog::selectDirC() { selectURL( m_pLineC, true, 3, false ); } joachim99@69: void OpenDialog::selectOutputDir() { selectURL( m_pLineOut, true, 4, true ); } joachim99@69: joachim99@69: void OpenDialog::internalSlot(int i) joachim99@69: { joachim99@69: emit internalSignal(i!=0); joachim99@69: } joachim99@69: joachim99@69: // Clear the output-filename when any input-filename changed, joachim99@69: // because users forgot to change the output and accidently overwrote it with joachim99@69: // wrong data during a merge. joachim99@69: void OpenDialog::inputFilenameChanged() joachim99@69: { joachim99@69: if(!m_bInputFileNameChanged) joachim99@69: { joachim99@69: m_bInputFileNameChanged=true; joachim99@75: m_pLineOut->clearEditText(); joachim99@69: } joachim99@69: } joachim99@69: joachim99@75: static void fixCurrentText( QComboBox* pCB ) joachim99@75: { joachim99@75: QString s = pCB->currentText(); joachim99@75: joachim99@75: int pos = s.indexOf( '\n' ); joachim99@75: if ( pos>=0 ) joachim99@75: s=s.left(pos); joachim99@75: pos = s.indexOf( '\r' ); joachim99@75: if ( pos>=0 ) joachim99@75: s=s.left(pos); joachim99@75: joachim99@75: pCB->setEditText( s ); joachim99@75: } joachim99@75: joachim99@69: void OpenDialog::accept() joachim99@69: { joachim99@70: int maxNofRecentFiles = 10; joachim99@75: fixCurrentText( m_pLineA ); joachim99@69: joachim99@69: QString s = m_pLineA->currentText(); joachim99@80: s = QUrl::fromLocalFile(s).toLocalFile(); joachim99@69: QStringList* sl = &m_pOptions->m_recentAFiles; joachim99@69: // If an item exist, remove it from the list and reinsert it at the beginning. joachim99@75: sl->removeAll(s); joachim99@69: if ( !s.isEmpty() ) sl->prepend( s ); joachim99@70: if (sl->count()>maxNofRecentFiles) sl->erase( sl->begin()+maxNofRecentFiles, sl->end() ); joachim99@69: joachim99@75: fixCurrentText( m_pLineB ); joachim99@69: s = m_pLineB->currentText(); joachim99@80: s = QUrl::fromLocalFile(s).toLocalFile(); joachim99@69: sl = &m_pOptions->m_recentBFiles; joachim99@75: sl->removeAll(s); joachim99@69: if ( !s.isEmpty() ) sl->prepend( s ); joachim99@70: if (sl->count()>maxNofRecentFiles) sl->erase( sl->begin()+maxNofRecentFiles, sl->end() ); joachim99@69: joachim99@75: fixCurrentText( m_pLineC ); joachim99@69: s = m_pLineC->currentText(); joachim99@80: s = QUrl::fromLocalFile(s).toLocalFile(); joachim99@69: sl = &m_pOptions->m_recentCFiles; joachim99@75: sl->removeAll(s); joachim99@69: if ( !s.isEmpty() ) sl->prepend( s ); joachim99@70: if (sl->count()>maxNofRecentFiles) sl->erase( sl->begin()+maxNofRecentFiles, sl->end() ); joachim99@69: joachim99@75: fixCurrentText( m_pLineOut ); joachim99@69: s = m_pLineOut->currentText(); joachim99@80: s = QUrl::fromLocalFile(s).toLocalFile(); joachim99@69: sl = &m_pOptions->m_recentOutputFiles; joachim99@75: sl->removeAll(s); joachim99@69: if ( !s.isEmpty() ) sl->prepend( s ); joachim99@70: if (sl->count()>maxNofRecentFiles) sl->erase( sl->begin()+maxNofRecentFiles, sl->end() ); joachim99@69: joachim99@69: QDialog::accept(); joachim99@69: } joachim99@69: joachim99@75: void OpenDialog::slotSwapCopyNames( QAction* pAction ) // id selected in the popup menu joachim99@69: { joachim99@75: int id = pAction->parentWidget()->actions().indexOf(pAction); joachim99@69: QComboBox* cb1=0; joachim99@69: QComboBox* cb2=0; joachim99@69: switch(id) joachim99@69: { joachim99@69: case 0: cb1=m_pLineA; cb2=m_pLineB; break; joachim99@69: case 1: cb1=m_pLineB; cb2=m_pLineC; break; joachim99@69: case 2: cb1=m_pLineC; cb2=m_pLineA; break; joachim99@69: case 3: cb1=m_pLineA; cb2=m_pLineOut; break; joachim99@69: case 4: cb1=m_pLineB; cb2=m_pLineOut; break; joachim99@69: case 5: cb1=m_pLineC; cb2=m_pLineOut; break; joachim99@69: case 6: cb1=m_pLineA; cb2=m_pLineOut; break; joachim99@69: case 7: cb1=m_pLineB; cb2=m_pLineOut; break; joachim99@69: case 8: cb1=m_pLineC; cb2=m_pLineOut; break; joachim99@69: } joachim99@69: if ( cb1 && cb2 ) joachim99@69: { joachim99@69: QString t1 = cb1->currentText(); joachim99@69: QString t2 = cb2->currentText(); joachim99@75: cb2->setEditText(t1); joachim99@69: if ( id<=2 || id>=6 ) joachim99@69: { joachim99@75: cb1->setEditText( t2 ); joachim99@69: } joachim99@69: } joachim99@69: } joachim99@69: joachim99@69: // FindDialog ********************************************* joachim99@69: joachim99@69: FindDialog::FindDialog(QWidget* pParent) joachim99@69: : QDialog( pParent ) joachim99@69: { joachim99@75: QGridLayout* layout = new QGridLayout( this ); joachim99@69: layout->setMargin(5); joachim99@69: layout->setSpacing(5); joachim99@69: joachim99@69: int line=0; joachim99@75: layout->addWidget( new QLabel(i18n("Search text:"),this), line, 0, 1, 2 ); joachim99@69: ++line; joachim99@69: joachim99@69: m_pSearchString = new QLineEdit( this ); joachim99@75: layout->addWidget( m_pSearchString, line, 0, 1, 2 ); joachim99@69: ++line; joachim99@69: joachim99@69: m_pCaseSensitive = new QCheckBox(i18n("Case sensitive"),this); joachim99@69: layout->addWidget( m_pCaseSensitive, line, 1 ); joachim99@69: joachim99@69: m_pSearchInA = new QCheckBox(i18n("Search A"),this); joachim99@69: layout->addWidget( m_pSearchInA, line, 0 ); joachim99@69: m_pSearchInA->setChecked( true ); joachim99@69: ++line; joachim99@69: joachim99@69: m_pSearchInB = new QCheckBox(i18n("Search B"),this); joachim99@69: layout->addWidget( m_pSearchInB, line, 0 ); joachim99@69: m_pSearchInB->setChecked( true ); joachim99@69: ++line; joachim99@69: joachim99@69: m_pSearchInC = new QCheckBox(i18n("Search C"),this); joachim99@69: layout->addWidget( m_pSearchInC, line, 0 ); joachim99@69: m_pSearchInC->setChecked( true ); joachim99@69: ++line; joachim99@69: joachim99@69: m_pSearchInOutput = new QCheckBox(i18n("Search output"),this); joachim99@69: layout->addWidget( m_pSearchInOutput, line, 0 ); joachim99@69: m_pSearchInOutput->setChecked( true ); joachim99@69: ++line; joachim99@69: joachim99@69: QPushButton* pButton = new QPushButton( i18n("&Search"), this ); joachim99@69: layout->addWidget( pButton, line, 0 ); joachim99@69: connect( pButton, SIGNAL(clicked()), this, SLOT(accept())); joachim99@69: joachim99@69: pButton = new QPushButton( i18n("&Cancel"), this ); joachim99@69: layout->addWidget( pButton, line, 1 ); joachim99@69: connect( pButton, SIGNAL(clicked()), this, SLOT(reject())); joachim99@69: joachim99@69: hide(); joachim99@69: } joachim99@69: joachim99@69: joachim99@69: RegExpTester::RegExpTester( QWidget* pParent, const QString& autoMergeRegExpToolTip, joachim99@69: const QString& historyStartRegExpToolTip, const QString& historyEntryStartRegExpToolTip, const QString& historySortKeyOrderToolTip ) joachim99@69: : QDialog( pParent) joachim99@69: { joachim99@69: int line=0; joachim99@75: setWindowTitle(i18n("Regular Expression Tester")); joachim99@75: QGridLayout* pGrid = new QGridLayout( this ); joachim99@75: pGrid->setSpacing(5); joachim99@75: pGrid->setMargin(5); joachim99@69: joachim99@69: QLabel* l = new QLabel(i18n("Auto merge regular expression:"), this); joachim99@69: pGrid->addWidget(l,line,0); joachim99@75: l->setToolTip( autoMergeRegExpToolTip ); joachim99@69: m_pAutoMergeRegExpEdit = new QLineEdit(this); joachim99@69: pGrid->addWidget(m_pAutoMergeRegExpEdit,line,1); joachim99@98: connect( m_pAutoMergeRegExpEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc())); joachim99@69: ++line; joachim99@69: joachim99@69: l = new QLabel(i18n("Example auto merge line:"), this); joachim99@98: pGrid->addWidget(l,line,0); joachim99@75: l->setToolTip( i18n("For auto merge test copy a line as used in your files.") ); joachim99@69: m_pAutoMergeExampleEdit = new QLineEdit(this); joachim99@69: pGrid->addWidget(m_pAutoMergeExampleEdit,line,1); joachim99@98: connect( m_pAutoMergeExampleEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc())); joachim99@69: ++line; joachim99@69: joachim99@69: l = new QLabel(i18n("Match result:"), this); joachim99@69: pGrid->addWidget(l,line,0); joachim99@69: m_pAutoMergeMatchResult = new QLineEdit(this); joachim99@69: m_pAutoMergeMatchResult->setReadOnly(true); joachim99@69: pGrid->addWidget(m_pAutoMergeMatchResult,line,1); joachim99@69: ++line; joachim99@69: joachim99@69: pGrid->addItem( new QSpacerItem(100,20), line, 0 ); joachim99@69: pGrid->setRowStretch( line, 5); joachim99@69: ++line; joachim99@69: joachim99@69: l = new QLabel(i18n("History start regular expression:"), this); joachim99@69: pGrid->addWidget(l,line,0); joachim99@75: l->setToolTip( historyStartRegExpToolTip ); joachim99@69: m_pHistoryStartRegExpEdit = new QLineEdit(this); joachim99@69: pGrid->addWidget(m_pHistoryStartRegExpEdit,line,1); joachim99@98: connect( m_pHistoryStartRegExpEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc())); joachim99@69: ++line; joachim99@69: joachim99@69: l = new QLabel(i18n("Example history start line (with leading comment):"), this); joachim99@98: pGrid->addWidget(l,line,0); joachim99@75: l->setToolTip( i18n("Copy a history start line as used in your files,\n" joachim99@69: "including the leading comment.") ); joachim99@69: m_pHistoryStartExampleEdit = new QLineEdit(this); joachim99@69: pGrid->addWidget(m_pHistoryStartExampleEdit,line,1); joachim99@98: connect( m_pHistoryStartExampleEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc())); joachim99@69: ++line; joachim99@69: joachim99@69: l = new QLabel(i18n("Match result:"), this); joachim99@69: pGrid->addWidget(l,line,0); joachim99@69: m_pHistoryStartMatchResult = new QLineEdit(this); joachim99@69: m_pHistoryStartMatchResult->setReadOnly(true); joachim99@69: pGrid->addWidget(m_pHistoryStartMatchResult,line,1); joachim99@69: ++line; joachim99@69: joachim99@69: pGrid->addItem( new QSpacerItem(100,20), line, 0 ); joachim99@69: pGrid->setRowStretch( line, 5); joachim99@69: ++line; joachim99@69: joachim99@69: l = new QLabel(i18n("History entry start regular expression:"), this); joachim99@69: pGrid->addWidget(l,line,0); joachim99@75: l->setToolTip( historyEntryStartRegExpToolTip ); joachim99@69: m_pHistoryEntryStartRegExpEdit = new QLineEdit(this); joachim99@69: pGrid->addWidget(m_pHistoryEntryStartRegExpEdit,line,1); joachim99@98: connect( m_pHistoryEntryStartRegExpEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc())); joachim99@69: ++line; joachim99@69: joachim99@69: l = new QLabel(i18n("History sort key order:"), this); joachim99@69: pGrid->addWidget(l,line,0); joachim99@75: l->setToolTip( historySortKeyOrderToolTip ); joachim99@69: m_pHistorySortKeyOrderEdit = new QLineEdit(this); joachim99@69: pGrid->addWidget(m_pHistorySortKeyOrderEdit,line,1); joachim99@98: connect( m_pHistorySortKeyOrderEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc())); joachim99@69: ++line; joachim99@69: joachim99@69: l = new QLabel(i18n("Example history entry start line (without leading comment):"), this); joachim99@98: pGrid->addWidget(l,line,0); joachim99@75: l->setToolTip( i18n("Copy a history entry start line as used in your files,\n" joachim99@69: "but omit the leading comment.") ); joachim99@69: m_pHistoryEntryStartExampleEdit = new QLineEdit(this); joachim99@69: pGrid->addWidget(m_pHistoryEntryStartExampleEdit,line,1); joachim99@98: connect( m_pHistoryEntryStartExampleEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc())); joachim99@69: ++line; joachim99@69: joachim99@69: l = new QLabel(i18n("Match result:"), this); joachim99@69: pGrid->addWidget(l,line,0); joachim99@69: m_pHistoryEntryStartMatchResult = new QLineEdit(this); joachim99@69: m_pHistoryEntryStartMatchResult->setReadOnly(true); joachim99@69: pGrid->addWidget(m_pHistoryEntryStartMatchResult,line,1); joachim99@69: ++line; joachim99@69: joachim99@69: l = new QLabel(i18n("Sort key result:"), this); joachim99@69: pGrid->addWidget(l,line,0); joachim99@69: m_pHistorySortKeyResult = new QLineEdit(this); joachim99@69: m_pHistorySortKeyResult->setReadOnly(true); joachim99@69: pGrid->addWidget(m_pHistorySortKeyResult,line,1); joachim99@69: ++line; joachim99@69: joachim99@69: QPushButton* pButton = new QPushButton(i18n("OK"), this); joachim99@69: pGrid->addWidget(pButton,line,0); joachim99@69: connect( pButton, SIGNAL(clicked()), this, SLOT(accept())); joachim99@69: joachim99@69: pButton = new QPushButton(i18n("Cancel"), this); joachim99@69: pGrid->addWidget(pButton,line,1); joachim99@69: connect( pButton, SIGNAL(clicked()), this, SLOT(reject())); joachim99@69: joachim99@69: resize( 800, sizeHint().height() ); joachim99@69: } joachim99@69: joachim99@69: void RegExpTester::init( const QString& autoMergeRegExp, const QString& historyStartRegExp, const QString& historyEntryStartRegExp, const QString historySortKeyOrder ) joachim99@69: { joachim99@69: m_pAutoMergeRegExpEdit->setText( autoMergeRegExp ); joachim99@69: m_pHistoryStartRegExpEdit->setText( historyStartRegExp ); joachim99@69: m_pHistoryEntryStartRegExpEdit->setText( historyEntryStartRegExp ); joachim99@69: m_pHistorySortKeyOrderEdit->setText( historySortKeyOrder ); joachim99@69: } joachim99@69: joachim99@69: QString RegExpTester::autoMergeRegExp() joachim99@69: { joachim99@69: return m_pAutoMergeRegExpEdit->text(); joachim99@69: } joachim99@69: joachim99@69: QString RegExpTester::historyStartRegExp() joachim99@69: { joachim99@69: return m_pHistoryStartRegExpEdit->text(); joachim99@69: } joachim99@69: joachim99@69: QString RegExpTester::historyEntryStartRegExp() joachim99@69: { joachim99@69: return m_pHistoryEntryStartRegExpEdit->text(); joachim99@69: } joachim99@69: joachim99@69: QString RegExpTester::historySortKeyOrder() joachim99@69: { joachim99@69: return m_pHistorySortKeyOrderEdit->text(); joachim99@69: } joachim99@69: joachim99@69: void RegExpTester::slotRecalc() joachim99@69: { joachim99@70: QRegExp autoMergeRegExp( m_pAutoMergeRegExpEdit->text() ); joachim99@69: if ( autoMergeRegExp.exactMatch( m_pAutoMergeExampleEdit->text() ) ) joachim99@69: { joachim99@69: m_pAutoMergeMatchResult->setText( i18n("Match success.") ); joachim99@69: } joachim99@69: else joachim99@69: { joachim99@69: m_pAutoMergeMatchResult->setText( i18n("Match failed.") ); joachim99@69: } joachim99@69: joachim99@70: QRegExp historyStartRegExp( m_pHistoryStartRegExpEdit->text() ); joachim99@69: if ( historyStartRegExp.exactMatch( m_pHistoryStartExampleEdit->text() ) ) joachim99@69: { joachim99@69: m_pHistoryStartMatchResult->setText( i18n("Match success.") ); joachim99@69: } joachim99@69: else joachim99@69: { joachim99@69: m_pHistoryStartMatchResult->setText( i18n("Match failed.") ); joachim99@69: } joachim99@69: joachim99@69: joachim99@69: QStringList parenthesesGroups; joachim99@69: bool bSuccess = findParenthesesGroups( m_pHistoryEntryStartRegExpEdit->text(), parenthesesGroups ); joachim99@69: if ( ! bSuccess ) joachim99@69: { joachim99@69: m_pHistoryEntryStartMatchResult->setText( i18n("Opening and closing parentheses don't match in regular expression.") ); joachim99@80: m_pHistorySortKeyResult->setText( "" ); joachim99@69: return; joachim99@69: } joachim99@70: QRegExp historyEntryStartRegExp( m_pHistoryEntryStartRegExpEdit->text() ); joachim99@69: QString s = m_pHistoryEntryStartExampleEdit->text(); joachim99@69: joachim99@69: if ( historyEntryStartRegExp.exactMatch( s ) ) joachim99@69: { joachim99@69: m_pHistoryEntryStartMatchResult->setText( i18n("Match success.") ); joachim99@69: QString key = calcHistorySortKey( m_pHistorySortKeyOrderEdit->text(),historyEntryStartRegExp,parenthesesGroups); joachim99@69: m_pHistorySortKeyResult->setText(key); joachim99@69: } joachim99@69: else joachim99@69: { joachim99@69: m_pHistoryEntryStartMatchResult->setText( i18n("Match failed.") ); joachim99@80: m_pHistorySortKeyResult->setText( "" ); joachim99@69: } joachim99@69: } joachim99@69: joachim99@70: //#include "smalldialogs.moc"