20#include "KoCustomVariablesDia.h"
21#include "KoCustomVariablesDia.moc"
24#include <kbuttonbox.h>
26#include <tqcombobox.h>
29#include <tqpushbutton.h>
40KoVariableNameDia::KoVariableNameDia( TQWidget *parent )
41 :
KDialogBase( parent,
"", true,i18n(
"Entry Name" ),Ok|Cancel )
47KoVariableNameDia::KoVariableNameDia( TQWidget *parent,
const TQPtrList<KoVariable>& vars )
48 :
KDialogBase( parent,
"", true, i18n(
"Variable Name" ), Ok|Cancel )
52 enableButtonOK(
false);
53 TQPtrListIterator<KoVariable> it( vars );
54 for ( ; it.current() ; ++it ) {
56 if ( var->type() == VT_CUSTOM )
62void KoVariableNameDia::init()
66 TQHBox *row1 =
new TQHBox( back );
69 TQLabel *l =
new TQLabel( i18n(
"Name:" ), row1 );
70 l->setFixedSize( l->sizeHint() );
71 names =
new TQComboBox(
true, row1 );
74 connect( names, TQ_SIGNAL( textChanged (
const TQString & )),
75 this, TQ_SLOT( textChanged (
const TQString & )));
77 this, TQ_SLOT( accept() ) );
79 this, TQ_SLOT( reject() ) );
84TQString KoVariableNameDia::getName()
const
86 return names->currentText();
89void KoVariableNameDia::textChanged (
const TQString &_text )
100KoCustomVariablesListItem::KoCustomVariablesListItem( TQListView *parent )
101 : TQListViewItem( parent )
103 editWidget =
new KLineEdit( listView()->viewport() );
104 listView()->addChild( editWidget );
107void KoCustomVariablesListItem::setup()
109 TQListViewItem::setup();
110 setHeight( TQMAX( listView()->fontMetrics().height(),
111 editWidget->sizeHint().height() ) );
116void KoCustomVariablesListItem::update()
118 editWidget->resize( listView()->header()->cellSize( 1 ), height() );
119 listView()->moveChild( editWidget, listView()->header()->cellPos( 1 ),
120 listView()->itemPos(
this ) + listView()->contentsY() );
127 editWidget->setText( var->value() );
128 setText( 0, v->name() );
136void KoCustomVariablesListItem::applyValue()
138 TQString newVal=editWidget->
text();
139 if(var->value()!=newVal)
140 var->setValue( newVal );
143int KoCustomVariablesListItem::width(
const TQFontMetrics & fm,
const TQListView *lv,
int c )
const
148 TQString val = editWidget->text();
149 int w = fm.width( val );
152 return TQListViewItem::width( fm, lv, c );
161KoCustomVariablesList::KoCustomVariablesList( TQWidget *parent )
164 header()->setMovingEnabled(
false );
165 addColumn( i18n(
"Variable" ) );
166 addColumn( i18n(
"Value" ) );
167 connect( header(), TQ_SIGNAL( sizeChange(
int,
int,
int ) ),
168 this, TQ_SLOT( columnSizeChange(
int,
int,
int ) ) );
169 connect( header(), TQ_SIGNAL( sectionClicked(
int ) ),
170 this, TQ_SLOT( sectionClicked(
int ) ) );
172 setResizeMode(TQListView::LastColumn);
176void KoCustomVariablesList::setValues()
178 TQListViewItemIterator it(
this );
179 for ( ; it.current(); ++it )
180 ( (KoCustomVariablesListItem *)it.current() )->applyValue();
183void KoCustomVariablesList::columnSizeChange(
int c,
int,
int )
185 if ( c == 0 || c == 1 )
189void KoCustomVariablesList::sectionClicked(
int )
194void KoCustomVariablesList::updateItems()
196 TQListViewItemIterator it(
this );
197 for ( ; it.current(); ++it )
198 ( (KoCustomVariablesListItem*)it.current() )->update();
207KoCustomVariablesDia::KoCustomVariablesDia( TQWidget *parent,
const TQPtrList<KoVariable> &variables )
208 :
KDialogBase( parent,
"", true,i18n(
"Variable Value Editor" ), Ok|Cancel )
211 back = makeVBoxMainWidget();
216 TQPtrListIterator<KoVariable> it( variables );
217 for ( ; it.current() ; ++it ) {
219 if ( var->type() == VT_CUSTOM ) {
221 if ( !lst.contains( v->name() ) ) {
222 lst.append( v->name() );
224 item->setVariable( v );
230 connect(
this, TQ_SIGNAL( okClicked() ),
231 this, TQ_SLOT( slotOk() ) );
232 connect(
this, TQ_SIGNAL( cancelClicked() ),
233 this, TQ_SLOT( reject() ) );
234 showButtonOK(lst.count()>0);
259 this, TQ_SLOT( slotAddOk() ) );
261 this, TQ_SLOT( reject() ) );
263 connect( m_name, TQ_SIGNAL( textChanged(
const TQString&) ),
264 this, TQ_SLOT( slotTextChanged(
const TQString&) ) );
276 m_name->setText( m_var->name() );
277 m_value->setText( m_var->value() );
278 m_name->setReadOnly(
true);
283 this, TQ_SLOT( slotEditOk() ) );
285 this, TQ_SLOT( reject() ) );
287 connect( m_value, TQ_SIGNAL( textChanged(
const TQString&) ),
288 this, TQ_SLOT( slotTextChanged(
const TQString&) ) );
294void KoCustomVarDialog::init()
297 TQHBox *row1 =
new TQHBox( back );
299 TQLabel *ln =
new TQLabel( i18n(
"Name:" ), row1 );
300 ln->setFixedSize( ln->sizeHint() );
303 TQHBox *row2 =
new TQHBox( back );
305 TQLabel *lv =
new TQLabel( i18n(
"Value:" ), row2 );
306 lv->setFixedSize( lv->sizeHint() );
310void KoCustomVarDialog::slotAddOk()
314void KoCustomVarDialog::slotEditOk()
316 m_var->setValue( m_value->text() );
320void KoCustomVarDialog::slotTextChanged(
const TQString&text)
324TQString KoCustomVarDialog::name()
326 if ( m_name->text().isEmpty() )
327 return TQString(
"No name" );
328 return m_name->text();
331TQString KoCustomVarDialog::value()
333 if ( m_value->text().isEmpty() )
334 return TQString(
"No value" );
335 return m_value->text();
void enableButtonOK(bool state)
KDialogBase(TQWidget *parent=0, const char *name=0, bool modal=true, const TQString &caption=TQString::null, int buttonMask=Ok|Apply|Cancel, ButtonCode defaultButton=Ok, bool separator=false, const KGuiItem &user1=KGuiItem(), const KGuiItem &user2=KGuiItem(), const KGuiItem &user3=KGuiItem())
TQVBox * makeVBoxMainWidget()
KoCustomVarDialog(TQWidget *parent)
Add new variable.
A custom variable is a variable whose value is entered by the user.
virtual TQString text(bool realValue=false)
Returns the text to be displayed for this variable It doesn't need to be cached, convert() is fast,...
Class: KoCustomVariablesListItem Used by KoCustomVariablesDia Represents an item in the listview,...
Class: KoCustomVariablesList The listview.
A KoVariable is a custom item, i.e.
TDEAction * back(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
const char * name(StdAction id)