Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Examples  

widgets.h

Go to the documentation of this file.
00001 
00002 //
00003 // YASA widgets declarations
00004 //
00005 // Project: Yasa 2
00006 // Author : Jan Blumenthal
00007 // Start  : 2002/02/28
00008 // $Header: /sources/yasa/yasagui/widgets.h,v 1.4 2003/01/24 15:47:44 bj Exp $
00009 //
00011 //
00012 // This program is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU General Public License as published by
00014 // the Free Software Foundation; either version 2 of the License, or
00015 // (at your option) any later version.
00016 //
00017 // This program is distributed in the hope that it will be useful,
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU General Public License
00023 // along with this program (See the included file COPYING);
00024 // if not, write to the Free Software Foundation, Inc.,
00025 // 675 Mass Ave, Cambridge, MA 02139, USA.
00026 //
00028 // This file contains all base widgets classes of YASAGUI
00030 #ifndef YASAGUI_WIDGETS_INCLUDE
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                             //connect( o, SIGNAL(UpdateObject(YObject *)), this, SLOT( UpdateObject(YObject *) ) );
00069                             UpdateObject(o);
00070                         }
00071     virtual void        Activate()                              // toggle mode open/closed "+"
00072                         {
00073                             /*if ( isOpen() )
00074                                 setOpen(FALSE);
00075                             else
00076                                 setOpen(TRUE);*/
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 // This is the QT3 version bug there is a bug in "moc". It does not resolve the right class
00254 /*
00255 #if QT_VERSION>=300
00256 class YDateTimeWidget : public QDateTimeEdit, public YWidget
00257 {   Q_OBJECT
00258 public:                 YDateTimeWidget(YObject *object, QWidget *parent) : QDateEdit(parent), YWidget(object)
00259                         {   connect( object, SIGNAL(UpdateObject()), this, SLOT(UpdateWidget() ) );
00260                             connect( this, SIGNAL(valueChanged(const QDateTime &)), this, SLOT(UpdateDate(const QDate &) ) );
00261                         }
00262     virtual QWidget*    GetWidget()                             { return this;      }
00263     void                SetDateTime(const QDateTime &t)
00264                         {
00265                             setDate( QDate( t.date() ) );
00266                             setTime( QTime(t.time() ) );
00267                         }
00268 public slots:
00269     virtual void        UpdateWidget()                          { }
00270     virtual void        UpdateDate(const QDateTime &date)       { Q_UNUSED(date);   }
00271 };
00272 #else
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                             //setDate( QDate( t.date() ) );
00287                             //setTime( QTime(t.time() ) );
00288                         }
00289     QDateTime           GetDateTime()
00290                         {
00291                             return datetime;
00292                             //return addDays(0);
00293                         }
00294 public slots:
00295     virtual void        UpdateWidget()                          {                       }
00296     virtual void        UpdateDate(const QDateTime &date)       { Q_CONSTUNUSED(date);  }
00297 };
00298 //#endif
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

Generated on Thu Feb 13 23:43:57 2003 for Yasa by doxygen1.3-rc3