kmail

regexplineedit.cpp
1/*
2 regexplineedit.cpp
3
4 This file is part of KMail, the KDE mail client.
5 Copyright (c) 2004 Ingo Kloecker <kloecker@kde.org>
6
7 KMail is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 KMail is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
21 In addition, as a special exception, the copyright holders give
22 permission to link the code of this program with any edition of
23 the TQt library by Trolltech AS, Norway (or with modified versions
24 of TQt that use the same license as TQt), and distribute linked
25 combinations including the two. You must obey the GNU General
26 Public License in all respects for all of the code used other than
27 TQt. If you modify this file, you may extend this exception to
28 your version of the file, but you are not obligated to do so. If
29 you do not wish to do so, delete this exception statement from
30 your version.
31*/
32
33#ifdef HAVE_CONFIG_H
34#include <config.h>
35#endif
36
37#include "regexplineedit.h"
38
39#include <tdelocale.h>
40#include <klineedit.h>
41#include <tdeparts/componentfactory.h>
42#include <kregexpeditorinterface.h>
43#include <kdialog.h>
44
45#include <tqlayout.h>
46#include <tqstring.h>
47#include <tqpushbutton.h>
48#include <tqdialog.h>
49
50namespace KMail {
51
52 RegExpLineEdit::RegExpLineEdit( TQWidget *parent, const char *name )
53 : TQWidget( parent, name ),
54 mLineEdit( 0 ),
55 mRegExpEditButton( 0 ),
56 mRegExpEditDialog( 0 )
57 {
58 initWidget();
59 }
60
61 RegExpLineEdit::RegExpLineEdit( const TQString &str, TQWidget *parent,
62 const char *name )
63 : TQWidget( parent, name ),
64 mLineEdit( 0 ),
65 mRegExpEditButton( 0 ),
66 mRegExpEditDialog( 0 )
67 {
68 initWidget( str );
69 }
70
71 void RegExpLineEdit::initWidget( const TQString &str )
72 {
73 TQHBoxLayout * hlay = new TQHBoxLayout( this, 0, KDialog::spacingHint() );
74
75 mLineEdit = new KLineEdit( str, this );
76 setFocusProxy( mLineEdit );
77 hlay->addWidget( mLineEdit );
78
79 connect( mLineEdit, TQ_SIGNAL( textChanged( const TQString & ) ),
80 this, TQ_SIGNAL( textChanged( const TQString & ) ) );
81
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 );
88
89 connect( mRegExpEditButton, TQ_SIGNAL( clicked() ),
90 this, TQ_SLOT( slotEditRegExp() ) );
91 }
92 }
93
94 void RegExpLineEdit::clear()
95 {
96 mLineEdit->clear();
97 }
98
99 TQString RegExpLineEdit::text() const
100 {
101 return mLineEdit->text();
102 }
103
104 void RegExpLineEdit::setText( const TQString & str )
105 {
106 mLineEdit->setText( str );
107 }
108
109 void RegExpLineEdit::showEditButton( bool show )
110 {
111 if ( !mRegExpEditButton )
112 return;
113
114 if ( show )
115 mRegExpEditButton->show();
116 else
117 mRegExpEditButton->hide();
118 }
119
120 void RegExpLineEdit::slotEditRegExp()
121 {
122 if ( !mRegExpEditDialog )
123 mRegExpEditDialog = KParts::ComponentFactory::createInstanceFromQuery<TQDialog>( "KRegExpEditor/KRegExpEditor", TQString(), this );
124
125 KRegExpEditorInterface *iface =
126 static_cast<KRegExpEditorInterface *>( mRegExpEditDialog->tqt_cast( "KRegExpEditorInterface" ) );
127 if( iface ) {
128 iface->setRegExp( mLineEdit->text() );
129 if( mRegExpEditDialog->exec() == TQDialog::Accepted )
130 mLineEdit->setText( iface->regExp() );
131 }
132 }
133
134} // namespace KMail
135
136#include "regexplineedit.moc"
folderdiaquotatab.h
Definition: aboutdata.cpp:40