23 #include <tqcheckbox.h>
24 #include <tqcombobox.h>
25 #include <tqdatetimeedit.h>
27 #include <tqobjectlist.h>
28 #include <tqspinbox.h>
30 #include <tqtextedit.h>
31 #include <tqwidgetfactory.h>
33 #include <kdatepicker.h>
34 #include <kdatetimewidget.h>
36 #include <klineedit.h>
37 #include <kstandarddirs.h>
40 #include "designerfields.h"
44 DesignerFields::DesignerFields(
const TQString &uiFile, TQWidget *parent,
46 : TQWidget( parent, name )
51 void DesignerFields::initGUI(
const TQString &uiFile )
53 TQVBoxLayout *layout =
new TQVBoxLayout(
this );
55 TQWidget *wdg = TQWidgetFactory::create( uiFile, 0,
this );
57 kdError() <<
"No ui file found" << endl;
61 mTitle = wdg->caption();
62 mIdentifier = wdg->name();
64 layout->addWidget( wdg );
66 TQObjectList *list = wdg->queryList(
"TQWidget" );
67 TQObjectListIt it( *list );
69 TQStringList allowedTypes;
70 allowedTypes <<
"TQLineEdit"
80 while ( it.current() ) {
81 if ( allowedTypes.contains( it.current()->className() ) ) {
82 TQString name = it.current()->name();
83 if ( name.startsWith(
"X_" ) ) {
86 TQWidget *widget =
static_cast<TQWidget*
>( it.current() );
87 if ( !name.isEmpty() )
88 mWidgets.insert( name, widget );
90 if ( it.current()->inherits(
"TQLineEdit" ) )
91 connect( it.current(), TQ_SIGNAL( textChanged(
const TQString& ) ),
92 TQ_SIGNAL( modified() ) );
93 else if ( it.current()->inherits(
"TQSpinBox" ) )
94 connect( it.current(), TQ_SIGNAL( valueChanged(
int ) ),
95 TQ_SIGNAL( modified() ) );
96 else if ( it.current()->inherits(
"TQCheckBox" ) )
97 connect( it.current(), TQ_SIGNAL( toggled(
bool ) ),
98 TQ_SIGNAL( modified() ) );
99 else if ( it.current()->inherits(
"TQComboBox" ) )
100 connect( it.current(), TQ_SIGNAL( activated(
const TQString& ) ),
101 TQ_SIGNAL( modified() ) );
102 else if ( it.current()->inherits(
"TQDateTimeEdit" ) )
103 connect( it.current(), TQ_SIGNAL( valueChanged(
const TQDateTime& ) ),
104 TQ_SIGNAL( modified() ) );
105 else if ( it.current()->inherits(
"KDateTimeWidget" ) )
106 connect( it.current(), TQ_SIGNAL( valueChanged(
const TQDateTime& ) ),
107 TQ_SIGNAL( modified() ) );
108 else if ( it.current()->inherits(
"KDatePicker" ) )
109 connect( it.current(), TQ_SIGNAL( dateChanged( TQDate ) ),
110 TQ_SIGNAL( modified() ) );
111 else if ( it.current()->inherits(
"TQTextEdit" ) )
112 connect( it.current(), TQ_SIGNAL( textChanged() ),
113 TQ_SIGNAL( modified() ) );
115 if ( !widget->isEnabled() )
116 mDisabledWidgets.append( widget );
126 TQString DesignerFields::identifier()
const
131 TQString DesignerFields::title()
const
136 void DesignerFields::load( DesignerFields::Storage *storage )
138 TQStringList keys = storage->keys();
143 TQMap<TQString, TQWidget *>::ConstIterator widIt;
144 for ( widIt = mWidgets.begin(); widIt != mWidgets.end(); ++widIt ) {
146 if ( widIt.data()->inherits(
"TQLineEdit" ) ) {
147 TQLineEdit *wdg =
static_cast<TQLineEdit*
>( widIt.data() );
148 wdg->setText( TQString() );
149 }
else if ( widIt.data()->inherits(
"TQSpinBox" ) ) {
150 TQSpinBox *wdg =
static_cast<TQSpinBox*
>( widIt.data() );
151 wdg->setValue( wdg->minValue() );
152 }
else if ( widIt.data()->inherits(
"TQCheckBox" ) ) {
153 TQCheckBox *wdg =
static_cast<TQCheckBox*
>( widIt.data() );
154 wdg->setChecked(
false );
155 }
else if ( widIt.data()->inherits(
"TQDateTimeEdit" ) ) {
156 TQDateTimeEdit *wdg =
static_cast<TQDateTimeEdit*
>( widIt.data() );
157 wdg->setDateTime( TQDateTime::currentDateTime() );
158 }
else if ( widIt.data()->inherits(
"KDateTimeWidget" ) ) {
159 KDateTimeWidget *wdg =
static_cast<KDateTimeWidget*
>( widIt.data() );
160 wdg->setDateTime( TQDateTime::currentDateTime() );
161 }
else if ( widIt.data()->inherits(
"KDatePicker" ) ) {
162 KDatePicker *wdg =
static_cast<KDatePicker*
>( widIt.data() );
163 wdg->setDate( TQDate::currentDate() );
164 }
else if ( widIt.data()->inherits(
"TQComboBox" ) ) {
165 TQComboBox *wdg =
static_cast<TQComboBox*
>( widIt.data() );
166 wdg->setCurrentItem( 0 );
167 }
else if ( widIt.data()->inherits(
"TQTextEdit" ) ) {
168 TQTextEdit *wdg =
static_cast<TQTextEdit*
>( widIt.data() );
169 wdg->setText( TQString() );
173 TQStringList::ConstIterator it2;
174 for ( it2 = keys.begin(); it2 != keys.end(); ++it2 ) {
175 TQString value = storage->read( *it2 );
177 TQMap<TQString, TQWidget *>::ConstIterator it = mWidgets.find( *it2 );
178 if ( it != mWidgets.end() ) {
179 if ( it.data()->inherits(
"TQLineEdit" ) ) {
180 TQLineEdit *wdg =
static_cast<TQLineEdit*
>( it.data() );
181 wdg->setText( value );
182 }
else if ( it.data()->inherits(
"TQSpinBox" ) ) {
183 TQSpinBox *wdg =
static_cast<TQSpinBox*
>( it.data() );
184 wdg->setValue( value.toInt() );
185 }
else if ( it.data()->inherits(
"TQCheckBox" ) ) {
186 TQCheckBox *wdg =
static_cast<TQCheckBox*
>( it.data() );
187 wdg->setChecked( value ==
"true" || value ==
"1" );
188 }
else if ( it.data()->inherits(
"TQDateTimeEdit" ) ) {
189 TQDateTimeEdit *wdg =
static_cast<TQDateTimeEdit*
>( it.data() );
190 wdg->setDateTime( TQDateTime::fromString( value, TQt::ISODate ) );
191 }
else if ( it.data()->inherits(
"KDateTimeWidget" ) ) {
192 KDateTimeWidget *wdg =
static_cast<KDateTimeWidget*
>( it.data() );
193 wdg->setDateTime( TQDateTime::fromString( value, TQt::ISODate ) );
194 }
else if ( it.data()->inherits(
"KDatePicker" ) ) {
195 KDatePicker *wdg =
static_cast<KDatePicker*
>( it.data() );
196 wdg->setDate( TQDate::fromString( value, TQt::ISODate ) );
197 }
else if ( it.data()->inherits(
"TQComboBox" ) ) {
198 TQComboBox *wdg =
static_cast<TQComboBox*
>( it.data() );
199 wdg->setCurrentText( value );
200 }
else if ( it.data()->inherits(
"TQTextEdit" ) ) {
201 TQTextEdit *wdg =
static_cast<TQTextEdit*
>( it.data() );
202 wdg->setText( value );
208 void DesignerFields::save( DesignerFields::Storage *storage )
210 TQMap<TQString, TQWidget*>::Iterator it;
211 for ( it = mWidgets.begin(); it != mWidgets.end(); ++it ) {
213 if ( it.data()->inherits(
"TQLineEdit" ) ) {
214 TQLineEdit *wdg =
static_cast<TQLineEdit*
>( it.data() );
216 }
else if ( it.data()->inherits(
"TQSpinBox" ) ) {
217 TQSpinBox *wdg =
static_cast<TQSpinBox*
>( it.data() );
218 value = TQString::number( wdg->value() );
219 }
else if ( it.data()->inherits(
"TQCheckBox" ) ) {
220 TQCheckBox *wdg =
static_cast<TQCheckBox*
>( it.data() );
221 value = ( wdg->isChecked() ?
"true" :
"false" );
222 }
else if ( it.data()->inherits(
"TQDateTimeEdit" ) ) {
223 TQDateTimeEdit *wdg =
static_cast<TQDateTimeEdit*
>( it.data() );
224 value = wdg->dateTime().toString( TQt::ISODate );
225 }
else if ( it.data()->inherits(
"KDateTimeWidget" ) ) {
226 KDateTimeWidget *wdg =
static_cast<KDateTimeWidget*
>( it.data() );
227 value = wdg->dateTime().toString( TQt::ISODate );
228 }
else if ( it.data()->inherits(
"KDatePicker" ) ) {
229 KDatePicker *wdg =
static_cast<KDatePicker*
>( it.data() );
230 value = wdg->date().toString( TQt::ISODate );
231 }
else if ( it.data()->inherits(
"TQComboBox" ) ) {
232 TQComboBox *wdg =
static_cast<TQComboBox*
>( it.data() );
233 value = wdg->currentText();
234 }
else if ( it.data()->inherits(
"TQTextEdit" ) ) {
235 TQTextEdit *wdg =
static_cast<TQTextEdit*
>( it.data() );
239 storage->write( it.key(), value );
243 void DesignerFields::setReadOnly(
bool readOnly )
245 TQMap<TQString, TQWidget*>::Iterator it;
246 for ( it = mWidgets.begin(); it != mWidgets.end(); ++it )
247 if ( mDisabledWidgets.find( it.data() ) == mDisabledWidgets.end() )
248 it.data()->setEnabled( !readOnly );
251 #include "designerfields.moc"
TDEPIM classes for drag and drop of mails.