home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / dist / fw_qt3.idb / usr / freeware / Qt / examples / demo / dnd / styledbutton.h.z / styledbutton.h
Encoding:
C/C++ Source or Header  |  2002-04-08  |  2.5 KB  |  94 lines

  1. /**********************************************************************
  2. ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
  3. **
  4. ** This file is part of Qt Designer.
  5. **
  6. ** This file may be distributed and/or modified under the terms of the
  7. ** GNU General Public License version 2 as published by the Free Software
  8. ** Foundation and appearing in the file LICENSE.GPL included in the
  9. ** packaging of this file.
  10. **
  11. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  12. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  13. **
  14. ** See http://www.trolltech.com/gpl/ for GPL licensing information.
  15. **
  16. ** Contact info@trolltech.com if any conditions of this licensing are
  17. ** not clear to you.
  18. **
  19. **********************************************************************/
  20.  
  21. #ifndef STYLEDBUTTON_H
  22. #define STYLEDBUTTON_H
  23.  
  24. #include <qbutton.h>
  25. #include <qpixmap.h>
  26.  
  27. class QColor;
  28. class QBrush;
  29.  
  30. class StyledButton : public QButton
  31. {
  32.     Q_OBJECT
  33.  
  34.     Q_PROPERTY( QColor color READ color WRITE setColor )
  35.     Q_PROPERTY( QPixmap pixmap READ pixmap WRITE setPixmap )
  36.     Q_PROPERTY( EditorType editor READ editor WRITE setEditor )
  37.     Q_PROPERTY( bool scale READ scale WRITE setScale )
  38.  
  39.     Q_ENUMS( EditorType )
  40.  
  41. public:
  42.     enum EditorType { ColorEditor, PixmapEditor };
  43.  
  44.     StyledButton( QWidget* parent = 0, const char* name = 0 );
  45.     StyledButton( const QBrush& b, QWidget* parent = 0, const char* name = 0, WFlags f = 0 );
  46.     ~StyledButton();
  47.  
  48.     void setEditor( EditorType );
  49.     EditorType editor() const;
  50.  
  51.     void setColor( const QColor& );
  52.     void setPixmap( const QPixmap& );
  53.  
  54.     QPixmap* pixmap() const;
  55.     QColor color() const;
  56.  
  57.     void setScale( bool );
  58.     bool scale() const;
  59.  
  60.     QSize sizeHint() const;
  61.     QSize minimumSizeHint() const;
  62.  
  63. public slots:
  64.     virtual void onEditor();
  65.  
  66. signals:
  67.     void changed();
  68.  
  69. protected:
  70.     void mousePressEvent(QMouseEvent*);
  71.     void mouseMoveEvent(QMouseEvent*);
  72. #ifndef QT_NO_DRAGANDDROP
  73.     void dragEnterEvent ( QDragEnterEvent * );
  74.     void dragMoveEvent ( QDragMoveEvent * );
  75.     void dragLeaveEvent ( QDragLeaveEvent * );
  76.     void dropEvent ( QDropEvent * );
  77. #endif // QT_NO_DRAGANDDROP
  78.     void drawButton( QPainter* );
  79.     void drawButtonLabel( QPainter* );
  80.     void resizeEvent( QResizeEvent* );
  81.     void scalePixmap();
  82.  
  83. private:
  84.     QPixmap* pix;
  85.     QPixmap* spix;  // the pixmap scaled down to fit into the button
  86.     QColor col;
  87.     EditorType edit;
  88.     bool s;
  89.     QPoint pressPos;
  90.     bool mousePressed;
  91. };
  92.  
  93. #endif //STYLEDBUTTON_H
  94.