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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
/* This file is part of the KDE Project
Copyright (C) 2000 Klaas Freitag <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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.
*/
#include <layout.h>
#include <tqpushbutton.h>
#include <tqspinbox.h>
#include <tqtooltip.h>
#include <tqcombobox.h>
#include <tqlabel.h>
#include <tqslider.h>
#include <tqlineedit.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kdebug.h>
#include "kscanslider.h"
KScanSlider::KScanSlider( TQWidget *parent, const TQString& text,
double min, double max, bool haveStdButt,
int stdValue )
: TQFrame( parent ),
m_stdValue( stdValue ),
m_stdButt(0)
{
TQHBoxLayout *hb = new TQHBoxLayout( this );
l1 = new TQLabel( text, this, "AUTO_SLIDER_LABEL" );
hb->addWidget( l1,20 );
if( haveStdButt )
{
KIconLoader *loader = KGlobal::iconLoader();
m_stdButt = new TQPushButton( this );
m_stdButt->setPixmap( loader->loadIcon( "undo",KIcon::Small ));
/* connect the button click to setting the value */
connect( m_stdButt, TQT_SIGNAL(clicked()),
this, TQT_SLOT(slRevertValue()));
TQToolTip::add( m_stdButt,
i18n( "Revert value back to its standard value %1" ).arg( stdValue ));
hb->addWidget( m_stdButt, 0 );
hb->addSpacing( 4 );
}
slider = new TQSlider( (int) min, (int)max, 1, (int)min, Qt::Horizontal, this, "AUTO_SLIDER_" );
slider->setTickmarks( TQSlider::Below );
slider->setTickInterval( int(TQMAX( (max-min)/10, 1 )) );
slider->setSteps( int(TQMAX( (max-min)/20, 1) ), int(TQMAX( (max-min)/10, 1) ) );
slider->setMinimumWidth( 140 );
/* set a buddy */
l1->setBuddy( slider );
/* create a spinbox for displaying the values */
m_spin = new TQSpinBox( (int) min, (int) max,
1, // step
this );
/* make spin box changes change the slider */
connect( m_spin, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slSliderChange(int)));
/* Handle internal number display */
// connect(slider, TQT_SIGNAL(valueChanged(int)), numdisp, TQT_SLOT( setNum(int) ));
connect(slider, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT( slSliderChange(int) ));
/* set Value 0 to the widget */
slider->setValue( (int) min -1 );
/* Add to layout widget and activate */
hb->addWidget( slider, 36 );
hb->addSpacing( 4 );
hb->addWidget( m_spin, 0 );
hb->activate();
}
void KScanSlider::setEnabled( bool b )
{
if( slider )
slider->setEnabled( b );
if( l1 )
l1->setEnabled( b );
if( m_spin )
m_spin->setEnabled( b );
if( m_stdButt )
m_stdButt->setEnabled( b );
}
void KScanSlider::slSetSlider( int value )
{
/* Important to check value to avoid recursive signals ;) */
// debug( "Slider val: %d -> %d", value, slider_val );
kdDebug(29000) << "Setting Slider with " << value << endl;
if( value == slider->value() )
{
kdDebug(29000) << "Returning because slider value is already == " << value << endl;
return;
}
slider->setValue( value );
slSliderChange( value );
}
void KScanSlider::slSliderChange( int v )
{
// kdDebug(29000) << "Got slider val: " << v << endl;
// slider_val = v;
int spin = m_spin->value();
if( v != spin )
m_spin->setValue(v);
int slid = slider->value();
if( v != slid )
slider->setValue(v);
emit( valueChanged( v ));
}
void KScanSlider::slRevertValue()
{
if( m_stdButt )
{
/* Only if stdButt is non-zero, the default value is valid */
slSetSlider( m_stdValue );
}
}
KScanSlider::~KScanSlider()
{
}
/* ====================================================================== */
KScanEntry::KScanEntry( TQWidget *parent, const TQString& text )
: TQFrame( parent )
{
TQHBoxLayout *hb = new TQHBoxLayout( this );
TQLabel *l1 = new TQLabel( text, this, "AUTO_ENTRYFIELD" );
hb->addWidget( l1,1 );
entry = new TQLineEdit( this, "AUTO_ENTRYFIELD_E" );
l1->setBuddy( entry );
connect( entry, TQT_SIGNAL( textChanged(const TQString& )),
this, TQT_SLOT( slEntryChange(const TQString&)));
connect( entry, TQT_SIGNAL( returnPressed()),
this, TQT_SLOT( slReturnPressed()));
hb->addWidget( entry,3 );
hb->activate();
}
TQString KScanEntry::text( void ) const
{
TQString str = TQString();
// kdDebug(29000) << "entry is "<< entry << endl;
if(entry)
{
str = entry->text();
if( ! str.isNull() && ! str.isEmpty())
{
kdDebug(29000) << "KScanEntry returns <" << str << ">" << endl;
}
else
{
kdDebug(29000) << "KScanEntry: nothing entered !" << endl;
}
}
else
{
kdDebug(29000) << "KScanEntry ERR: member var entry not defined!" << endl;
}
return ( str );
}
void KScanEntry::slSetEntry( const TQString& t )
{
if( t == entry->text() )
return;
/* Important to check value to avoid recursive signals ;) */
entry->setText( t );
}
void KScanEntry::slEntryChange( const TQString& t )
{
emit valueChanged( TQCString( t.latin1() ) );
}
void KScanEntry::slReturnPressed( void )
{
TQString t = text();
emit returnPressed( TQCString( t.latin1()));
}
KScanCombo::KScanCombo( TQWidget *parent, const TQString& text,
const TQStrList& list )
: TQHBox( parent ),
combo(0)
{
createCombo( text );
if( combo )
combo->insertStrList( list);
combolist = list;
}
KScanCombo::KScanCombo( TQWidget *parent, const TQString& text,
const TQStringList& list )
: TQHBox( parent ),
combo(0)
{
createCombo( text );
if( combo )
combo->insertStringList( list );
for ( TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
combolist.append( (*it).local8Bit() );
}
}
void KScanCombo::createCombo( const TQString& text )
{
setSpacing( 12 );
setMargin( 2 );
(void) new TQLabel( text, this, "AUTO_COMBOLABEL" );
combo = new TQComboBox( this, "AUTO_COMBO" );
connect( combo, TQT_SIGNAL(activated( const TQString &)), this,
TQT_SLOT( slComboChange( const TQString &)));
connect( combo, TQT_SIGNAL(activated( int )),
this, TQT_SLOT(slFireActivated(int)));
}
void KScanCombo::slSetEntry( const TQString &t )
{
if( t.isNull() ) return;
int i = combolist.find( t.local8Bit() );
/* Important to check value to avoid recursive signals ;) */
if( i == combo->currentItem() )
return;
if( i > -1 )
combo->setCurrentItem( i );
else
kdDebug(29000) << "Combo item not in list !" << endl;
}
void KScanCombo::slComboChange( const TQString &t )
{
emit valueChanged( TQCString( t.latin1() ) );
kdDebug(29000) << "Combo: valueChanged emitted!" << endl;
}
void KScanCombo::slSetIcon( const TQPixmap& pix, const TQString& str)
{
for( int i=0; i < combo->count(); i++ )
{
if( combo->text(i) == str )
{
combo->changeItem( pix, str, i );
break;
}
}
}
TQString KScanCombo::currentText( void ) const
{
return( combo->currentText() );
}
TQString KScanCombo::text( int i ) const
{
return( combo->text(i) );
}
void KScanCombo::setCurrentItem( int i )
{
combo->setCurrentItem( i );
}
int KScanCombo::count( void ) const
{
return( combo->count() );
}
void KScanCombo::slFireActivated( int i )
{
emit( activated( i ));
}
#include "kscanslider.moc"
|