37 #include "regexplineedit.h"
39 #include <tdelocale.h>
40 #include <klineedit.h>
41 #include <tdeparts/componentfactory.h>
42 #include <kregexpeditorinterface.h>
47 #include <tqpushbutton.h>
52 RegExpLineEdit::RegExpLineEdit( TQWidget *parent,
const char *name )
53 : TQWidget( parent, name ),
55 mRegExpEditButton( 0 ),
56 mRegExpEditDialog( 0 )
61 RegExpLineEdit::RegExpLineEdit(
const TQString &str, TQWidget *parent,
63 : TQWidget( parent, name ),
65 mRegExpEditButton( 0 ),
66 mRegExpEditDialog( 0 )
71 void RegExpLineEdit::initWidget(
const TQString &str )
73 TQHBoxLayout * hlay =
new TQHBoxLayout(
this, 0, KDialog::spacingHint() );
75 mLineEdit =
new KLineEdit( str,
this );
76 setFocusProxy( mLineEdit );
77 hlay->addWidget( mLineEdit );
79 connect( mLineEdit, TQ_SIGNAL( textChanged(
const TQString & ) ),
80 this, TQ_SIGNAL( textChanged(
const TQString & ) ) );
82 if( !TDETrader::self()->query(
"KRegExpEditor/KRegExpEditor").isEmpty() ) {
83 mRegExpEditButton =
new TQPushButton( i18n(
"Edit..."),
this,
84 "mRegExpEditButton" );
85 mRegExpEditButton->setSizePolicy( TQSizePolicy::Minimum,
86 TQSizePolicy::Fixed );
87 hlay->addWidget( mRegExpEditButton );
89 connect( mRegExpEditButton, TQ_SIGNAL( clicked() ),
90 this, TQ_SLOT( slotEditRegExp() ) );
94 void RegExpLineEdit::clear()
99 TQString RegExpLineEdit::text()
const
101 return mLineEdit->text();
104 void RegExpLineEdit::setText(
const TQString & str )
106 mLineEdit->setText( str );
109 void RegExpLineEdit::showEditButton(
bool show )
111 if ( !mRegExpEditButton )
115 mRegExpEditButton->show();
117 mRegExpEditButton->hide();
120 void RegExpLineEdit::slotEditRegExp()
122 if ( !mRegExpEditDialog )
123 mRegExpEditDialog = KParts::ComponentFactory::createInstanceFromQuery<TQDialog>(
"KRegExpEditor/KRegExpEditor", TQString(),
this );
125 KRegExpEditorInterface *iface =
126 static_cast<KRegExpEditorInterface *
>( mRegExpEditDialog->tqt_cast(
"KRegExpEditorInterface" ) );
128 iface->setRegExp( mLineEdit->text() );
129 if( mRegExpEditDialog->exec() == TQDialog::Accepted )
130 mLineEdit->setText( iface->regExp() );
136 #include "regexplineedit.moc"