- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# 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 #include <QtGui/QDialog>
    00042 #include <QtCore/QTimer>
    00043
    00044 #if defined(JAMBUILD)
    00045 #include <Mudbox/mudbox.h>
    00046 #else
    00047 #include "mudbox.h"
    00048 #endif
    00049
    00050 #define CPBOX_WIDTH 6
    00051 // max # of curve points. Matches the limit in the Curve class defined in Maths.h which may be used as an alternate to NURBS
    00052 // curve sometimes.
    00053 #define MAX_CURVE_POINTS 64
    00054
    00055
    00056 namespace mudbox
    00057 {
    00058     class MBDLL_DECL AttributeSign : public QLabel
    00059     {
    00060         Q_OBJECT
    00061         class AttributeWidget *m_pOwner;
    00062         void mousePressEvent( QMouseEvent *pEvent );
    00063         void dragEnterEvent( QDragEnterEvent *pEvent );
    00064         void dropEvent( QDropEvent *pEvent );
    00065         void SetImage( const QString &sFileName );
    00066
    00067     public:
    00068         AttributeSign( class AttributeWidget *pOwner );
    00069         void UpdateImage( void );
    00070     };
    00071
    00072     class MBDLL_DECL AttributeWidget : public QWidget, public Node
    00073     {
    00074         Attribute *m_pAttribute;
    00075         Node *m_pNode;
    00076         int m_iNodeID;
    00077         AttributeWatch m_cWatcher;
    00078         QSize sizeHint( void ) const;
    00079         bool m_bDestructed; // HACK
    00080
    00081     protected:
    00082         void OnNodeEvent( const Attribute &cAttribute, NodeEventType eType );
    00083         QLabel m_cLabel;
    00084         QHBoxLayout m_cMainLayout, *m_pValueLayout, *m_pValueStretchLayout;
    00085         QWidget m_cValue;
    00086         float m_fLabelWidth;
    00087         int m_iHeight;
    00088         bool m_bLeftAlignedName;
    00089
    00090     public:
    00091         AttributeWidget( QWidget *pParent, int iWidth, Attribute *pAttribute );
    00092         ~AttributeWidget( void );
    00093         bool Validate( void );
    00094         virtual void Update( void ) {};
    00095         virtual void MoveValue( int /*iStart*/, int /*iEnd*/ ) {};
    00096         virtual void MoveContent( int iStart, int iEnd, bool bVisibleValue );
    00097         virtual void ChangeWidth( int iWidth, bool bVisibleValue );
    00098         inline Attribute *GetAttribute( void ) const { return m_pAttribute; };
    00099         inline Node *GetNode( void ) const { return m_pNode; };
    00100     };
    00101
    00102     class MBDLL_DECL AttributeVectorbox : public AttributeWidget
    00103     {
    00104         Q_OBJECT
    00105
    00106     protected:
    00107         void Update( void );
    00108         QLineEdit m_cXBox, m_cYBox, m_cZBox;
    00109
    00110     public:
    00111         AttributeVectorbox( QWidget *pParent, int iWidth, avector *pAttribute );
    00112
    00113     public slots:
    00114         void OnChange( void );
    00115     };
    00116
    00118     class MBDLL_DECL AttributeVector4box : public AttributeWidget
    00119     {
    00120         Q_OBJECT
    00121
    00122     protected:
    00123         void Update( void );
    00124         QLineEdit m_cXBox, m_cYBox, m_cZBox, m_cWBox;
    00125
    00126     public:
    00127         AttributeVector4box( QWidget *pParent, int iWidth, avector4 *pAttribute );
    00128
    00129         public slots:
    00130             void OnChange( void );
    00131     };
    00132
    00133     class MBDLL_DECL AttributeEditbox : public AttributeWidget
    00134     {
    00135         Q_OBJECT
    00136
    00137     protected:
    00138         void Update( void );
    00139         QLineEdit m_cEditbox;
    00140         QLabel m_cValueLabel;
    00141
    00142     public:
    00143         AttributeEditbox( QWidget *pParent, int iWidth, Attribute *pAttribute );
    00144
    00145     public slots:
    00146         void OnChange( void );
    00147         void OnEditFinished( void );
    00148     };
    00149
    00151     class MBDLL_DECL AttributeImagebox : public AttributeWidget
    00152     {
    00153         Q_OBJECT
    00154         void MoveValue( int iStart, int iEnd );
    00155         void Update( void );
    00156         void OnNodeEvent( const Attribute &cAttribute, NodeEventType eType );
    00157
    00158         unsigned int m_iWidth;
    00159
    00160     protected:
    00161         QLabel m_cLabel;
    00162
    00163     public:
    00164         AttributeImagebox( QWidget *pParent, int iWidth, AttributePointer<Image> *pImage );
    00165     };
    00166
    00168     class MBDLL_DECL AttributeCheckbox : public AttributeWidget
    00169     {
    00170         Q_OBJECT
    00171         bool m_bLock;
    00172         void Update( void );
    00173
    00174     protected:
    00175         QCheckBox m_cCheckbox;
    00176
    00177     public:
    00178         AttributeCheckbox( QWidget *pParent, int iWidth, abool *pAttribute );
    00179
    00180     public slots:
    00181         void OnChange( int iState );
    00182     };
    00183
    00184     class MBDLL_DECL AttributeColorbox : public AttributeWidget
    00185     {
    00186         Q_OBJECT
    00187
    00188     protected:
    00189         void Update( void );
    00190
    00191     public:
    00192         AttributeColorbox( QWidget *pParent, int iWidth, acolor *pAttribute );
    00193
    00194     public slots:
    00195         void OnAboutToShowChooser(QColor* color);
    00196         void OnColorChanged(const QColor&);
    00197
    00198     public:
    00199         static QWidget* CreateColorButton(const QColor& color, QWidget* parent, Attribute *pAttribute);
    00200     };
    00201
    00203     class MBDLL_DECL AttributeSliderbox : public AttributeEditbox
    00204     {
    00205         class Slider : public QSlider
    00206         {
    00207             void mouseDoubleClickEvent( QMouseEvent *pEvent )
    00208             {
    00209                 if ( m_pOwner )
    00210                 {
    00211                     afloatr* pA = (afloatr *)m_pOwner->GetAttribute();
    00212                     if ( pEvent->button() == Qt::LeftButton )
    00213                         pA->SetMax( pA->Value() );
    00214                     if ( pEvent->button() == Qt::RightButton )
    00215                         pA->SetMin( pA->Value() );
    00216                     setValue( (int)(1000*(pA->Value()-pA->Min())/(pA->Max()-pA->Min())) );
    00217                 };
    00218             };
    00219         public:
    00220             Slider( QWidget *pParent ) : QSlider( pParent ) { m_pOwner = 0; };
    00221             AttributeSliderbox *m_pOwner;
    00222         };
    00223         Q_OBJECT
    00224         bool m_bLock, m_bSliderLock;
    00225
    00226     protected:
    00227         void Update( void );
    00228         Slider m_cSlider;
    00229
    00230     public:
    00231         AttributeSliderbox( QWidget *pParent, int iWidth, afloatr *pAttribute );
    00232
    00233     public slots:
    00234         void OnMove( int );
    00235     };
    00236
    00237     class MBDLL_DECL AttributeSpinbox : public AttributeWidget
    00238     {
    00239         struct SpinBox : public QSpinBox
    00240         {
    00241             SpinBox( QWidget *pParent, int iDigitCount ) : QSpinBox( pParent )
    00242             {
    00243                 m_iDigitCount = iDigitCount;
    00244             };
    00245         private:
    00246             QString textFromValue ( int v ) const
    00247             {
    00248                 QString s = QString::number( v );
    00249                 while ( s.length() < m_iDigitCount )
    00250                     s = "0"+s;
    00251                 return s;
    00252             };
    00253             int m_iDigitCount;
    00254         };
    00255         Q_OBJECT
    00256
    00257     protected:
    00258         SpinBox m_cSpin;
    00259         bool m_bLock;
    00260         void Update( void );
    00261
    00262     public:
    00263         AttributeSpinbox( QWidget *pParent, int iWidth, aint *pAttribute, int iSpinWidth = 40, int iDigitCount = 1 );
    00264
    00265     public slots:
    00266         void OnChange( int );
    00267     };
    00268
    00270     class MBDLL_DECL AttributeCombobox : public AttributeWidget
    00271     {
    00272         Q_OBJECT
    00273         bool m_bLock;
    00274
    00275     protected:
    00276         void Update( void );
    00277         QComboBox m_cCombo;
    00278         QTabBar *m_cTabBar;
    00279         QWidget *m_pButtonFrame;
    00280
    00281     public:
    00282         AttributeCombobox( QWidget *pParent, int iWidth, aenum *pAttribute );
    00283
    00284     public slots:
    00285         void OnActivate( int );
    00286     };
    00287
    00288     class MBDLL_DECL AttributeComboboxMap : public AttributeWidget
    00289     {
    00290         Q_OBJECT
    00291
    00292     protected:
    00293         QComboBox m_cCombo;
    00294
    00295     public:
    00296         AttributeComboboxMap( QWidget* pParent, int iWidth, astring* pAttribute, const QMap<QString, QString>& pMap );
    00297
    00298     protected:
    00299         void Update(const QMap<QString, QString>&);
    00300         static void Update(QComboBox* cComboBox, const QMap<QString, QString>& pMap, const QString& sSelected);
    00301
    00302     public slots:
    00303         void OnActivate( int );
    00304     };
    00305
    00307     class MBDLL_DECL AttributeFilenamebox : public AttributeEditbox
    00308     {
    00309         Q_OBJECT
    00310
    00311     protected:
    00312         QPushButton m_cBrowseButton;
    00313
    00314     public:
    00315         AttributeFilenamebox( QWidget *pParent, int iWidth, afilename *pAttribute );
    00316
    00317     public slots:
    00318         void OnBrowse( void );
    00319         void OnEdit( void );
    00320     };
    00321
    00323     class MBDLL_DECL AttributeTextureFilenamebox : public AttributeFilenamebox
    00324     {
    00325         Q_OBJECT
    00326
    00327     public:
    00328         AttributeTextureFilenamebox( QWidget *pParent, int iWidth, afilename *pAttribute );
    00329
    00330     public slots:
    00331         void OnMenu( void );
    00332         void OnSave( void );
    00333     };
    00334
    00335     class MBDLL_DECL AttributeEventbox : public AttributeWidget
    00336     {
    00337         Q_OBJECT
    00338
    00339     protected:
    00340         QPushButton m_cButton;
    00341
    00342     public:
    00343         AttributeEventbox( QWidget *pParent, int iWidth, EventGate *pAttribute );
    00344
    00345     public slots:
    00346         void OnAction( void );
    00347     };
    00348
    00350     class MBDLL_DECL AttributePointerbox : public AttributeWidget
    00351     {
    00352         Q_OBJECT
    00353         bool m_bLock;
    00354         bool m_bNullStringInserted;
    00355
    00356     protected: QComboBox m_cCombo; const ClassDesc *m_pType; void Update( void );
    00357     public: AttributePointerbox( QWidget *pParent, int iWidth, Attribute *pAttribute, const ClassDesc *pClass );
    00358     public slots: void OnChange( int );
    00359     };
    00360
    00362     class MBDLL_DECL AttributeCheckboxCollection : public AttributeWidget
    00363     {
    00364         Q_OBJECT
    00365         QCheckBox *m_aCheckboxes[32];
    00366         QWidget m_cValues;
    00367         void Update( void );
    00368
    00369     public:
    00370         AttributeCheckboxCollection( QWidget *pParent, int iWidth, aboolc *pAttribute );
    00371
    00372     public slots:
    00373         void OnChange( int iState );
    00374     };
    00375
    00377     class MBDLL_DECL AttributeSliderWithCheckbox : public AttributeWidget
    00378     {
    00379         Q_OBJECT
    00380         bool m_bLock;
    00381         void Update( void );
    00382
    00383     protected:
    00384         QLabel *m_pLabel;
    00385         QSlider *m_pSlider;
    00386         QLineEdit *m_pEditBox;
    00387         QGroupBox m_cGroupBox;
    00388
    00389     public:
    00390         AttributeSliderWithCheckbox( QWidget *pParent, int iWidth, acheckablefloat *pAttribute );
    00391
    00392     public slots:
    00393         void OnChange( void );
    00394     };
    00395
    00397     class MBDLL_DECL AttributeSliderArrayWithCheckbox : public AttributeWidget
    00398     {
    00399         Q_OBJECT
    00400         bool m_bLock;
    00401         void Update( void );
    00402
    00403     protected:
    00404         QVector<QLabel *> m_aLabel;
    00405         QVector<QLineEdit *> m_aEditBox;
    00406         QVector<QSlider *> m_aSlider;
    00407         QGroupBox m_cGroupBox;
    00408
    00409     public:
    00410         AttributeSliderArrayWithCheckbox( QWidget *pParent, int iWidth, AttributeCheckableFloatArray *pAttribute );
    00411
    00412     public slots:
    00413         void OnChange( void );
    00414     };
    00415
    00416     class MBDLL_DECL CPBox : public QWidget
    00417     {
    00418         Q_OBJECT
    00419     public:
    00420         CPBox( int iIndex, QWidget *pParent = 0, const char *sName = 0 );
    00421         bool m_bSelected;
    00422         int m_iIndex;
    00423
    00424     protected:
    00425         void mousePressEvent( QMouseEvent *pEvent );
    00426         QSize sizeHint( void ) const;
    00427         void paintEvent( QPaintEvent *pEvent );
    00428     };
    00429
    00430     class MBDLL_DECL CurveEditor : public QFrame
    00431     {
    00432         Q_OBJECT
    00433     public:
    00434         CurveEditor( QWidget *pParent = 0, const char *sName = 0, bool bNurbs = false );
    00435         void SelectCP( CPBox *pCP );
    00436         void DeleteCP( void );
    00437         void AddCP( float x, float y );
    00438         void Init( void *pCurve = 0 );
    00439         void SetFixedSize(int w, int h);
    00440         void MakeReadOnly();
    00441         void NurbsValueChanged();
    00442         void ApplyCurve();
    00443
    00444         bool m_bSnap, m_bNurbs;
    00445         int m_iDeleteHandleSize;
    00446         void *m_pCurve;
    00447
    00448     signals:
    00449         void nurbsValueChanged();
    00450         void CurveReadyToBeApplied();
    00451
    00452     protected:
    00453         QSize sizeHint( void ) const;
    00454         void paintEvent( QPaintEvent *pe );
    00455         void resizeEvent( QResizeEvent *pEvent );
    00456         void mousePressEvent( QMouseEvent *pEvent );
    00457         void mouseReleaseEvent( QMouseEvent *pEvent );
    00458         void mouseMoveEvent( QMouseEvent *pEvent );
    00459         void keyPressEvent( QKeyEvent *pEvent );
    00460         void keyReleaseEvent ( QKeyEvent *pEvent );
    00461         int CanvasToScreenX( float f );
    00462         int CanvasToScreenY( float f );
    00463         float ScreenToCanvasX( int i );
    00464         float ScreenToCanvasY( int i );
    00465         int m_iCanvasWidth, m_iCanvasHeight;
    00466         CPBox *m_aBoxes[MAX_CURVE_POINTS];
    00467         CPBox *m_pSelectedBox;
    00468         QPoint m_aDeleteCoordinates[MAX_CURVE_POINTS];
    00469
    00470     private:
    00471         void ComputeDeleteCoordinates();
    00472         bool IsPointNear(const QPoint& pos);
    00473         int IndexOfClosestPoint(const QPoint& post);
    00474
    00475         bool m_bIsDragging, m_bReadOnly, m_bIsPointAddable, m_bIsPointDeletable;
    00476         int m_iSnapDistance, m_iNumBoxes, m_iDeleteIndex;
    00477         float m_fGridSizeX, m_fGridSizeY, m_fStep;
    00478         QCursor m_addCursor, m_deleteCursor;
    00479         QRect m_CurveDisplayBoundary, m_DeleteDisplayBoundary;
    00480     };
    00481
    00491     class MBDLL_DECL AttributeCurveEditor : public AttributeWidget
    00492     {
    00493         Q_OBJECT
    00494
    00495     protected:
    00496         QPushButton *m_pStoreF;
    00497         CurveEditor *m_pCurveEditor;
    00498         bool eventFilter( QObject *pTarget, QEvent *pEvent );
    00499
    00500     public:
    00502         AttributeCurveEditor(
    00503                             QWidget *pParent,
    00504                             int iWidth,
    00505                             acurveptr *pAttribute,
    00506                             bool bSnapAndStore,
    00507                             bool bInAdjustColor = false
    00508                             );
    00509
    00511         bool EditorInAdjustColor() const { return m_bUsedInAdjustColor; };
    00512
    00521         void ReplaceNurbsInEditor(NURBSCurve *pCurve) { m_pCurveEditor->Init(pCurve); };
    00522
    00523     public slots:
    00525         void OnChange( void );
    00526
    00528         void Update( void );
    00529
    00531         void OnEnlarge(void);
    00532
    00534         void StartUpdateCountdown(void);
    00535
    00539         void OnColorCorrectionClosing(void);
    00540
    00541     signals:
    00543         void ParentEditorInColorCorrectionClosing(void);
    00544
    00545     private:
    00546         QTimer m_updateTimer;
    00547         bool m_bIsUpdatingTargets, m_bUsedInAdjustColor;
    00548     };
    00549
    00552     class MBDLL_DECL EnlargedCurveEditor : public QDialog
    00553     {
    00554         Q_OBJECT
    00555     public:
    00557         EnlargedCurveEditor(
    00558             AttributeCurveEditor *pCurve
    00559             );
    00560
    00561     signals:
    00566         void CurveSelected( int iIndex );
    00567
    00568     protected:
    00570         void resizeEvent( QResizeEvent *pEvent );
    00571
    00574         void changeEvent ( QEvent *pEvent );
    00575
    00576     private:
    00577         CurveEditor *m_pCurveEditorFrame;
    00578         AttributeCurveEditor *m_pAttributeCurve;
    00579         // if the AttributeCurveEditor contained in this dialog belongs to a curve from Adjust Color Dialog, this is the index of
    00580         // the item in the combo box for the curve selection. -1 otherwise.
    00581         int m_iIndexOfCurve;
    00582     };
    00583
    00584     class MBDLL_DECL AttributeStampConfigurationWidget : public AttributeWidget
    00585     {
    00586         Q_OBJECT
    00587
    00588     protected:
    00589         void UpdateImage( void );
    00590         bool LoadImage(const QString &imgFileName);
    00591
    00592         QImage        m_CachedImage;
    00593         QString       m_CachedImageFileName;
    00594
    00595         QGroupBox     m_cGroupBox;
    00596         QLabel       *m_pPreviewImage;
    00597         QGroupBox    *m_pRandomize;
    00598         QToolButton  *m_pOrientToStroke;
    00599         QToolButton  *m_pRotateStamp;
    00600         QToolButton  *m_pFlipXStamp;
    00601         QToolButton  *m_pFlipYStamp;
    00602         QSlider      *m_pRotateRandomize;
    00603         QSlider      *m_pPositionXRandomize;
    00604         QSlider      *m_pPositionYRandomize;
    00605         QSlider      *m_pScaleRandomize;
    00606         QSlider      *m_pStrengthRandomize;
    00607         QCheckBox    *m_pFlipRandomize;
    00608         QCheckBox    *m_pFlopRandomize;
    00609         bool          m_bUpdating;
    00610
    00611     public:
    00612         AttributeStampConfigurationWidget( QWidget *pParent, int iWidth, astampcfg *pAttribute );
    00613
    00614     public slots:
    00615         void Update( void );
    00616         void OnChange( void );
    00617         void OnRotate( void );
    00618     };
    00619
    00620
    00625     class MirrorComboBox : public QComboBox
    00626     {
    00627         Q_OBJECT
    00628     public:
    00630         MirrorComboBox(QWidget * parent = 0, const char * name = 0)
    00631         :QComboBox(parent){ setObjectName(name); }
    00632
    00634         ~MirrorComboBox(){}
    00635
    00636     signals:
    00639         void departed(int);
    00640
    00641     protected:
    00643         void focusOutEvent ( QFocusEvent * )
    00644         {
    00645             emit departed(0);
    00646         }
    00647     };
    00648
    00649
    00651     class MBDLL_DECL AttributeMirrorConfigurationWidget : public AttributeWidget
    00652     {
    00653         Q_OBJECT
    00654     public:
    00656         AttributeMirrorConfigurationWidget( QWidget *pParent, int iWidth, amirrorcfg *pAttribute );
    00657
    00658     protected:
    00660         bool m_bLock;
    00662         void Update( void );
    00664         MirrorComboBox m_cCombo;
    00665     public slots:
    00667         void OnChange( int );
    00670         void ShowMirrorAxis( int );
    00671     };
    00672
    00674     class MBDLL_DECL HelpButton : public QPushButton
    00675     {
    00676         Q_OBJECT
    00677     public:
    00679         HelpButton( QWidget* parent, const QString & sID, const QString & sText = tr("Help...") );
    00681         void SetHelpID( const QString & sID );
    00683         QString HelpID( void ) { return m_sID; };
    00684
    00685     protected:
    00687         QString m_sID;
    00689         static QSignalMapper *s_pSignalMapper;
    00690
    00691     };
    00692 };
    00693
    00694 #endif