You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tdelibs/tdecore/tdestringmatcher-dialog.cpp

235 lines
7.3 KiB
C++

#include "tdestringmatcher-dialog.h"
#include "tdestringmatcher.h"
#include "tdeglobal.h"
#include "tdelocale.h"
#include "kdebug.h"
Customize_TDEStringMatcher_Dialog::Customize_TDEStringMatcher_Dialog(
TQStringList initPatternList,
bool initPatternIsRegex,
bool initPatternIsCaseInsensitive,
TQString callerTitle
)
{
// Initialize our "output" variables
patternList.clear();
patternIsRegex = false;
patternIsCaseInsensitive = false;
dialogResult = CriteriaApplied;
setModal( TRUE );
setCaption( i18n( "Specify string match criteria" ) );
// Create main layout and subordinate grid to position the widgets
TQHBoxLayout *topLayout = new TQHBoxLayout( this, 10 );
TQGridLayout *grid = new TQGridLayout( 0, 2 ); // 2 wide and autodetect number of rows
topLayout->addLayout( grid, 1 );
int gridrow = 1;
//=== Set up dialog title ===//
//TQString titleGeneral = i18n( "Define 'Hidden' files for" ) ;
//setCaption( titleGeneral + " " + callerTitle );
TQLabel *dialogTitle = new TQLabel( this );
dialogTitle->setText( "<b>" + callerTitle );
dialogTitle->setFrameStyle( TQFrame::Box | TQFrame::Plain );
dialogTitle->setAlignment( TQt::AlignHCenter | TQt::AlignVCenter );
grid->addMultiCellWidget( dialogTitle, gridrow, gridrow, 0, 1 );
gridrow++;
//=== Set up match pattern edit boxes ===/
TQLabel *patterns_label = new TQLabel( this );
patterns_label->setText( i18n( "Match any of these patterns" ) );
patterns_label->setAlignment( TQt::AlignHCenter );
grid->addMultiCellWidget( patterns_label, gridrow, gridrow, 0, 1 );
gridrow++;
// Limit the number of patterns to display to something reasonable
maxPatterns = initPatternList.size() + 2;
if ( maxPatterns > MAX_PATTERNS )
maxPatterns = MAX_PATTERNS;
// Set up edit boxes with initial patterns
short i = 0 ;
for (
TQStringList::iterator it = initPatternList.begin();
i < maxPatterns, it != initPatternList.end() ;
++it, i++, gridrow++
) {
le_Patterns[i] = new TQLineEdit( this );
le_Patterns[i]->setText(it->latin1()) ;
grid->addMultiCellWidget( le_Patterns[i], gridrow, gridrow, 0, 1 );
}
short first_empty_editbox = i;
for ( ; i < maxPatterns; i++, gridrow++ ) {
le_Patterns[i] = new TQLineEdit( this );
grid->addMultiCellWidget( le_Patterns[i], gridrow, gridrow, 0, 1 );
}
le_Patterns[first_empty_editbox]->setFocus();
//=== Set up match option check boxes ===//
// Create a group of check boxes
bg_Options = new TQButtonGroup( this, "checkGroup" );
bg_Options->setTitle( i18n( "Match options" ) );
grid->addMultiCellWidget( bg_Options, gridrow, gridrow, 0, 1 );
gridrow++;
// Create a layout for the check boxes
TQVBoxLayout *vbox = new TQVBoxLayout(bg_Options, 10);
vbox->addSpacing( bg_Options->fontMetrics().height() );
// Set up first checkbox
cb_patternIsRegex = new TQCheckBox( bg_Options );
cb_patternIsRegex->setChecked( initPatternIsRegex );
cb_patternIsRegex->setText( i18n( "&Regex (vs Wildcard)" ) );
TQToolTip::add( cb_patternIsRegex, i18n( "Regex (vs Wildcard)" ) );
vbox->addWidget( cb_patternIsRegex );
// Set up second checkbox
cb_patternIsCaseInsensitive = new TQCheckBox( bg_Options );
cb_patternIsCaseInsensitive->setChecked( initPatternIsCaseInsensitive );
cb_patternIsCaseInsensitive->setText( i18n( "&Case insensitive" ) );
TQToolTip::add( cb_patternIsCaseInsensitive, i18n( "Case insensitive" ) );
vbox->addWidget( cb_patternIsCaseInsensitive );
//=== Set up final dispostion radio buttons ===//
// Create a group of radio buttons
bg_Disposition = new TQButtonGroup( this, "radioGroup" );
bg_Disposition->setTitle( i18n( "Disposition of Match Criteria:" ) );
bg_Disposition->setRadioButtonExclusive(true);
grid->addMultiCellWidget( bg_Disposition, gridrow, gridrow, 0, 1 );
gridrow++;
// Create a layout for the radio buttons
TQVBoxLayout *vbox2 = new TQVBoxLayout(bg_Disposition, 10);
vbox2->addSpacing( bg_Disposition->fontMetrics().height() );
// Set up radio button 0
rb_Disposition = new TQRadioButton( bg_Disposition );
rb_Disposition->setText( i18n( "&Apply but do not save" ) );
rb_Disposition->setChecked( TRUE );
TQToolTip::add( rb_Disposition, i18n( "Changes will be applied temporarily" ) );
vbox2->addWidget( rb_Disposition );
// Set up radio button 1
rb_Disposition = new TQRadioButton( bg_Disposition );
rb_Disposition->setText( i18n( "Apply and &save as default" ) );
TQToolTip::add( rb_Disposition, i18n( "Changes will be applied and saved to disk" ) );
vbox2->addWidget( rb_Disposition );
// Set up radio button 2
rb_Disposition = new TQRadioButton( bg_Disposition );
rb_Disposition->setText( i18n( "Ignore and restore &default" ) );
TQToolTip::add( rb_Disposition, i18n( "Changes will be ignored and saved default restored" ) );
vbox2->addWidget( rb_Disposition );
connect( bg_Disposition, SIGNAL(clicked(int)), SLOT(setExitDisposition(int)) );
//=== Set up dialog exit buttons ===/
pb_OK = new TQPushButton( this, "pb_OK" );
pb_OK->setDefault( FALSE );
pb_OK->setText( i18n( "&OK" ) );
TQToolTip::add( pb_OK, i18n( "Save settings as default" ) );
pb_OK->setAccel( TQKeySequence( "Return" ) );
grid->addWidget( pb_OK, gridrow, 0 );
pb_Cancel = new TQPushButton( this, "pb_Cancel" );
pb_Cancel->setDefault( FALSE );
pb_Cancel->setText( i18n( "&Cancel" ) );
pb_Cancel->setAccel( TQKeySequence( "Esc" ) );
grid->addWidget( pb_Cancel, gridrow, 1 );
connect( pb_OK, SIGNAL( clicked() ), this, SLOT( exitOK() ) );
connect( pb_Cancel, SIGNAL( clicked() ), this, SLOT( exitCancel() ) );
}
//=== Dialog event handlers ===/
bool Customize_TDEStringMatcher_Dialog::event( TQEvent * e ) {
if ( e->type() != TQEvent::KeyPress ) {
TQKeyEvent * ke = (TQKeyEvent*) e;
if ( ke->key() == Key_Escape ) {
ke->accept();
exitCancel();
return TRUE;
}
else if ( ke->key() == Key_Return ) {
ke->accept();
exitOK();
return TRUE;
}
}
return TQWidget::event( e );
}
void Customize_TDEStringMatcher_Dialog::setExitDisposition(int buttonNum )
{
switch( buttonNum ) {
case 0:
dialogResult = CriteriaApplied;
break;
case 1:
dialogResult = SaveCriteria;
break;
case 2:
dialogResult = ReloadCriteria;
break;
}
}
//=== Dialog exit functions ===//
void Customize_TDEStringMatcher_Dialog::exitOK()
{
if ( dialogResult > CriteriaUnchanged ) {
patternList.clear();
for ( int i = 0; i < maxPatterns; i++ ) {
TQString pattern = le_Patterns[i]->text();
if ( ! ( pattern.isEmpty() ) ) {
patternList += pattern;
}
}
patternIsRegex = cb_patternIsRegex->isChecked();
patternIsCaseInsensitive = cb_patternIsCaseInsensitive->isChecked();
}
close();
}
void Customize_TDEStringMatcher_Dialog::exitCancel()
{
dialogResult = CriteriaUnchanged;
close();
}
//=== Object property accessors ===//
int Customize_TDEStringMatcher_Dialog::result()
{
return dialogResult;
}
bool Customize_TDEStringMatcher_Dialog::isPatternRegex()
{
return patternIsRegex;
}
bool Customize_TDEStringMatcher_Dialog::isPatternCaseInsensitive()
{
return patternIsCaseInsensitive;
}
TQStringList Customize_TDEStringMatcher_Dialog::getPatternList()
{
return patternList;
}
#include "tdestringmatcher-dialog.moc"