00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00028
00030
00031 #define YASAGUI_WIDGETS_INCLUDE
00032
00033 #include <qspinbox.h>
00034 #include <qlineedit.h>
00035 #include <qcombobox.h>
00036 #include <qcheckbox.h>
00037 #include <qmultilineedit.h>
00038 #include <qvbox.h>
00039 #include <qhbox.h>
00040 #include <qgroupbox.h>
00041 #include <qpushbutton.h>
00042 #include <qlistview.h>
00043 #include <qdatetime.h>
00044 #if QT_VERSION>=300
00045 #include <qdatetimeedit.h>
00046 #endif
00047 #include "datatypes.h"
00048
00049
00050
00052 class YListViewItem : public QObject, public QListViewItem
00053 {
00054 Q_OBJECT
00055 protected:
00056 YObject *object;
00057 public:
00058 YListViewItem(YObject *o, QListView *parent, QListViewItem *after=0) :
00059 QListViewItem(parent,after), object(o)
00060 {
00061 o->UpdateArgConnect(this, SLOT( UpdateObject(YObject *) ) );
00062 UpdateObject(o);
00063 }
00064 YListViewItem(YObject *o, QListViewItem *parent, QListViewItem *after=0) :
00065 QListViewItem(parent, after, o->GetName() ), object(o)
00066 {
00067 o->UpdateArgConnect(this, SLOT( UpdateObject(YObject *) ) );
00068
00069 UpdateObject(o);
00070 }
00071 virtual void Activate()
00072 {
00073
00074
00075
00076
00077 }
00078 virtual int InitInstance()
00079 {
00080 EnableInlineRename();
00081 return 0;
00082 }
00083 YObject* GetObject() const { return object; }
00084 void DisableInlineRename()
00085 {
00086 #if QT_VERSION>=300
00087 setRenameEnabled(0, FALSE);
00088 #endif
00089 }
00090 void EnableInlineRename()
00091 {
00092 #if QT_VERSION>=300
00093 setRenameEnabled(0, TRUE);
00094 #endif
00095 }
00096 public slots:
00097 virtual void UpdateObject(YObject *);
00098 };
00099
00100
00102 class YListView : public QListView
00103 { Q_OBJECT
00104 private:
00105 YListViewItem* _FindItemRecursive(YListViewItem *item, YObject *o);
00106 protected:
00107 YSet *set;
00108 public: YListView(YSet *s, QWidget *parent, const QString &title);
00109 YListViewItem* FindItemFromObject(YObject *object) { return _FindItemRecursive( (YListViewItem*)firstChild(), object); }
00110 virtual YListViewItem* CreateNewItem(QListViewItem *parent, YObject *object, QListViewItem *after=0);
00111 YSet* GetSet() { return set; }
00112 YListViewItem* GetCurrentItem() const { return (YListViewItem*)currentItem(); }
00113 void SetSelectedItem(YListViewItem *item=0);
00114 virtual int InitInstance();
00115 public slots:
00116 virtual void NewChildObject(YObject *object);
00117 virtual void ChildObjectRemoved(YObject *object);
00118 virtual int CreateSetItems();
00119 virtual void UpdateList(YObject *object)
00120 {
00121 sort();
00122 Q_UNUSED(object);
00123 }
00124 signals:
00125 void ListViewEmpty();
00126 };
00127
00128
00129
00131 class YWidget
00132 {
00133 protected:
00134 YObject *object;
00135 public: YWidget(YObject *o) : object(o)
00136 {}
00137 virtual void UpdateWidget() {}
00138 virtual QWidget* GetWidget() =0;
00139 };
00140
00141
00143 class YCheckBoxWidget : public QCheckBox, public YWidget
00144 { Q_OBJECT
00145 public: YCheckBoxWidget(YObject *object, QWidget *parent) : QCheckBox(parent), YWidget(object)
00146 { connect( object, SIGNAL(UpdateObject(YObject *)), this, SLOT(UpdateWidget(YObject *) ) );
00147 connect( this, SIGNAL(toggled(bool)), this, SLOT(UpdateValue(bool) ) );
00148 }
00149 virtual QWidget* GetWidget() { return this; }
00150 public slots:
00151 virtual void UpdateWidget(YObject *o) { Q_UNUSED(o); }
00152 virtual void UpdateValue(bool state) { Q_UNUSED(state); }
00153 };
00154
00155
00157 class YIntegerWidget : public QSpinBox, public YWidget
00158 { Q_OBJECT
00159 public: YIntegerWidget(YObject *object, QWidget *parent) : QSpinBox(parent), YWidget(object)
00160 { connect( object, SIGNAL(UpdateObject()), this, SLOT(UpdateWidget() ) );
00161 connect( this, SIGNAL(valueChanged(int)), this, SLOT(UpdateValue(int) ) );
00162 }
00163 virtual QWidget* GetWidget() { return this; }
00164 public slots:
00165 virtual void UpdateWidget() { }
00166 virtual void UpdateValue(int value) { Q_UNUSED(value); }
00167 };
00168
00169
00171 class YComboWidget : public QComboBox, public YWidget
00172 { Q_OBJECT
00173 public: YComboWidget(YObject *object, QWidget *parent) : QComboBox(parent), YWidget(object)
00174 { connect( object, SIGNAL(UpdateObject()), this, SLOT(UpdateWidget() ) );
00175 connect( this, SIGNAL(activated(int)), this, SLOT(UpdateValue(int) ) );
00176 }
00177 virtual QWidget* GetWidget() { return this; }
00178 public slots:
00179 virtual void UpdateWidget() { }
00180 virtual void UpdateValue(int value) { Q_UNUSED(value); }
00181 };
00182
00184 class YTextComboWidget : public QComboBox, public YWidget
00185 { Q_OBJECT
00186 public: YTextComboWidget(YObject *object, QWidget *parent) : QComboBox(parent), YWidget(object)
00187 { connect( object, SIGNAL(UpdateObject()), this, SLOT(UpdateWidget() ) );
00188 connect( this, SIGNAL(activated(const QString &)), this, SLOT(UpdateValue(const QString &) ) );
00189 }
00190 virtual QWidget* GetWidget() { return this; }
00191 public slots:
00192 virtual void UpdateWidget() { }
00193 virtual void UpdateValue(const QString &value) { Q_CONSTUNUSED(value); }
00194 };
00195
00196
00198 class YStringWidget : public QLineEdit, public YWidget
00199 { Q_OBJECT
00200 public: YStringWidget(YObject *object, QWidget *parent) : QLineEdit(parent), YWidget(object)
00201 { connect( object, SIGNAL(UpdateObject()), this, SLOT(UpdateWidget() ) );
00202 connect( this, SIGNAL(textChanged(const QString &)), this, SLOT(UpdateValue( const QString &) ) );
00203 }
00204 virtual QWidget* GetWidget() { return this; }
00205 public slots:
00206 virtual void UpdateWidget() { }
00207 virtual void UpdateValue( const QString &t) { (const void)(t); }
00208 };
00209
00210
00212 class YTextWidget : public QMultiLineEdit, public YWidget
00213 { Q_OBJECT
00214 public: YTextWidget(YObject *object, QWidget *parent) : QMultiLineEdit(parent), YWidget(object)
00215 { setWordWrap(WidgetWidth);
00216 connect( object, SIGNAL(UpdateObject()), this, SLOT(UpdateWidget() ) );
00217 connect( this, SIGNAL(textChanged()), this, SLOT(UpdateValue() ) );
00218 }
00219 virtual QWidget* GetWidget() { return this; }
00220 public slots:
00221 virtual void UpdateWidget() { }
00222 virtual void UpdateValue() { }
00223 };
00224
00225
00227 class YYasaTimeWidget : public QSpinBox, public YWidget
00228 { Q_OBJECT
00229 public: YYasaTimeWidget(YObject *object, QWidget *parent) : QSpinBox(parent), YWidget(object)
00230 { setMinValue(0);
00231 setMaxValue(YTIME::YASA_TIME_INT_MAX);
00232 if ( object )
00233 connect( object, SIGNAL(UpdateObject()), this, SLOT(UpdateWidget() ) );
00234 connect( this, SIGNAL(valueChanged(int)), this, SLOT(UpdateIntValue(int) ) );
00235 }
00236 virtual QWidget* GetWidget() { return this; }
00237 void SetYasaTime(YASA_TIME t) { setValue(t); }
00238 YASA_TIME GetYasaTime() const { return value(); }
00239 void SetReadOnly(bool b) { editor()->setReadOnly(b);
00240 #if QT_VERSION<300
00241 upButton()->setEnabled(!b);
00242 downButton()->setEnabled(!b);
00243 #endif
00244 }
00245 public slots:
00246 virtual void UpdateWidget() { }
00247 virtual void UpdateIntValue(int value) { UpdateValue(value); }
00248 virtual void UpdateValue(YASA_TIME value) { Q_UNUSED(value); }
00249 };
00250
00251
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 class YDateTimeWidget : public QLineEdit, public YWidget
00275 { Q_OBJECT
00276 QDateTime datetime;
00277 public: YDateTimeWidget(YObject *object, QWidget *parent) : QLineEdit(parent), YWidget(object)
00278 { connect( object, SIGNAL(UpdateObject()), this, SLOT(UpdateWidget() ) );
00279 setReadOnly(true);
00280 }
00281 virtual QWidget* GetWidget() { return this; }
00282 void SetDateTime(const QDateTime &t)
00283 {
00284 datetime=t;
00285 setText(MSGP_NOT_AVAILABLE_BEFORE_QT3);
00286
00287
00288 }
00289 QDateTime GetDateTime()
00290 {
00291 return datetime;
00292
00293 }
00294 public slots:
00295 virtual void UpdateWidget() { }
00296 virtual void UpdateDate(const QDateTime &date) { Q_CONSTUNUSED(date); }
00297 };
00298
00299
00300
00302 class YNameWidget : public YStringWidget
00303 { Q_OBJECT
00304 public: YNameWidget(YObject *object, QWidget *parent) : YStringWidget(object, parent)
00305 { UpdateWidget(); }
00306 public slots:
00307 virtual void UpdateWidget() { if ( text()!=object->GetName())
00308 setText(object->GetName() ); }
00309 virtual void UpdateValue( const QString &t) { object->SetName( text() );
00310 Q_CONSTUNUSED(t); }
00311 };
00312
00313
00315 class YDescriptionWidget : public YTextWidget
00316 { Q_OBJECT
00317 public: YDescriptionWidget(YObject *object, QWidget *parent) : YTextWidget(object,parent)
00318 { UpdateWidget(); }
00319 public slots:
00320 virtual void UpdateWidget() { if ( text()!=object->GetDescription())
00321 setText(object->GetDescription() ); }
00322 virtual void UpdateValue() { object->SetDescription( text() ); }
00323 };
00324
00325
00326
00327
00329 class YStringList : public QObject, public QStringList
00330 { Q_OBJECT
00331 YSet *set;
00332 bool makeconnections;
00333 QList<YObject> objectlist;
00334 public: YStringList(YSet *s, bool mc=false) :
00335 set(s),
00336 makeconnections(mc)
00337 {
00338 connect( (YObject*)set, SIGNAL(NewItem(YObject *)), this, SLOT( NewItem(YObject *) ) );
00339 connect( (YObject*)set, SIGNAL(ItemRemoved(YObject *)), this, SLOT( ItemRemoved(YObject *) ) );
00340 UpdateList(0);
00341 }
00342 void ClearList();
00343 unsigned int FindIndex(YObject *object);
00344 YObject* FindObject(unsigned int index);
00345 YObject* FindObject(const QString &s);
00346 void AddItem(YObject *newobject, const QString &name=QString::null, bool appenditem=true);
00347 public slots:
00348 virtual void UpdateList(YObject *);
00349 void UpdateItem(YObject *);
00350 void NewItem(YObject *o) { AddItem(o); }
00351 void ItemRemoved(YObject *object);
00352 signals:
00353 void StringListChanged();
00354 };
00355
00356
00357
00358
00359
00361 #endif // ifndef YASAGUI_WIDGETS_INCLUDE