1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
/*
* Copyright (c) 2002-2003 Jesper K. Pedersen <blackie@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
**/
#ifdef TQT_ONLY
#include "compat.h"
#include <tqfiledialog.h>
#include "images.h"
#else
#include <klocale.h>
#include "verifybuttons.moc"
#include <kstandarddirs.h>
#include <kfiledialog.h>
#include <kiconloader.h>
#include <kmessagebox.h>
#endif
#include "verifybuttons.h"
#include <tqtooltip.h>
#include <tqlayout.h>
#include <tqwhatsthis.h>
#include "qtregexpconverter.h"
#include "emacsregexpconverter.h"
#include <tqtoolbutton.h>
#include "util.h"
#include <tqpopupmenu.h>
#include <tqaction.h>
VerifyButtons::VerifyButtons( TQWidget* tqparent, const char* name )
:TQDockWindow( TQDockWindow::InDock, tqparent, name ), _configMenu( 0 )
{
TQBoxLayout* tqlayout = boxLayout();
_verify = new TQToolButton(this);
TQIconSet icon = Util::getSystemIconSet( TQString::tqfromLatin1("spellcheck"));
_verify->setIconSet( icon );
TQToolTip::add( _verify, i18n( "Verify regular expression" ) );
TQWhatsThis::add( _verify, i18n("Shows what part of the regular expression is being matched in the <i>verifier window</i>."
"(The window below the graphical editor window)."));
tqlayout->addWidget( _verify );
connect( _verify, TQT_SIGNAL( clicked() ), this, TQT_SIGNAL( verify() ) );
TQToolButton* button = new TQToolButton(this);
button->setPixmap( Util::getSystemIcon( TQString::tqfromLatin1("fileopen")) );
tqlayout->addWidget( button );
connect(button, TQT_SIGNAL(clicked()), this, TQT_SLOT(loadText()));
TQToolTip::add( button, i18n("Load text in the verifier window") );
button = new TQToolButton(this);
button->setPixmap( Util::getSystemIcon( TQString::tqfromLatin1("package_settings")) );
tqlayout->addWidget( button );
connect(button, TQT_SIGNAL(clicked()), this, TQT_SLOT(configure()));
TQToolTip::add( button, i18n("Settings") );
// It is currently not possible to ask for the paragraph being highlighted, thefore scrolling to next/prev match
// do not work. Enable this when they work.
// _first = new TQToolButton( TQString::tqfromLatin1("<<"), this);
// tqlayout->addWidget( _first );
// connect(_first, TQT_SIGNAL(clicked()), this, TQT_SIGNAL( gotoFirst()));
// _first->setFixedWidth( 25 );
//
// _prev = new TQToolButton(TQString::tqfromLatin1("<"), this);
// tqlayout->addWidget( _prev );
// connect(_prev, TQT_SIGNAL(clicked()), this, TQT_SIGNAL( gotoPrev()));
// _prev->setFixedWidth( 20 );
//
// _next = new TQToolButton(TQString::tqfromLatin1(">"), this);
// tqlayout->addWidget( _next );
// connect(_next, TQT_SIGNAL(clicked()), this, TQT_SIGNAL( gotoNext()));
// _next->setFixedWidth( 20 );
//
// _last = new TQToolButton(TQString::tqfromLatin1(">>"), this);
// tqlayout->addWidget( _last );
// connect(_last, TQT_SIGNAL(clicked()), this, TQT_SIGNAL( gotoLast()));
// _last->setFixedWidth( 25 );
// Same as above
// TQLabel* label = new TQLabel( i18n("Matches: "), this );
// tqlayout->addWidget( label );
// _matches = new TQLabel(i18n("-"), this );
// tqlayout->addWidget( _matches );
// TQString txt = i18n( "Shows number of times regular expression matches the text in the verifier window");
// TQToolTip::add( label, txt );
// TQToolTip::add( _matches, txt );
_verify->setEnabled( false );
// -------------------------------------------------- RegExp Converters
// TQt
RegExpConverter* converter = new TQtRegExpConverter();
_converters.append( tqMakePair( converter, static_cast<TQAction*>( 0 ) ) );
TQString qtConverterName = converter->name();
// Emacs
converter = new EmacsRegExpConverter();
_converters.append( tqMakePair( converter, static_cast<TQAction*>( 0 ) ) );
// -------------------------------------------------- Initialize the config menu
_configMenu = new TQPopupMenu( this, "config menu" );
// Auto Verify
TQAction* autoVerify = new TQAction( i18n("Verify on the Fly"), 0, this );
autoVerify->setToggleAction( true );
autoVerify->setOn( true );
connect( autoVerify, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( updateVerifyButton( bool ) ) );
connect( autoVerify, TQT_SIGNAL( toggled( bool ) ), this, TQT_SIGNAL( autoVerify( bool ) ) );
autoVerify->addTo( _configMenu );
autoVerify->setToolTip( i18n( "Toggle on-the-fly verification of regular expression" ) );
autoVerify->setWhatsThis( i18n( "Enabling this option will make the verifier update for each edit. "
"If the verify window contains much text, or if the regular expression is either "
"complex or matches a lot of time, this may be very slow."));
// RegExp Languages
TQPopupMenu* languages = new TQPopupMenu( _configMenu );
_languageId = _configMenu->insertItem( i18n("RegExp Language"), languages );
TQActionGroup* grp = new TQActionGroup( this );
for( TQValueList< TQPair<RegExpConverter*,TQAction*> >::Iterator it = _converters.begin(); it != _converters.end(); ++it ) {
TQString name = (*it).first->name();
TQAction* action = new TQAction( name, 0, this );
action->setToggleAction( true );
grp->add( action );
(*it).second = action;
}
grp->addTo( languages );
connect( grp, TQT_SIGNAL( selected( TQAction* ) ), this, TQT_SLOT( slotChangeSyntax( TQAction* ) ) );
_configMenu->setItemEnabled( _languageId, false );
// Select the TQt converter by default
setSyntax( qtConverterName );
}
void VerifyButtons::updateVerifyButton( bool b )
{
_verify->setEnabled( !b );
}
void VerifyButtons::loadText()
{
TQString fileName = KFileDialog::getOpenFileName(TQString(), TQString(), this);
if ( !fileName.isNull() ) {
emit loadVerifyText( fileName );
}
}
// TQt anchors do not work for <pre>...</pre>, thefore scrolling to next/prev match
// do not work. Enable this when they work.
// void VerifyButtons::enableBackwardButtons( bool b )
// {
// _first->setEnabled( b );
// _prev->setEnabled( b );
// }
//
// void VerifyButtons::enableForwardButtons( bool b )
// {
// _next->setEnabled( b );
// _last->setEnabled( b );
// }
void VerifyButtons::setMatchCount( int /*count*/ )
{
// currently this is not possible due to limitation in TQSyntaxHighlighter
/*
if ( count == -1 )
_matches->setText( TQString::tqfromLatin1("-") );
else
_matches->setText( TQString::number( count ) );
*/
}
void VerifyButtons::slotChangeSyntax( TQAction* action )
{
emit changeSyntax( action->menuText() );
}
RegExpConverter* VerifyButtons::setSyntax( const TQString& which)
{
for( TQValueList< TQPair<RegExpConverter*, TQAction*> >::Iterator it = _converters.begin(); it != _converters.end(); ++it ) {
TQString name = (*it).first->name();
if ( name == which ) {
(*it).second->setOn( true );
return (*it).first;
}
}
qWarning( "No such converter: '%s'", which.latin1() );
return 0;
}
void VerifyButtons::configure()
{
_configMenu->exec( TQCursor::pos() );
}
void VerifyButtons::setAllowNonTQtSyntax( bool b )
{
_configMenu->setItemEnabled( _languageId, b );
}
|