widgets.h

Go to the documentation of this file.
00001 //**************************************************************************/
00002 // Copyright (c) 2008 Autodesk, Inc.
00003 // All rights reserved.
00004 //
00005 // Use of this software is subject to the terms of the Autodesk license
00006 // agreement provided at the time of installation or download, or which
00007 // otherwise accompanies this software in either electronic or hard copy form.
00008 //
00009 //**************************************************************************/ 
00010 // DESCRIPTION:
00011 // CREATED: October 2008
00012 //**************************************************************************/
00013    
00014 #ifndef __MUDBOXSDK_WIDGETS_H__
00015 #define __MUDBOXSDK_WIDGETS_H__
00016 #pragma once
00017    
00018 // In order to create custom gui for your plugins, you need to install the Qt library. 
00019 // Classes in this file are valid only when Qt is properly installed
00020   
00021 #include <QtCore/QObject>
00022 #include <QtCore/QFileInfo>
00023 #include <QtCore/QMap>
00024 #include <QtCore/QSignalMapper>
00025 #include <QtGui/QWidget>
00026 #include <QtGui/QLabel>
00027 #include <QtGui/QLineEdit>
00028 #include <QtGui/QCheckBox>
00029 #include <QtGui/QPushButton>
00030 #include <QtGui/QSlider>
00031 #include <QtGui/QMouseEvent>
00032 #include <QtGui/QSpinBox>
00033 #include <QtGui/QComboBox>
00034 #include <QtGui/QGroupBox>
00035 #include <QtGui/QFrame>
00036 #include <QtGui/QToolButton>
00037 #include <QtGui/QHBoxLayout>
00038 #include <QtGui/QGridLayout>
00039 #include <QtGui/QButtonGroup>
00040 #include <QtGui/QTabBar>
00041 
00042 #if defined(JAMBUILD)
00043 #include <Mudbox/mudbox.h>
00044 #else
00045 #include "mudbox.h"
00046 #endif            
00047  
00048 namespace mudbox
00049 {
00050     class MBDLL_DECL AttributeSign : public QLabel
00051     {
00052         Q_OBJECT
00053         class AttributeWidget *m_pOwner;
00054         void mousePressEvent( QMouseEvent *pEvent );
00055         void dragEnterEvent( QDragEnterEvent *pEvent );
00056         void dropEvent( QDropEvent *pEvent );
00057         void SetImage( const QString &sFileName );
00058 
00059     public:
00060         AttributeSign( class AttributeWidget *pOwner );
00061         void UpdateImage( void );
00062     };
00063 
00064     class MBDLL_DECL AttributeWidget : public QWidget, public Node
00065     {
00066         Attribute *m_pAttribute;
00067         Node *m_pNode;
00068         int m_iNodeID;
00069         AttributeWatch m_cWatcher;
00070         QSize sizeHint( void ) const;
00071         bool m_bDestructed; // HACK
00072 
00073     protected:
00074         void OnNodeEvent( const Attribute &cAttribute, NodeEventType eType );
00075         QLabel m_cLabel;
00076         QHBoxLayout m_cMainLayout, *m_pValueLayout, *m_pValueStretchLayout;
00077         QWidget m_cValue;
00078         float m_fLabelWidth;
00079         int m_iHeight;
00080         bool m_bLeftAlignedName;
00081 
00082     public:
00083         AttributeWidget( QWidget *pParent, int iWidth, Attribute *pAttribute );
00084         ~AttributeWidget( void );
00085         bool Validate( void );
00086         virtual void Update( void ) {};
00087         virtual void MoveValue( int /*iStart*/, int /*iEnd*/ ) {};
00088         virtual void MoveContent( int iStart, int iEnd, bool bVisibleValue );
00089         virtual void ChangeWidth( int iWidth, bool bVisibleValue );
00090         inline Attribute *GetAttribute( void ) const { return m_pAttribute; };
00091         inline Node *GetNode( void ) const { return m_pNode; };
00092     };
00093 
00094     class MBDLL_DECL AttributeVectorbox : public AttributeWidget
00095     {
00096         Q_OBJECT
00097 
00098     protected:
00099         void Update( void );
00100         QLineEdit m_cXBox, m_cYBox, m_cZBox;
00101 
00102     public:
00103         AttributeVectorbox( QWidget *pParent, int iWidth, avector *pAttribute );
00104 
00105     public slots:
00106         void OnChange( void );
00107     };
00108 
00110     class MBDLL_DECL AttributeVector4box : public AttributeWidget
00111     {
00112         Q_OBJECT
00113 
00114     protected:
00115         void Update( void );
00116         QLineEdit m_cXBox, m_cYBox, m_cZBox, m_cWBox;
00117 
00118     public:
00119         AttributeVector4box( QWidget *pParent, int iWidth, avector4 *pAttribute );
00120 
00121         public slots:
00122             void OnChange( void );
00123     };
00124 
00125     class MBDLL_DECL AttributeEditbox : public AttributeWidget
00126     {
00127         Q_OBJECT
00128 
00129     protected:
00130         void Update( void );
00131         QLineEdit m_cEditbox;
00132         QLabel m_cValueLabel;
00133 
00134     public:
00135         AttributeEditbox( QWidget *pParent, int iWidth, Attribute *pAttribute );
00136 
00137     public slots:
00138         void OnChange( void );
00139     };
00140 
00142     class MBDLL_DECL AttributeImagebox : public AttributeWidget
00143     {
00144         Q_OBJECT
00145         void MoveValue( int iStart, int iEnd );
00146         void Update( void );
00147         void OnNodeEvent( const Attribute &cAttribute, NodeEventType eType );
00148 
00149         unsigned int m_iWidth;
00150 
00151     protected:
00152         QLabel m_cLabel;
00153 
00154     public:
00155         AttributeImagebox( QWidget *pParent, int iWidth, AttributePointer<Image> *pImage );
00156     };
00157 
00159     class MBDLL_DECL AttributeCheckbox : public AttributeWidget
00160     {
00161         Q_OBJECT
00162         bool m_bLock;
00163         void Update( void );
00164 
00165     protected:
00166         QCheckBox m_cCheckbox;
00167 
00168     public:
00169         AttributeCheckbox( QWidget *pParent, int iWidth, abool *pAttribute );
00170 
00171     public slots:
00172         void OnChange( int iState );
00173     };
00174 
00175     class MBDLL_DECL AttributeColorbox : public AttributeWidget
00176     {
00177         Q_OBJECT
00178 
00179     protected:
00180         void Update( void );
00181 
00182     public:
00183         AttributeColorbox( QWidget *pParent, int iWidth, acolor *pAttribute );
00184 
00185     public slots:
00186         void OnAboutToShowChooser(QColor* color);
00187         void OnColorChanged(const QColor&);
00188 
00189     public:
00190         static QWidget* CreateColorButton(const QColor& color, QWidget* parent, Attribute *pAttribute);
00191     };
00192 
00194     class MBDLL_DECL AttributeSliderbox : public AttributeEditbox
00195     {
00196         class Slider : public QSlider
00197         {
00198             void mouseDoubleClickEvent( QMouseEvent *pEvent )
00199             {
00200                 if ( m_pOwner )
00201                 {
00202                     afloatr* pA = (afloatr *)m_pOwner->GetAttribute();
00203                     if ( pEvent->button() == Qt::LeftButton )
00204                         pA->SetMax( pA->Value() );
00205                     if ( pEvent->button() == Qt::RightButton )
00206                         pA->SetMin( pA->Value() );
00207                     setValue( (int)(1000*(pA->Value()-pA->Min())/(pA->Max()-pA->Min())) );
00208                 };
00209             };
00210         public:
00211             Slider( QWidget *pParent ) : QSlider( pParent ) { m_pOwner = 0; };
00212             AttributeSliderbox *m_pOwner;
00213         };
00214         Q_OBJECT
00215         bool m_bLock, m_bSliderLock;
00216 
00217     protected:
00218         void Update( void );
00219         Slider m_cSlider;
00220 
00221     public:
00222         AttributeSliderbox( QWidget *pParent, int iWidth, afloatr *pAttribute );
00223 
00224     public slots:
00225         void OnMove( int );
00226     };
00227 
00228     class MBDLL_DECL AttributeSpinbox : public AttributeWidget
00229     {
00230         struct SpinBox : public QSpinBox
00231         {
00232             SpinBox( QWidget *pParent, int iDigitCount ) : QSpinBox( pParent )
00233             {
00234                 m_iDigitCount = iDigitCount;
00235             };
00236         private:
00237             QString textFromValue ( int v ) const
00238             {
00239                 QString s = QString::number( v );
00240                 while ( s.length() < m_iDigitCount )
00241                     s = "0"+s;
00242                 return s;
00243             };
00244             int m_iDigitCount;
00245         };
00246         Q_OBJECT
00247 
00248     protected:
00249         SpinBox m_cSpin;
00250         bool m_bLock;
00251         void Update( void );
00252 
00253     public:
00254         AttributeSpinbox( QWidget *pParent, int iWidth, aint *pAttribute, int iSpinWidth = 40, int iDigitCount = 1 );
00255 
00256     public slots:
00257         void OnChange( int );
00258     };
00259 
00261     class MBDLL_DECL AttributeCombobox : public AttributeWidget
00262     {
00263         Q_OBJECT
00264         bool m_bLock;
00265 
00266     protected:
00267         void Update( void );
00268         QComboBox m_cCombo;
00269         QTabBar *m_cTabBar;
00270         QWidget *m_pButtonFrame;
00271 
00272     public:
00273         AttributeCombobox( QWidget *pParent, int iWidth, aenum *pAttribute );
00274 
00275     public slots:
00276         void OnActivate( int ); 
00277     };
00278 
00279     class MBDLL_DECL AttributeComboboxMap : public AttributeWidget
00280     {
00281         Q_OBJECT
00282 
00283     protected:
00284         QComboBox m_cCombo;
00285 
00286     public:
00287         AttributeComboboxMap( QWidget* pParent, int iWidth, astring* pAttribute, const QMap<QString, QString>& pMap );
00288 
00289     protected:
00290         void Update(const QMap<QString, QString>&);
00291         static void Update(QComboBox* cComboBox, const QMap<QString, QString>& pMap, const QString& sSelected);
00292 
00293     public slots:
00294         void OnActivate( int );
00295     };
00296 
00298     class MBDLL_DECL AttributeFilenamebox : public AttributeEditbox
00299     {
00300         Q_OBJECT
00301 
00302     protected:
00303         QPushButton m_cBrowseButton;
00304 
00305     public:
00306         AttributeFilenamebox( QWidget *pParent, int iWidth, afilename *pAttribute );
00307 
00308     public slots:
00309         void OnBrowse( void );
00310     };
00311 
00313     class MBDLL_DECL AttributeTextureFilenamebox : public AttributeFilenamebox
00314     {
00315         Q_OBJECT
00316 
00317     public:
00318         AttributeTextureFilenamebox( QWidget *pParent, int iWidth, afilename *pAttribute );
00319 
00320     public slots:
00321         void OnMenu( void );
00322         void OnSave( void );
00323     };
00324 
00325     class MBDLL_DECL AttributeEventbox : public AttributeWidget
00326     {
00327         Q_OBJECT
00328 
00329     protected:
00330         QPushButton m_cButton;
00331 
00332     public:
00333         AttributeEventbox( QWidget *pParent, int iWidth, EventGate *pAttribute );
00334 
00335     public slots:
00336         void OnAction( void );
00337     };
00338 
00340     class MBDLL_DECL AttributePointerbox : public AttributeWidget
00341     {
00342         Q_OBJECT
00343         bool m_bLock;
00344         bool m_bNullStringInserted;
00345 
00346     protected: QComboBox m_cCombo; const ClassDesc *m_pType; void Update( void );
00347     public: AttributePointerbox( QWidget *pParent, int iWidth, Attribute *pAttribute, const ClassDesc *pClass );
00348     public slots: void OnChange( int );
00349     };
00350 
00352     class MBDLL_DECL AttributeCheckboxCollection : public AttributeWidget
00353     {
00354         Q_OBJECT
00355         QCheckBox *m_aCheckboxes[32];
00356         QWidget m_cValues;
00357         void Update( void );
00358 
00359     public:
00360         AttributeCheckboxCollection( QWidget *pParent, int iWidth, aboolc *pAttribute );
00361 
00362     public slots:
00363         void OnChange( int iState );
00364     };
00365 
00367     class MBDLL_DECL AttributeSliderWithCheckbox : public AttributeWidget
00368     {
00369         Q_OBJECT
00370         bool m_bLock;
00371         void Update( void );
00372 
00373     protected:
00374         QLabel *m_pLabel;
00375         QSlider *m_pSlider;
00376         QLineEdit *m_pEditBox;
00377         QGroupBox m_cGroupBox;
00378 
00379     public:
00380         AttributeSliderWithCheckbox( QWidget *pParent, int iWidth, acheckablefloat *pAttribute );
00381 
00382     public slots:
00383         void OnChange( void );
00384     };
00385 
00387     class MBDLL_DECL AttributeSliderArrayWithCheckbox : public AttributeWidget
00388     {
00389         Q_OBJECT
00390         bool m_bLock;
00391         void Update( void );
00392 
00393     protected:
00394         QVector<QLabel *> m_aLabel;
00395         QVector<QLineEdit *> m_aEditBox;
00396         QVector<QSlider *> m_aSlider;
00397         QGroupBox m_cGroupBox;
00398 
00399     public:
00400         AttributeSliderArrayWithCheckbox( QWidget *pParent, int iWidth, AttributeCheckableFloatArray *pAttribute );
00401 
00402     public slots:
00403         void OnChange( void );
00404     };
00405 
00406     class MBDLL_DECL CPBox : public QWidget
00407     {
00408         Q_OBJECT
00409     public:
00410         CPBox( int iIndex, QWidget *pParent = 0, const char *sName = 0 );
00411         bool m_bSelected;
00412         int m_iIndex;
00413 
00414     protected:
00415         void contextMenuEvent( QContextMenuEvent *pEvent );
00416         void mousePressEvent( QMouseEvent *pEvent );
00417         QSize sizeHint( void ) const;
00418         void paintEvent( QPaintEvent *pEvent );
00419     };
00420 
00421     class MBDLL_DECL CurveEditor : public QFrame
00422     {
00423         Q_OBJECT
00424     public:
00425         CurveEditor( QWidget *pParent = 0, const char *sName = 0, bool bNurbs = false );
00426         void SelectCP( CPBox *pCP );
00427         void DeleteCP( void );
00428         void AddCP( float x, float y );
00429         void Init( void *pCurve = 0 );
00430         int m_iSnapDistance;
00431         static bool s_bSnap;
00432         bool m_bReadOnly, m_bNurbs;
00433         float m_fGridSizeX, m_fGridSizeY;
00434         void *m_pCurve;
00435 
00436 signals:
00437         void nurbsValueChanged();
00438 
00439     protected:
00440         QSize sizeHint( void ) const;
00441         void paintEvent( QPaintEvent *pe );
00442         void resizeEvent( QResizeEvent *pEvent );
00443         void mousePressEvent( QMouseEvent *pEvent );
00444         void mouseReleaseEvent( QMouseEvent *pEvent );
00445         void mouseMoveEvent( QMouseEvent *pEvent );
00446         void contextMenuEvent( QContextMenuEvent *pEvent );
00447         void NurbsValueChanged();
00448         int CanvasToScreenX( float f );
00449         int CanvasToScreenY( float f );
00450         float ScreenToCanvasX( int i );
00451         float ScreenToCanvasY( int i );
00452         int m_iCanvasWidth, m_iCanvasHeight;
00453         CPBox *m_aBoxes[16];
00454         CPBox *m_pSelectedBox;
00455         class Vector m_vDragDistance;
00456     };
00457 
00458     class MBDLL_DECL AttributeCurveEditor : public AttributeWidget
00459     {
00460         Q_OBJECT
00461 
00462     protected:
00463         QPushButton *m_pStoreF;
00464         CurveEditor *m_pCurveEditor;
00465         bool eventFilter( QObject *pTarget, QEvent *pEvent );
00466 
00467     public:
00468         AttributeCurveEditor( QWidget *pParent, int iWidth, acurveptr *pAttribute, bool );
00469 
00470     public slots:
00471         void OnChange( void );
00472         void Update( void );
00473     };
00474 
00475     class MBDLL_DECL AttributeStampConfigurationWidget : public AttributeWidget
00476     {
00477         Q_OBJECT
00478 
00479     protected:
00480         void UpdateImage( void );
00481         bool LoadImage(const QString &imgFileName);
00482 
00483         QImage        m_CachedImage;
00484         QString       m_CachedImageFileName;
00485 
00486         QGroupBox     m_cGroupBox;
00487         QLabel       *m_pPreviewImage;
00488         QGroupBox    *m_pRandomize;
00489         QToolButton  *m_pOrientToStroke; 
00490         QToolButton  *m_pRotateStamp; 
00491         QToolButton  *m_pFlipXStamp; 
00492         QToolButton  *m_pFlipYStamp;
00493         QSlider      *m_pRotateRandomize; 
00494         QSlider      *m_pPositionXRandomize; 
00495         QSlider      *m_pPositionYRandomize; 
00496         QSlider      *m_pScaleRandomize; 
00497         QSlider      *m_pStrengthRandomize;
00498         QCheckBox    *m_pFlipRandomize;
00499         QCheckBox    *m_pFlopRandomize;
00500         bool          m_bUpdating;
00501 
00502     public:
00503         AttributeStampConfigurationWidget( QWidget *pParent, int iWidth, astampcfg *pAttribute );
00504 
00505     public slots:
00506         void Update( void );
00507         void OnChange( void );
00508         void OnRotate( void );
00509     };
00510     
00511     
00516     class MirrorComboBox : public QComboBox
00517     {
00518         Q_OBJECT
00519     public:
00521         MirrorComboBox(QWidget * parent = 0, const char * name = 0)
00522         :QComboBox(parent){ setObjectName(name); }
00523         
00525         ~MirrorComboBox(){}
00526         
00527     signals:
00530         void departed(int);
00531         
00532     protected:
00534         void focusOutEvent ( QFocusEvent * )
00535         {
00536             emit departed(0);
00537         }
00538     };
00539     
00540 
00542     class MBDLL_DECL AttributeMirrorConfigurationWidget : public AttributeWidget
00543     {
00544         Q_OBJECT
00545     public:
00547         AttributeMirrorConfigurationWidget( QWidget *pParent, int iWidth, amirrorcfg *pAttribute );
00548 
00549     protected:
00551         bool m_bLock;
00553         void Update( void );
00555         MirrorComboBox m_cCombo;
00556     public slots:
00558         void OnChange( int );   
00561         void ShowMirrorAxis( int );
00562     };
00563 
00565     class MBDLL_DECL HelpButton : public QPushButton
00566     {
00567         Q_OBJECT
00568     public:
00570         HelpButton( QWidget* parent, const QString & sID, const QString & sText = tr("Help...") );
00572         void SetHelpID( const QString & sID );
00574         QString HelpID( void ) { return m_sID; };
00575 
00576     protected:
00578         QString m_sID;
00580         static QSignalMapper *s_pSignalMapper;
00581 
00582     };
00583 };
00584 
00585 #endif