00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
#ifdef HAVE_CONFIG_H
00034
#include <config.h>
00035
#endif
00036
00037
#include "regexplineedit.h"
00038
00039
#include <klocale.h>
00040
#include <klineedit.h>
00041
#include <kparts/componentfactory.h>
00042
#include <kregexpeditorinterface.h>
00043
#include <kdialog.h>
00044
00045
#include <qlayout.h>
00046
#include <qstring.h>
00047
#include <qpushbutton.h>
00048
#include <qdialog.h>
00049
00050
namespace KMail {
00051
00052 RegExpLineEdit::RegExpLineEdit(
QWidget *parent,
const char *name )
00053 :
QWidget( parent, name ),
00054 mLineEdit( 0 ),
00055 mRegExpEditButton( 0 ),
00056 mRegExpEditDialog( 0 )
00057 {
00058 initWidget();
00059 }
00060
00061 RegExpLineEdit::RegExpLineEdit(
const QString &str,
QWidget *parent,
00062
const char *name )
00063 :
QWidget( parent, name ),
00064 mLineEdit( 0 ),
00065 mRegExpEditButton( 0 ),
00066 mRegExpEditDialog( 0 )
00067 {
00068 initWidget( str );
00069 }
00070
00071
void RegExpLineEdit::initWidget(
const QString &str )
00072 {
00073
QHBoxLayout * hlay =
new QHBoxLayout(
this, 0, KDialog::spacingHint() );
00074
00075 mLineEdit =
new KLineEdit( str,
this );
00076 setFocusProxy( mLineEdit );
00077 hlay->addWidget( mLineEdit );
00078
00079 connect( mLineEdit, SIGNAL( textChanged(
const QString & ) ),
00080
this, SIGNAL( textChanged(
const QString & ) ) );
00081
00082
if( !KTrader::self()->query(
"KRegExpEditor/KRegExpEditor").isEmpty() ) {
00083 mRegExpEditButton =
new QPushButton( i18n(
"Edit..."),
this,
00084
"mRegExpEditButton" );
00085 mRegExpEditButton->setSizePolicy( QSizePolicy::Minimum,
00086 QSizePolicy::Fixed );
00087 hlay->addWidget( mRegExpEditButton );
00088
00089 connect( mRegExpEditButton, SIGNAL( clicked() ),
00090
this, SLOT( slotEditRegExp() ) );
00091 }
00092 }
00093
00094
void RegExpLineEdit::clear()
00095 {
00096 mLineEdit->clear();
00097 }
00098
00099
QString RegExpLineEdit::text()
const
00100
{
00101
return mLineEdit->text();
00102 }
00103
00104
void RegExpLineEdit::setText(
const QString & str )
00105 {
00106 mLineEdit->setText( str );
00107 }
00108
00109
void RegExpLineEdit::showEditButton(
bool show )
00110 {
00111
if ( !mRegExpEditButton )
00112
return;
00113
00114
if ( show )
00115 mRegExpEditButton->show();
00116
else
00117 mRegExpEditButton->hide();
00118 }
00119
00120
void RegExpLineEdit::slotEditRegExp()
00121 {
00122
if ( !mRegExpEditDialog )
00123 mRegExpEditDialog = KParts::ComponentFactory::createInstanceFromQuery<QDialog>(
"KRegExpEditor/KRegExpEditor", QString::null,
this );
00124
00125 KRegExpEditorInterface *iface =
00126 static_cast<KRegExpEditorInterface *>( mRegExpEditDialog->qt_cast(
"KRegExpEditorInterface" ) );
00127
if( iface ) {
00128 iface->setRegExp( mLineEdit->text() );
00129
if( mRegExpEditDialog->exec() == QDialog::Accepted )
00130 mLineEdit->setText( iface->regExp() );
00131 }
00132 }
00133
00134 }
00135
00136
#include "regexplineedit.moc"