Mudbox/widgets.h Source File

widgets.h
Go to the documentation of this file.
1 //**************************************************************************/
2 // Copyright (c) 2008 Autodesk, Inc.
3 // All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Autodesk license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 //
9 //**************************************************************************/
10 // DESCRIPTION:
11 // CREATED: October 2008
12 //**************************************************************************/
13 
14 #ifndef __MUDBOXSDK_WIDGETS_H__
15 #define __MUDBOXSDK_WIDGETS_H__
16 #pragma once
17 
18 // In order to create custom gui for your plugins, you need to install the Qt library.
19 // Classes in this file are valid only when Qt is properly installed
20 
21 #include <QtCore/QObject>
22 #include <QtCore/QFileInfo>
23 #include <QtCore/QMap>
24 #include <QtCore/QSignalMapper>
25 #include <QtGui/QWidget>
26 #include <QtGui/QLabel>
27 #include <QtGui/QLineEdit>
28 #include <QtGui/QCheckBox>
29 #include <QtGui/QPushButton>
30 #include <QtGui/QSlider>
31 #include <QtGui/QMouseEvent>
32 #include <QtGui/QSpinBox>
33 #include <QtGui/QComboBox>
34 #include <QtGui/QGroupBox>
35 #include <QtGui/QFrame>
36 #include <QtGui/QToolButton>
37 #include <QtGui/QHBoxLayout>
38 #include <QtGui/QGridLayout>
39 #include <QtGui/QButtonGroup>
40 #include <QtGui/QTabBar>
41 #include <QtGui/QDialog>
42 #include <QtCore/QTimer>
43 
44 #if defined(JAMBUILD)
45 #include <Mudbox/mudbox.h>
46 #else
47 #include "mudbox.h"
48 #endif
49 
50 #define CPBOX_WIDTH 6
51 // max # of curve points. Matches the limit in the Curve class defined in Maths.h which may be used as an alternate to NURBS
52 // curve sometimes.
53 #define MAX_CURVE_POINTS 64
54 
55 
56 namespace mudbox
57 {
63  {
64  Q_OBJECT
65  public:
67  MirrorComboBox(QWidget * parent = 0, const char * name = 0)
68  :QComboBox(parent){ setObjectName(name); }
69 
72 
73  signals:
76  void departed(int);
77 
78  // This signal is emitted when the popup list is closed.
80  void popupClosed(int);
81 
82  protected:
85  {
86  emit departed(0);
87  }
88 
89  void hidePopup()
90  {
91  emit popupClosed(0);
93  };
94  };
95 
96 
98  {
99  Q_OBJECT
100  class AttributeWidget *m_pOwner;
101  void mousePressEvent( QMouseEvent *pEvent );
102  void dragEnterEvent( QDragEnterEvent *pEvent );
103  void dropEvent( QDropEvent *pEvent );
104  void SetImage( const QString &sFileName );
105 
106  public:
107  AttributeSign( class AttributeWidget *pOwner );
108  void UpdateImage( void );
109  };
110 
111  class MBDLL_DECL AttributeWidget : public QWidget, public Node
112  {
113  Attribute *m_pAttribute;
114  Node *m_pNode;
115  int m_iNodeID;
116  AttributeWatch m_cWatcher;
117  QSize sizeHint( void ) const;
118  bool m_bDestructed; // HACK
119 
120  protected:
121  void OnNodeEvent( const Attribute &cAttribute, NodeEventType eType );
123  QHBoxLayout m_cMainLayout, *m_pValueLayout, *m_pValueStretchLayout;
128 
129  public:
130  AttributeWidget( QWidget *pParent, int iWidth, Attribute *pAttribute );
131  ~AttributeWidget( void );
132  bool Validate( void );
133  virtual void Update( void ) {};
134  virtual void MoveValue( int /*iStart*/, int /*iEnd*/ ) {};
135  virtual void MoveContent( int iStart, int iEnd, bool bVisibleValue );
136  virtual void ChangeWidth( int iWidth, bool bVisibleValue );
137  inline Attribute *GetAttribute( void ) const { return m_pAttribute; };
138  inline Node *GetNode( void ) const { return m_pNode; };
139  };
140 
142  {
143  Q_OBJECT
144 
145  protected:
146  void Update( void );
147  QLineEdit m_cXBox, m_cYBox, m_cZBox;
148 
149  public:
150  AttributeVectorbox( QWidget *pParent, int iWidth, avector *pAttribute );
151 
152  public slots:
153  void OnChange( void );
154  };
155 
158  {
159  Q_OBJECT
160 
161  protected:
162  void Update( void );
163  QLineEdit m_cXBox, m_cYBox, m_cZBox, m_cWBox;
164 
165  public:
166  AttributeVector4box( QWidget *pParent, int iWidth, avector4 *pAttribute );
167 
168  public slots:
169  void OnChange( void );
170  };
171 
173  {
174  Q_OBJECT
175 
176  protected:
177  void Update( void );
180 
181  public:
182  AttributeEditbox( QWidget *pParent, int iWidth, Attribute *pAttribute );
183 
184  public slots:
185  void OnChange( void );
186  void OnEditFinished( void );
187  };
188 
191  {
192  Q_OBJECT
193  void MoveValue( int iStart, int iEnd );
194  void Update( void );
195  void OnNodeEvent( const Attribute &cAttribute, NodeEventType eType );
196 
197  unsigned int m_iWidth;
198 
199  protected:
201 
202  public:
203  AttributeImagebox( QWidget *pParent, int iWidth, AttributePointer<Image> *pImage );
204  };
205 
208  {
209  Q_OBJECT
210  bool m_bLock;
211  void Update( void );
212 
213  protected:
215 
216  public:
217  AttributeCheckbox( QWidget *pParent, int iWidth, abool *pAttribute );
218 
219  public slots:
220  void OnChange( int iState );
221  };
222 
224  {
225  Q_OBJECT
226 
227  protected:
228  void Update( void );
229 
230  public:
231  AttributeColorbox( QWidget *pParent, int iWidth, acolor *pAttribute );
232 
233  public slots:
234  void OnAboutToShowChooser(QColor* color);
235  void OnColorChanged(const QColor&);
236 
237  public:
238  static QWidget* CreateColorButton(const QColor& color, QWidget* parent, Attribute *pAttribute);
239  };
240 
243  {
244  class Slider : public QSlider
245  {
246  void mouseDoubleClickEvent( QMouseEvent *pEvent )
247  {
248  if ( m_pOwner )
249  {
250  afloatr* pA = (afloatr *)m_pOwner->GetAttribute();
251  if ( pEvent->button() == Qt::LeftButton )
252  pA->SetMax( pA->Value() );
253  if ( pEvent->button() == Qt::RightButton )
254  pA->SetMin( pA->Value() );
255  setValue( (int)(1000*(pA->Value()-pA->Min())/(pA->Max()-pA->Min())) );
256  };
257  };
258  public:
259  Slider( QWidget *pParent ) : QSlider( pParent ) { m_pOwner = 0; };
260  AttributeSliderbox *m_pOwner;
261  };
262  Q_OBJECT
263  bool m_bLock, m_bSliderLock;
264 
265  protected:
266  void Update( void );
267  Slider m_cSlider;
268 
269  public:
270  AttributeSliderbox( QWidget *pParent, int iWidth, afloatr *pAttribute );
271 
272  public slots:
273  void OnMove( int );
274  };
275 
277  {
278  struct SpinBox : public QSpinBox
279  {
280  SpinBox( QWidget *pParent, int iDigitCount ) : QSpinBox( pParent )
281  {
282  m_iDigitCount = iDigitCount;
283  };
284  private:
285  QString textFromValue ( int v ) const
286  {
287  QString s = QString::number( v );
288  while ( s.length() < m_iDigitCount )
289  s = "0"+s;
290  return s;
291  };
292  int m_iDigitCount;
293  };
294  Q_OBJECT
295 
296  protected:
297  SpinBox m_cSpin;
298  bool m_bLock;
299  void Update( void );
300 
301  public:
302  AttributeSpinbox( QWidget *pParent, int iWidth, aint *pAttribute, int iSpinWidth = 40, int iDigitCount = 1 );
303 
304  public slots:
305  void OnChange( int );
306  };
307 
310  {
311  Q_OBJECT
312  bool m_bLock;
313 
314  protected:
315  void Update( void );
319 
320  public:
321  AttributeCombobox( QWidget *pParent, int iWidth, aenum *pAttribute );
322 
323  public slots:
324  void OnActivate( int );
325  void OnFinished( int );
326  };
327 
329  {
330  Q_OBJECT
331 
332  protected:
334 
335  public:
336  AttributeComboboxMap( QWidget* pParent, int iWidth, astring* pAttribute, const QMap<QString, QString>& pMap );
337 
338  protected:
339  void Update(const QMap<QString, QString>&);
340  static void Update(QComboBox* cComboBox, const QMap<QString, QString>& pMap, const QString& sSelected);
341 
342  public slots:
343  void OnActivate( int );
344  };
345 
348  {
349  Q_OBJECT
350 
351  protected:
353 
354  public:
355  AttributeFilenamebox( QWidget *pParent, int iWidth, afilename *pAttribute );
356 
357  public slots:
358  void OnBrowse( void );
359  void OnEdit( void );
360  };
361 
364  {
365  Q_OBJECT
366 
367  public:
368  AttributeTextureFilenamebox( QWidget *pParent, int iWidth, afilename *pAttribute );
369 
370  public slots:
371  void OnMenu( void );
372  void OnSave( void );
373  };
374 
376  {
377  Q_OBJECT
378 
379  protected:
381 
382  public:
383  AttributeEventbox( QWidget *pParent, int iWidth, EventGate *pAttribute );
384 
385  public slots:
386  void OnAction( void );
387  };
388 
391  {
392  Q_OBJECT
393  bool m_bLock;
394  bool m_bNullStringInserted;
395 
396  protected: QComboBox m_cCombo; const ClassDesc *m_pType; void Update( void );
397  public: AttributePointerbox( QWidget *pParent, int iWidth, Attribute *pAttribute, const ClassDesc *pClass );
398  public slots: void OnChange( int );
399  };
400 
403  {
404  Q_OBJECT
405  QCheckBox *m_aCheckboxes[32];
406  QWidget m_cValues;
407  void Update( void );
408 
409  public:
410  AttributeCheckboxCollection( QWidget *pParent, int iWidth, aboolc *pAttribute );
411 
412  public slots:
413  void OnChange( int iState );
414  };
415 
418  {
419  Q_OBJECT
420  bool m_bLock;
421  void Update( void );
422 
423  protected:
428 
429  public:
430  AttributeSliderWithCheckbox( QWidget *pParent, int iWidth, acheckablefloat *pAttribute );
431 
432  public slots:
433  void OnChange( void );
434  };
435 
438  {
439  Q_OBJECT
440  bool m_bLock;
441  void Update( void );
442 
443  protected:
448 
449  public:
450  AttributeSliderArrayWithCheckbox( QWidget *pParent, int iWidth, AttributeCheckableFloatArray *pAttribute );
451 
452  public slots:
453  void OnChange( void );
454  };
455 
456  class MBDLL_DECL CPBox : public QWidget
457  {
458  Q_OBJECT
459  public:
460  CPBox( int iIndex, QWidget *pParent = 0, const char *sName = 0 );
462  int m_iIndex;
463 
464  protected:
465  void mousePressEvent( QMouseEvent *pEvent );
466  QSize sizeHint( void ) const;
467  void paintEvent( QPaintEvent *pEvent );
468  };
469 
471  {
472  Q_OBJECT
473  public:
474  CurveEditor( QWidget *pParent = 0, const char *sName = 0, bool bNurbs = false );
475  void SelectCP( CPBox *pCP );
476  void DeleteCP( void );
477  void AddCP( float x, float y );
478  void Init( void *pCurve = 0 );
479  void SetFixedSize(int w, int h);
480  void MakeReadOnly();
481  void NurbsValueChanged();
482  void ApplyCurve();
483 
484  bool m_bSnap, m_bNurbs;
486  void *m_pCurve;
487 
488  signals:
489  void nurbsValueChanged();
490  void CurveReadyToBeApplied();
491 
492  protected:
493  QSize sizeHint( void ) const;
494  void paintEvent( QPaintEvent *pe );
495  void resizeEvent( QResizeEvent *pEvent );
496  void mousePressEvent( QMouseEvent *pEvent );
497  void mouseReleaseEvent( QMouseEvent *pEvent );
498  void mouseMoveEvent( QMouseEvent *pEvent );
499  void keyPressEvent( QKeyEvent *pEvent );
500  void keyReleaseEvent ( QKeyEvent *pEvent );
501  int CanvasToScreenX( float f );
502  int CanvasToScreenY( float f );
503  float ScreenToCanvasX( int i );
504  float ScreenToCanvasY( int i );
505  int m_iCanvasWidth, m_iCanvasHeight;
508  QPoint m_aDeleteCoordinates[MAX_CURVE_POINTS];
509 
510  private:
511  void ComputeDeleteCoordinates();
512  bool IsPointNear(const QPoint& pos);
513  int IndexOfClosestPoint(const QPoint& post);
514 
515  bool m_bIsDragging, m_bReadOnly, m_bIsPointAddable, m_bIsPointDeletable;
516  int m_iSnapDistance, m_iNumBoxes, m_iDeleteIndex;
517  float m_fGridSizeX, m_fGridSizeY, m_fStep;
518  QCursor m_addCursor, m_deleteCursor;
519  QRect m_CurveDisplayBoundary, m_DeleteDisplayBoundary;
520  };
521 
532  {
533  Q_OBJECT
534 
535  protected:
538  bool eventFilter( QObject *pTarget, QEvent *pEvent );
539 
540  public:
543  QWidget *pParent,
544  int iWidth,
545  acurveptr *pAttribute,
546  bool bSnapAndStore,
547  bool bInAdjustColor = false
548  );
549 
551  bool EditorInAdjustColor() const { return m_bUsedInAdjustColor; };
552 
561  void ReplaceNurbsInEditor(NURBSCurve *pCurve) { m_pCurveEditor->Init(pCurve); };
562 
563  public slots:
565  void OnChange( void );
566 
568  void Update( void );
569 
571  void OnEnlarge(void);
572 
574  void StartUpdateCountdown(void);
575 
579  void OnColorCorrectionClosing(void);
580 
581  signals:
583  void ParentEditorInColorCorrectionClosing(void);
584 
585  private:
586  QTimer m_updateTimer;
587  bool m_bIsUpdatingTargets, m_bUsedInAdjustColor;
588  };
589 
593  {
594  Q_OBJECT
595  public:
598  AttributeCurveEditor *pCurve
599  );
600 
601  signals:
606  void CurveSelected( int iIndex );
607 
608  protected:
610  void resizeEvent( QResizeEvent *pEvent );
611 
614  void changeEvent ( QEvent *pEvent );
615 
616  private:
617  CurveEditor *m_pCurveEditorFrame;
618  AttributeCurveEditor *m_pAttributeCurve;
619  // if the AttributeCurveEditor contained in this dialog belongs to a curve from Adjust Color Dialog, this is the index of
620  // the item in the combo box for the curve selection. -1 otherwise.
621  int m_iIndexOfCurve;
622  };
623 
625  {
626  Q_OBJECT
627 
628  protected:
629  void UpdateImage( void );
630  bool LoadImage(const QString &imgFileName);
631 
634 
650 
651  public:
652  AttributeStampConfigurationWidget( QWidget *pParent, int iWidth, astampcfg *pAttribute );
653 
654  public slots:
655  void Update( void );
656  void OnChange( void );
657  void OnRotate( void );
658  };
659 
660 
663  {
664  Q_OBJECT
665  public:
667  AttributeMirrorConfigurationWidget( QWidget *pParent, int iWidth, amirrorcfg *pAttribute );
668 
669  protected:
671  bool m_bLock;
673  void Update( void );
676  public slots:
678  void OnChange( int );
681  void ShowMirrorAxis( int );
682  };
683 
686  {
687  Q_OBJECT
688  public:
690  HelpButton( QWidget* parent, const QString & sID, const QString & sText = tr("Help...") );
692  void SetHelpID( const QString & sID );
694  QString HelpID( void ) { return m_sID; };
695 
696  protected:
698  QString m_sID;
701 
702  };
703 };
704 
705 #endif
706 
QVector< QLineEdit * > m_aEditBox
Definition: widgets.h:445
GLenum GLint GLint y
Definition: GLee.h:876
#define MAX_CURVE_POINTS
Definition: widgets.h:53
virtual void hidePopup()
This attribute represents a float value which has a minimum and a maximum value.
Definition: node.h:1020
virtual void Update(void)
Definition: widgets.h:133
QPushButton * m_pStoreF
Definition: widgets.h:536
A widget used to display and alter the value for a bool collection attribute.
Definition: widgets.h:402
void Init(void *pCurve=0)
bool m_bSelected
Definition: widgets.h:461
MirrorComboBox(QWidget *parent=0, const char *name=0)
Constructor (the same as QComboBox)
Definition: widgets.h:67
Qt::MouseButton button() const
Definition: qevent.h:101
A widget used to display and alter the value for an image attribute.
Definition: widgets.h:190
virtual void MoveValue(int, int)
Definition: widgets.h:134
Definition: qlabel.h:55
A widget which is used to display and alter the value for a texture attribu.
Definition: widgets.h:363
A widget for accessing the context sensitive help.
Definition: widgets.h:685
An attribute widget for setting the brush mirror mode.
Definition: widgets.h:662
int m_iIndex
Definition: widgets.h:462
Definition: qcolor.h:67
MirrorComboBox m_cCombo
The combo box to display mirror modes.
Definition: widgets.h:675
const ClassDesc * m_pType
Definition: widgets.h:396
A widget which is used to display and alter the value for a bool attribute.
Definition: widgets.h:207
This is the base class for most classes in the Mudbox SDK.
Definition: node.h:740
QPushButton m_cButton
Definition: widgets.h:380
QPushButton m_cBrowseButton
Definition: widgets.h:352
NodeEventType
Possible event types when Node::OnNodeEvent is called.
Definition: node.h:148
bool EditorInAdjustColor() const
Returns whether this widget is being used in the Adjust Color dialog.
Definition: widgets.h:551
MirrorComboBox m_cCombo
Definition: widgets.h:316
static QSignalMapper * s_pSignalMapper
Definition: widgets.h:700
bool m_bLock
Prevents unnecessary window updates.
Definition: widgets.h:671
A fake attribute used to watch an attribute in your class which is not a member.
Definition: node.h:1159
Node * GetNode(void) const
Definition: widgets.h:138
Definition: qframe.h:55
Definition: qpoint.h:53
This attribute is a collection of bools.
Definition: node.h:1167
A widget which is used to display and alter some values for a bool attribute.
Definition: widgets.h:437
Definition: qtimer.h:56
QHBoxLayout * m_pValueStretchLayout
Definition: widgets.h:123
This dialog allows an AttributeCurveEditor to be resizable in order to manipulate its curve more easi...
Definition: widgets.h:592
#define emit
Definition: qobjectdefs.h:76
Definition: qimage.h:87
This is a generic attribute which can be used instead of the standard built in types.
Definition: node.h:394
This structure represents and describes a class.
Definition: node.h:22
A widget used to display and alter the value for a filename attribute.
Definition: widgets.h:347
A widget which used to display and alter the value for a float range attribute.
Definition: widgets.h:242
GLenum GLint x
Definition: GLee.h:876
MirrorComboBox is a QComboBox that emits a signal when it loses keyboard focus.
Definition: widgets.h:62
A widget used to display and alter the value for a four dimensional vector attribute.
Definition: widgets.h:157
This class represents an event receiver/triggerer point.
Definition: node.h:999
#define Q_OBJECT
Definition: qobjectdefs.h:157
const type & Value(void) const
Returns the value of the attribute.
Definition: node.h:406
A widget used to display and alter the value for a pointer attribute.
Definition: widgets.h:390
~MirrorComboBox()
Destructor.
Definition: widgets.h:71
const GLdouble * v
Definition: GLee.h:1174
void SetMin(float fValue)
void ReplaceNurbsInEditor(NURBSCurve *pCurve)
Call this in order to override the NURBSCurve being used in this widget with another one...
Definition: widgets.h:561
Similar to AttributeInstance but it provides a button on the interface where the user can bro...
Definition: node.h:1126
Definition: qrect.h:58
A widget which is used to display and alter the value for a bool attribute.
Definition: widgets.h:417
QWidget * m_pButtonFrame
Definition: widgets.h:318
float Max(void) const
int int int int int int h
Definition: GLee.h:10534
Definition: qsize.h:53
GLuint const GLchar * name
Definition: GLee.h:1704
Class: ConvolutionKernel.
Definition: array.h:15
This is an abstract base structure for all attributes.
Definition: node.h:181
int length() const
Definition: qstring.h:696
A widget used to display and alter the value for an enum attribute.
Definition: widgets.h:309
CurveEditor * m_pCurveEditor
Definition: widgets.h:537
static QString number(int, int base=10)
GLubyte GLubyte GLubyte GLubyte w
Definition: GLee.h:1775
This attribute is very similar to the aint type but on the user interface it will be displayed as a c...
Definition: node.h:1071
#define slots
Definition: qobjectdefs.h:68
void focusOutEvent(QFocusEvent *)
This QWidget method is overridden here to emit the "departed" signal.
Definition: widgets.h:84
#define signals
Definition: qobjectdefs.h:69
An attribute widget for displaying and interacting with multiple curve editors.
Definition: widgets.h:531
CPBox * m_pSelectedBox
Definition: widgets.h:507
GLdouble s
Definition: GLee.h:1173
GLclampf f
Definition: GLee.h:9303
Attribute * GetAttribute(void) const
Definition: widgets.h:137
#define MBDLL_DECL
Definition: dllinterface.h:35
This class can be used instead of standard pointers, when the pointer target class is derived from th...
Definition: node.h:601
void SetMax(float fValue)
float Min(void) const
GLuint color
Definition: GLee.h:8456