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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
/* This file is part of the KDE project
Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@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 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 "KoCustomVariablesDia.h"
#include "KoCustomVariablesDia.moc"
#include <klocale.h>
#include <kbuttonbox.h>
#include <tqcombobox.h>
#include <tqvbox.h>
#include <tqlabel.h>
#include <tqpushbutton.h>
#include <tqheader.h>
#include <klineedit.h>
#include <kdebug.h>
/******************************************************************
*
* Class: KoVariableNameDia
*
******************************************************************/
KoVariableNameDia::KoVariableNameDia( TQWidget *parent )
: KDialogBase( parent, "", TRUE,i18n( "Entry Name" ),Ok|Cancel )
{
init();
}
KoVariableNameDia::KoVariableNameDia( TQWidget *parent, const TQPtrList<KoVariable>& vars )
: KDialogBase( parent, "", TRUE, i18n( "Variable Name" ), Ok|Cancel )
{
init();
enableButtonOK(false);
TQPtrListIterator<KoVariable> it( vars );
for ( ; it.current() ; ++it ) {
KoVariable *var = it.current();
if ( var->type() == VT_CUSTOM )
names->insertItem( ( (KoCustomVariable*) var )->name(), -1 );
}
}
void KoVariableNameDia::init()
{
back = makeVBoxMainWidget();
TQHBox *row1 = new TQHBox( back );
row1->setSpacing( KDialog::spacingHint() );
TQLabel *l = new TQLabel( i18n( "Name:" ), row1 );
l->setFixedSize( l->sizeHint() );
names = new TQComboBox( TRUE, row1 );
names->setFocus();
connect( names, TQT_SIGNAL( textChanged ( const TQString & )),
this, TQT_SLOT( textChanged ( const TQString & )));
connect( this, TQT_SIGNAL( okClicked() ),
this, TQT_SLOT( accept() ) );
connect( this, TQT_SIGNAL( cancelClicked() ),
this, TQT_SLOT( reject() ) );
enableButtonOK( !names->currentText().isEmpty() );
resize( 350, 100 );
}
TQString KoVariableNameDia::getName() const
{
return names->currentText();
}
void KoVariableNameDia::textChanged ( const TQString &_text )
{
enableButtonOK(!_text.isEmpty());
}
/******************************************************************
*
* Class: KoCustomVariablesListItem
*
******************************************************************/
KoCustomVariablesListItem::KoCustomVariablesListItem( TQListView *parent )
: TQListViewItem( parent )
{
editWidget = new KLineEdit( listView()->viewport() );
listView()->addChild( editWidget );
}
void KoCustomVariablesListItem::setup()
{
TQListViewItem::setup();
setHeight( TQMAX( listView()->fontMetrics().height(),
editWidget->sizeHint().height() ) );
//if ( listView()->columnWidth( 1 ) < editWidget->sizeHint().width() )
// listView()->setColumnWidth( 1, editWidget->sizeHint().width() );
}
void KoCustomVariablesListItem::update()
{
editWidget->resize( listView()->header()->cellSize( 1 ), height() );
listView()->moveChild( editWidget, listView()->header()->cellPos( 1 ),
listView()->itemPos( this ) + listView()->contentsY() );
editWidget->show();
}
void KoCustomVariablesListItem::setVariable( KoCustomVariable *v )
{
var = v;
editWidget->setText( var->value() );
setText( 0, v->name() );
}
KoCustomVariable *KoCustomVariablesListItem::getVariable() const
{
return var;
}
void KoCustomVariablesListItem::applyValue()
{
TQString newVal=editWidget->text();
if(var->value()!=newVal)
var->setValue( newVal );
}
int KoCustomVariablesListItem::width( const TQFontMetrics & fm, const TQListView *lv, int c ) const
{
// The text of the 2nd column isn't known to TQListViewItem, only we know it
// (it's in our lineedit)
if ( c == 1 ) {
TQString val = editWidget->text();
int w = fm.width( val );
return w;
} else
return TQListViewItem::width( fm, lv, c );
}
/******************************************************************
*
* Class: KoCustomVariablesList
*
******************************************************************/
KoCustomVariablesList::KoCustomVariablesList( TQWidget *parent )
: KListView( parent )
{
header()->setMovingEnabled( FALSE );
addColumn( i18n( "Variable" ) );
addColumn( i18n( "Value" ) );
connect( header(), TQT_SIGNAL( sizeChange( int, int, int ) ),
this, TQT_SLOT( columnSizeChange( int, int, int ) ) );
connect( header(), TQT_SIGNAL( sectionClicked( int ) ),
this, TQT_SLOT( sectionClicked( int ) ) );
setResizeMode(TQListView::LastColumn);
setSorting( -1 );
}
void KoCustomVariablesList::setValues()
{
TQListViewItemIterator it( this );
for ( ; it.current(); ++it )
( (KoCustomVariablesListItem *)it.current() )->applyValue();
}
void KoCustomVariablesList::columnSizeChange( int c, int, int )
{
if ( c == 0 || c == 1 )
updateItems();
}
void KoCustomVariablesList::sectionClicked( int )
{
updateItems();
}
void KoCustomVariablesList::updateItems()
{
TQListViewItemIterator it( this );
for ( ; it.current(); ++it )
( (KoCustomVariablesListItem*)it.current() )->update();
}
/******************************************************************
*
* Class: KoCustomVariablesDia
*
******************************************************************/
KoCustomVariablesDia::KoCustomVariablesDia( TQWidget *parent, const TQPtrList<KoVariable> &variables )
: KDialogBase( parent, "", TRUE,i18n( "Variable Value Editor" ), Ok|Cancel )
{
back = makeVBoxMainWidget();
list = new KoCustomVariablesList( back );
TQStringList lst;
TQPtrListIterator<KoVariable> it( variables );
for ( ; it.current() ; ++it ) {
KoVariable *var = it.current();
if ( var->type() == VT_CUSTOM ) {
KoCustomVariable *v = (KoCustomVariable*)var;
if ( !lst.contains( v->name() ) ) {
lst.append( v->name() );
KoCustomVariablesListItem *item = new KoCustomVariablesListItem( list );
item->setVariable( v );
}
}
}
connect( this, TQT_SIGNAL( okClicked() ),
this, TQT_SLOT( slotOk() ) );
connect( this, TQT_SIGNAL( cancelClicked() ),
this, TQT_SLOT( reject() ) );
showButtonOK(lst.count()>0);
resize( 600, 400 );
}
void KoCustomVariablesDia::slotOk()
{
list->setValues();
accept();
}
/******************************************************************
*
* Class: KoCustomVarDialog
*
******************************************************************/
KoCustomVarDialog::KoCustomVarDialog( TQWidget *parent )
: KDialogBase( parent, "", TRUE,i18n( "Add Variable" ), Ok|Cancel )
{
init();
m_name->setFocus();
connect( this, TQT_SIGNAL( okClicked() ),
this, TQT_SLOT( slotAddOk() ) );
connect( this, TQT_SIGNAL( cancelClicked() ),
this, TQT_SLOT( reject() ) );
connect( m_name, TQT_SIGNAL( textChanged(const TQString&) ),
this, TQT_SLOT( slotTextChanged(const TQString&) ) );
enableButtonOK( false );
resize( 350, 100 );
}
// edit existing variable
KoCustomVarDialog::KoCustomVarDialog( TQWidget *parent, KoCustomVariable *var )
: KDialogBase( parent, "", TRUE,i18n( "Edit Variable" ), Ok|Cancel )
{
m_var = var;
init();
m_name->setText( m_var->name() );
m_value->setText( m_var->value() );
m_name->setReadOnly(true);
m_value->setFocus();
connect( this, TQT_SIGNAL( okClicked() ),
this, TQT_SLOT( slotEditOk() ) );
connect( this, TQT_SIGNAL( cancelClicked() ),
this, TQT_SLOT( reject() ) );
connect( m_value, TQT_SIGNAL( textChanged(const TQString&) ),
this, TQT_SLOT( slotTextChanged(const TQString&) ) );
enableButtonOK( true );
resize( 350, 100 );
}
void KoCustomVarDialog::init()
{
back = makeVBoxMainWidget();
TQHBox *row1 = new TQHBox( back );
row1->setSpacing( KDialog::spacingHint() );
TQLabel *ln = new TQLabel( i18n( "Name:" ), row1 );
ln->setFixedSize( ln->sizeHint() );
m_name = new KLineEdit( row1 );
TQHBox *row2 = new TQHBox( back );
row2->setSpacing( KDialog::spacingHint() );
TQLabel *lv = new TQLabel( i18n( "Value:" ), row2 );
lv->setFixedSize( lv->sizeHint() );
m_value = new KLineEdit( row2 );
}
void KoCustomVarDialog::slotAddOk()
{
accept();
}
void KoCustomVarDialog::slotEditOk()
{
m_var->setValue( m_value->text() );
accept();
}
void KoCustomVarDialog::slotTextChanged(const TQString&text)
{
enableButtonOK( !text.isEmpty() );
}
TQString KoCustomVarDialog::name()
{
if ( m_name->text().isEmpty() )
return TQString( "No name" );
return m_name->text();
}
TQString KoCustomVarDialog::value()
{
if ( m_value->text().isEmpty() )
return TQString( "No value" );
return m_value->text();
}
|