Framework for looking up contacts directly in nepomuk in addition to going through...
[kdepim.git] / mailcommon / regexplineedit.cpp
blob119cb2cff1ca6c203aca0a9fda651a23ebe8a17e
1 /* -*- mode: C++; c-file-style: "gnu" -*-
3 Copyright (c) 2004 Ingo Kloecker <kloecker@kde.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of this program with any edition of
21 the Qt library by Trolltech AS, Norway (or with modified versions
22 of Qt that use the same license as Qt), and distribute linked
23 combinations including the two. You must obey the GNU General
24 Public License in all respects for all of the code used other than
25 Qt. If you modify this file, you may extend this exception to
26 your version of the file, but you are not obligated to do so. If
27 you do not wish to do so, delete this exception statement from
28 your version.
31 #include "regexplineedit.h"
33 #include <KDialog>
34 #include <KLineEdit>
35 #include <KLocale>
36 #include <kregexpeditorinterface.h> //krazy:exclude=camelcase as no such
37 #include <KServiceTypeTrader>
39 #include <QHBoxLayout>
40 #include <QString>
41 #include <QPushButton>
43 namespace MailCommon {
45 RegExpLineEdit::RegExpLineEdit( QWidget *parent )
46 : QWidget( parent ),
47 mLineEdit( 0 ),
48 mRegExpEditButton( 0 ),
49 mRegExpEditDialog( 0 )
51 initWidget();
54 RegExpLineEdit::RegExpLineEdit( const QString &str, QWidget *parent )
55 : QWidget( parent ),
56 mLineEdit( 0 ),
57 mRegExpEditButton( 0 ),
58 mRegExpEditDialog( 0 )
60 initWidget( str );
63 void RegExpLineEdit::initWidget( const QString &str )
65 QHBoxLayout * hlay = new QHBoxLayout( this );
66 hlay->setSpacing( KDialog::spacingHint() );
67 hlay->setMargin( 0 );
69 mLineEdit = new KLineEdit( str, this );
70 mLineEdit->setClearButtonShown( true );
71 setFocusProxy( mLineEdit );
72 hlay->addWidget( mLineEdit );
74 connect( mLineEdit, SIGNAL(textChanged(QString)),
75 this, SIGNAL(textChanged(QString)) );
77 if( !KServiceTypeTrader::self()->query( "KRegExpEditor/KRegExpEditor" ).isEmpty() ) {
78 mRegExpEditButton = new QPushButton( i18n( "Edit..." ), this );
79 mRegExpEditButton->setObjectName( "mRegExpEditButton" );
80 mRegExpEditButton->setSizePolicy( QSizePolicy::Minimum,
81 QSizePolicy::Fixed );
82 hlay->addWidget( mRegExpEditButton );
84 connect( mRegExpEditButton, SIGNAL(clicked()),
85 this, SLOT(slotEditRegExp()) );
89 void RegExpLineEdit::clear()
91 mLineEdit->clear();
94 QString RegExpLineEdit::text() const
96 return mLineEdit->text();
99 void RegExpLineEdit::setText( const QString & str )
101 mLineEdit->setText( str );
104 void RegExpLineEdit::showEditButton( bool show )
106 if ( !mRegExpEditButton ) {
107 return;
110 if ( show ) {
111 mRegExpEditButton->show();
112 } else {
113 mRegExpEditButton->hide();
117 void RegExpLineEdit::slotEditRegExp()
119 if ( !mRegExpEditDialog ) {
120 mRegExpEditDialog =
121 KServiceTypeTrader::createInstanceFromQuery<KDialog>(
122 "KRegExpEditor/KRegExpEditor", QString(), this );
125 KRegExpEditorInterface *iface = qobject_cast<KRegExpEditorInterface *>( mRegExpEditDialog );
127 if ( iface ) {
128 iface->setRegExp( mLineEdit->text() );
129 if ( mRegExpEditDialog->exec() == KDialog::Accepted ) {
130 mLineEdit->setText( iface->regExp() );
135 } // namespace MailCommon
137 #include "regexplineedit.moc"